KVM: x86: Do not set access bit on accessed segments
authorNadav Amit <namit@cs.technion.ac.il>
Thu, 25 Dec 2014 00:52:22 +0000 (02:52 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 8 Jan 2015 21:48:07 +0000 (22:48 +0100)
When segment is loaded, the segment access bit is set unconditionally.  In
fact, it should be set conditionally, based on whether the segment had the
accessed bit set before. In addition, it can improve performance.

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/emulate.c

index cc24b74b74541eb34233bf1246eb26612f717390..e36e1fc5bf85174dde0c44402f2fba0f4174dc5f 100644 (file)
@@ -1618,10 +1618,13 @@ static int __load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
 
        if (seg_desc.s) {
                /* mark segment as accessed */
-               seg_desc.type |= 1;
-               ret = write_segment_descriptor(ctxt, selector, &seg_desc);
-               if (ret != X86EMUL_CONTINUE)
-                       return ret;
+               if (!(seg_desc.type & 1)) {
+                       seg_desc.type |= 1;
+                       ret = write_segment_descriptor(ctxt, selector,
+                                                      &seg_desc);
+                       if (ret != X86EMUL_CONTINUE)
+                               return ret;
+               }
        } else if (ctxt->mode == X86EMUL_MODE_PROT64) {
                ret = ctxt->ops->read_std(ctxt, desc_addr+8, &base3,
                                sizeof(base3), &ctxt->exception);