linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* rpc_xprt_debugfs_register() - atomic_inc_return() usage
@ 2021-01-20 23:52 Shuah Khan
  2021-01-21 17:56 ` Trond Myklebust
  0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2021-01-20 23:52 UTC (permalink / raw)
  To: Anna.Schumaker, trond.myklebust
  Cc: J. Bruce Fields, chuck.lever, David S. Miller, kuba, linux-nfs,
	Networking, Linux Kernel Mailing List

Hi Anna and Trond,

I came across the following while reviewing atomic_inc_return() usages
that cast return value to unsigned

rpc_xprt_debugfs_register()'s atomic_inc_return() usage looks a bit odd.

- cur_id isn't initialized
- id = (unsigned int)atomic_inc_return(&cur_id);

Please note that id is int. Is it expected that cur_id could overflow?
Is there a maximum limit for this value?

thanks,
-- Shuah


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: rpc_xprt_debugfs_register() - atomic_inc_return() usage
  2021-01-20 23:52 rpc_xprt_debugfs_register() - atomic_inc_return() usage Shuah Khan
@ 2021-01-21 17:56 ` Trond Myklebust
  2021-01-21 18:01   ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Trond Myklebust @ 2021-01-21 17:56 UTC (permalink / raw)
  To: skhan, Anna.Schumaker
  Cc: bfields, linux-nfs, linux-kernel, davem, kuba, chuck.lever, netdev

On Wed, 2021-01-20 at 16:52 -0700, Shuah Khan wrote:
> Hi Anna and Trond,
> 
> I came across the following while reviewing atomic_inc_return()
> usages
> that cast return value to unsigned
> 
> rpc_xprt_debugfs_register()'s atomic_inc_return() usage looks a bit
> odd.
> 
> - cur_id isn't initialized
> - id = (unsigned int)atomic_inc_return(&cur_id);
> 
> Please note that id is int. Is it expected that cur_id could
> overflow?
> Is there a maximum limit for this value?
> 

Yes, we do expect cur_id to eventually overflow (once you have created
2 billion RPC client instances), however the atomic increment
operations are expected to handle this correctly according to the
maintainers (I already asked them in a different context). Furthermore,
the code itself doesn't care about strict sequentiality. All it wants
from the counter is uniqueness, with that uniqueness condition actually
being enforced by the subsequent debugfs_create_file() call.

IOW: I don't think this is a real problem.

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: rpc_xprt_debugfs_register() - atomic_inc_return() usage
  2021-01-21 17:56 ` Trond Myklebust
@ 2021-01-21 18:01   ` Shuah Khan
  0 siblings, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2021-01-21 18:01 UTC (permalink / raw)
  To: Trond Myklebust, Anna.Schumaker
  Cc: bfields, linux-nfs, linux-kernel, davem, kuba, chuck.lever,
	netdev, Shuah Khan

On 1/21/21 10:56 AM, Trond Myklebust wrote:
> On Wed, 2021-01-20 at 16:52 -0700, Shuah Khan wrote:
>> Hi Anna and Trond,
>>
>> I came across the following while reviewing atomic_inc_return()
>> usages
>> that cast return value to unsigned
>>
>> rpc_xprt_debugfs_register()'s atomic_inc_return() usage looks a bit
>> odd.
>>
>> - cur_id isn't initialized
>> - id = (unsigned int)atomic_inc_return(&cur_id);
>>
>> Please note that id is int. Is it expected that cur_id could
>> overflow?
>> Is there a maximum limit for this value?
>>
> 
> Yes, we do expect cur_id to eventually overflow (once you have created
> 2 billion RPC client instances), however the atomic increment
> operations are expected to handle this correctly according to the
> maintainers (I already asked them in a different context). Furthermore,
> the code itself doesn't care about strict sequentiality. All it wants
> from the counter is uniqueness, with that uniqueness condition actually
> being enforced by the subsequent debugfs_create_file() call.
> 
> IOW: I don't think this is a real problem.
> 

Great. Thank you for a detailed explanation.

-- Shuah

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-21 18:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-20 23:52 rpc_xprt_debugfs_register() - atomic_inc_return() usage Shuah Khan
2021-01-21 17:56 ` Trond Myklebust
2021-01-21 18:01   ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).