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

From: Linus Torvalds
Date: Sun Feb 05 2023 - 15:22:09 EST


On Sun, Feb 5, 2023 at 5:20 AM Borislav Petkov <bp@xxxxxxxxx> wrote:
>
> @@ -53,7 +53,8 @@ static inline u8 mtrr_type_lookup(u64 addr,
> /*
> * Return no-MTRRs:
> */
> - return MTRR_TYPE_INVALID;
> + *uniform = 1;
> + return MTRR_TYPE_UNCACHABLE;

So this is the one I'd almost leave alone.

Because this is not a "there are no MTRR's" situation, this is a "I
haven't enabled CONFIG_MTRR, so I don't _know_ if there are any MTRR's
or not.

And returning MTRR_TYPE_UNCACHABLE will then disable things like
largepages etc, so this change would effectively mean that if
CONFIG_MTRR is off, it would turn off hugepage support too.

But maybe that was the only thing that cared, and we have:

> @@ -721,8 +721,9 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
> u8 mtrr, uniform;
>
> mtrr = mtrr_type_lookup(addr, addr + PUD_SIZE, &uniform);
> - if ((mtrr != MTRR_TYPE_INVALID) && (!uniform) &&
> - (mtrr != MTRR_TYPE_WRBACK))
> + if (mtrr != MTRR_TYPE_UNCACHABLE &&
> + mtrr != MTRR_TYPE_WRBACK &&
> + !uniform)
> return 0;

Here you make up for it, but I don't actually understand why these
checks exist at all.

I *think* that what the check should do is just check for uniformity.

Why would the largepage code otherwise care?

Other MTRR types are explicitly fine, and I think things like the X
server might even want to do write-combining with large pages etc.

So I think the hugepage code should only do

if (!uniform)
return 0;

or there should be some explanation for why those types are special?

>> @@ -748,8 +749,9 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
> u8 mtrr, uniform;
>
> mtrr = mtrr_type_lookup(addr, addr + PMD_SIZE, &uniform);
> - if ((mtrr != MTRR_TYPE_INVALID) && (!uniform) &&
> - (mtrr != MTRR_TYPE_WRBACK)) {
> + if (mtrr != MTRR_TYPE_UNCACHABLE &&
> + mtrr != MTRR_TYPE_WRBACK &&
> + !uniform) {

Same here.

Again, I *think* that the reason it used to do that "check two types"
thing is simply because "uniform" wasn't set correctly.

But I don't know.

Linus