2021-10-21 07:08:09

by Chenyi Qiang

[permalink] [raw]
Subject: [PATCH] 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")
Signed-off-by: Chenyi Qiang <[email protected]>
---
arch/x86/kvm/mmu/mmu.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index c6ddb042b281..fe73d7ee5492 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -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);

--
2.17.1


2021-10-21 14:56:32

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH] KVM: MMU: Reset mmu->pkru_mask to avoid stale data

On Thu, Oct 21, 2021, Chenyi Qiang wrote:
> 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")
> Signed-off-by: Chenyi Qiang <[email protected]>
> ---

Reviewed-by: Sean Christopherson <[email protected]>

2021-10-21 15:13:44

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH] KVM: MMU: Reset mmu->pkru_mask to avoid stale data

On 21/10/21 09:10, Chenyi Qiang wrote:
> 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")
> Signed-off-by: Chenyi Qiang <[email protected]>
> ---
> arch/x86/kvm/mmu/mmu.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index c6ddb042b281..fe73d7ee5492 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -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);
>
>

Queued, thanks.

Paolo