x86: enable port accesses with (almost) full register context
PATCH RESEND 1/1 x86: enable port accesses with (almost) full register context
This helped HP getting certain system management software going (in dom0) that triggers SMIs and depends upon other than port number and data register values being visible to the SMI handler.
Signed-off-by Jan Beulich <[email protected]>
xen/arch/x86/domain_build.c +56 -8
@@ -33,6 +33,11 @@extern unsigned long initial_images_nrpages (void );extern void discard_initial_images (void ); +/* I/O-port Xen-enforced or admin-specified access control. */ +struct rangeset *ioport_caps =NULL ; +/* I/O-port admin-specified non-special access requirements. */ +struct rangeset *ioport_emul =NULL ; +static long dom0_nrpages, dom0_min_nrpages, dom0_max_nrpages =LONG_MAX ;/*
@@ -81,6 +86,12 @@ integer_param("dom0_max_vcpus", opt_dom0static unsigned int opt_dom0_shadow;boolean_param ("dom0_shadow" , opt_dom0_shadow); +static char opt_ioports_noemul[200 ] ="" ; +string_param ("ioports_noemul" , opt_ioports_noemul); + +static char opt_ioports_disable[200 ] ="" ; +string_param ("ioports_disable" , opt_ioports_disable); +static char opt_dom0_ioports_disable[200 ] ="" ;string_param ("dom0_ioports_disable" , opt_dom0_ioports_disable);
@@ -149,10 +160,10 @@ static unsigned long compute_dom0_nr_pareturn dom0_nrpages; } -static void process_dom0_ioports_disable (void ) +static void process_ioports (char *opt) {unsigned long io_from, io_to; -char *t, *u, *s = opt_dom0_ioports_disable; +char *t, *u, *s = opt;if ( *s =='\0' )return ;
@@ -164,7 +175,9 @@ static void process_dom0_ioports_disable { parse_error:printk ("Invalid ioport range <%s> " -"in dom0_ioports_disable, skipping\n" , t); +"in %sioports_%s, skipping\n" , t, + opt == opt_dom0_ioports_disable ?"dom0_" :"" , + opt != opt_ioports_noemul ?"disable" :"noemul" );continue ; }
@@ -178,11 +191,26 @@ static void process_dom0_ioports_disableif ( (*u !='\0' ) || (io_to < io_from) || (io_to >=65536 ) ) goto parse_error; -printk ("Disabling dom0 access to ioport range %04lx-%04lx\n" , - io_from, io_to); +if ( opt != opt_ioports_noemul ) + { +printk ("Disabling %saccess to ioport range %04lx-%04lx\n" , + opt != opt_ioports_disable ?"dom0 " :"" , + io_from, io_to); -if (ioports_deny_access (dom0, io_from, io_to) !=0 ) -BUG (); +if ( opt == opt_ioports_disable + &&ioports_deny_access_all (io_from, io_to) !=0 ) +BUG (); +if (ioports_deny_access (dom0, io_from, io_to) !=0 ) +BUG (); + } +else + { +printk ("Setting non-emulated access for ioport range %04lx-%04lx\n" , + io_from, io_to); + +if (ioports_set_noemul (io_from, io_to) !=0 ) +BUG (); + } } }
@@ -843,6 +871,13 @@ int construct_dom0(struct domain *d, rc =0 ; +/* Command-line I/O ranges. */ + ioport_caps =rangeset_new (NULL , +"global I/O Port access control" , + RANGESETF_prettyprint_hex); +BUG_ON (!ioport_caps); + rc |=ioports_permit_access_all (0 ,0xFFFF ); +/* DOM0 is permitted full I/O capabilities. */ rc |=ioports_permit_access (dom0,0 ,0xFFFF ); rc |=iomem_permit_access (dom0,0UL , ~0UL );
@@ -852,15 +887,20 @@ int construct_dom0(struct domain *d,* Modify I/O port access permissions. */ /* Master Interrupt Controller (PIC). */ + rc |=ioports_deny_access_all (0x20 ,0x21 ); rc |=ioports_deny_access (dom0,0x20 ,0x21 );/* Slave Interrupt Controller (PIC). */ + rc |=ioports_deny_access_all (0xA0 ,0xA1 ); rc |=ioports_deny_access (dom0,0xA0 ,0xA1 );/* Interval Timer (PIT). */ + rc |=ioports_deny_access_all (0x40 ,0x43 ); rc |=ioports_deny_access (dom0,0x40 ,0x43 );/* PIT Channel 2 / PC Speaker Control. */ + rc |=ioports_deny_access_all (0x61 ,0x61 ); rc |=ioports_deny_access (dom0,0x61 ,0x61 );/* Command-line I/O ranges. */ -process_dom0_ioports_disable (); +process_ioports (opt_ioports_disable); +process_ioports (opt_dom0_ioports_disable);/* * Modify I/O memory access permissions.
@@ -879,6 +919,14 @@ int construct_dom0(struct domain *d, rc |=iomem_deny_access (dom0, mfn, mfn); } +/* Command-line I/O ranges requiring full register context access. */ + ioport_emul =rangeset_new (NULL , +"I/O Port emulation control" , + RANGESETF_prettyprint_hex); +BUG_ON (!ioport_emul); + rc |=ioports_set_emul (0 ,0xFFFF ); +process_ioports (opt_ioports_noemul); +BUG_ON (rc !=0 );return 0 ;
xen/arch/x86/sysctl.c +17 -0
@@ -57,6 +57,23 @@ long arch_do_sysctl( }break ; +case XEN_SYSCTL_ioport_emulation: + { +unsigned int fp = sysctl->u.ioport_emulation.first_port; +unsigned int np = sysctl->u.ioport_emulation.nr_ports; + + ret = -EINVAL ; +if ( (fp + np) >65536 ) +break ; + +if ( np ==0 ) + ret =0 ; +else if ( sysctl->u.ioport_emulation.emulate ) + ret =ioports_set_emul (fp, fp + np -1 ); +else + ret =ioports_set_noemul (fp, fp + np -1 ); + } +break ;default : ret = -ENOSYS ;
xen/arch/x86/traps.c +83 -25
200 lines not on this page · raw message
xen/arch/x86/x86_32/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-y += domain_page.o obj-y += entry.o +obj-y += io.o obj-y += mm.o obj-y += seg_fixup.o obj-y += traps.o
xen/arch/x86/x86_32/io.S new file +42 -0
42 lines not on this page · raw message
xen/arch/x86/x86_32/traps.c +24 -0
@@ -13,6 +13,7 @@#include <xen/nmi.h> #include <asm/current.h> #include <asm/flushtlb.h> +#include <asm/io.h> #include <asm/hvm/hvm.h> #include <asm/hvm/support.h>
@@ -242,6 +243,7 @@ fastcall void smp_deferred_nmi(struct cpvoid __init percpu_traps_init (void ) {struct tss_struct *tss = &doublefault_tss; +char *stack_bottom, *stack; asmlinkage int hypercall(void);if (smp_processor_id () !=0 )
@@ -275,6 +277,28 @@ void __init percpu_traps_init(void) (unsigned long)tss, 235, 9);set_task_gate (TRAP_double_fault, __DOUBLEFAULT_TSS_ENTRY<<3 ); + +/* +* Stub for full-context I/O emulation. +*/ + stack_bottom = (char *)get_stack_bottom (); + stack = (char *)((unsigned long )stack_bottom & ~(STACK_SIZE -1 )); +if ( !io_emul_stub_offset ) + io_emul_stub_offset = stack - stack_bottom; +else +BUG_ON (io_emul_stub_offset != stack - stack_bottom); +/* call save_host_restore_guest */ + stack[0 ] =0xe8 ; + *(s32 *)&stack[1 ] = (char *)save_host_restore_guest - &stack[5 ]; + stack +=5 ; +if ( !io_emul_insn_offset ) + io_emul_insn_offset = stack - stack_bottom; +else +BUG_ON (io_emul_insn_offset != stack - stack_bottom); + stack +=3 ;/* operand size prefix, opcode, immediate */ +/* jmp save_guest_restore_host */ + stack[0 ] =0xe9 ; + *(s32 *)&stack[1 ] = (char *)save_guest_restore_host - &stack[5 ]; }void init_int80_direct_trap (struct vcpu *v)
xen/arch/x86/x86_64/Makefile +1 -0
@@ -1,3 +1,4 @@ obj-y += entry.o +obj-y += io.o obj-y += mm.o obj-y += traps.o
xen/arch/x86/x86_64/io.S new file +62 -0
62 lines not on this page · raw message
xen/arch/x86/x86_64/traps.c +24 -0
@@ -14,6 +14,7 @@#include <xen/nmi.h> #include <asm/current.h> #include <asm/flushtlb.h> +#include <asm/io.h> #include <asm/msr.h> #include <asm/page.h> #include <asm/shadow.h>
@@ -331,6 +332,29 @@ void __init percpu_traps_init(void)wrmsr (MSR_STAR ,0 , (FLAT_RING3_CS32 <<16 ) | __HYPERVISOR_CS);wrmsr (MSR_SYSCALL_MASK ,EF_VM |EF_RF |EF_NT |EF_DF |EF_IE |EF_TF ,0U ); + +/* +* Stub for full-context I/O emulation. +*/ + +/* Skip the compatibility-mode entry trampoline. */ + stack +=26 ; +if ( !io_emul_stub_offset ) + io_emul_stub_offset = stack - stack_bottom; +else +BUG_ON (io_emul_stub_offset != stack - stack_bottom); +/* call save_host_restore_guest */ + stack[0 ] =0xe8 ; + *(s32 *)&stack[1 ] = (char *)save_host_restore_guest - &stack[5 ]; + stack +=5 ; +if ( !io_emul_insn_offset ) + io_emul_insn_offset = stack - stack_bottom; +else +BUG_ON (io_emul_insn_offset != stack - stack_bottom); + stack +=3 ;/* operand size prefix, opcode, immediate */ +/* jmp save_guest_restore_host */ + stack[0 ] =0xe9 ; + *(s32 *)&stack[1 ] = (char *)save_guest_restore_host - &stack[5 ]; }static long register_guest_callback (struct callback_register *reg)
xen/include/asm-x86/io.h +6 -0
@@ -50,4 +50,10 @@ __OUT(b,"b",char) __OUT(w,"w",short) __OUT(l,,int) +struct cpu_user_regs ; +void save_host_restore_guest (struct cpu_user_regs *) __attribute__((__regparm__ (1 ))); +unsigned long save_guest_restore_host (unsigned long ) __attribute__((__regparm__ (1 ))); + +extern long io_emul_stub_offset, io_emul_insn_offset; +#endif
xen/include/asm-x86/iocap.h +16 -0
@@ -7,6 +7,15 @@#ifndef __X86_IOCAP_H__#define __X86_IOCAP_H__ +extern struct rangeset *ioport_caps, *ioport_emul; + +#define ioports_permit_access_all (s, e) \ + rangeset_add_range(ioport_caps, s, e) +#define ioports_deny_access_all (s, e) \ + rangeset_remove_range(ioport_caps, s, e) +#define ioports_any_access_permitted (s, e) \ + rangeset_contains_range(ioport_caps, s, e) +#define ioports_permit_access (d, s, e) \ rangeset_add_range((d)->arch.ioport_caps, s, e)#define ioports_deny_access (d, s, e) \
@@ -14,6 +23,13 @@#define ioports_access_permitted (d, s, e) \ rangeset_contains_range((d)->arch.ioport_caps, s, e) +#define ioports_set_emul (s, e) \ + rangeset_add_range(ioport_emul, s, e) +#define ioports_set_noemul (s, e) \ + rangeset_remove_range(ioport_emul, s, e) +#define ioports_emul (s, e) \ + rangeset_contains_range(ioport_emul, s, e) +#define cache_flush_permitted (d) \ (!rangeset_is_empty((d)->iomem_caps))
xen/include/public/sysctl.h +10 -0
@@ -140,6 +140,15 @@ struct xen_sysctl_getdomaininfolist {typedef struct xen_sysctl_getdomaininfolist xen_sysctl_getdomaininfolist_t ;DEFINE_XEN_GUEST_HANDLE (xen_sysctl_getdomaininfolist_t); +#define XEN_SYSCTL_ioport_emulation 7 +struct xen_sysctl_ioport_emulation { +uint32_t first_port;/* first port int range */ +uint32_t nr_ports;/* size of port range */ +uint8_t emulate;/* emulate access to range? */ +}; +typedef struct xen_sysctl_ioport_emulation xen_sysctl_ioport_emulation_t ; +DEFINE_XEN_GUEST_HANDLE (xen_sysctl_ioport_emulation_t); +struct xen_sysctl {uint32_t cmd;uint32_t interface_version;/* XEN_SYSCTL_INTERFACE_VERSION */
@@ -150,6 +159,7 @@ struct xen_sysctl {struct xen_sysctl_sched_id sched_id;struct xen_sysctl_perfc_op perfc_op;struct xen_sysctl_getdomaininfolist getdomaininfolist; +struct xen_sysctl_ioport_emulation ioport_emulation;uint8_t pad[128 ]; } u; };