Re: [PATCH] KVM: x86/mmu: treat WC memory as MMIO

From: francisco flynn
Date: Tue Mar 12 2024 - 04:42:25 EST




On 2024/3/12 00:20, Sean Christopherson wrote:
> On Mon, Mar 11, 2024, francisco_flynn wrote:
>> when doing kvm_tdp_mmu_map for WC memory, such as pages
>> allocated by amdgpu ttm driver for ttm_write_combined
>> caching mode(e.g. host coherent in vulkan),
>> the spte would be set to WB, in this case, vcpu write
>> to these pages would goes to cache first, and never
>> be write-combined and host-coherent anymore. so
>> WC memory should be treated as MMIO, and the effective
>> memory type is depending on guest PAT.
>
> No, the effective memtype is not fully guest controlled. By forcing the EPT memtype
> to UC, the guest can only use UC or WC. I don't know if there's a use case for

Well,it's actually the host mapping memory WC and guest uses WC,
one use case is virtio-gpu host blob, which is to map physical GPU buffers into guest

> the host mapping memory WC while the guest uses WB, but it should be a moot point,
> because this this series should do what you want (allow guest to map GPU buffers
> as WC).
>
> https://lore.kernel.org/all/20240309010929.1403984-1-seanjc@xxxxxxxxxx
>

yes, this is what i want, but for virtio-gpu device, if we mapping WC typed
GPU buffer into guest, kvm_arch_has_noncoherent_dma would return false,
so on cpu without self-snoop support, guest PAT will be ignored, the effective
memory type would be set to WB, causing data inconsistency.

+ if (!static_cpu_has(X86_FEATURE_SELFSNOOP) &&
+ !kvm_arch_has_noncoherent_dma(vcpu->kvm))
return (MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT;


>> Signed-off-by: francisco_flynn <francisco_flynn@xxxxxxxxxxx>
>> ---
>> arch/x86/include/asm/memtype.h | 2 ++
>> arch/x86/kvm/mmu/spte.c | 5 +++--
>
> Please use get_maintainers.pl.

sure.

>
>> arch/x86/mm/pat/memtype.c | 8 ++++++++
>> 3 files changed, 13 insertions(+), 2 deletions(-)