Skip to contentSkip to conversation

KVM: VMX: Always return 0 for clear_flush_young() when using EPT

PATCH Applied Yang, Sheng 2 participants 4 messages Sep 4, 2008 – Sep 11, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: VMX: Always return 0 for clear_flush_young() when using EPT

Hi Avi

It seems something wrong with my git-send-email, and I can't got my post from [email protected], so resend it. Sorry for inconvenient.

Thanks!

Signature · 13 lines
From: Sheng Yang <[email protected]>
Date: Mon, 1 Sep 2008 13:22:09 +0800
Subject: [PATCH] KVM: VMX: Always return 0 for clear_flush_young() when using 
EPT

As well as discard fake accessed bit and dirty bit of EPT.

Signed-off-by: Sheng Yang <[email protected]>
---
 arch/x86/kvm/mmu.c |   15 +++++++++++----
 arch/x86/kvm/vmx.c |    3 +--
 arch/x86/kvm/vmx.h |    2 --
 3 files changed, 12 insertions(+), 8 deletions(-)
arch/x86/kvm/mmu.c +0 -0
index f33c594..e437985 100644
@@ -716,10 +716,17 @@ static int kvm_age_rmapp(struct kvm *kvm, unsigned long 

*rmapp)
int _young;
u64 _spte = *spte; BUG_ON(!(_spte & PT_PRESENT_MASK));
- _young = _spte & PT_ACCESSED_MASK;
- if (_young) {
- young = 1;
- clear_bit(PT_ACCESSED_SHIFT, (unsigned long *)spte);
+
+ /* always return old for EPT */
+ if (!shadow_accessed_mask)
+ _young = 0;
+ else {
+ _young = _spte & PT_ACCESSED_MASK;
+ if (_young) {
+ young = 1;
+ clear_bit(PT_ACCESSED_SHIFT,
+ (unsigned long *)spte);
+ }
}
spte = rmap_next(kvm, rmapp, spte);
}

arch/x86/kvm/vmx.c +1 -2
index 81c121c..d637897 100644
@@ -3557,8 +3557,7 @@ static int __init vmx_init(void)
 		kvm_mmu_set_base_ptes(VMX_EPT_READABLE_MASK |
 			VMX_EPT_WRITABLE_MASK |
 			VMX_EPT_DEFAULT_MT << VMX_EPT_MT_EPTE_SHIFT);
-		kvm_mmu_set_mask_ptes(0ull, VMX_EPT_FAKE_ACCESSED_MASK,
-				VMX_EPT_FAKE_DIRTY_MASK, 0ull,
+		kvm_mmu_set_mask_ptes(0ull, 0ull, 0ull, 0ull,
 				VMX_EPT_EXECUTABLE_MASK);
 		kvm_enable_tdp();
 	} else
