Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp21813001ybl; Mon, 6 Jan 2020 11:46:47 -0800 (PST) X-Google-Smtp-Source: APXvYqz0OB1rCKDRGU5MOpYhqo99dZVvqwwK8Pu+EK/48clNApbWKfOv4C+a/RGytN/yV8ZmR8rB X-Received: by 2002:a9d:3b5:: with SMTP id f50mr114113011otf.354.1578340007047; Mon, 06 Jan 2020 11:46:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578340007; cv=none; d=google.com; s=arc-20160816; b=KP7uCU2wsYAJBvEnBp4o8FqnVoUnmaLKEFo4e4mi4ugF/lNFXES9tifsK44bHMjE7S uMeyxMeW1lU3heagAwRVpmP82nRSX7P9WQ8HUH5k3RgJbKwOhYh2EESzX6FzQ+gR25Rg cdoQZW8BP8urBNN31ClbdeO7GcaPsNzmpw3ZFwoGJ3stkzjSYZyRmT5mkYB8Yr8vjPGe z1evC2DfbkZkYJbQqJUDCQsxTQ6+Wl1XJgDH4fyqMbO5T2ForjWUNUpul8XtXGWCI0Z7 Emps4PoUst1sqtlCC65ieqVC5D7nlHGLOA5xFuADCN0Og2PnR1O4I7q7K34cTeWJRb3y kWZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=gpLVehKsw9pdSpMm1yqFIhOLqlglL6oiP1hq7qoQPP4=; b=HCwTewlKTr88xulKul+gYHaRQLRjddtF7ztBv2fD2RN56ZB9LptDk2RZs3y8aTGseY rbJ7zqUKe0zFonqOjPRDtn5F777LKKnYEuIuPsX7MgvdDVjcJ0x9GSlVW1OZ2DxHW4UC D8Exgv9NBRBobZLN4rYbNxPNeBTRuBQRp8mWEvZTz0LlbFLOxC5xiqrX+cUE6byZN5/L i+OxT6kpn5swK+MtUXY8nO5UWI1xhP8+v2vc8GBXh7oPXt/zIXROuYPt686v1lAMQb7y Tw5qS9peF+CkOCjZ7bHTmuDkDyvmMnkuVDHl1mFJGnOftNR7Ttc3V3mRt7Ost4GsbZ/H nirg== 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 u16si32202086oia.233.2020.01.06.11.46.33; Mon, 06 Jan 2020 11:46:47 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726713AbgAFTpt (ORCPT + 99 others); Mon, 6 Jan 2020 14:45:49 -0500 Received: from mx2.suse.de ([195.135.220.15]:42946 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726657AbgAFTpt (ORCPT ); Mon, 6 Jan 2020 14:45:49 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4C53EAD11; Mon, 6 Jan 2020 19:45:47 +0000 (UTC) From: Davidlohr Bueso To: rpenyaev@suse.de Cc: akpm@linux-foundation.org, dave@stgolabs.net, jbaron@akamai.com, linux-kernel@vger.kernel.org, normalperson@yhbt.net, viro@zeniv.linux.org.uk, Davidlohr Bueso Subject: [PATCH] fs/epoll: rework safewake for CONFIG_DEBUG_LOCK_ALLOC Date: Mon, 6 Jan 2020 11:38:30 -0800 Message-Id: <20200106193830.27224-1-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <76f656dc7ac92f92682641e22e1c44c4@suse.de> References: <76f656dc7ac92f92682641e22e1c44c4@suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some comments on: f6520c52084 (epoll: simplify ep_poll_safewake() for CONFIG_DEBUG_LOCK_ALLOC) For one this does not play nice with preempt_rt as disabling irq and then taking a spinlock_t is a no no; the critical region becomes preemptible. This is particularly important as -rt is being mainlined. Secondly, it is really ugly compared to what we had before - albeit not having to deal with all the ep_call_nested() checks, but I doubt this overhead matters at all with CONFIG_DEBUG_LOCK_ALLOC. While the current logic avoids nesting by disabling irq during the whole path, this seems like an overkill under debug. This patch proposes using this_cpu_inc_return() then taking the irq-safe lock - albeit a possible irq coming in the middle between these operations and messing up the subclass. If this is unacceptable, we could always revert the patch, as this was never a problem in the first place. Signed-off-by: Davidlohr Bueso --- This is pretty much untested - I wanted to see what is the best way to address the concerns first. XXX: I don't think we need get/put_cpu() around the call, this was intended only for ep_call_nested() tasks_call_list checking afaict. fs/eventpoll.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 67a395039268..97d036deff3e 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -558,16 +558,17 @@ static void ep_poll_safewake(wait_queue_head_t *wq) unsigned long flags; int subclass; - local_irq_save(flags); - preempt_disable(); - subclass = __this_cpu_read(wakeup_nest); - spin_lock_nested(&wq->lock, subclass + 1); - __this_cpu_inc(wakeup_nest); + subclass = this_cpu_inc_return(wakeup_nest); + /* + * Careful: while unlikely, an irq can occur here and mess up + * the subclass. The same goes for right before the dec + * operation, but that does not matter. + */ + spin_lock_irqsave_nested(&wq->lock, flags, subclass + 1); wake_up_locked_poll(wq, POLLIN); - __this_cpu_dec(wakeup_nest); - spin_unlock(&wq->lock); - local_irq_restore(flags); - preempt_enable(); + spin_unlock_irqrestore(&wq->lock, flags); + + this_cpu_dec(wakeup_nest); } #else -- 2.16.4