[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: Thu, 16 Mar 2023 17:56:00 +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=EoYtS6FIFHj0yhJbGSZSkmElypIr8mg/xeYqKVNiFe0=; b=jx2F5dfAcBcpqp9Xr8vI7kRW66cDE9w1iXLZHepfY12J3zlTYkWz6fNpqqP7iL2LTxGteEiM9Om4Wfu9rF62mzkqyiyKspbJKVQh2lbu5ECCxnS0vzVRSYDqSW5fZHlu/pZcUNF4QCX64rcQuPNO7uduQIfDeoaCh4AGLa4TVYA0qe3xyGmRAGPocwXgWdQFl80jvG6f65qAaOd/Ggm7F1NkG4p/kO7nTKJ/UdkdiOyIBnG4t6J5bPatc4nxafP07o+cieFVYP2Nrz5xMvjChXpnOecQiuV5y5Sb7vf8zlAvuSPXa7sWRz997ovHZQokX1IPoco887bmT4tp+kbS7w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wh5VfUGhlcgD5XOnXGOgdXOm0P+BfKRGbIxsN7j3prYytq5SywjqHrFAWi1q53duxSDQYFtbU0H8x3gDKoTUxWt4bfuXr/hsnUctCwxpx1BeLiVp2BRgiNiexx5qVtLTNCo/bSTC78pKNfH9o3YOMeVy3fNwVIHbcxslqKQx0CY8zUrz6ziVFPer0Ce9h74CoP5xMJdQ/5rRF6h0Na4aKudqc5y7datJ132P1Ew2NDfTTuowyTuI6QBVePkjCymBBlo9upsB63lvViDGg9INQPzynDyVC7ymkhEs96mY7HVopnj2rgS1r/eXOwRcC/dHMutqOI3UPE2JVOExy+n46Q==
  • 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: Thu, 16 Mar 2023 16:56:19 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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.

Jan



 


Rackspace

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