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

Re: [PATCH v3 1/6] xen: add reference counter support


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Fri, 17 Mar 2023 11:05:32 +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=09Qnpf0epWFhf1C2bypJQVHdua/AjLFMIs9olYFn/68=; b=N82//oD2MEwjE4xjuTs88T863PpssQXrKoavJM2JXm6q2ZmNBkm0KnxC7olp7DRTUOTY2eh8he5M8OngyHfsxhN8FllK3gbuLTLvM9si6iQAMhFBddszmcaHAoEQrIchaBDtZVgxZ3GsT2C9g7BtnuK8sUHACuIkEISKwdYts2ZFPGNRctvnAVUGs49WcM7gLlHzSlU6VUmaRrLhvW6NB+74GkxQh8ZZNO6Oq8eD8yWdypM+DLxOY23L2SN0iprVHoSRrCJUBAf+MlW+Lh+MuC0ALKPBeUkmC2WsmszKBFey4qql+TzcbJJAJ6C/tQ2V75cMpDiWbjuwfRJ+m991Xw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jgJ8gkL4FpTaBpPLNjSB7U6UCu4z2KZCpVCMAMK1S0nDmbOS68XhsF6v8Gqw2csoq9uGy9H5+oeQnWJ7wxfo9ZvU06lcMdYytZHgUOygwYO1CHxDH65s1JazzM96SkT5qJvvpw3QAKO3gGl2Kmvp35+FYnXEPvF6YCUufa3kqUwaLDXezi10P7nElxtO7LZnrDYPWRZGQO5EasAqo9jr90W8f/2XEEGsM0/Ys4NFWOHH5PMIF28EwtizoaHL6TjYc7y6NUYhp/qggen+M4cNwC4wX4LVrhQnq7d0MnbB8BukP1sLc+M6+7F/JyTPxFak7WUPddjrVAhH0+d7cE35cQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Fri, 17 Mar 2023 10:05:57 +0000
  • Ironport-data: A9a23:ezuGvqlwRPYSex+8ANwFM4zo5gxjJ0RdPkR7XQ2eYbSJt1+Wr1Gzt xIZWD+CaP2IYmv9eNpzaY3n8E1S6JTXm9RmHQM5/iExFyMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icfHgqH2eIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE4p7aSaVA8w5ARkPqgQ5QCGzhH5MbpETU2PByqgKmVrNrbSq 9brlNmR4m7f9hExPdKp+p6TnpoiG+O60aCm0xK6aoD66vRwjnVaPpUTbZLwXXx/mTSR9+2d/ f0W3XCGpaXFCYWX8AgVe0Ew/yiTpsSq8pefSZS0mZT7I0Er7xIAahihZa07FdRwxwp5PY1B3 eY0MW4zale4vd7o462bR8gvlt8fIta+aevzulk4pd3YJdAPZMifBoD1v5pf1jp2gd1SF/HDY cZfcSBocBnLfxxIPBEQFY46m+CrwHL4dlW0qnrM/fZxvzeVk1c3iee2WDbWUoXiqcF9hEGXq 3iA523kKhobKMae2XyO9XfEaurnxHujBttOS+3inhJsqFqs12E4JR0Wb1qYhd+grRC3XPdwF kNBr0LCqoB3riRHVOLVXRe1vXqFtR40QMdLHqsx7wTl4rrZ5UOVC3YJShZFacc6r4kmSDoyz FiLktj1Qzt1v9W9S2+Z97qShSO/P24SN2BqTTQfUQIP7t3noYcyphHCVNBuFOiylNKdMS706 yCHqm45nbp7pfAM06K37FXWmQWGr5LCThM2zgjPV2fj5QR8DLNJfKSt4FnfqPNfdoCQSwHdu GBewpfFqucTEZuKiSqBBv0XG62k7OqENzuahkNzG54m9HKm/HvLkZ1s3QyS7XxBaq4sEQIFq meJ0e+NzPe/5EeXUJI=
  • Ironport-hdrordr: A9a23:3zH+Hqxzv+pNORl9DaB8KrPwl71zdoMgy1knxilNoNJuE/Bw8P re+sjztCWE7wr5PUtLpTnuAsS9qB/nmaKdpLNhXotLsmHdyReVxcJZnPbfKwSJIVyAygcl79 YfT0EdMr3N5ClB/KLHCVKDYq8dKbC8mcjCuQ6d9QYOcegNUc5dBmxCe2Om+yNNKjWuLKBJZa a0145opyeAZX9SVciyHH8DNtKz3eHjpdbJYQMmGxVi0wWFjSqp5LnmeiLopSs2YndgwaoC7W OAqADy5ryiv/anjjfQ2nTe9Y4+oqqQ9vJzQOKNl+kIIXHXhgGkaJ8JYcz7gAwI
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Thu, Mar 16, 2023 at 05:56:00PM +0100, Jan Beulich wrote:
> On 16.03.2023 17:48, Roger Pau Monné wrote:
> > On Thu, Mar 16, 2023 at 05:43:18PM +0100, Jan Beulich wrote:
> >> On 16.03.2023 17:39, Roger Pau Monné wrote:
> >>> On Thu, Mar 16, 2023 at 05:32:38PM +0100, Jan Beulich wrote:
> >>>> On 16.03.2023 17:19, Roger Pau Monné wrote:
> >>>>> On Tue, Mar 14, 2023 at 08:56:29PM +0000, Volodymyr Babchuk wrote:
> >>>>>> +static inline void refcnt_get(refcnt_t *refcnt)
> >>>>>> +{
> >>>>>> +    int old = atomic_add_unless(&refcnt->refcnt, 1, 0);
> >>>>>
> >>>>> Occurred to me while looking at the next patch:
> >>>>>
> >>>>> Don't you also need to print a warning (and saturate the counter
> >>>>> maybe?) if old == 0, as that would imply the caller is attempting
> >>>>> to take a reference of an object that should be destroyed? IOW: it
> >>>>> would point to some kind of memory leak.
> >>>>
> >>>> Hmm, I notice the function presently returns void. I think what to do
> >>>> when the counter is zero needs leaving to the caller. See e.g.
> >>>> get_page() which will simply indicate failure to the caller in case
> >>>> the refcnt is zero. (There overflow handling also is left to the
> >>>> caller ... All that matters is whether a ref can be acquired.)
> >>>
> >>> Hm, likely.  I guess pages never go away even when it's refcount
> >>> reaches 0.
> >>>
> >>> For the pdev case attempting to take a refcount on an object that has
> >>> 0 refcounts implies that the caller is using leaked memory, as the
> >>> point an object reaches 0 it supposed to be destroyed.
> >>
> >> Hmm, my thinking was that a device would remain at refcnt 0 until it is
> >> actually removed, i.e. refcnt == 0 being a prereq for pci_remove_device()
> >> to be willing to do anything at all. But maybe that's not a viable model.
> > 
> > Right, I think the intention was for pci_remove_device() to drop the
> > refcount to 0 and do the removal, so the refcount should be 1 when
> > calling pci_remove_device().  But none of this is written down, so
> > it's mostly my assumptions from looking at the code.
> 
> Could such work at all? The function can't safely drop a reference
> and _then_ check whether it was the last one. The function either has
> to take refcnt == 0 as prereq, or it needs to be the destructor
> function that refcnt_put() calls.

But then you also get in the trouble of asserting that refcnt == 0
doesn't change between evaluation and actual removal of the structure.

Should all refcounts to pdev be taken and dropped while holding the
pcidevs lock?

I there an email (outside of this series) that contains a description
of how the refcounting is to be used with pdevs?

Thanks, Roger.



 


Rackspace

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