From: Dave Hansen <dave.hansen@intel.com>
To: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>,
linux-kernel@vger.kernel.org
Cc: x86@kernel.org, dave.hansen@linux.intel.com, tglx@linutronix.de,
matthias.neugschwandtner@oracle.com,
andrew.brownsword@oracle.com
Subject: Re: [RFC PATCH v2 1/1] x86/pkeys: update PKRU to enable pkey 0 before XSAVE
Date: Fri, 22 Mar 2024 08:40:56 -0700 [thread overview]
Message-ID: <5b536d60-d130-4061-984e-3b83a3cab092@intel.com> (raw)
In-Reply-To: <20240321215622.3396410-2-aruna.ramakrishna@oracle.com>
On 3/21/24 14:56, Aruna Ramakrishna wrote:
> +/*
> + * Ensure that the both the current stack and the alternate signal
> + * stack is writeable. The alternate stack must be accessible by the
> + * init PKRU value.
> + */
> +static inline u32 sig_prepare_pkru(void)
> +{
> + u32 current_pkru = read_pkru();
> + u32 init_pkru_snapshot = pkru_get_init_value();
> +
> + write_pkru(current_pkru & init_pkru_snapshot);
> + return current_pkru;
> +}
That comment is quite misleading. This code has *ZERO* knowledge of the
permissions on either the current or alternate stack. It _assumes_ that
the current PKRU permissions allow writes to the current stack and
_assumes_ that the init PKRU value can write to the alternative stack.
Those aren't bad assumptions, but they _are_ assumptions and need to be
clearly called out as such.
The '&' operation looks rather random and needs an explanation. What is
that logically trying to do? It's trying to clear bits in the old
(pre-signal) PKRU value so that it gains write access to the alt stack.
Please say that.
Which leads me to ask: Why bother with the '&'? It would be simpler to,
for instance, just wrpkru(0). What is being written to the old stack at
this point?
I also dislike something being called 'current_pkru' when it's clearly
the old value by the time it is returned.
> +static inline void sig_restore_pkru(u32 pkru)
> +{
> + write_pkru(pkru);
> +}
This seems like unnecessary abstraction.
next prev parent reply other threads:[~2024-03-22 15:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-21 21:56 [RFC PATCH v2 0/1] x86/pkeys: update PKRU to enable pkey 0 Aruna Ramakrishna
2024-03-21 21:56 ` [RFC PATCH v2 1/1] x86/pkeys: update PKRU to enable pkey 0 before XSAVE Aruna Ramakrishna
2024-03-22 9:46 ` Ingo Molnar
2024-03-22 18:30 ` Aruna Ramakrishna
2024-04-25 22:03 ` jeffxu
2024-03-22 15:40 ` Dave Hansen [this message]
2024-03-22 18:28 ` Aruna Ramakrishna
2024-04-25 21:05 ` jeffxu
2024-04-25 22:49 ` Aruna Ramakrishna
2024-04-26 0:12 ` Jeff Xu
2024-04-26 16:13 ` Jeff Xu
2024-04-26 16:33 ` Edgecombe, Rick P
2024-04-26 17:13 ` Jeff Xu
2024-04-25 21:58 ` jeffxu
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=5b536d60-d130-4061-984e-3b83a3cab092@intel.com \
--to=dave.hansen@intel.com \
--cc=andrew.brownsword@oracle.com \
--cc=aruna.ramakrishna@oracle.com \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matthias.neugschwandtner@oracle.com \
--cc=tglx@linutronix.de \
--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