From patchwork Tue Jan 7 16:27:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 13929304 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 4EED71F7091 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=1736267278; cv=none; b=pJ/eVMoKt0gsXsLxNDdWwr3107CK7n+pt36CRKHI9zMEjLHCy1Ho20PtDL3UqBkEexGUPRmG/sZMieVcKOU7v4L/WBE4GPhBfqgoBihyTevx4YAAHNVUrFKAmoKiBfOqlKYyUGwrcAHvj9nyiEzHkOWHdgHjj8nboP6si8FB4E0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267278; c=relaxed/simple; bh=dmHj3dmkOxAQoBGRaUgSFco2HaCv1Up75FAsMyu9T+c=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=gJrS0TEqH+/nrdQQL3aycCYUiEfensKooClvBYqEBl9bm8VzOsw0M8ccwAyWmVAq0RJkdZ1sF3JWMPN96DX2/i2/NHFdmUE2y1DR6gCokPQqadks1C6nFY5pb8pKb2xmHuQMGq2fLIv56+ehr3EFcNRIWxkd7aXsNV9NpFRTEEg= 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: netdev@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 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 { 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(); + } } /* From patchwork Tue Jan 7 16:27:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 13929305 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 38FA81F709C for ; Tue, 7 Jan 2025 16:28:01 +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=1736267284; cv=none; b=eq7QJzSrpTUBvYDP1qHhiXxwWWG2YW7NpvdVXqw8zs5+ayuv2bCTqhyD2rbtDBvxpHoBbS/4yAx3S7ZJI8d24ACd8otpOfUaHzYhVQKAeqPE/H9fuiThWdgGgdwvXyksBXqEMjxKS85TVzsHZDhSRFCPi6Ix6yoJQikJcSQfNmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267284; c=relaxed/simple; bh=ro5SOHPGE494O8O02u5koqsBJ1Cw4yZfst2ne6UUoFY=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=PWv+WuJczFpUzAZKJer0qB1JpzmviaYd/EmhKwP6eyeSqbNe4QTMBp90Mu2eckQNIWofLTG+DoIvOh/yNVYT53jgMWGozk5A6tyL+mIVZ3iSi8E2M+KFc7WldiA1tJ0kx7VgwCUkQeoO6shn2H2dwYjm04oKdlsWWle95wB/XX8= 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=TA6IVByO; 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="TA6IVByO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736267281; 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=TA6IVByO+NfMJQ6d9tGJgG0i9QtCQBaKfndTZFpwjLD7MeY10MHVUftz8axQmxb36BNE3I 63SkZKcEKTJFpERdQjfeBLeUchSlviXVo4sanmif+TgqLjpGzlYDoHVXAtgNpMTk1oL3Ks UF9znpQWjHZTTxgStlGZvHlPN5jdGd8= 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: netdev@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 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 != 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 { 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(). From patchwork Tue Jan 7 16:27:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 13929306 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 A8A8F1F428A for ; Tue, 7 Jan 2025 16:28:06 +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=1736267288; cv=none; b=sXMEbdnp3SiXY7jEF0c0/tMhHNucHLq9ZvuDXcURGXdSVWgahU+CSlEdzjsBujQWY2f2uWU4oyfzbwzbYZfb/wtBtvGoklvyB4dVBsax3WypziqlSq9t9TGbuG/FK8/+/DxDUCfyU261BkM98p97A+eyiKa0SqrAeWONPZRmjh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267288; c=relaxed/simple; bh=8KUvX1mipGlvZnr3pyDyRpQyKInPgruNqY+hjvSMHr8=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=uQ13QchXZT7qP2U4mTeSNkdw7WlVxT5ELY6uB0KUa0nkw9YxDn0xWD62H5RuUgeBq4CHfBzK8nSAkA4kfdGGv1GP3MOOJl0/7FZ0OPUtVXB5lq2JU3nLRFk2DC2esDdOh9S5AENR6QvV18e1UCiuDgHMUOpkE6zAzb2l0BLzi3A= 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=Yol7MWqi; 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="Yol7MWqi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736267285; 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=Yol7MWqi6WkQ748ypyam++R+ovdcCt0BKtgQSQ1ifYScusYQ3nOrrTpIM8nEp/37VqmhJu O1rrzCuq9MPa2Xjf58Ig4p+yZfPOjg6cA3nQ5yuaTak63xTmMnPOKPtPupsqWAEdQSaDcx rAY5DSC/uBuIT0bcMYYQyJF0uVPWogo= 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: netdev@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 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, poll_table *wait) 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 |= EPOLLOUT | EPOLLWRNORM; From patchwork Tue Jan 7 16:27:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 13929307 X-Patchwork-Delegate: kuba@kernel.org 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 57CB91F76DF 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: netdev@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 X-Patchwork-Delegate: kuba@kernel.org 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) } /** - * 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_wq *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); } static inline void skb_set_hash_from_sk(struct sk_buff *skb, struct sock *sk) From patchwork Tue Jan 7 16:27:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 13929308 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 50F5A1F76D4 for ; Tue, 7 Jan 2025 16:28:22 +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=1736267306; cv=none; b=B1hkv9poFJObd/oFb7ZlFuR50JunjSs3rIa0Ptr4tMQdc40ciN3ItSHCtdOK8/J17AHY3Pry/7FmMDG88MoxT5Xop3UQROfUOL1HaTa9reT0HQLAy8TUF+2lNMo7xpRi2/rf6YQ/B8KZt1EDxj4v8A+tTSRg3abOJgkgL1y0I44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736267306; c=relaxed/simple; bh=747ikJyTyNIg0mXhy/B6zmZu9JIIYkk8XQpmBk8Hquo=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=VsTne0l3Vl3hXBM7PLdMGK6k8eeo+2/7gJ+JbrBDM/KqF2DFRNBITOzZRhhNOxhAXsE3dGzIf/0f3eXGKYutDNjY1XHjZmA9jnGUyH5WpVj+O9DWqMZrIVs1Y4DuAytUnxZ52MiRj42m2SMA4Ndzk5JNs9DNy9r5uJaj/4k+H6A= 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: netdev@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 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 @@ struct poll_table_struct; -/* +/* * structures and helpers for f_op->poll implementations */ typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *); /* - * 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_queue_head_t * wait_addres } } -/* - * Return true if it is guaranteed that poll will not wait. This is the case - * if the poll() of another file descriptor in the set got an event, so there - * is no need for waiting. - */ -static inline bool poll_does_not_wait(const poll_table *p) -{ - return p == NULL || p->_qproc == 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