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

Re: [PATCH v2 1/4] pci: add rwlock to pcidevs_lock machinery


  • To: Wei Chen <Wei.Chen@xxxxxxx>
  • From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Date: Wed, 20 Jul 2022 18:43:41 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.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=eZdKd5ovZyiwO036SsIMsoGHufaPZnO4eryczz+BMfI=; b=deKkMGrYbxHumPIbciS9bQWuYHvI0N4eG5U9QJLKo9HlVUujgHKwmOPMV0BOWBTGTUn6zAduc8vs7IqIaTAma7+5H3ydtYneM4BKj2dOYJFKL3naY5W9r/v2VGKGsmH9JitfAmNKOmD49SIobjZLGHFw4NwIAA9mzAzHlSga7r1r6b3yfsfK3iwOfvc3vXVJUgRkeCf0N6nEp6uyj7UN6LfqjYe1XlMv9BYt+/Hqpzt/bJQKJsjQT8lZQ7ciRutLnFy+RW32MFj6sBpc8pS890RZmVciU8U23tjqOL1gnhTThggzhXJ2JJtVG5/JRrR5KkRii2RjUQatwFqfs1qvhw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ErM32AbG+hCWIw+QnpU1c142uOuXjTkbIhaipYZWw9o7Cx0NHEC6FJlMK1A7c5959mayFHv07bPWG3/MdhgsJXF2xtTpwCyhWfZEPCHmV2TOD9yXgOALeRGUoGz0TIa34iLv6H1SWovmGtUpDm6b702RRakiNwCON0Vt3XYkjYevtPKwp9+ydjSsgKhalgbKRxM0DFgPTPDnvFSYVZBZqlWgHEm8R+Q4570StvUmToDLvWfM4GGkVQUkwzhptbN3FP9nk3YmGLIpkGa8A2tXvLUNLF53FAVraeyNtxMEvFaZQC0bORM7kU0PAKo00yTDjRtXajw0m1bciZrWUTlkBA==
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, Jan Beulich <jbeulich@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>
  • Delivery-date: Wed, 20 Jul 2022 18:44:09 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYmuuJlTOCfCU2VEeylMdGd6xTk62FOW4AgAJgrAA=
  • Thread-topic: [PATCH v2 1/4] pci: add rwlock to pcidevs_lock machinery

Hello Wei,

Wei Chen <Wei.Chen@xxxxxxx> writes:

> Hi Volodymyr,
>
> On 2022/7/19 5:15, Volodymyr Babchuk wrote:
>> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>
>
>>         if ( !use_msi )
>>           return -EOPNOTSUPP;
>> diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
>> index 938821e593..f93922acc8 100644
>> --- a/xen/drivers/passthrough/pci.c
>> +++ b/xen/drivers/passthrough/pci.c
>> @@ -50,21 +50,74 @@ struct pci_seg {
>>       } bus2bridge[MAX_BUSES];
>>   };
>>   -static spinlock_t _pcidevs_lock = SPIN_LOCK_UNLOCKED;
>> +static DEFINE_RWLOCK(_pcidevs_rwlock);
>> +static DEFINE_PER_CPU(unsigned int, pcidevs_read_cnt);
>> +static DEFINE_PER_CPU(unsigned int, pcidevs_write_cnt);
>>     void pcidevs_lock(void)
>>   {
>> -    spin_lock_recursive(&_pcidevs_lock);
>> +    pcidevs_write_lock();
>>   }
>>     void pcidevs_unlock(void)
>>   {
>> -    spin_unlock_recursive(&_pcidevs_lock);
>> +    pcidevs_write_unlock();
>>   }
>>   -bool_t pcidevs_locked(void)
>> +bool pcidevs_locked(void)
>>   {
>> -    return !!spin_is_locked(&_pcidevs_lock);
>> +    return pcidevs_write_locked();
>> +}
>> +
>> +void pcidevs_read_lock(void)
>> +{
>> +    if ( this_cpu(pcidevs_read_cnt)++ == 0 )
>> +        read_lock(&_pcidevs_rwlock);
>> +}
>> +
>
> For my understanding, if pcidevs_read_cnt > 0, pcidevs_read_lock
> will be unblocked.I am not sure if this behavior is consistent with
> the original lock? According to my understanding, the original
> spinlock should be blocked all the time, if the lock is not
> acquired. Maybe

Original spinlock was recursive one. As read-write locks are
non-recursive in Xen, we need to implement some other mechanism to
support recursion. This code ensures that pCPU will not dead-lock itself
if it'll call pcidevs_read_lock() twice. Per-CPU counter ensures that
read_unlock() will be called only when pcidevs_read_unlock() calls is
balanced with pcidevs_read_lock()s.

> I have misunderstanding something, I am not very familiar with PCI
> subsystem.
>
> Cheers,
> Wei Chen

[...]

-- 
Volodymyr Babchuk at EPAM


 


Rackspace

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