Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1969111ybv; Fri, 14 Feb 2020 09:04:49 -0800 (PST) X-Google-Smtp-Source: APXvYqxE71UyyUCTs2SVq5K/7vHulQSHeRRa8F2YEL+WJrQNcUPEKGRg12yo+MzaTp22JvWg+oSk X-Received: by 2002:a05:6830:1e86:: with SMTP id n6mr3086480otr.321.1581699889521; Fri, 14 Feb 2020 09:04:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581699889; cv=none; d=google.com; s=arc-20160816; b=z2PuxLPtQQdUW1prew/dQ57vaepsZpi56FCkJhiDGfL8L+p25KG5oFn9NOoBZoTDD/ pYIM6iLh23wJuvxWgnEYG4goZmGrGLazU0EG/tAD33wV+JzP3yPRSrxHKOiLelmXwbHG efMtleNXlKLjImMX/djaCAagDZDeLY8ET+tzKow8z9v3jFG8G1QF7TGNdN7Isgq71L+S od6Z46hPKtrBgaVzKlwFK8V6Ia54Ew0HNqsVJEOmLBkJrxyvF6st9PjcD02Roc++HPZh sYivG1njqijFeLDVGAWtrEguLZC+nA+Pd/XV424/RA5syuPq8yuTK1jG6cYKicg8D9Nl AFkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from; bh=dPEcI1DAInO0DtVtsuz35sNQLMhpmva2+6Q5pgNQ/iA=; b=Ebm/ota1tTYjbZP678PJ6VaWXmsjAFE/zxdlKHlz30YQ2rLrZt4pVWcZRGklhDGEQ0 fhC8/zKEtHXRqAicZ2SuLLDWrJkz9NC6HZw1AMoRiZDiVSh7jk2PRGa7sIbZIqNd/YJ5 THCYDMjTHkyTVH/jR8T6i0ZzVtOr65CslwWYMfNsd72Hiuh8fLh4u1rFukMqZ5qne8i2 7oKC9mTsYGKUDc6v2Ru5vhX1Tfv/LS4HVNdrdw+iFvkuYRDMk+SfreJTJ22s8lSQmajR kmMcljMsVVEvk+yWMIqpjHOsGNjMp6p4MXfDhVf5fapIJTUlXd/mVSUwqPQQdrZNcyR+ gdrg== 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 n7si2981940oie.95.2020.02.14.09.04.37; Fri, 14 Feb 2020 09:04:49 -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 S2394440AbgBNRCw (ORCPT + 99 others); Fri, 14 Feb 2020 12:02:52 -0500 Received: from mx2.suse.de ([195.135.220.15]:34652 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394411AbgBNRCs (ORCPT ); Fri, 14 Feb 2020 12:02:48 -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 65BD3B133; Fri, 14 Feb 2020 17:02:46 +0000 (UTC) From: Roman Penyaev Cc: Roman Penyaev , Max Neunhoeffer , Jakub Kicinski , Christopher Kohlhoff , Davidlohr Bueso , Jason Baron , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v3 1/2] epoll: fix possible lost wakeup on epoll_ctl() path Date: Fri, 14 Feb 2020 18:02:10 +0100 Message-Id: <20200214170211.561524-1-rpenyaev@suse.de> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 modifications of ep ready list, thus wake up can be lost. And yes, can be healed by explicit smp_mb(): list_add_tail(&epi->rdlink, &ep->rdllist); smp_mb(); if (waitqueue_active(&ep->wq)) wake_up(&ep->wp); But let's make it simple, thus 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 Reported-by: Max Neunhoeffer Bisected-by: Max Neunhoeffer Tested-by: 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 Cc: stable@vger.kernel.org #5.1+ --- Nothing was changed in v3 Nothing interesting in v2: changed the comment a bit and specified Reported-by and Bisected-by tags 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; -- 2.24.1