Skip to contentSkip to conversation

KVM: MMU: Reset mmu->pkru_mask to avoid stale data

PATCH Applied Chenyi Qiang 3 participants 3 messages Oct 21, 2021

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

PATCH 1/1 KVM: MMU: Reset mmu->pkru_mask to avoid stale data

When updating mmu->pkru_mask, the value can only be added but it isn't reset in advance. This will make mmu->pkru_mask keep the stale data. Fix this issue.

Fixes commit 2d344105f57c ("KVM, pkeys: introduce pkru_mask to cache conditions")
---
 arch/x86/kvm/mmu/mmu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kvm/mmu/mmu.c +3 -3
index c6ddb042b281..fe73d7ee5492 100644
@@ -4556,10 +4556,10 @@ static void update_pkru_bitmask(struct kvm_mmu *mmu)
 	unsigned bit;
 	bool wp;
 
-	if (!is_cr4_pke(mmu)) {
-		mmu->pkru_mask = 0;
+	mmu->pkru_mask = 0;
+
+	if (!is_cr4_pke(mmu))
 		return;
-	}
 
 	wp = is_cr0_wp(mmu);
 
Signature · 1 line
2.17.1
maintainer Applied
#2 lore raw
In reply to Chenyi Qiang
Quoted 19 lines · Chenyi Qiang

When updating mmu->pkru_mask, the value can only be added but it isn't reset in advance. This will make mmu->pkru_mask keep the stale data. Fix this issue.

Fixes commit 2d344105f57c ("KVM, pkeys: introduce pkru_mask to cache conditions")
---
  arch/x86/kvm/mmu/mmu.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kvm/mmu/mmu.c +0 -0
index c6ddb042b281..fe73d7ee5492 100644
@@ -4556,10 +4556,10 @@ static void update_pkru_bitmask(struct kvm_mmu *mmu)
  	unsigned bit;
  	bool wp;
 

arch/x86/kvm/mmu/mmu.c static void update_pkru_bitmask(struct kvm_mmu *mmu) · line 4565

Quoted 10 lines
arch/x86/kvm/mmu/mmu.c +3 -3
-	if (!is_cr4_pke(mmu)) {
-		mmu->pkru_mask = 0;
+	mmu->pkru_mask = 0;
+
+	if (!is_cr4_pke(mmu))
  		return;
-	}
 
  	wp = is_cr0_wp(mmu);
 

Queued, thanks.

Paolo