From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754343AbbBNU7m (ORCPT ); Sat, 14 Feb 2015 15:59:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34371 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754225AbbBNU7l (ORCPT ); Sat, 14 Feb 2015 15:59:41 -0500 Date: Sat, 14 Feb 2015 21:57:45 +0100 From: Oleg Nesterov To: Davidlohr Bueso Cc: Darren Hart , Peter Zijlstra , Thomas Gleixner , Jerome Marchand , Larry Woodman , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] futex: check PF_KTHREAD rather than !p->mm to filter out kthreads Message-ID: <20150214205745.GA15695@redhat.com> References: <20150202140515.GA26398@redhat.com> <20150202140536.GA26406@redhat.com> <1423936866.2046.88.camel@stgolabs.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1423936866.2046.88.camel@stgolabs.net> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/14, Davidlohr Bueso wrote: > > On Mon, 2015-02-02 at 15:05 +0100, Oleg Nesterov wrote: > > --- a/kernel/futex.c > > +++ b/kernel/futex.c > > @@ -900,7 +900,7 @@ static int attach_to_pi_owner(u32 uval, union futex_key *key, > > if (!p) > > return -ESRCH; > > > > - if (!p->mm) { > > + if (unlikely(p->flags & PF_KTHREAD)) { > > put_task_struct(p); > > return -EPERM; > > } > > Futexes aren't the only naughty checkers, Yes, this is the common mistake, > a quick search shows that, at > least, the oom killer and proc have this same problem. oom looks fine, note the PF_KTHREAD check in oom_unkillable(). It check ->mm for another reason, to figure out if this task has passed exit_mm() or not. proc looks fine too at first glance... we do not care if this mm was adopted via use_mm() or not. > Should we make > this generic and update accordingly? ie: > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 8db31ef..b0d37d6 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -1991,6 +1991,11 @@ extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, > #define tsk_used_math(p) ((p)->flags & PF_USED_MATH) > #define used_math() tsk_used_math(current) > > +static inline bool task_is_kthread(struct task_struct *task) > +{ > + return task->flags & PF_KTHREAD; > +} Perhaps... but PF_KTHREAD looks self-documented too ;) Oleg.