| From 9ffdcfd7ae75731328018465f61d58fcd90fa749 Mon Sep 17 00:00:00 2001 |
| From: Yan Zhao <yan.y.zhao@intel.com> |
| Date: Fri, 5 Jan 2024 17:15:35 +0800 |
| Subject: [PATCH] BACKPORT: FROMLIST: KVM: VMX: Honor guest PATs for memslots |
| of flag KVM_MEM_NON_COHERENT_DMA |
| |
| Honor guest PATs in the range of memslots of flag KVM_MEM_NON_COHERENT_DMA |
| set no matter the value of noncoherent dma count. |
| |
| Just honoring guest PATs (without honoring guest MTRRs) for memslots of |
| flag KVM_MEM_NON_COHERENT_DMA is because |
| - guest OS will ensure no page aliasing issue in guest side by honoring |
| guest MTRRs in guest page table. |
| Combinations like guest MTRR=WC or UC, guest PAT = WB is not allowed. |
| (at least in Linux, see pat_x_mtrr_type()). |
| - guest device driver programs device hardware according to guest PATs in |
| modern platforms. |
| |
| Besides, we don't break down an EPT huge page if guest MTRRs in its range |
| are not consistent, because |
| - guest should have chosen correct guest PATs according to guest MTRRs. |
| - in normal platforms, small guest pages with different PATs must |
| correspond to different TLBs though they are mapped in a huge page in |
| EPT. |
| |
| However, one condition may not be supported well by honoring guest PAT |
| alone -- when guest MTRR=WC, guest PAT=UC-. |
| By honoring guest MTRRs+PATs, the effective memory type is WC; while |
| by honoring guest PATs alone, the effective memory type is UC. |
| But it's arguable to support such a usage. |
| |
| Suggested-by: Sean Christopherson <seanjc@google.com> |
| Cc: Kevin Tian <kevin.tian@intel.com> |
| Cc: Zhenyu Wang <zhenyuw@linux.intel.com> |
| Tested-by: Yongwei Ma <yongwei.ma@intel.com> |
| Signed-off-by: Yan Zhao <yan.y.zhao@intel.com> |
| Signed-off-by: Dawn Han <dawnhan@google.com> |
| |
| (am from https://lore.kernel.org/all/20240105091535.24760-1-yan.y.zhao@intel.com/) |
| |
| BUG=b:335525888 |
| UPSTREAM-TASK=b:321924870 |
| TEST=run against ARCVM with change patch |
| |
| Change-Id: I6cbdad495708fbf43e078a5fbda491b8424f1813 |
| Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/5479189 |
| Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> |
| Commit-Queue: Dawn Han <dawnhan@google.com> |
| Tested-by: Dawn Han <dawnhan@google.com> |
| --- |
| arch/x86/kvm/vmx/vmx.c | 3 +++ |
| 1 file changed, 3 insertions(+) |
| |
| diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c |
| index 81c101bbc1aa9d40bdfca50f4ee47c0b7c6bbb11..fa9a9b168c4bba50459d38e140df3298c25783e3 100644 |
| --- a/arch/x86/kvm/vmx/vmx.c |
| +++ b/arch/x86/kvm/vmx/vmx.c |
| @@ -7658,6 +7658,9 @@ u8 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio, |
| if (is_mmio) |
| return MTRR_TYPE_UNCACHABLE << VMX_EPT_MT_EPTE_SHIFT; |
| |
| + if (slot->flags & KVM_MEM_NON_COHERENT_DMA) |
| + return MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT; |
| + |
| /* |
| * Force WB and ignore guest PAT if the VM does NOT have a non-coherent |
| * device attached and the CPU doesn't support self-snoop. Letting the |
| -- |
| 2.46.0.rc2.264.g509ed76dc8-goog |
| |