Skip to contentSkip to conversation

I/O port access handling for PVH

DISCUSSION Jan Beulich 3 participants 6 messages Oct 21, 2013 – Dec 2, 2013

lore
Share & tools
lore
#0 lore raw

George,

since you asked on Friday, I though about the situation some more over the weekend.

On PV, the requirement to trap all INs and OUTs is a result from us needing the enforce two levels of restrictions - Xen's and the guest kernel's. I.e. we can't make use of the hardware's access control mechanisms, as we can't put two I/O bit maps in place, and we (obviously) can't run the guest kernel at IOPL 0.

On PVH, otoh, we do have two bitmaps, and hence we could at least allow those port accesses to go without interception that Xen doesn't need to do any internal state keeping on (and of course also only for those the guest is allowed to access). That would make - for PVH - unnecessary a significant part of emulate_privileged_op(): In essence, all you'd need to wire up are guest_io_read() and guest_io_write().

In particular it would then hopefully be safe to do all that without the on-stack emulation stub, as this ought to be necessary only for Dom0, which ought to always have direct access to such "special" I/O ports. With one apparent caveat: SVM sets GENERAL1_INTERCEPT_SMI (for a reason that escapes my right now), and hence control doesn't transfer directly to SMM when an SMI occurs (and consequently registers aren't expected). But I would hope that this intercept isn't really needed, and hence could be dropped at least for PVH guests.

Jan

#1 lore raw
Quoted 9 lines · Jan Beulich

In particular it would then hopefully be safe to do all that without the on-stack emulation stub, as this ought to be necessary only for Dom0, which ought to always have direct access to such "special" I/O ports. With one apparent caveat: SVM sets GENERAL1_INTERCEPT_SMI (for a reason that escapes my right now), and hence control doesn't transfer directly to SMM when an SMI occurs (and consequently registers aren't expected). But I would hope that this intercept isn't really needed, and hence could be dropped at least for PVH guests.

(I realise I'm rather late replying to this - I put it aside and then only found it again today)

On machines where the BIOS has locked down SMM mode, this intercept is in fact ignored by the hardware, and that works fine. So we can drop it for all VMs if it's convenient:

commit a842864f3901078e2a5f4d1cca2f01a72c8d7d13

Author: Tim Deegan <[email protected]>
Date:   Thu Nov 28 10:58:42 2013 +0000

x86/svm: don't intercept SMI.

The SMI intercept is ignored anyway when the BIOS has set the SMMLOCK bit in HWCR (see APM v3.21, volume 2, 15.13.3) and it's convenient for PVH IO processing to have the SMI handled directly with the guest's GPR state (for BIOSes that use SMI as a sort of function call interface).

xen/arch/x86/hvm/svm/vmcb.c +1 -1
index 21292bb..de6fed0 100644
@@ -75,7 +75,7 @@ static int construct_vmcb(struct vcpu *v)
 
     vmcb->_general1_intercepts = 
         GENERAL1_INTERCEPT_INTR        | GENERAL1_INTERCEPT_NMI         |
-        GENERAL1_INTERCEPT_SMI         | GENERAL1_INTERCEPT_INIT        |
+        GENERAL1_INTERCEPT_INIT        |
         GENERAL1_INTERCEPT_CPUID       | GENERAL1_INTERCEPT_INVD        |
         GENERAL1_INTERCEPT_HLT         | GENERAL1_INTERCEPT_INVLPG      | 
         GENERAL1_INTERCEPT_INVLPGA     | GENERAL1_INTERCEPT_IOIO_PROT   |
#2 lore raw
Quoted 21 lines · Tim Deegan
Quoted 9 lines · Jan Beulich

In particular it would then hopefully be safe to do all that without the on-stack emulation stub, as this ought to be necessary only for Dom0, which ought to always have direct access to such "special" I/O ports. With one apparent caveat: SVM sets GENERAL1_INTERCEPT_SMI (for a reason that escapes my right now), and hence control doesn't transfer directly to SMM when an SMI occurs (and consequently registers aren't expected). But I would hope that this intercept isn't really needed, and hence could be dropped at least for PVH guests.

(I realise I'm rather late replying to this - I put it aside and then only found it again today)

On machines where the BIOS has locked down SMM mode, this intercept is in fact ignored by the hardware, and that works fine. So we can drop it for all VMs if it's convenient:

commit a842864f3901078e2a5f4d1cca2f01a72c8d7d13

Author: Tim Deegan <[email protected]>
Date:   Thu Nov 28 10:58:42 2013 +0000
Quoted 8 lines

x86/svm: don't intercept SMI.

The SMI intercept is ignored anyway when the BIOS has set the SMMLOCK bit in HWCR (see APM v3.21, volume 2, 15.13.3) and it's convenient for PVH IO processing to have the SMI handled directly with the guest's GPR state (for BIOSes that use SMI as a sort of function call interface).

I take it you're not targeting this for 4.4?

-George

#3 lore raw
Quoted 24 lines · George Dunlap
Quoted 23 lines · Tim Deegan
Quoted 9 lines · Jan Beulich

In particular it would then hopefully be safe to do all that without the on-stack emulation stub, as this ought to be necessary only for Dom0, which ought to always have direct access to such "special" I/O ports. With one apparent caveat: SVM sets GENERAL1_INTERCEPT_SMI (for a reason that escapes my right now), and hence control doesn't transfer directly to SMM when an SMI occurs (and consequently registers aren't expected). But I would hope that this intercept isn't really needed, and hence could be dropped at least for PVH guests.

