From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388003; b=nxau9kC8HTLPJwMWWzqG8Y0Stv04N0XgV4ndxjY91bmrgcCbZkEO/M3fx4GZH8IXZtnv 5Fz7O6hDKuJHXTsMhvRMpOtlUSmCXF5CXFJ/TkXQTWM7jWFAGLN9/3KtjJhsJqtH6zywZ nIhGE/sCjA6fauYTur8ru9ttIF09OKAI8IVcQY66Z4XCK8V4seXaiwoWXR2kpRKH/poZG Lq3UiJSmDStWINuujwu/DixMP47W6WUNBqybkdLoPfJg5FgaFYctJ81725bG3AFJNRAcn 5nBf0MtNDmY4NEmcY+vSBLey9tTbGtkdX7O1QVsBqwW4h5RfzbV6fNUm3QZm1Ssk9mw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388003; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=xnqZD5sAX/p2qGSWHD3p1zLRl6ZrWQj4Nomes6Ohbyk=; b=m5w00PoijPdPV12BeLobqjJBNphJVVDwdNrMqlQaRtp6ZYsxC4yXTAVloT90s72Dz3vQ 2SO2mchUEEChNp10P/5T75bUasZhGpv0Wp7yZuvLXhJypjwrD9fxi4nEnReSQwhYjTdn6 brpPQAMA+MkqLeZGg3WdGDKNrzPnhA7SNXzSUjh8o7T5l0hjao0VEhK7wQs16Ixnhj6C+ BadC9TcLq2QWmJ8+RnmQiBK6rZYErMEwwP6q7y+qemc8xN+f7cjY2fAkOA9Gh9oozcO9I trlZOF2sBIv56gi9xp0r8r+L6RUWayXSOzajfnCFFfKiobX6/qU4YB4615ZUIEjzydg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=lSV4rTiU; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB551606A332; Fri, 4 Dec 2026 12:40:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=lSV4rTiU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C1341F00897; Fri, 4 Dec 2026 12:40:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388003; bh=xnqZD5sAX/p2qGSWHD3p1zLRl6ZrWQj4Nomes6Ohbyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lSV4rTiUQvM0uU2dcYeHK46ydOUCA3gZlWIfGQMIaq9hQNvp1L7C7LrxH1IHiLjuJ 4OkXER+sCXlbB1+pGFPa5aWQzTT44hrOiPq7rwm+v2KoLjGcw8CWw6h6SYHOKSl+xy q4b+dt7Z3PeucwIfM1reMs3verLlkmuMx4uXB1qE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tejun Heo , Josef Bacik , Jens Axboe , Sasha Levin Subject: [PATCH 6.1 0445/1059] blk-cgroup: dont free a blkg with its punt work queued Date: Fri, 4 Dec 2026 18:59:36 +0900 Message-ID: <20261204100655.832498531@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit 4def096314cf29fb6940b74c087a0b923185580e ] blkg_async_bio_workfn() relies on the bios on the list pinning the blkg. But blkcg_punt_bio_submit() can call queue_work() after a running instance already took and completed the bio, and queue_work() succeeds on an empty list for the same reason. Nothing holds the blkg then, and free_work shares its memory with async_bio_work on top of that. Hold a reference across blkcg_punt_bio_submit(), give the two works memory of their own, and cancel async_bio_work in blkg_free_workfn(). Fixes: d3f77dfdc718 ("blkcg: implement REQ_CGROUP_PUNT") Cc: Tejun Heo Signed-off-by: Josef Bacik Acked-by: Tejun Heo Link: https://patch.msgid.link/20261028164415.1262013-20-axboe@kernel.dk Signed-off-by: Jens Axboe [ sashal: Moved INIT_WORK of async_bio_work earlier in blkg_alloc() so early-failure frees don't cancel an uninitialized work, and dropped upstream's CONFIG_BLK_CGROUP_PUNT_BIO guards and adapted to the older punt helper layout. ] Signed-off-by: Sasha Levin --- block/blk-cgroup.c | 14 ++++++++++++-- block/blk-cgroup.h | 6 ++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index b65aaf585f04d..2ba82bd2dd422 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -90,6 +90,9 @@ static void blkg_free_workfn(struct work_struct *work) free_work); int i; + /* It may have been queued for bios which an earlier run has taken */ + cancel_work_sync(&blkg->async_bio_work); + for (i = 0; i < BLKCG_MAX_POLS; i++) if (blkg->pd[i]) blkcg_policy[i]->pd_free_fn(blkg->pd[i]); @@ -157,7 +160,7 @@ static void blkg_async_bio_workfn(struct work_struct *work) struct blk_plug plug; bool need_plug = false; - /* as long as there are pending bios, @blkg can't go away */ + /* blkg_free_workfn() waits for us */ spin_lock_bh(&blkg->async_bio_lock); bio_list_merge(&bios, &blkg->async_bios); bio_list_init(&blkg->async_bios); @@ -220,6 +223,8 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk, if (!blkg) return NULL; + INIT_WORK(&blkg->async_bio_work, blkg_async_bio_workfn); + if (percpu_ref_init(&blkg->refcnt, blkg_release, 0, gfp_mask)) goto err_free; @@ -234,7 +239,6 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk, INIT_LIST_HEAD(&blkg->q_node); spin_lock_init(&blkg->async_bio_lock); bio_list_init(&blkg->async_bios); - INIT_WORK(&blkg->async_bio_work, blkg_async_bio_workfn); blkg->blkcg = blkcg; u64_stats_init(&blkg->iostat.sync); @@ -1683,11 +1687,17 @@ bool __blkcg_punt_bio_submit(struct bio *bio) if (!blkg->parent) return false; + /* + * Once it is on the list, a run which is under way can submit + * @bio, and its reference goes when it completes. + */ + blkg_get(blkg); spin_lock_bh(&blkg->async_bio_lock); bio_list_add(&blkg->async_bios, bio); spin_unlock_bh(&blkg->async_bio_lock); queue_work(blkcg_punt_bio_wq, &blkg->async_bio_work); + blkg_put(blkg); return true; } diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h index 840deb32746c1..4619aef1bc6f5 100644 --- a/block/blk-cgroup.h +++ b/block/blk-cgroup.h @@ -71,10 +71,8 @@ struct blkcg_gq { spinlock_t async_bio_lock; struct bio_list async_bios; - union { - struct work_struct async_bio_work; - struct work_struct free_work; - }; + struct work_struct async_bio_work; + struct work_struct free_work; atomic_t use_delay; atomic64_t delay_nsec; -- 2.53.0