From: Marcelo Tosatti <mtosatti@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, Nitesh Lal <nilal@redhat.com>,
Nicolas Saenz Julienne <nsaenzju@redhat.com>,
Frederic Weisbecker <frederic@kernel.org>,
Christoph Lameter <cl@linux.com>,
Juri Lelli <juri.lelli@redhat.com>,
Alex Belits <abelits@belits.com>, Peter Xu <peterx@redhat.com>
Subject: Re: [patch v4 1/8] add basic task isolation prctl interface
Date: Tue, 19 Oct 2021 12:07:18 -0300 [thread overview]
Message-ID: <20211019150718.GA61531@fuller.cnet> (raw)
In-Reply-To: <YWb0ycw/sNV8isBH@hirez.programming.kicks-ass.net>
On Wed, Oct 13, 2021 at 05:01:29PM +0200, Peter Zijlstra wrote:
> That's absolutely terrible :/ you're adding extra unconditinal atomics
> to the entry/exit path instead of using the ones that are already there.
> That's no good.
>
> Also, you're very much not dealing with that race either.
Again, because we haven't seen any use for the notification signal.
But anyway, about the general race:
CPU0 CPU1
sys_prctl()
<kernel entry>
if (target_cpu->isolated)
// checks CPU0, not userspace, queues IPI
mark task 'task isolated'
<kernel exit>
arch_send_call_function_ipi_mask()
task is interrupted
----
A possible solution would be to synchronize_rcu (or _expedited if
necessary):
CPU0 CPU1
sys_prctl()
<kernel entry>
rcu_read_lock()
if (target_cpu->isolated) {
// checks CPU0, not userspace, queues IPI
cpu0->isolated = true
synchronize_rcu/synchronize_rcu_expedited
arch_send_call_function_ipi_mask()
}
rcu_read_unlock()
<kernel exit>
----
But that cpu0->isolated variable is not usable for the TLB flush
stuff, for example.
But regarding the question
"the inherently racy nature of some of the don't disturb me stuff":
i think it depends on the case (as in what piece of kernel code).
For example, for the TLB flush case the atomic cmpxchg loop gets rid of the race.
But the above RCU protection might be sufficient for other cases.
And about the notification to userspace, can't see a reason why it can't
be performed in asynchronous fashion (say via eventfd to a manager
thread rather than isolated threads themselves).
> Also, I think you're broken vs instrumentation, all of this needs to
> happen super early on entry, possibly while still on the entry stack,
> otherwise the missed TLBi might be handled too late and we just used a
> stale TLB entry.
Alright, right after switch to kernel CR3, right before switch to user CR3
(or as early/late as possible).
next prev parent reply other threads:[~2021-10-19 15:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-07 19:23 [patch v4 0/8] extensible prctl task isolation interface and vmstat sync Marcelo Tosatti
2021-10-07 19:23 ` [patch v4 1/8] add basic task isolation prctl interface Marcelo Tosatti
2021-10-12 13:05 ` Peter Zijlstra
2021-10-13 10:56 ` Marcelo Tosatti
2021-10-13 11:37 ` Marcelo Tosatti
2021-10-13 15:01 ` Peter Zijlstra
2021-10-13 16:06 ` Marcelo Tosatti
2021-10-14 13:02 ` Marcelo Tosatti
2021-10-19 15:07 ` Marcelo Tosatti [this message]
2021-10-07 19:23 ` [patch v4 2/8] add prctl task isolation prctl docs and samples Marcelo Tosatti
2021-10-07 19:23 ` [patch v4 3/8] task isolation: sync vmstats on return to userspace Marcelo Tosatti
2021-10-07 19:23 ` [patch v4 4/8] procfs: add per-pid task isolation state Marcelo Tosatti
2021-10-07 19:23 ` [patch v4 5/8] task isolation: sync vmstats conditional on changes Marcelo Tosatti
2021-10-07 19:23 ` [patch v4 6/8] KVM: x86: call isolation prepare from VM-entry code path Marcelo Tosatti
2021-10-07 19:23 ` [patch v4 7/8] mm: vmstat: move need_update Marcelo Tosatti
2021-10-07 19:23 ` [patch v4 8/8] mm: vmstat_refresh: avoid queueing work item if cpu stats are clean Marcelo Tosatti
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=20211019150718.GA61531@fuller.cnet \
--to=mtosatti@redhat.com \
--cc=abelits@belits.com \
--cc=cl@linux.com \
--cc=frederic@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nilal@redhat.com \
--cc=nsaenzju@redhat.com \
--cc=peterx@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