arch/x86/kvm/vmx.h +0 -2
index 0c22e5f..41e8c10 100644
@@ -370,8 +370,6 @@ enum vmcs_field {
 #define VMX_EPT_READABLE_MASK			0x1ull
 #define VMX_EPT_WRITABLE_MASK			0x2ull
 #define VMX_EPT_EXECUTABLE_MASK			0x4ull
-#define VMX_EPT_FAKE_ACCESSED_MASK		(1ull << 62)
-#define VMX_EPT_FAKE_DIRTY_MASK			(1ull << 63)
 
 #define VMX_EPT_IDENTITY_PAGETABLE_ADDR		0xfffbc000ul
 

--
1.5.4.5

From 23229946e717294091bf54cee704fb3b1cd4167d Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Mon, 1 Sep 2008 13:22:09 +0800
Subject: [PATCH] KVM: VMX: Always return 0 for clear_flush_young() when using EPT

As well as discard fake accessed bit and dirty bit of EPT.

---
 arch/x86/kvm/mmu.c |   15 +++++++++++----
 arch/x86/kvm/vmx.c |    3 +--
 arch/x86/kvm/vmx.h |    2 --
 3 files changed, 12 insertions(+), 8 deletions(-)
arch/x86/kvm/mmu.c +11 -4
index f33c594..e437985 100644
@@ -716,10 +716,17 @@ static int kvm_age_rmapp(struct kvm *kvm, unsigned long *rmapp)
 		int _young;
 		u64 _spte = *spte;
 		BUG_ON(!(_spte & PT_PRESENT_MASK));
-		_young = _spte & PT_ACCESSED_MASK;
-		if (_young) {
-			young = 1;
-			clear_bit(PT_ACCESSED_SHIFT, (unsigned long *)spte);
+
+		/* always return old for EPT */
+		if (!shadow_accessed_mask)
+			_young = 0;
+		else {
+			_young = _spte & PT_ACCESSED_MASK;
+			if (_young) {
+				young = 1;
+				clear_bit(PT_ACCESSED_SHIFT,
+					  (unsigned long *)spte);
+			}
 		}
 		spte = rmap_next(kvm, rmapp, spte);
 	}
arch/x86/kvm/vmx.c +1 -2
index 81c121c..d637897 100644
@@ -3557,8 +3557,7 @@ static int __init vmx_init(void)
 		kvm_mmu_set_base_ptes(VMX_EPT_READABLE_MASK |
 			VMX_EPT_WRITABLE_MASK |
 			VMX_EPT_DEFAULT_MT << VMX_EPT_MT_EPTE_SHIFT);
-		kvm_mmu_set_mask_ptes(0ull, VMX_EPT_FAKE_ACCESSED_MASK,
-				VMX_EPT_FAKE_DIRTY_MASK, 0ull,
+		kvm_mmu_set_mask_ptes(0ull, 0ull, 0ull, 0ull,
 				VMX_EPT_EXECUTABLE_MASK);
 		kvm_enable_tdp();
 	} else
arch/x86/kvm/vmx.h +0 -2
index 0c22e5f..41e8c10 100644
@@ -370,8 +370,6 @@ enum vmcs_field {
 #define VMX_EPT_READABLE_MASK			0x1ull
 #define VMX_EPT_WRITABLE_MASK			0x2ull
 #define VMX_EPT_EXECUTABLE_MASK			0x4ull
-#define VMX_EPT_FAKE_ACCESSED_MASK		(1ull << 62)
-#define VMX_EPT_FAKE_DIRTY_MASK			(1ull << 63)
 
 #define VMX_EPT_IDENTITY_PAGETABLE_ADDR		0xfffbc000ul
 
Signature · 1 line
1.5.4.5
#1 lore raw
Quoted 4 lines · Sheng

Hi Avi

It seems something wrong with my git-send-email, and I can't got my post from [email protected], so resend it. Sorry for inconvenient.

- _young = _spte & PT_ACCESSED_MASK;
- if (_young) {
- young = 1;
- clear_bit(PT_ACCESSED_SHIFT, (unsigned long *)spte);
+
+ /* always return old for EPT */
+ if (!shadow_accessed_mask)
+ _young = 0;
+ else {
+ _young = _spte & PT_ACCESSED_MASK;
+ if (_young) {
+ young = 1;
+ clear_bit(PT_ACCESSED_SHIFT,
+ (unsigned long *)spte);
+ }

Why not to a

if (!shadow_access_mask)

      return 0;

in the beginning?

I guess returning 'old' is safer than returning 'young'.

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 6 lines · On Sunday 07 September 2008 21:31:54 Avi Kivity wrote:

Why not to a

if (!shadow_access_mask)

       return 0;

in the beginning?

Oops...

Quoted 2 lines

I guess returning 'old' is safer than returning 'young'.

Yeah, me too, though possibly cause thrashing.

How about this one?

--
From: Sheng Yang <[email protected]>
Date: Mon, 8 Sep 2008 15:12:30 +0800
Subject: [PATCH] KVM: VMX: Always return old for clear_flush_young() when using EPT

As well as discard fake accessed bit and dirty bit of EPT.

---
 arch/x86/kvm/mmu.c |    4 ++++
 arch/x86/kvm/vmx.c |    3 +--
 arch/x86/kvm/vmx.h |    2 --
 3 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/kvm/mmu.c +0 -0
index a87a11e..bce3e25 100644
@@ -711,6 +711,10 @@ static int kvm_age_rmapp(struct kvm *kvm, unsigned long 

*rmapp)
u64 *spte;
int young = 0;

+ /* always return old for EPT */
+ if (!shadow_accessed_mask)
+ return 0;
+
spte = rmap_next(kvm, rmapp, NULL);
while (spte) {
int _young;

arch/x86/kvm/vmx.c +1 -2
index 14671f4..2d6c770 100644
@@ -3558,8 +3558,7 @@ static int __init vmx_init(void)
 		kvm_mmu_set_base_ptes(VMX_EPT_READABLE_MASK |
 			VMX_EPT_WRITABLE_MASK |
 			VMX_EPT_DEFAULT_MT << VMX_EPT_MT_EPTE_SHIFT);
-		kvm_mmu_set_mask_ptes(0ull, VMX_EPT_FAKE_ACCESSED_MASK,
-				VMX_EPT_FAKE_DIRTY_MASK, 0ull,
+		kvm_mmu_set_mask_ptes(0ull, 0ull, 0ull, 0ull,
 				VMX_EPT_EXECUTABLE_MASK);
 		kvm_enable_tdp();
 	} else
arch/x86/kvm/vmx.h +0 -2
index 0c22e5f..41e8c10 100644
@@ -370,8 +370,6 @@ enum vmcs_field {
 #define VMX_EPT_READABLE_MASK			0x1ull
 #define VMX_EPT_WRITABLE_MASK			0x2ull
 #define VMX_EPT_EXECUTABLE_MASK			0x4ull
-#define VMX_EPT_FAKE_ACCESSED_MASK		(1ull << 62)
-#define VMX_EPT_FAKE_DIRTY_MASK			(1ull << 63)
 
 #define VMX_EPT_IDENTITY_PAGETABLE_ADDR		0xfffbc000ul
 

--
1.5.6.5

From 250f978cf178fce89b9e5c68007307ccddbb2868 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Mon, 8 Sep 2008 15:12:30 +0800
Subject: [PATCH] KVM: VMX: Always return old for clear_flush_young() when using EPT

As well as discard fake accessed bit and dirty bit of EPT.

---
 arch/x86/kvm/mmu.c |    4 ++++
 arch/x86/kvm/vmx.c |    3 +--
 arch/x86/kvm/vmx.h |    2 --
 3 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/kvm/mmu.c +4 -0
index a87a11e..bce3e25 100644
@@ -711,6 +711,10 @@ static int kvm_age_rmapp(struct kvm *kvm, unsigned long *rmapp)
 	u64 *spte;
 	int young = 0;
 
+	/* always return old for EPT */
+	if (!shadow_accessed_mask)
+		return 0;
+
 	spte = rmap_next(kvm, rmapp, NULL);
 	while (spte) {
 		int _young;
arch/x86/kvm/vmx.c +1 -2
index 14671f4..2d6c770 100644
@@ -3558,8 +3558,7 @@ static int __init vmx_init(void)
 		kvm_mmu_set_base_ptes(VMX_EPT_READABLE_MASK |
 			VMX_EPT_WRITABLE_MASK |
 			VMX_EPT_DEFAULT_MT << VMX_EPT_MT_EPTE_SHIFT);
-		kvm_mmu_set_mask_ptes(0ull, VMX_EPT_FAKE_ACCESSED_MASK,
-				VMX_EPT_FAKE_DIRTY_MASK, 0ull,
+		kvm_mmu_set_mask_ptes(0ull, 0ull, 0ull, 0ull,
 				VMX_EPT_EXECUTABLE_MASK);
 		kvm_enable_tdp();
 	} else
arch/x86/kvm/vmx.h +0 -2
index 0c22e5f..41e8c10 100644
@@ -370,8 +370,6 @@ enum vmcs_field {
 #define VMX_EPT_READABLE_MASK			0x1ull
 #define VMX_EPT_WRITABLE_MASK			0x2ull
 #define VMX_EPT_EXECUTABLE_MASK			0x4ull
-#define VMX_EPT_FAKE_ACCESSED_MASK		(1ull << 62)
-#define VMX_EPT_FAKE_DIRTY_MASK			(1ull << 63)
 
 #define VMX_EPT_IDENTITY_PAGETABLE_ADDR		0xfffbc000ul
 
Signature · 1 line
1.5.6.5
Applied
#3 lore raw
Quoted 8 lines · Sheng

How about this one?

Subject: [PATCH] KVM: VMX: Always return old for clear_flush_young() when using EPT

As well as discard fake accessed bit and dirty bit of EPT.

Applied, thanks.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.