diff options
author | Victor Stinner <vstinner@python.org> | 2022-03-11 23:04:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-11 23:04:14 (GMT) |
commit | 393e2bf6bc6effbfe821f051a230978f0edd70df (patch) | |
tree | caebdaeaf2382d8b4456bd9579770a3ab48c3aa7 | |
parent | b35b36e106152245fe68880f4073fd99ec17f65d (diff) | |
download | cpython-393e2bf6bc6effbfe821f051a230978f0edd70df.zip cpython-393e2bf6bc6effbfe821f051a230978f0edd70df.tar.gz cpython-393e2bf6bc6effbfe821f051a230978f0edd70df.tar.bz2 |
bpo-46968: Fix faulthandler for Sapphire Rapids Xeon (GH-31789) (GH-31830)
In Linux kernel 5.14 one can dynamically request size of altstacksize
based on hardware capabilities with getauxval(AT_MINSIGSTKSZ).
This changes allows for Python extension's request to Linux kernel
to use AMX_TILE instruction set on Sapphire Rapids Xeon processor
to succeed, unblocking use of the ISA in frameworks.
Introduced HAVE_LINUX_AUXVEC_H in configure.ac and pyconfig.h.in
Used cpython_autoconf:269 docker container to generate configure.
(cherry picked from commit 3b128c054885fe881c3b57a5978de3ea89c81a9c)
Co-authored-by: Oleksandr Pavlyk <oleksandr.pavlyk@intel.com>
-rw-r--r-- | Misc/NEWS.d/next/Library/2022-03-10-14-51-11.bpo-46968.ym2QxL.rst | 5 | ||||
-rw-r--r-- | Modules/faulthandler.c | 26 | ||||
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | pyconfig.h.in | 3 |
5 files changed, 30 insertions, 8 deletions
diff --git a/Misc/NEWS.d/next/Library/2022-03-10-14-51-11.bpo-46968.ym2QxL.rst b/Misc/NEWS.d/next/Library/2022-03-10-14-51-11.bpo-46968.ym2QxL.rst new file mode 100644 index 0000000..0da5ae7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-03-10-14-51-11.bpo-46968.ym2QxL.rst @@ -0,0 +1,5 @@ +:mod:`faulthandler`: On Linux 5.14 and newer, dynamically determine size of +signal handler stack size CPython allocates using ``getauxval(AT_MINSIGSTKSZ)``. +This changes allows for Python extension's request to Linux kernel to use +AMX_TILE instruction set on Sapphire Rapids Xeon processor to succeed, +unblocking use of the ISA in frameworks. diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index e03f6d9..88a5b93 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -17,6 +17,17 @@ # include <sys/resource.h> #endif +/* Using an alternative stack requires sigaltstack() + and sigaction() SA_ONSTACK */ +#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) +# define FAULTHANDLER_USE_ALT_STACK +#endif + +#if defined(FAULTHANDLER_USE_ALT_STACK) && defined(HAVE_LINUX_AUXVEC_H) +# include <linux/auxvec.h> +# include <sys/auxv.h> +#endif + /* Allocate at maximum 100 MiB of the stack to raise the stack overflow */ #define STACK_OVERFLOW_MAX_SIZE (100 * 1024 * 1024) @@ -139,12 +150,6 @@ static fault_handler_t faulthandler_handlers[] = { static const size_t faulthandler_nsignals = \ Py_ARRAY_LENGTH(faulthandler_handlers); -/* Using an alternative stack requires sigaltstack() - and sigaction() SA_ONSTACK */ -#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) -# define FAULTHANDLER_USE_ALT_STACK -#endif - #ifdef FAULTHANDLER_USE_ALT_STACK static stack_t stack; static stack_t old_stack; @@ -1374,6 +1379,15 @@ _PyFaulthandler_Init(int enable) signal handler uses more than SIGSTKSZ bytes of stack memory on some platforms. */ stack.ss_size = SIGSTKSZ * 2; +#ifdef AT_MINSIGSTKSZ + /* bpo-46968: Query Linux for minimal stack size to ensure signal delivery + for the hardware running CPython. This OS feature is available in + Linux kernel version >= 5.14 */ + unsigned long at_minstack_size = getauxval(AT_MINSIGSTKSZ); + if (at_minstack_size != 0) { + stack.ss_size = SIGSTKSZ + at_minstack_size; + } +#endif #endif memset(&thread, 0, sizeof(thread)); @@ -8101,7 +8101,7 @@ sys/stat.h sys/syscall.h sys/sys_domain.h sys/termio.h sys/time.h \ sys/times.h sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h pty.h \ libutil.h sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \ linux/tipc.h linux/random.h spawn.h util.h alloca.h endian.h \ -sys/endian.h sys/sysmacros.h linux/memfd.h linux/wait.h sys/memfd.h \ +sys/endian.h sys/sysmacros.h linux/auxvec.h linux/memfd.h linux/wait.h sys/memfd.h \ sys/mman.h sys/eventfd.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` diff --git a/configure.ac b/configure.ac index 0efeb8f..547255f 100644 --- a/configure.ac +++ b/configure.ac @@ -2225,7 +2225,7 @@ sys/stat.h sys/syscall.h sys/sys_domain.h sys/termio.h sys/time.h \ sys/times.h sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h pty.h \ libutil.h sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \ linux/tipc.h linux/random.h spawn.h util.h alloca.h endian.h \ -sys/endian.h sys/sysmacros.h linux/memfd.h linux/wait.h sys/memfd.h \ +sys/endian.h sys/sysmacros.h linux/auxvec.h linux/memfd.h linux/wait.h sys/memfd.h \ sys/mman.h sys/eventfd.h) AC_HEADER_DIRENT AC_HEADER_MAJOR diff --git a/pyconfig.h.in b/pyconfig.h.in index 8a4aeda..b0948e9 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -637,6 +637,9 @@ /* Define to 1 if you have the `linkat' function. */ #undef HAVE_LINKAT +/* Define to 1 if you have the <linux/auxvec.h> header file. */ +#undef HAVE_LINUX_AUXVEC_H + /* Define to 1 if you have the <linux/can/bcm.h> header file. */ #undef HAVE_LINUX_CAN_BCM_H |