From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from 013.lax.mailroute.net (013.lax.mailroute.net [199.89.1.16]) (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 CB7EE4508F7 for ; Mon, 11 May 2026 16:31:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778517086; cv=none; b=dQA2L3si5xKGdrU0+O3ETdcr4FAHiETRp99HAKg5hBKJTEsOcNXy1Y/IVh9H43IiAZX3QO4722gQ1QguTCAf/xf/rTJLDiLs6/67ZaCHO5+5qcsal1EV7IUJ96P0H9OjgAcTM5ruJqyxdh0oJSqAG3S0Zu27eQcs2DsD8D8X9/k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778517086; c=relaxed/simple; bh=XaJi5LE0jKsvSKyAgJO4oZYzyfUOGlFglcauLZx7Wd0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z5dKvqTv93XzfApE5gqv8SqF9d2u9QZox1rIrDyXW+5Sg9FGD7EHNkAgGSE3pMXRAuY0BQfcoQpbrvEt8MI3HY/gzfnSK/OAgOugpRH9owJOYcXvCoRXFq+Ht6Zfl4NaezbjazRlOd85+J6oXV+Wtqtc5DNBCMvnTp/BK4pfWI4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=RJlYod+B; arc=none smtp.client-ip=199.89.1.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="RJlYod+B" Received: from localhost (localhost [127.0.0.1]) by 013.lax.mailroute.net (Postfix) with ESMTP id 4gDlbc3mBpzlffvg; Mon, 11 May 2026 16:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1778517077; x=1781109078; bh=jvpCo j9sifG4EMQk16WARHRYK/ZaSZ0RFY7h39W9bGM=; b=RJlYod+B1NIi5Do7Y9yeO B9tVjR8MR3cNpg4GHSN22+sLDxMMWXfsqccVOCKK+wTb/0sPOdwXoCdBudWWIaN0 bd2mR7Veuo7qIs3/Fssx/J3nuU8kuxWaMphUigGWecN/wXL2kCs9Xhbbmswr/B1o B8j5zBmfvzKqtaRBOqy+YurTn+sF6pY0Wi1e5SiVxCgAo1PdeEwkC+poOj89G6o2 BJvo/7XJqWg/IMCrNJqDQj6bMOXU+B9gRjTcGLqjorz1rvRx5UzC6VWvcmPplMCa bxP7W3RYYqXmkTJBVoGoikmqA2/VJFCTP1u0ypGxNz4KAV4b/00OiQRVOIl2Z44S Q== X-Virus-Scanned: by MailRoute Received: from 013.lax.mailroute.net ([127.0.0.1]) by localhost (013.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id kTtWkPtRUMtU; Mon, 11 May 2026 16:31:17 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.180.219]) (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) (Authenticated sender: bvanassche@acm.org) by 013.lax.mailroute.net (Postfix) with ESMTPSA id 4gDlbR1x15zlgwNH; Mon, 11 May 2026 16:31:14 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Marco Elver , Bart Van Assche , Tejun Heo , Yu Kuai , Josef Bacik Subject: [PATCH v4 03/12] block/cgroup: Split blkg_conf_prep() Date: Mon, 11 May 2026 09:30:45 -0700 Message-ID: <20260511163100.1887263-4-bvanassche@acm.org> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog In-Reply-To: <20260511163100.1887263-1-bvanassche@acm.org> References: <20260511163100.1887263-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Move the blkg_conf_open_bdev() call out of blkg_conf_prep() to make it possible to add lock context annotations to blkg_conf_prep(). Change an if-statement in blkg_conf_open_bdev() into a WARN_ON_ONCE() call. Export blkg_conf_open_bdev() because it is called by the BFQ I/O scheduler and the BFQ I/O scheduler may be built as a kernel module. Reviewed-by: Christoph Hellwig Cc: Tejun Heo Signed-off-by: Bart Van Assche --- block/bfq-cgroup.c | 4 ++++ block/blk-cgroup.c | 18 ++++++++---------- block/blk-iocost.c | 4 ++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index ac83b0668764..38396df9dce7 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -1051,6 +1051,10 @@ static ssize_t bfq_io_set_device_weight(struct ker= nfs_open_file *of, =20 blkg_conf_init(&ctx, buf); =20 + ret =3D blkg_conf_open_bdev(&ctx); + if (ret) + goto out; + ret =3D blkg_conf_prep(blkcg, &blkcg_policy_bfq, &ctx); if (ret) goto out; diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 554c87bb4a86..a8d95d51b866 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -771,10 +771,7 @@ EXPORT_SYMBOL_GPL(blkg_conf_init); * @ctx->input and get and store the matching bdev in @ctx->bdev. @ctx->= body is * set to point past the device node prefix. * - * This function may be called multiple times on @ctx and the extra call= s become - * NOOPs. blkg_conf_prep() implicitly calls this function. Use this func= tion - * explicitly if bdev access is needed without resolving the blkcg / pol= icy part - * of @ctx->input. Returns -errno on error. + * Returns: -errno on error. */ int blkg_conf_open_bdev(struct blkg_conf_ctx *ctx) { @@ -783,8 +780,8 @@ int blkg_conf_open_bdev(struct blkg_conf_ctx *ctx) struct block_device *bdev; int key_len; =20 - if (ctx->bdev) - return 0; + if (WARN_ON_ONCE(ctx->bdev)) + return -EINVAL; =20 if (sscanf(input, "%u:%u%n", &major, &minor, &key_len) !=3D 2) return -EINVAL; @@ -813,6 +810,8 @@ int blkg_conf_open_bdev(struct blkg_conf_ctx *ctx) ctx->bdev =3D bdev; return 0; } +EXPORT_SYMBOL_GPL(blkg_conf_open_bdev); + /* * Similar to blkg_conf_open_bdev, but additionally freezes the queue, * ensures the correct locking order between freeze queue and q->rq_qos_= mutex. @@ -857,7 +856,7 @@ unsigned long __must_check blkg_conf_open_bdev_frozen= (struct blkg_conf_ctx *ctx) * following MAJ:MIN, @ctx->bdev points to the target block device and * @ctx->blkg to the blkg being configured. * - * blkg_conf_open_bdev() may be called on @ctx beforehand. On success, t= his + * blkg_conf_open_bdev() must be called on @ctx beforehand. On success, = this * function returns with queue lock held and must be followed by * blkg_conf_exit(). */ @@ -870,9 +869,8 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct = blkcg_policy *pol, struct blkcg_gq *blkg; int ret; =20 - ret =3D blkg_conf_open_bdev(ctx); - if (ret) - return ret; + if (WARN_ON_ONCE(!ctx->bdev)) + return -EINVAL; =20 disk =3D ctx->bdev->bd_disk; q =3D disk->queue; diff --git a/block/blk-iocost.c b/block/blk-iocost.c index 0cca88a366dc..b34f820dedcc 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -3140,6 +3140,10 @@ static ssize_t ioc_weight_write(struct kernfs_open= _file *of, char *buf, =20 blkg_conf_init(&ctx, buf); =20 + ret =3D blkg_conf_open_bdev(&ctx); + if (ret) + goto err; + ret =3D blkg_conf_prep(blkcg, &blkcg_policy_iocost, &ctx); if (ret) goto err;