From nobody Fri Dec 19 06:39:19 2025 Received: from mail-pl1-f228.google.com (mail-pl1-f228.google.com [209.85.214.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C977E2C327D for ; Thu, 18 Dec 2025 02:45:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.228 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766025905; cv=none; b=nE1bJEi8Mn7MVhvDUhGmfSLFe+5jt3LYNh7mq8SnRXYwF0kecsso35v6HaqK4CCkIn08xSeEmZZd3T9z1RhZEZUse7luKc+ON8TQ/ArtWhT/JmlrKsScMSku+j3VDKkf7GRxxR5NHGhnMXAm4vycE0gUKEMSoscqL6PKm2w34fI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766025905; c=relaxed/simple; bh=rpg9xRwqXJdoa9o/0hJC0BVwNsBbVZZp4L9qh0QLmM4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HBxMFcdtr7vIJCrpRC4FsMlO/Z14H4PtZwOPpoiiS3zQ/VvRirjme2KPsrwDevv/24bPsaXE02baGTkM+HbTSUyKMBV7EGhjU3lGmIRjm6+g9IHzDfTAHXVLoUQxYlZGQcGp+gCfFD0nAuv0F+uEAXZKWqvt5bfZJEZCZBWqKz0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=NladGGCv; arc=none smtp.client-ip=209.85.214.228 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="NladGGCv" Received: by mail-pl1-f228.google.com with SMTP id d9443c01a7336-29efc031eddso435505ad.3 for ; Wed, 17 Dec 2025 18:45:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1766025903; x=1766630703; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BMOc2yXwMWNwizXE4LJ3r+8jQkSXD2ri2LLDuLQglmM=; b=NladGGCvz9hx3HUKT+udV9PoXHncEEwwjBmd/DWBBV9fYZY+O+pcyYoGqTAuh84ROt LNy1i5az+fCWRHewJhgSYFZhf08hjq39a40ZFcdjkpcoX994S+O1qjrHufUVbCJDR5S/ EWVt1Dseu5QY/q2fohWSrovOoT8jmw+vtB+h1o3RTFPiQT8nl2aZuN6K5jodTaXBSWV5 hV4M37nooP+kEvC5OcifI+/L/h0xb4XRaR5HRfD9E6Y8FWPDv77CQmV3MUTccl2UO2c3 lzm4un4uf31DvgWcbp5TTUzA+3nIfW0v7UKkOHDWa+IF2Lji545HPf8GnUC4K4CvH+ct zQIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766025903; x=1766630703; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BMOc2yXwMWNwizXE4LJ3r+8jQkSXD2ri2LLDuLQglmM=; b=go/Zb6O1F21DaTKJwbHw0DyxX7Wm7Ef+Vrk23a1shyyA9tdgp761y7vQCopg4Rty9S Dfgq5kixnDtrHh4iHzo9u96ccznX32jbOuX22HJ6aqcftsDGRsLbrkCsKpxcHDe3errc B4bAcvf2wEf7c4/lReq7Xo3VFZ6176Q+YyLEJ4ifAW30w7aR8VjtQsUoyVLNaFD2fB67 jjFXM4FTzIxMwduwB+etblr/D41aXkFb+YtFiNwOpwlBFaotmV5FdovoQkKxuDJt4KQF Z+4zbSxzNkYBfoZCCcE6HC9cxX0XFAcMXAoZjccJkDJYOak6mv4onK8eYUKKTGIKv5g2 W+Bg== X-Forwarded-Encrypted: i=1; AJvYcCUKlE8ejixPuW6+x/4QdRw0XCXEaGGzi1zMKVOSxY/Uu+JS3oeMFRB53kdkgzOVLfyWGqsaxLN6+DHkp+U=@vger.kernel.org X-Gm-Message-State: AOJu0YzismGvS1EZkwAPkfhoAKiYPZdoMehji5u/uE1sivGoRv3/Ujzz RCA5o+tJY6X1sB4urFtJ376VvZBGv4QGxbTKS0RYLjrg6lLVS3zXC7dzENuQ7Var/Eurnt+VKUm QYpUCKDahXBGXdOnKWtrKAnWJTZkzPRI/Qhn2QoajXMr1CLTBrRFK X-Gm-Gg: AY/fxX4Nien5/tGv9YBLr+ljp6BuzRc9KdqFn/rbCG/XGT29aQn1NT2Thn4KGywh+iQ qM0UkctOde3kHkLeL6G8TpdYBc/hkH3xz1GE+1N6PFKHXL8n7q+FYecqHaufHD44uAi8PjIGsie 6z9BVyMqWJul2wZMYSn6uH+3ORsgRwlr/e/d9eFGjNRNecQRMo4IV/yvTAwkIt6c4S+rdxbMT96 4tuNSkijRO2myUfTRzuEjZTZbPnpq+RqnEk3ece8CS9/yB8IT0iZe+oDkyck4GQHbmPPiURjTKu CMPzeY8YCTWv7QdgWXGR+esVe9/YV0WYzWUpst5vmntNETGeCXAaMfLzX1EW5l3pjQ0zcJe5rIk BEF/upscWzCQwtO4DLb0Hzh9YoTY= X-Google-Smtp-Source: AGHT+IFH+pl8jKSdmMofH8xpbY+iOFdJxlVTeWYz56gwdoc2mTCaFO5HLwh1g+k03mnsyYLRY4FHfibrTnS6 X-Received: by 2002:a17:902:f647:b0:29f:2df2:cf49 with SMTP id d9443c01a7336-2a2d4516c82mr6470925ad.5.1766025902885; Wed, 17 Dec 2025 18:45:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id d9443c01a7336-2a2d13e9e91sm1610865ad.46.2025.12.17.18.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 18:45:02 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (unknown [IPv6:2620:125:9007:640:ffff::1199]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id 3203334023F; Wed, 17 Dec 2025 19:45:02 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 2DBE7E41A13; Wed, 17 Dec 2025 19:45:02 -0700 (MST) From: Caleb Sander Mateos To: Jens Axboe , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Joanne Koong , Caleb Sander Mateos Subject: [PATCH v6 1/6] io_uring: use release-acquire ordering for IORING_SETUP_R_DISABLED Date: Wed, 17 Dec 2025 19:44:54 -0700 Message-ID: <20251218024459.1083572-2-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20251218024459.1083572-1-csander@purestorage.com> References: <20251218024459.1083572-1-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" io_uring_enter() and io_msg_ring() read ctx->flags and ctx->submitter_task without holding the ctx's uring_lock. This means they may race with the assignment to ctx->submitter_task and the clearing of IORING_SETUP_R_DISABLED from ctx->flags in io_register_enable_rings(). Ensure the correct ordering of the ctx->flags and ctx->submitter_task memory accesses by storing to ctx->flags using release ordering and loading it using acquire ordering. Signed-off-by: Caleb Sander Mateos Fixes: 4add705e4eeb ("io_uring: remove io_register_submitter") Reviewed-by: Joanne Koong --- io_uring/io_uring.c | 2 +- io_uring/msg_ring.c | 4 ++-- io_uring/register.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 6cb24cdf8e68..761b9612c5b6 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3249,11 +3249,11 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u= 32, to_submit, goto out; } =20 ctx =3D file->private_data; ret =3D -EBADFD; - if (unlikely(ctx->flags & IORING_SETUP_R_DISABLED)) + if (unlikely(smp_load_acquire(&ctx->flags) & IORING_SETUP_R_DISABLED)) goto out; =20 /* * For SQ polling, the thread will do all submissions and completions. * Just return the requested submit count, and wake the thread if diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c index 7063ea7964e7..c48588e06bfb 100644 --- a/io_uring/msg_ring.c +++ b/io_uring/msg_ring.c @@ -123,11 +123,11 @@ static int __io_msg_ring_data(struct io_ring_ctx *tar= get_ctx, =20 if (msg->src_fd || msg->flags & ~IORING_MSG_RING_FLAGS_PASS) return -EINVAL; if (!(msg->flags & IORING_MSG_RING_FLAGS_PASS) && msg->dst_fd) return -EINVAL; - if (target_ctx->flags & IORING_SETUP_R_DISABLED) + if (smp_load_acquire(&target_ctx->flags) & IORING_SETUP_R_DISABLED) return -EBADFD; =20 if (io_msg_need_remote(target_ctx)) return io_msg_data_remote(target_ctx, msg); =20 @@ -243,11 +243,11 @@ static int io_msg_send_fd(struct io_kiocb *req, unsig= ned int issue_flags) =20 if (msg->len) return -EINVAL; if (target_ctx =3D=3D ctx) return -EINVAL; - if (target_ctx->flags & IORING_SETUP_R_DISABLED) + if (smp_load_acquire(&target_ctx->flags) & IORING_SETUP_R_DISABLED) return -EBADFD; if (!msg->src_file) { int ret =3D io_msg_grab_file(req, issue_flags); if (unlikely(ret)) return ret; diff --git a/io_uring/register.c b/io_uring/register.c index 62d39b3ff317..9e473c244041 100644 --- a/io_uring/register.c +++ b/io_uring/register.c @@ -191,11 +191,11 @@ static int io_register_enable_rings(struct io_ring_ct= x *ctx) } =20 if (ctx->restrictions.registered) ctx->restricted =3D 1; =20 - ctx->flags &=3D ~IORING_SETUP_R_DISABLED; + smp_store_release(&ctx->flags, ctx->flags & ~IORING_SETUP_R_DISABLED); if (ctx->sq_data && wq_has_sleeper(&ctx->sq_data->wait)) wake_up(&ctx->sq_data->wait); return 0; } =20 --=20 2.45.2