Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4158657imm; Sat, 21 Jul 2018 11:32:36 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcvm5eLRVQu/6C+96T3zdrdfaxMOF4H1FKhmIi2xqXSMl3rQ+uPmT0AXCqV2xfTkbKk7Bh4 X-Received: by 2002:a62:a018:: with SMTP id r24-v6mr6962377pfe.144.1532197956794; Sat, 21 Jul 2018 11:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532197956; cv=none; d=google.com; s=arc-20160816; b=OPyg+xVZocirfwKp+X8pozhe3/NrT5Gfz1jDMh0uZhPHrxMUsc8W9fw+S1F7pi+hMc bJ1mBUtPZ3yuoAsiSaIRaD5S39l6kyx8kA2NfGsLGIO2FmSuCESHGKClwmqePBMIZwbg DbrZIuR2AGdUhpHkDa2FJDUUnV+efZWUqTYhjnq/AeaxGB/oCaKu3VqCr+fjvZnP2qtA hI4T3VEEeF6wpROlu6AIEssgZ7iPZ7WvF8VBfpBJifPpeeaSZkhOtXUn6FRU5ebX2BYe in5xBSzfChMD/eegjK88azUTcHdiFYodDOXfBEYGGoIDxolNY4BrjKRa8jU5hWOKVtqH 35pA== 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:arc-authentication-results; bh=3gqXesIZ3H2E2IO70w8EIVjD2iKzLvVrMjcjCu3rEvU=; b=U5UPzTFW5CvhaGYxE/UBCbS/S1OwMCHMbYpBg4HrzTHbIbSwaETowx1MUN7EZeQGDE qSVmu/h5HU5HxF7Lv734WROJfqVgvOt0m9TAC9nVWtCUeLwsYr3QXMp4DtFiOGltsN/G 0rG3cUaAyI7JgyMIp/xXl7MtEDjpt8iYugsiPkeFwEGhSbCEOy3zd3qfJlcJOrDJkd8C G6mCJLllqYlkP4M+dn884e8TAyz7NFBFhuuKoI7pzbg7BVTG+nyXwGj3NB5nShVYvP8T +hKKL5dhRS+DyQ8KwJt1zEMo3X1PrPtScUYbZH1CacPv87f0XLDzIpRjlShJAaOXpJ7q Z5pA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v1-v6si3995080pgr.469.2018.07.21.11.32.21; Sat, 21 Jul 2018 11:32:36 -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; 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 S1728395AbeGUTZN (ORCPT + 99 others); Sat, 21 Jul 2018 15:25:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:36480 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727854AbeGUTZN (ORCPT ); Sat, 21 Jul 2018 15:25:13 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 26F2FAD9D; Sat, 21 Jul 2018 18:31:32 +0000 (UTC) Date: Sat, 21 Jul 2018 11:31:27 -0700 From: Davidlohr Bueso To: Peter Zijlstra Cc: Andrew Morton , jbaron@akamai.com, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org Subject: Re: [PATCH -next 0/2] fs/epoll: loosen irq safety when possible Message-ID: <20180721183127.3busfa335zlcjeox@linux-r8p5> References: <20180720172956.2883-1-dave@stgolabs.net> <20180720124212.7260d76d83e2b8e5e3349ea5@linux-foundation.org> <20180720200559.27nc7j2rrxpy5p3n@linux-r8p5> <20180720134429.1ba61018934b084bb2e17bdb@linux-foundation.org> <20180721172120.kbdu4euc2wn4xzgf@linux-r8p5> <20180721173944.GV2494@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20180721173944.GV2494@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 21 Jul 2018, Peter Zijlstra wrote: >On Sat, Jul 21, 2018 at 10:21:20AM -0700, Davidlohr Bueso wrote: >> On Fri, 20 Jul 2018, Andrew Morton wrote: >> >> > We could open-code it locally. Add a couple of >> > WARN_ON_ONCE(irqs_disabled())? That might need re-benchmarking with >> > Xen but surely just reading the thing isn't too expensive? >> >> We could also pass on the responsibility to lockdep and just use >> lockdep_assert_irqs_disabled(). But I guess that would be less effective >> than to just open code it in epoll without lockdep -- note that over 80 >> places in the kernel do this. > >The lockdep thing is relatively recent. I think someone proposed to go >replace a bunch of the open-coded ones at some point. For the open coded checks, I'm seeing a small (1-2% ish) cost for bare metal on workload 1). I don't see (via code inspection) any additional overhead in xen either. While negligible in the overall of things, I do like the idea of lockdep handling it nonetheless. I can add the open coded version if people really feel that it would catch more bugs (no lockdep users out there in production afaik :) in the long term; but if lockdep is where things are headed... Thanks, Davidlohr -------8<-------------------------------------------------------- [PATCH -next 3/2] fs/epoll: robustify irq safety with lockdep_assert_irqs_enabled() Sprinkle lockdep_assert_irqs_enabled() checks in the functions that do not save and restore interrupts when dealing with the ep->wq.lock. These are ep_scan_ready_list() and those called by epoll_ctl(): ep_insert, ep_modify and ep_remove. Signed-off-by: Davidlohr Bueso --- fs/eventpoll.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 1b1abc461fc0..97b9b73dfec8 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -670,6 +670,9 @@ static __poll_t ep_scan_ready_list(struct eventpoll *ep, struct epitem *epi, *nepi; LIST_HEAD(txlist); + /* must not be called with irqs off */ + lockdep_assert_irqs_enabled(); + /* * We need to lock this because we could be hit by * eventpoll_release_file() and epoll_ctl(). @@ -764,6 +767,9 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi) { struct file *file = epi->ffd.file; + /* must not be called with irqs off */ + lockdep_assert_irqs_enabled(); + /* * Removes poll wait queue hooks. */ @@ -1412,6 +1418,9 @@ static int ep_insert(struct eventpoll *ep, const struct epoll_event *event, struct epitem *epi; struct ep_pqueue epq; + /* must not be called with irqs off */ + lockdep_assert_irqs_enabled(); + user_watches = atomic_long_read(&ep->user->epoll_watches); if (unlikely(user_watches >= max_user_watches)) return -ENOSPC; @@ -1540,6 +1549,9 @@ static int ep_modify(struct eventpoll *ep, struct epitem *epi, int pwake = 0; poll_table pt; + /* must not be called with irqs off */ + lockdep_assert_irqs_enabled(); + init_poll_funcptr(&pt, NULL); /* -- 2.16.4