(I realise I'm rather late replying to this - I put it aside and then only found it again today)

On machines where the BIOS has locked down SMM mode, this intercept is in fact ignored by the hardware, and that works fine. So we can drop it for all VMs if it's convenient:

commit a842864f3901078e2a5f4d1cca2f01a72c8d7d13

Author: Tim Deegan <[email protected]>
Date:   Thu Nov 28 10:58:42 2013 +0000

x86/svm: don't intercept SMI.

Quoted 8 lines
Quoted 6 lines

The SMI intercept is ignored anyway when the BIOS has set the SMMLOCK bit in HWCR (see APM v3.21, volume 2, 15.13.3) and it's convenient for PVH IO processing to have the SMI handled directly with the guest's GPR state (for BIOSes that use SMI as a sort of function call interface).

I take it you're not targeting this for 4.4?

Indeed not. Sorry, I should have said so.

Cheers,

Tim.

#4 lore raw
Quoted 30 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 22 lines · George Dunlap
Quoted 21 lines · Tim Deegan
Quoted 9 lines · Jan Beulich

In particular it would then hopefully be safe to do all that without the on-stack emulation stub, as this ought to be necessary only for Dom0, which ought to always have direct access to such "special" I/O ports. With one apparent caveat: SVM sets GENERAL1_INTERCEPT_SMI (for a reason that escapes my right now), and hence control doesn't transfer directly to SMM when an SMI occurs (and consequently registers aren't expected). But I would hope that this intercept isn't really needed, and hence could be dropped at least for PVH guests.

(I realise I'm rather late replying to this - I put it aside and then only found it again today)

On machines where the BIOS has locked down SMM mode, this intercept is in fact ignored by the hardware, and that works fine. So we can drop it for all VMs if it's convenient:

commit a842864f3901078e2a5f4d1cca2f01a72c8d7d13

Author: Tim Deegan <[email protected]>
Date:   Thu Nov 28 10:58:42 2013 +0000
Quoted 6 lines
Quoted 6 lines

x86/svm: don't intercept SMI.

The SMI intercept is ignored anyway when the BIOS has set the SMMLOCK bit in HWCR (see APM v3.21, volume 2, 15.13.3) and it's convenient for PVH IO processing to have the SMI handled directly with the guest's GPR state (for BIOSes that use SMI as a sort of function call

Quoted 7 lines

interface).

Quoted 4 lines
Quoted 2 lines

I take it you're not targeting this for 4.4?

Indeed not. Sorry, I should have said so.

And even more so considering that PVH support on SVM is going to remain a todo item for after 4.4 anyway.

Jan

#5 lore raw
Quoted 30 lines · Jan Beulich
Quoted 30 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 28 lines · George Dunlap
Quoted 27 lines · Tim Deegan
Quoted 9 lines · Jan Beulich

In particular it would then hopefully be safe to do all that without the on-stack emulation stub, as this ought to be necessary only for Dom0, which ought to always have direct access to such "special" I/O ports. With one apparent caveat: SVM sets GENERAL1_INTERCEPT_SMI (for a reason that escapes my right now), and hence control doesn't transfer directly to SMM when an SMI occurs (and consequently registers aren't expected). But I would hope that this intercept isn't really needed, and hence could be dropped at least for PVH guests.

(I realise I'm rather late replying to this - I put it aside and then only found it again today)

On machines where the BIOS has locked down SMM mode, this intercept is in fact ignored by the hardware, and that works fine. So we can drop it for all VMs if it's convenient:

commit a842864f3901078e2a5f4d1cca2f01a72c8d7d13

Author: Tim Deegan <[email protected]>
Date:   Thu Nov 28 10:58:42 2013 +0000

x86/svm: don't intercept SMI.

The SMI intercept is ignored anyway when the BIOS has set the SMMLOCK bit in HWCR (see APM v3.21, volume 2, 15.13.3) and it's convenient for PVH IO processing to have the SMI handled directly with the guest's GPR state (for BIOSes that use SMI as a sort of function call

Quoted 7 lines
Quoted 5 lines

interface).

Quoted 3 lines
Quoted 2 lines

I take it you're not targeting this for 4.4?

Indeed not. Sorry, I should have said so.

And even more so considering that PVH support on SVM is going to remain a todo item for after 4.4 anyway.

Yes, I had started to write this, but figured there was no point discussing the merits of accepting it if Tim wasn't asking for it to be accepted. :-)

-George