Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-17 Thread David Holmes
On 12/03/2022 2:37 am, Anton Kozlov wrote: On Thu, 10 Mar 2022 18:04:50 GMT, Thomas Stuefe wrote: blocking SIGSEGV and SIGBUS - or other synchronous error signals like SIGFPE - and then triggering said signal is UB. What happens is OS-dependent. I saw processes vanishing, or hang, or core.

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-12 Thread Andrew Haley
On Sat, 12 Mar 2022 12:30:39 GMT, Andrew Haley wrote: > 1ns Incidentally, there must be a lot of speculation and bypassing going on there. I can see 15 cycles of latency, probably 20, so that'd be more like 5ns start to finish. M1 is a remarkable thing. - PR:

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-12 Thread Andrew Haley
On Fri, 11 Mar 2022 12:18:36 GMT, Florian Weimer wrote: > > According to > > https://forums.swift.org/t/concurrencys-use-of-thread-local-variables/48654: > > "these accesses are just a move from a system register plus a load/store > > at a constant offset." > > Ideally you'd still benchmark

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-11 Thread Thomas Stuefe
On Fri, 11 Mar 2022 16:34:29 GMT, Anton Kozlov wrote: > > blocking SIGSEGV and SIGBUS - or other synchronous error signals like > > SIGFPE - and then triggering said signal is UB. What happens is > > OS-dependent. I saw processes vanishing, or hang, or core. It makes sense, > > since what is

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-11 Thread Anton Kozlov
On Thu, 10 Mar 2022 18:04:50 GMT, Thomas Stuefe wrote: > blocking SIGSEGV and SIGBUS - or other synchronous error signals like SIGFPE > - and then triggering said signal is UB. What happens is OS-dependent. I saw > processes vanishing, or hang, or core. It makes sense, since what is the >

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-11 Thread Anton Kozlov
On Thu, 10 Mar 2022 18:07:37 GMT, Thomas Stuefe wrote: > > > > Is it possible to change SafeFetch only? Switch to WXExec before > > > > calling the stub and switch WXWrite back unconditionally? We won't need > > > > to provide assert in ThreadWXEnable. But SafeFetch can check the > > > >

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-11 Thread Florian Weimer
On Fri, 11 Mar 2022 09:50:22 GMT, Johannes Bechberger wrote: > According to > https://forums.swift.org/t/concurrencys-use-of-thread-local-variables/48654: > "these accesses are just a move from a system register plus a load/store at a > constant offset." Ideally you'd still benchmark that.

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-11 Thread Thomas Stuefe
On Fri, 11 Mar 2022 09:33:40 GMT, Andrew Haley wrote: > We could also redefine SafeFetch on MacOS/AArch64 to not need WX. We could do > this by statically generating SafeFetch on that platform, and it wouldn't be > in the JIT region at all. Why not just do that? Do you mean using inline

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-11 Thread Johannes Bechberger
On Fri, 11 Mar 2022 09:33:40 GMT, Andrew Haley wrote: > But we don't need to speculate. If thread-local variables are cheap on MacOS, > and there is no reason why they should be expensive, then we can stop > worrying and just use a thread-local variable for WX state. We can measure > how long

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-11 Thread Andrew Haley
On Thu, 10 Mar 2022 14:09:24 GMT, Anton Kozlov wrote: > > Depending on what the pthread library call does, and if it's a real > > function call into a library, it would be more expensive than that. > > Yes, unfortunately we need something like this. But we don't need to speculate. If

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-10 Thread Johannes Bechberger
On Wed, 9 Mar 2022 08:35:41 GMT, Johannes Bechberger wrote: >> The WXMode for the current thread (on MacOS aarch64) is currently stored in >> the thread class which is unnecessary as the WXMode is bound to the current >> OS thread, not the current instance of the thread class. >> This pull

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-10 Thread David Holmes
On Wed, 9 Mar 2022 08:35:41 GMT, Johannes Bechberger wrote: >> The WXMode for the current thread (on MacOS aarch64) is currently stored in >> the thread class which is unnecessary as the WXMode is bound to the current >> OS thread, not the current instance of the thread class. >> This pull

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-10 Thread Thomas Stuefe
On Thu, 10 Mar 2022 14:09:24 GMT, Anton Kozlov wrote: > > > Is it possible to change SafeFetch only? Switch to WXExec before calling > > > the stub and switch WXWrite back unconditionally? We won't need to > > > provide assert in ThreadWXEnable. But SafeFetch can check the assumption > > >

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-10 Thread Thomas Stuefe
On Thu, 10 Mar 2022 12:31:06 GMT, Anton Kozlov wrote: > > Signal handlers are per-process not per-thread, so a thread need not be > > attached to the VM for our signal handlers to get involved - that is why > > they call Thread::current_or_null_safe(). > > Oh, right, thanks. I was too

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-10 Thread David Holmes
On Thu, 10 Mar 2022 12:31:06 GMT, Anton Kozlov wrote: > The signal mask is per-thread, and a native thread may block the JVM signal. @AntonKozlov the signal from safefetch (if it is not safe) is a SIGSEGV or SIGBUS. If these signals happen to be blocked and we raise the signal synchronously

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-10 Thread Anton Kozlov
On Thu, 10 Mar 2022 12:41:11 GMT, Thomas Stuefe wrote: > You are saying that Java Threads may write too. And CompilerThreads, in the > case of SafeFetch at least, may run generated code. So switching has to be > done as a stack mark. Have I gotten this right? Right. > Depending on what the

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-10 Thread Thomas Stuefe
On Wed, 9 Mar 2022 08:35:41 GMT, Johannes Bechberger wrote: >> The WXMode for the current thread (on MacOS aarch64) is currently stored in >> the thread class which is unnecessary as the WXMode is bound to the current >> OS thread, not the current instance of the thread class. >> This pull

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-10 Thread Anton Kozlov
On Thu, 10 Mar 2022 10:17:31 GMT, David Holmes wrote: > Signal handlers are per-process not per-thread, so a thread need not be > attached to the VM for our signal handlers to get involved - that is why they > call Thread::current_or_null_safe(). Oh, right, thanks. I was too concentrated on

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-10 Thread David Holmes
On Thu, 10 Mar 2022 07:31:47 GMT, Anton Kozlov wrote: > How in general safe to call SafeFetch on a native thread that has no Thread > object? The JVM has not initialized the thread, so there could be no JVM > signal handler installed. @AntonKozlov Signal handlers are per-process not

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Anton Kozlov
On Thu, 10 Mar 2022 07:09:27 GMT, Anton Kozlov wrote: > > Interesting. But I would nonetheless create an assertion that checks that > > there is no nesting in the case without a Thread object. I would this using > > a thread local nesting counter in the ThreadWXEnable class (incremented in >

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Anton Kozlov
On Thu, 10 Mar 2022 06:00:42 GMT, Thomas Stuefe wrote: > Arguably we should restore, upon leaving the VM, the state that has been > present before. Because a native thread may already have modified the wx > state and overruling it is just rude. But I offhand don't see a way to do > this since

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Anton Kozlov
On Wed, 9 Mar 2022 20:25:02 GMT, Johannes Bechberger wrote: > Interesting. But I would nonetheless create an assertion that checks that > there is no nesting in the case without a Thread object. I would this using a > thread local nesting counter in the ThreadWXEnable class (incremented in

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Anton Kozlov
On Thu, 10 Mar 2022 05:52:48 GMT, Thomas Stuefe wrote: > Why don't we just switch it on once, for a thread that conceivably may call > into generated code, and be done with? Why is this fine granular switching > even needed? I find it difficult to imagine an attack vector that exploits >

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Thomas Stuefe
On Wed, 9 Mar 2022 19:03:16 GMT, Anton Kozlov wrote: >> Johannes Bechberger has updated the pull request incrementally with one >> additional commit since the last revision: >> >> current_thread_wx -> ThreadWX > >

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Thomas Stuefe
On Wed, 9 Mar 2022 19:03:16 GMT, Anton Kozlov wrote: >> Johannes Bechberger has updated the pull request incrementally with one >> additional commit since the last revision: >> >> current_thread_wx -> ThreadWX > >

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Johannes Bechberger
On Wed, 9 Mar 2022 08:35:41 GMT, Johannes Bechberger wrote: >> The WXMode for the current thread (on MacOS aarch64) is currently stored in >> the thread class which is unnecessary as the WXMode is bound to the current >> OS thread, not the current instance of the thread class. >> This pull

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Anton Kozlov
On Wed, 9 Mar 2022 08:35:41 GMT, Johannes Bechberger wrote: >> The WXMode for the current thread (on MacOS aarch64) is currently stored in >> the thread class which is unnecessary as the WXMode is bound to the current >> OS thread, not the current instance of the thread class. >> This pull

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Johannes Bechberger
On Wed, 9 Mar 2022 08:35:41 GMT, Johannes Bechberger wrote: >> The WXMode for the current thread (on MacOS aarch64) is currently stored in >> the thread class which is unnecessary as the WXMode is bound to the current >> OS thread, not the current instance of the thread class. >> This pull

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Anton Kozlov
On Wed, 9 Mar 2022 08:35:41 GMT, Johannes Bechberger wrote: >> The WXMode for the current thread (on MacOS aarch64) is currently stored in >> the thread class which is unnecessary as the WXMode is bound to the current >> OS thread, not the current instance of the thread class. >> This pull

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Johannes Bechberger
On Wed, 9 Mar 2022 11:14:09 GMT, David Holmes wrote: >> Johannes Bechberger has updated the pull request incrementally with one >> additional commit since the last revision: >> >> current_thread_wx -> ThreadWX > > src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp line 35: > >> 33:

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread David Holmes
On Wed, 9 Mar 2022 08:35:41 GMT, Johannes Bechberger wrote: >> The WXMode for the current thread (on MacOS aarch64) is currently stored in >> the thread class which is unnecessary as the WXMode is bound to the current >> OS thread, not the current instance of the thread class. >> This pull

Re: RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v6]

2022-03-09 Thread Johannes Bechberger
> The WXMode for the current thread (on MacOS aarch64) is currently stored in > the thread class which is unnecessary as the WXMode is bound to the current > OS thread, not the current instance of the thread class. > This pull request moves the storage of the current WXMode into a thread local