[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] x86/pci: Correct ECS handling with CF8/CFC emulation


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 4 Apr 2023 17:04:25 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SAJceG8SYRB7dmczQIz9NoKmgKqs2EQZOu9yMBGtoAw=; b=lCH1Z81IlhvjG1CmJLos7NLbWThErhel9E0JUo9j7JXZw7iR1oRZv2bw8dAY4Egc7xCeec9KbG1bJCPIjrpoZnCfiadBA/wADOgYJXAS74U7jjiRKreLjccJRxLBEmompdQ3Ux/WXtdYef8Cj3kb//DYchPMr3Wg4lYr2CrWc7B0UDqN38E0p2Dm8qRjQON2FUW7tHfTTRIe/nA6RAw42dZ0rLU1kYwnQwY3VSoY0v4kxAcVBapm6P2CH3r/kzWQDv4i6AoP8lZkaEQfFHMvXmflgLwCL32/Ht3TRkTS8C4QsuyRq7/84E/Ij64LaZnPDjhQrVBu+nNd3OElk01gGg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zep+hn5yw3NA1jJHq1tf6kXrYY45O8INcCRz3PgUYawe2hIl5bbZfvzjeEgM0JNNJIrg8awLHkpdrN5MDrlr0rGqDtL1yedDV7ecWCCu8sctv+WMUc7wAjO1+pJetJOnVX4zvuqvMVZm14cKTU9NzXEkJvD67l1WSTtR8jQT/3l5t3CZ/P98CSuUYli8AcpiXZxOPjf/GZElTekluiUBMqooAQmVB6lLjRpbMKrU3qvd0Vf0PRn7e4i0h1R7Y9BAnlLhBYhMDaIgAFeO7zQVjjtKwRfaav2+1O+ayIKETvwSR1N6msfuoEdTuyd7xhIXgatujSy2wG2WbImoH2SjBw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Jan Beulich <JBeulich@xxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 04 Apr 2023 15:04:45 +0000
  • Ironport-data: A9a23:xDo0HKKNRu6hUnKtFE+R9pQlxSXFcZb7ZxGr2PjKsXjdYENSgTVWy TQZXWmCM67fM2qmLd90bN7l9BwDsZ7Vm4c2GgRlqX01Q3x08seUXt7xwmUcnc+xBpaaEB84t ZV2hv3odp1coqr0/0/1WlTZhSAgk/rOHvykU7Ss1hlZHWdMUD0mhQ9oh9k3i4tphcnRKw6Ws Jb5rta31GWNglaYCUpJrfPTwP9TlK6q4mhA4gRiPaojUGL2zBH5MrpOfcldEFOgKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0hK6aYD76vRxjnVaPpIAHOgdcS9qZwChxLid/ jnvWauYEm/FNoWU8AgUvoIx/ytWZcWq85efSZSzXFD6I+QrvBIAzt03ZHzaM7H09c5zGWZB2 tw9MwoPTTCIt6G0kJCLYeVF05FLwMnDZOvzu1lG5BSBV7MdZ8mGRK/Ho9hFwD03m8ZCW+7EY NYUYiZuaxKGZABTPlAQC9Q1m+LAanvXKmUE7g7K4/dopTSNpOBy+OGF3N79YNuFSN8Thk+Fj mnH4374ElcRM9n3JT+tqyr33rCexnmnMG4UPIaBptI0knbU/X0WMw8/eEGWoP6Tj0HrDrqzL GRRoELCt5Ma5EGtC9XwQRC8iHqFpQIHHcpdFfUg7wOAwbaS5ByWbkAmZDNcbN0ttOctWCcnk FSOmrvBGjhHoLCTD3WH+d+pQSiaPCEUKSoZY3YCRA5dud37+tlv0FTIU8ppF7OzgpvtAzbsz juWrS84wbIOkcoM0Kb99lfC696xmqX0oscOzl2/dgqYAslRP+ZJu6TABYDn0Mt9
  • Ironport-hdrordr: A9a23:EWHwRqoO3mHraeV0iCd3j2AaV5oJeYIsimQD101hICG9E/bo8v xG+c5wuCMc5wx8ZJhNo7+90dC7MBThHP1OkOss1NWZPDUO0VHARL2Ki7GN/9SKIVycygcy78 Zdmp9FebnN5AhB5voSODPIaerIGuP3iJxAWN2uqUuFkTsaEJ2IMT0JdzpyfSVNNXB7OaY=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, Apr 04, 2023 at 02:27:36PM +0100, Andrew Cooper wrote:
