Re: Looking at "int vforked" in signal handler is racy

Herbert Xu <[email protected]> Mon, 11 Aug 2025 13:00:45 +0800
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
On Sun, Aug 10, 2025 at 11:20:40PM +0100, Harald van Dijk wrote:
>
> That approach seems solid to me at a very quick glance. I think you don't
> even need separate have_vfork_sibling and vfork_parent_pid variables, just
> make the existing vforked variable a pid, or 0. A mostly untested patch
> using that:

Looks good to me.  Could you turn this into a patch please? If
you could run some quick speed tests on this versus the existing
code that would be even better :)

> I do wonder if the use of vforked in a signal handler, even in current dash,
> would require the use of volatile to ensure no compiler optimisations mess
> with it, but I think that is not affected by this patch. If it is necessary,
> it is already necessary now, and if it is not necessary now, it will not
> become necessary with this patch.

Yes vfork should be marked as volatile.  Although being a global
variable means that there shouldn't be any practical difference.

Thanks,
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt