Re: [PATCH v12 05/22] selftests/vm: generic function to handle shadow key register

From
Dave Hansen <hidden>
Date
2018-03-16 22:05:32
Also in
linux-arch, linux-doc, linux-kselftest, linux-mm, lkml
Reply to
Ram Pai, 2018-02-22
On 02/21/2018 05:55 PM, Ram Pai wrote:
quoted hunk ↗ jump to hunk
+static inline u32 pkey_to_shift(int pkey)
+{
+	return pkey * PKEY_BITS_PER_PKEY;
+}
pkey_bit_position(), perhaps?
quoted hunk ↗ jump to hunk
+static inline pkey_reg_t reset_bits(int pkey, pkey_reg_t bits)
+{
+	u32 shift = pkey_to_shift(pkey);
+
+	return ~(bits << shift);
+}
I'd prefer clear_pkey_flags() or maybe clear_pkey_bits().  "reset" can
mean "reset to 0" or "reset to 1".

Also, why the u32 here?  Isn't an int more appropriate?
quoted hunk ↗ jump to hunk
+static inline pkey_reg_t left_shift_bits(int pkey, pkey_reg_t bits)
+{
+	u32 shift = pkey_to_shift(pkey);
+
+	return (bits << shift);
+}
+
+static inline pkey_reg_t right_shift_bits(int pkey, pkey_reg_t bits)
+{
+	u32 shift = pkey_to_shift(pkey);
+
+	return (bits >> shift);
+}
Some comments on these would be handy.  Basically that this takes a
per-key flags value and puts it at the right position so it can be
shoved in the register.
Thread (49 messages) 49 messages, 5 authors, last reply 2018-03-28
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