i386/kvm: do not zero out segment flags if segment is unusable or not present
PATCH 1/1 i386/kvm: do not zero out segment flags if segment is unusable or not present
This is a fix for the problem [1], where VMCB.CPL was set to 0 and interrupt was taken on userspace stack. The root cause lies in the specific AMD CPU behaviour which manifests itself as unusable segment attributes on SYSRET[2].
Here in this patch flags are not touched even segment is unusable or is not present, therefore CPL (which is stored in DPL field) should not be lost and will be successfully restored on kvm/svm kernel side.
Also current patch should not break desired behavior described in this commit:
4cae9c97967a ("target-i386: kvm: clear unusable segments' flags in migration")
since present bit will be dropped if segment is unusable or is not present.
This is the second part of the whole fix of the corresponding problem [1], first part is related to kvm/svm kernel side and does exactly the same:
segment attributes are not zeroed out.
[1] Message id: CAJrWOzD6Xq==b-zYCDdFLgSRMPM-NkNuTSDFEtX=7MreT45i7Q@mail.gmail.com
[2] Message id: 5d120f358612d73fc909f5bfa47e7bd082db0af0.1429841474.git.luto@kernel.org
--- target/i386/kvm.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
target/i386/kvm.c +8 -12
@@ -1300,18 +1300,14 @@ static void get_seg(SegmentCache *lhs, const struct kvm_segment *rhs) lhs->selector = rhs->selector; lhs->base = rhs->base; lhs->limit = rhs->limit; -if (rhs->unusable) { - lhs->flags =0 ; - }else { - lhs->flags = (rhs->type <<DESC_TYPE_SHIFT ) | - (rhs->present *DESC_P_MASK ) | - (rhs->dpl <<DESC_DPL_SHIFT ) | - (rhs->db <<DESC_B_SHIFT ) | - (rhs->s *DESC_S_MASK ) | - (rhs->l <<DESC_L_SHIFT ) | - (rhs->g *DESC_G_MASK ) | - (rhs->avl *DESC_AVL_MASK ); - } + lhs->flags = (rhs->type <<DESC_TYPE_SHIFT ) | + ((rhs->present && !rhs->unusable) *DESC_P_MASK ) | + (rhs->dpl <<DESC_DPL_SHIFT ) | + (rhs->db <<DESC_B_SHIFT ) | + (rhs->s *DESC_S_MASK ) | + (rhs->l <<DESC_L_SHIFT ) | + (rhs->g *DESC_G_MASK ) | + (rhs->avl *DESC_AVL_MASK ); }static void kvm_getput_reg (__u64 *kvm_reg,target_ulong *qemu_reg,int set)
Signature · 1 line
2.11.0
Paolo Bonzini
AppliedQuoted 27 lines · Roman Pen
This is a fix for the problem [1], where VMCB.CPL was set to 0 and interrupt was taken on userspace stack. The root cause lies in the specific AMD CPU behaviour which manifests itself as unusable segment attributes on SYSRET[2].
Here in this patch flags are not touched even segment is unusable or is not present, therefore CPL (which is stored in DPL field) should not be lost and will be successfully restored on kvm/svm kernel side.
Also current patch should not break desired behavior described in this commit:
4cae9c97967a("target-i386: kvm: clear unusable segments' flags in migration")since present bit will be dropped if segment is unusable or is not present.
This is the second part of the whole fix of the corresponding problem [1], first part is related to kvm/svm kernel side and does exactly the same:
segment attributes are not zeroed out.[1] Message id: CAJrWOzD6Xq==b-zYCDdFLgSRMPM-NkNuTSDFEtX=7MreT45i7Q@mail.gmail.com
[2] Message id: 5d120f358612d73fc909f5bfa47e7bd082db0af0.1429841474.git.luto@kernel.orgSigned-off-by Roman Pen <[email protected]>Signed-off-by Mikhail Sennikovskii <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Rddadim Krčmář <[email protected]>Cc Michael Chapman <[email protected]>
Quoted 3 lines
--- target/i386/kvm.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
Queued, thanks.
Paolo
Quoted 32 lines
target/i386/kvm.c +8
-12@@ -1300,18 +1300,14 @@ static void get_seg(SegmentCache *lhs, const struct kvm_segment *rhs) lhs->selector = rhs->selector; lhs->base = rhs->base; lhs->limit = rhs->limit; -if (rhs->unusable) { - lhs->flags =0 ; - }else { - lhs->flags = (rhs->type <<DESC_TYPE_SHIFT ) | - (rhs->present *DESC_P_MASK ) | - (rhs->dpl <<DESC_DPL_SHIFT ) | - (rhs->db <<DESC_B_SHIFT ) | - (rhs->s *DESC_S_MASK ) | - (rhs->l <<DESC_L_SHIFT ) | - (rhs->g *DESC_G_MASK ) | - (rhs->avl *DESC_AVL_MASK ); - } + lhs->flags = (rhs->type <<DESC_TYPE_SHIFT ) | + ((rhs->present && !rhs->unusable) *DESC_P_MASK ) | + (rhs->dpl <<DESC_DPL_SHIFT ) | + (rhs->db <<DESC_B_SHIFT ) | + (rhs->s *DESC_S_MASK ) | + (rhs->l <<DESC_L_SHIFT ) | + (rhs->g *DESC_G_MASK ) | + (rhs->avl *DESC_AVL_MASK ); }static void kvm_getput_reg (__u64 *kvm_reg,target_ulong *qemu_reg,int set)