Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1248888ybl; Wed, 28 Aug 2019 11:45:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoYKopLPTO0tVn3GLlJCRFMr1ASgAxDI/ceVJjjppqa55GXKMdd/7KhwdnualiCr/RSoPQ X-Received: by 2002:a17:90a:b946:: with SMTP id f6mr5772826pjw.86.1567017937528; Wed, 28 Aug 2019 11:45:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567017937; cv=none; d=google.com; s=arc-20160816; b=i4JypAFIPX1nKrNRJRNZX6GBqs9vIUI6t+D7o2LiHWwIeS1vRkWfkd7C6KJwOiYSOV KJah6xj4IfLWaWcEgUgoerM/qACPjL+FtI54hMwzyJPcfVpdjsgr4ZUlEQ5yJYlJVlcy y0hCAV7h03fUILyC28thex5i4JvV5FhoGwQsMjuV3lXwH2TRtidA3cXQ5dZMlrzGDng0 8n7SRL9S5ZK1CsgaaJES14ttL4H2rLGmAkmXXZzc6QyX43/5V2ItspBTJT8KXSosQb6j ZGXf/VJ7umZWFTQgqksQYk8USvC47rQPWeB2vwUlaTTHL+Dg3RgoP8BY0GGXlRLY1wH/ XQTg== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=OjPkEOv+DLtOkFTqeu8lwQuWyFpGs0nrOsZbcx7SOSc=; b=rfIAeolXd/a1tHjwLov3T8+IYbXNn7DqPRz5x/xD+7jGZ83euZ0yGJGRuqW1x5YOCN 8NyDFcvyqDCSMIjPiQENrBHvIbVfU4Bz6pnzVnPABT84xfo91D0Pkh8StR2is1m6NfrA uADv82rh8Uslca6ZXktMxQBZ1q503jwQdD6IIHRT0ynzbyzpNnlo836hshnhBmnqmh6i O4abVgLAOssTLIx6DlPDeR2dEqlU3OoNl4kqzMmYV+4dr/wdRCqGhemhBhXOahzkF88O mIGC4LBIJH9b0bobJR9FHuRze2KxSt5O8R3/S1pLS6u+68vMcmpxwn34dHB0kDE8M2s7 Ba2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=HbHXDrzL; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z9si2538818plo.66.2019.08.28.11.45.21; Wed, 28 Aug 2019 11:45:37 -0700 (PDT) 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; dkim=pass header.i=@ziepe.ca header.s=google header.b=HbHXDrzL; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726924AbfH1Sne (ORCPT + 99 others); Wed, 28 Aug 2019 14:43:34 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:38310 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726515AbfH1Snd (ORCPT ); Wed, 28 Aug 2019 14:43:33 -0400 Received: by mail-qt1-f193.google.com with SMTP id q64so717583qtd.5 for ; Wed, 28 Aug 2019 11:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=OjPkEOv+DLtOkFTqeu8lwQuWyFpGs0nrOsZbcx7SOSc=; b=HbHXDrzLqc3lpVU55Nd/0BI2SIQ2x72GzuKH/C2UAiJOAp38bcuMdbQptguyCeoa8S XtS6TSStn/7XppLzX0ltVtzjXABmeo1iBZlbJIsc4IjxoQVNK0XgHoe5qnT8leWBFLKp ygUAeNgUsdCWiSK9m1VX/B1VNJIeObqWI6AHSZGYIK+Qowf5xQW46ccAvDBEfsckznWb MmKN+mdFBQ6Nzf54I3ucE1GI2CyvGbcHp7ySqkRKMENGHCY7dCaaAu8QWTMfUcwQtNxa Ro8JrnGi/uzzbWR34UB7mEtJw9KlHNFZfY2+dANrWQiodo233hpz5sMhLvpLGJJjf8W7 2liA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=OjPkEOv+DLtOkFTqeu8lwQuWyFpGs0nrOsZbcx7SOSc=; b=jThY1Y0IpxskVAgHEw4Wu3N1ExhczNkgIgSYI64t+oZgW2a4Pno6aM2GnrUZkgvsQV QMpzLcLE+n657oljasZaTqgpIpVcx9ybCj0vSn1sZ742zpjfIDByJW67iFLwW/1z6FIT Or9VKvxpXm0DpzktBytsyfIcOJx5KSmWn7PNMvzx8rJP38iU62rByUG1ZYHGkqyiUwOa 1ILdQFnwbmzx9OPmQIk3SNCxND+DI9HgtgoKohkiuyrI8iSZ49X/4eyhIOVAwqJBrfVX bh3vDEXXBZsro7yVi7pbzdqrRrQHyN6drmp/3Ymzi7rWd+zMHGyPb/OnklNbLoJZbn3k A/Fg== X-Gm-Message-State: APjAAAU8BwyWumH06R0jbx9ILDP5ODTNK960tHfOjpSa0wo06BDtbSIb OYJ7Hj6ewQKf57MPqnKhVKcjCA== X-Received: by 2002:ac8:750e:: with SMTP id u14mr5800709qtq.282.1567017812387; Wed, 28 Aug 2019 11:43:32 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-167-216-168.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.167.216.168]) by smtp.gmail.com with ESMTPSA id k11sm21089qtp.26.2019.08.28.11.43.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Aug 2019 11:43:31 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1i32uo-0006U8-Rg; Wed, 28 Aug 2019 15:43:30 -0300 Date: Wed, 28 Aug 2019 15:43:30 -0300 From: Jason Gunthorpe To: Daniel Vetter Cc: LKML , Linux MM , DRI Development , Peter Zijlstra , Ingo Molnar , Andrew Morton , Michal Hocko , David Rientjes , Christian =?utf-8?B?S8O2bmln?= , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Masahiro Yamada , Wei Wang , Andy Shevchenko , Thomas Gleixner , Jann Horn , Feng Tang , Kees Cook , Randy Dunlap , Daniel Vetter Subject: Re: [PATCH 3/5] kernel.h: Add non_block_start/end() Message-ID: <20190828184330.GD933@ziepe.ca> References: <20190826201425.17547-1-daniel.vetter@ffwll.ch> <20190826201425.17547-4-daniel.vetter@ffwll.ch> <20190827225002.GB30700@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 28, 2019 at 08:33:13PM +0200, Daniel Vetter wrote: > On Wed, Aug 28, 2019 at 12:50 AM Jason Gunthorpe wrote: > > > > > diff --git a/include/linux/kernel.h b/include/linux/kernel.h > > > index 4fa360a13c1e..82f84cfe372f 100644 > > > +++ b/include/linux/kernel.h > > > @@ -217,7 +217,9 @@ extern void __cant_sleep(const char *file, int line, int preempt_offset); > > > * 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 > > > @@ -233,6 +235,25 @@ extern void __cant_sleep(const char *file, int line, int preempt_offset); > > > # define cant_sleep() \ > > > do { __cant_sleep(__FILE__, __LINE__, 0); } while (0) > > > # define sched_annotate_sleep() (current->task_state_change = 0) > > > +/** > > > + * non_block_start - annotate the start of section where sleeping is prohibited > > > + * > > > + * This is on behalf of the oom reaper, specifically when it is calling the mmu > > > + * notifiers. The problem is that if the notifier were to block on, for example, > > > + * mutex_lock() and if the process which holds that mutex were to perform a > > > + * sleeping memory allocation, the oom reaper is now blocked on completion of > > > + * that memory allocation. Other blocking calls like wait_event() pose similar > > > + * issues. > > > + */ > > > +# define non_block_start() \ > > > + do { current->non_block_count++; } while (0) > > > +/** > > > + * non_block_end - annotate the end of section where sleeping is prohibited > > > + * > > > + * Closes a section opened by non_block_start(). > > > + */ > > > +# define non_block_end() \ > > > + do { WARN_ON(current->non_block_count-- == 0); } while (0) > > > > check-patch does not like these, and I agree > > > > #101: FILE: include/linux/kernel.h:248: > > +# define non_block_start() \ > > + do { current->non_block_count++; } while (0) > > > > /tmp/tmp1spfxufy/0006-kernel-h-Add-non_block_start-end-.patch:108: WARNING: Single statement macros should not use a do {} while (0) loop > > #108: FILE: include/linux/kernel.h:255: > > +# define non_block_end() \ > > + do { WARN_ON(current->non_block_count-- == 0); } while (0) > > > > Please use a static inline? > > We need get_current() plus the task_struct, so this gets real messy > real fast. Not even sure which header this would fit in, or whether > I'd need to create a new one. You're insisting on this or respinning > with the do { } while (0) dropped ok. My prefernce is always a static inline, but if the headers are so twisty we need to use #define to solve a missing include, then I wouldn't insist on it. If dropping do while is the only change then I can edit it in.. I think we have the acks now Jason