From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
"Paul E . McKenney" <paulmck@linux.ibm.com>,
Boqun Feng <boqun.feng@gmail.com>,
"H . Peter Anvin" <hpa@zytor.com>, Paul Turner <pjt@google.com>,
linux-api@vger.kernel.org, Florian Weimer <fw@deneb.enyo.de>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Dmitry Vyukov <dvyukov@google.com>,
Neel Natu <neelnatu@google.com>
Subject: [RFC PATCH for 5.8 2/4] rseq: Introduce RSEQ_FLAG_REGISTER
Date: Mon, 6 Jul 2020 16:49:11 -0400 [thread overview]
Message-ID: <20200706204913.20347-3-mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <20200706204913.20347-1-mathieu.desnoyers@efficios.com>
Introduce RSEQ_FLAG_REGISTER with the same behavior as the flag value
"0". The main advantage of introducing this flag as a non-zero (1 << 1)
value is that it can be combined with other flags to register and check
for features with a single system call. Considering that this system
call needs to be performed for each new thread in glibc, minimize the
amount of overhead required.
This is needed for introducing a new RSEQ_FLAG_RELIABLE_CPU_ID flag in a
later change.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Florian Weimer <fw@deneb.enyo.de>
Cc: "Paul E. McKenney" <paulmck@linux.ibm.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: "H . Peter Anvin" <hpa@zytor.com>
Cc: Paul Turner <pjt@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Neel Natu <neelnatu@google.com>
Cc: linux-api@vger.kernel.org
---
include/uapi/linux/rseq.h | 10 ++++-
kernel/rseq.c | 77 +++++++++++++++++++++------------------
2 files changed, 51 insertions(+), 36 deletions(-)
diff --git a/include/uapi/linux/rseq.h b/include/uapi/linux/rseq.h
index 9a402fdb60e9..3b5fba25461a 100644
--- a/include/uapi/linux/rseq.h
+++ b/include/uapi/linux/rseq.h
@@ -18,8 +18,16 @@ enum rseq_cpu_id_state {
RSEQ_CPU_ID_REGISTRATION_FAILED = -2,
};
+/*
+ * RSEQ_FLAG_UNREGISTER: Unregister rseq ABI for caller thread.
+ * RSEQ_FLAG_REGISTER: Register rseq ABI for caller thread.
+ *
+ * Flag value 0 has the same behavior as RSEQ_FLAG_REGISTER, but cannot be
+ * combined with other flags. This behavior is kept for backward compatibility.
+ */
enum rseq_flags {
- RSEQ_FLAG_UNREGISTER = (1 << 0),
+ RSEQ_FLAG_UNREGISTER = (1 << 0),
+ RSEQ_FLAG_REGISTER = (1 << 1),
};
enum rseq_cs_flags_bit {
diff --git a/kernel/rseq.c b/kernel/rseq.c
index a4f86a9d6937..47ce221cd6f9 100644
--- a/kernel/rseq.c
+++ b/kernel/rseq.c
@@ -309,9 +309,16 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,
{
int ret;
- if (flags & RSEQ_FLAG_UNREGISTER) {
- if (flags & ~RSEQ_FLAG_UNREGISTER)
- return -EINVAL;
+ /*
+ * Flag value 0 has the same behavior as RSEQ_FLAG_REGISTER, but cannot
+ * be combined with other flags. This behavior is kept for backward
+ * compatibility.
+ */
+ if (!flags)
+ flags = RSEQ_FLAG_REGISTER;
+
+ switch (flags) {
+ case RSEQ_FLAG_UNREGISTER:
/* Unregister rseq for current thread. */
if (current->rseq != rseq || !current->rseq)
return -EINVAL;
@@ -324,43 +331,43 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,
return ret;
current->rseq = NULL;
current->rseq_sig = 0;
- return 0;
- }
-
- if (unlikely(flags))
- return -EINVAL;
+ break;
+ case RSEQ_FLAG_REGISTER:
+ if (current->rseq) {
+ /*
+ * If rseq is already registered, check whether
+ * the provided address differs from the prior
+ * one.
+ */
+ if (current->rseq != rseq || rseq_len != sizeof(*rseq))
+ return -EINVAL;
+ if (current->rseq_sig != sig)
+ return -EPERM;
+ /* Already registered. */
+ return -EBUSY;
+ }
- if (current->rseq) {
/*
- * If rseq is already registered, check whether
- * the provided address differs from the prior
- * one.
+ * If there was no rseq previously registered,
+ * ensure the provided rseq is properly aligned and valid.
*/
- if (current->rseq != rseq || rseq_len != sizeof(*rseq))
+ if (!IS_ALIGNED((unsigned long)rseq, __alignof__(*rseq)) ||
+ rseq_len != sizeof(*rseq))
return -EINVAL;
- if (current->rseq_sig != sig)
- return -EPERM;
- /* Already registered. */
- return -EBUSY;
- }
-
- /*
- * If there was no rseq previously registered,
- * ensure the provided rseq is properly aligned and valid.
- */
- if (!IS_ALIGNED((unsigned long)rseq, __alignof__(*rseq)) ||
- rseq_len != sizeof(*rseq))
+ if (!access_ok(rseq, rseq_len))
+ return -EFAULT;
+ current->rseq = rseq;
+ current->rseq_sig = sig;
+ /*
+ * If rseq was previously inactive, and has just been
+ * registered, ensure the cpu_id_start and cpu_id fields
+ * are updated before returning to user-space.
+ */
+ rseq_set_notify_resume(current);
+ break;
+ default:
return -EINVAL;
- if (!access_ok(rseq, rseq_len))
- return -EFAULT;
- current->rseq = rseq;
- current->rseq_sig = sig;
- /*
- * If rseq was previously inactive, and has just been
- * registered, ensure the cpu_id_start and cpu_id fields
- * are updated before returning to user-space.
- */
- rseq_set_notify_resume(current);
+ }
return 0;
}
--
2.17.1
next prev parent reply other threads:[~2020-07-06 20:49 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-06 20:49 [RFC PATCH for 5.8 0/4] rseq cpu_id ABI fix Mathieu Desnoyers
2020-07-06 20:49 ` [RFC PATCH for 5.8 1/4] sched: Fix unreliable rseq cpu_id for new tasks Mathieu Desnoyers
2020-07-07 7:30 ` Florian Weimer
2020-07-07 10:51 ` Mathieu Desnoyers
2020-07-06 20:49 ` Mathieu Desnoyers [this message]
2020-07-06 20:49 ` [RFC PATCH for 5.8 3/4] rseq: Introduce RSEQ_FLAG_RELIABLE_CPU_ID Mathieu Desnoyers
2020-07-07 7:29 ` Florian Weimer
2020-07-07 10:48 ` Mathieu Desnoyers
2020-07-07 11:32 ` Florian Weimer
2020-07-07 12:06 ` Mathieu Desnoyers
2020-07-07 18:53 ` Carlos O'Donell
2020-07-07 18:59 ` Mathieu Desnoyers
2020-07-08 8:31 ` Florian Weimer
2020-07-07 19:55 ` Florian Weimer
2020-07-08 15:33 ` Mathieu Desnoyers
2020-07-08 16:22 ` Christian Brauner
2020-07-08 16:36 ` Florian Weimer
2020-07-08 17:34 ` Mathieu Desnoyers
2020-07-09 12:49 ` Christian Brauner
2020-07-09 15:15 ` Mathieu Desnoyers
2020-07-11 15:54 ` Christian Brauner
2020-07-13 18:40 ` Mathieu Desnoyers
2020-07-06 20:49 ` [RFC PATCH for 5.8 4/4] rseq: selftests: Expect reliable cpu_id field Mathieu Desnoyers
2020-07-07 6:26 ` [RFC PATCH for 5.8 0/4] rseq cpu_id ABI fix Florian Weimer
2020-07-07 14:54 ` Florian Weimer
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=20200706204913.20347-3-mathieu.desnoyers@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=boqun.feng@gmail.com \
--cc=dvyukov@google.com \
--cc=fw@deneb.enyo.de \
--cc=hpa@zytor.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neelnatu@google.com \
--cc=paulmck@linux.ibm.com \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®