Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4119775ybl; Mon, 3 Feb 2020 13:00:27 -0800 (PST) X-Google-Smtp-Source: APXvYqzSyV+YaAfZaX7IvmhEhZt4eL7JQiP2jQKZvs3XvOGiq5tw2kBDDsEJz+KfUEVWFjuE9AIw X-Received: by 2002:a05:6830:112:: with SMTP id i18mr225334otp.253.1580763627403; Mon, 03 Feb 2020 13:00:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580763627; cv=none; d=google.com; s=arc-20160816; b=TBZtHZls+6rC1bzRYBfaiUDGIEluibfGdHKJSs9uBnr0nTdSQ0pqtP4soyiot03iLT W82cuMpCleIwzb4miBlyN63UH3/b3svdZN8yxJTYFMnptFF6VtNbgjqOPP9M1kudHDWu rkIDjWMl2UooeTSvrbKPcuX0Jx9oVsTvN8MDCZEoFHq76zprFIS8/9ByIAio4/6T7dCp y14+hFVWPggW2Z2yhWi6uFFjUUDXJteuv4F/IFtS9zntT7xXxKVCdTBlxbmIXXP9fw5J /GToDkFRozan7SoQGpkfq9c+jOI4sjg2abKlPTfjPi2e1jPl9LsjbEcjvigHCPspzMl8 7pvA== 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=ASkb2Ux99/apLYp6XOynhHUSIUkyTwyqUZzqhgn00bM=; b=T1LS5j0zDRhmfAXfEG82nWQDRCtu9+ipcaQ3vcOvVqjPF52kwU2zHNYEy8J4hca0w1 yv4HfQbtUg/rOcBYvkrBktsQl5C4kEJypr0PHe+kyxtDUxhJBcvJ1YWLUkFeyGEYlslP emPKPN5VmsJtqw+EX4QL7UHuvUm2kZWEDITlMqs8pJWLji5imEvu7eAP46sBMbuiKhBa YxcTL7jCOvWicvBjWaA8kijiQRdH+U9MAByPfraJuGM9TrNjsSAglSnV/VLziisE2lTT Zynyxd+hH9SIgPHgM5CxZgQM/8PuuDC6xmyx66CikxP5Wcs8t7ZC+gFf3hPWYr97vQnL j70w== 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 m24si9994604otn.67.2020.02.03.13.00.15; Mon, 03 Feb 2020 13:00:27 -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 S1727148AbgBCU7X (ORCPT + 99 others); Mon, 3 Feb 2020 15:59:23 -0500 Received: from mx2.suse.de ([195.135.220.15]:47744 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726272AbgBCU7V (ORCPT ); Mon, 3 Feb 2020 15:59:21 -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 1DB3CACAC; Mon, 3 Feb 2020 20:59:19 +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 Subject: [PATCH 1/3] epoll: fix possible lost wakeup on epoll_ctl() path Date: Mon, 3 Feb 2020 21:59:05 +0100 Message-Id: <20200203205907.291929-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 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; -- 2.24.1