# \[PATCH 5.14 124/169\] KVM: MMU: Reset mmu-\>pkru\_mask to avoid stale data

- From: Greg Kroah-Hartman \<gregkh@linuxfoundation.org\>
- Date: 2021-10-25 19:56:52 
- List: stable
- Page: https://ratatoskr.run/stable/2021/10/1553467
- Thread: https://ratatoskr.run/stable/2021/10/1553329/t/2.md

```text
From: Chenyi Qiang <redacted>

commit a3ca5281bb771d8103ea16f0a6a8a5df9a7fb4f3 upstream.

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: 2d344105f57c ("KVM, pkeys: introduce pkru_mask to cache conditions")
Signed-off-by: Chenyi Qiang <redacted>
Message-Id: [ref]
Reviewed-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 arch/x86/kvm/mmu/mmu.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -4465,10 +4465,10 @@ static void update_pkru_bitmask(struct k
 	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);
 


```
