Linux Documentation
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: Wei Yang <richard.weiyang@gmail.com>,
	Alan Huang <mmpgouride@gmail.com>,
	paulmck@kernel.org, frederic@kernel.org,
	neeraj.upadhyay@kernel.org, rcu@vger.kernel.org,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH] doc/RCU/listRCU: fix an example code snippets
Date: Tue, 18 Feb 2025 00:25:41 +0000	[thread overview]
Message-ID: <20250218002541.sxj3l34gv256pkaj@master> (raw)
In-Reply-To: <Z7O4owmajnmtqh2x@Mac.home>

On Mon, Feb 17, 2025 at 02:30:59PM -0800, Boqun Feng wrote:
>On Mon, Feb 17, 2025 at 09:18:42AM +0000, Wei Yang wrote:
>> On Mon, Feb 17, 2025 at 04:02:53PM +0800, Alan Huang wrote:
>> >On Feb 17, 2025, at 15:41, Wei Yang <richard.weiyang@gmail.com> wrote:
>> >> 
>> >> On Mon, Feb 17, 2025 at 10:22:53AM +0800, Alan Huang wrote:
>> >>> On Feb 17, 2025, at 10:12, Boqun Feng <boqun.feng@gmail.com> wrote:
>> >>>> 
>> >>>> Hi Wei,
>> >>>> 
>> >>>> The change loosk good to me, thanks!
>> >>>> 
>> >>>> I queued the patch for futher reviews and tests with some changes in the
>> >>>> commit log (for title formating and a bit more explanation), please see
>> >>>> below.
>> >>>> 
>> >>>> Regards,
>> >>>> Boqun
>> >>>> 
>> >>>> On Wed, Jan 01, 2025 at 08:23:06AM +0000, Wei Yang wrote:
>> >>>>> The example code for "Eliminating Stale Data" looks not correct:
>> >>>>> 
>> >>>>> * rcu_read_unlock() should put after kstrdup()
>> >>>>> * spin_unlock() should be called before return
>> >>>>> 
>> >>>>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>> >>>> [...]
>> >>>> 
>> >>>> 
>> >>>> ------------------>8
>> >>>> Subject: [PATCH] doc/RCU/listRCU: Fix an example code snippets
>> >>>> 
>> >>>> The example code for "Eliminating Stale Data" looks not correct:
>> >>>> 
>> >>>> * rcu_read_unlock() should put after kstrdup(), because otherwise
>> >>>> entry may get freed while kstrdup() is being called.
>> >>>> 
>> >>>> * spin_unlock() should be called before return, otherwise the
>> >>>> function would return with the lock of the entry held.
>> >>>> 
>> >>>> Hence fix these.
>> >>>> 
>> >>>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>> >>>> Link: https://lore.kernel.org/r/20250101082306.10404-1-richard.weiyang@gmail.com
>> >>>> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
>> >>>> ---
>> >>>> Documentation/RCU/listRCU.rst | 3 ++-
>> >>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>> >>>> 
>> >>>> diff --git a/Documentation/RCU/listRCU.rst b/Documentation/RCU/listRCU.rst
>> >>>> index ed5c9d8c9afe..8df50fcd69fd 100644
>> >>>> --- a/Documentation/RCU/listRCU.rst
>> >>>> +++ b/Documentation/RCU/listRCU.rst
>> >>>> @@ -348,9 +348,10 @@ to accomplish this would be to add a ``deleted`` flag and a ``lock`` spinlock to
>> >>>> rcu_read_unlock();
>> >>>> return AUDIT_BUILD_CONTEXT;
>> >>>> }
>> >>>> - rcu_read_unlock();
>> >>>> if (state == AUDIT_STATE_RECORD)
>> >>>> *key = kstrdup(e->rule.filterkey, GFP_ATOMIC);
>> >>>> + spin_unlock(&e->lock);
>> >>> 
>> >>> According to the above quick quiz, we should return with the lock held.
>> >>> 
>> >> 
>> >> Thanks, I think you have some reason.
>> >> 
>> >> If my understanding is correct, the example here is to emphasize we could
>> >> still access the value out of critical section but with spinlock held.
>> >
>> >This example is intended to highlight how we can eliminate stale data.
>> >
>> 
>> Yes, you are more accurate.
>> 
>> >> 
>> >> In current example, we don't return e(struct audit_entry) from
>> >> audit_filter_task(). So no one suppose to release the spinlock again. This
>> >> looks to be a mistake.
>> >
>> >Then the example code should return e instead. ( *key is also undefined)
>> >
>> 
>> So you prefer a version with e returned?
>> 
>> Boqun
>> 
>> What's your preference?
>> 
>
>Yeah, I think it make more sense with e returned, and you can add some
>comments at the return statement like:
>
>	return e; // as long as the lock of e is held, e is valid.
>
>, but feel free to use whatever you see fit.
>

Thanks, let me prepare one.

>Regards,
>Boqun

-- 
Wei Yang
Help you, Help me

      reply	other threads:[~2025-02-18  0:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-01  8:23 [PATCH] doc/RCU/listRCU: fix an example code snippets Wei Yang
2025-01-23  1:48 ` Wei Yang
2025-02-17  2:12 ` Boqun Feng
2025-02-17  2:22   ` Alan Huang
2025-02-17  2:35     ` Boqun Feng
2025-02-17  7:41     ` Wei Yang
2025-02-17  8:02       ` Alan Huang
2025-02-17  9:18         ` Wei Yang
2025-02-17 22:30           ` Boqun Feng
2025-02-18  0:25             ` Wei Yang [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=20250218002541.sxj3l34gv256pkaj@master \
    --to=richard.weiyang@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=frederic@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=mmpgouride@gmail.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    /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