From: Sean Christopherson <seanjc@xxxxxxxxxx> Sent: Thursday, February 23, 2023 1:08 PM > > On Thu, Feb 23, 2023, Michael Kelley (LINUX) wrote: > > From: Dave Hansen <dave.hansen@xxxxxxxxx> Sent: Thursday, February 23, 2023 > 12:42 PM > > > > > > On 2/23/23 12:26, Dave Hansen wrote: > > > >> + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) { > > > >> + /* > > > >> + * Ensure fixmaps for IOAPIC MMIO respect memory encryption pgprot > > > >> + * bits, just like normal ioremap(): > > > >> + */ > > > >> + if (x86_platform.hyper.is_private_mmio(phys)) > > > >> + flags = pgprot_encrypted(flags); > > > >> + else > > > >> + flags = pgprot_decrypted(flags); > > > >> + } > > > ... > > > > It does seem a bit odd that there's a new CC_ATTR_GUEST_MEM_ENCRYPT > > > > check wrapping this whole thing. I guess the trip through > > > > pgprot_decrypted() is harmless on normal platforms, though. > > > > > > Yeah, that's _really_ odd. Sean, were you trying to optimize away the > > > indirect call or something? > > No, my thought was simply to require platforms that support GUEST_MEM_ENCRYPT > to > implement x86_platform.hyper.is_private_mmio, e.g. to avoid having to check if > is_private_mmio is NULL, to explicit document that non-Hyper-V encrypted guests > don't (yet) support private MMIO, and to add a bit of documentation around the > {de,en}crypted logic. > > > > I would just expect the Hyper-V/vTOM code to leave > > > x86_platform.hyper.is_private_mmio alone unless it *knows* the platform has > > > private MMIO *and* CC_ATTR_GUEST_MEM_ENCRYPT. > > > > Agreed. > > > > > > > > Is there ever a case where CC_ATTR_GUEST_MEM_ENCRYPT==0 and he > > > Hyper-V/vTOM code would need to set x86_platform.hyper.is_private_mmio? > > > > There's no such case. > > > > I agree that gating with CC_ATTR_GUEST_MEM_ENCRYPT isn't really necessary. > > Current upstream code always does the pgprot_decrypted(), and as you said, > > that's a no-op on platforms with no memory encryption. > > Right, but since is_private_mmio can be NULL, unless I'm missing something we'll > need an extra check no matter what, i.e. the alternative would be > > if (x86_platform.hyper.is_private_mmio && > x86_platform.hyper.is_private_mmio(phys)) > flags = pgprot_encrypted(flags); > else > flags = pgprot_decrypted(flags); > > I have no objection to that approach. It does have the advantage of not needing > an indirect call for encrypted guests that don't support private MMIO, though > I can't imagine this code is performance sensitive. Or statically set a default stub function for is_private_mmio() that returns "false". Then there's no need to check for NULL, and only platforms that want to use it have to code anything. Several other entries in x86_platform have such defaults. Michael