Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4827612ybl; Tue, 4 Feb 2020 02:42:52 -0800 (PST) X-Google-Smtp-Source: APXvYqxjCIyMdhO6hICGjhBLnHJ6ehPxcO66k5ZE+beBMwTMXqEEzuyFQ/waQUFhMaBFZRQX0dql X-Received: by 2002:a05:6830:15d2:: with SMTP id j18mr22378866otr.187.1580812972515; Tue, 04 Feb 2020 02:42:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580812972; cv=none; d=google.com; s=arc-20160816; b=fr0h54zswXjpNnW8JLs07+rL2A9Sdsg5TVwAh5/0G9BDo8ATdRT5c5SbatX3zer47q wmN1LuTfa1JAjsQOmyQtS6X/fxNUZEk2XoXb4e77DLD820hu5SRYdXOygIOQ394Ag6cx RVNXFUtkQW7PFKkadRrWXhIXA/CBfhtP111x4LmzazqRbD6HWSCr9c7Gv2TE+X/Y5E86 492Whr1+3JMH9EClOSbteBvPEa8eemD3dpP99t/BbuvgiE+dv0WmYtb7T5FqRYkEu0vD 7dhkUnsCdFiKT1kNFejmBij/J+T+nWZ5zIMPcteMuT5F5MWX1Qg3iSyahacRuUydrRWh XVJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version; bh=BzMT2e68HIZ822hOsw/PZZZwm8nrGd7eR3E1/5vGpUQ=; b=CO1CgmC+uNuAjqEizZw73Nma5ONinyP4whyNrTZ9eheIcRRJHAt1X21uj4wcDJYLS7 zOXZKkZ8Y8hJj41HsBbHKmTPFxTYSJmKDH9OSmkLchu9RmVfCZEraEOaU9IcwBjGQb8m 86QWZKFV3TYuBf2ZgY8Cx32AfLyknZ8R96tD4Tu2HYlfS5BI5Bdi/JCF1Z8um3jH5B2C qdyjNYpLatVshsUgh4p+4/n0DHwEYJnujhd6kkOpJGthjhOKc0T4YsZSyBqmTJTr+88o uu4sTRJt20SQuJxpfakwjinhNFH+/gOY7t0QUhC2ntwI3O/W//ENr1UVLob5aYaXllPh 4xHw== 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 x22si11108894otp.107.2020.02.04.02.42.38; Tue, 04 Feb 2020 02:42:52 -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 S1726730AbgBDKlp (ORCPT + 99 others); Tue, 4 Feb 2020 05:41:45 -0500 Received: from mx2.suse.de ([195.135.220.15]:51882 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726364AbgBDKlp (ORCPT ); Tue, 4 Feb 2020 05:41:45 -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 656B0B066; Tue, 4 Feb 2020 10:41:43 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 04 Feb 2020 11:41:42 +0100 From: Roman Penyaev To: Andrew Morton Cc: Max Neunhoeffer , Jakub Kicinski , Christopher Kohlhoff , Davidlohr Bueso , Jason Baron , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] epoll: fix possible lost wakeup on epoll_ctl() path In-Reply-To: <20200203205907.291929-1-rpenyaev@suse.de> References: <20200203205907.291929-1-rpenyaev@suse.de> Message-ID: <51f29f23a4d996810bfad12b9634ee12@suse.de> X-Sender: rpenyaev@suse.de User-Agent: Roundcube Webmail Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrew, Could you please suggest me, do I need to include Reported-by tag, or reference to the bug is enough? -- Roman On 2020-02-03 21:59, Roman Penyaev wrote: > This fixes possible lost wakeup introduced by the a218cc491420. > Originally modifications to ep->wq were serialized by ep->wq.lock, > but in the a218cc491420 new rw lock was introduced in order to > relax fd event path, i.e. callers of ep_poll_callback() function. > > After the change ep_modify and ep_insert (both are called on > epoll_ctl() path) were switched to ep->lock, but ep_poll > (epoll_wait) was using ep->wq.lock on wqueue list modification. > > The bug doesn't lead to any wqueue list corruptions, because wake up > path and list modifications were serialized by ep->wq.lock > internally, but actual waitqueue_active() check prior wake_up() > call can be reordered with modification of ep ready list, thus > wake up can be lost. > > Current patch replaces ep->wq.lock with the ep->lock for wqueue > modifications, thus wake up path always observes activeness of > the wqueue correcty. > > Fixes: a218cc491420 ("epoll: use rwlock in order to reduce > ep_poll_callback() contention") > References: https://bugzilla.kernel.org/show_bug.cgi?id=205933 > Signed-off-by: Roman Penyaev > Cc: Max Neunhoeffer > Cc: Jakub Kicinski > Cc: Christopher Kohlhoff > Cc: Davidlohr Bueso > Cc: Jason Baron > Cc: Andrew Morton > Cc: linux-fsdevel@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > --- > fs/eventpoll.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/fs/eventpoll.c b/fs/eventpoll.c > index b041b66002db..eee3c92a9ebf 100644 > --- a/fs/eventpoll.c > +++ b/fs/eventpoll.c > @@ -1854,9 +1854,9 @@ static int ep_poll(struct eventpoll *ep, struct > epoll_event __user *events, > waiter = true; > init_waitqueue_entry(&wait, current); > > - spin_lock_irq(&ep->wq.lock); > + write_lock_irq(&ep->lock); > __add_wait_queue_exclusive(&ep->wq, &wait); > - spin_unlock_irq(&ep->wq.lock); > + write_unlock_irq(&ep->lock); > } > > for (;;) { > @@ -1904,9 +1904,9 @@ static int ep_poll(struct eventpoll *ep, struct > epoll_event __user *events, > goto fetch_events; > > if (waiter) { > - spin_lock_irq(&ep->wq.lock); > + write_lock_irq(&ep->lock); > __remove_wait_queue(&ep->wq, &wait); > - spin_unlock_irq(&ep->wq.lock); > + write_unlock_irq(&ep->lock); > } > > return res;