Re: External USB disks not recognized with v6.1.8 when using Xen

From: Christian Kujau
Date: Fri Feb 03 2023 - 11:50:51 EST


On Thu, 2 Feb 2023, Linus Torvalds wrote:
> So I think that commit should be reverted as broken, and then people
> should *maybe* look at something like this (intentionally whitespace
> damaged, and people should *really* think about what the
> MTRR_TYPE_INVALID case should be - returning UC- is probably what is

Not fully understanding what your proposal really does, I got curious and
applied it to v6.2-rc6 with 90b926e68f50 (upstream) reverted. And it
boots, and the disks are there, and the "ioremap error" is gone, but now
I've got strange memory allocation errors, for like really small
operations (I wanted to capture dmesg):

$ dmesg -t | xz -9ec | base64
xz: (stdin): Out of memory

With v6.2-rc6 (vanilla, and also booted under Xen) there's no problem
allocating much more memory than that, so something is still not right.
Patch applied for reference, but as you said: nobody should apply this :-)

More details:

- https://nerdbynature.de/bits/usb_v6.1.8/dmesg.6.1.8.xen
- https://nerdbynature.de/bits/usb_v6.1.8/dmesg_xen-6.1.8_MTRR_TYPE_INVALID.txt
- https://nerdbynature.de/bits/usb_v6.1.8/meminfo_xen-6.1.8.txt
- https://nerdbynature.de/bits/usb_v6.1.8/meminfo_xen-6.1.8_MTRR_TYPE_INVALID.txt

Thanks,
Christian.
--
BOFH excuse #448:

vi needs to be upgraded to viicommit 56a159efebc0
Author: Christian Kujau <lists@xxxxxxxxxxxxxxx>
Date: Fri Feb 3 17:13:33 2023 +0100

MTRR_TYPE_INVALID fixes as proposed by Linus.

diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h
index f0eeaf6e5f5f..38ded2762847 100644
--- a/arch/x86/include/asm/mtrr.h
+++ b/arch/x86/include/asm/mtrr.h
@@ -53,7 +53,8 @@ static inline u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform)
/*
* Return no-MTRRs:
*/
- return MTRR_TYPE_INVALID;
+ *uniform = 1;
+ return MTRR_TYPE_INVALID; /* ??? */
}
#define mtrr_save_fixed_ranges(arg) do {} while (0)
#define mtrr_save_state() do {} while (0)
diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
index ee09d359e08f..0d77998b90ea 100644
--- a/arch/x86/kernel/cpu/mtrr/generic.c
+++ b/arch/x86/kernel/cpu/mtrr/generic.c
@@ -261,11 +261,13 @@ u8 mtrr_type_lookup(u64 start, u64 end, u8 *uniform)
/* Make end inclusive instead of exclusive */
end--;

+ type = MTRR_TYPE_INVALID; /* ??? */
if (!mtrr_state_set)
- return MTRR_TYPE_INVALID;
+ goto out;

+ type = mtrr_state.def_type;
if (!(mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED))
- return MTRR_TYPE_INVALID;
+ goto out;

/*
* Look up the fixed ranges first, which take priority over