From patchwork Mon Dec 10 10:36:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10721073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B42B13BF for ; Mon, 10 Dec 2018 10:37:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69F6529B1A for ; Mon, 10 Dec 2018 10:37:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E99C29BC2; Mon, 10 Dec 2018 10:37:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ED57829B1A for ; Mon, 10 Dec 2018 10:37:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BF2AD6E98A; Mon, 10 Dec 2018 10:36:56 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id D88B76E984 for ; Mon, 10 Dec 2018 10:36:52 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id b14so9019369edt.6 for ; Mon, 10 Dec 2018 02:36:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XEsctnSJl6ojJTv9Gu+kKqy9VNezjsl3TRV+ARV/mkc=; b=ONXZhAZk+hLtllt2pZJqQt2msxwfohJD/aJpd53Zp1LawcywIlf0wkqgzgjaUObnTu b1Ac6WC8CZBdN8jkfK9Xf/U/cFRhCEeb558hPHSXWKaYEpTaWE2DLDpX4tLgcvd0f1WK FgVP7XDlrp5jlmYoVmMveBMJUTNOt5WtvdimeboKtI0SY8JyZUSypSEFeLJK1L28/oWg YUmIeKqzbMqMRJpTKIeT15H94Uw7G7tbmgu+XW6UfmfAQ9M1P2/FhOj4zaT0IkIjVg2X +/SoJaGaBBBbmDXcCTDgl7fkdVYJVD/C8sWRv0T6fQKgxA0W6RDa+3Z8WAOna+taDmM3 vWxw== X-Gm-Message-State: AA+aEWb9UA0MQquneOwV7dqguYxzSr3t7I5Aijw2Nl2vx0YFZIWQ5igI c2dQoaIb7vsrbB0roHv2dAhYyx12N0c= X-Google-Smtp-Source: AFSGD/Uk9Y35fLYH2MG6TLt5GU2n4GMlNtntTdbUScLCDF73rMg9GXcbK7pjTLciIvgEi+Dvmd7bgA== X-Received: by 2002:a17:906:55a:: with SMTP id k26-v6mr9502822eja.218.1544438210804; Mon, 10 Dec 2018 02:36:50 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id q50sm3223862edd.66.2018.12.10.02.36.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Dec 2018 02:36:50 -0800 (PST) From: Daniel Vetter To: Intel Graphics Development Date: Mon, 10 Dec 2018 11:36:39 +0100 Message-Id: <20181210103641.31259-3-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181210103641.31259-1-daniel.vetter@ffwll.ch> References: <20181210103641.31259-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 2/4] kernel.h: Add non_block_start/end() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Hocko , Daniel Vetter , LKML , DRI Development , linux-mm@kvack.org, =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , David Rientjes , Daniel Vetter , Andrew Morton , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP 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. 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))