Skip to contentSkip to conversation

x86/hvm: Don't ignore unknown MSRs in the migration stream

PATCH In review Andrew Cooper 4 participants 6 messages Nov 16, 2017 – Nov 27, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: Don't ignore unknown MSRs in the migration stream

Doing so amounts to silent state corruption, and must be avoided.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Julien Grall <[email protected]>

This wants backporting to all stable trees, so should also be considered for inclusion into 4.10 at this point.

---
 xen/arch/x86/hvm/svm/svm.c | 2 +-
 xen/arch/x86/hvm/vmx/vmx.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/svm/svm.c +1 -1
index b9cf423..7b0e688 100644
@@ -450,7 +450,7 @@ static int svm_load_msr(struct vcpu *v, struct hvm_msr *ctxt)
             break;
 
         default:
-            continue;
+            err = -ENXIO;
         }
         if ( err )
             break;
xen/arch/x86/hvm/vmx/vmx.c +2 -1
index b18ccea..fdb65a5 100644
@@ -954,8 +954,9 @@ static int vmx_load_msr(struct vcpu *v, struct hvm_msr *ctxt)
             else
                 err = -ENXIO;
             break;
+
         default:
-            continue;
+            err = -ENXIO;
         }
         if ( err )
             break;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw
In reply to Andrew Cooper
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 16.11.17 at 20:15, <[email protected]> wrote:

Doing so amounts to silent state corruption, and must be avoided.

I think a little more explanation is needed on why the current code is insufficient. Note specifically this

    for ( i = 0; !err && i < ctxt->count; ++i )
    {
        switch ( ctxt->msr[i].index )
        {
        default:
            if ( !ctxt->msr[i]._rsvd )
                err = -ENXIO;
            break;
        }
    }

in hvm_load_cpu_msrs(), intended to give vendor code a first shot, but allowing for vendor independent MSRs to be handled here.

xen/arch/x86/hvm/svm/svm.c static int svm_load_msr(struct vcpu *v, struct hvm_msr *ctxt) · line 454

Quoted 9 lines
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -450,7 +450,7 @@ static int svm_load_msr(struct vcpu *v, struct hvm_msr *ctxt)
             break;
 
         default:
-            continue;
+            err = -ENXIO;
         }

If the change was nevertheless needed, please add break statements here (and in VMX code as well), despite this currently being the last label in the switch() block.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 16 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 16.11.17 at 20:15, <[email protected]> wrote:

Doing so amounts to silent state corruption, and must be avoided.

I think a little more explanation is needed on why the current code is insufficient. Note specifically this

    for ( i = 0; !err && i < ctxt->count; ++i )
    {
        switch ( ctxt->msr[i].index )
        {
        default:
            if ( !ctxt->msr[i]._rsvd )
                err = -ENXIO;
            break;
        }
    }
Quoted 3 lines

in hvm_load_cpu_msrs(), intended to give vendor code a first shot, but allowing for vendor independent MSRs to be handled here.

That is sufficiently subtle and non-obvious that I'm still having a hard time convincing myself that its correct.  Also, this use of _rsvd really should be document.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 20.11.17 at 15:10, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 16.11.17 at 20:15, <[email protected]> wrote:

Doing so amounts to silent state corruption, and must be avoided.

I think a little more explanation is needed on why the current code is insufficient. Note specifically this

    for ( i = 0; !err && i < ctxt->count; ++i )
    {
        switch ( ctxt->msr[i].index )
        {
        default:
            if ( !ctxt->msr[i]._rsvd )
                err = -ENXIO;
            break;
        }
    }
Quoted 7 lines
Quoted 3 lines

in hvm_load_cpu_msrs(), intended to give vendor code a first shot, but allowing for vendor independent MSRs to be handled here.

That is sufficiently subtle and non-obvious that I'm still having a hard time convincing myself that its correct. Also, this use of _rsvd really should be document.

Well, from an abstract pov I agree. The field being defined in the public interface though, I don't see a good place where to document that - its point of declaration certainly isn't the right one in such a case, as the public interface should not document implementation details.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#5 lore raw
In reply to Andrew Cooper
Quoted 15 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Friday, November 17, 2017 3:16 AM

Doing so amounts to silent state corruption, and must be avoided.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Julien Grall <[email protected]>

Quoted 2 lines

This wants backporting to all stable trees, so should also be considered for inclusion into 4.10 at this point.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel