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

Re: [PATCH v13 01/14] vpci: use per-domain PCI lock to protect vpci structure


  • To: Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Tue, 13 Feb 2024 11:58:18 -0500
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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=cF4kq4/gZXL/ma7LW3N023XPKQzfYSmH+abcvn4PgpU=; b=gvb9b+hlJVX4b7SoMCdHcB6WJlXukZfdXpAdVxrCgyqmR4EtGJfN9gk+jgaf3vdj/WLFQ+yc4Sdl01k15J4heY5SvUDOxLxbAvHiOfx4zCBW8zHJ4VQfF5sHFlPV7H8qL+Y1KHNTkUzcmd+BMvFAFtGGp99SSRFJkBDwUdc+3TGzmi4DElKM7gslxrmXnsasHYYv8q7w0MR3s6jcv4SP5PGgQ70i6cDLcCwew5uBwPwzOyYUI0ivf6p2AX7EmSBIcaQdvuhRWPO368D2K456+QMLX1LsTZd3Hq9yKGB980s3bGf9m0lL0h3X4rU+ikWJQcLrTvsP5+nZqNX3udBdZA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FMvpHEGFBJyCWvdLFWcxeGU6T7rjS/krUXHMqzEEM8mekmoFwsSZgbOmHCDjSuRi5UjwBJhlcvveftArZ7MWrQkuPx+Emf8yKmt7DITw9r7pfdYdzXJAZwRSwlGQDbc+mjhHuLg8A8knqyJ2Jt+vJMJiirlKT4H4R+ykdyPgKT58IsOxNOgYYN2AdYv/9MHKWswGK4euHP5Yc6SOxHAO5k/ZhivrSBSOPee/QY2ncWw710N+KvrAOMZNT7lby4Ozv6OtEG8Zr5HUucGBwAkXoOSfOnPfKm7NzL/ganGAEF7IKw4HpENXBuulmywadFj+9qRUow6v1vNq57kyliaifA==
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Jun Nakajima <jun.nakajima@xxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>
  • Delivery-date: Tue, 13 Feb 2024 16:58:28 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2/13/24 04:05, Jan Beulich wrote:
> On 13.02.2024 10:01, Roger Pau Monné wrote:
>> On Tue, Feb 13, 2024 at 09:44:58AM +0100, Jan Beulich wrote:
>>> On 13.02.2024 09:35, Roger Pau Monné wrote:
>>>> On Fri, Feb 02, 2024 at 04:33:05PM -0500, Stewart Hildebrand wrote:
>>>>> --- a/xen/include/xen/sched.h
>>>>> +++ b/xen/include/xen/sched.h
>>>>> @@ -462,7 +462,8 @@ struct domain
>>>>>  #ifdef CONFIG_HAS_PCI
>>>>>      struct list_head pdev_list;
>>>>>      /*
>>>>> -     * pci_lock protects access to pdev_list.
>>>>> +     * pci_lock protects access to pdev_list. pci_lock also protects 
>>>>> pdev->vpci
>>>>> +     * structure from being removed.
>>>>>       *
>>>>>       * Any user *reading* from pdev_list, or from devices stored in 
>>>>> pdev_list,
>>>>>       * should hold either pcidevs_lock() or pci_lock in read mode. 
>>>>> Optionally,
>>>>> @@ -628,6 +629,18 @@ struct domain
>>>>>      unsigned int cdf;
>>>>>  };
>>>>>  
>>>>> +/*
>>>>> + * Check for use in ASSERTs to ensure that:
>>>>> + *   1. we can *read* d->pdev_list
>>>>> + *   2. pdevs (belonging to this domain) do not go away
>>>>> + *   3. pdevs (belonging to this domain) do not get assigned to other 
>>>>> domains
>>>>
>>>> I think you can just state that this check ensures there will be no
>>>> changes to the entries in d->pdev_list, but not the contents of each
>>>> entry.  No changes to d->pdev_list already ensures not devices can be
>>>> deassigned or removed from the system, and obviously makes the list
>>>> safe to iterate against.
>>>>
>>>> I would also drop the explicitly mention this is intended for ASSERT
>>>> usage: there's nothing specific in the code that prevents it from
>>>> being used in other places (albeit I think that's unlikely).
>>>
>>> But pcidevs_locked(), resolving to spin_is_locked(), isn't reliable. The
>>> assertion usage is best-effort only, without a guarantee that all wrong
>>> uses would be caught.
>>
>> Do we want to protect this with !NDEBUG guards then?
> 
> Yes, that would look to be desirable.

We will then also need a definition of pdev_list_is_read_locked() in the
#else case so we don't risk running into "error: implicit declaration of
function 'pdev_list_is_read_locked'".

Such a definition might look like:

#define pdev_list_is_read_locked(d) ({ (void)d; ASSERT_UNREACHABLE(); false; })

so that we still evaluate d exactly once in the NDEBUG case.

>>>>> + * This check is not suitable for protecting other state or critical 
>>>>> regions.
>>>>> + */
>>>>> +#define pdev_list_is_read_locked(d) ({                           \
>>>>
>>>> I would be tempted to drop at least the '_read_' part from the name,
>>>> the name is getting a bit too long for my taste.
>>>
>>> While I agree with the long-ish aspect, I'm afraid the "read" part is
>>> crucial. As a result I see no room for shortening.
>>
>> OK, if you think that's crucial then I'm not going to argue.
>>
>>>>> +        struct domain *d_ = (d);                                 \
>>>>
>>>> Why do you need this local domain variable?  Can't you use the d
>>>> parameter directly?
>>>
>>> It would be evaluated then somewhere between 0 and 2 times.
>>
>> It's ASSERT code only, so I don't see that as an issue.
> 
> Fair point.
> 
>>  Otherwise d_ needs to be made const.
> 
> Indeed, but for assert-only code I agree the option is slightly better,
> ideally suitably commented upon.

Is "the option" here referring to making d_ const, or using d directly
(with suitable comment)?



 


Rackspace

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