From: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
To: Stefano Stabellini <sstabellini@kernel.org>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
"Oleksandr Andrushchenko" <Oleksandr_Andrushchenko@epam.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>, "Wei Liu" <wl@xen.org>,
"George Dunlap" <george.dunlap@citrix.com>,
"Julien Grall" <julien@xen.org>, "Paul Durrant" <paul@xen.org>,
"Kevin Tian" <kevin.tian@intel.com>
Subject: Re: [RFC PATCH 05/10] xen: pci: introduce reference counting for pdev
Date: Mon, 20 Feb 2023 22:00:04 +0000 [thread overview]
Message-ID: <87mt58yp3w.fsf@epam.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2301261604370.1978264@ubuntu-linux-20-04-desktop>
Hi Stefano,
Thank you for the review
Stefano Stabellini <sstabellini@kernel.org> writes:
> On Wed, 31 Aug 2022, 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.
>>
>> Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
>
> tabs everywhere in this patch
>
Oh, yes, sorry. I asked sometime ago, and want to ask again: instead of
adding EMACS magic into each file, we can put one .dir-locals.el file with
basically the same config in xen/ directory. This will accomplish two
things:
- there will be no need to add EMACS magic strings into each new file
- the same config will apply to files that do not have magic
strings. Files with different coding style rules can be filtered by
code in .dir-locals.el and/or by strategically placed files in
sub-directories.
I am happy to hear maintainers opinion about this.
>> ---
>>
>> - Jan, can I add your Suggested-by tag?
>> ---
>> xen/arch/x86/hvm/vmsi.c | 2 +-
>> xen/arch/x86/irq.c | 4 +
>> xen/arch/x86/msi.c | 41 ++++++-
>> xen/arch/x86/pci.c | 4 +-
>> xen/arch/x86/physdev.c | 17 ++-
>> xen/common/sysctl.c | 5 +-
>> xen/drivers/passthrough/amd/iommu_init.c | 12 ++-
>> xen/drivers/passthrough/amd/iommu_map.c | 6 +-
>> xen/drivers/passthrough/pci.c | 131 +++++++++++++++--------
>> xen/drivers/passthrough/vtd/quirks.c | 2 +
>> xen/drivers/video/vga.c | 10 +-
>> xen/drivers/vpci/vpci.c | 6 +-
>> xen/include/xen/pci.h | 18 ++++
>> 13 files changed, 201 insertions(+), 57 deletions(-)
>>
>> diff --git a/xen/arch/x86/hvm/vmsi.c b/xen/arch/x86/hvm/vmsi.c
>> index 75f92885dc..7fb1075673 100644
>> --- a/xen/arch/x86/hvm/vmsi.c
>> +++ b/xen/arch/x86/hvm/vmsi.c
>> @@ -912,7 +912,7 @@ int vpci_msix_arch_print(const struct vpci_msix *msix)
>>
>> spin_unlock(&msix->pdev->vpci->lock);
>> process_pending_softirqs();
>> - /* NB: we assume that pdev cannot go away for an alive domain. */
>> +
>> if ( !pdev->vpci || !spin_trylock(&pdev->vpci->lock) )
>> return -EBUSY;
>> if ( pdev->vpci->msix != msix )
>> diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c
>> index cd0c8a30a8..d8672a03e1 100644
>> --- a/xen/arch/x86/irq.c
>> +++ b/xen/arch/x86/irq.c
>> @@ -2174,6 +2174,7 @@ int map_domain_pirq(
>> msi->entry_nr = ret;
>> ret = -ENFILE;
>> }
>> + pcidev_put(pdev);
>
> I think it would be better to move pcidev_put just after done:
I'd love to do this, but pdev is declared inside "if" block while "done:"
is outside of this scope. I can move pdev into outer scope if you believe
that it will be better.
[...]
All other comments were taken into account.
next prev parent reply other threads:[~2023-02-20 22:00 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 14:10 [RFC PATCH 00/10] Rework PCI locking Volodymyr Babchuk
2022-08-31 14:10 ` [RFC PATCH 01/10] xen: pci: add per-domain pci list lock Volodymyr Babchuk
2023-01-26 23:18 ` Stefano Stabellini
2023-01-27 8:01 ` Jan Beulich
2023-02-14 23:38 ` Volodymyr Babchuk
2023-02-15 9:06 ` Jan Beulich
2022-08-31 14:10 ` [RFC PATCH 03/10] xen: pci: introduce ats_list_lock Volodymyr Babchuk
2023-01-26 23:56 ` Stefano Stabellini
2023-01-27 8:13 ` Jan Beulich
2023-02-17 1:20 ` Volodymyr Babchuk
2023-02-17 7:39 ` Jan Beulich
2022-08-31 14:10 ` [RFC PATCH 02/10] xen: pci: add pci_seg->alldevs_lock Volodymyr Babchuk
2023-01-26 23:40 ` Stefano Stabellini
2023-02-28 16:32 ` Jan Beulich
2022-08-31 14:10 ` [RFC PATCH 04/10] xen: add reference counter support Volodymyr Babchuk
2023-02-15 11:20 ` Jan Beulich
2023-02-17 1:56 ` Volodymyr Babchuk
2023-02-17 7:53 ` Jan Beulich
2023-02-19 22:34 ` Volodymyr Babchuk
2022-08-31 14:11 ` [RFC PATCH 05/10] xen: pci: introduce reference counting for pdev Volodymyr Babchuk
2023-01-27 0:43 ` Stefano Stabellini
2023-02-20 22:00 ` Volodymyr Babchuk [this message]
2023-02-28 17:06 ` Jan Beulich
2022-08-31 14:11 ` [RFC PATCH 06/10] xen: pci: print reference counter when dumping pci_devs Volodymyr Babchuk
2022-08-31 14:11 ` [RFC PATCH 09/10] [RFC only] xen: iommu: remove last pcidevs_lock() calls in iommu Volodymyr Babchuk
2023-01-28 1:36 ` Stefano Stabellini
2023-02-20 0:41 ` Volodymyr Babchuk
2023-02-28 16:25 ` Jan Beulich
2022-08-31 14:11 ` [RFC PATCH 07/10] xen: pci: add per-device locking Volodymyr Babchuk
2023-01-28 0:56 ` Stefano Stabellini
2023-02-20 22:29 ` Volodymyr Babchuk
2023-02-28 16:46 ` Jan Beulich
2022-08-31 14:11 ` [RFC PATCH 08/10] xen: pci: remove pcidev_[un]lock[ed] calls Volodymyr Babchuk
2023-01-28 1:32 ` Stefano Stabellini
2023-02-20 23:13 ` Volodymyr Babchuk
2023-02-21 9:50 ` Jan Beulich
2023-03-09 1:22 ` Volodymyr Babchuk
2023-03-09 9:06 ` Jan Beulich
2023-02-28 16:51 ` Jan Beulich
2022-08-31 14:11 ` [RFC PATCH 10/10] [RFC only] xen: pci: remove pcidev_lock() function Volodymyr Babchuk
2022-09-06 10:32 ` [RFC PATCH 00/10] Rework PCI locking Jan Beulich
2023-01-18 18:21 ` Julien Grall
2023-01-19 9:47 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mt58yp3w.fsf@epam.com \
--to=volodymyr_babchuk@epam.com \
--cc=Oleksandr_Andrushchenko@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=kevin.tian@intel.com \
--cc=paul@xen.org \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.