linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] selftests, x86: updates for x86 protection keys self tests
@ 2017-02-02 23:28 Dave Hansen
  2017-02-02 23:28 ` [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings Dave Hansen
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Dave Hansen @ 2017-02-02 23:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: x86, Dave Hansen

The memory protection keys selftests are spewing warnings.  This
fixes them up.  Thanks, Shuah, for sending these first two a few
weeks ago!  I wrongly assumed they would get picked up somewhere.

I also included a fix that affected the 32-bit version of the
pkeys test case.  It was parsing the siginfo incorrectly.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings
  2017-02-02 23:28 [PATCH 0/4] selftests, x86: updates for x86 protection keys self tests Dave Hansen
@ 2017-02-02 23:28 ` Dave Hansen
  2017-02-02 23:36   ` Shuah Khan
  2017-02-02 23:28 ` [PATCH 2/4] selftests, x86, protection_keys: remove dead code Dave Hansen
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Dave Hansen @ 2017-02-02 23:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: x86, Dave Hansen, shuahkh


From: Shuah Khan <shuahkh@osg.samsung.com>

Fix unused variable compile warnings in protection_keys.c

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---

 b/tools/testing/selftests/x86/protection_keys.c |    5 -----
 1 file changed, 5 deletions(-)

diff -puN tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-fix-unused-variable-compile-warnings tools/testing/selftests/x86/protection_keys.c
--- a/tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-fix-unused-variable-compile-warnings	2017-02-02 15:27:12.898110827 -0800
+++ b/tools/testing/selftests/x86/protection_keys.c	2017-02-02 15:27:12.901110962 -0800
@@ -812,8 +812,6 @@ void setup_hugetlbfs(void)
 {
 	int err;
 	int fd;
-	int validated_nr_pages;
-	int i;
 	char buf[] = "123";
 
 	if (geteuid() != 0) {
@@ -1133,7 +1131,6 @@ void test_pkey_syscalls_on_non_allocated
 void test_pkey_syscalls_bad_args(int *ptr, u16 pkey)
 {
 	int err;
-	int bad_flag = (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE) + 1;
 	int bad_pkey = NR_PKEYS+99;
 
 	/* not enforced when pkey_get() is not a syscall
@@ -1149,8 +1146,6 @@ void test_pkey_syscalls_bad_args(int *pt
 /* Assumes that all pkeys other than 'pkey' are unallocated */
 void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
 {
-	unsigned long flags;
-	unsigned long init_val;
 	int err;
 	int allocated_pkeys[NR_PKEYS] = {0};
 	int nr_allocated_pkeys = 0;
_

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/4] selftests, x86, protection_keys: remove dead code
  2017-02-02 23:28 [PATCH 0/4] selftests, x86: updates for x86 protection keys self tests Dave Hansen
  2017-02-02 23:28 ` [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings Dave Hansen
@ 2017-02-02 23:28 ` Dave Hansen
  2017-02-02 23:36   ` Shuah Khan
  2017-02-02 23:28 ` [PATCH 3/4] selftests, x86, protection_keys: fix uninitialized variable warning Dave Hansen
  2017-02-02 23:28 ` [PATCH 4/4] selftests, x86, protection_keys: fix wrong offset in siginfo Dave Hansen
  3 siblings, 1 reply; 10+ messages in thread
From: Dave Hansen @ 2017-02-02 23:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: x86, Dave Hansen, shuahkh


From: Shuah Khan <shuahkh@osg.samsung.com>

Remove commented out calls to pkey_get().

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---

 b/tools/testing/selftests/x86/protection_keys.c |   10 ----------
 1 file changed, 10 deletions(-)

diff -puN tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-remove-dead-code tools/testing/selftests/x86/protection_keys.c
--- a/tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-remove-dead-code	2017-02-02 15:27:13.329130196 -0800
+++ b/tools/testing/selftests/x86/protection_keys.c	2017-02-02 15:27:13.333130376 -0800
@@ -1114,11 +1114,6 @@ void test_pkey_syscalls_on_non_allocated
 		err = sys_pkey_free(i);
 		pkey_assert(err);
 
-		/* not enforced when pkey_get() is not a syscall
-		err = pkey_get(i, 0);
-		pkey_assert(err < 0);
-		*/
-
 		err = sys_pkey_free(i);
 		pkey_assert(err);
 
@@ -1133,11 +1128,6 @@ void test_pkey_syscalls_bad_args(int *pt
 	int err;
 	int bad_pkey = NR_PKEYS+99;
 
-	/* not enforced when pkey_get() is not a syscall
-	err = pkey_get(bad_pkey, bad_flag);
-	pkey_assert(err < 0);
-	*/
-
 	/* pass a known-invalid pkey in: */
 	err = sys_mprotect_pkey(ptr, PAGE_SIZE, PROT_READ, bad_pkey);
 	pkey_assert(err);
_

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/4] selftests, x86, protection_keys: fix uninitialized variable warning
  2017-02-02 23:28 [PATCH 0/4] selftests, x86: updates for x86 protection keys self tests Dave Hansen
  2017-02-02 23:28 ` [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings Dave Hansen
  2017-02-02 23:28 ` [PATCH 2/4] selftests, x86, protection_keys: remove dead code Dave Hansen
@ 2017-02-02 23:28 ` Dave Hansen
  2017-02-02 23:28 ` [PATCH 4/4] selftests, x86, protection_keys: fix wrong offset in siginfo Dave Hansen
  3 siblings, 0 replies; 10+ messages in thread
From: Dave Hansen @ 2017-02-02 23:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: x86, Dave Hansen


From: Dave Hansen <dave.hansen@linux.intel.com>

'orig_pkru' might have been uninitialized here.  Fix it.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---

 b/tools/testing/selftests/x86/protection_keys.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff -puN tools/testing/selftests/x86/protection_keys.c~pkeys-selftests-cleanrup-4-10-ish tools/testing/selftests/x86/protection_keys.c
--- a/tools/testing/selftests/x86/protection_keys.c~pkeys-selftests-cleanrup-4-10-ish	2017-02-02 15:27:13.758149477 -0800
+++ b/tools/testing/selftests/x86/protection_keys.c	2017-02-02 15:27:13.762149656 -0800
@@ -462,7 +462,7 @@ void pkey_disable_set(int pkey, int flag
 	unsigned long syscall_flags = 0;
 	int ret;
 	int pkey_rights;
-	u32 orig_pkru;
+	u32 orig_pkru = rdpkru();
 
 	dprintf1("START->%s(%d, 0x%x)\n", __func__,
 		pkey, flags);
_

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/4] selftests, x86, protection_keys: fix wrong offset in siginfo
  2017-02-02 23:28 [PATCH 0/4] selftests, x86: updates for x86 protection keys self tests Dave Hansen
                   ` (2 preceding siblings ...)
  2017-02-02 23:28 ` [PATCH 3/4] selftests, x86, protection_keys: fix uninitialized variable warning Dave Hansen
@ 2017-02-02 23:28 ` Dave Hansen
  3 siblings, 0 replies; 10+ messages in thread
From: Dave Hansen @ 2017-02-02 23:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: x86, Dave Hansen


From: Dave Hansen <dave.hansen@linux.intel.com>

The siginfo contains a bunch of information about the fault.
For protection keys, it tells us which protection key's
permissions were violated.

The wrong offset in here leads to reading garbage and thus
failures in the tests.

We should probably eventually move this over to using the
kernel's headers defining the siginfo instead of a hard-coded
offset.  But, for now, just do the simplest fix.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---

 b/tools/testing/selftests/x86/protection_keys.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff -puN tools/testing/selftests/x86/protection_keys.c~pkeys-selftest-fix-32bit-offset tools/testing/selftests/x86/protection_keys.c
--- a/tools/testing/selftests/x86/protection_keys.c~pkeys-selftest-fix-32bit-offset	2017-02-02 15:27:14.185168666 -0800
+++ b/tools/testing/selftests/x86/protection_keys.c	2017-02-02 15:27:14.188168801 -0800
@@ -192,7 +192,7 @@ void lots_o_noops_around_write(int *writ
 #define SYS_pkey_alloc	 381
 #define SYS_pkey_free	 382
 #define REG_IP_IDX REG_EIP
-#define si_pkey_offset 0x18
+#define si_pkey_offset 0x14
 #else
 #define SYS_mprotect_key 329
 #define SYS_pkey_alloc	 330
_

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings
  2017-02-02 23:28 ` [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings Dave Hansen
@ 2017-02-02 23:36   ` Shuah Khan
  2017-02-02 23:45     ` Dave Hansen
  0 siblings, 1 reply; 10+ messages in thread
From: Shuah Khan @ 2017-02-02 23:36 UTC (permalink / raw)
  To: Dave Hansen, linux-kernel; +Cc: x86, Shuah Khan

On 02/02/2017 04:28 PM, Dave Hansen wrote:
> From: Shuah Khan <shuahkh@osg.samsung.com>
> 
> Fix unused variable compile warnings in protection_keys.c
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>

Hi Dave,

This patches is already in linux-kselftest next for 4.11

Is there a reason why you chose to resend these.

-- Shuah

> ---
> 
>  b/tools/testing/selftests/x86/protection_keys.c |    5 -----
>  1 file changed, 5 deletions(-)
> 
> diff -puN tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-fix-unused-variable-compile-warnings tools/testing/selftests/x86/protection_keys.c
> --- a/tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-fix-unused-variable-compile-warnings	2017-02-02 15:27:12.898110827 -0800
> +++ b/tools/testing/selftests/x86/protection_keys.c	2017-02-02 15:27:12.901110962 -0800
> @@ -812,8 +812,6 @@ void setup_hugetlbfs(void)
>  {
>  	int err;
>  	int fd;
> -	int validated_nr_pages;
> -	int i;
>  	char buf[] = "123";
>  
>  	if (geteuid() != 0) {
> @@ -1133,7 +1131,6 @@ void test_pkey_syscalls_on_non_allocated
>  void test_pkey_syscalls_bad_args(int *ptr, u16 pkey)
>  {
>  	int err;
> -	int bad_flag = (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE) + 1;
>  	int bad_pkey = NR_PKEYS+99;
>  
>  	/* not enforced when pkey_get() is not a syscall
> @@ -1149,8 +1146,6 @@ void test_pkey_syscalls_bad_args(int *pt
>  /* Assumes that all pkeys other than 'pkey' are unallocated */
>  void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
>  {
> -	unsigned long flags;
> -	unsigned long init_val;
>  	int err;
>  	int allocated_pkeys[NR_PKEYS] = {0};
>  	int nr_allocated_pkeys = 0;
> _
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/4] selftests, x86, protection_keys: remove dead code
  2017-02-02 23:28 ` [PATCH 2/4] selftests, x86, protection_keys: remove dead code Dave Hansen
@ 2017-02-02 23:36   ` Shuah Khan
  0 siblings, 0 replies; 10+ messages in thread
From: Shuah Khan @ 2017-02-02 23:36 UTC (permalink / raw)
  To: Dave Hansen, linux-kernel; +Cc: x86, Shuah Khan

On 02/02/2017 04:28 PM, Dave Hansen wrote:
> From: Shuah Khan <shuahkh@osg.samsung.com>
> 
> Remove commented out calls to pkey_get().
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>

Hi Dave,

This patches is already in linux-kselftest next for 4.11

Is there a reason why you chose to resend these.

-- Shuah

> ---
> 
>  b/tools/testing/selftests/x86/protection_keys.c |   10 ----------
>  1 file changed, 10 deletions(-)
> 
> diff -puN tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-remove-dead-code tools/testing/selftests/x86/protection_keys.c
> --- a/tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-remove-dead-code	2017-02-02 15:27:13.329130196 -0800
> +++ b/tools/testing/selftests/x86/protection_keys.c	2017-02-02 15:27:13.333130376 -0800
> @@ -1114,11 +1114,6 @@ void test_pkey_syscalls_on_non_allocated
>  		err = sys_pkey_free(i);
>  		pkey_assert(err);
>  
> -		/* not enforced when pkey_get() is not a syscall
> -		err = pkey_get(i, 0);
> -		pkey_assert(err < 0);
> -		*/
> -
>  		err = sys_pkey_free(i);
>  		pkey_assert(err);
>  
> @@ -1133,11 +1128,6 @@ void test_pkey_syscalls_bad_args(int *pt
>  	int err;
>  	int bad_pkey = NR_PKEYS+99;
>  
> -	/* not enforced when pkey_get() is not a syscall
> -	err = pkey_get(bad_pkey, bad_flag);
> -	pkey_assert(err < 0);
> -	*/
> -
>  	/* pass a known-invalid pkey in: */
>  	err = sys_mprotect_pkey(ptr, PAGE_SIZE, PROT_READ, bad_pkey);
>  	pkey_assert(err);
> _
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings
  2017-02-02 23:36   ` Shuah Khan
@ 2017-02-02 23:45     ` Dave Hansen
  2017-02-02 23:49       ` Shuah Khan
  0 siblings, 1 reply; 10+ messages in thread
From: Dave Hansen @ 2017-02-02 23:45 UTC (permalink / raw)
  To: Shuah Khan, linux-kernel; +Cc: x86

On 02/02/2017 03:36 PM, Shuah Khan wrote:
> This patches is already in linux-kselftest next for 4.11
> 
> Is there a reason why you chose to resend these.

Oh, my apologies!  I didn't realize it had been picked up elsewhere.
Ingo had mentioned a few times in the last few days that he'd noticed
the warnings.

So, x86 maintainers, do we want these to go through the kselftest tree
or the x86 tree?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings
  2017-02-02 23:45     ` Dave Hansen
@ 2017-02-02 23:49       ` Shuah Khan
  2017-02-03  6:43         ` Ingo Molnar
  0 siblings, 1 reply; 10+ messages in thread
From: Shuah Khan @ 2017-02-02 23:49 UTC (permalink / raw)
  To: Dave Hansen, linux-kernel; +Cc: x86, Shuah Khan

On 02/02/2017 04:45 PM, Dave Hansen wrote:
> On 02/02/2017 03:36 PM, Shuah Khan wrote:
>> This patches is already in linux-kselftest next for 4.11
>>
>> Is there a reason why you chose to resend these.
> 
> Oh, my apologies!  I didn't realize it had been picked up elsewhere.
> Ingo had mentioned a few times in the last few days that he'd noticed
> the warnings.
> 
> So, x86 maintainers, do we want these to go through the kselftest tree
> or the x86 tree?
> 

I usually let many of the new tests that depend on new features go through
x86 tree. Patches that fix problems that are already in kselftest, I send
them up in via kselftest.

I noticed these when very early on when 4.10-rc1 came out and send the patches
out. SO they have been in linux-kselftest next for a while now.

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings
  2017-02-02 23:49       ` Shuah Khan
@ 2017-02-03  6:43         ` Ingo Molnar
  0 siblings, 0 replies; 10+ messages in thread
From: Ingo Molnar @ 2017-02-03  6:43 UTC (permalink / raw)
  To: Shuah Khan; +Cc: Dave Hansen, linux-kernel, x86


* Shuah Khan <shuahkh@osg.samsung.com> wrote:

> On 02/02/2017 04:45 PM, Dave Hansen wrote:
> > On 02/02/2017 03:36 PM, Shuah Khan wrote:
> >> This patches is already in linux-kselftest next for 4.11
> >>
> >> Is there a reason why you chose to resend these.
> > 
> > Oh, my apologies!  I didn't realize it had been picked up elsewhere.
> > Ingo had mentioned a few times in the last few days that he'd noticed
> > the warnings.
> > 
> > So, x86 maintainers, do we want these to go through the kselftest tree
> > or the x86 tree?
> > 
> 
> I usually let many of the new tests that depend on new features go through
> x86 tree. Patches that fix problems that are already in kselftest, I send
> them up in via kselftest.
> 
> I noticed these when very early on when 4.10-rc1 came out and send the patches
> out. SO they have been in linux-kselftest next for a while now.

That's OK, but please Cc: me (or at least lkml) next time around.

Also, these should have been sent to Linus as fixes once the warnings were 
noticed, not queued up for v4.11 - but it's probably too late for that.

Are you going to pick up the other two fixes as well? They look good to me:

Acked-by: Ingo Molnar <mingo@kernel.org>

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-02-03  6:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-02 23:28 [PATCH 0/4] selftests, x86: updates for x86 protection keys self tests Dave Hansen
2017-02-02 23:28 ` [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings Dave Hansen
2017-02-02 23:36   ` Shuah Khan
2017-02-02 23:45     ` Dave Hansen
2017-02-02 23:49       ` Shuah Khan
2017-02-03  6:43         ` Ingo Molnar
2017-02-02 23:28 ` [PATCH 2/4] selftests, x86, protection_keys: remove dead code Dave Hansen
2017-02-02 23:36   ` Shuah Khan
2017-02-02 23:28 ` [PATCH 3/4] selftests, x86, protection_keys: fix uninitialized variable warning Dave Hansen
2017-02-02 23:28 ` [PATCH 4/4] selftests, x86, protection_keys: fix wrong offset in siginfo Dave Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).