From nobody Fri Dec 19 20:33:52 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F7621F7093 for ; Tue, 7 Jan 2025 16:27:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267279; cv=none; b=eWO0w/LNDU2m/SiUHVdIdM+V//BtK33y35lHgigOagrUlVqWYaQYL767VgnLgfE5eE35PGsD7HFUzxv2gjHz4F1xdkEJ2X2j7uQ3C/xlq1KCPAIT3JlYLWzifNnXDTI8v91PYUGEa5gYBgZreWH4taA5BXScln7JYvUppH3TaB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267279; c=relaxed/simple; bh=dmHj3dmkOxAQoBGRaUgSFco2HaCv1Up75FAsMyu9T+c=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=ThpoH1EpGeHtu72dyAws+2dhqjpV2PNcthLXrBPTe5PyYn0yZ6NopZZun2TUrJm7wVydTDHB2zfQioRIgJHJZsTHjmeFrpxLK6p2pDz2nhgrokYlpNDm0VISYfN7SOi6hggAxs4ul2V/pXZbKLIqHdAHWtmywp8bDhx2hlJalnE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RoHZlS6P; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RoHZlS6P" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736267275; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=ZbRXxXmg9OkxN0j4zEVJR2Rc1pGGwym27qVLcHNh0nE=; b=RoHZlS6PgRelKbqHf6bKkdMxkQcWxUuAg2E5NDwU+idHJv7vzU3OBfoPm+IhnVVoLTIQuf gYCQH/+BbaU8Ll2gBH0Do4ilUuUZTQyH0PJJQ25bVBt7TWbEUeKiEX05qKli70mfxwVtXY 8QoymElOjsAKdE8NlolA1HlKZGdK01s= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-jKm-_prrN7WFvwE98lj3oQ-1; Tue, 07 Jan 2025 11:27:49 -0500 X-MC-Unique: jKm-_prrN7WFvwE98lj3oQ-1 X-Mimecast-MFC-AGG-ID: jKm-_prrN7WFvwE98lj3oQ Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CC54C1955E84; Tue, 7 Jan 2025 16:27:47 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.23]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 4A700195606B; Tue, 7 Jan 2025 16:27:42 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 7 Jan 2025 17:27:23 +0100 (CET) Date: Tue, 7 Jan 2025 17:27:17 +0100 From: Oleg Nesterov To: Christian Brauner , Linus Torvalds , Manfred Spraul Cc: "David S. Miller" , Eric Dumazet , Jens Axboe , Pavel Begunkov , WangYuli , linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 1/5] poll_wait: add mb() to fix theoretical race between waitqueue_active() and .poll() Message-ID: <20250107162717.GA18922@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250107162649.GA18886@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As the comment above waitqueue_active() explains, it can only be used if both waker and waiter have mb()'s that pair with each other. However __pollwait() is broken in this respect. This is not pipe-specific, but let's look at pipe_poll() for example: poll_wait(...); // -> __pollwait() -> add_wait_queue() LOAD(pipe->head); LOAD(pipe->head); In theory these LOAD()'s can leak into the critical section inside add_wait_queue() and can happen before list_add(entry, wq_head), in this case pipe_poll() can race with wakeup_pipe_readers/writers which do smp_mb(); if (waitqueue_active(wq_head)) wake_up_interruptible(wq_head); There are more __pollwait()-like functions (grep init_poll_funcptr), and it seems that at least ep_ptable_queue_proc() has the same problem, so the patch adds smp_mb() into poll_wait(). Link: https://lore.kernel.org/all/20250102163320.GA17691@redhat.com/ Signed-off-by: Oleg Nesterov --- include/linux/poll.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/poll.h b/include/linux/poll.h index d1ea4f3714a8..fc641b50f129 100644 --- a/include/linux/poll.h +++ b/include/linux/poll.h @@ -41,8 +41,16 @@ typedef struct poll_table_struct { =20 static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_= address, poll_table *p) { - if (p && p->_qproc && wait_address) + if (p && p->_qproc && wait_address) { p->_qproc(filp, wait_address, p); + /* + * This memory barrier is paired in the wq_has_sleeper(). + * See the comment above prepare_to_wait(), we need to + * ensure that subsequent tests in this thread can't be + * reordered with __add_wait_queue() in _qproc() paths. + */ + smp_mb(); + } } =20 /* --=20 2.25.1.362.g51ebf55 From nobody Fri Dec 19 20:33:52 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DE061F63E9 for ; Tue, 7 Jan 2025 16:28:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267282; cv=none; b=E1MHE2JTn/cC6t0Zd8qAMusPqgSfrFE1KMnJdzzQM8qf1/ZUezDmVl5eYO3gvAXekgSkyq0qr7/ox7mIKjy68cBY3v2Kk7eWKFQJB8ZYc0ksIm2XnNFnwj2WA9aoJj93k2snCxe6lEh4Zj9AdMffkBsqHgwuXIOM2JGh/+1lhAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267282; c=relaxed/simple; bh=ro5SOHPGE494O8O02u5koqsBJ1Cw4yZfst2ne6UUoFY=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=NeaAAxSVerc+kw0GUn4a0SKdgIibGJ7ooxJILlHSNxkujX6uX2Lxn0Fl30UolMSZNdiRazgEk5EvZxhztvZgMTqs6QeM4haMrrW8WiuvrrVQZNbmRVIHsUF8TkVAENdhDV7sumd5VgyaGWykAvO6sPkznhvXE9t4g1rOdy4rCes= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JiZ5Hbpa; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JiZ5Hbpa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736267279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=HDclS/DES8DLCo0SqLfzizwQKhbxuQktc23NSw3frko=; b=JiZ5HbparDu+Vvhoi6CZXgo8OQtmjLMmZxLJuJ3YVmffGwL6wAp/Trb5AX4stuMmbSUHF9 MVbSpLFMCnuDMAGPbKUHK5Rh63BeC6PLfLbfQxkk8aZAuMifPYCyitim2Lib4G2aih6O3R xZMb2C3f37/9PqEKXaRFXDDqtDy4WEI= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-q_1yp0tVNjyYqvWtWX8FjQ-1; Tue, 07 Jan 2025 11:27:55 -0500 X-MC-Unique: q_1yp0tVNjyYqvWtWX8FjQ-1 X-Mimecast-MFC-AGG-ID: q_1yp0tVNjyYqvWtWX8FjQ Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1449119560BD; Tue, 7 Jan 2025 16:27:54 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.23]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id EC1FF195395A; Tue, 7 Jan 2025 16:27:49 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 7 Jan 2025 17:27:29 +0100 (CET) Date: Tue, 7 Jan 2025 17:27:24 +0100 From: Oleg Nesterov To: Christian Brauner , Linus Torvalds , Manfred Spraul Cc: "David S. Miller" , Eric Dumazet , Jens Axboe , Pavel Begunkov , WangYuli , linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 2/5] poll_wait: kill the obsolete wait_address check Message-ID: <20250107162724.GA18926@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250107162649.GA18886@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This check is historical and no longer needed, wait_address is never NULL. These days we rely on the poll_table->_qproc check. NULL if select/poll is not going to sleep, or it already has a data to report, or all waiters have already been registered after the 1st iteration. However, poll_table *p can be NULL, see p9_fd_poll() for example, so we can't remove the "p !=3D NULL" check. Link: https://lore.kernel.org/all/20250106180325.GF7233@redhat.com/ Signed-off-by: Oleg Nesterov --- include/linux/poll.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/poll.h b/include/linux/poll.h index fc641b50f129..57b6d1ccd8bf 100644 --- a/include/linux/poll.h +++ b/include/linux/poll.h @@ -41,7 +41,7 @@ typedef struct poll_table_struct { =20 static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_= address, poll_table *p) { - if (p && p->_qproc && wait_address) { + if (p && p->_qproc) { p->_qproc(filp, wait_address, p); /* * This memory barrier is paired in the wq_has_sleeper(). --=20 2.25.1.362.g51ebf55 From nobody Fri Dec 19 20:33:52 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9378B1F7088 for ; Tue, 7 Jan 2025 16:28:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267290; cv=none; b=kBMIWH3aC5H04NHsSpanqLkMy6zpCIVk4V3uimx9lIqgOU2XCZlDdBcPn57mQW2hyuCkWhekOnKmhXuys65uxxxj9Nzz6kBKeU9B3RAhfM0qatfNyagJwCMtvoVhRDZOvj11nIZrXl3zusKjxkyOf8/t9NjxhxSqiweb2xYLFi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267290; c=relaxed/simple; bh=8KUvX1mipGlvZnr3pyDyRpQyKInPgruNqY+hjvSMHr8=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=Fl/SWZjolr2/iQtiHEJzVCtw1qriKBkEJn4c7q+zumwAKDIvLY4OZ23COxn++F7ysX85UpJjyNT+CptQ5I2a2w1l53FQ9l+0kiLklDYyOTuYJFC8qsGNPJCYqTqrwOANVWHz3XXleL3wuIhDoRRUTKjy+j401mXpZvBNlE8AQLw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EQxbKBRi; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EQxbKBRi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736267287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=0Hkc/r/J05Eu+h5oxPQEivv9ALULDWls00aLQM9qKG8=; b=EQxbKBRiJzMNDZh2ZfOu4hDGPC3zFxDWv7XBgaH+DeuL/8iI/PabhhjozZV0n2ymoTP9tx EM1jsXsOW8qNmWNAHTZLL62R5jWi8q+/3A24X+U4vLtqylqJLCMy/Mx/aQex4VANoOq4o7 9uDomzzDl/L2WFiS1AItvjh1ljW82Ek= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-131-PDawU3_sPHyeaIXWivLkAg-1; Tue, 07 Jan 2025 11:28:02 -0500 X-MC-Unique: PDawU3_sPHyeaIXWivLkAg-1 X-Mimecast-MFC-AGG-ID: PDawU3_sPHyeaIXWivLkAg Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 367B219560B9; Tue, 7 Jan 2025 16:28:00 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.23]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 197E01956088; Tue, 7 Jan 2025 16:27:55 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 7 Jan 2025 17:27:35 +0100 (CET) Date: Tue, 7 Jan 2025 17:27:30 +0100 From: Oleg Nesterov To: Christian Brauner , Linus Torvalds , Manfred Spraul Cc: "David S. Miller" , Eric Dumazet , Jens Axboe , Pavel Begunkov , WangYuli , linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 3/5] io_uring_poll: kill the no longer necessary barrier after poll_wait() Message-ID: <20250107162730.GA18940@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250107162649.GA18886@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that poll_wait() provides a full barrier we can remove smp_rmb() from io_uring_poll(). In fact I don't think smp_rmb() was correct, it can't serialize LOADs and STOREs. Signed-off-by: Oleg Nesterov --- io_uring/io_uring.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 06ff41484e29..a64a82b93b86 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2809,13 +2809,12 @@ static __poll_t io_uring_poll(struct file *file, po= ll_table *wait) =20 if (unlikely(!ctx->poll_activated)) io_activate_pollwq(ctx); - - poll_wait(file, &ctx->poll_wq, wait); /* - * synchronizes with barrier from wq_has_sleeper call in - * io_commit_cqring + * provides mb() which pairs with barrier from wq_has_sleeper + * call in io_commit_cqring */ - smp_rmb(); + poll_wait(file, &ctx->poll_wq, wait); + if (!io_sqring_full(ctx)) mask |=3D EPOLLOUT | EPOLLWRNORM; =20 --=20 2.25.1.362.g51ebf55 From nobody Fri Dec 19 20:33:52 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57BF51F76D6 for ; Tue, 7 Jan 2025 16:28:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267298; cv=none; b=KIRxTQdwfr1fcp5OlhQ8RkY7YRxilLcYBU4uIR3LHJ0+EVlo4e0IIg276qGQc2afvUnXHbr2iZn3sHMkoWZVktWY8rkvrWiPCUdGgXZaufpknE4CGVXuwHw0S3tV0/pOFNnf/5esZljeY8kpsQxv+kRzsIIkB9u6C2FrDO+rOIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267298; c=relaxed/simple; bh=D78ycDc0GJSDzjMxkMcR0mWhHo7fjIfKpgWtS/LY+8M=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=WKd/SwBoAuZn2Z4v81RcmcgEE1looGGpCN73q8uYOZBeBQ1JBJGKOqZ4zBwzUHVNzSstodTq3tmLmWDm8GgKRQFcgIraPqKaLAuQzRBDFiC3/B5NDjpApLtzMLXpszKtu29E03kd2lgwQngPpYy6k7gxTJr5Y6ZX2p9DEIMr1G4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LdCvTKl2; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LdCvTKl2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736267294; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=tqnBBbQoUY3GF4Dg2U11xguk1LdJlHU1RyqHwXPwrJE=; b=LdCvTKl2IHPLc4iyNqlVklemMIr7TpSqRxMJYHv9wFwJOdAQskmfx3muX7J5vSe9gykITP PS6vsmmrNIQTfAmTVTmRD2E8dtk4BopMzIB18qNI61W2VO42sv7rZ1jEiHYLnNmWozqpjW ykObZgEW+0uzGmPWpPyFaySPFOTWwrE= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-l6jgmbfNP5Cnuudsv6Q33Q-1; Tue, 07 Jan 2025 11:28:09 -0500 X-MC-Unique: l6jgmbfNP5Cnuudsv6Q33Q-1 X-Mimecast-MFC-AGG-ID: l6jgmbfNP5Cnuudsv6Q33Q Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B471B1955E9F; Tue, 7 Jan 2025 16:28:06 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.23]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 3E3881956088; Tue, 7 Jan 2025 16:28:01 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 7 Jan 2025 17:27:42 +0100 (CET) Date: Tue, 7 Jan 2025 17:27:36 +0100 From: Oleg Nesterov To: Christian Brauner , Linus Torvalds , Manfred Spraul Cc: "David S. Miller" , Eric Dumazet , Jens Axboe , Pavel Begunkov , WangYuli , linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 4/5] sock_poll_wait: kill the no longer necessary barrier after poll_wait() Message-ID: <20250107162736.GA18944@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250107162649.GA18886@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that poll_wait() provides a full barrier we can remove smp_mb() from sock_poll_wait(). Also, the poll_does_not_wait() check before poll_wait() just adds the unnecessary confusion, kill it. poll_wait() does the same "p && p->_qproc" check. Signed-off-by: Oleg Nesterov --- include/net/sock.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 7464e9f9f47c..305f3ae5edc2 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2291,7 +2291,7 @@ static inline bool skwq_has_sleeper(struct socket_wq = *wq) } =20 /** - * sock_poll_wait - place memory barrier behind the poll_wait call. + * sock_poll_wait - wrapper for the poll_wait call. * @filp: file * @sock: socket to wait on * @p: poll_table @@ -2301,15 +2301,12 @@ static inline bool skwq_has_sleeper(struct socket_w= q *wq) static inline void sock_poll_wait(struct file *filp, struct socket *sock, poll_table *p) { - if (!poll_does_not_wait(p)) { - poll_wait(filp, &sock->wq.wait, p); - /* We need to be sure we are in sync with the - * socket flags modification. - * - * This memory barrier is paired in the wq_has_sleeper. - */ - smp_mb(); - } + /* Provides a barrier we need to be sure we are in sync + * with the socket flags modification. + * + * This memory barrier is paired in the wq_has_sleeper. + */ + poll_wait(filp, &sock->wq.wait, p); } =20 static inline void skb_set_hash_from_sk(struct sk_buff *skb, struct sock *= sk) --=20 2.25.1.362.g51ebf55 From nobody Fri Dec 19 20:33:52 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18A0F1F8676 for ; Tue, 7 Jan 2025 16:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267307; cv=none; b=fWBmN9sgglNjgeHMTgYbLMe578ABl4fO5Y26+JRo76TVyc0OCjpIhNKlAGM/13AW9aSKIkANswFztKvkXmfJ12L0/WVJLWil25wPFLwKVHg7InWrZ06BuaJpSWSi/Qb37A2w5DY++OBz5l7+5n9503vS0db0hxFkW7bik9Hpad4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267307; c=relaxed/simple; bh=747ikJyTyNIg0mXhy/B6zmZu9JIIYkk8XQpmBk8Hquo=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=AGMgEXE3HgMP3c9ujJ1BXJJkYdYCHIxALlAbA26+o34CG/2z3AwDxL8g8d+Bg2z/Udowna7GZr+P06aXIE5Zlcahhvjra7/s0Dj0/daNoj9OHpVdGt8u2KZMqX16CLzYcNL6GHKrCZN/MQoyNpnkAA5RQjNy0PwMzifyXjizWQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CGOE90Du; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CGOE90Du" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736267301; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=ggzPhdIvprjKO6zo/NvbJC2/YROGoQldUxo9aidxPIM=; b=CGOE90Dux5XwsAJ3HgUyip3YRM5EKH++/3kgQ/GDw/nwOEXu2lRCy+y+fbf5u6lx0R4E80 PJyeyzPjZ/8ScJH2jorFLAl1XiIGCxIFGQTQHsGEBsblInqE9ngCRerbEXOXmvs+JSd5pW 0uakxJVEEaVfLMUaHXpoBoI1mKzQaqU= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-670-vfGwU8W8OU6n2Z7y0dIW_Q-1; Tue, 07 Jan 2025 11:28:15 -0500 X-MC-Unique: vfGwU8W8OU6n2Z7y0dIW_Q-1 X-Mimecast-MFC-AGG-ID: vfGwU8W8OU6n2Z7y0dIW_Q Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8223619560A6; Tue, 7 Jan 2025 16:28:13 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.23]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id DC6A7195606C; Tue, 7 Jan 2025 16:28:08 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 7 Jan 2025 17:27:49 +0100 (CET) Date: Tue, 7 Jan 2025 17:27:43 +0100 From: Oleg Nesterov To: Christian Brauner , Linus Torvalds , Manfred Spraul Cc: "David S. Miller" , Eric Dumazet , Jens Axboe , Pavel Begunkov , WangYuli , linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 5/5] poll: kill poll_does_not_wait() Message-ID: <20250107162743.GA18947@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250107162649.GA18886@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It no longer has users. Signed-off-by: Oleg Nesterov --- include/linux/poll.h | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/include/linux/poll.h b/include/linux/poll.h index 57b6d1ccd8bf..12bb18e8b978 100644 --- a/include/linux/poll.h +++ b/include/linux/poll.h @@ -25,14 +25,14 @@ =20 struct poll_table_struct; =20 -/*=20 +/* * structures and helpers for f_op->poll implementations */ typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct= poll_table_struct *); =20 /* - * Do not touch the structure directly, use the access functions - * poll_does_not_wait() and poll_requested_events() instead. + * Do not touch the structure directly, use the access function + * poll_requested_events() instead. */ typedef struct poll_table_struct { poll_queue_proc _qproc; @@ -53,16 +53,6 @@ static inline void poll_wait(struct file * filp, wait_qu= eue_head_t * wait_addres } } =20 -/* - * Return true if it is guaranteed that poll will not wait. This is the ca= se - * if the poll() of another file descriptor in the set got an event, so th= ere - * is no need for waiting. - */ -static inline bool poll_does_not_wait(const poll_table *p) -{ - return p =3D=3D NULL || p->_qproc =3D=3D NULL; -} - /* * Return the set of events that the application wants to poll for. * This is useful for drivers that need to know whether a DMA transfer has --=20 2.25.1.362.g51ebf55