From: "Liao, Chang" <liaochang1@huawei.com>
To: Andi Kleen <ak@linux.intel.com>
Cc: <mhiramat@kernel.org>, <oleg@redhat.com>, <andrii@kernel.org>,
<peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
<namhyung@kernel.org>, <mark.rutland@arm.com>,
<alexander.shishkin@linux.intel.com>, <jolsa@kernel.org>,
<irogers@google.com>, <adrian.hunter@intel.com>,
<kan.liang@linux.intel.com>, <linux-kernel@vger.kernel.org>,
<linux-trace-kernel@vger.kernel.org>,
<linux-perf-users@vger.kernel.org>, <bpf@vger.kernel.org>
Subject: Re: [PATCH] uprobes: Improve the usage of xol slots for better scalability
Date: Thu, 19 Sep 2024 20:20:43 +0800 [thread overview]
Message-ID: <7a6ba3f3-dffa-cdac-73c7-074505ea4b44@huawei.com> (raw)
In-Reply-To: <87jzf9b12w.fsf@linux.intel.com>
在 2024/9/18 20:25, Andi Kleen 写道:
> Liao Chang <liaochang1@huawei.com> writes:
>> +
>> +/*
>> + * xol_recycle_insn_slot - recycle a slot from the garbage collection list.
>> + */
>> +static int xol_recycle_insn_slot(struct xol_area *area)
>> +{
>> + struct uprobe_task *utask;
>> + int slot = UINSNS_PER_PAGE;
>> +
>> + rcu_read_lock();
>> + list_for_each_entry_rcu(utask, &area->gc_list, gc) {
>> + /*
>> + * The utask associated slot is in-use or recycling when
>> + * utask associated slot_ref is not one.
>> + */
>> + if (test_and_put_task_slot(utask)) {
>> + slot = utask->insn_slot;
>> + utask->insn_slot = UINSNS_PER_PAGE;
>> + clear_bit(slot, area->bitmap);
>> + atomic_dec(&area->slot_count);
>> + get_task_slot(utask);
>
> Doesn't this need some annotation to make ThreadSanitizer happy?
Hi, Andi
Sorry, I know nothing about the ThreadSanitizer and related annotation,
could you provide some information about it, thanks.
> Would be good to have some commentary why doing so
> many write operations with merely a rcu_read_lock as protection is safe.
> It might be safer to put some write type operations under a real lock.
> Also it is unclear how the RCU grace period for utasks is enforced.
You are right, but I think using atomic refcount routine might be a more
suitable apprach for this scenario. The slot_ret field of utask instance
is used to track the status of insn_slot. slot_ret supports three values.
A value of 2 means the utask associated insn_slot is currently in use by
uprobe. A value of 1 means the slot is no being used by uprobe. A value
of 0 means the slot has been reclaimed. So in some term, the atomic refcount
routine test_and_pout_task_slot() also avoid the racing when writing to
the utask instance, providing additional status information about insn_slot.
BTW, You reminded me that since it might recycle the slot after deleting the
utask from the garbage collection list, so it's necessary to use
test_and_put_task_slot() to avoid the racing on the stale utask. the correct
code might be something like this:
@@ -1771,16 +1783,16 @@ static void xol_free_insn_slot(struct task_struct *tsk)
spin_lock_irqsave(&area->list_lock, flags);
list_del_rcu(&tsk->utask->gc);
+ /* Ensure the slot is not in use or reclaimed on other CPU */
+ if (test_and_put_task_slot(tsk->utask)) {
+ clear_bit(tsk->utask->insn_slot, area->bitmap);
+ atomic_dec(&area->slot_count);
+ tsk->utask->insn_slot = UINSNS_PER_PAGE;
+ get_task_slot(tsk->utask);
+ }
spin_unlock_irqrestore(&area->list_lock, flags);
synchronize_rcu();
If I've made any mistakes about RCU usage, please don't hesitate to corret me.
Thank you in advance.
>
>
> -Andi
>
--
BR
Liao, Chang
next prev parent reply other threads:[~2024-09-19 12:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-18 1:27 [PATCH] uprobes: Improve the usage of xol slots for better scalability Liao Chang
2024-09-18 12:25 ` Andi Kleen
2024-09-19 12:20 ` Liao, Chang [this message]
2024-09-19 13:34 ` Andi Kleen
2024-09-23 10:29 ` Liao, Chang
2024-09-23 23:52 ` Andi Kleen
2024-09-27 10:01 ` Liao, Chang
2024-09-18 14:41 ` kernel test robot
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=7a6ba3f3-dffa-cdac-73c7-074505ea4b44@huawei.com \
--to=liaochang1@huawei.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.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