From: "Jan Beulich" Subject: [PATCH v2] x86: synchronize PCI config space access decoding Date: Mon, 15 Jun 2015 15:30:59 +0100 Message-ID: <557EFDC30200007800084F27@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part112537B3.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 1Z4VPm-0003ZV-Fi for xen-devel@lists.xenproject.org; Mon, 15 Jun 2015 14:31:06 +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. --=__Part112537B3.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Both PV and HVM logic have similar but not similar enough code here. Synchronize the two so that - in the HVM case we don't unconditionally try to access extended config space - in the PV case we pass a correct range to the XSM hook - in the PV case we don't needlessly deny access when the operation isn't really on PCI config space All this along with sharing the macros HVM already had here. Signed-off-by: Jan Beulich --- v2: hvm_select_ioreq_server() no longer (directly) depends on host properties. --- a/xen/arch/x86/cpu/amd.c +++ b/xen/arch/x86/cpu/amd.c @@ -620,7 +620,7 @@ static void __devinit init_amd(struct cp check_syscfg_dram_mod_en(); } =20 -static struct cpu_dev amd_cpu_dev __cpuinitdata =3D { +static const struct cpu_dev amd_cpu_dev =3D { .c_vendor =3D "AMD", .c_ident =3D { "AuthenticAMD" }, .c_init =3D init_amd, --- a/xen/arch/x86/cpu/centaur.c +++ b/xen/arch/x86/cpu/centaur.c @@ -60,7 +60,7 @@ static void __init init_centaur(struct c init_c3(c); } =20 -static struct cpu_dev centaur_cpu_dev __cpuinitdata =3D { +static const struct cpu_dev centaur_cpu_dev =3D { .c_vendor =3D "Centaur", .c_ident =3D { "CentaurHauls" }, .c_init =3D init_centaur, --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -35,7 +35,7 @@ integer_param("cpuid_mask_ext_ecx", opt_ unsigned int __devinitdata opt_cpuid_mask_ext_edx =3D ~0u; integer_param("cpuid_mask_ext_edx", opt_cpuid_mask_ext_edx); =20 -struct cpu_dev * cpu_devs[X86_VENDOR_NUM] =3D {}; +const struct cpu_dev *__read_mostly cpu_devs[X86_VENDOR_NUM] =3D {}; =20 unsigned int paddr_bits __read_mostly =3D 36; =20 @@ -61,11 +61,11 @@ static void default_init(struct cpuinfo_ __clear_bit(X86_FEATURE_SEP, c->x86_capability); } =20 -static struct cpu_dev default_cpu =3D { +static const struct cpu_dev default_cpu =3D { .c_init =3D default_init, .c_vendor =3D "Unknown", }; -static struct cpu_dev * this_cpu =3D &default_cpu; +static const struct cpu_dev *this_cpu =3D &default_cpu; =20 bool_t opt_cpu_info; boolean_param("cpuinfo", opt_cpu_info); @@ -126,9 +126,8 @@ void __cpuinit display_cacheinfo(struct=20 l2size, ecx & 0xFF); } =20 -static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c, int early) +int get_cpu_vendor(const char v[], enum get_cpu_vendor mode) { - char *v =3D c->x86_vendor_id; int i; static int printed; =20 @@ -137,20 +136,22 @@ static void __cpuinit get_cpu_vendor(str if (!strcmp(v,cpu_devs[i]->c_ident[0]) || (cpu_devs[i]->c_ident[1] &&=20 !strcmp(v,cpu_devs[i]->c_ident[1]))) { - c->x86_vendor =3D i; - if (!early) + if (mode =3D=3D gcv_host_late) this_cpu =3D cpu_devs[i]; - return; + return i; } } } + if (mode =3D=3D gcv_guest) + return X86_VENDOR_UNKNOWN; if (!printed) { printed++; printk(KERN_ERR "CPU: Vendor unknown, using generic = init.\n"); printk(KERN_ERR "CPU: Your system may be unstable.\n"); } - c->x86_vendor =3D X86_VENDOR_UNKNOWN; this_cpu =3D &default_cpu; + + return X86_VENDOR_UNKNOWN; } =20 static inline u32 _phys_pkg_id(u32 cpuid_apic, int index_msb) @@ -189,7 +190,7 @@ static void __init early_cpu_detect(void (int *)&c->x86_vendor_id[8], (int *)&c->x86_vendor_id[4]); =20 - get_cpu_vendor(c, 1); + c->x86_vendor =3D get_cpu_vendor(c->x86_vendor_id, gcv_host_early);= =20 cpuid(0x00000001, &tfms, &misc, &cap4, &cap0); c->x86 =3D (tfms >> 8) & 15; @@ -218,7 +219,7 @@ static void __cpuinit generic_identify(s (int *)&c->x86_vendor_id[8], (int *)&c->x86_vendor_id[4]); =09 - get_cpu_vendor(c, 0); + c->x86_vendor =3D get_cpu_vendor(c->x86_vendor_id, gcv_host_late); /* Initialize the standard set of capabilities */ /* Note that the vendor-specific code below might override */ =09 --- a/xen/arch/x86/cpu/cpu.h +++ b/xen/arch/x86/cpu/cpu.h @@ -8,7 +8,7 @@ struct cpu_dev { void (*c_init)(struct cpuinfo_x86 * c); }; =20 -extern struct cpu_dev * cpu_devs [X86_VENDOR_NUM]; +extern const struct cpu_dev *cpu_devs[X86_VENDOR_NUM]; =20 extern bool_t opt_arat; extern unsigned int opt_cpuid_mask_ecx, opt_cpuid_mask_edx; --- a/xen/arch/x86/cpu/intel.c +++ b/xen/arch/x86/cpu/intel.c @@ -286,7 +286,7 @@ static void __devinit init_intel(struct=20 set_bit(X86_FEATURE_ARAT, c->x86_capability); } =20 -static struct cpu_dev intel_cpu_dev __cpuinitdata =3D { +static const struct cpu_dev intel_cpu_dev =3D { .c_vendor =3D "Intel", .c_ident =3D { "GenuineIntel" }, .c_init =3D init_intel, --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -579,6 +579,10 @@ int arch_domain_create(struct domain *d, d->arch.cpuids[i].input[1] =3D XEN_CPUID_INPUT_UNUSED; } =20 + d->arch.x86_vendor =3D boot_cpu_data.x86_vendor; + d->arch.x86 =3D boot_cpu_data.x86; + d->arch.x86_model =3D boot_cpu_data.x86_model; + d->arch.ioport_caps =3D=20 rangeset_new(d, "I/O Ports", RANGESETF_prettyprint_hex); rc =3D -ENOMEM; --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -695,6 +695,38 @@ long arch_do_domctl( *unused =3D *ctl; else ret =3D -ENOENT; + + if ( !ret ) + { + switch ( ctl->input[0] ) + { + case 0: { + union { + typeof(boot_cpu_data.x86_vendor_id) str; + struct { + uint32_t ebx, edx, ecx; + } reg; + } vendor_id =3D { + .reg =3D { + .ebx =3D ctl->ebx, + .edx =3D ctl->edx, + .ecx =3D ctl->ecx + } + }; + + d->arch.x86_vendor =3D get_cpu_vendor(vendor_id.str, = gcv_guest); + break; + } + case 1: + d->arch.x86 =3D (ctl->eax >> 8) & 0xf; + if ( d->arch.x86 =3D=3D 0xf ) + d->arch.x86 +=3D (ctl->eax >> 20) & 0xff; + d->arch.x86_model =3D (ctl->eax >> 4) & 0xf; + if ( d->arch.x86 >=3D 0x6 ) + d->arch.x86_model |=3D (ctl->eax >> 12) & 0xf0; + break; + } + } break; } =20 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -2406,11 +2406,6 @@ void hvm_vcpu_down(struct vcpu *v) struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d, ioreq_t *p) { -#define CF8_BDF(cf8) (((cf8) & 0x00ffff00) >> 8) -#define CF8_ADDR_LO(cf8) ((cf8) & 0x000000fc) -#define CF8_ADDR_HI(cf8) (((cf8) & 0x0f000000) >> 16) -#define CF8_ENABLED(cf8) (!!((cf8) & 0x80000000)) - struct hvm_ioreq_server *s; uint32_t cf8; uint8_t type; @@ -2439,9 +2434,19 @@ struct hvm_ioreq_server *hvm_select_iore =20 type =3D IOREQ_TYPE_PCI_CONFIG; addr =3D ((uint64_t)sbdf << 32) | - CF8_ADDR_HI(cf8) | CF8_ADDR_LO(cf8) | (p->addr & 3); + /* AMD extended configuration space access? */ + if ( CF8_ADDR_HI(cf8) && + d->arch.x86_vendor =3D=3D X86_VENDOR_AMD && + d->arch.x86 >=3D 0x10 && d->arch.x86 <=3D 0x17 ) + { + uint64_t msr_val; + + if ( !rdmsr_safe(MSR_AMD64_NB_CFG, msr_val) && + (msr_val & (1ULL << AMD64_NB_CFG_CF8_EXT_ENABLE_BIT)) ) + addr |=3D CF8_ADDR_HI(cf8); + } } else { @@ -2495,11 +2500,6 @@ struct hvm_ioreq_server *hvm_select_iore } =20 return d->arch.hvm_domain.default_ioreq_server; - -#undef CF8_ADDR_ENABLED -#undef CF8_ADDR_HI -#undef CF8_ADDR_LO -#undef CF8_BDF } =20 int hvm_buffered_io_send(ioreq_t *p) --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1771,15 +1771,18 @@ static bool_t admin_io_okay(unsigned int return ioports_access_permitted(d, port, port + bytes - 1); } =20 -static bool_t pci_cfg_ok(struct domain *currd, bool_t write, unsigned int = size) +static bool_t pci_cfg_ok(struct domain *currd, bool_t write, + unsigned int start, unsigned int size) { uint32_t machine_bdf; - unsigned int start; =20 if ( !is_hardware_domain(currd) ) return 0; =20 - machine_bdf =3D (currd->arch.pci_cf8 >> 8) & 0xFFFF; + if ( !CF8_ENABLED(currd->arch.pci_cf8) ) + return 1; + + machine_bdf =3D CF8_BDF(currd->arch.pci_cf8); if ( write ) { const unsigned long *ro_map =3D pci_get_ro_map(0); @@ -1787,9 +1790,9 @@ static bool_t pci_cfg_ok(struct domain * if ( ro_map && test_bit(machine_bdf, ro_map) ) return 0; } - start =3D currd->arch.pci_cf8 & 0xFF; + start |=3D CF8_ADDR_LO(currd->arch.pci_cf8); /* AMD extended configuration space access? */ - if ( (currd->arch.pci_cf8 & 0x0F000000) && + if ( CF8_ADDR_HI(currd->arch.pci_cf8) && boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD && boot_cpu_data.x86 >=3D 0x10 && boot_cpu_data.x86 <=3D 0x17 ) { @@ -1798,7 +1801,7 @@ static bool_t pci_cfg_ok(struct domain * if ( rdmsr_safe(MSR_AMD64_NB_CFG, msr_val) ) return 0; if ( msr_val & (1ULL << AMD64_NB_CFG_CF8_EXT_ENABLE_BIT) ) - start |=3D (currd->arch.pci_cf8 >> 16) & 0xF00; + start |=3D CF8_ADDR_HI(currd->arch.pci_cf8); } =20 return !xsm_pci_config_permission(XSM_HOOK, currd, machine_bdf, @@ -1854,7 +1857,7 @@ uint32_t guest_io_read(unsigned int port size =3D min(bytes, 4 - (port & 3)); if ( size =3D=3D 3 ) size =3D 2; - if ( pci_cfg_ok(currd, 0, size) ) + if ( pci_cfg_ok(currd, 0, port & 3, size) ) sub_data =3D pci_conf_read(currd->arch.pci_cf8, port & 3, = size); } =20 @@ -1925,7 +1928,7 @@ void guest_io_write(unsigned int port, u size =3D min(bytes, 4 - (port & 3)); if ( size =3D=3D 3 ) size =3D 2; - if ( pci_cfg_ok(currd, 1, size) ) + if ( pci_cfg_ok(currd, 1, port & 3, size) ) pci_conf_write(currd->arch.pci_cf8, port & 3, size, = data); } =20 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -308,6 +308,11 @@ struct arch_domain /* Is PHYSDEVOP_eoi to automatically unmask the event channel? */ bool_t auto_unmask; =20 + /* Values snooped from updates to cpuids[] (below). */ + u8 x86; /* CPU family */ + u8 x86_vendor; /* CPU vendor */ + u8 x86_model; /* CPU model */ + cpuid_input_t *cpuids; =20 struct PITState vpit; --- a/xen/include/asm-x86/pci.h +++ b/xen/include/asm-x86/pci.h @@ -1,6 +1,11 @@ #ifndef __X86_PCI_H__ #define __X86_PCI_H__ =20 +#define CF8_BDF(cf8) (((cf8) & 0x00ffff00) >> 8) +#define CF8_ADDR_LO(cf8) ((cf8) & 0x000000fc) +#define CF8_ADDR_HI(cf8) (((cf8) & 0x0f000000) >> 16) +#define CF8_ENABLED(cf8) (!!((cf8) & 0x80000000)) + #define IS_SNB_GFX(id) (id =3D=3D 0x01068086 || id =3D=3D 0x01168086 \ || id =3D=3D 0x01268086 || id =3D=3D 0x01028086 \ || id =3D=3D 0x01128086 || id =3D=3D 0x01228086 \ --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -561,6 +561,13 @@ void microcode_set_module(unsigned int); int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void), unsigned long = len); int microcode_resume_cpu(int cpu); =20 +enum get_cpu_vendor { + gcv_host_early, + gcv_host_late, + gcv_guest +}; + +int get_cpu_vendor(const char vendor_id[], enum get_cpu_vendor); void pv_cpuid(struct cpu_user_regs *regs); =20 #endif /* !__ASSEMBLY__ */ --=__Part112537B3.1__= Content-Type: text/plain; name="x86-CF8-decode.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-CF8-decode.patch" x86: synchronize PCI config space access decoding=0A=0ABoth PV and HVM = logic have similar but not similar enough code here.=0ASynchronize the two = so that=0A- in the HVM case we don't unconditionally try to access = extended=0A config space=0A- in the PV case we pass a correct range to = the XSM hook=0A- in the PV case we don't needlessly deny access when the = operation=0A isn't really on PCI config space=0AAll this along with = sharing the macros HVM already had here.=0A=0ASigned-off-by: Jan Beulich = =0A---=0Av2: hvm_select_ioreq_server() no longer = (directly) depends on host=0A properties.=0A=0A--- a/xen/arch/x86/cpu/am= d.c=0A+++ b/xen/arch/x86/cpu/amd.c=0A@@ -620,7 +620,7 @@ static void = __devinit init_amd(struct cp=0A check_syscfg_dram_mod_en();=0A = }=0A =0A-static struct cpu_dev amd_cpu_dev __cpuinitdata =3D {=0A+static = const struct cpu_dev amd_cpu_dev =3D {=0A .c_vendor =3D = "AMD",=0A .c_ident =3D { "AuthenticAMD" },=0A .c_init = =3D init_amd,=0A--- a/xen/arch/x86/cpu/centaur.c=0A+++ b/xen/arch/x86/cpu/c= entaur.c=0A@@ -60,7 +60,7 @@ static void __init init_centaur(struct c=0A = init_c3(c);=0A }=0A =0A-static struct cpu_dev centaur_cpu_dev = __cpuinitdata =3D {=0A+static const struct cpu_dev centaur_cpu_dev =3D = {=0A .c_vendor =3D "Centaur",=0A .c_ident =3D { = "CentaurHauls" },=0A .c_init =3D init_centaur,=0A--- a/xen/arch/= x86/cpu/common.c=0A+++ b/xen/arch/x86/cpu/common.c=0A@@ -35,7 +35,7 @@ = integer_param("cpuid_mask_ext_ecx", opt_=0A unsigned int __devinitdata = opt_cpuid_mask_ext_edx =3D ~0u;=0A integer_param("cpuid_mask_ext_edx", = opt_cpuid_mask_ext_edx);=0A =0A-struct cpu_dev * cpu_devs[X86_VENDOR_NUM] = =3D {};=0A+const struct cpu_dev *__read_mostly cpu_devs[X86_VENDOR_NUM] = =3D {};=0A =0A unsigned int paddr_bits __read_mostly =3D 36;=0A =0A@@ = -61,11 +61,11 @@ static void default_init(struct cpuinfo_=0A __clear_bit= (X86_FEATURE_SEP, c->x86_capability);=0A }=0A =0A-static struct cpu_dev = default_cpu =3D {=0A+static const struct cpu_dev default_cpu =3D {=0A = .c_init =3D default_init,=0A .c_vendor =3D "Unknown",=0A };=0A-static = struct cpu_dev * this_cpu =3D &default_cpu;=0A+static const struct cpu_dev = *this_cpu =3D &default_cpu;=0A =0A bool_t opt_cpu_info;=0A boolean_param("c= puinfo", opt_cpu_info);=0A@@ -126,9 +126,8 @@ void __cpuinit display_cachei= nfo(struct =0A l2size, ecx & 0xFF);=0A }=0A =0A-static = void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c, int early)=0A+int = get_cpu_vendor(const char v[], enum get_cpu_vendor mode)=0A {=0A- = char *v =3D c->x86_vendor_id;=0A int i;=0A static int = printed;=0A =0A@@ -137,20 +136,22 @@ static void __cpuinit get_cpu_vendor(s= tr=0A if (!strcmp(v,cpu_devs[i]->c_ident[0]) ||=0A = (cpu_devs[i]->c_ident[1] && =0A = !strcmp(v,cpu_devs[i]->c_ident[1]))) {=0A- = c->x86_vendor =3D i;=0A- if (!early)=0A+ = if (mode =3D=3D gcv_host_late)=0A = this_cpu =3D cpu_devs[i];=0A- return;=0A+= return i;=0A }=0A = }=0A }=0A+ if (mode =3D=3D gcv_guest)=0A+ return X86_VENDOR_U= NKNOWN;=0A if (!printed) {=0A printed++;=0A = printk(KERN_ERR "CPU: Vendor unknown, using generic init.\n");=0A = printk(KERN_ERR "CPU: Your system may be unstable.\n");=0A }=0A- = c->x86_vendor =3D X86_VENDOR_UNKNOWN;=0A this_cpu =3D &default_cpu;= =0A+=0A+ return X86_VENDOR_UNKNOWN;=0A }=0A =0A static inline u32 = _phys_pkg_id(u32 cpuid_apic, int index_msb)=0A@@ -189,7 +190,7 @@ static = void __init early_cpu_detect(void=0A (int *)&c->x86_vendor_id[8],= =0A (int *)&c->x86_vendor_id[4]);=0A =0A- get_cpu_vendor(c, = 1);=0A+ c->x86_vendor =3D get_cpu_vendor(c->x86_vendor_id, gcv_host_early);= =0A =0A cpuid(0x00000001, &tfms, &misc, &cap4, &cap0);=0A = c->x86 =3D (tfms >> 8) & 15;=0A@@ -218,7 +219,7 @@ static void __cpuinit = generic_identify(s=0A (int *)&c->x86_vendor_id[8],=0A (int = *)&c->x86_vendor_id[4]);=0A =0A- get_cpu_vendor(c, 0);=0A+ = c->x86_vendor =3D get_cpu_vendor(c->x86_vendor_id, gcv_host_late);=0A /* = Initialize the standard set of capabilities */=0A /* Note that the = vendor-specific code below might override */=0A =0A--- a/xen/arch/x= 86/cpu/cpu.h=0A+++ b/xen/arch/x86/cpu/cpu.h=0A@@ -8,7 +8,7 @@ struct = cpu_dev {=0A void (*c_init)(struct cpuinfo_x86 * c);=0A = };=0A =0A-extern struct cpu_dev * cpu_devs [X86_VENDOR_NUM];=0A+extern = const struct cpu_dev *cpu_devs[X86_VENDOR_NUM];=0A =0A extern bool_t = opt_arat;=0A extern unsigned int opt_cpuid_mask_ecx, opt_cpuid_mask_edx;=0A= --- a/xen/arch/x86/cpu/intel.c=0A+++ b/xen/arch/x86/cpu/intel.c=0A@@ = -286,7 +286,7 @@ static void __devinit init_intel(struct =0A = set_bit(X86_FEATURE_ARAT, c->x86_capability);=0A }=0A =0A-static struct = cpu_dev intel_cpu_dev __cpuinitdata =3D {=0A+static const struct cpu_dev = intel_cpu_dev =3D {=0A .c_vendor =3D "Intel",=0A .c_ident = =3D { "GenuineIntel" },=0A .c_init =3D init_intel,=0A--- = a/xen/arch/x86/domain.c=0A+++ b/xen/arch/x86/domain.c=0A@@ -579,6 +579,10 = @@ int arch_domain_create(struct domain *d,=0A d->arch.cpuids[i= ].input[1] =3D XEN_CPUID_INPUT_UNUSED;=0A }=0A =0A+ = d->arch.x86_vendor =3D boot_cpu_data.x86_vendor;=0A+ d->arch.x86 = =3D boot_cpu_data.x86;=0A+ d->arch.x86_model =3D boot_cpu_data.= x86_model;=0A+=0A d->arch.ioport_caps =3D =0A = rangeset_new(d, "I/O Ports", RANGESETF_prettyprint_hex);=0A rc =3D = -ENOMEM;=0A--- a/xen/arch/x86/domctl.c=0A+++ b/xen/arch/x86/domctl.c=0A@@ = -695,6 +695,38 @@ long arch_do_domctl(=0A *unused =3D *ctl;=0A = else=0A ret =3D -ENOENT;=0A+=0A+ if ( !ret = )=0A+ {=0A+ switch ( ctl->input[0] )=0A+ = {=0A+ case 0: {=0A+ union {=0A+ = typeof(boot_cpu_data.x86_vendor_id) str;=0A+ struct = {=0A+ uint32_t ebx, edx, ecx;=0A+ = } reg;=0A+ } vendor_id =3D {=0A+ .reg = =3D {=0A+ .ebx =3D ctl->ebx,=0A+ = .edx =3D ctl->edx,=0A+ .ecx =3D ctl->ecx=0A+ = }=0A+ };=0A+=0A+ d->arch.x86_= vendor =3D get_cpu_vendor(vendor_id.str, gcv_guest);=0A+ = break;=0A+ }=0A+ case 1:=0A+ = d->arch.x86 =3D (ctl->eax >> 8) & 0xf;=0A+ if ( d->arch.x86 = =3D=3D 0xf )=0A+ d->arch.x86 +=3D (ctl->eax >> 20) & = 0xff;=0A+ d->arch.x86_model =3D (ctl->eax >> 4) & 0xf;=0A+ = if ( d->arch.x86 >=3D 0x6 )=0A+ d->arch.x8= 6_model |=3D (ctl->eax >> 12) & 0xf0;=0A+ break;=0A+ = }=0A+ }=0A break;=0A }=0A =0A--- a/xen/arch/x86/hvm/= hvm.c=0A+++ b/xen/arch/x86/hvm/hvm.c=0A@@ -2406,11 +2406,6 @@ void = hvm_vcpu_down(struct vcpu *v)=0A struct hvm_ioreq_server *hvm_select_ioreq_= server(struct domain *d,=0A = ioreq_t *p)=0A {=0A-#define CF8_BDF(cf8) (((cf8) & 0x00ffff00) >> = 8)=0A-#define CF8_ADDR_LO(cf8) ((cf8) & 0x000000fc)=0A-#define CF8_ADDR_HI(= cf8) (((cf8) & 0x0f000000) >> 16)=0A-#define CF8_ENABLED(cf8) (!!((cf8) & = 0x80000000))=0A-=0A struct hvm_ioreq_server *s;=0A uint32_t = cf8;=0A uint8_t type;=0A@@ -2439,9 +2434,19 @@ struct hvm_ioreq_server = *hvm_select_iore=0A =0A type =3D IOREQ_TYPE_PCI_CONFIG;=0A = addr =3D ((uint64_t)sbdf << 32) |=0A- CF8_ADDR_HI(cf8) |=0A = CF8_ADDR_LO(cf8) |=0A (p->addr & 3);=0A+ = /* AMD extended configuration space access? */=0A+ if ( CF8_ADDR_H= I(cf8) &&=0A+ d->arch.x86_vendor =3D=3D X86_VENDOR_AMD &&=0A+ = d->arch.x86 >=3D 0x10 && d->arch.x86 <=3D 0x17 )=0A+ = {=0A+ uint64_t msr_val;=0A+=0A+ if ( !rdmsr_safe(MSR_= AMD64_NB_CFG, msr_val) &&=0A+ (msr_val & (1ULL << = AMD64_NB_CFG_CF8_EXT_ENABLE_BIT)) )=0A+ addr |=3D CF8_ADDR_H= I(cf8);=0A+ }=0A }=0A else=0A {=0A@@ -2495,11 +2500,6 = @@ struct hvm_ioreq_server *hvm_select_iore=0A }=0A =0A return = d->arch.hvm_domain.default_ioreq_server;=0A-=0A-#undef CF8_ADDR_ENABLED=0A-= #undef CF8_ADDR_HI=0A-#undef CF8_ADDR_LO=0A-#undef CF8_BDF=0A }=0A =0A int = hvm_buffered_io_send(ioreq_t *p)=0A--- a/xen/arch/x86/traps.c=0A+++ = b/xen/arch/x86/traps.c=0A@@ -1771,15 +1771,18 @@ static bool_t admin_io_oka= y(unsigned int=0A return ioports_access_permitted(d, port, port + = bytes - 1);=0A }=0A =0A-static bool_t pci_cfg_ok(struct domain *currd, = bool_t write, unsigned int size)=0A+static bool_t pci_cfg_ok(struct domain = *currd, bool_t write,=0A+ unsigned int start, = unsigned int size)=0A {=0A uint32_t machine_bdf;=0A- unsigned int = start;=0A =0A if ( !is_hardware_domain(currd) )=0A return = 0;=0A =0A- machine_bdf =3D (currd->arch.pci_cf8 >> 8) & 0xFFFF;=0A+ = if ( !CF8_ENABLED(currd->arch.pci_cf8) )=0A+ return 1;=0A+=0A+ = machine_bdf =3D CF8_BDF(currd->arch.pci_cf8);=0A if ( write )=0A = {=0A const unsigned long *ro_map =3D pci_get_ro_map(0);=0A@@ = -1787,9 +1790,9 @@ static bool_t pci_cfg_ok(struct domain *=0A if = ( ro_map && test_bit(machine_bdf, ro_map) )=0A return 0;=0A = }=0A- start =3D currd->arch.pci_cf8 & 0xFF;=0A+ start |=3D = CF8_ADDR_LO(currd->arch.pci_cf8);=0A /* AMD extended configuration = space access? */=0A- if ( (currd->arch.pci_cf8 & 0x0F000000) &&=0A+ = if ( CF8_ADDR_HI(currd->arch.pci_cf8) &&=0A boot_cpu_data.x86_vend= or =3D=3D X86_VENDOR_AMD &&=0A boot_cpu_data.x86 >=3D 0x10 && = boot_cpu_data.x86 <=3D 0x17 )=0A {=0A@@ -1798,7 +1801,7 @@ static = bool_t pci_cfg_ok(struct domain *=0A if ( rdmsr_safe(MSR_AMD64_NB_C= FG, msr_val) )=0A return 0;=0A if ( msr_val & (1ULL << = AMD64_NB_CFG_CF8_EXT_ENABLE_BIT) )=0A- start |=3D (currd->arch.p= ci_cf8 >> 16) & 0xF00;=0A+ start |=3D CF8_ADDR_HI(currd->arch.pc= i_cf8);=0A }=0A =0A return !xsm_pci_config_permission(XSM_HOOK, = currd, machine_bdf,=0A@@ -1854,7 +1857,7 @@ uint32_t guest_io_read(unsigned= int port=0A size =3D min(bytes, 4 - (port & 3));=0A = if ( size =3D=3D 3 )=0A size =3D 2;=0A- if ( = pci_cfg_ok(currd, 0, size) )=0A+ if ( pci_cfg_ok(currd, 0, port = & 3, size) )=0A sub_data =3D pci_conf_read(currd->arch.pci_= cf8, port & 3, size);=0A }=0A =0A@@ -1925,7 +1928,7 @@ void = guest_io_write(unsigned int port, u=0A size =3D min(bytes, 4 - = (port & 3));=0A if ( size =3D=3D 3 )=0A size = =3D 2;=0A- if ( pci_cfg_ok(currd, 1, size) )=0A+ if = ( pci_cfg_ok(currd, 1, port & 3, size) )=0A pci_conf_write(= currd->arch.pci_cf8, port & 3, size, data);=0A }=0A =0A--- = a/xen/include/asm-x86/domain.h=0A+++ b/xen/include/asm-x86/domain.h=0A@@ = -308,6 +308,11 @@ struct arch_domain=0A /* Is PHYSDEVOP_eoi to = automatically unmask the event channel? */=0A bool_t auto_unmask;=0A = =0A+ /* Values snooped from updates to cpuids[] (below). */=0A+ u8 = x86; /* CPU family */=0A+ u8 x86_vendor; /* = CPU vendor */=0A+ u8 x86_model; /* CPU model */=0A+=0A = cpuid_input_t *cpuids;=0A =0A struct PITState vpit;=0A--- a/xen/include= /asm-x86/pci.h=0A+++ b/xen/include/asm-x86/pci.h=0A@@ -1,6 +1,11 @@=0A = #ifndef __X86_PCI_H__=0A #define __X86_PCI_H__=0A =0A+#define CF8_BDF(cf8) = (((cf8) & 0x00ffff00) >> 8)=0A+#define CF8_ADDR_LO(cf8) ((cf8) & = 0x000000fc)=0A+#define CF8_ADDR_HI(cf8) (((cf8) & 0x0f000000) >> 16)=0A+#de= fine CF8_ENABLED(cf8) (!!((cf8) & 0x80000000))=0A+=0A #define IS_SNB_GFX(id= ) (id =3D=3D 0x01068086 || id =3D=3D 0x01168086 \=0A = || id =3D=3D 0x01268086 || id =3D=3D 0x01028086 \=0A = || id =3D=3D 0x01128086 || id =3D=3D 0x01228086 \=0A--- a/xen/include/a= sm-x86/processor.h=0A+++ b/xen/include/asm-x86/processor.h=0A@@ -561,6 = +561,13 @@ void microcode_set_module(unsigned int);=0A int microcode_update= (XEN_GUEST_HANDLE_PARAM(const_void), unsigned long len);=0A int microcode_r= esume_cpu(int cpu);=0A =0A+enum get_cpu_vendor {=0A+ gcv_host_early,=0A+ = gcv_host_late,=0A+ gcv_guest=0A+};=0A+=0A+int get_cpu_vendor(const = char vendor_id[], enum get_cpu_vendor);=0A void pv_cpuid(struct cpu_user_re= gs *regs);=0A =0A #endif /* !__ASSEMBLY__ */=0A --=__Part112537B3.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 --=__Part112537B3.1__=--