mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-08-16 14:45:36 +00:00

Commit50910acd6f
("selftests/mm: use sys_pkey helpers consistently") added a pkey_util.c to refactor some of the protection_keys functions accessible by other tests. But this broken the build in powerpc in two ways, pkey-powerpc.h: In function `arch_is_powervm': pkey-powerpc.h:73:21: error: storage size of `buf' isn't known 73 | struct stat buf; | ^~~ pkey-powerpc.h:75:14: error: implicit declaration of function `stat'; did you mean `strcat'? [-Wimplicit-function-declaration] 75 | if ((stat("/sys/firmware/devicetree/base/ibm,partition-name", &buf) == 0) && | ^~~~ | strcat Since pkey_util.c includes pkeys-helper.h, which in turn includes pkeys-powerpc.h, stat.h including is missing for "struct stat". This is fixed by adding "sys/stat.h" in pkeys-powerpc.h Secondly, pkey-powerpc.h:55:18: warning: format `%llx' expects argument of type `long long unsigned int', but argument 3 has type `u64' {aka `long unsigned int'} [-Wformat=] 55 | dprintf4("%s() changing %016llx to %016llx\n", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 56 | __func__, __read_pkey_reg(), pkey_reg); | ~~~~~~~~~~~~~~~~~ | | | u64 {aka long unsigned int} pkey-helpers.h:63:32: note: in definition of macro `dprintf_level' 63 | sigsafe_printf(args); \ | ^~~~ These format specifier related warning are removed by adding "__SANE_USERSPACE_TYPES__" to pkeys_utils.c. Link: https://lkml.kernel.org/r/20250428131937.641989-1-nysal@linux.ibm.com Fixes:50910acd6f
("selftests/mm: use sys_pkey helpers consistently") Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Signed-off-by: Nysal Jan K.A. <nysal@linux.ibm.com> Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
42 lines
1.1 KiB
C
42 lines
1.1 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
#define __SANE_USERSPACE_TYPES__
|
|
#include <sys/syscall.h>
|
|
#include <unistd.h>
|
|
|
|
#include "pkey-helpers.h"
|
|
|
|
int sys_pkey_alloc(unsigned long flags, unsigned long init_val)
|
|
{
|
|
int ret = syscall(SYS_pkey_alloc, flags, init_val);
|
|
dprintf1("%s(flags=%lx, init_val=%lx) syscall ret: %d errno: %d\n",
|
|
__func__, flags, init_val, ret, errno);
|
|
return ret;
|
|
}
|
|
|
|
int sys_pkey_free(unsigned long pkey)
|
|
{
|
|
int ret = syscall(SYS_pkey_free, pkey);
|
|
dprintf1("%s(pkey=%ld) syscall ret: %d\n", __func__, pkey, ret);
|
|
return ret;
|
|
}
|
|
|
|
int sys_mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
|
|
unsigned long pkey)
|
|
{
|
|
int sret;
|
|
|
|
dprintf2("%s(0x%p, %zx, prot=%lx, pkey=%lx)\n", __func__,
|
|
ptr, size, orig_prot, pkey);
|
|
|
|
errno = 0;
|
|
sret = syscall(__NR_pkey_mprotect, ptr, size, orig_prot, pkey);
|
|
if (errno) {
|
|
dprintf2("SYS_mprotect_key sret: %d\n", sret);
|
|
dprintf2("SYS_mprotect_key prot: 0x%lx\n", orig_prot);
|
|
dprintf2("SYS_mprotect_key failed, errno: %d\n", errno);
|
|
if (DEBUG_LEVEL >= 2)
|
|
perror("SYS_mprotect_pkey");
|
|
}
|
|
return sret;
|
|
}
|