> On 03/04/2023 2:26 pm, Roger Pau Monné wrote:
> > On Mon, Apr 03, 2023 at 11:16:52AM +0100, Andrew Cooper wrote:
> >> On 03/04/2023 9:57 am, Roger Pau Monné wrote:
> >> (Quick tangent...  Our PCI handling is currently very dumb. 
> >> pci_mmcfg_read() returns its value by pointer but the callers never
> >> check.  Swapping it to return by value would improve code gen quite a
> >> lot.  Also, when MMCFG is active we still pass BCS accesses to IO ports.)
> > I wonder if it's really preferred to access registers below 255 using
> > the IO ports, as Linux seems to do the same (prefer IO port access if
> > possible).
> 
> And see how many attempts there have been to change this, only blocked
> on untangling the IO port mess on other architectures (a problem Xen
> doesn't have to contend with).
> 
> MMCFG, when available is strictly preferable to IO ports.
> 
> An MMCFG access is a single UC read or write, whereas IO ports are a
> pair of UC accesses *and* a global spinlock.

Right, I know it's better from a performance PoV, but didn't know
whether there was some known glitches for not using MMCFG when
accessing regs < 255.

> >>>>  
> >>>>  #define IS_SNB_GFX(id) (id == 0x01068086 || id == 0x01168086 \
> >>>>                          || id == 0x01268086 || id == 0x01028086 \
> >>>> diff --git a/xen/arch/x86/pv/emul-priv-op.c 
> >>>> b/xen/arch/x86/pv/emul-priv-op.c
> >>>> index 5da00e24e4ff..008367195c78 100644
> >>>> --- a/xen/arch/x86/pv/emul-priv-op.c
> >>>> +++ b/xen/arch/x86/pv/emul-priv-op.c
> >>>> @@ -245,19 +245,7 @@ static bool pci_cfg_ok(struct domain *currd, 
> >>>> unsigned int start,
> >>>>          if ( ro_map && test_bit(machine_bdf, ro_map) )
> >>>>              return false;
> >>>>      }
> >>>> -    start |= CF8_ADDR_LO(currd->arch.pci_cf8);
> >>>> -    /* AMD extended configuration space access? */
> >>>> -    if ( CF8_ADDR_HI(currd->arch.pci_cf8) &&
> >>>> -         boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
> >>>> -         boot_cpu_data.x86 >= 0x10 && boot_cpu_data.x86 < 0x17 )
> >>>> -    {
> >>>> -        uint64_t msr_val;
> >>>> -
> >>>> -        if ( rdmsr_safe(MSR_AMD64_NB_CFG, msr_val) )
> >>>> -            return false;
> >>>> -        if ( msr_val & (1ULL << AMD64_NB_CFG_CF8_EXT_ENABLE_BIT) )
> >>>> -            start |= CF8_ADDR_HI(currd->arch.pci_cf8);
> >>>> -    }
> >>>> +    start |= CF8_REG(currd->arch.pci_cf8);
> >>>>  
> >>>>      return !write ?
> >>>>             xsm_pci_config_permission(XSM_HOOK, currd, machine_bdf,
> >>>> @@ -1104,6 +1092,11 @@ static int cf_check write_msr(
> >>>>          if ( !is_hwdom_pinned_vcpu(curr) )
> >>>>              return X86EMUL_OKAY;
> >>>>          if ( (rdmsr_safe(MSR_AMD64_NB_CFG, temp) != 0) ||
> >>>> +             /*
> >>>> +              * TODO: this is broken.  What happens when dom0 is pinned 
> >>>> but
> >>>> +              * can't see the full system?  CF8_EXT probably ought to 
> >>>> be a
> >>>> +              * Xen-owned setting, and made symmetric across the system.
> >>>> +              */
> >>> I would assume CF8_EXT would be symmetric across the system, specially
> >>> given that it seems to be phased out and only used in older AMD
> >>> families that where all symmetric?
> >> The CF8_EXT bit has been phased out.  The IO ECS functionality still 
> >> exists.
> >>
> >> But yes, the more I think about letting dom0 play with this, the more I
> >> think it is a fundamentally broken idea...  I bet it was from the very
> >> early AMD Fam10h days where dom0 knew how to turn it on, and Xen was
> >> trying to pretend it didn't have to touch any PCI devices.
> > It seems to me Xen should set CF8_EXT on all threads (when available)
> > and expose it to dom0, so that accesses using pci_{conf,write}_read()
> > work as expected?
> 
> It's per northbridge in the system, not per thread.  Hence needing the
> spinlock protecting the CF8/CFC IO port pair access, and why MMCFG is
> strictly preferable.

So just setting CF8_EXT_ENABLE on MSR_AMD64_NB_CFG by the BSP should
be enough to have it enabled?  I expect all other threads will see the
bit as set in the MSR then.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.