Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3026680ybv; Mon, 24 Feb 2020 16:39:21 -0800 (PST) X-Google-Smtp-Source: APXvYqzkdDJCTIFk1dr01ClKjhBB0y6X4QnZFAz64K07rtJ3JFAn546gVbIIBxlplH1+vJuU4Wwn X-Received: by 2002:a9d:6548:: with SMTP id q8mr40654487otl.356.1582591161046; Mon, 24 Feb 2020 16:39:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582591161; cv=none; d=google.com; s=arc-20160816; b=J7/CicJ5VObEQrVsQkOQ22Tyduajiph6QPubGbgpL9mQNY6Vyoi2VzRdx7fW+/jDAT C2pbOl24TmNrBAa3gm3042Um3/CMoW3ybcxYdKo0x2QwfOn+j6x/N3jPsPD8TEqglPKV d1S6fZMmTYONXvJ744m7qqUapWFzV6xW9AX3V1YQ7eYxnDCsn0WymHA62RCCmdO+ZgwM xfGqsWzMonVoI3OUOlRePikXCtczkCFxhkOUMGybowE7Nt+DNWuq/XAvfXmr7t4stdUE GiAcOOkw8uMlAxIzW5aHo//7qD13JW8PjZvQNpBYVZgtPSMfDswVZXx8dMMtmcxHH8va BdSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=vm5X9ZK6V0tSLsjGWe5ff6+8Jhtk5E07DnY7WbdbLLU=; b=XP0z+Ehfct/b1Ltm62DjsUTA53pkoX0T2R5avioUuZ2M66u2Rds7sDJb9l+cRYpIvV 18BCYvYTN/+9Xl6eXFev6mukPM2Y8jhUs5jsQGFEJ0aErYU6lGL9FDMCrdi4EnNF36HM YWIYmuoWUjnCfaBHmVYo5TXph0Oh0+AJOerWNyzMUyWt3bmsaXEGMhCg3HNqPszJ9mt2 ZwFG/8edS4oy8SQ1xAOYYAssJzEQTpVgUwYDyNFhe1C4H8JtM0/HyTvFucj7OgYZ4dfi G+0SqqLqPdNBH3205isDbza5yvEuvrA+vxaRnAqVWx95Jr239x122Fj4ietGHZeJcuUJ J/Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0bkniVS3; 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 y24si5940066oih.24.2020.02.24.16.39.05; Mon, 24 Feb 2020 16:39:21 -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; dkim=pass header.i=@kernel.org header.s=default header.b=0bkniVS3; 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 S1728546AbgBYAij (ORCPT + 99 others); Mon, 24 Feb 2020 19:38:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:43460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728011AbgBYAii (ORCPT ); Mon, 24 Feb 2020 19:38:38 -0500 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 727EC2072D; Tue, 25 Feb 2020 00:38:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582591116; bh=jq3ODePJ3Q6zoN0OHkVIb2ToZ28VrtYjD3/dPpBAwUM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=0bkniVS3jwtRsC+8G6oMWVV5CiKekmBhS3eBDkSEHm1jAB9Mfu7zT2BAsRTwSnOI/ nif9ExSCKPT2copXKF7CCogu+iOq9LFdzn2HmqT3glMgLZcwi4tcTrNbdL8/+akbXD NpvxEngILyVqP2R1oZSb+x6GvzBiTtenwtM26xGI= Date: Mon, 24 Feb 2020 16:38:35 -0800 From: Andrew Morton To: Jason Baron Cc: dave@stgolabs.net, rpenyaev@suse.de, linux-kernel@vger.kernel.org, normalperson@yhbt.net, viro@zeniv.linux.org.uk Subject: Re: [PATCH] fs/epoll: make nesting accounting safe for -rt kernel Message-Id: <20200224163835.08ab964483519052d7c2e39b@linux-foundation.org> In-Reply-To: <1579288607-11868-1-git-send-email-jbaron@akamai.com> References: <20200106210104.4hqlgpujqujcbeg7@linux-p48b> <1579288607-11868-1-git-send-email-jbaron@akamai.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 17 Jan 2020 14:16:47 -0500 Jason Baron wrote: > Davidlohr Bueso pointed out that when CONFIG_DEBUG_LOCK_ALLOC is set > ep_poll_safewake() can take several non-raw spinlocks after disabling > pre-emption which is no no for the -rt kernel. So let's re-work how we > determine the nesting level such that it plays nicely with -rt kernel. "no no" isn't terribly informative, and knowledge of -rt's requirements isn't widespread. Can we please spell this requirement out in full detail, if only to spread the -rt education a bit? > Let's introduce a 'nests' field in struct eventpoll that records the > current nesting level during ep_poll_callback(). Then, if we nest again we > can find the previous struct eventpoll that we were called from and > increase our count by 1. The 'nests' field is protected by > ep->poll_wait.lock. > > I've also moved napi_id field into a hole in struct eventpoll as part of > introduing the nests field. This change reduces the struct eventpoll from > 184 bytes to 176 bytes on x86_64 for the !CONFIG_DEBUG_LOCK_ALLOC > production config. > > ... > > @@ -551,30 +557,43 @@ static int ep_call_nested(struct nested_calls *ncalls, > */ > #ifdef CONFIG_DEBUG_LOCK_ALLOC > > -static DEFINE_PER_CPU(int, wakeup_nest); > - > -static void ep_poll_safewake(wait_queue_head_t *wq) > +static void ep_poll_safewake(struct eventpoll *ep, struct epitem *epi) > { > + struct eventpoll *ep_src; > unsigned long flags; > - int subclass; > + u8 nests = 0; > > - local_irq_save(flags); > - preempt_disable(); > - subclass = __this_cpu_read(wakeup_nest); > - spin_lock_nested(&wq->lock, subclass + 1); > - __this_cpu_inc(wakeup_nest); > - wake_up_locked_poll(wq, POLLIN); > - __this_cpu_dec(wakeup_nest); > - spin_unlock(&wq->lock); > - local_irq_restore(flags); > - preempt_enable(); > + /* > + * If we are not being call from ep_poll_callback(), epi is > + * NULL and we are at the first level of nesting, 0. Otherwise, > + * we are being called from ep_poll_callback() and if a previous > + * wakeup source is not an epoll file itself, we are at depth > + * 1 since the wakeup source is depth 0. If the wakeup source > + * is a previous epoll file in the wakeup chain then we use its > + * nests value and record ours as nests + 1. The previous epoll > + * file nests value is stable since its already holding its > + * own poll_wait.lock. > + */ Similarly, it would be helpful if this comment were to explain that this code exists for -rt's requirements, and to briefly describe what that requirement is. > + if (epi) { > + if ((is_file_epoll(epi->ffd.file))) { > + ep_src = epi->ffd.file->private_data; > + nests = ep_src->nests; > + } else { > + nests = 1; > + } > + } > + spin_lock_irqsave_nested(&ep->poll_wait.lock, flags, nests); > + ep->nests = nests + 1; > + wake_up_locked_poll(&ep->poll_wait, EPOLLIN); > + ep->nests = 0; > + spin_unlock_irqrestore(&ep->poll_wait.lock, flags); > }