KVM: SVM: Add Page Modification Logging (PML) support
cover KVM: SVM: Add Page Modification Logging (PML) support
This series implements Page Modification Logging (PML) for guests, bringing hardware-assisted dirty logging support. PML is designed to track guest modified memory pages. PML enables the hypervisor to identify which pages in a guest's memory have been modified since the last checkpoint or during live migration.
The PML feature uses two new VMCB fields (PML_ADDR and PML_INDEX) and generates a VMEXIT when the 4KB log buffer becomes full.
Patch breakdown:
1. Refactor existing VMX PML code to be shared between VMX and SVM
2. Skip SNP-safe alloc when HvInUseWrAllowed is available
3. Add AMD SVM PML CPUID
4. Implement SVM PML support using the shared infrastructure
The feature is enabled by default when hardware support is detected and can be disabled via the 'pml' module parameter.
Nikunj A Dadhania (4):
KVM: x86: Carve out PML flush routine
KVM: SEV: Skip SNP-safe allocation when HvInUseWrAllowed is supported x86/cpufeatures: Add Page modification logging
KVM: SVM: Add Page modification logging support
arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/svm.h | 6 +- arch/x86/include/uapi/asm/svm.h | 2 + arch/x86/kernel/cpu/scattered.c | 1 + arch/x86/kvm/svm/sev.c | 3 +- arch/x86/kvm/svm/svm.c | 99 +++++++++++++++++++++++++++++- arch/x86/kvm/svm/svm.h | 4 ++ arch/x86/kvm/vmx/vmx.c | 26 +------- arch/x86/kvm/vmx/vmx.h | 5 -- arch/x86/kvm/x86.c | 31 ++++++++++ arch/x86/kvm/x86.h | 7 +++ 11 files changed, 151 insertions(+), 34 deletions(-)
base-commit: 196d9e72c4b0bd68b74a4ec7f52d248f37d0f030 --
2.43.0
RFC PATCH 1/4 KVM: x86: Carve out PML flush routine
Move the PML (Page Modification Logging) buffer flushing logic from VMX-specific code to common x86 KVM code to enable reuse by SVM and avoid code duplication.
The PML constants (PML_LOG_NR_ENTRIES and PML_HEAD_INDEX) are moved from vmx.h to x86.h to make them available to both VMX and SVM.
No functional change intended for VMX, except tone down the WARN_ON() to WARN_ON_ONCE() for the page alignment check. If hardware exhibits this behavior once, it's likely to occur repeatedly, so use WARN_ON_ONCE() to avoid log flooding while still capturing the unexpected condition.
The refactoring prepares for SVM to leverage the same PML flushing implementation.
--- arch/x86/kvm/vmx/vmx.c | 26 ++------------------------ arch/x86/kvm/vmx/vmx.h | 5 ----- arch/x86/kvm/x86.c | 31 +++++++++++++++++++++++++++++++ arch/x86/kvm/x86.h | 7 +++++++ 4 files changed, 40 insertions(+), 29 deletions(-)
arch/x86/kvm/vmx/vmx.c +2 -24
@@ -6107,37 +6107,15 @@ static void vmx_destroy_pml_buffer(struct vcpu_vmx *vmx)static void vmx_flush_pml_buffer (struct kvm_vcpu *vcpu) {struct vcpu_vmx *vmx =to_vmx (vcpu); -u16 pml_idx, pml_tail_index; -u64 *pml_buf; -int i; +u16 pml_idx; pml_idx =vmcs_read16 (GUEST_PML_INDEX );/* Do nothing if PML buffer is empty */ if (pml_idx ==PML_HEAD_INDEX )return ; -/* -* PML index always points to the next available PML buffer entity -* unless PML log has just overflowed. -*/ - pml_tail_index = (pml_idx >=PML_LOG_NR_ENTRIES ) ?0 : pml_idx +1 ; -/* -* PML log is written backwards: the CPU first writes the entry 511 -* then the entry 510, and so on. -* -* Read the entries in the same order they were written, to ensure that -* the dirty ring is filled in the same order the CPU wrote them. -*/ - pml_buf =page_address (vmx->pml_pg); - -for (i =PML_HEAD_INDEX ; i >= pml_tail_index; i--) { -u64 gpa; - - gpa = pml_buf[i]; -WARN_ON (gpa & (PAGE_SIZE -1 )); -kvm_vcpu_mark_page_dirty (vcpu, gpa >>PAGE_SHIFT ); - } +kvm_flush_pml_buffer (vcpu, vmx->pml_pg, pml_idx);/* reset PML index */ vmcs_write16 (GUEST_PML_INDEX ,PML_HEAD_INDEX );
arch/x86/kvm/vmx/vmx.h +0 -5
@@ -269,11 +269,6 @@ struct vcpu_vmx {unsigned int ple_window;bool ple_window_dirty; -/* Support for PML */ -#define PML_LOG_NR_ENTRIES 512 -/* PML is written backwards: this is the first entry written by the CPU */ -#define PML_HEAD_INDEX (PML_LOG_NR_ENTRIES-1) -struct page *pml_pg;/* apic deadline value in host tsc */
arch/x86/kvm/x86.c +31 -0
@@ -6417,6 +6417,37 @@ void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot)kvm_vcpu_kick (vcpu); } +void kvm_flush_pml_buffer (struct kvm_vcpu *vcpu,struct page *pml_page,u16 pml_idx) +{ +u16 pml_tail_index; +u64 *pml_buf; +int i; + +/* +* PML index always points to the next available PML buffer entity +* unless PML log has just overflowed. +*/ + pml_tail_index = (pml_idx >=PML_LOG_NR_ENTRIES ) ?0 : pml_idx +1 ; + +/* +* PML log is written backwards: the CPU first writes the entry 511 +* then the entry 510, and so on. +* +* Read the entries in the same order they were written, to ensure that +* the dirty ring is filled in the same order the CPU wrote them. +*/ + pml_buf =page_address (pml_page); + +for (i =PML_HEAD_INDEX ; i >= pml_tail_index; i--) { +u64 gpa; + + gpa = pml_buf[i]; +WARN_ON_ONCE (gpa & (PAGE_SIZE -1 )); +kvm_vcpu_mark_page_dirty (vcpu, gpa >>PAGE_SHIFT ); + } +} +EXPORT_SYMBOL_GPL (kvm_flush_pml_buffer); +int kvm_vm_ioctl_enable_cap (struct kvm *kvm,struct kvm_enable_cap *cap) {
arch/x86/kvm/x86.h +7 -0
@@ -699,4 +699,11 @@ int ____kvm_emulate_hypercall(struct kvm_vcpu *vcpu, int cpl,int kvm_emulate_hypercall (struct kvm_vcpu *vcpu); +/* Support for PML */ +#define PML_LOG_NR_ENTRIES 512 +/* PML is written backwards: this is the first entry written by the CPU */ +#define PML_HEAD_INDEX (PML_LOG_NR_ENTRIES-1) + +void kvm_flush_pml_buffer (struct kvm_vcpu *vcpu,struct page *pml_pg,u16 pml_idx); +#endif
Signature · 1 line
2.43.0
Re: [RFC PATCH 1/4] KVM: x86: Carve out PML flush routine
Quoted 3 lines · Nikunj A Dadhania
Move the PML (Page Modification Logging) buffer flushing logic from VMX-specific code to common x86 KVM code to enable reuse by SVM and avoid code duplication.
Looking at the code change, IIUC the PML code that is moved to x86 common assumes AMD's PML also follows VMX's behaviour:
1) The PML buffer is a 4K page;
2) The hardware records the dirty GPA in backwards to the PML buffer
Could we point this out in the changelog?
[...]
arch/x86/kvm/vmx/vmx.h struct vcpu_vmx { · line 272
Quoted 12 lines
arch/x86/kvm/vmx/vmx.h +0
-5@@ -269,11 +269,6 @@ struct vcpu_vmx {unsigned int ple_window;bool ple_window_dirty; -/* Support for PML */ -#define PML_LOG_NR_ENTRIES 512 -/* PML is written backwards: this is the first entry written by the CPU */ -#define PML_HEAD_INDEX (PML_LOG_NR_ENTRIES-1) -struct page *pml_pg;
Can we share the 'pml_pg' as well?
Re: [RFC PATCH 1/4] KVM: x86: Carve out PML flush routine
Quoted 5 lines · Kai
Quoted 3 lines · Nikunj A Dadhania
Move the PML (Page Modification Logging) buffer flushing logic from VMX-specific code to common x86 KVM code to enable reuse by SVM and avoid code duplication.
Quoted 7 lines
Looking at the code change, IIUC the PML code that is moved to x86 common assumes AMD's PML also follows VMX's behaviour:
1) The PML buffer is a 4K page;
2) The hardware records the dirty GPA in backwards to the PML bufferCould we point this out in the changelog?
Ack, will add in the next revision
Quoted 9 lines
[...]
Quoted 6 lines
arch/x86/kvm/vmx/vmx.h +0
-0@@ -269,11 +269,6 @@ struct vcpu_vmx {unsigned int ple_window;bool ple_window_dirty;
Quoted 8 lines
arch/x86/kvm/vmx/vmx.h struct vcpu_vmx { · line 272
Quoted 6 lines
arch/x86/kvm/vmx/vmx.h +0
-5-/* Support for PML */ -#define PML_LOG_NR_ENTRIES 512 -/* PML is written backwards: this is the first entry written by the CPU */ -#define PML_HEAD_INDEX (PML_LOG_NR_ENTRIES-1) -struct page *pml_pg;Can we share the '
pml_pg' as well?
Sure, Is struct kvm_vcpu_arch the right place?
Regards,
Nikunj
Re: [RFC PATCH 1/4] KVM: x86: Carve out PML flush routine
Quoted 10 lines · Nikunj A. Dadhania
Quoted 8 lines · Kai
Quoted 3 lines · Nikunj A Dadhania
Move the PML (Page Modification Logging) buffer flushing logic from VMX-specific code to common x86 KVM code to enable reuse by SVM and avoid code duplication.
Looking at the code change, IIUC the PML code that is moved to x86 common assumes AMD's PML also follows VMX's behaviour:
Quoted 6 lines
Quoted 4 lines
1) The PML buffer is a 4K page;
2) The hardware records the dirty GPA in backwards to the PML bufferCould we point this out in the changelog?
Ack, will add in the next revision
Thanks. Maybe one more to point out:
3) AMD PML also clears bit 11:0 when recording the GPA.
Quoted 19 lines
Quoted 10 lines
[...]
Quoted 6 lines
arch/x86/kvm/vmx/vmx.h +0
-0@@ -269,11 +269,6 @@ struct vcpu_vmx {unsigned int ple_window;bool ple_window_dirty;Quoted 8 lines
arch/x86/kvm/vmx/vmx.h struct vcpu_vmx { · line 272
Quoted 6 lines
arch/x86/kvm/vmx/vmx.h +0
-5-/* Support for PML */ -#define PML_LOG_NR_ENTRIES 512 -/* PML is written backwards: this is the first entry written by the CPU */ -#define PML_HEAD_INDEX (PML_LOG_NR_ENTRIES-1) -struct page *pml_pg;Can we share the '
pml_pg' as well?
Quoted 2 lines
Sure, Is struct
kvm_vcpu_archthe right place?
Yeah I think so.
Re: [RFC PATCH 1/4] KVM: x86: Carve out PML flush routine
Quoted 11 lines · Kai
Quoted 10 lines · Nikunj A. Dadhania
Quoted 8 lines · Kai
On Mon, 2025-08-25 at 15:20 +0000, Nikunj A Dadhania wrote:
Looking at the code change, IIUC the PML code that is moved to x86 common assumes AMD's PML also follows VMX's behaviour:
1) The PML buffer is a 4K page;
2) The hardware records the dirty GPA in backwards to the PML buffer
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Could we point this out in the changelog?
Ack, will add in the next revision
Thanks. Maybe one more to point out:
3) AMD PML also clears bit 11:0 when recording the GPA.
Sure.
RFC PATCH 2/4 KVM: SEV: Skip SNP-safe allocation when HvInUseWrAllowed is supported
In reply to Nikunj A DadhaniaWhen HvInUseWrAllowed (CPUID 8000001F EAX[30]) is supported, the CPU allows hypervisor writes to in-use pages without RMP violations, making the 2MB alignment workaround unnecessary. Check for this capability to avoid the allocation overhead when it's not needed.
--- arch/x86/kvm/svm/sev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/sev.c +2 -1
@@ -4666,7 +4666,8 @@ struct page *snp_safe_alloc_page_node(int node, gfp_t gfp)unsigned long pfn;struct page *p; -if (!cc_platform_has (CC_ATTR_HOST_SEV_SNP )) +if (!cc_platform_has (CC_ATTR_HOST_SEV_SNP ) || +cpu_feature_enabled (X86_FEATURE_HV_INUSE_WR_ALLOWED ))return alloc_pages_node (node, gfp | __GFP_ZERO,0 );/*
Signature · 1 line
2.43.0
Re: [RFC PATCH 2/4] KVM: SEV: Skip SNP-safe allocation when HvInUseWrAllowed is supported
Quoted 4 lines · Nikunj A Dadhania
When HvInUseWrAllowed (CPUID 8000001F EAX[30]) is supported, the CPU allows hypervisor writes to in-use pages without RMP violations, making the 2MB alignment workaround unnecessary. Check for this capability to avoid the allocation overhead when it's not needed.
Could you add some text to explain why this is related to PML?
Quoted 21 lines
Suggested-by Tom Lendacky <[email protected]>Signed-off-by Nikunj A Dadhania <[email protected]>--- arch/x86/kvm/svm/sev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/x86/kvm/svm/sev.c +2
-1@@ -4666,7 +4666,8 @@ struct page *snp_safe_alloc_page_node(int node, gfp_t gfp)unsigned long pfn;struct page *p; -if (!cc_platform_has (CC_ATTR_HOST_SEV_SNP )) +if (!cc_platform_has (CC_ATTR_HOST_SEV_SNP ) || +cpu_feature_enabled (X86_FEATURE_HV_INUSE_WR_ALLOWED ))return alloc_pages_node (node, gfp | __GFP_ZERO,0 );/*
Re: [RFC PATCH 2/4] KVM: SEV: Skip SNP-safe allocation when HvInUseWrAllowed is supported
Quoted 7 lines · Kai
Quoted 4 lines · Nikunj A Dadhania
When HvInUseWrAllowed (CPUID 8000001F EAX[30]) is supported, the CPU allows hypervisor writes to in-use pages without RMP violations, making the 2MB alignment workaround unnecessary. Check for this capability to avoid the allocation overhead when it's not needed.
Could you add some text to explain why this is related to PML?
PML works fine without this and the change is not linked to PML. This can go as a separate fix.
While working on PML which was using the snp_safe_alloc_page(), Tom had suggested to apply the alignment workaround only on the CPUs without HvInUseWrAllowed.
Quoted 16 lines
Quoted 16 lines
Suggested-by Tom Lendacky <[email protected]>Signed-off-by Nikunj A Dadhania <[email protected]>--- arch/x86/kvm/svm/sev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/x86/kvm/svm/sev.c +0
-0@@ -4666,7 +4666,8 @@ struct page *snp_safe_alloc_page_node(int node, gfp_t gfp)unsigned long pfn;struct page *p;
Quoted 6 lines
arch/x86/kvm/svm/sev.c struct page *snp_safe_alloc_page_node(int node, gfp_t gfp) · line 4673
Quoted 6 lines
arch/x86/kvm/svm/sev.c +2
-1-if (!cc_platform_has (CC_ATTR_HOST_SEV_SNP )) +if (!cc_platform_has (CC_ATTR_HOST_SEV_SNP ) || +cpu_feature_enabled (X86_FEATURE_HV_INUSE_WR_ALLOWED ))return alloc_pages_node (node, gfp | __GFP_ZERO,0 );/*
Regards,
Nikunj
Re: [RFC PATCH 2/4] KVM: SEV: Skip SNP-safe allocation when HvInUseWrAllowed is supported
Quoted 8 lines · Nikunj A. Dadhania
Quoted 6 lines · Kai
Quoted 4 lines · Nikunj A Dadhania
When HvInUseWrAllowed (CPUID 8000001F EAX[30]) is supported, the CPU allows hypervisor writes to in-use pages without RMP violations, making the 2MB alignment workaround unnecessary. Check for this capability to avoid the allocation overhead when it's not needed.
Quoted 4 lines
Quoted 1 line
Could you add some text to explain why this is related to PML?
PML works fine without this and the change is not linked to PML. This can go as a separate fix.
I suppose it's better to send it out as a separate one if PML doesn't need it to work.
RFC PATCH 3/4 x86/cpufeatures: Add Page modification logging
In reply to Nikunj A DadhaniaPage modification logging(PML) is a hardware feature designed to track guest modified memory pages. PML enables the hypervisor to identify which pages in a guest's memory have been changed since the last checkpoint or during live migration.
The PML feature is advertised via CPUID leaf 0x8000000A ECX[4] bit.
--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -227,6 +227,7 @@#define X86_FEATURE_PVUNLOCK ( 8*32+20)/* PV unlock function */ #define X86_FEATURE_VCPUPREEMPT ( 8*32+21)/* PV vcpu_is_preempted function */ #define X86_FEATURE_TDX_GUEST ( 8*32+22)/* "tdx_guest" Intel Trust Domain Extensions Guest */ +#define X86_FEATURE_PML ( 8*32+23)/* AMD Page Modification logging */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */ #define X86_FEATURE_FSGSBASE ( 9*32+ 0)/* "fsgsbase" RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/
arch/x86/kernel/cpu/scattered.c +1 -0
@@ -48,6 +48,7 @@ static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_PROC_FEEDBACK, CPUID_EDX, 11, 0x80000007, 0 }, { X86_FEATURE_AMD_FAST_CPPC, CPUID_EDX, 15, 0x80000007, 0 }, { X86_FEATURE_MBA, CPUID_EBX, 6, 0x80000008, 0 }, + { X86_FEATURE_PML, CPUID_ECX, 4, 0x8000000A, 0 }, { X86_FEATURE_SMBA, CPUID_EBX, 2, 0x80000020, 0 }, { X86_FEATURE_BMEC, CPUID_EBX, 3, 0x80000020, 0 }, { X86_FEATURE_TSA_SQ_NO, CPUID_ECX, 1, 0x80000021, 0 },
Signature · 1 line
2.43.0
Re: [RFC PATCH 3/4] x86/cpufeatures: Add Page modification logging
Quoted 31 lines · Nikunj A Dadhania
Page modification logging(PML) is a hardware feature designed to track guest modified memory pages. PML enables the hypervisor to identify which pages in a guest's memory have been changed since the last checkpoint or during live migration.
The PML feature is advertised via CPUID leaf
0x8000000AECX[4] bit.Signed-off-by Nikunj A Dadhania <[email protected]>--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+)arch/x86/include/asm/cpufeatures.h +1
-0@@ -227,6 +227,7 @@#define X86_FEATURE_PVUNLOCK ( 8*32+20)/* PV unlock function */ #define X86_FEATURE_VCPUPREEMPT ( 8*32+21)/* PV vcpu_is_preempted function */ #define X86_FEATURE_TDX_GUEST ( 8*32+22)/* "tdx_guest" Intel Trust Domain Extensions Guest */ +#define X86_FEATURE_PML ( 8*32+23)/* AMD Page Modification logging */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */ #define X86_FEATURE_FSGSBASE ( 9*32+ 0)/* "fsgsbase" RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/ arch/x86/kernel/cpu/scattered.c +0
-0
arch/x86/kernel/cpu/scattered.c static const struct cpuid_bit cpuid_bits[] = { · line 54
Quoted 7 lines
arch/x86/kernel/cpu/scattered.c +1
-0@@ -48,6 +48,7 @@ static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_PROC_FEEDBACK, CPUID_EDX, 11, 0x80000007, 0 }, { X86_FEATURE_AMD_FAST_CPPC, CPUID_EDX, 15, 0x80000007, 0 }, { X86_FEATURE_MBA, CPUID_EBX, 6, 0x80000008, 0 }, + { X86_FEATURE_PML, CPUID_ECX, 4, 0x8000000A, 0 }, { X86_FEATURE_SMBA, CPUID_EBX, 2, 0x80000020, 0 }, { X86_FEATURE_BMEC, CPUID_EBX, 3, 0x80000020, 0 }, { X86_FEATURE_TSA_SQ_NO, CPUID_ECX, 1, 0x80000021, 0 },
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRFC PATCH 4/4 KVM: SVM: Add Page modification logging support
In reply to Nikunj A DadhaniaCurrently, dirty logging relies on write protecting guest memory and marking dirty GFNs during subsequent write faults. This method works but incurs overhead due to additional write faults for each dirty GFN.
Implement support for the Page Modification Logging (PML) feature, a hardware-assisted method for efficient dirty logging. PML automatically logs dirty GPA[51:12] to a 4K buffer when the CPU sets NPT D-bits. Two new VMCB fields are utilized: PML_ADDR and PML_INDEX. The PML_INDEX is initialized to 511 (8 bytes per GPA entry), and the CPU decreases the PML_INDEX after logging each GPA. When the PML buffer is full, a VMEXIT(PML_FULL) with exit code 0x407 is generated.
PML is enabled by default when supported and can be disabled via the 'pml' module parameter.
--- arch/x86/include/asm/svm.h | 6 +- arch/x86/include/uapi/asm/svm.h | 2 + arch/x86/kvm/svm/svm.c | 99 ++++++++++++++++++++++++++++++++- arch/x86/kvm/svm/svm.h | 4 ++ 4 files changed, 107 insertions(+), 4 deletions(-)
arch/x86/include/asm/svm.h +5 -1
@@ -165,7 +165,10 @@ struct __attribute__ ((__packed__)) vmcb_control_area {u8 reserved_9[22 ];u64 allowed_sev_features;/* Offset 0x138 */ u64 guest_sev_features;/* Offset 0x140 */ -u8 reserved_10[664 ]; +u8 reserved_10[128 ]; +u64 pml_addr;/* Offset 0x1c8 */ +u16 pml_index;/* Offset 0x1d0 */ +u8 reserved_11[526 ];/* * Offset 0x3e0, 32 bytes reserved * for use by hypervisor/software.
@@ -239,6 +242,7 @@ struct __attribute__ ((__packed__)) vmcb_control_area {#define SVM_NESTED_CTL_NP_ENABLE BIT(0)#define SVM_NESTED_CTL_SEV_ENABLE BIT(1)#define SVM_NESTED_CTL_SEV_ES_ENABLE BIT(2) +#define SVM_NESTED_CTL_PML_ENABLE BIT(11)#define SVM_TSC_RATIO_RSVD 0xffffff0000000000ULL
arch/x86/include/uapi/asm/svm.h +2 -0
@@ -101,6 +101,7 @@#define SVM_EXIT_AVIC_INCOMPLETE_IPI 0x401#define SVM_EXIT_AVIC_UNACCELERATED_ACCESS 0x402#define SVM_EXIT_VMGEXIT 0x403 +#define SVM_EXIT_PML_FULL 0x407/* SEV-ES software-defined VMGEXIT events */ #define SVM_VMGEXIT_MMIO_READ 0x80000001
@@ -232,6 +233,7 @@ { SVM_EXIT_AVIC_INCOMPLETE_IPI, "avic_incomplete_ipi" }, \ { SVM_EXIT_AVIC_UNACCELERATED_ACCESS, "avic_unaccelerated_access" }, \ { SVM_EXIT_VMGEXIT, "vmgexit" }, \ + { SVM_EXIT_PML_FULL, "pml_full" }, \ { SVM_VMGEXIT_MMIO_READ, "vmgexit_mmio_read" }, \ { SVM_VMGEXIT_MMIO_WRITE, "vmgexit_mmio_write" }, \ { SVM_VMGEXIT_NMI_COMPLETE, "vmgexit_nmi_complete" }, \
arch/x86/kvm/svm/svm.c +96 -3
178 lines not on this page · raw message
arch/x86/kvm/svm/svm.h +4 -0
@@ -335,6 +335,8 @@ struct vcpu_svm {/* Guest GIF value, used when vGIF is not enabled */ bool guest_gif; + +struct page *pml_page; };struct svm_cpu_data {
@@ -717,6 +719,8 @@ static inline void svm_enable_intercept_for_msr(struct kvm_vcpu *vcpu,svm_set_intercept_for_msr (vcpu, msr, type, true); } +void svm_update_cpu_dirty_logging (struct kvm_vcpu *vcpu); +/* nested.c */ #define NESTED_EXIT_HOST 0/* Exit handled on host level */
Signature · 1 line
2.43.0
Re: [RFC PATCH 4/4] KVM: SVM: Add Page modification logging support
arch/x86/kvm/svm/svm.c static int svm_vcpu_create(struct kvm_vcpu *vcpu) · line 1316
Quoted 5 lines · Nikunj A Dadhania
arch/x86/kvm/svm/svm.c +5
-0+if (pml) { + svm->pml_page =snp_safe_alloc_page (); +if (!svm->pml_page) + goto error_free_vmsa_page; + }
I didn't see this yesterday. Is it mandatory for AMD PML to use snp_safe_alloc_page() to allocate the PML buffer, or we can also use normal page allocation API?
VMX PML just uses alloc_pages(). I was thinking the page allocation/free code could be moved to x86 common as shared code too.
Re: [RFC PATCH 4/4] KVM: SVM: Add Page modification logging support
Quoted 10 lines · Kai
arch/x86/kvm/svm/svm.c static int svm_vcpu_create(struct kvm_vcpu *vcpu) · line 1316
Quoted 5 lines · Nikunj A Dadhania
arch/x86/kvm/svm/svm.c +5
-0+if (pml) { + svm->pml_page =snp_safe_alloc_page (); +if (!svm->pml_page) + goto error_free_vmsa_page; + }I didn't see this yesterday. Is it mandatory for AMD PML to use
snp_safe_alloc_page()to allocate the PML buffer, or we can also use normal page allocation API?
As it is dependent on HvInUseWrAllowed, I need to use snp_safe_alloc_page().
Tom?
Quoted 2 lines
VMX PML just uses
alloc_pages(). I was thinking the page allocation/free code could be moved to x86 common as shared code too.
Got that, because of the above requirement, I was going to share the variable (pml_page) but do the allocation in the vmx/svm code.
Regards,
Nikunj
Re: [RFC PATCH 4/4] KVM: SVM: Add Page modification logging support
Quoted 13 lines · Nikunj A. Dadhania
Quoted 10 lines · Kai
arch/x86/kvm/svm/svm.c static int svm_vcpu_create(struct kvm_vcpu *vcpu) · line 1316
Quoted 5 lines · Nikunj A Dadhania
arch/x86/kvm/svm/svm.c +5
-0+if (pml) { + svm->pml_page =snp_safe_alloc_page (); +if (!svm->pml_page) + goto error_free_vmsa_page; + }I didn't see this yesterday. Is it mandatory for AMD PML to use
snp_safe_alloc_page()to allocate the PML buffer, or we can also use normal page allocation API?
Quoted 1 line
As it is dependent on HvInUseWrAllowed, I need to use
snp_safe_alloc_page().
So the patch 2 is actually a dependent for PML?
Quoted 8 lines
Tom?
Quoted 2 lines
VMX PML just uses
alloc_pages(). I was thinking the page allocation/free code could be moved to x86 common as shared code too.Got that, because of the above requirement, I was going to share the variable (
pml_page) but do the allocation in the vmx/svm code.
If AMD and VMX PML cannot share PML buffer allocation/free code, my desire to share 'pml_pg' is becoming less, but I guess I kinda still think it's better to share the buffer pointer. :-)
Re: [RFC PATCH 4/4] KVM: SVM: Add Page modification logging support
Quoted 14 lines · Kai
Quoted 13 lines · Nikunj A. Dadhania
Quoted 10 lines · Kai
arch/x86/kvm/svm/svm.c static int svm_vcpu_create(struct kvm_vcpu *vcpu) · line 1316
Quoted 5 lines · Nikunj A Dadhania
arch/x86/kvm/svm/svm.c +5
-0+if (pml) { + svm->pml_page =snp_safe_alloc_page (); +if (!svm->pml_page) + goto error_free_vmsa_page; + }I didn't see this yesterday. Is it mandatory for AMD PML to use
snp_safe_alloc_page()to allocate the PML buffer, or we can also use normal page allocation API?
Quoted 3 lines
Quoted 1 line
As it is dependent on HvInUseWrAllowed, I need to use
snp_safe_alloc_page().So the patch 2 is actually a dependent for PML?
Not really, if the patch 2 is not there, the 2MB alignment workaround will be applied to PML page allocation.
Quoted 6 lines
Quoted 6 lines
Tom?
Quoted 2 lines
VMX PML just uses
alloc_pages(). I was thinking the page allocation/free code could be moved to x86 common as shared code too.
Quoted 7 lines
Quoted 3 lines
Got that, because of the above requirement, I was going to share the variable (
pml_page) but do the allocation in the vmx/svm code.If AMD and VMX PML cannot share PML buffer allocation/free code, my desire to share '
pml_pg' is becoming less, but I guess I kinda still think it's better to share the buffer pointer. :-)
Sure, will add in my next revision.
Regards
Nikunj
Re: [RFC PATCH 4/4] KVM: SVM: Add Page modification logging support
Quoted 15 lines · Nikunj A. Dadhania
Quoted 14 lines · Kai
Quoted 13 lines · Nikunj A. Dadhania
Quoted 10 lines · Kai
arch/x86/kvm/svm/svm.c static int svm_vcpu_create(struct kvm_vcpu *vcpu) · line 1316
Quoted 5 lines · Nikunj A Dadhania
arch/x86/kvm/svm/svm.c +5
-0+if (pml) { + svm->pml_page =snp_safe_alloc_page (); +if (!svm->pml_page) + goto error_free_vmsa_page; + }I didn't see this yesterday. Is it mandatory for AMD PML to use
snp_safe_alloc_page()to allocate the PML buffer, or we can also use normal page allocation API?
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
As it is dependent on HvInUseWrAllowed, I need to use
snp_safe_alloc_page().So the patch 2 is actually a dependent for PML?
Not really, if the patch 2 is not there, the 2MB alignment workaround will be applied to PML page allocation.
Sounds they are related, at least.
I don't have intention to judge whether patch 2 should be in this series or not, nor whether snp_safe_alloc_page_node() is the right place to workaround the 2MB alignment for PML buffer.
I just think it's good to see some text explaining why patch 2 is needed for PML if eventually you decide to keep it in this series.
Re: [RFC PATCH 4/4] KVM: SVM: Add Page modification logging support
Quoted 23 lines · Kai
Quoted 15 lines · Nikunj A. Dadhania
Quoted 14 lines · Kai
Quoted 13 lines · Nikunj A. Dadhania
Quoted 10 lines · Kai
arch/x86/kvm/svm/svm.c static int svm_vcpu_create(struct kvm_vcpu *vcpu) · line 1316
Quoted 5 lines · Nikunj A Dadhania
arch/x86/kvm/svm/svm.c +5
-0+if (pml) { + svm->pml_page =snp_safe_alloc_page (); +if (!svm->pml_page) + goto error_free_vmsa_page; + }I didn't see this yesterday. Is it mandatory for AMD PML to use
snp_safe_alloc_page()to allocate the PML buffer, or we can also use normal page allocation API?Quoted 6 lines
Quoted 3 lines
Quoted 1 line
As it is dependent on HvInUseWrAllowed, I need to use
snp_safe_alloc_page().So the patch 2 is actually a dependent for PML?
Not really, if the patch 2 is not there, the 2MB alignment workaround will be applied to PML page allocation.
Quoted 8 lines
Sounds they are related, at least.
I don't have intention to judge whether patch 2 should be in this series or not, nor whether
snp_safe_alloc_page_node()is the right place to workaround the 2MB alignment for PML buffer.I just think it's good to see some text explaining why patch 2 is needed for PML if eventually you decide to keep it in this series.
Btw, there's one big comment in snp_safe_alloc_page_node():
/*
* Allocate an SNP-safe page to workaround the SNP erratum where
* the CPU will incorrectly signal an RMP violation #PF if a
* hugepage (2MB or 1GB) collides with the RMP entry of a
* 2MB-aligned VMCB, VMSA, or AVIC backing page.
* ...
*/
You might want to include the PML buffer to the list too.