Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp800883ybk; Wed, 13 May 2020 13:30:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxn+3t1BTx3Qag/ZYPI/0lGdGu+CH5iy1UMIetle30SKBq6wGM0/e2N4cPL1IxgH5nuWZ1 X-Received: by 2002:a17:906:7da:: with SMTP id m26mr797605ejc.342.1589401826522; Wed, 13 May 2020 13:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589401826; cv=none; d=google.com; s=arc-20160816; b=GiZhdspt6+lTJB4BYJCxVP+hCwWW4ZWjSw72SQXPllJpXzvejFxadbCXTOunSg2ZTD D4+8bKZlmVPWll8d1vi0I79p4wdFihcB8rfAL1BK1wHhcGDn8z/WCLgFWZDlZvQEbnmO DNhjnR05L5oyoPrgO3/WVofALl57YZcvW+3dm4kYb6APC3Cce1yUte6350FtEdFn09iZ j6yan0Bn1eBsU3YIQ7FAIkI4iT3av+HnEdN5cILkzb22CHWmx2xGp5yuzK/AHUHWa1BN D52rTC7ZAFOcKOB6aim88BGKxOSry+FyWnrNZ/tBL4fnu2HeMJo90B9hewD1DfTaeXA7 DpKQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7pBivQk/UumOMKuzW7Ejl1EElaRx5+Xzdl5HMD+TxlI=; b=idSEPbT1qtEplELLZXSY3RJ3L6yZ9kuFwTN8GSvDgprEXxzZ5bE5sVaGaREkNXBQVA Kv4vx/0mxZktiYm9MuFx+NZJTrLLJGZO0nDquztUc5eueA/WmduHFEpkoI+0bZn5UC73 lZ2mrEKwnUPunV0b+pqHax7nwQ8Qzzy+nneXGZCblbGO+k46BjX7zCHJlth/+b8BTlQj o8CvPtCxcfA3lNEI/E9ExC5zRmfJD/yN194ke0VQb9AG6uBFOUhW+aVoV7BSM7aaIoOx Wtr+/MyIhl76W7uMzTDc9HioHufgSu8RmzTipE/bkboPR3OORA9WQnUETcaBbdARraeG ZWpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NIABCVsM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k13si432223edn.344.2020.05.13.13.30.04; Wed, 13 May 2020 13:30:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NIABCVsM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732804AbgEMJuF (ORCPT + 99 others); Wed, 13 May 2020 05:50:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:49590 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387433AbgEMJuC (ORCPT ); Wed, 13 May 2020 05:50:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 C5D5C23128; Wed, 13 May 2020 09:50:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589363402; bh=H6RK4Fn9JCQrahNvg7ybV844UB/P0cnu7StCAIBei8I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NIABCVsMFeUEcsIOh0l7E83e8/AJBwu6FIxD9JFjf5wzYgfwJOzn85/kf5TbSfyB+ YufsjvSRjyXbtYqOqJfyTOBsHqF0OoTFBTsauxFCkKVbeOrDPEhFnKrVC/2Rg3jmlQ n8dqLzLDb7mDStmfqrYPexHvmoIYq2dmGK75f1Qo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Khazhismel Kumykov , Andrew Morton , Roman Penyaev , Alexander Viro , Heiher , Jason Baron , Linus Torvalds Subject: [PATCH 5.4 59/90] eventpoll: fix missing wakeup for ovflist in ep_poll_callback Date: Wed, 13 May 2020 11:44:55 +0200 Message-Id: <20200513094415.943881845@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513094408.810028856@linuxfoundation.org> References: <20200513094408.810028856@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Khazhismel Kumykov commit 0c54a6a44bf3d41e76ce3f583a6ece267618df2e upstream. In the event that we add to ovflist, before commit 339ddb53d373 ("fs/epoll: remove unnecessary wakeups of nested epoll") we would be woken up by ep_scan_ready_list, and did no wakeup in ep_poll_callback. With that wakeup removed, if we add to ovflist here, we may never wake up. Rather than adding back the ep_scan_ready_list wakeup - which was resulting in unnecessary wakeups, trigger a wake-up in ep_poll_callback. We noticed that one of our workloads was missing wakeups starting with 339ddb53d373 and upon manual inspection, this wakeup seemed missing to me. With this patch added, we no longer see missing wakeups. I haven't yet tried to make a small reproducer, but the existing kselftests in filesystem/epoll passed for me with this patch. [khazhy@google.com: use if/elif instead of goto + cleanup suggested by Roman] Link: http://lkml.kernel.org/r/20200424190039.192373-1-khazhy@google.com Fixes: 339ddb53d373 ("fs/epoll: remove unnecessary wakeups of nested epoll") Signed-off-by: Khazhismel Kumykov Signed-off-by: Andrew Morton Reviewed-by: Roman Penyaev Cc: Alexander Viro Cc: Roman Penyaev Cc: Heiher Cc: Jason Baron Cc: Link: http://lkml.kernel.org/r/20200424025057.118641-1-khazhy@google.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/eventpoll.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -1176,6 +1176,10 @@ static inline bool chain_epi_lockless(st { struct eventpoll *ep = epi->ep; + /* Fast preliminary check */ + if (epi->next != EP_UNACTIVE_PTR) + return false; + /* Check that the same epi has not been just chained from another CPU */ if (cmpxchg(&epi->next, EP_UNACTIVE_PTR, NULL) != EP_UNACTIVE_PTR) return false; @@ -1242,16 +1246,12 @@ static int ep_poll_callback(wait_queue_e * chained in ep->ovflist and requeued later on. */ if (READ_ONCE(ep->ovflist) != EP_UNACTIVE_PTR) { - if (epi->next == EP_UNACTIVE_PTR && - chain_epi_lockless(epi)) + if (chain_epi_lockless(epi)) + ep_pm_stay_awake_rcu(epi); + } else if (!ep_is_linked(epi)) { + /* In the usual case, add event to ready list. */ + if (list_add_tail_lockless(&epi->rdllink, &ep->rdllist)) ep_pm_stay_awake_rcu(epi); - goto out_unlock; - } - - /* If this file is already in the ready list we exit soon */ - if (!ep_is_linked(epi) && - list_add_tail_lockless(&epi->rdllink, &ep->rdllist)) { - ep_pm_stay_awake_rcu(epi); } /*