Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3538772ybv; Mon, 10 Feb 2020 01:42:42 -0800 (PST) X-Google-Smtp-Source: APXvYqxdHAzDSRXuc+cnUtCMSGNw6vfPE0s6lx+4uzTg6QnR6a//xiQk6YfbWCwi2mbzT9udIlck X-Received: by 2002:a9d:600e:: with SMTP id h14mr388812otj.113.1581327762061; Mon, 10 Feb 2020 01:42:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581327762; cv=none; d=google.com; s=arc-20160816; b=kCMEdDXBtJTpbvPCqenVUiqUQrAd8eLVKOQvhCm+8PcLB8hCo5SytBbkWzNEWyzShB 0D7Dfnlbfj5puIZKJTrNETTwVTuQwhHE9BK3w5yIfB/Xh8aRBNrVEDfgYy/YgjrrkIBm ILX1Oq07TcHpPXdSkzs38ZvkQ8O55tCYvNxGbuHxFb4iFhaLyLfXWhobZo7jQtCnEwue 1whD1u+6KCT0OpYFTxyr3lJg5OGKLNAjg72PTB9uq7RCezBglG1OIY9JH+3zo44myip8 fk4cwM3QbwL2DrR2PO8Lv+a49yVQT9pm4qPcxdiJL/e0ooUVM2tB3Sv7ckAU1N705Grm GifA== 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=ho2btyCRj/X+qCaS1khv1WErgiqUvDkDEXIS4PRNFRE=; b=gRfsriRbeOzE/86jBQAc5gAc07kZ/U9DH88ONd2xF/SiQf2bha6shruatuhpUqMKD1 4bPGfhXZ6MDAbn6OwId08x+ekFo7QNGyylwDGAcYekQpY/EOuGaUz+3kF7GR5CN4yJcT IfAajVOs7UG9RprXSPBMlbVLRvE2bf3Pd13ZuFBKV5xMMZGyl3kTcHEcpL7578/3H4m7 qXBVruxT0m3GsiRKlyU9Zs0uOnBoglCHs33zWRhTflMFGMqP5uPoULWn9yanPfO22rbU YoO6E7n0deBlHptrJs18bTZYjX9FqdBTZEpG6EnNVrC2Ikc/1fWkDwiiH2eW2TMg+Y2n TQ4A== 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 i8si8120954oih.206.2020.02.10.01.42.30; Mon, 10 Feb 2020 01:42:42 -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 S1727563AbgBJJmT (ORCPT + 99 others); Mon, 10 Feb 2020 04:42:19 -0500 Received: from mx2.suse.de ([195.135.220.15]:51736 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727429AbgBJJmS (ORCPT ); Mon, 10 Feb 2020 04:42:18 -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 8FDE0AEC4; Mon, 10 Feb 2020 09:42:16 +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 v2 1/3] epoll: fix possible lost wakeup on epoll_ctl() path Date: Mon, 10 Feb 2020 10:41:21 +0100 Message-Id: <20200210094123.389854-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 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 --- 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