Netdev List
 help / color / mirror / Atom feed
From: Qingfang Deng <qingfang.deng@linux.dev>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	netdev@vger.kernel.org, eric.dumazet@gmail.com,
	linux-ppp@vger.kernel.org
Subject: Re: [PATCH net] ppp: annotate data races in ppp_generic
Date: Thu, 23 Jul 2026 15:21:56 +0800	[thread overview]
Message-ID: <86e82246-c842-4d0c-927a-52e21a996008@linux.dev> (raw)
In-Reply-To: <CANn89i+E=JBRGj3cK+6mfVEX+PUjYrpkkWk1dB3VswnW4X_KGw@mail.gmail.com>

Hi,

On 2026/7/23 14:48, Eric Dumazet wrote:
> On Thu, Jul 23, 2026 at 8:24 AM Qingfang Deng <qingfang.deng@linux.dev> wrote:
>> Hi,
>>
>> On 2026/7/22 18:16, Eric Dumazet wrote:
>>> diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
>>> index ef54e0a0462a175bb989db8dda895e9ae755965f..cacc4c3a37d2cda0aea2e176e5d0638f959e18a3 100644
>>> --- a/drivers/net/ppp/ppp_generic.c
>>> +++ b/drivers/net/ppp/ppp_generic.c
>>> @@ -866,16 +870,16 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>>>                break;
>>>
>>>        case PPPIOCGIDLE32:
>>> -                idle32.xmit_idle = (jiffies - ppp->last_xmit) / HZ;
>>> -                idle32.recv_idle = (jiffies - ppp->last_recv) / HZ;
>>> -                if (copy_to_user(argp, &idle32, sizeof(idle32)))
>>> +             idle32.xmit_idle = max(0L, (long)(jiffies - READ_ONCE(ppp->last_xmit))) / HZ;
>>> +             idle32.recv_idle = max(0L, (long)(jiffies - READ_ONCE(ppp->last_recv))) / HZ;
>> In the original code, the difference will wrap around on a 32-bit kernel
>> with HZ=1000 if the session sits idle for 4,294,967.295 seconds
>> (approximately 49.7 days). With this change, as the difference is cast
>> to a long, it will be negative after 2,147,483.647 seconds
>> (approximately 24.9 days) and then clamped to zero by max(), making the
>> situation worse.
> I do not think the code was ready to handle long idle sessions to begin with.
>
> Can you elaborate on the 'worse' part, because I do not get it,
>
> We perform a max(0L, delta) quite often in the kernel, in lockless contexts.
>
> delta = jiffies - ppp->last_recv ; can be ~0UL if another cpu was able
> to update last_recv to (jiffies+1).
>
> We prefer in this case returning 0 instead of ~infinity.

Now I get it. A CPU may see an up-to-date `last_recv` from another CPU 
but a stale `jiffies`, as the order of reading the two variables is 
undefined (sequence points and memory ordering). So:

Reviewed-by: Qingfang Deng <qingfang.deng@linux.dev>


      reply	other threads:[~2026-07-23  7:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22 10:16 [PATCH net] ppp: annotate data races in ppp_generic Eric Dumazet
2026-07-23  6:24 ` Qingfang Deng
2026-07-23  6:48   ` Eric Dumazet
2026-07-23  7:21     ` Qingfang Deng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86e82246-c842-4d0c-927a-52e21a996008@linux.dev \
    --to=qingfang.deng@linux.dev \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-ppp@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox