Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3681860imu; Mon, 10 Dec 2018 06:16:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/UTNaRf2h2IzP0+UgL8BSKMexgi8SdEqNDpQt1zQ0lvftsl+GjGS3RGCyn24a7z+nF5G6NB X-Received: by 2002:a17:902:d01:: with SMTP id 1mr12494427plu.127.1544451364803; Mon, 10 Dec 2018 06:16:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544451364; cv=none; d=google.com; s=arc-20160816; b=Bm67+4lsEklrdUaNaU4/p7/n2s5xNPVbHXLsUFW27yHXaNoa9VFKlkjbtFHuijBNBZ 6HvbPZsH0iNi8zHvVHtbXOeCERgyzHmEP46XNJWusr5Vnhh7xv6TIJlEcC0Vj+zYNnpv fUu+If0EuH4L1+c77kScaySmmyiZgRUbWJkwhnTlPGSC6EpbJ4exzvNM1qqkdXSKNJNp Ier/fu/+DuGSG8XFUmkm+xkZzZGiTo4NLDtLOrPQY958A0MgswDUTD0gm3PYaNlvF238 RKU0Qf/5xr34me5BgY/6imUGmbHnN7JDYRIPQruqXPi9thkyRHaXCkT+Nf4Lk9ARm0zy Mpaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=FXp+EqVOYpOqcWrl5bTzU7TKCPskILEbrkCU3wcyM6A=; b=RmrMRWLscVOslMtMFSfg5oNvdmhZ54pN1PNDpSUNFKhKBV+l/q3gM8JWh5qFFOAEwW ptm5CBHLwk0T8yO4DFKx9uIS2xCLKadfyEK0QZsPsgyrCQxeAwxyva9WHogOHlXrs503 qNLLEPlaiweNkP+jTFu83z6L+O68w/4STFCSux6gAbDKymkE6W7GWKXpv4IfoSZ1o5J2 guqUTa1UdKIb+A9WujW8WxaR2QMEpw1aUjIbTYJbeZ3sh06ZsiPQ3PXMta3yIA3TaftF /1iHO7o4A3YtImPTOxRjxNKLiBclehGXCqyiL/SxAKvVMRBCKpZ0Qn6xZX1D3XPLKWm6 MlEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9si7967426plz.427.2018.12.10.06.15.47; Mon, 10 Dec 2018 06:16:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727781AbeLJONl (ORCPT + 99 others); Mon, 10 Dec 2018 09:13:41 -0500 Received: from mx2.suse.de ([195.135.220.15]:40134 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727396AbeLJONk (ORCPT ); Mon, 10 Dec 2018 09:13:40 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 29CD2AD8F; Mon, 10 Dec 2018 14:13:38 +0000 (UTC) Date: Mon, 10 Dec 2018 15:13:37 +0100 From: Michal Hocko To: Daniel Vetter Cc: Intel Graphics Development , DRI Development , LKML , linux-mm@kvack.org, Andrew Morton , David Rientjes , Christian =?iso-8859-1?Q?K=F6nig?= , =?iso-8859-1?B?Suly9G1l?= Glisse , Daniel Vetter , Peter Zijlstra Subject: Re: [PATCH 2/4] kernel.h: Add non_block_start/end() Message-ID: <20181210141337.GQ1286@dhcp22.suse.cz> References: <20181210103641.31259-1-daniel.vetter@ffwll.ch> <20181210103641.31259-3-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20181210103641.31259-3-daniel.vetter@ffwll.ch> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I do not see any scheduler guys Cced and it would be really great to get their opinion here. On Mon 10-12-18 11:36:39, Daniel Vetter wrote: > In some special cases we must not block, but there's not a > spinlock, preempt-off, irqs-off or similar critical section already > that arms the might_sleep() debug checks. Add a non_block_start/end() > pair to annotate these. > > This will be used in the oom paths of mmu-notifiers, where blocking is > not allowed to make sure there's forward progress. Considering the only alternative would be to abuse preempt_{disable,enable}, and that really has a different semantic, I think this makes some sense. The cotext is preemptible but we do not want notifier to sleep on any locks, WQ etc. > Suggested by Michal Hocko. > > Cc: Andrew Morton > Cc: Michal Hocko > Cc: David Rientjes > Cc: "Christian K?nig" > Cc: Daniel Vetter > Cc: "J?r?me Glisse" > Cc: linux-mm@kvack.org > Signed-off-by: Daniel Vetter > --- > include/linux/kernel.h | 10 +++++++++- > include/linux/sched.h | 4 ++++ > kernel/sched/core.c | 6 +++--- > 3 files changed, 16 insertions(+), 4 deletions(-) > > diff --git a/include/linux/kernel.h b/include/linux/kernel.h > index d6aac75b51ba..c2cf31515b3d 100644 > --- a/include/linux/kernel.h > +++ b/include/linux/kernel.h > @@ -251,7 +251,9 @@ extern int _cond_resched(void); > * might_sleep - annotation for functions that can sleep > * > * this macro will print a stack trace if it is executed in an atomic > - * context (spinlock, irq-handler, ...). > + * context (spinlock, irq-handler, ...). Additional sections where blocking is > + * not allowed can be annotated with non_block_start() and non_block_end() > + * pairs. > * > * This is a useful debugging help to be able to catch problems early and not > * be bitten later when the calling function happens to sleep when it is not > @@ -260,6 +262,10 @@ extern int _cond_resched(void); > # define might_sleep() \ > do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) > # define sched_annotate_sleep() (current->task_state_change = 0) > +# define non_block_start() \ > + do { current->non_block_count++; } while (0) > +# define non_block_end() \ > + do { WARN_ON(current->non_block_count-- == 0); } while (0) > #else > static inline void ___might_sleep(const char *file, int line, > int preempt_offset) { } > @@ -267,6 +273,8 @@ extern int _cond_resched(void); > int preempt_offset) { } > # define might_sleep() do { might_resched(); } while (0) > # define sched_annotate_sleep() do { } while (0) > +# define non_block_start() do { } while (0) > +# define non_block_end() do { } while (0) > #endif > > #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) > diff --git a/include/linux/sched.h b/include/linux/sched.h > index ecffd4e37453..41249dbf8f27 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -916,6 +916,10 @@ struct task_struct { > struct mutex_waiter *blocked_on; > #endif > > +#ifdef CONFIG_DEBUG_ATOMIC_SLEEP > + int non_block_count; > +#endif > + > #ifdef CONFIG_TRACE_IRQFLAGS > unsigned int irq_events; > unsigned long hardirq_enable_ip; > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 6fedf3a98581..969d7a71f30c 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -6113,7 +6113,7 @@ void ___might_sleep(const char *file, int line, int preempt_offset) > rcu_sleep_check(); > > if ((preempt_count_equals(preempt_offset) && !irqs_disabled() && > - !is_idle_task(current)) || > + !is_idle_task(current) && !current->non_block_count) || > system_state == SYSTEM_BOOTING || system_state > SYSTEM_RUNNING || > oops_in_progress) > return; > @@ -6129,8 +6129,8 @@ void ___might_sleep(const char *file, int line, int preempt_offset) > "BUG: sleeping function called from invalid context at %s:%d\n", > file, line); > printk(KERN_ERR > - "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n", > - in_atomic(), irqs_disabled(), > + "in_atomic(): %d, irqs_disabled(): %d, non_block: %d, pid: %d, name: %s\n", > + in_atomic(), irqs_disabled(), current->non_block_count, > current->pid, current->comm); > > if (task_stack_end_corrupted(current)) > -- > 2.20.0.rc1 > -- Michal Hocko SUSE Labs