From: "Jan Beulich" Subject: [PATCH] x86: adjust PV I/O emulation functions' types Date: Tue, 09 Jun 2015 09:58:31 +0100 Message-ID: <5576C6D7020000780008276E@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part467268A7.1__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Z2FMi-0003a3-IJ for xen-devel@lists.xenproject.org; Tue, 09 Jun 2015 08:58:36 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Andrew Cooper , Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part467268A7.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline admin_io_okay(), guest_io_read(), and guest_io_write() all don't need their current "regs" parameter at all, and they don't use the vCPU passed to them for other than obtaining its domain. Drop the former and replace the latter by a struct domain pointer. pci_cfg_okay() returns a boolean type, and its "write" parameter is of boolean kind too. All of them get called for the current vCPU (and hence current domain) only, so name the domain parameters accordingly except in the admin_io_okay() case, which a subsequent patch will use for simplifying setup_io_bitmap(). Latch current->domain into a local variable in emulate_privileged_op(). Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -599,13 +599,12 @@ static int hvm_access_cf8( static int handle_pvh_io( int dir, uint32_t port, uint32_t bytes, uint32_t *val) { - struct vcpu *curr =3D current; - struct cpu_user_regs *regs =3D guest_cpu_user_regs(); + struct domain *currd =3D current->domain; =20 if ( dir =3D=3D IOREQ_WRITE ) - guest_io_write(port, bytes, *val, curr, regs); + guest_io_write(port, bytes, *val, currd); else - *val =3D guest_io_read(port, bytes, curr, regs); + *val =3D guest_io_read(port, bytes, currd); =20 return X86EMUL_OKAY; } --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1754,9 +1754,8 @@ static int guest_io_okay( } =20 /* Has the administrator granted sufficient permission for this I/O = access? */ -static int admin_io_okay( - unsigned int port, unsigned int bytes, - struct vcpu *v, struct cpu_user_regs *regs) +static bool_t admin_io_okay(unsigned int port, unsigned int bytes, + const struct domain *d) { /* * Port 0xcf8 (CONFIG_ADDRESS) is only visible for DWORD accesses. @@ -1769,17 +1768,18 @@ static int admin_io_okay( if ( ((port & ~1) =3D=3D RTC_PORT(0)) ) return 0; =20 - return ioports_access_permitted(v->domain, port, port + bytes - 1); + return ioports_access_permitted(d, port, port + bytes - 1); } =20 -static int pci_cfg_ok(struct domain *d, int write, int size) +static bool_t pci_cfg_ok(struct domain *currd, bool_t write, unsigned int = size) { uint32_t machine_bdf; - uint16_t start, end; - if (!is_hardware_domain(d)) + unsigned int start; + + if ( !is_hardware_domain(currd) ) return 0; =20 - machine_bdf =3D (d->arch.pci_cf8 >> 8) & 0xFFFF; + machine_bdf =3D (currd->arch.pci_cf8 >> 8) & 0xFFFF; if ( write ) { const unsigned long *ro_map =3D pci_get_ro_map(0); @@ -1787,9 +1787,9 @@ static int pci_cfg_ok(struct domain *d,=20 if ( ro_map && test_bit(machine_bdf, ro_map) ) return 0; } - start =3D d->arch.pci_cf8 & 0xFF; + start =3D currd->arch.pci_cf8 & 0xFF; /* AMD extended configuration space access? */ - if ( (d->arch.pci_cf8 & 0x0F000000) && + if ( (currd->arch.pci_cf8 & 0x0F000000) && boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD && boot_cpu_data.x86 >=3D 0x10 && boot_cpu_data.x86 <=3D 0x17 ) { @@ -1798,22 +1798,20 @@ static int pci_cfg_ok(struct domain *d,=20 if ( rdmsr_safe(MSR_AMD64_NB_CFG, msr_val) ) return 0; if ( msr_val & (1ULL << AMD64_NB_CFG_CF8_EXT_ENABLE_BIT) ) - start |=3D (d->arch.pci_cf8 >> 16) & 0xF00; + start |=3D (currd->arch.pci_cf8 >> 16) & 0xF00; } - end =3D start + size - 1; - if (xsm_pci_config_permission(XSM_HOOK, d, machine_bdf, start, end, = write)) - return 0; - return 1; + + return !xsm_pci_config_permission(XSM_HOOK, currd, machine_bdf, + start, start + size - 1, write); } =20 -uint32_t guest_io_read( - unsigned int port, unsigned int bytes, - struct vcpu *v, struct cpu_user_regs *regs) +uint32_t guest_io_read(unsigned int port, unsigned int bytes, + struct domain *currd) { uint32_t data =3D 0; unsigned int shift =3D 0; =20 - if ( admin_io_okay(port, bytes, v, regs) ) + if ( admin_io_okay(port, bytes, currd) ) { switch ( bytes ) { @@ -1834,31 +1832,30 @@ uint32_t guest_io_read( } else if ( (port =3D=3D RTC_PORT(0)) ) { - sub_data =3D v->domain->arch.cmos_idx; + sub_data =3D currd->arch.cmos_idx; } else if ( (port =3D=3D RTC_PORT(1)) && - ioports_access_permitted(v->domain, RTC_PORT(0), - RTC_PORT(1)) ) + ioports_access_permitted(currd, RTC_PORT(0), RTC_PORT(1)= ) ) { unsigned long flags; =20 spin_lock_irqsave(&rtc_lock, flags); - outb(v->domain->arch.cmos_idx & 0x7f, RTC_PORT(0)); + outb(currd->arch.cmos_idx & 0x7f, RTC_PORT(0)); sub_data =3D inb(RTC_PORT(1)); spin_unlock_irqrestore(&rtc_lock, flags); } else if ( (port =3D=3D 0xcf8) && (bytes =3D=3D 4) ) { size =3D 4; - sub_data =3D v->domain->arch.pci_cf8; + sub_data =3D currd->arch.pci_cf8; } else if ( (port & 0xfffc) =3D=3D 0xcfc ) { size =3D min(bytes, 4 - (port & 3)); if ( size =3D=3D 3 ) size =3D 2; - if ( pci_cfg_ok(v->domain, 0, size) ) - sub_data =3D pci_conf_read(v->domain->arch.pci_cf8, port = & 3, size); + if ( pci_cfg_ok(currd, 0, size) ) + sub_data =3D pci_conf_read(currd->arch.pci_cf8, port & 3, = size); } =20 if ( size =3D=3D 4 ) @@ -1873,11 +1870,10 @@ uint32_t guest_io_read( return data; } =20 -void guest_io_write( - unsigned int port, unsigned int bytes, uint32_t data, - struct vcpu *v, struct cpu_user_regs *regs) +void guest_io_write(unsigned int port, unsigned int bytes, uint32_t data, + struct domain *currd) { - if ( admin_io_okay(port, bytes, v, regs) ) + if ( admin_io_okay(port, bytes, currd) ) { switch ( bytes ) { case 1: @@ -1905,33 +1901,32 @@ void guest_io_write( } else if ( (port =3D=3D RTC_PORT(0)) ) { - v->domain->arch.cmos_idx =3D data; + currd->arch.cmos_idx =3D data; } else if ( (port =3D=3D RTC_PORT(1)) && - ioports_access_permitted(v->domain, RTC_PORT(0), - RTC_PORT(1)) ) + ioports_access_permitted(currd, RTC_PORT(0), RTC_PORT(1)= ) ) { unsigned long flags; =20 if ( pv_rtc_handler ) - pv_rtc_handler(v->domain->arch.cmos_idx & 0x7f, data); + pv_rtc_handler(currd->arch.cmos_idx & 0x7f, data); spin_lock_irqsave(&rtc_lock, flags); - outb(v->domain->arch.cmos_idx & 0x7f, RTC_PORT(0)); + outb(currd->arch.cmos_idx & 0x7f, RTC_PORT(0)); outb(data, RTC_PORT(1)); spin_unlock_irqrestore(&rtc_lock, flags); } else if ( (port =3D=3D 0xcf8) && (bytes =3D=3D 4) ) { size =3D 4; - v->domain->arch.pci_cf8 =3D data; + currd->arch.pci_cf8 =3D data; } else if ( (port & 0xfffc) =3D=3D 0xcfc ) { size =3D min(bytes, 4 - (port & 3)); if ( size =3D=3D 3 ) size =3D 2; - if ( pci_cfg_ok(v->domain, 1, size) ) - pci_conf_write(v->domain->arch.pci_cf8, port & 3, size, = data); + if ( pci_cfg_ok(currd, 1, size) ) + pci_conf_write(currd->arch.pci_cf8, port & 3, size, = data); } =20 if ( size =3D=3D 4 ) @@ -1989,6 +1984,7 @@ static int is_cpufreq_controller(struct=20 static int emulate_privileged_op(struct cpu_user_regs *regs) { struct vcpu *v =3D current; + struct domain *currd =3D v->domain; unsigned long *reg, eip =3D regs->eip; u8 opcode, modrm_reg =3D 0, modrm_rm =3D 0, rep_prefix =3D 0, lock = =3D 0, rex =3D 0; enum { lm_seg_none, lm_seg_fs, lm_seg_gs } lm_ovr =3D lm_seg_none; @@ -2145,7 +2141,7 @@ static int emulate_privileged_op(struct=20 (rd_ad(edi) > (data_limit - (op_bytes - 1))) || !guest_io_okay(port, op_bytes, v, regs) ) goto fail; - data =3D guest_io_read(port, op_bytes, v, regs); + data =3D guest_io_read(port, op_bytes, currd); if ( (rc =3D copy_to_user((void *)data_base + rd_ad(edi), &data, op_bytes)) !=3D 0 ) { @@ -2171,7 +2167,7 @@ static int emulate_privileged_op(struct=20 + op_bytes - rc, 0); return EXCRET_fault_fixed; } - guest_io_write(port, op_bytes, data, v, regs); + guest_io_write(port, op_bytes, data, currd); wr_ad(esi, regs->esi + (int)((regs->eflags & X86_EFLAGS_DF) ? -op_bytes : op_bytes)); break; @@ -2232,7 +2228,7 @@ static int emulate_privileged_op(struct=20 exec_in: if ( !guest_io_okay(port, op_bytes, v, regs) ) goto fail; - if ( admin_io_okay(port, op_bytes, v, regs) ) + if ( admin_io_okay(port, op_bytes, currd) ) { mark_regs_dirty(regs); io_emul(regs); =20 @@ -2243,7 +2239,7 @@ static int emulate_privileged_op(struct=20 regs->eax =3D 0; else regs->eax &=3D ~((1 << (op_bytes * 8)) - 1); - regs->eax |=3D guest_io_read(port, op_bytes, v, regs); + regs->eax |=3D guest_io_read(port, op_bytes, currd); } bpmatch =3D check_guest_io_breakpoint(v, port, op_bytes); goto done; @@ -2262,7 +2258,7 @@ static int emulate_privileged_op(struct=20 exec_out: if ( !guest_io_okay(port, op_bytes, v, regs) ) goto fail; - if ( admin_io_okay(port, op_bytes, v, regs) ) + if ( admin_io_okay(port, op_bytes, currd) ) { mark_regs_dirty(regs); io_emul(regs); =20 @@ -2271,7 +2267,7 @@ static int emulate_privileged_op(struct=20 } else { - guest_io_write(port, op_bytes, regs->eax, v, regs); + guest_io_write(port, op_bytes, regs->eax, currd); } bpmatch =3D check_guest_io_breakpoint(v, port, op_bytes); goto done; @@ -2353,7 +2349,7 @@ static int emulate_privileged_op(struct=20 =20 case 0x09: /* WBINVD */ /* Ignore the instruction if unprivileged. */ - if ( !cache_flush_permitted(v->domain) ) + if ( !cache_flush_permitted(currd) ) /* Non-physdev domain attempted WBINVD; ignore for now since newer linux uses this in some start-of-day timing loops */ ; @@ -2386,8 +2382,7 @@ static int emulate_privileged_op(struct=20 if ( !is_pv_32on64_vcpu(v) ) { mfn =3D pagetable_get_pfn(v->arch.guest_table); - *reg =3D xen_pfn_to_cr3(mfn_to_gmfn( - v->domain, mfn)); + *reg =3D xen_pfn_to_cr3(mfn_to_gmfn(currd, mfn)); } else { @@ -2396,8 +2391,7 @@ static int emulate_privileged_op(struct=20 =20 mfn =3D l4e_get_pfn(*pl4e); unmap_domain_page(pl4e); - *reg =3D compat_pfn_to_cr3(mfn_to_gmfn( - v->domain, mfn)); + *reg =3D compat_pfn_to_cr3(mfn_to_gmfn(currd, mfn)); } /* PTs should not be shared */ BUG_ON(page_get_owner(mfn_to_page(mfn)) =3D=3D dom_cow); @@ -2457,7 +2451,7 @@ static int emulate_privileged_op(struct=20 =20 gfn =3D !is_pv_32on64_vcpu(v) ? xen_cr3_to_pfn(*reg) : compat_cr3_to_pfn(*reg); - page =3D get_page_from_gfn(v->domain, gfn, NULL, P2M_ALLOC); + page =3D get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC); if ( page ) { rc =3D new_guest_cr3(page_to_mfn(page)); @@ -2541,7 +2535,7 @@ static int emulate_privileged_op(struct=20 case MSR_K8_HWCR: if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD ) goto fail; - if ( !is_cpufreq_controller(v->domain) ) + if ( !is_cpufreq_controller(currd) ) break; if ( wrmsr_safe(regs->ecx, msr_content) !=3D 0 ) goto fail; @@ -2550,7 +2544,7 @@ static int emulate_privileged_op(struct=20 if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD || boot_cpu_data.x86 < 0x10 || boot_cpu_data.x86 > 0x17 ) goto fail; - if ( !is_hardware_domain(v->domain) || !is_pinned_vcpu(v) ) + if ( !is_hardware_domain(currd) || !is_pinned_vcpu(v) ) break; if ( (rdmsr_safe(MSR_AMD64_NB_CFG, val) !=3D 0) || (eax !=3D (uint32_t)val) || @@ -2563,7 +2557,7 @@ static int emulate_privileged_op(struct=20 if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD || boot_cpu_data.x86 < 0x10 || boot_cpu_data.x86 > 0x17 ) goto fail; - if ( !is_hardware_domain(v->domain) || !is_pinned_vcpu(v) ) + if ( !is_hardware_domain(currd) || !is_pinned_vcpu(v) ) break; if ( (rdmsr_safe(MSR_FAM10H_MMIO_CONF_BASE, val) !=3D 0) ) goto fail; @@ -2583,7 +2577,7 @@ static int emulate_privileged_op(struct=20 case MSR_IA32_UCODE_REV: if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL ) goto fail; - if ( !is_hardware_domain(v->domain) || !is_pinned_vcpu(v) ) + if ( !is_hardware_domain(currd) || !is_pinned_vcpu(v) ) break; if ( rdmsr_safe(regs->ecx, val) ) goto fail; @@ -2602,7 +2596,7 @@ static int emulate_privileged_op(struct=20 if (( boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL ) && ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD ) ) goto fail; - if ( !is_cpufreq_controller(v->domain) ) + if ( !is_cpufreq_controller(currd) ) break; if ( wrmsr_safe(regs->ecx, msr_content ) !=3D 0 ) goto fail; @@ -2610,7 +2604,7 @@ static int emulate_privileged_op(struct=20 case MSR_IA32_PERF_CTL: if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL ) goto fail; - if ( !is_cpufreq_controller(v->domain) ) + if ( !is_cpufreq_controller(currd) ) break; if ( wrmsr_safe(regs->ecx, msr_content) !=3D 0 ) goto fail; @@ -2619,7 +2613,7 @@ static int emulate_privileged_op(struct=20 case MSR_IA32_ENERGY_PERF_BIAS: if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL ) goto fail; - if ( !is_hardware_domain(v->domain) || !is_pinned_vcpu(v) ) + if ( !is_hardware_domain(currd) || !is_pinned_vcpu(v) ) break; if ( wrmsr_safe(regs->ecx, msr_content) !=3D 0 ) goto fail; @@ -2665,7 +2659,7 @@ static int emulate_privileged_op(struct=20 if ( (v->arch.pv_vcpu.ctrlreg[4] & X86_CR4_TSD) && !guest_kernel_mode(v, regs) ) goto fail; - if ( v->domain->arch.vtsc ) + if ( currd->arch.vtsc ) pv_soft_rdtsc(v, regs, 0); else { @@ -2708,7 +2702,7 @@ static int emulate_privileged_op(struct=20 case MSR_K8_PSTATE7: if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD ) goto fail; - if ( !is_cpufreq_controller(v->domain) ) + if ( !is_cpufreq_controller(currd) ) { regs->eax =3D regs->edx =3D 0; break; --- a/xen/include/asm-x86/traps.h +++ b/xen/include/asm-x86/traps.h @@ -48,8 +48,8 @@ extern int send_guest_trap(struct domain unsigned int trap_nr); =20 uint32_t guest_io_read(unsigned int port, unsigned int bytes, - struct vcpu *, struct cpu_user_regs *); + struct domain *); void guest_io_write(unsigned int port, unsigned int bytes, uint32_t data, - struct vcpu *, struct cpu_user_regs *); + struct domain *); =20 #endif /* ASM_TRAP_H */ --=__Part467268A7.1__= Content-Type: text/plain; name="x86-guest-io-params.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-guest-io-params.patch" x86: adjust PV I/O emulation functions' types=0A=0Aadmin_io_okay(), = guest_io_read(), and guest_io_write() all don't need=0Atheir current = "regs" parameter at all, and they don't use the vCPU=0Apassed to them for = other than obtaining its domain. Drop the former and=0Areplace the latter = by a struct domain pointer.=0A=0Apci_cfg_okay() returns a boolean type, = and its "write" parameter is of=0Aboolean kind too.=0A=0AAll of them get = called for the current vCPU (and hence current domain)=0Aonly, so name the = domain parameters accordingly except in the=0Aadmin_io_okay() case, which = a subsequent patch will use for simplifying=0Asetup_io_bitmap().=0A=0ALatch= current->domain into a local variable in emulate_privileged_op().=0A=0ASig= ned-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/hvm/hvm= .c=0A+++ b/xen/arch/x86/hvm/hvm.c=0A@@ -599,13 +599,12 @@ static int = hvm_access_cf8(=0A static int handle_pvh_io(=0A int dir, uint32_t = port, uint32_t bytes, uint32_t *val)=0A {=0A- struct vcpu *curr =3D = current;=0A- struct cpu_user_regs *regs =3D guest_cpu_user_regs();=0A+ = struct domain *currd =3D current->domain;=0A =0A if ( dir =3D=3D = IOREQ_WRITE )=0A- guest_io_write(port, bytes, *val, curr, regs);=0A+= guest_io_write(port, bytes, *val, currd);=0A else=0A- = *val =3D guest_io_read(port, bytes, curr, regs);=0A+ *val =3D = guest_io_read(port, bytes, currd);=0A =0A return X86EMUL_OKAY;=0A = }=0A--- a/xen/arch/x86/traps.c=0A+++ b/xen/arch/x86/traps.c=0A@@ -1754,9 = +1754,8 @@ static int guest_io_okay(=0A }=0A =0A /* Has the administrator = granted sufficient permission for this I/O access? */=0A-static int = admin_io_okay(=0A- unsigned int port, unsigned int bytes,=0A- struct = vcpu *v, struct cpu_user_regs *regs)=0A+static bool_t admin_io_okay(unsigne= d int port, unsigned int bytes,=0A+ const = struct domain *d)=0A {=0A /*=0A * Port 0xcf8 (CONFIG_ADDRESS) is = only visible for DWORD accesses.=0A@@ -1769,17 +1768,18 @@ static int = admin_io_okay(=0A if ( ((port & ~1) =3D=3D RTC_PORT(0)) )=0A = return 0;=0A =0A- return ioports_access_permitted(v->domain, port, port = + bytes - 1);=0A+ return ioports_access_permitted(d, port, port + bytes = - 1);=0A }=0A =0A-static int pci_cfg_ok(struct domain *d, int write, int = size)=0A+static bool_t pci_cfg_ok(struct domain *currd, bool_t write, = unsigned int size)=0A {=0A uint32_t machine_bdf;=0A- uint16_t = start, end;=0A- if (!is_hardware_domain(d))=0A+ unsigned int = start;=0A+=0A+ if ( !is_hardware_domain(currd) )=0A return = 0;=0A =0A- machine_bdf =3D (d->arch.pci_cf8 >> 8) & 0xFFFF;=0A+ = machine_bdf =3D (currd->arch.pci_cf8 >> 8) & 0xFFFF;=0A if ( write = )=0A {=0A const unsigned long *ro_map =3D pci_get_ro_map(0);=0A= @@ -1787,9 +1787,9 @@ static int pci_cfg_ok(struct domain *d, =0A = if ( ro_map && test_bit(machine_bdf, ro_map) )=0A return 0;=0A = }=0A- start =3D d->arch.pci_cf8 & 0xFF;=0A+ start =3D currd->arch= .pci_cf8 & 0xFF;=0A /* AMD extended configuration space access? */=0A- = if ( (d->arch.pci_cf8 & 0x0F000000) &&=0A+ if ( (currd->arch.pci_cf8 = & 0x0F000000) &&=0A boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD= &&=0A boot_cpu_data.x86 >=3D 0x10 && boot_cpu_data.x86 <=3D 0x17 = )=0A {=0A@@ -1798,22 +1798,20 @@ static int pci_cfg_ok(struct domain = *d, =0A if ( rdmsr_safe(MSR_AMD64_NB_CFG, msr_val) )=0A = return 0;=0A if ( msr_val & (1ULL << AMD64_NB_CFG_CF8_EXT_ENABLE_B= IT) )=0A- start |=3D (d->arch.pci_cf8 >> 16) & 0xF00;=0A+ = start |=3D (currd->arch.pci_cf8 >> 16) & 0xF00;=0A }=0A- end = =3D start + size - 1;=0A- if (xsm_pci_config_permission(XSM_HOOK, d, = machine_bdf, start, end, write))=0A- return 0;=0A- return = 1;=0A+=0A+ return !xsm_pci_config_permission(XSM_HOOK, currd, machine_bd= f,=0A+ start, start + size - 1, = write);=0A }=0A =0A-uint32_t guest_io_read(=0A- unsigned int port, = unsigned int bytes,=0A- struct vcpu *v, struct cpu_user_regs *regs)=0A+u= int32_t guest_io_read(unsigned int port, unsigned int bytes,=0A+ = struct domain *currd)=0A {=0A uint32_t data =3D 0;=0A = unsigned int shift =3D 0;=0A =0A- if ( admin_io_okay(port, bytes, v, = regs) )=0A+ if ( admin_io_okay(port, bytes, currd) )=0A {=0A = switch ( bytes )=0A {=0A@@ -1834,31 +1832,30 @@ uint32_t = guest_io_read(=0A }=0A else if ( (port =3D=3D RTC_PORT(0)) = )=0A {=0A- sub_data =3D v->domain->arch.cmos_idx;=0A+ = sub_data =3D currd->arch.cmos_idx;=0A }=0A else = if ( (port =3D=3D RTC_PORT(1)) &&=0A- ioports_access_permi= tted(v->domain, RTC_PORT(0),=0A- = RTC_PORT(1)) )=0A+ ioports_access_permitted(currd, = RTC_PORT(0), RTC_PORT(1)) )=0A {=0A unsigned long = flags;=0A =0A spin_lock_irqsave(&rtc_lock, flags);=0A- = outb(v->domain->arch.cmos_idx & 0x7f, RTC_PORT(0));=0A+ = outb(currd->arch.cmos_idx & 0x7f, RTC_PORT(0));=0A sub_data = =3D inb(RTC_PORT(1));=0A spin_unlock_irqrestore(&rtc_lock, = flags);=0A }=0A else if ( (port =3D=3D 0xcf8) && (bytes = =3D=3D 4) )=0A {=0A size =3D 4;=0A- = sub_data =3D v->domain->arch.pci_cf8;=0A+ sub_data =3D = currd->arch.pci_cf8;=0A }=0A else if ( (port & 0xfffc) = =3D=3D 0xcfc )=0A {=0A size =3D min(bytes, 4 - (port & = 3));=0A if ( size =3D=3D 3 )=0A size =3D = 2;=0A- if ( pci_cfg_ok(v->domain, 0, size) )=0A- = sub_data =3D pci_conf_read(v->domain->arch.pci_cf8, port & 3, size);=0A+ = if ( pci_cfg_ok(currd, 0, size) )=0A+ sub_data =3D = pci_conf_read(currd->arch.pci_cf8, port & 3, size);=0A }=0A =0A = if ( size =3D=3D 4 )=0A@@ -1873,11 +1870,10 @@ uint32_t guest_io_read(= =0A return data;=0A }=0A =0A-void guest_io_write(=0A- unsigned int = port, unsigned int bytes, uint32_t data,=0A- struct vcpu *v, struct = cpu_user_regs *regs)=0A+void guest_io_write(unsigned int port, unsigned = int bytes, uint32_t data,=0A+ struct domain *currd)=0A = {=0A- if ( admin_io_okay(port, bytes, v, regs) )=0A+ if ( admin_io_ok= ay(port, bytes, currd) )=0A {=0A switch ( bytes ) {=0A = case 1:=0A@@ -1905,33 +1901,32 @@ void guest_io_write(=0A }=0A = else if ( (port =3D=3D RTC_PORT(0)) )=0A {=0A- = v->domain->arch.cmos_idx =3D data;=0A+ currd->arch.cmos_idx =3D = data;=0A }=0A else if ( (port =3D=3D RTC_PORT(1)) &&=0A- = ioports_access_permitted(v->domain, RTC_PORT(0),=0A- = RTC_PORT(1)) )=0A+ = ioports_access_permitted(currd, RTC_PORT(0), RTC_PORT(1)) )=0A = {=0A unsigned long flags;=0A =0A if ( pv_rtc_handle= r )=0A- pv_rtc_handler(v->domain->arch.cmos_idx & 0x7f, = data);=0A+ pv_rtc_handler(currd->arch.cmos_idx & 0x7f, = data);=0A spin_lock_irqsave(&rtc_lock, flags);=0A- = outb(v->domain->arch.cmos_idx & 0x7f, RTC_PORT(0));=0A+ = outb(currd->arch.cmos_idx & 0x7f, RTC_PORT(0));=0A outb(data, = RTC_PORT(1));=0A spin_unlock_irqrestore(&rtc_lock, flags);=0A = }=0A else if ( (port =3D=3D 0xcf8) && (bytes =3D=3D 4) )=0A = {=0A size =3D 4;=0A- v->domain->arch.pci_cf8= =3D data;=0A+ currd->arch.pci_cf8 =3D data;=0A }=0A = else if ( (port & 0xfffc) =3D=3D 0xcfc )=0A {=0A = size =3D min(bytes, 4 - (port & 3));=0A if ( size =3D=3D 3 = )=0A size =3D 2;=0A- if ( pci_cfg_ok(v->domain, = 1, size) )=0A- pci_conf_write(v->domain->arch.pci_cf8, port = & 3, size, data);=0A+ if ( pci_cfg_ok(currd, 1, size) )=0A+ = pci_conf_write(currd->arch.pci_cf8, port & 3, size, data);=0A = }=0A =0A if ( size =3D=3D 4 )=0A@@ -1989,6 +1984,7 @@ static = int is_cpufreq_controller(struct =0A static int emulate_privileged_op(struc= t cpu_user_regs *regs)=0A {=0A struct vcpu *v =3D current;=0A+ = struct domain *currd =3D v->domain;=0A unsigned long *reg, eip =3D = regs->eip;=0A u8 opcode, modrm_reg =3D 0, modrm_rm =3D 0, rep_prefix = =3D 0, lock =3D 0, rex =3D 0;=0A enum { lm_seg_none, lm_seg_fs, = lm_seg_gs } lm_ovr =3D lm_seg_none;=0A@@ -2145,7 +2141,7 @@ static int = emulate_privileged_op(struct =0A (rd_ad(edi) > (data_limit= - (op_bytes - 1))) ||=0A !guest_io_okay(port, op_bytes, = v, regs) )=0A goto fail;=0A- data =3D guest_io_r= ead(port, op_bytes, v, regs);=0A+ data =3D guest_io_read(port, = op_bytes, currd);=0A if ( (rc =3D copy_to_user((void *)data_bas= e + rd_ad(edi),=0A &data, op_bytes)) = !=3D 0 )=0A {=0A@@ -2171,7 +2167,7 @@ static int emulate_privil= eged_op(struct =0A + op_bytes - rc, = 0);=0A return EXCRET_fault_fixed;=0A }=0A- = guest_io_write(port, op_bytes, data, v, regs);=0A+ = guest_io_write(port, op_bytes, data, currd);=0A wr_ad(esi, = regs->esi + (int)((regs->eflags & X86_EFLAGS_DF)=0A = ? -op_bytes : op_bytes));=0A break;=0A@@ = -2232,7 +2228,7 @@ static int emulate_privileged_op(struct =0A = exec_in:=0A if ( !guest_io_okay(port, op_bytes, v, regs) )=0A = goto fail;=0A- if ( admin_io_okay(port, op_bytes, v, regs) = )=0A+ if ( admin_io_okay(port, op_bytes, currd) )=0A {=0A = mark_regs_dirty(regs);=0A io_emul(regs); = =0A@@ -2243,7 +2239,7 @@ static int emulate_privileged_op(struct =0A = regs->eax =3D 0;=0A else=0A = regs->eax &=3D ~((1 << (op_bytes * 8)) - 1);=0A- regs->eax |=3D = guest_io_read(port, op_bytes, v, regs);=0A+ regs->eax |=3D = guest_io_read(port, op_bytes, currd);=0A }=0A bpmatch =3D = check_guest_io_breakpoint(v, port, op_bytes);=0A goto done;=0A@@ = -2262,7 +2258,7 @@ static int emulate_privileged_op(struct =0A = exec_out:=0A if ( !guest_io_okay(port, op_bytes, v, regs) )=0A = goto fail;=0A- if ( admin_io_okay(port, op_bytes, v, regs) = )=0A+ if ( admin_io_okay(port, op_bytes, currd) )=0A {=0A = mark_regs_dirty(regs);=0A io_emul(regs); = =0A@@ -2271,7 +2267,7 @@ static int emulate_privileged_op(struct =0A = }=0A else=0A {=0A- guest_io_write(port, = op_bytes, regs->eax, v, regs);=0A+ guest_io_write(port, = op_bytes, regs->eax, currd);=0A }=0A bpmatch =3D check_gues= t_io_breakpoint(v, port, op_bytes);=0A goto done;=0A@@ -2353,7 = +2349,7 @@ static int emulate_privileged_op(struct =0A =0A case 0x09: = /* WBINVD */=0A /* Ignore the instruction if unprivileged. */=0A- = if ( !cache_flush_permitted(v->domain) )=0A+ if ( !cache_flush= _permitted(currd) )=0A /* Non-physdev domain attempted WBINVD; = ignore for now since=0A newer linux uses this in some = start-of-day timing loops */=0A ;=0A@@ -2386,8 +2382,7 @@ = static int emulate_privileged_op(struct =0A if ( !is_pv_32on64_= vcpu(v) )=0A {=0A mfn =3D pagetable_get_pfn(v->= arch.guest_table);=0A- *reg =3D xen_pfn_to_cr3(mfn_to_gmfn(= =0A- v->domain, mfn));=0A+ *reg =3D = xen_pfn_to_cr3(mfn_to_gmfn(currd, mfn));=0A }=0A = else=0A {=0A@@ -2396,8 +2391,7 @@ static int emulate_privileged= _op(struct =0A =0A mfn =3D l4e_get_pfn(*pl4e);=0A = unmap_domain_page(pl4e);=0A- *reg =3D compat_pfn_to_c= r3(mfn_to_gmfn(=0A- v->domain, mfn));=0A+ = *reg =3D compat_pfn_to_cr3(mfn_to_gmfn(currd, mfn));=0A }=0A = /* PTs should not be shared */=0A BUG_ON(page_get_ow= ner(mfn_to_page(mfn)) =3D=3D dom_cow);=0A@@ -2457,7 +2451,7 @@ static int = emulate_privileged_op(struct =0A =0A gfn =3D !is_pv_32on64_vcpu= (v)=0A ? xen_cr3_to_pfn(*reg) : compat_cr3_to_pfn(*reg);=0A= - page =3D get_page_from_gfn(v->domain, gfn, NULL, P2M_ALLOC);= =0A+ page =3D get_page_from_gfn(currd, gfn, NULL, P2M_ALLOC);=0A= if ( page )=0A {=0A rc =3D = new_guest_cr3(page_to_mfn(page));=0A@@ -2541,7 +2535,7 @@ static int = emulate_privileged_op(struct =0A case MSR_K8_HWCR:=0A = if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD )=0A = goto fail;=0A- if ( !is_cpufreq_controller(v->domain) )=0A+ = if ( !is_cpufreq_controller(currd) )=0A break;=0A = if ( wrmsr_safe(regs->ecx, msr_content) !=3D 0 )=0A = goto fail;=0A@@ -2550,7 +2544,7 @@ static int emulate_privileged_op(stru= ct =0A if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD ||=0A = boot_cpu_data.x86 < 0x10 || boot_cpu_data.x86 > 0x17 )=0A = goto fail;=0A- if ( !is_hardware_domain(v->domai= n) || !is_pinned_vcpu(v) )=0A+ if ( !is_hardware_domain(currd) = || !is_pinned_vcpu(v) )=0A break;=0A if ( = (rdmsr_safe(MSR_AMD64_NB_CFG, val) !=3D 0) ||=0A (eax = !=3D (uint32_t)val) ||=0A@@ -2563,7 +2557,7 @@ static int emulate_privilege= d_op(struct =0A if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_A= MD ||=0A boot_cpu_data.x86 < 0x10 || boot_cpu_data.x86 > = 0x17 )=0A goto fail;=0A- if ( !is_hardware_domai= n(v->domain) || !is_pinned_vcpu(v) )=0A+ if ( !is_hardware_domai= n(currd) || !is_pinned_vcpu(v) )=0A break;=0A = if ( (rdmsr_safe(MSR_FAM10H_MMIO_CONF_BASE, val) !=3D 0) )=0A = goto fail;=0A@@ -2583,7 +2577,7 @@ static int emulate_privileged_op(stru= ct =0A case MSR_IA32_UCODE_REV:=0A if ( boot_cpu_data.x= 86_vendor !=3D X86_VENDOR_INTEL )=0A goto fail;=0A- = if ( !is_hardware_domain(v->domain) || !is_pinned_vcpu(v) )=0A+ = if ( !is_hardware_domain(currd) || !is_pinned_vcpu(v) )=0A = break;=0A if ( rdmsr_safe(regs->ecx, val) )=0A = goto fail;=0A@@ -2602,7 +2596,7 @@ static int emulate_privileged_op(str= uct =0A if (( boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL ) = &&=0A ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD ) = )=0A goto fail;=0A- if ( !is_cpufreq_controller(= v->domain) )=0A+ if ( !is_cpufreq_controller(currd) )=0A = break;=0A if ( wrmsr_safe(regs->ecx, msr_content ) = !=3D 0 )=0A goto fail;=0A@@ -2610,7 +2604,7 @@ static int = emulate_privileged_op(struct =0A case MSR_IA32_PERF_CTL:=0A = if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL )=0A = goto fail;=0A- if ( !is_cpufreq_controller(v->domain) )=0A+ = if ( !is_cpufreq_controller(currd) )=0A = break;=0A if ( wrmsr_safe(regs->ecx, msr_content) !=3D 0 )=0A = goto fail;=0A@@ -2619,7 +2613,7 @@ static int emulate_privil= eged_op(struct =0A case MSR_IA32_ENERGY_PERF_BIAS:=0A = if ( boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL )=0A = goto fail;=0A- if ( !is_hardware_domain(v->domain) || !is_pinned= _vcpu(v) )=0A+ if ( !is_hardware_domain(currd) || !is_pinned_vcp= u(v) )=0A break;=0A if ( wrmsr_safe(regs->ecx, = msr_content) !=3D 0 )=0A goto fail;=0A@@ -2665,7 +2659,7 = @@ static int emulate_privileged_op(struct =0A if ( (v->arch.pv_vcp= u.ctrlreg[4] & X86_CR4_TSD) &&=0A !guest_kernel_mode(v, regs) = )=0A goto fail;=0A- if ( v->domain->arch.vtsc )=0A+ = if ( currd->arch.vtsc )=0A pv_soft_rdtsc(v, regs, 0);=0A = else=0A {=0A@@ -2708,7 +2702,7 @@ static int emulate_privilege= d_op(struct =0A case MSR_K8_PSTATE7:=0A if ( boot_cpu_d= ata.x86_vendor !=3D X86_VENDOR_AMD )=0A goto fail;=0A- = if ( !is_cpufreq_controller(v->domain) )=0A+ if ( = !is_cpufreq_controller(currd) )=0A {=0A = regs->eax =3D regs->edx =3D 0;=0A break;=0A--- a/xen/includ= e/asm-x86/traps.h=0A+++ b/xen/include/asm-x86/traps.h=0A@@ -48,8 +48,8 @@ = extern int send_guest_trap(struct domain=0A = unsigned int trap_nr);=0A =0A uint32_t guest_io_read(unsigned int port, = unsigned int bytes,=0A- struct vcpu *, struct = cpu_user_regs *);=0A+ struct domain *);=0A void = guest_io_write(unsigned int port, unsigned int bytes, uint32_t data,=0A- = struct vcpu *, struct cpu_user_regs *);=0A+ = struct domain *);=0A =0A #endif /* ASM_TRAP_H */=0A --=__Part467268A7.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part467268A7.1__=--