From: Dave Hansen <dave.hansen@intel.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"keescook@chromium.org" <keescook@chromium.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"x86@kernel.org" <x86@kernel.org>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Subject: Re: [GIT PULL] x86/shstk for 6.4
Date: Fri, 12 May 2023 10:34:17 -0700 [thread overview]
Message-ID: <95c2e669-bce9-3dd5-e197-3faf816c4b45@intel.com> (raw)
In-Reply-To: <CAHk-=wg4vpYz+xRtd+PsdmQ9gtNGbXrFKW3ndvXcrLEEDN0hyw@mail.gmail.com>
On 5/8/23 16:47, Linus Torvalds wrote:
> - we would probably be *much* better off with a "if (mm->count == 1)"
> test that goes off and does *not* do the atomic case (which also
> doesn't have any worries about dirty bits). I'll take a well-predicted
> conditional branch over an atomic op any day of the week
Were you really thinking of mm->count==1, or did you mean
mm->mm_users==1? I _think_ the only clue that things like ptrace() and
kthread_use_mm() are poking around in the page tables is when
mm->mm_users>1. They don't bump mm->count.
Most mmget() (or get_task_mm()->atomic_inc(&mm->mm_users)) callers are
obviously harmless for our purposes, like proc_pid_statm().
There are others like idxd_copy_cr()->copy_to_user() that are less
obviously OK. They're OK if they fault during a fork() because the
fault will end up stuck on mmap_read(mm) waiting for fork() to release
its write.
But the worry is if those kthread_use_mm() users *don't* fault:
CPU-1 CPU-2
fork()
// mm->mm_users==1
ptep_set_wrprotect()
^ non-atomic
kthread_use_mm()
// mm->mm_users==2
copy_to_user()
// page walker sets Dirty=1
There's always a race there because mm->mm_users can always get bumped
after the fork()er checks it.
Is there something that fixes this race that I'm missing?
We can probably do something more comprehensive to make sure that
mm->mm_users isn't bumped during fork(), but it'll be a bit more
complicated than just checking mm->mm_users in fork().
next prev parent reply other threads:[~2023-05-12 17:34 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-24 21:21 [GIT PULL] x86/shstk for 6.4 Dave Hansen
2023-04-28 18:17 ` Linus Torvalds
2023-04-29 0:26 ` Edgecombe, Rick P
2023-04-29 0:40 ` Dave Hansen
2023-05-06 19:34 ` Linus Torvalds
2023-05-06 20:09 ` Linus Torvalds
2023-05-07 0:18 ` Edgecombe, Rick P
2023-05-07 0:38 ` Linus Torvalds
2023-05-07 15:57 ` Edgecombe, Rick P
2023-05-08 22:57 ` Dave Hansen
2023-05-08 23:31 ` Linus Torvalds
2023-05-08 23:47 ` Linus Torvalds
2023-05-12 17:34 ` Dave Hansen [this message]
2023-05-12 21:55 ` Linus Torvalds
2023-05-15 21:36 ` Dave Hansen
2023-05-15 21:37 ` Dave Hansen
2023-05-15 22:40 ` Linus Torvalds
2023-05-15 23:02 ` Linus Torvalds
2023-05-16 20:38 ` Linus Torvalds
2023-05-16 20:42 ` Dave Hansen
2023-05-09 0:07 ` Dave Hansen
2023-05-07 0:10 ` Edgecombe, Rick P
2023-05-07 0:19 ` Linus Torvalds
2023-05-07 16:24 ` Edgecombe, Rick P
2023-05-15 21:22 ` Deepak Gupta
2023-05-25 16:20 ` Mark Brown
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=95c2e669-bce9-3dd5-e197-3faf816c4b45@intel.com \
--to=dave.hansen@intel.com \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@linux.intel.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rick.p.edgecombe@intel.com \
--cc=torvalds@linux-foundation.org \
--cc=x86@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