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

Re: [RFC PATCH 05/10] xen: pci: introduce reference counting for pdev


  • To: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 28 Feb 2023 18:06:36 +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=AUwJSy2E/tJ9qFnJ2LTSzt8ak4265XZlhUlUeQR8tjE=; b=D1gDFYpiEAvraLfNGt3rM9Okf/mLyk+AE1KiT4bdxorAFvL+FahDnzo9fL7xD+dr2pIBp+DOw9CoSIXBoXXEG5eKCKWV0CuptDfijUf+bgyJ1sPTcqlmHw2X5jVt0X1FTuT2nf5XsFhzt7xQ+UkpARGsA2XUFlP29/8lzevzEEWYRsZ9vKTnSOyBM8oMies6aMY8pc4FBe3G5LJM9JkrliuGEi470KEn/VRKpyTXd7eBfMeSKMY4LSRmJyIJxMaOSN4c0pmMN/Dup1j4Fz9d18lUxMAJWWQC9AbX3fkmyi9BqAFZUNc36exbOHHbFhlXd0q3wGk4LBxOdIkuKd6UXw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DmjeQHyZ5HqYzSGGgg5qnUJ0tlM/EnPOBhCjDFg25H0HxXlJ+vo/29GEl4vCWvl8uUv6LeLuGtENlgvtABwkICZk17N4vsGvpnnQH8avAde7MV0WU/6jd1LjUbwfovrvlhPQaM3ynBGXwxKOB4ewQnUo0qNLdoYTa84JBNt6aR66MreJ94xVILHx9RFmYNmWCjf8SgE2pjL09RcSunlGn1Q7PyC/Bs3LE31pSShZmFIoy1cBFrJc29/N4gTbfevBMSzpKpPrhsyygAurgI+Ws1agu7fN5eTWf/5QRc12WiSHBaHf6euBP1hkTYZA3CV0onyK4SOdFoU6lBO6S4zPNA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 28 Feb 2023 17:06:54 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 31.08.2022 16:11, Volodymyr Babchuk wrote:
> Prior to this change, lifetime of pci_dev objects was protected by global
> pcidevs_lock(). We are going to get if of this lock, so we need some
> other mechanism to ensure that those objects will not disappear under
> feet of code that access them. Reference counting is a good choice as
> it provides easy to comprehend way to control object lifetime with
> better granularity than global super lock.
> 
> This patch adds two new helper functions: pcidev_get() and
> pcidev_put(). pcidev_get() will increase reference counter, while
> pcidev_put() will decrease it, destroying object when counter reaches
> zero.
> 
> pcidev_get() should be used only when you already have a valid pointer
> to the object or you are holding lock that protects one of the
> lists (domain, pseg or ats) that store pci_dev structs.
> 
> pcidev_get() is rarely used directly, because there already are
> functions that will provide valid pointer to pci_dev struct:
> pci_get_pdev() and pci_get_real_pdev(). They will lock appropriate
> list, find needed object and increase its reference counter before
> returning to the caller.
> 
> Naturally, pci_put() should be called after finishing working with a
> received object. This is the reason why this patch have so many
> pcidev_put()s and so little pcidev_get()s: existing calls to
> pci_get_*() functions now will increase reference counter
> automatically, we just need to decrease it back when we finished.
> 
> This patch removes "const" qualifier from some pdev pointers because
> pcidev_put() technically alters the contents of pci_dev structure.

I wonder if you have so few "get"s because in some cases references
would be needed, but aren't being obtained. As a rule of thumb I'd
expect any entity storing a pointer in a long-lived data structure
to obtain a ref first. And we have quite a few struct fields pointing
to devices. I'd also expect a reference to be held when a device is
e.g. put on a domain's list. This would then likely mean that for
example in deassign_device() (or maybe pci_add_device()) you wouldn't
drop the ref in the success case, but instead the ref would transfer
to the domain the device is added to.

> ---
> 
> - Jan, can I add your Suggested-by tag?

Sure, why not.

Jan



 


Rackspace

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