KVM: arm64: Map GPU device memory as cacheable
Status from this message: Applied to next, thanks!
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v10 Latest6 patches 10 repliesApplied
- v96 patches 26 repliesSuperseded
- v86 patches 2 repliesSuperseded
Earlier versions · 6
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v7 | 5 patches | 12 replies | Superseded | |
| v6 | 5 patches | 13 replies | Superseded | |
| v5 | 5 patches | 4 replies | Superseded | |
| v4 | 5 patches | 5 replies | Superseded | |
| v3 | 1 patch | 59 replies | Superseded | |
| v2 | 1 patch | 28 replies | Superseded |
Changes in v10 from the cover letter
1. Removed dead code in 5/6 (Jason Gunthorpe).
2. Collected Reviewed-by from Jason Gunthorpe and David Hildenbrand on all but 5/6 patch. (Thanks!)
3. Collected Tested-by from Donald Dutile (Thanks!).
Patches in v10 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/6 | KVM: arm64: Rename the device variable to s2_force_noncacheablearch/ | +6 | 1 reply | |
| 2/6 | KVM: arm64: Update the check to detect device memoryarch/ | +4 | 1 reply | |
| 3/6 | KVM: arm64: Block cacheable PFNMAP mappingarch/ | +33 | 1 reply | |
| 4/6 | KVM: arm64: New function to determine hardware cache management supportarch/ include/ virt/ | +30 | 0 replies | |
| 5/6 | KVM: arm64: Allow cacheable stage 2 mapping using VMA flagsarch/ | +40 | 3 replies | |
| 6/6 | KVM: arm64: Expose new KVM cap for cacheable PFNMAPDocumentation/ arch/ include/ | +20 | 1 reply |
Reviews trailers per patch
All 6 patches have a Reviewed-by or Acked-by.
| Patch | Jason Gunthorpe | David Hildenbrand | Donald Dutile | Catalin Marinas |
|---|---|---|---|---|
| 1/6 | R-b | R-b | T-b | R-b |
| 2/6 | R-b | R-b | T-b | R-b |
| 3/6 | R-b | R-b | T-b | R-b |
| 4/6 | R-b | R-b | T-b | R-b |
| 5/6 | R-b | R-b | T-b | R-b |
| 6/6 | R-b | T-b | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.
Cover letter [PATCH v10 0/6] KVM: arm64: Map GPU device memory as cacheable
From: Ankit Agrawal <[email protected]>
Grace based platforms such as Grace Hopper/Blackwell Superchips have CPU accessible cache coherent GPU memory. The GPU device memory is essentially a DDR memory and retains properties such as cacheability, unaligned accesses, atomics and handling of executable faults. This requires the device memory to be mapped as NORMAL in stage-2.
Today KVM forces the memory to either NORMAL or DEVICE_nGnRE depending on whether the memory region is added to the kernel. The KVM code is thus restrictive and prevents device memory that is not added to the kernel to be marked as cacheable. The patch aims to solve this.
A cachebility check is made by consulting the VMA pgprot value. If the pgprot mapping type is cacheable, it is considered safe to be mapped cacheable as the KVM S2 will have the same Normal memory type as the VMA has in the S1 and KVM has no additional responsibility for safety.
Note when FWB (Force Write Back) is not enabled, the kernel expects to trivially do cache management by flushing the memory by linearly converting a kvm_pte to phys_addr to a KVA. The cache management thus relies on memory being mapped. Since the GPU device memory is not kernel mapped, exit when the FWB is not supported. Similarly, ARM64_HAS_CACHE_DIC allows KVM to avoid flushing the icache and turns icache_inval_pou() into a NOP. So the cacheable PFNMAP is made contingent on these two hardware features.
The ability to safely do the cacheable mapping of PFNMAP is exposed through a KVM capability for userspace consumption.
The changes are heavily influenced by the discussions among maintainers Marc Zyngier and Oliver Upton besides Jason Gunthorpe, Catalin Marinas, David Hildenbrand, Sean Christopherson [1]. Many thanks for their valuable suggestions. Thanks to Donald Dutile for testing the patch series and providing Tested-by.
Applied over next-20250610 and tested on the Grace Blackwell platform by booting up VM, loading NVIDIA module [2] and running nvidia-smi in the VM.
To run CUDA workloads, there is a dependency on the IOMMUFD and the Nested Page Table patches being worked on separately by Nicolin Chen. ([email protected]). NVIDIA has provided git repositories which includes all the requisite kernel [3] and Qemu [4] patches in case one wants to try.
v9 -> v10
1. Removed dead code in 5/6 (Jason Gunthorpe).
2. Collected Reviewed-by from Jason Gunthorpe and David Hildenbrand on all but 5/6 patch. (Thanks!)
3. Collected Tested-by from Donald Dutile (Thanks!).
v8 -> v9
1. Included MIXEDMAP to also be considered for cacheable mapping. (Jason Gunthorpe).
2. Minor text nits (Jason Gunthorpe).
v7 -> v8
1. Renamed device variable to s2_force_noncacheable. (Jason Gunthorpe, Catalin Marinas)
2. Updated code location that block S1 cacheable, S2 non-cacheable mapping. (Jason Gunthorpe, Catalin Marinas)
3. Added comments in the code for COW and cacheability checks. (Jason Gunthorpe, Catalin Marinas)
4. Reorganised the code to setup s2_force_noncacheable variable. (Jason Gunthorpe).
5. Collected Reviewed-By on patch 4/6. (Catalin Marinas)
v6 -> v7
1. New patch to rename symbols to more accurately reflect the CMO usage functionality (Jason Gunthorpe).
2. Updated the block cacheable PFNMAP patch invert the cacheability check function (Sean Christopherson).
3. Removed the memslot flag KVM_MEM_ENABLE_CACHEABLE_PFNMAP. (Jason Gunthorpe, Sean Christopherson, Oliver Upton).
4. Commit message changes in 2/5. (Jason Gunthorpe)
v5 -> v6
1. 2/5 updated to add kvm_arch_supports_cacheable_pfnmap weak definition to avoid build warnings. (Donald Dutile).
v4 -> v5
1. Invert the check to allow MT_DEVICE_* or NORMAL_NC instead of disallowing MT_NORMAL in 1/5. (Catalin Marinas)
2. Removed usage of stage2_has_fwb and directly using the FWB cap check. (Oliver Upton)
3. Introduced kvm_arch_supports_cacheable_pfnmap to check if the prereq features are present. (David Hildenbrand)
v3 -> v4
1. Fixed a security bug due to mismatched attributes between S1 and S2 mapping to move it to a separate patch. Suggestion by Jason Gunthorpe ([email protected]).
2. New minor patch to change the scope of the FWB support indicator function.
3. Patch to introduce a new memslot flag. Suggestion by Oliver Upton ([email protected]) and Marc Zyngier ([email protected])
4. Patch to introduce a new KVM cap to expose cacheable PFNMAP support. Suggestion by Marc Zyngier ([email protected]).
5. Added checks for ARM64_HAS_CACHE_DIC. Suggestion by Catalin Marinas ([email protected])
v2 -> v3
1. Restricted the new changes to check for cacheability to VM_PFNMAP based on David Hildenbrand's ([email protected]) suggestion.
2. Removed the MTE checks based on Jason Gunthorpe's ([email protected]) observation that it already done earlier in kvm_arch_prepare_memory_region.
3. Dropped the pfn_valid() checks based on suggestions by Catalin Marinas ([email protected]).
4. Removed the code for exec fault handling as it is not needed anymore.
v1 -> v2
1. Removed kvm_is_device_pfn() as a determiner for device type memory determination. Instead using pfn_valid()
2. Added handling for MTE.
3. Minor cleanup.
v9 Link:
Ankit Agrawal (6):
KVM: arm64: Rename the device variable to s2_force_noncacheable
KVM: arm64: Update the check to detect device memory
KVM: arm64: Block cacheable PFNMAP mapping
KVM: arm64: New function to determine hardware cache management
support
KVM: arm64: Allow cacheable stage 2 mapping using VMA flags
KVM: arm64: Expose new KVM cap for cacheable PFNMAP
Documentation/virt/kvm/api.rst | 13 +++- arch/arm64/kvm/arm.c | 7 ++ arch/arm64/kvm/mmu.c | 118 ++++++++++++++++++++++++++------- include/linux/kvm_host.h | 2 + include/uapi/linux/kvm.h | 1 + virt/kvm/kvm_main.c | 5 ++ 6 files changed, 122 insertions(+), 24 deletions(-)
Signature · 1 line
2.34.1