-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-46968: Query altstack size dynamically on Linux kernel >=5.14 #31789
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
The CLA has been signed. I am the first time contributor to CPython proper. Please guide me through the process of getting this PR to the required state to make the merge possible. Thank you. |
Thanks for signing the CLA! It may take a few days for the bot to update your PR with the "CLA signed" label, as the form needs to be manually reviewed by a human at the PSF :) The first step is to change the title of your PR to "bpo-46968: Query altstack size dynamically on Linux kernel >=5.14". This will cause the bots to automatically link this PR to that BPO issue, which will make the relevant CI check go green. The second thing you'll need to do is to add a NEWS entry to your PR, which you can do using https://blurb-it.herokuapp.com. |
You'll probably also need to add a test to your PR to make it mergeable. For a fuller guide to the process, the devguide is here :) |
Since size of size of sigaltstack used by faulthandler extensions is not user accessible to the best of my knowledge, I am not entirely sure how once can test the change. Suggestions are welcome. |
I'm afraid this is an area I know next to nothing about, so I can't really help you any further I'm afraid :/ Don't worry too much about it — if it seems like a good idea, a core developer with more expertise in this area should be able to help you with writing tests 🙂 (though there's quite a large PR backlog, so it might take a while). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The core of the changes look good, the annoying part is in the generated configure and aclocal.m4 files - those should be generated with the same version as the existing ones.
See the 2022 comment on https://bugs.python.org/issue44035 for a pointer to a docker image that can be used for the autoconf regeneration stuff. (that image is not yet documented AFAICT)
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
f8c09d0
to
854a577
Compare
I have made the requested changes; please review again I modified I regenerated
Assuming this change eventually gets accepted, what is the process of requesting backports to all earlier versions of CPython? |
Thanks for making the requested changes! @gpshead: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a verify specific combination of autoconf 2.69 + runstatedir patch, autoarchive version, and pkg-config m4 macro version. Your version of autoconf aclocal macros is too old. If you cannot use the container image to regenerate the files, then apply the changes manually.
- revert
aclocal.m4
andconfigure
changes. - manually add
linux/auxvec.h
toconfigure
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Introduced HAVE_LINUX_AUXVEC_H in configure.ac and pyconfig.h.in Used cpython_autoconf:269 docker container to generate configure
d3e2045
to
570a176
Compare
I have made the requested changes; please review again |
Misc/NEWS.d/next/Library/2022-03-10-14-51-11.bpo-46968.ym2QxL.rst
Outdated
Show resolved
Hide resolved
In Linux kernel 5.14 one can dynamically request size of altstacksize based on hardware capabilities. This patch sets stack size to be the maximum of current value of SIGSTKSZ * 2 and SIGSTKSZ + 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.
570a176
to
2a2cbd6
Compare
I have made the requested changes; please review again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised that AT_MINSIGSTKSZ doesn't return directly the value which should be passed to sigaltstack(), but it seems like your code is the correct way to use the value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AT_MINSIGSTKSZ
is a preprocessor variable. The getauxval
checks hardware capabilities (e.g. total size of CPU state to be saved at context switches) and may return different values on different platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that I expected to write (simplified code without error handling): stack.ss_size = getauxval(AT_MINSIGSTKSZ)
, rather than stack.ss_size = SIGSTKSZ + getauxval(AT_MINSIGSTKSZ)
. But your code looks correct according to the doc that I found on the Internet. Like the official Linux documentation:
ss.ss_size = getauxval(AT_MINSIGSTKSZ) + SIGSTKSZ;
ref: https://docs.kernel.org/x86/elf_auxvec.html#introduction
I wrote PR #31824 to add |
Thanks @oleksandr-pavlyk for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Sorry, @oleksandr-pavlyk and @vstinner, I could not cleanly backport this to |
Merged, thank you! |
GH-31830 is a backport of this pull request to the 3.10 branch. |
I fixed the conflict on configure.ac and backported the change to 3.10: #31830 Then I will backport the fix to 3.9. |
…1830) 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 3b128c0) Co-authored-by: Oleksandr Pavlyk <[email protected]>
…1831) 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 3b128c0) Co-authored-by: Oleksandr Pavlyk <[email protected]>
…pythonGH-31831) 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 3b128c0) Co-authored-by: Oleksandr Pavlyk <[email protected]>
In Linux kernel 5.14 one can dynamically request size of altstacksize
needed to handle signals based on hardware capabilities.
This patch sets stack size to be the maximum of current value of SIGSTKSZ * 2 and
SIGSTKSZ + 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.
This change proposes a solution to the problem described
in https://bugs.python.org/msg414809
https://bugs.python.org/issue46968