[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250705071717.5062-3-ankita@nvidia.com>
Date: Sat, 5 Jul 2025 07:17:13 +0000
From: <ankita@...dia.com>
To: <ankita@...dia.com>, <jgg@...dia.com>, <maz@...nel.org>,
<oliver.upton@...ux.dev>, <joey.gouly@....com>, <suzuki.poulose@....com>,
<yuzenghui@...wei.com>, <catalin.marinas@....com>, <will@...nel.org>,
<ryan.roberts@....com>, <shahuang@...hat.com>, <lpieralisi@...nel.org>,
<david@...hat.com>, <ddutile@...hat.com>, <seanjc@...gle.com>
CC: <aniketa@...dia.com>, <cjia@...dia.com>, <kwankhede@...dia.com>,
<kjaju@...dia.com>, <targupta@...dia.com>, <vsethi@...dia.com>,
<acurrid@...dia.com>, <apopple@...dia.com>, <jhubbard@...dia.com>,
<danw@...dia.com>, <zhiw@...dia.com>, <mochs@...dia.com>,
<udhoke@...dia.com>, <dnigam@...dia.com>, <alex.williamson@...hat.com>,
<sebastianene@...gle.com>, <coltonlewis@...gle.com>, <kevin.tian@...el.com>,
<yi.l.liu@...el.com>, <ardb@...nel.org>, <akpm@...ux-foundation.org>,
<gshan@...hat.com>, <linux-mm@...ck.org>, <tabba@...gle.com>,
<qperret@...gle.com>, <kvmarm@...ts.linux.dev>,
<linux-kernel@...r.kernel.org>, <linux-arm-kernel@...ts.infradead.org>,
<maobibo@...ngson.cn>
Subject: [PATCH v10 2/6] KVM: arm64: Update the check to detect device memory
From: Ankit Agrawal <ankita@...dia.com>
Currently, the kvm_is_device_pfn() detects if the memory is kernel
mapped through pfn_is_map_memory. It thus implies whether KVM can
use Cache Maintenance Operations (CMOs) on that PFN. It is a bit
of a misnomer as it does not necessarily detect whether a PFN
is for a device memory. Moreover, the function is only used at
one place.
It would be better to directly call pfn_is_map_memory. Moreover
we should restrict this call to VM_PFNMAP or VM_MIXEDMAP. Non PFMAP
or MIXEDMAP VMA's must always contain normal pages which are
struct page backed, have KVA's and are cachable. So we should always
be able to go from phys to KVA to do a CMO.
Suggested-by: Jason Gunthorpe <jgg@...dia.com>
Reviewed-by: Jason Gunthorpe <jgg@...dia.com>
Reviewed-by: David Hildenbrand <david@...hat.com>
Tested-by: Donald Dutile <ddutile@...hat.com>
Signed-off-by: Ankit Agrawal <ankita@...dia.com>
---
arch/arm64/kvm/mmu.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 1601ab9527d4..5fe24f30999d 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -193,11 +193,6 @@ int kvm_arch_flush_remote_tlbs_range(struct kvm *kvm,
return 0;
}
-static bool kvm_is_device_pfn(unsigned long pfn)
-{
- return !pfn_is_map_memory(pfn);
-}
-
static void *stage2_memcache_zalloc_page(void *arg)
{
struct kvm_mmu_memory_cache *mc = arg;
@@ -1492,6 +1487,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R;
struct kvm_pgtable *pgt;
struct page *page;
+ vm_flags_t vm_flags;
enum kvm_pgtable_walk_flags flags = KVM_PGTABLE_WALK_HANDLE_FAULT | KVM_PGTABLE_WALK_SHARED;
if (fault_is_perm)
@@ -1619,6 +1615,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
vfio_allow_any_uc = vma->vm_flags & VM_ALLOW_ANY_UNCACHED;
+ vm_flags = vma->vm_flags;
+
/* Don't use the VMA after the unlock -- it may have vanished */
vma = NULL;
@@ -1642,7 +1640,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
if (is_error_noslot_pfn(pfn))
return -EFAULT;
- if (kvm_is_device_pfn(pfn)) {
+ if (vm_flags & (VM_PFNMAP | VM_MIXEDMAP) && !pfn_is_map_memory(pfn)) {
/*
* If the page was identified as device early by looking at
* the VMA flags, vma_pagesize is already representing the
--
2.34.1
Powered by blists - more mailing lists