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

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


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 4 Apr 2023 14:27:36 +0100
  • 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=Nl1vY8U0d5COAPbhowL7ndLBAeSmFOBTksyjV33zWzE=; b=Og5uW2nJZ20lpsCTDjtjS5UcQfCMOJ5SvR0/DeQETv7nRgqeLhfMl1W81WPGypbxXQygxf1sNyr3/n7mq6qB/CYgN1Sz6QOF/m5A34eS+eHoCPHsL7x3KnxLRFm9pqmM81usvIr5tqGu/ei2S1m/YUMBHwXO8+pKBiFCKaQRD5ZeBqCjF/8p4iV1UVvnRrnCq9VXapGA03zmW8vPgkB0u0V+kW2O2+KXkV70MZvcxW+gq82IuZPPPGDpOPPsxDSP3UtiwLjxSWKuDHUCp/hnNN4Wwj8Jv1Zo8eVTbY1lqFcYzbVpEhrMjnNi5cMFbr8Pv5YX3j90kK3Ixe9m/UVbQA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PmjaESlC89RsgFZZdc6/0rXISbvxkADkFhu0Oof7SCM/8ems2hd1mTV3R9pSXET4227gzI/5ZGJh+cQy9LrUWDkFbsJb8SKnoNm49zNP6Bws3y6169UVCq0c/ax+vBhCZ8hFU9FgFTg0Wv0GFDuBJJEK9uGLg0bvjB2wYrJbYvQ5GrgCkEqBrMDdXFnS6MvLFZ7qG/CZcV9CoIkyt0kstoIZTg2gKR2SEGm24MM5L/yrR8lU9VwLjzDGflc5+QZ1uFZ4yMa29Ir6IhPh4qIzmFcJkiVqEJ2ZoB5ceAw3OBS8tyoN3lDYcUysRPXLnn4xL5EsnYfEX1BXr8mzrVfE8A==
  • 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 13:28:12 +0000
  • Ironport-data: A9a23:sddWT6LYDtlHsemgFE+R/JQlxSXFcZb7ZxGr2PjKsXjdYENS1TwCz mYaCmyCbqvYYTPwfd9ybNi39EoC6JKAnNMyHFFlqX01Q3x08seUXt7xwmUcnc+xBpaaEB84t ZV2hv3odp1coqr0/0/1WlTZhSAgk/rOHvykU7Ss1hlZHWdMUD0mhQ9oh9k3i4tphcnRKw6Ws Jb5rta31GWNglaYCUpJrfPTwP9TlK6q4mhA4gRiPakjUGL2zBH5MrpOfcldEFOgKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0hK6aYD76vRxjnVaPpIAHOgdcS9qZwChxLid/ jnvWauYEm/FNoWU8AgUvoIx/ytWZcWq85efSZSzXFD6I+QrvBIAzt03ZHzaM7H09c53WDxR1 qQ4EglKQQuG1+yE+YjiE/BF05FLwMnDZOvzu1lG5BSAVLMKZM6GRK/Ho9hFwD03m8ZCW+7EY NYUYiZuaxKGZABTPlAQC9Q1m+LAanvXKmUE7g7K4/dopTGMlGSd05C0WDbRUvWMSd9YgQCzo WXe8n6iKhobKMae2XyO9XfEaurnxHulBtNNTOLjnhJsqB6N+ExUGSMab2aEhaiclUyQfMJ0E GVBr0LCqoB3riRHVOLVTxC+5XKJoBMYc95RCPEhrhGAzLLO5ASUDXRCSSROAPQEnsIrQT0h1 neSgsjkQzdotdW9Vna15rqS6zSoNkAowXQqYCYFSU4J5oflqYRq1xbXFI88SOiyk8H/Hiz2z 3aSti8iir4PjMkNkaKm4VTAhDHqrZ/MJuIo2jjqsquexlsRTOaYi0aAszA3Md4owF6lc2S8
  • Ironport-hdrordr: A9a23:E9U/sK5tmKHRMlG8JAPXwPvXdLJyesId70hD6qkmc20tTiX+rb HKoB17726XtN5yMEtLpTnuAsS9qB/nmaKdgrNhXotKPjOGhILyFvAF0WKK+VSJcBEWkNQz6U 4KSchD4bPLY2STIqzBkXGF+3pL+qjizEgI792uqEtQcQ==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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.

>>>>  
>>>>  #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.

~Andrew



 


Rackspace

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