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

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


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 17 Mar 2023 15:46:14 +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=v0PAxUohAInL4ozQC8nVKLmfRg7BMPInBq6Q9Qwt/mc=; b=n4xRRpjw6cVg/9QCj9RID+gKhF8n99li+vAxbTcZlU0RSPVa2LezdIUeLPoheQ/wDiIjbScc0kW6nXIHGrPhMD/5TszjOJ9hAQz1mpaEgeOHXZEp2LEBWWpd1EtjpoBP5Qk5n/nFqAvfQKIWtypbCY8z8ueGVsSuMLANbGJEBRjc8LQKLfTjVAG6RDsUEHsS8O0ojr883eaqXrrJKVYrBnub78P8xlCN7kiJV9mZesbFVWiHCfgmlsd95Ha02VgquKVdOuG4n1OMUy/SqorebJMHCSknl/C0/EI8Xvzw+TbWhGDQTtncQlratYeZVYqQ0eQ4vbwGP8py9iom49VQ4A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YyXj/hnm9ZwY3kwNuQDjIzvH3ci+f+ID3Mo5UkbFSd+KSK/kohZkViJoC18LfV6c5eGMR7BXVA4trA+8zyqdpWPeLQXeaZFyF2dSw2FayAoZWBQNO7AytqHzsqAd3k3tzXnzFed4JL8deK2nOX+WlWRutqo8zO/pujGUfdv9GLcZdrWP16VgY89zc5GFmBcvpRrhaztHnK1xHMwRCqYXeucINCQe4TlpTRgl47FgodKO7D293eJO1lhpyEfYdu+p8R3NXdygdV5FgwuPpSArkECO3PyFZsOf6HJ79cmKxjmntfFOouzF9FhJ3ok432CRcg1ejOn/lqoHzpK1TBRbTQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.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 14:46:23 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 17.03.2023 11:05, Roger Pau Monné wrote:
> 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?

I'm not aware of one. The intentions indeed need outlining somewhere.

Jan



 


Rackspace

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