Re: [PATCH RFC V3 2/9] x86/fpu: Refactor arch_set_user_pkey_access() for PKS support

From
Ira Weiny <hidden>
Date
2020-10-13 23:57:05
Also in
linux-fsdevel, linux-kselftest, linux-mm, lkml, nvdimm
Reply to
Dave Hansen, 2020-10-13
On Tue, Oct 13, 2020 at 10:50:05AM -0700, Dave Hansen wrote:
On 10/9/20 12:42 PM, ira.weiny@intel.com wrote:
quoted
+/*
+ * Update the pk_reg value and return it.
How about:

	Replace disable bits for @pkey with values from @flags.
Done.
quoted
+ * Kernel users use the same flags as user space:
+ *     PKEY_DISABLE_ACCESS
+ *     PKEY_DISABLE_WRITE
+ */
+u32 update_pkey_val(u32 pk_reg, int pkey, unsigned int flags)
+{
+	int pkey_shift = pkey * PKR_BITS_PER_PKEY;
+
+	pk_reg &= ~(((1 << PKR_BITS_PER_PKEY) - 1) << pkey_shift);
+
+	if (flags & PKEY_DISABLE_ACCESS)
+		pk_reg |= PKR_AD_BIT << pkey_shift;
+	if (flags & PKEY_DISABLE_WRITE)
+		pk_reg |= PKR_WD_BIT << pkey_shift;
I still think this deserves two lines of comments:

	/* Mask out old bit values */

	/* Or in new values */
Sure, done.
Ira
Thread (47 messages) 47 messages, 4 authors, last reply 2020-10-20
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help