All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Savitz <jsavitz@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Nico Pache <npache@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-mm@kvack.org, linux-kernel <linux-kernel@vger.kernel.org>,
	Rafael Aquini <aquini@redhat.com>,
	Waiman Long <longman@redhat.com>, Baoquan He <bhe@redhat.com>,
	Christoph von Recklinghausen <crecklin@redhat.com>,
	Don Dutile <ddutile@redhat.com>,
	"Herton R . Krzesinski" <herton@redhat.com>,
	David Rientjes <rientjes@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Ingo Molnar <mingo@redhat.com>,
	Darren Hart <dvhart@infradead.org>,
	stable@kernel.org
Subject: Re: [PATCH v8] oom_kill.c: futex: Don't OOM reap the VMA containing the robust_list_head
Date: Fri, 8 Apr 2022 12:13:16 -0400	[thread overview]
Message-ID: <CAL1p7m4ukBQdQihkeSTjGHTM+HAF-GVf=QSnNPhRmetC213ANg@mail.gmail.com> (raw)
In-Reply-To: <87k0bzk7e5.ffs@tglx>

> ---
> #include <errno.h>
> #include <fcntl.h>
> #include <pthread.h>
> #include <time.h>
> #include <stdio.h>
> #include <string.h>
> #include <unistd.h>
>
> #include <sys/types.h>
> #include <sys/mman.h>
>
> static char n[4096];
>
> int main(void)
> {
>         pthread_mutexattr_t mat_s, mat_p;
>         pthread_mutex_t *mut_s, *mut_p;
>         pthread_barrierattr_t ba;
>         pthread_barrier_t *b;
>         struct timespec to;
>         void *pri, *shr;
>         int r;
>
>         shr = mmap(NULL, sizeof(n), PROT_READ | PROT_WRITE,
>                    MAP_SHARED | MAP_ANONYMOUS, -1, 0);
>
>         pthread_mutexattr_init(&mat_s);
>         pthread_mutexattr_setrobust(&mat_s, PTHREAD_MUTEX_ROBUST);
>         mut_s = shr;
>         pthread_mutex_init(mut_s, &mat_s);
>
>         pthread_barrierattr_init(&ba);
>         pthread_barrierattr_setpshared(&ba, PTHREAD_PROCESS_SHARED);
>         b = shr + 1024;
>         pthread_barrier_init(b, &ba, 2);
>
>         if (!fork()) {
>                 pri = mmap(NULL, 1<<20, PROT_READ | PROT_WRITE,
>                            MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>                 pthread_mutexattr_init(&mat_p);
>                 pthread_mutexattr_setpshared(&mat_p, PTHREAD_PROCESS_PRIVATE);
>                 pthread_mutexattr_setrobust(&mat_p, PTHREAD_MUTEX_ROBUST);
One thing I don't understand is what kind of sane use case relies on
robust futex for a process-private lock?
Is there a purpose to a lock being on the robust list if there are no
other processes that must be woken in case the holder process is
killed?
If this usage serves no purpose besides causing races during oom, we
should discourage this use, perhaps by adding a note on the manpage.

>                 mut_p = pri;
>                 pthread_mutex_init(mut_p, &mat_p);
>
>                 // With lock order s, p parent gets timeout
>                 // With lock order p, s parent gets owner died
>                 pthread_mutex_lock(mut_s);
>                 pthread_mutex_lock(mut_p);
>                 // Remove unmap and lock order does not matter
>                 munmap(pri, sizeof(n));
>                 pthread_barrier_wait(b);
>                 printf("child gone\n");
>         } else {
>                 pthread_barrier_wait(b);
>                 printf("parent lock\n");
>                 clock_gettime(CLOCK_REALTIME, &to);
>                 to.tv_sec += 1;
>                 r = pthread_mutex_timedlock(mut_s, &to);
>                 printf("parent lock returned: %s\n", strerror(r));
>         }
>         return 0;
> }
>


  reply	other threads:[~2022-04-08 16:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-08  3:28 [PATCH v8] oom_kill.c: futex: Don't OOM reap the VMA containing the robust_list_head Nico Pache
2022-04-08  8:15 ` Peter Zijlstra
2022-04-08  8:37   ` Thomas Gleixner
2022-04-08  8:52     ` Nico Pache
2022-04-08  9:36       ` Michal Hocko
2022-04-08  9:40         ` Nico Pache
2022-04-08  9:59           ` Michal Hocko
2022-04-08 10:36             ` Nico Pache
2022-04-08 10:51               ` Michal Hocko
2022-04-08 11:26                 ` Nico Pache
2022-04-08 11:48                   ` Michal Hocko
2022-04-08  8:41   ` Nico Pache
2022-04-08 13:54     ` Thomas Gleixner
2022-04-08 16:13       ` Joel Savitz [this message]
2022-04-08 21:41         ` Thomas Gleixner
2022-04-11  6:48           ` Michal Hocko
2022-04-11  7:47             ` Thomas Gleixner
2022-04-11  9:08               ` Michal Hocko
2022-04-12  0:02                 ` Nico Pache
2022-04-13 16:00                 ` Nico Pache
2022-04-11 23:51       ` Nico Pache
2022-04-12 16:20         ` Thomas Gleixner
2022-04-12 17:03           ` Nico Pache
2022-04-08 14:41 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAL1p7m4ukBQdQihkeSTjGHTM+HAF-GVf=QSnNPhRmetC213ANg@mail.gmail.com' \
    --to=jsavitz@redhat.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=aquini@redhat.com \
    --cc=bhe@redhat.com \
    --cc=crecklin@redhat.com \
    --cc=dave@stgolabs.net \
    --cc=ddutile@redhat.com \
    --cc=dvhart@infradead.org \
    --cc=herton@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=longman@redhat.com \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=npache@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rientjes@google.com \
    --cc=stable@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.