mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH 0/9] linux v4.16 update
@ 2018-04-28 19:56 Szabolcs Nagy
  2018-04-28 21:39 ` Szabolcs Nagy
  2018-05-15 17:39 ` Rich Felker
  0 siblings, 2 replies; 5+ messages in thread
From: Szabolcs Nagy @ 2018-04-28 19:56 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 2056 bytes --]

the ptrace.h change is probably not ok
(glibc added struct __ptrace_seccomp_metadata
instead of the kernel struct seccomp_metadata,
but the same is true for ptrace_peeksiginfo_args
where musl currently follows linux instead of
glibc, maybe that should be fixed?).

the last patch is an unfinished proposal to add
some new syscalls glibc already has, but i ran
into some issues so comments are welcome.

i ran the patch set through compile testing.

Szabolcs Nagy (9):
  siginfo struct change following linux v4.16
  elf.h: add NT_PPC_PKEY from linux v4.16
  sys/epoll.h: add EPOLLNVAL from linux v4.16
  netinet/if_ether.h: add ETH_P_ERSPAN2 from linux v4.16
  netinet/if_ether.h: add ETH_TLEN from linux v4.16
  sys/ptrace.h: add PTRACE_SECCOMP_GET_METADATA from linux v4.16
  aarch64: add HWCAP_ASIMDFHM from linux v4.16
  powerpc: add pkey syscall numbers from linux v4.16
  [RFC] add new memory mapping related apis

 arch/aarch64/bits/hwcap.h        |  1 +
 arch/powerpc/bits/mman.h         |  4 ++++
 arch/powerpc/bits/syscall.h.in   |  3 +++
 arch/powerpc64/bits/mman.h       |  4 ++++
 arch/powerpc64/bits/syscall.h.in |  3 +++
 include/elf.h                    |  1 +
 include/netinet/if_ether.h       |  2 ++
 include/signal.h                 | 12 ++++++++----
 include/sys/epoll.h              |  1 +
 include/sys/mman.h               | 24 +++++++++++++++++++++---
 include/sys/ptrace.h             |  6 ++++++
 src/linux/memfd_create.c         | 10 ++++++++++
 src/linux/mlock2.c               | 15 +++++++++++++++
 src/linux/pkey_alloc.c           | 15 +++++++++++++++
 src/linux/pkey_get.c             |  9 +++++++++
 src/linux/pkey_mprotect.c        | 15 +++++++++++++++
 src/linux/pkey_set.c             |  9 +++++++++
 17 files changed, 127 insertions(+), 7 deletions(-)
 create mode 100644 src/linux/memfd_create.c
 create mode 100644 src/linux/mlock2.c
 create mode 100644 src/linux/pkey_alloc.c
 create mode 100644 src/linux/pkey_get.c
 create mode 100644 src/linux/pkey_mprotect.c
 create mode 100644 src/linux/pkey_set.c

-- 
2.16.3


[-- Attachment #2: 0001-siginfo-struct-change-following-linux-v4.16.patch --]
[-- Type: text/x-diff, Size: 1970 bytes --]

From f7eb8934396890e39b9e5e2b4fdd1534f1c024cc Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Mon, 16 Apr 2018 22:16:29 +0000
Subject: [PATCH 1/9] siginfo struct change following linux v4.16

this is supposed to be a cosmetic change only, not affecting api or abi,
follows linux commit b68a68d3dcc15ebbf23cbe91af1abf57591bd96b and
859d880cf544dbe095ce97534ef04cd88ba2f2b4 with slightly different field
names to follow musl conventions (which must be different to avoid
depending on anonymous union support and polluting the namespace).
---
 include/signal.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/signal.h b/include/signal.h
index a4f85cca..d68331e8 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -123,13 +123,17 @@ typedef struct {
 		} __si_common;
 		struct {
 			void *si_addr;
-			short si_addr_lsb;
 			union {
+				short si_addr_lsb;
 				struct {
+					void *__dummy_bnd;
 					void *si_lower;
 					void *si_upper;
 				} __addr_bnd;
-				unsigned si_pkey;
+				struct {
+					void *__dummy_pkey;
+					unsigned si_pkey;
+				} __addr_pkey;
 			} __first;
 		} __sigfault;
 		struct {
@@ -150,10 +154,10 @@ typedef struct {
 #define si_stime   __si_fields.__si_common.__second.__sigchld.si_stime
 #define si_value   __si_fields.__si_common.__second.si_value
 #define si_addr    __si_fields.__sigfault.si_addr
-#define si_addr_lsb __si_fields.__sigfault.si_addr_lsb
+#define si_addr_lsb __si_fields.__sigfault.__first.si_addr_lsb
 #define si_lower   __si_fields.__sigfault.__first.__addr_bnd.si_lower
 #define si_upper   __si_fields.__sigfault.__first.__addr_bnd.si_upper
-#define si_pkey    __si_fields.__sigfault.__first.si_pkey
+#define si_pkey    __si_fields.__sigfault.__first.__addr_pkey.si_pkey
 #define si_band    __si_fields.__sigpoll.si_band
 #define si_fd      __si_fields.__sigpoll.si_fd
 #define si_timerid __si_fields.__si_common.__first.__timer.si_timerid
-- 
2.16.3


[-- Attachment #3: 0002-elf.h-add-NT_PPC_PKEY-from-linux-v4.16.patch --]
[-- Type: text/x-diff, Size: 727 bytes --]

From 053000e97c8e840ef845bba4c3b30d6dd913b327 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 28 Apr 2018 15:17:22 +0000
Subject: [PATCH 2/9] elf.h: add NT_PPC_PKEY from linux v4.16

new in linux commit c5cc1f4df6b16646f8fae7aab523c1820bf916e8
for memory protection key regset.
---
 include/elf.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/elf.h b/include/elf.h
index 78906f15..824da72a 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -658,6 +658,7 @@ typedef struct {
 #define NT_PPC_TM_CTAR	0x10d
 #define NT_PPC_TM_CPPR	0x10e
 #define NT_PPC_TM_CDSCR	0x10f
+#define NT_PPC_PKEY	0x110
 #define NT_386_TLS	0x200
 #define NT_386_IOPERM	0x201
 #define NT_X86_XSTATE	0x202
-- 
2.16.3


[-- Attachment #4: 0003-sys-epoll.h-add-EPOLLNVAL-from-linux-v4.16.patch --]
[-- Type: text/x-diff, Size: 833 bytes --]

From fc0f2a15e6a88e986d3f69accaff5e5ac038ab97 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 28 Apr 2018 15:52:06 +0000
Subject: [PATCH 3/9] sys/epoll.h: add EPOLLNVAL from linux v4.16

added to uapi in commit 65aaf87b3aa2d049c6b9fd85221858a895df3393
used since commit a9a08845e9acbd224e4ee466f5c1275ed50054e8,
which renamed POLL* to EPOLL* in the kernel.
---
 include/sys/epoll.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/sys/epoll.h b/include/sys/epoll.h
index ffe2311f..ac81a841 100644
--- a/include/sys/epoll.h
+++ b/include/sys/epoll.h
@@ -21,6 +21,7 @@ enum EPOLL_EVENTS { __EPOLL_DUMMY };
 #define EPOLLPRI 0x002
 #define EPOLLOUT 0x004
 #define EPOLLRDNORM 0x040
+#define EPOLLNVAL 0x020
 #define EPOLLRDBAND 0x080
 #define EPOLLWRNORM 0x100
 #define EPOLLWRBAND 0x200
-- 
2.16.3


[-- Attachment #5: 0004-netinet-if_ether.h-add-ETH_P_ERSPAN2-from-linux-v4.1.patch --]
[-- Type: text/x-diff, Size: 779 bytes --]

From 79a4caaa6710729c8abd928f1b60200769d0a72b Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 28 Apr 2018 16:10:53 +0000
Subject: [PATCH 4/9] netinet/if_ether.h: add ETH_P_ERSPAN2 from linux v4.16

protocol number for erspan v2 support
added in linux commit f551c91de262ba36b20c3ac19538afb4f4507441
---
 include/netinet/if_ether.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h
index 9007d609..33f08a31 100644
--- a/include/netinet/if_ether.h
+++ b/include/netinet/if_ether.h
@@ -17,6 +17,7 @@
 #define ETH_P_PUP	0x0200
 #define ETH_P_PUPAT	0x0201
 #define ETH_P_TSN	0x22F0
+#define ETH_P_ERSPAN2	0x22EB
 #define ETH_P_IP	0x0800
 #define ETH_P_X25	0x0805
 #define ETH_P_ARP	0x0806
-- 
2.16.3


[-- Attachment #6: 0005-netinet-if_ether.h-add-ETH_TLEN-from-linux-v4.16.patch --]
[-- Type: text/x-diff, Size: 712 bytes --]

From 0ec099eeb809d8fa0d0f9930f8febf6cc9cf2438 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 28 Apr 2018 16:16:12 +0000
Subject: [PATCH 5/9] netinet/if_ether.h: add ETH_TLEN from linux v4.16

octets in ethernet type field
added in linux commit 4bbb3e0e8239f9079bf1fe20b3c0cb598714ae61
---
 include/netinet/if_ether.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h
index 33f08a31..f7df5f7f 100644
--- a/include/netinet/if_ether.h
+++ b/include/netinet/if_ether.h
@@ -5,6 +5,7 @@
 #include <sys/types.h>
 
 #define ETH_ALEN	6
+#define ETH_TLEN	2
 #define ETH_HLEN	14
 #define ETH_ZLEN	60
 #define ETH_DATA_LEN	1500
-- 
2.16.3


[-- Attachment #7: 0006-sys-ptrace.h-add-PTRACE_SECCOMP_GET_METADATA-from-li.patch --]
[-- Type: text/x-diff, Size: 1015 bytes --]

From 9f06414a68af64fa1834e46ef59ac32d2b82aa11 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 28 Apr 2018 16:23:23 +0000
Subject: [PATCH 6/9] sys/ptrace.h: add PTRACE_SECCOMP_GET_METADATA from linux
 v4.16

to get seccomp state for checkpoint restore.
added in linux commit 26500475ac1b499d8636ff281311d633909f5d20
---
 include/sys/ptrace.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/sys/ptrace.h b/include/sys/ptrace.h
index d9d45408..4eedbbb4 100644
--- a/include/sys/ptrace.h
+++ b/include/sys/ptrace.h
@@ -40,6 +40,7 @@ extern "C" {
 #define PTRACE_GETSIGMASK 0x420a
 #define PTRACE_SETSIGMASK 0x420b
 #define PTRACE_SECCOMP_GET_FILTER 0x420c
+#define PTRACE_SECCOMP_GET_METADATA 0x420d
 
 #define PT_READ_I PTRACE_PEEKTEXT
 #define PT_READ_D PTRACE_PEEKDATA
@@ -92,6 +93,11 @@ struct ptrace_peeksiginfo_args {
 	int32_t nr;
 };
 
+struct seccomp_metadata {
+	uint64_t filter_off;
+	uint64_t flags;
+};
+
 long ptrace(int, ...);
 
 #ifdef __cplusplus
-- 
2.16.3


[-- Attachment #8: 0007-aarch64-add-HWCAP_ASIMDFHM-from-linux-v4.16.patch --]
[-- Type: text/x-diff, Size: 694 bytes --]

From 8821b766147efcc88352e656c3a456a61b0e3ed4 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 28 Apr 2018 16:29:55 +0000
Subject: [PATCH 7/9] aarch64: add HWCAP_ASIMDFHM from linux v4.16

armv8.4 fp mul instructions.
added in commit 3b3b681097fae73b7f5dcdd42db6cfdf32943d4c
---
 arch/aarch64/bits/hwcap.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/aarch64/bits/hwcap.h b/arch/aarch64/bits/hwcap.h
index 1727a387..6fa64e8c 100644
--- a/arch/aarch64/bits/hwcap.h
+++ b/arch/aarch64/bits/hwcap.h
@@ -21,3 +21,4 @@
 #define HWCAP_ASIMDDP		(1 << 20)
 #define HWCAP_SHA512		(1 << 21)
 #define HWCAP_SVE		(1 << 22)
+#define HWCAP_ASIMDFHM		(1 << 23)
-- 
2.16.3


[-- Attachment #9: 0008-powerpc-add-pkey-syscall-numbers-from-linux-v4.16.patch --]
[-- Type: text/x-diff, Size: 1423 bytes --]

From 811fd993675e21c752099ee15c0600688672a78b Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 28 Apr 2018 16:36:40 +0000
Subject: [PATCH 8/9] powerpc: add pkey syscall numbers from linux v4.16

add pkey_mprotect, pkey_alloc, pkey_free syscall numbers,
new in linux commits 3350eb2ea127978319ced883523d828046af4045
and 9499ec1b5e82321829e1c1510bcc37edc20b6f38
---
 arch/powerpc/bits/syscall.h.in   | 3 +++
 arch/powerpc64/bits/syscall.h.in | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/arch/powerpc/bits/syscall.h.in b/arch/powerpc/bits/syscall.h.in
index 20833915..7ce94bbd 100644
--- a/arch/powerpc/bits/syscall.h.in
+++ b/arch/powerpc/bits/syscall.h.in
@@ -368,4 +368,7 @@
 #define __NR_pwritev2              381
 #define __NR_kexec_file_load       382
 #define __NR_statx                 383
+#define __NR_pkey_alloc            384
+#define __NR_pkey_free             385
+#define __NR_pkey_mprotect         386
 
diff --git a/arch/powerpc64/bits/syscall.h.in b/arch/powerpc64/bits/syscall.h.in
index 936f43c0..1da1ecc0 100644
--- a/arch/powerpc64/bits/syscall.h.in
+++ b/arch/powerpc64/bits/syscall.h.in
@@ -359,4 +359,7 @@
 #define __NR_pwritev2               381
 #define __NR_kexec_file_load        382
 #define __NR_statx                  383
+#define __NR_pkey_alloc             384
+#define __NR_pkey_free              385
+#define __NR_pkey_mprotect          386
 
-- 
2.16.3


[-- Attachment #10: 0009-RFC-add-new-memory-mapping-related-apis.patch --]
[-- Type: text/x-diff, Size: 5892 bytes --]

From de4ca3284d759563322c795479601e9eee394832 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 28 Apr 2018 17:25:41 +0000
Subject: [PATCH 9/9] [RFC] add new memory mapping related apis

memfd_create (linux v3.17)
mlock2 (linux v4.4)
pkey_alloc (linux v4.9)
pkey_free (linux v4.9)
pkey_mprotect (linux v4.9)
pkey_get (glibc 2.27)
pkey_set (glibc 2.27)

notes:

- pkey_alloc type is inconsistent between the manual and
  the glibc source (unsigned int vs unsigned long args)
- pkey_get / pkey_set are not syscalls (query/update the
  pkru register on x86), not implemented yet.
- fallback in mlock2 to mlock and pkey_mprotect to mprotect
  follows glibc.
- mlock2 EINVAL return means invalid (or unsupported) flags.
- moved MLOCK_ONFAULT under _GNU_SOURCE following glibc.
---
 arch/powerpc/bits/mman.h   |  4 ++++
 arch/powerpc64/bits/mman.h |  4 ++++
 include/sys/mman.h         | 24 +++++++++++++++++++++---
 src/linux/memfd_create.c   | 10 ++++++++++
 src/linux/mlock2.c         | 15 +++++++++++++++
 src/linux/pkey_alloc.c     | 15 +++++++++++++++
 src/linux/pkey_get.c       |  9 +++++++++
 src/linux/pkey_mprotect.c  | 15 +++++++++++++++
 src/linux/pkey_set.c       |  9 +++++++++
 9 files changed, 102 insertions(+), 3 deletions(-)
 create mode 100644 src/linux/memfd_create.c
 create mode 100644 src/linux/mlock2.c
 create mode 100644 src/linux/pkey_alloc.c
 create mode 100644 src/linux/pkey_get.c
 create mode 100644 src/linux/pkey_mprotect.c
 create mode 100644 src/linux/pkey_set.c

diff --git a/arch/powerpc/bits/mman.h b/arch/powerpc/bits/mman.h
index b3a675a8..23e18eb1 100644
--- a/arch/powerpc/bits/mman.h
+++ b/arch/powerpc/bits/mman.h
@@ -12,3 +12,7 @@
 #define MCL_FUTURE      0x4000
 #undef MCL_ONFAULT
 #define MCL_ONFAULT     0x8000
+
+#ifdef _GNU_SOURCE
+#define PKEY_DISABLE_EXECUTE   0x4
+#endif
diff --git a/arch/powerpc64/bits/mman.h b/arch/powerpc64/bits/mman.h
index b3a675a8..23e18eb1 100644
--- a/arch/powerpc64/bits/mman.h
+++ b/arch/powerpc64/bits/mman.h
@@ -12,3 +12,7 @@
 #define MCL_FUTURE      0x4000
 #undef MCL_ONFAULT
 #define MCL_ONFAULT     0x8000
+
+#ifdef _GNU_SOURCE
+#define PKEY_DISABLE_EXECUTE   0x4
+#endif
diff --git a/include/sys/mman.h b/include/sys/mman.h
index 302ad134..aea40452 100644
--- a/include/sys/mman.h
+++ b/include/sys/mman.h
@@ -93,6 +93,20 @@ extern "C" {
 #define MADV_SOFT_OFFLINE 101
 #endif
 
+#ifdef _GNU_SOURCE
+#define MREMAP_MAYMOVE 1
+#define MREMAP_FIXED 2
+
+#define PKEY_DISABLE_ACCESS 0x1
+#define PKEY_DISABLE_WRITE 0x2
+
+#define MLOCK_ONFAULT 0x01
+
+#define MFD_CLOEXEC 0x0001U
+#define MFD_ALLOW_SEALING 0x0002U
+#define MFD_HUGETLB 0x0004U
+#endif
+
 #include <bits/mman.h>
 
 void *mmap (void *, size_t, int, int, int, off_t);
@@ -109,14 +123,18 @@ int mlockall (int);
 int munlockall (void);
 
 #ifdef _GNU_SOURCE
-#define MREMAP_MAYMOVE 1
-#define MREMAP_FIXED 2
 void *mremap (void *, size_t, size_t, int, ...);
 int remap_file_pages (void *, size_t, int, size_t, int);
+int memfd_create (const char *, unsigned);
+int mlock2 (const void *, size_t, unsigned);
+int pkey_alloc (unsigned, unsigned);
+int pkey_free (int);
+int pkey_mprotect (void *, size_t, int, int);
+int pkey_get (int);
+int pkey_set (int, unsigned);
 #endif
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define MLOCK_ONFAULT   0x01
 int madvise (void *, size_t, int);
 int mincore (void *, size_t, unsigned char *);
 #endif
diff --git a/src/linux/memfd_create.c b/src/linux/memfd_create.c
new file mode 100644
index 00000000..0b33cc23
--- /dev/null
+++ b/src/linux/memfd_create.c
@@ -0,0 +1,10 @@
+#include "syscall.h"
+
+#ifdef SYS_memfd_create
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+int memfd_create (const char *name, unsigned flags)
+{
+	return syscall(SYS_memfd_create, name, flags);
+}
+#endif
diff --git a/src/linux/mlock2.c b/src/linux/mlock2.c
new file mode 100644
index 00000000..5cd3fbe7
--- /dev/null
+++ b/src/linux/mlock2.c
@@ -0,0 +1,15 @@
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+#include <errno.h>
+#include "syscall.h"
+
+int mlock2(const void *addr, size_t len, unsigned flags)
+{
+	if (flags == 0)
+		return mlock(addr, len);
+#ifdef SYS_mlock2
+	return syscall(SYS_mlock2, addr, len, flags);
+#else
+	return __syscall_ret(-EINVAL);
+#endif
+}
diff --git a/src/linux/pkey_alloc.c b/src/linux/pkey_alloc.c
new file mode 100644
index 00000000..0b0770a6
--- /dev/null
+++ b/src/linux/pkey_alloc.c
@@ -0,0 +1,15 @@
+#include "syscall.h"
+
+#ifdef SYS_pkey_alloc
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+int pkey_alloc(unsigned flags, unsigned access)
+{
+	return syscall(SYS_pkey_alloc, flags, access);
+}
+
+int pkey_free(int pkey)
+{
+	return syscall(SYS_pkey_free, pkey);
+}
+#endif
diff --git a/src/linux/pkey_get.c b/src/linux/pkey_get.c
new file mode 100644
index 00000000..d583fa9c
--- /dev/null
+++ b/src/linux/pkey_get.c
@@ -0,0 +1,9 @@
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+#include <errno.h>
+#include "syscall.h"
+
+int pkey_get(int pkey)
+{
+	return __syscall_ret(-ENOSYS);
+}
diff --git a/src/linux/pkey_mprotect.c b/src/linux/pkey_mprotect.c
new file mode 100644
index 00000000..dabf9b61
--- /dev/null
+++ b/src/linux/pkey_mprotect.c
@@ -0,0 +1,15 @@
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+#include <errno.h>
+#include "syscall.h"
+
+int pkey_mprotect(void *addr, size_t len, int prot, int pkey)
+{
+	if (pkey == -1)
+		return mprotect(addr, len, prot);
+#ifdef SYS_pkey_mprotect
+	return syscall(SYS_pkey_mprotect, addr, len, prot, pkey);
+#else
+	return __syscall_ret(-EINVAL);
+#endif
+}
diff --git a/src/linux/pkey_set.c b/src/linux/pkey_set.c
new file mode 100644
index 00000000..addf8da5
--- /dev/null
+++ b/src/linux/pkey_set.c
@@ -0,0 +1,9 @@
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+#include <errno.h>
+#include "syscall.h"
+
+int pkey_set(int pkey, unsigned access)
+{
+	return __syscall_ret(-ENOSYS);
+}
-- 
2.16.3


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

* Re: [PATCH 0/9] linux v4.16 update
  2018-04-28 19:56 [PATCH 0/9] linux v4.16 update Szabolcs Nagy
@ 2018-04-28 21:39 ` Szabolcs Nagy
  2018-05-15 17:39 ` Rich Felker
  1 sibling, 0 replies; 5+ messages in thread
From: Szabolcs Nagy @ 2018-04-28 21:39 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 635 bytes --]

* Szabolcs Nagy <nsz@port70.net> [2018-04-28 21:56:56 +0200]:
> the ptrace.h change is probably not ok
> (glibc added struct __ptrace_seccomp_metadata
> instead of the kernel struct seccomp_metadata,
> but the same is true for ptrace_peeksiginfo_args
> where musl currently follows linux instead of
> glibc, maybe that should be fixed?).
> 

i created a patch that follows the glibc api.

> the last patch is an unfinished proposal to add
> some new syscalls glibc already has, but i ran
> into some issues so comments are welcome.
> 

i fixed up a few issues there, i'm still not sure
about pkey*.

attached v2 of these two patches.


[-- Attachment #2: 0006-sys-ptrace.h-add-PTRACE_SECCOMP_GET_METADATA-from-li.patch --]
[-- Type: text/x-diff, Size: 1258 bytes --]

From ffeb39f15a7b1558534b26556e6fc19f40b1b3d9 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 28 Apr 2018 16:23:23 +0000
Subject: [PATCH 6/9] sys/ptrace.h: add PTRACE_SECCOMP_GET_METADATA from linux
 v4.16

to get seccomp state for checkpoint restore.
added in linux commit 26500475ac1b499d8636ff281311d633909f5d20

struct tag follows the glibc api and ptrace_peeksiginfo_args
got changed too accordingly.
---
 include/sys/ptrace.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/sys/ptrace.h b/include/sys/ptrace.h
index d9d45408..f501ff08 100644
--- a/include/sys/ptrace.h
+++ b/include/sys/ptrace.h
@@ -40,6 +40,7 @@ extern "C" {
 #define PTRACE_GETSIGMASK 0x420a
 #define PTRACE_SETSIGMASK 0x420b
 #define PTRACE_SECCOMP_GET_FILTER 0x420c
+#define PTRACE_SECCOMP_GET_METADATA 0x420d
 
 #define PT_READ_I PTRACE_PEEKTEXT
 #define PT_READ_D PTRACE_PEEKDATA
@@ -86,12 +87,17 @@ extern "C" {
 
 #define PTRACE_PEEKSIGINFO_SHARED 1
 
-struct ptrace_peeksiginfo_args {
+struct __ptrace_peeksiginfo_args {
 	uint64_t off;
 	uint32_t flags;
 	int32_t nr;
 };
 
+struct __ptrace_seccomp_metadata {
+	uint64_t filter_off;
+	uint64_t flags;
+};
+
 long ptrace(int, ...);
 
 #ifdef __cplusplus
-- 
2.16.3


[-- Attachment #3: 0009-RFC-add-memfd_create-mlock2-pkey_-apis.patch --]
[-- Type: text/x-diff, Size: 5843 bytes --]

From 3484c45dbf59d0a6ee97b742d98e9f31f5384c17 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 28 Apr 2018 17:25:41 +0000
Subject: [PATCH 9/9] [RFC] add memfd_create, mlock2, pkey_* apis

memfd_create (linux v3.17)
mlock2 (linux v4.4)
pkey_alloc (linux v4.9)
pkey_free (linux v4.9)
pkey_mprotect (linux v4.9)
pkey_get (glibc 2.27)
pkey_set (glibc 2.27)

notes:

- pkey_alloc type is inconsistent between the linux manual
  and glibc (unsigned int vs unsigned long args), this patch
  follows glibc.
- pkey_get / pkey_set are glibc apis, not syscalls.
  (not implement for now on any targets).
- moved MLOCK_ONFAULT under _GNU_SOURCE following glibc.
- mlock2 and pkey_mprotect have fallbacks.
---
 arch/powerpc/bits/mman.h   |  4 ++++
 arch/powerpc64/bits/mman.h |  4 ++++
 include/sys/mman.h         | 24 +++++++++++++++++++++---
 src/linux/memfd_create.c   |  8 ++++++++
 src/linux/mlock2.c         | 11 +++++++++++
 src/linux/pkey_alloc.c     | 22 ++++++++++++++++++++++
 src/linux/pkey_get.c       |  9 +++++++++
 src/linux/pkey_mprotect.c  | 15 +++++++++++++++
 src/linux/pkey_set.c       |  9 +++++++++
 9 files changed, 103 insertions(+), 3 deletions(-)
 create mode 100644 src/linux/memfd_create.c
 create mode 100644 src/linux/mlock2.c
 create mode 100644 src/linux/pkey_alloc.c
 create mode 100644 src/linux/pkey_get.c
 create mode 100644 src/linux/pkey_mprotect.c
 create mode 100644 src/linux/pkey_set.c

diff --git a/arch/powerpc/bits/mman.h b/arch/powerpc/bits/mman.h
index b3a675a8..23e18eb1 100644
--- a/arch/powerpc/bits/mman.h
+++ b/arch/powerpc/bits/mman.h
@@ -12,3 +12,7 @@
 #define MCL_FUTURE      0x4000
 #undef MCL_ONFAULT
 #define MCL_ONFAULT     0x8000
+
+#ifdef _GNU_SOURCE
+#define PKEY_DISABLE_EXECUTE   0x4
+#endif
diff --git a/arch/powerpc64/bits/mman.h b/arch/powerpc64/bits/mman.h
index b3a675a8..23e18eb1 100644
--- a/arch/powerpc64/bits/mman.h
+++ b/arch/powerpc64/bits/mman.h
@@ -12,3 +12,7 @@
 #define MCL_FUTURE      0x4000
 #undef MCL_ONFAULT
 #define MCL_ONFAULT     0x8000
+
+#ifdef _GNU_SOURCE
+#define PKEY_DISABLE_EXECUTE   0x4
+#endif
diff --git a/include/sys/mman.h b/include/sys/mman.h
index 302ad134..aea40452 100644
--- a/include/sys/mman.h
+++ b/include/sys/mman.h
@@ -93,6 +93,20 @@ extern "C" {
 #define MADV_SOFT_OFFLINE 101
 #endif
 
+#ifdef _GNU_SOURCE
+#define MREMAP_MAYMOVE 1
+#define MREMAP_FIXED 2
+
+#define PKEY_DISABLE_ACCESS 0x1
+#define PKEY_DISABLE_WRITE 0x2
+
+#define MLOCK_ONFAULT 0x01
+
+#define MFD_CLOEXEC 0x0001U
+#define MFD_ALLOW_SEALING 0x0002U
+#define MFD_HUGETLB 0x0004U
+#endif
+
 #include <bits/mman.h>
 
 void *mmap (void *, size_t, int, int, int, off_t);
@@ -109,14 +123,18 @@ int mlockall (int);
 int munlockall (void);
 
 #ifdef _GNU_SOURCE
-#define MREMAP_MAYMOVE 1
-#define MREMAP_FIXED 2
 void *mremap (void *, size_t, size_t, int, ...);
 int remap_file_pages (void *, size_t, int, size_t, int);
+int memfd_create (const char *, unsigned);
+int mlock2 (const void *, size_t, unsigned);
+int pkey_alloc (unsigned, unsigned);
+int pkey_free (int);
+int pkey_mprotect (void *, size_t, int, int);
+int pkey_get (int);
+int pkey_set (int, unsigned);
 #endif
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define MLOCK_ONFAULT   0x01
 int madvise (void *, size_t, int);
 int mincore (void *, size_t, unsigned char *);
 #endif
diff --git a/src/linux/memfd_create.c b/src/linux/memfd_create.c
new file mode 100644
index 00000000..1649fe55
--- /dev/null
+++ b/src/linux/memfd_create.c
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+#include "syscall.h"
+
+int memfd_create(const char *name, unsigned flags)
+{
+	return syscall(SYS_memfd_create, name, flags);
+}
diff --git a/src/linux/mlock2.c b/src/linux/mlock2.c
new file mode 100644
index 00000000..e1235c46
--- /dev/null
+++ b/src/linux/mlock2.c
@@ -0,0 +1,11 @@
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+#include <errno.h>
+#include "syscall.h"
+
+int mlock2(const void *addr, size_t len, unsigned flags)
+{
+	if (flags == 0)
+		return mlock(addr, len);
+	return syscall(SYS_mlock2, addr, len, flags);
+}
diff --git a/src/linux/pkey_alloc.c b/src/linux/pkey_alloc.c
new file mode 100644
index 00000000..8027cd12
--- /dev/null
+++ b/src/linux/pkey_alloc.c
@@ -0,0 +1,22 @@
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+#include <errno.h>
+#include "syscall.h"
+
+int pkey_alloc(unsigned flags, unsigned access)
+{
+#ifdef SYS_pkey_alloc
+	return syscall(SYS_pkey_alloc, flags, access);
+#else
+	return __syscall_ret(-ENOSYS);
+#endif
+}
+
+int pkey_free(int pkey)
+{
+#ifdef SYS_pkey_free
+	return syscall(SYS_pkey_free, pkey);
+#else
+	return __syscall_ret(-ENOSYS);
+#endif
+}
diff --git a/src/linux/pkey_get.c b/src/linux/pkey_get.c
new file mode 100644
index 00000000..d583fa9c
--- /dev/null
+++ b/src/linux/pkey_get.c
@@ -0,0 +1,9 @@
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+#include <errno.h>
+#include "syscall.h"
+
+int pkey_get(int pkey)
+{
+	return __syscall_ret(-ENOSYS);
+}
diff --git a/src/linux/pkey_mprotect.c b/src/linux/pkey_mprotect.c
new file mode 100644
index 00000000..0a1f97ad
--- /dev/null
+++ b/src/linux/pkey_mprotect.c
@@ -0,0 +1,15 @@
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+#include <errno.h>
+#include "syscall.h"
+
+int pkey_mprotect(void *addr, size_t len, int prot, int pkey)
+{
+	if (pkey == -1)
+		return mprotect(addr, len, prot);
+#ifdef SYS_pkey_mprotect
+	return syscall(SYS_pkey_mprotect, addr, len, prot, pkey);
+#else
+	return __syscall_ret(-ENOSYS);
+#endif
+}
diff --git a/src/linux/pkey_set.c b/src/linux/pkey_set.c
new file mode 100644
index 00000000..addf8da5
--- /dev/null
+++ b/src/linux/pkey_set.c
@@ -0,0 +1,9 @@
+#define _GNU_SOURCE 1
+#include <sys/mman.h>
+#include <errno.h>
+#include "syscall.h"
+
+int pkey_set(int pkey, unsigned access)
+{
+	return __syscall_ret(-ENOSYS);
+}
-- 
2.16.3


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

* Re: [PATCH 0/9] linux v4.16 update
  2018-04-28 19:56 [PATCH 0/9] linux v4.16 update Szabolcs Nagy
  2018-04-28 21:39 ` Szabolcs Nagy
@ 2018-05-15 17:39 ` Rich Felker
  2018-06-09 22:41   ` Szabolcs Nagy
  1 sibling, 1 reply; 5+ messages in thread
From: Rich Felker @ 2018-05-15 17:39 UTC (permalink / raw)
  To: musl

On Sat, Apr 28, 2018 at 09:56:56PM +0200, Szabolcs Nagy wrote:
> the ptrace.h change is probably not ok
> (glibc added struct __ptrace_seccomp_metadata
> instead of the kernel struct seccomp_metadata,
> but the same is true for ptrace_peeksiginfo_args
> where musl currently follows linux instead of
> glibc, maybe that should be fixed?).

I'm not sure. The ptrace-related (including ptrace.h, user.h, etc.)
stuff has always been a mess.

> the last patch is an unfinished proposal to add
> some new syscalls glibc already has, but i ran
> into some issues so comments are welcome.
> 
> i ran the patch set through compile testing.
> 
> Szabolcs Nagy (9):
>   siginfo struct change following linux v4.16
>   elf.h: add NT_PPC_PKEY from linux v4.16
>   sys/epoll.h: add EPOLLNVAL from linux v4.16
>   netinet/if_ether.h: add ETH_P_ERSPAN2 from linux v4.16
>   netinet/if_ether.h: add ETH_TLEN from linux v4.16
>   sys/ptrace.h: add PTRACE_SECCOMP_GET_METADATA from linux v4.16
>   aarch64: add HWCAP_ASIMDFHM from linux v4.16
>   powerpc: add pkey syscall numbers from linux v4.16
>   [RFC] add new memory mapping related apis
> 
>  arch/aarch64/bits/hwcap.h        |  1 +
>  arch/powerpc/bits/mman.h         |  4 ++++
>  arch/powerpc/bits/syscall.h.in   |  3 +++
>  arch/powerpc64/bits/mman.h       |  4 ++++
>  arch/powerpc64/bits/syscall.h.in |  3 +++
>  include/elf.h                    |  1 +
>  include/netinet/if_ether.h       |  2 ++
>  include/signal.h                 | 12 ++++++++----
>  include/sys/epoll.h              |  1 +
>  include/sys/mman.h               | 24 +++++++++++++++++++++---
>  include/sys/ptrace.h             |  6 ++++++
>  src/linux/memfd_create.c         | 10 ++++++++++
>  src/linux/mlock2.c               | 15 +++++++++++++++
>  src/linux/pkey_alloc.c           | 15 +++++++++++++++
>  src/linux/pkey_get.c             |  9 +++++++++
>  src/linux/pkey_mprotect.c        | 15 +++++++++++++++
>  src/linux/pkey_set.c             |  9 +++++++++
>  17 files changed, 127 insertions(+), 7 deletions(-)
>  create mode 100644 src/linux/memfd_create.c
>  create mode 100644 src/linux/mlock2.c
>  create mode 100644 src/linux/pkey_alloc.c
>  create mode 100644 src/linux/pkey_get.c
>  create mode 100644 src/linux/pkey_mprotect.c
>  create mode 100644 src/linux/pkey_set.c
> 
> -- 
> 2.16.3
> 

> From f7eb8934396890e39b9e5e2b4fdd1534f1c024cc Mon Sep 17 00:00:00 2001
> From: Szabolcs Nagy <nsz@port70.net>
> Date: Mon, 16 Apr 2018 22:16:29 +0000
> Subject: [PATCH 1/9] siginfo struct change following linux v4.16
> 
> this is supposed to be a cosmetic change only, not affecting api or abi,
> follows linux commit b68a68d3dcc15ebbf23cbe91af1abf57591bd96b and
> 859d880cf544dbe095ce97534ef04cd88ba2f2b4 with slightly different field
> names to follow musl conventions (which must be different to avoid
> depending on anonymous union support and polluting the namespace).
> ---
>  include/signal.h | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/include/signal.h b/include/signal.h
> index a4f85cca..d68331e8 100644
> --- a/include/signal.h
> +++ b/include/signal.h
> @@ -123,13 +123,17 @@ typedef struct {
>  		} __si_common;
>  		struct {
>  			void *si_addr;
> -			short si_addr_lsb;
>  			union {
> +				short si_addr_lsb;
>  				struct {
> +					void *__dummy_bnd;
>  					void *si_lower;
>  					void *si_upper;
>  				} __addr_bnd;
> -				unsigned si_pkey;
> +				struct {
> +					void *__dummy_pkey;
> +					unsigned si_pkey;
> +				} __addr_pkey;
>  			} __first;
>  		} __sigfault;
>  		struct {
> @@ -150,10 +154,10 @@ typedef struct {
>  #define si_stime   __si_fields.__si_common.__second.__sigchld.si_stime
>  #define si_value   __si_fields.__si_common.__second.si_value
>  #define si_addr    __si_fields.__sigfault.si_addr
> -#define si_addr_lsb __si_fields.__sigfault.si_addr_lsb
> +#define si_addr_lsb __si_fields.__sigfault.__first.si_addr_lsb
>  #define si_lower   __si_fields.__sigfault.__first.__addr_bnd.si_lower
>  #define si_upper   __si_fields.__sigfault.__first.__addr_bnd.si_upper
> -#define si_pkey    __si_fields.__sigfault.__first.si_pkey
> +#define si_pkey    __si_fields.__sigfault.__first.__addr_pkey.si_pkey
>  #define si_band    __si_fields.__sigpoll.si_band
>  #define si_fd      __si_fields.__sigpoll.si_fd
>  #define si_timerid __si_fields.__si_common.__first.__timer.si_timerid

Is there any benefit to making this change?

> From de4ca3284d759563322c795479601e9eee394832 Mon Sep 17 00:00:00 2001
> From: Szabolcs Nagy <nsz@port70.net>
> Date: Sat, 28 Apr 2018 17:25:41 +0000
> Subject: [PATCH 9/9] [RFC] add new memory mapping related apis
> 
> memfd_create (linux v3.17)
> mlock2 (linux v4.4)
> pkey_alloc (linux v4.9)
> pkey_free (linux v4.9)
> pkey_mprotect (linux v4.9)
> pkey_get (glibc 2.27)
> pkey_set (glibc 2.27)
> 
> notes:
> 
> - pkey_alloc type is inconsistent between the manual and
>   the glibc source (unsigned int vs unsigned long args)

This needs to be resolved, I think.

> - pkey_get / pkey_set are not syscalls (query/update the
>   pkru register on x86), not implemented yet.
> - fallback in mlock2 to mlock and pkey_mprotect to mprotect
>   follows glibc.
> - mlock2 EINVAL return means invalid (or unsupported) flags.
> - moved MLOCK_ONFAULT under _GNU_SOURCE following glibc.
> ---
>  arch/powerpc/bits/mman.h   |  4 ++++
>  arch/powerpc64/bits/mman.h |  4 ++++
>  include/sys/mman.h         | 24 +++++++++++++++++++++---
>  src/linux/memfd_create.c   | 10 ++++++++++
>  src/linux/mlock2.c         | 15 +++++++++++++++
>  src/linux/pkey_alloc.c     | 15 +++++++++++++++
>  src/linux/pkey_get.c       |  9 +++++++++
>  src/linux/pkey_mprotect.c  | 15 +++++++++++++++
>  src/linux/pkey_set.c       |  9 +++++++++
>  9 files changed, 102 insertions(+), 3 deletions(-)

Am I correct in assuming the header & external function interfaces
match how glibc is exposing these functions?

One thing that looks a little bit weird to me is conditioning
existence of some functions on the syscall macro:

> diff --git a/src/linux/pkey_alloc.c b/src/linux/pkey_alloc.c
> new file mode 100644
> index 00000000..0b0770a6
> --- /dev/null
> +++ b/src/linux/pkey_alloc.c
> @@ -0,0 +1,15 @@
> +#include "syscall.h"
> +
> +#ifdef SYS_pkey_alloc
> +#define _GNU_SOURCE 1
> +#include <sys/mman.h>
> +int pkey_alloc(unsigned flags, unsigned access)
> +{
> +	return syscall(SYS_pkey_alloc, flags, access);
> +}
> +
> +int pkey_free(int pkey)
> +{
> +	return syscall(SYS_pkey_free, pkey);
> +}
> +#endif

where others fail with ENOSYS when the arch has no definition. I think
it's also problematic that syscall.h is being included before #define
_GNU_SOURCE. This would break under changes in how the features.h
mechanisms work.

Is there a reason you want to avoid an external functon existing when
the arch lacks the feature?

The other patches in this series look ok I think. I'll commit them
soon if I don't see any further things to ask about.

Rich


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

* Re: [PATCH 0/9] linux v4.16 update
  2018-05-15 17:39 ` Rich Felker
@ 2018-06-09 22:41   ` Szabolcs Nagy
  2018-06-10  0:51     ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Szabolcs Nagy @ 2018-06-09 22:41 UTC (permalink / raw)
  To: musl

* Rich Felker <dalias@libc.org> [2018-05-15 13:39:23 -0400]:
> On Sat, Apr 28, 2018 at 09:56:56PM +0200, Szabolcs Nagy wrote:
> > From f7eb8934396890e39b9e5e2b4fdd1534f1c024cc Mon Sep 17 00:00:00 2001
> > From: Szabolcs Nagy <nsz@port70.net>
> > Date: Mon, 16 Apr 2018 22:16:29 +0000
> > Subject: [PATCH 1/9] siginfo struct change following linux v4.16
> > 
> > this is supposed to be a cosmetic change only, not affecting api or abi,
> > follows linux commit b68a68d3dcc15ebbf23cbe91af1abf57591bd96b and
> > 859d880cf544dbe095ce97534ef04cd88ba2f2b4 with slightly different field
> > names to follow musl conventions (which must be different to avoid
> > depending on anonymous union support and polluting the namespace).
> > ---
> >  include/signal.h | 12 ++++++++----
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> > 
> > diff --git a/include/signal.h b/include/signal.h
> > index a4f85cca..d68331e8 100644
> > --- a/include/signal.h
> > +++ b/include/signal.h
> > @@ -123,13 +123,17 @@ typedef struct {
> >  		} __si_common;
> >  		struct {
> >  			void *si_addr;
> > -			short si_addr_lsb;
> >  			union {
> > +				short si_addr_lsb;
> >  				struct {
> > +					void *__dummy_bnd;
> >  					void *si_lower;
> >  					void *si_upper;
> >  				} __addr_bnd;
> > -				unsigned si_pkey;
> > +				struct {
> > +					void *__dummy_pkey;
> > +					unsigned si_pkey;
> > +				} __addr_pkey;
> >  			} __first;
> >  		} __sigfault;
> >  		struct {
> > @@ -150,10 +154,10 @@ typedef struct {
> >  #define si_stime   __si_fields.__si_common.__second.__sigchld.si_stime
> >  #define si_value   __si_fields.__si_common.__second.si_value
> >  #define si_addr    __si_fields.__sigfault.si_addr
> > -#define si_addr_lsb __si_fields.__sigfault.si_addr_lsb
> > +#define si_addr_lsb __si_fields.__sigfault.__first.si_addr_lsb
> >  #define si_lower   __si_fields.__sigfault.__first.__addr_bnd.si_lower
> >  #define si_upper   __si_fields.__sigfault.__first.__addr_bnd.si_upper
> > -#define si_pkey    __si_fields.__sigfault.__first.si_pkey
> > +#define si_pkey    __si_fields.__sigfault.__first.__addr_pkey.si_pkey
> >  #define si_band    __si_fields.__sigpoll.si_band
> >  #define si_fd      __si_fields.__sigpoll.si_fd
> >  #define si_timerid __si_fields.__si_common.__first.__timer.si_timerid
> 
> Is there any benefit to making this change?
> 

only to follow the linux headers might make it easier to track changes

turns out the change was wrong though and now it's even more messy:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8420f71943ae96dcd78da5bd4a5c2827419d340c


> > From de4ca3284d759563322c795479601e9eee394832 Mon Sep 17 00:00:00 2001
> > From: Szabolcs Nagy <nsz@port70.net>
> > Date: Sat, 28 Apr 2018 17:25:41 +0000
> > Subject: [PATCH 9/9] [RFC] add new memory mapping related apis
> > 
> > memfd_create (linux v3.17)
> > mlock2 (linux v4.4)
> > pkey_alloc (linux v4.9)
> > pkey_free (linux v4.9)
> > pkey_mprotect (linux v4.9)
> > pkey_get (glibc 2.27)
> > pkey_set (glibc 2.27)
> > 
> > notes:
> > 
> > - pkey_alloc type is inconsistent between the manual and
> >   the glibc source (unsigned int vs unsigned long args)
> 
> This needs to be resolved, I think.
> 

glibc is right, the man was documenting the syscall layer

> > - pkey_get / pkey_set are not syscalls (query/update the
> >   pkru register on x86), not implemented yet.
> > - fallback in mlock2 to mlock and pkey_mprotect to mprotect
> >   follows glibc.
> > - mlock2 EINVAL return means invalid (or unsupported) flags.
> > - moved MLOCK_ONFAULT under _GNU_SOURCE following glibc.
> > ---
> >  arch/powerpc/bits/mman.h   |  4 ++++
> >  arch/powerpc64/bits/mman.h |  4 ++++
> >  include/sys/mman.h         | 24 +++++++++++++++++++++---
> >  src/linux/memfd_create.c   | 10 ++++++++++
> >  src/linux/mlock2.c         | 15 +++++++++++++++
> >  src/linux/pkey_alloc.c     | 15 +++++++++++++++
> >  src/linux/pkey_get.c       |  9 +++++++++
> >  src/linux/pkey_mprotect.c  | 15 +++++++++++++++
> >  src/linux/pkey_set.c       |  9 +++++++++
> >  9 files changed, 102 insertions(+), 3 deletions(-)
> 
> Am I correct in assuming the header & external function interfaces
> match how glibc is exposing these functions?
> 
> One thing that looks a little bit weird to me is conditioning
> existence of some functions on the syscall macro:
> 
> > diff --git a/src/linux/pkey_alloc.c b/src/linux/pkey_alloc.c
> > new file mode 100644
> > index 00000000..0b0770a6
> > --- /dev/null
> > +++ b/src/linux/pkey_alloc.c
> > @@ -0,0 +1,15 @@
> > +#include "syscall.h"
> > +
> > +#ifdef SYS_pkey_alloc
> > +#define _GNU_SOURCE 1
> > +#include <sys/mman.h>
> > +int pkey_alloc(unsigned flags, unsigned access)
> > +{
> > +	return syscall(SYS_pkey_alloc, flags, access);
> > +}
> > +
> > +int pkey_free(int pkey)
> > +{
> > +	return syscall(SYS_pkey_free, pkey);
> > +}
> > +#endif
> 
> where others fail with ENOSYS when the arch has no definition. I think
> it's also problematic that syscall.h is being included before #define
> _GNU_SOURCE. This would break under changes in how the features.h
> mechanisms work.
> 

ok this should fail ENOSYS when not available.

> Is there a reason you want to avoid an external functon existing when
> the arch lacks the feature?
> 
> The other patches in this series look ok I think. I'll commit them
> soon if I don't see any further things to ask about.
> 
> Rich


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

* Re: [PATCH 0/9] linux v4.16 update
  2018-06-09 22:41   ` Szabolcs Nagy
@ 2018-06-10  0:51     ` Rich Felker
  0 siblings, 0 replies; 5+ messages in thread
From: Rich Felker @ 2018-06-10  0:51 UTC (permalink / raw)
  To: musl

On Sun, Jun 10, 2018 at 12:41:59AM +0200, Szabolcs Nagy wrote:
> * Rich Felker <dalias@libc.org> [2018-05-15 13:39:23 -0400]:
> > On Sat, Apr 28, 2018 at 09:56:56PM +0200, Szabolcs Nagy wrote:
> > > From f7eb8934396890e39b9e5e2b4fdd1534f1c024cc Mon Sep 17 00:00:00 2001
> > > From: Szabolcs Nagy <nsz@port70.net>
> > > Date: Mon, 16 Apr 2018 22:16:29 +0000
> > > Subject: [PATCH 1/9] siginfo struct change following linux v4.16
> > > 
> > > this is supposed to be a cosmetic change only, not affecting api or abi,
> > > follows linux commit b68a68d3dcc15ebbf23cbe91af1abf57591bd96b and
> > > 859d880cf544dbe095ce97534ef04cd88ba2f2b4 with slightly different field
> > > names to follow musl conventions (which must be different to avoid
> > > depending on anonymous union support and polluting the namespace).
> > > ---
> > >  include/signal.h | 12 ++++++++----
> > >  1 file changed, 8 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/include/signal.h b/include/signal.h
> > > index a4f85cca..d68331e8 100644
> > > --- a/include/signal.h
> > > +++ b/include/signal.h
> > > @@ -123,13 +123,17 @@ typedef struct {
> > >  		} __si_common;
> > >  		struct {
> > >  			void *si_addr;
> > > -			short si_addr_lsb;
> > >  			union {
> > > +				short si_addr_lsb;
> > >  				struct {
> > > +					void *__dummy_bnd;
> > >  					void *si_lower;
> > >  					void *si_upper;
> > >  				} __addr_bnd;
> > > -				unsigned si_pkey;
> > > +				struct {
> > > +					void *__dummy_pkey;
> > > +					unsigned si_pkey;
> > > +				} __addr_pkey;
> > >  			} __first;
> > >  		} __sigfault;
> > >  		struct {
> > > @@ -150,10 +154,10 @@ typedef struct {
> > >  #define si_stime   __si_fields.__si_common.__second.__sigchld.si_stime
> > >  #define si_value   __si_fields.__si_common.__second.si_value
> > >  #define si_addr    __si_fields.__sigfault.si_addr
> > > -#define si_addr_lsb __si_fields.__sigfault.si_addr_lsb
> > > +#define si_addr_lsb __si_fields.__sigfault.__first.si_addr_lsb
> > >  #define si_lower   __si_fields.__sigfault.__first.__addr_bnd.si_lower
> > >  #define si_upper   __si_fields.__sigfault.__first.__addr_bnd.si_upper
> > > -#define si_pkey    __si_fields.__sigfault.__first.si_pkey
> > > +#define si_pkey    __si_fields.__sigfault.__first.__addr_pkey.si_pkey
> > >  #define si_band    __si_fields.__sigpoll.si_band
> > >  #define si_fd      __si_fields.__sigpoll.si_fd
> > >  #define si_timerid __si_fields.__si_common.__first.__timer.si_timerid
> > 
> > Is there any benefit to making this change?
> > 
> 
> only to follow the linux headers might make it easier to track changes
> 
> turns out the change was wrong though and now it's even more messy:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8420f71943ae96dcd78da5bd4a5c2827419d340c

It looks like the change is just for archs where pointers aren't
aligned, of which we presently don't have any, but it makes the whole
change rather blah, and I don't like the new version either. If they
mean to reserve space for a short plus any alignment it causes, they
should just add a short there rather than a wacky-sized char array.

Anyway my leaning is just to drop this unless it turns out that future
additions to the struct depend on it, and we can address that if/when
it happens.

> > > From de4ca3284d759563322c795479601e9eee394832 Mon Sep 17 00:00:00 2001
> > > From: Szabolcs Nagy <nsz@port70.net>
> > > Date: Sat, 28 Apr 2018 17:25:41 +0000
> > > Subject: [PATCH 9/9] [RFC] add new memory mapping related apis
> > > 
> > > memfd_create (linux v3.17)
> > > mlock2 (linux v4.4)
> > > pkey_alloc (linux v4.9)
> > > pkey_free (linux v4.9)
> > > pkey_mprotect (linux v4.9)
> > > pkey_get (glibc 2.27)
> > > pkey_set (glibc 2.27)
> > > 
> > > notes:
> > > 
> > > - pkey_alloc type is inconsistent between the manual and
> > >   the glibc source (unsigned int vs unsigned long args)
> > 
> > This needs to be resolved, I think.
> > 
> 
> glibc is right, the man was documenting the syscall layer

OK.

> > > - pkey_get / pkey_set are not syscalls (query/update the
> > >   pkru register on x86), not implemented yet.
> > > - fallback in mlock2 to mlock and pkey_mprotect to mprotect
> > >   follows glibc.
> > > - mlock2 EINVAL return means invalid (or unsupported) flags.
> > > - moved MLOCK_ONFAULT under _GNU_SOURCE following glibc.
> > > ---
> > >  arch/powerpc/bits/mman.h   |  4 ++++
> > >  arch/powerpc64/bits/mman.h |  4 ++++
> > >  include/sys/mman.h         | 24 +++++++++++++++++++++---
> > >  src/linux/memfd_create.c   | 10 ++++++++++
> > >  src/linux/mlock2.c         | 15 +++++++++++++++
> > >  src/linux/pkey_alloc.c     | 15 +++++++++++++++
> > >  src/linux/pkey_get.c       |  9 +++++++++
> > >  src/linux/pkey_mprotect.c  | 15 +++++++++++++++
> > >  src/linux/pkey_set.c       |  9 +++++++++
> > >  9 files changed, 102 insertions(+), 3 deletions(-)
> > 
> > Am I correct in assuming the header & external function interfaces
> > match how glibc is exposing these functions?
> > 
> > One thing that looks a little bit weird to me is conditioning
> > existence of some functions on the syscall macro:
> > 
> > > diff --git a/src/linux/pkey_alloc.c b/src/linux/pkey_alloc.c
> > > new file mode 100644
> > > index 00000000..0b0770a6
> > > --- /dev/null
> > > +++ b/src/linux/pkey_alloc.c
> > > @@ -0,0 +1,15 @@
> > > +#include "syscall.h"
> > > +
> > > +#ifdef SYS_pkey_alloc
> > > +#define _GNU_SOURCE 1
> > > +#include <sys/mman.h>
> > > +int pkey_alloc(unsigned flags, unsigned access)
> > > +{
> > > +	return syscall(SYS_pkey_alloc, flags, access);
> > > +}
> > > +
> > > +int pkey_free(int pkey)
> > > +{
> > > +	return syscall(SYS_pkey_free, pkey);
> > > +}
> > > +#endif
> > 
> > where others fail with ENOSYS when the arch has no definition. I think
> > it's also problematic that syscall.h is being included before #define
> > _GNU_SOURCE. This would break under changes in how the features.h
> > mechanisms work.
> > 
> 
> ok this should fail ENOSYS when not available.

OK.

Rich


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

end of thread, other threads:[~2018-06-10  0:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-28 19:56 [PATCH 0/9] linux v4.16 update Szabolcs Nagy
2018-04-28 21:39 ` Szabolcs Nagy
2018-05-15 17:39 ` Rich Felker
2018-06-09 22:41   ` Szabolcs Nagy
2018-06-10  0:51     ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).