Re: [PATCH] KVM, pkeys: fix guest pkru save wrong on migration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2017/7/12 22:45, Paolo Bonzini wrote:
On 12/07/2017 15:14, Junkang Fu wrote:
From 47e659a592009cda35a0d42fced626f7b3f7d3ca Mon Sep 17 00:00:00 2001
From: tianyi <junkang.fjk@xxxxxxxxxxxxxxx
<mailto:junkang.fjk@xxxxxxxxxxxxxxx>>
Date: Mon, 10 Jul 2017 15:53:07 +0800
Subject: [PATCH] KVM, pkeys: fix guest pkru save wrong on migration

host pkru is restored right after vcpu exit (commit 1be0e61) so host
pkru will be saved
on migration, fix this by using guest_pkru explicitly in fill_save

Signed-off-by: Tianyi <junkang.fjk@xxxxxxxxxxxxxxx
<mailto:junkang.fjk@xxxxxxxxxxxxxxx>>
Signed-off-by: Quan Xu <wutu.xq@xxxxxxxxxxxxxxx
<mailto:wutu.xq@xxxxxxxxxxxxxxx>>
Reviewed-by: Yang Zhang <zy107165@xxxxxxxxxxxxxxx
<mailto:zy107165@xxxxxxxxxxxxxxx>>
---
 arch/x86/kvm/x86.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 02363e3..0351831 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3211,6 +3211,7 @@ static void fill_xsave(u8 *dest, struct kvm_vcpu
*vcpu)
        struct xregs_state *xsave = &vcpu->arch.guest_fpu.state.xsave;
        u64 xstate_bv = xsave->header.xfeatures;
        u64 valid;
+       u32 guest_pkru;

        /*
         * Copy legacy XSAVE area, to avoid complications with CPUID
@@ -3236,7 +3237,11 @@ static void fill_xsave(u8 *dest, struct kvm_vcpu
*vcpu)
                        u32 size, offset, ecx, edx;
                        cpuid_count(XSTATE_CPUID, index,
                                    &size, &offset, &ecx, &edx);
-                       memcpy(dest + offset, src, size);
+                       if (XFEATURE_MASK_PKRU == feature) {

"Yoda conditions" are not used in Linux.  Can be fixed when committing.

+                               guest_pkru = kvm_x86_ops->get_pkru(vcpu);
+                               memcpy(dest + offset, &guest_pkru, 4);
+                       } else
+                               memcpy(dest + offset, src, size);
                }

                valid -= feature;
--
1.8.3.1

Don't you need to do the opposite in load_xsave, including setting
vmx->guest_pkru_valid?

Since we already save right pkru into guest_fpu state, so load_xsave will get the right value. And in vcpu_enter_guest(), KVM will load guest_fpu into hardware which same as guest_pkru_valid is true.


Thanks,

Paolo



--
Yang
Alibaba Cloud Computing



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux