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

Re: [PATCH 3/3] x86/pci: Fix racy accesses to MSI-X Control register


  • To: David Vrabel <dvrabel@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 13 Dec 2022 12:50:02 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=ssesvDldU0t7qmLV4JTp66rx59p48v+0v6QU8SFGCX8=; b=dkkk1zCCWOyNcT6v9OojVNokqm7RVOfJhhvARJvQvexzcX+xZsb7nlvRxHRgnOkuEvxzkwTf2oq4Bfv06SHix2jJVACjiUNipQ+ItXH/aGxhrtzCoWne/LGkQC5ahE4/nJNkKugrhMlasmqkvkZY4mOyh660u3ddGDeDKpHwIVe7lphUU1OXgzNTJW/4Oi7PKNDwXdWrC9pw2xOQNBibWLm/3MnnwLVVoMFd6bNXxYaKYdAIKPJeWXMHh31uTfS3pRjlFyprVC1nc4WEa/0zrnOoxMvC9XzCbPsAktraO0kukJzJx6x6d9VfrVCIYPL1Du+XwKJx8tt4/oSHROVp4A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cfGI0spFGbDr/w8nO6dfQtv6PTSZp7iF2JTVi1fDckBcCxKtLtym6lXR0I89VGz7Fv1Oes6mp7OaPj+y75VN+0/uxu/G+qNe2N8VGT/CckufFvgFUhaqZkPi4AaRDBUqjXXDiWc0ugBy0NQydNL4VSjMyo5J4R0rhDmh2IKlD45HLBiihCJ08DNbn6ChL7BN0ay2P5jXeC5fNJIgpEVQkmtnzUBI4AgdA8Bkj9XIaOR1hReAnSlXHbDMibmRP/jigbMoHiO0VpWsUVE8Kp6+F5BizjG6+te6V6RvZwsStd87CdyvkWls5SIYSYocMB6EVdQum4npidL9AOZnKw5jHQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, David Vrabel <dvrabel@xxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 13 Dec 2022 11:50:14 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 13.12.2022 12:34, David Vrabel wrote:
> On 12/12/2022 17:04, Jan Beulich wrote:
>> On 10.11.2022 17:59, David Vrabel wrote:
>>>
>>> --- a/xen/arch/x86/include/asm/msi.h
>>> +++ b/xen/arch/x86/include/asm/msi.h
>>> @@ -237,7 +237,10 @@ struct arch_msix {
>>>       int table_refcnt[MAX_MSIX_TABLE_PAGES];
>>>       int table_idx[MAX_MSIX_TABLE_PAGES];
>>>       spinlock_t table_lock;
>>> +    spinlock_t control_lock;
>>>       bool host_maskall, guest_maskall;
>>> +    uint16_t host_enable;
>>
>> If you want to keep this more narrow than "unsigned int", then please
>> add a BUILD_BUG_ON() against NR_CPUS, so the need to update the field
>> can be easily noticed (in some perhaps distant future).
> 
> This is only incremented:
> 
> - while holding the pci_devs lock, or
> - while holding a lock for one of the associated IRQs.

How do the locks held matter here, especially given that - as iirc you say
in the description - neither lock is held uniformly?

> Since there are at most 4096 MSI-X vectors (and thus at most 4096 IRQs), 
> the highest value this can be (even with >> 4096 PCPUs) is 4097, thus a 
> uint16_t is fine.

Where's the 4096 coming from as a limit for MSI-X vectors? DYM 2048, which
is the per-device limit (because the qsize field is 11 bits wide)? If so,
yes, I think that's indeed restricting how large the number can get.

>>> +static void msix_update_unlock(struct pci_dev *dev, unsigned int pos, 
>>> uint16_t control)
>>> +{
>>> +    uint16_t new_control;
>>> +    unsigned long flags;
>>> +
>>> +    spin_lock_irqsave(&dev->msix->control_lock, flags);
>>> +
>>> +    dev->msix->host_enable--;
>>> +
>>> +    new_control = control & ~(PCI_MSIX_FLAGS_ENABLE | 
>>> PCI_MSIX_FLAGS_MASKALL);
>>> +
>>> +    if ( dev->msix->host_enable || dev->msix->guest_enable )
>>> +        new_control |= PCI_MSIX_FLAGS_ENABLE;
>>> +    if ( dev->msix->host_maskall || dev->msix->guest_maskall || 
>>> dev->msix->host_enable )
>>> +        new_control |= PCI_MSIX_FLAGS_MASKALL;
>>
>> In particular this use of "host_enable" suggests the field wants to be
>> named differently: It makes no sense to derive MASKALL from ENABLE
>> without it being clear (from the name) that the field is an init-time
>> override only.
> 
> I think the name as-is makes sense. It is analogous to the host_maskall 
> and complements guest_enable. I can't think of a better name, so what 
> name do you suggest.

I could only think of less neat ones like host_enable_override or
forced_enable or some such. If I had any good name in mind, I would
certainly have said so.

Jan



 


Rackspace

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