From: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
To: "jeffxu@chromium.org" <jeffxu@chromium.org>
Cc: "dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
Keith Lucas <keith.lucas@oracle.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
"x86@kernel.org" <x86@kernel.org>,
Andrew Brownsword <andrew.brownsword@oracle.com>,
Matthias Neugschwandtner <matthias.neugschwandtner@oracle.com>,
"jeffxu@google.com" <jeffxu@google.com>,
"jannh@google.com" <jannh@google.com>,
"keescook@chromium.org" <keescook@chromium.org>,
"sroettger@google.com" <sroettger@google.com>,
"jorgelo@chromium.org" <jorgelo@chromium.org>,
"rick.p.edgecombe@intel.com" <rick.p.edgecombe@intel.com>
Subject: Re: Re [PATCH v5 2/5] x86/pkeys: Add helper functions to update PKRU on sigframe
Date: Tue, 11 Jun 2024 14:05:32 +0000 [thread overview]
Message-ID: <2DB720B0-0921-4912-8C5F-F0EDDF77845D@oracle.com> (raw)
In-Reply-To: <20240610213934.3378947-1-jeffxu@chromium.org>
> On Jun 10, 2024, at 2:39 PM, jeffxu@chromium.org wrote:
>
> The orig_pkru & init_pkru_value is quite difficult to understand.
>
> case 1> init_pkru: 00 (allow all)
> orig_pkru all cases => allow all
>
> case 2> init_pkru: 01 (disable all)
> Orig_pkru:
> allow all 00 => 00 allow all.
> disable all 01 => 01 disable all.
> disable write 10 => 00 allow all <--- *** odd ***
> disable all 11 => 01 disable all
>
> case 3> init pkru: 10 (disable write)
> allow all 00 => 00 allow all.
> disable all 01 => 00 (allow all) <----*** odd ***
> disable write 10 => 10 allow all
> disable all 11 => 10 disable write <--- *** odd ***
>
> case 4> init pkru: 11 (disable all)
> orig_pkru all cases => unchanged.
>
> set PKRU(0) seems to be better, easy to understand.
>
I’m not sure I follow.
The default init_pkru is 0x55555554 (enable only pkey 0). Let’s assume the application
sets up PKRU = 0x55555545 (i.e. enable only pkey 2). We want to set up the PKRU
to enable both pkey 0 and pkey 2, before the XSAVE, so that both the current stack as
well as the alternate signal stack are writable.
So with
write_pkru(orig_pkru & pkru_get_init_value());
It changes PKRU to 0x55555544 - enabling both pkey 0 and pkey 2.
After the XSAVE, it calls update_pkru_in_sigframe(), which overwrites this (new)
PKRU saved on the sigframe with orig_pkru, which is 0x55555545 in this example.
Setting PKRU to 0 would be simpler, it would enable all pkeys - 0 through 15 - which,
as Thomas pointed out, seems unnecessary. The application needs the pkey it
enabled for access to its own stack, and we need to enable pkey 0 under the hood
to enable access to the alternate signal stack.
Thanks,
Aruna
next prev parent reply other threads:[~2024-06-11 14:05 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-06 22:40 [PATCH v5 0/5] x86/pkeys: update PKRU to enable pkey 0 before XSAVE Aruna Ramakrishna
2024-06-06 22:40 ` [PATCH v5 1/5] x86/pkeys: Add PKRU as a parameter in signal handling functions Aruna Ramakrishna
2024-06-10 21:31 ` Re " jeffxu
2024-06-11 13:56 ` Aruna Ramakrishna
2024-06-11 21:26 ` Jeff Xu
2024-06-06 22:40 ` [PATCH v5 2/5] x86/pkeys: Add helper functions to update PKRU on sigframe Aruna Ramakrishna
2024-06-10 21:39 ` Re " jeffxu
2024-06-11 14:05 ` Aruna Ramakrishna [this message]
2024-06-11 22:13 ` Jeff Xu
2024-06-17 16:43 ` Aruna Ramakrishna
2024-06-20 19:23 ` Jeff Xu
2024-06-06 22:40 ` [PATCH v5 3/5] x86/pkeys: Update PKRU to enable minimally required pkeys before XSAVE Aruna Ramakrishna
2024-06-06 22:40 ` [PATCH v5 4/5] x86/pkeys: Restore altstack before sigcontext Aruna Ramakrishna
2024-06-10 21:44 ` Re " jeffxu
2024-06-11 14:08 ` Aruna Ramakrishna
2024-06-11 22:16 ` Jeff Xu
2024-06-06 22:40 ` [PATCH v5 5/5] selftests/mm: Add new testcases for pkeys Aruna Ramakrishna
2024-06-10 21:21 ` Re [PATCH v5 0/5] x86/pkeys: update PKRU to enable pkey 0 before XSAVE jeffxu
2024-06-26 16:51 ` Aruna Ramakrishna
2024-06-26 16:56 ` Dave Hansen
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=2DB720B0-0921-4912-8C5F-F0EDDF77845D@oracle.com \
--to=aruna.ramakrishna@oracle.com \
--cc=andrew.brownsword@oracle.com \
--cc=dave.hansen@linux.intel.com \
--cc=jannh@google.com \
--cc=jeffxu@chromium.org \
--cc=jeffxu@google.com \
--cc=jorgelo@chromium.org \
--cc=keescook@chromium.org \
--cc=keith.lucas@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matthias.neugschwandtner@oracle.com \
--cc=mingo@kernel.org \
--cc=rick.p.edgecombe@intel.com \
--cc=sroettger@google.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
all inboxes | Powered by JetHome®