From nobody Thu Dec 18 12:30:10 2025 Received: from mail-ed1-f100.google.com (mail-ed1-f100.google.com [209.85.208.100]) (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 10D0D28D8ED for ; Tue, 2 Dec 2025 16:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764693692; cv=none; b=Nh0Of9xQsAO3bodLOPQRDuGSs4yZVSCqPWt3sGVMpoY0T3zuc7ajaZyAgrK/C6EBLIwugIxgSUCO9GValhTNrD8Sa7Sy5Py/RgHlm4bsgzjwNx2BXtCyjhtk/yV2hGh1AViwJxoCUjoi9b4LN8dhHEMhia0JBiSoZzcxhdo5uUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764693692; c=relaxed/simple; bh=rfcJtYpApZgZ3ggMk6Lu6xqNaGNNQRUrF0JUvpvg2v8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XNhvJvGn2/zCjDa2C4cYu/WzR/MaqFegaYaSaWCv47CQCYWzKZqEzFVW3KJSepRSEtoKC4YPXjIY13TPpQNeG6Lrr+YMzx9S73DuG3u0rbEIIJ8aD3qS38+ETL/0H/WoXks3X6Rql83WcI01uCwkzlP1zod+7gv2YhT6Fz57Z2c= 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=EFLGtCwO; arc=none smtp.client-ip=209.85.208.100 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="EFLGtCwO" Received: by mail-ed1-f100.google.com with SMTP id 4fb4d7f45d1cf-640e970598cso1146323a12.3 for ; Tue, 02 Dec 2025 08:41:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1764693689; x=1765298489; 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=9Oc38qZVe+2zts7GwGqPTlWIWW8FzVfjm2VCTYXmKJg=; b=EFLGtCwOYlWTfpFoK25Ay8QGWLEqhxP3zi9u7GthSdMBGP0QspACfqOvhmmAvDnWGI /+FtRsr3KIRAvJH2liVVO2U7BpYAk2C9d4l/APzgzVAHEcvdYnOlPLcMVSIVM5w2wF9l uCge9Q6JVyFKErKpg/1dia4f10GMzuGuPlb/R40pNZQBYU+lzOkJvfLUeJmzmXQMTE8J BsCYfQxLMnWKa+KQBxriGGE6+GibAOh7MopAMG5WX3pmTf5TBPJdCkjTaG6zstJXaxTU Fxf0VHgaQZLOEyhF1pVVcDjjyJw/2JoxjijDpr569Bo6uvKLR4EJuo6IQXztJi4CIHX0 vDsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764693689; x=1765298489; 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=9Oc38qZVe+2zts7GwGqPTlWIWW8FzVfjm2VCTYXmKJg=; b=mcaH2I1iZ3iMKaVtG9wNkgGwFIQ0eCLt+GJ7yb3cmuQOu9Q30H61kgF3s1E9+egS7U Efcu6T+dWK9RQ41dsk/g5cAHTL5hs0ENatpZM++vfpE6eamWOT4+2ziVeeyjwMEiu9Er C/rUmoNJfJQp6yc95I5CBcflXTrifsP5vpJNz2qKioNzYdKsSISGSDRj1U56Gv48j3Uo zzyzn18Pz26CbHfhl0dNeX238x1YbSy4i+7Vxfq/odrNRSXFO/V8x0qLIhmjALYV5y7l kX5a4wlYtNI7KebGz1SWyeX7pWHE6K7auvKeqtlN0KaUHs8Lu7X0/Pjp8hQToHjRy9cZ DFvw== X-Forwarded-Encrypted: i=1; AJvYcCXLUxdV7Q2rSXeDMdESnApO1VxYPl431/Lhh4Nao7pGtiMVbzvJUqfZA6k0Nh1RgsuQgtM6CwhM4gU6jfk=@vger.kernel.org X-Gm-Message-State: AOJu0YyZ1DkUOlbuBpZvEgARE7EAEeklCPaFU1wZr46J+LZ+8YwHHXfi /kR9aUKwaVeIwptms0CaApbkusKmiDP2xWemQyIiDwcGZH81MlYOkySf6Zj28GtYe6o/KlKmCwc LtU0Jf9TublU1snS6U0TcapicNLGCkMg/aZwM X-Gm-Gg: ASbGncsWzTAceONL+7d/ah+16BdVKIIK3sL8TK6xEcDbStixmJHJ1I3yZY5GLH+eSPc Q/lSRASR2HdHdTlbAYwOuVblItO4BlyDAxHKpCY+buZofZs7V6DrHTvDjPNbnaLSyUJP0a/BzmS DLTKbprZmPmQx2WTdxbEfObhSAjohPTKKCAyG7x6KnTIMu8P0cMNCfjxWxV5cmlbPSSbBlKbLgj zlgtWZ878Nwf3FZiGDNo+96JAQPmXeFZ52J+de/wp3XkDUfv7kv48FfM9s6b/YMD6GZaMXwaWsa jMuCCxgvb+RiabR++XN3AW3b5WNvTYu0F0unWUF6R5YM3BlIwrJZI9eluqNeS3yxRJhoW5X3HO7 or2S9oEN1vgASi7WoIlCr+sXOU8Acc2yeiQCopEHNbA== X-Google-Smtp-Source: AGHT+IGvPqXs6ksMogVRx2uhOVrpAHsXcVLaUdtkGKSKHzyRU55KnHDWuiHPOuOdg2Dlo4Qr1d/rdUj4hn7B X-Received: by 2002:a05:6402:2112:b0:643:130c:eb1 with SMTP id 4fb4d7f45d1cf-64559f58067mr20447502a12.1.1764693689271; Tue, 02 Dec 2025 08:41:29 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id a640c23a62f3a-b76f51c8e1bsm235442366b.42.2025.12.02.08.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Dec 2025 08:41:29 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.7.70.37]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id EA5F03402AD; Tue, 2 Dec 2025 09:41:27 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id E9C22E41DB4; Tue, 2 Dec 2025 09:41:27 -0700 (MST) From: Caleb Sander Mateos To: Jens Axboe Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH v4 1/5] io_uring: use release-acquire ordering for IORING_SETUP_R_DISABLED Date: Tue, 2 Dec 2025 09:41:17 -0700 Message-ID: <20251202164121.3612929-2-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20251202164121.3612929-1-csander@purestorage.com> References: <20251202164121.3612929-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: 7e84e1c7566a ("io_uring: allow disabling rings during the creation") 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 1e58fc1d5667..e32eb63e3cf2 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3244,11 +3244,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