From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7A86230BB99; Mon, 13 Oct 2025 15:22:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760368944; cv=none; b=FSdPmAvxrfXLnHDDBG14ZYhTW1ybkbHeVoiGJ0BG9QceMtHAH4yh5mc2bIMSW8PHxWJ+i1Nj5WVEigl9alQvwxm0LrD8u6g/Kbrkxs4L99/Te57YDAQE6+K7H+YqUr9S5b/SdMDBfmLgJBYKTxq12skB5kawo0AavINzUkfME5Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760368944; c=relaxed/simple; bh=Hs19ZHW0Kh884IcLn5PahzpkiRdx4STMCuYkO9VzQdg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=khVNzds4Iv2ZIuXPKXRCd6m9Z4PR+6Q8thBZydvKpzvw2zbNkPh7zNKrQf0IN0A9Mg+hyi7a+nQcew7/iVEsDWJiQ1Q6v6k7J4gB/WLw8CpOcRXAKdKFFAyBHNQIXtYmD2ddRuXbzPe4CvZb38p+tK0C0Fn8+Vc3jbxaMeUrKAI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Z1FvYjq+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Z1FvYjq+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0719EC4CEE7; Mon, 13 Oct 2025 15:22:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1760368944; bh=Hs19ZHW0Kh884IcLn5PahzpkiRdx4STMCuYkO9VzQdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z1FvYjq+P1ZhIi64wiuSEnQQciEre8YUTE2Hou9F+GobtmZPMIOAdSvHP1z+zFNTH fz4wx0DhHvx3Byx3L5sAlAv6WcVsxwEYWq/oLIdnI9AoYljXzHVIPpHpL48Y9YGxt+ iiKJFcgfyesRSO+mcgymbmGEnsd1DDkPL/f2lewU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Li Nan , Yu Kuai , Jens Axboe , Sasha Levin Subject: [PATCH 6.17 073/563] blk-mq: check kobject state_in_sysfs before deleting in blk_mq_unregister_hctx Date: Mon, 13 Oct 2025 16:38:54 +0200 Message-ID: <20251013144413.938075785@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251013144411.274874080@linuxfoundation.org> References: <20251013144411.274874080@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Li Nan [ Upstream commit 4c7ef92f6d4d08a27d676e4c348f4e2922cab3ed ] In __blk_mq_update_nr_hw_queues() the return value of blk_mq_sysfs_register_hctxs() is not checked. If sysfs creation for hctx fails, later changing the number of hw_queues or removing disk will trigger the following warning: kernfs: can not remove 'nr_tags', no directory WARNING: CPU: 2 PID: 637 at fs/kernfs/dir.c:1707 kernfs_remove_by_name_ns+0x13f/0x160 Call Trace: remove_files.isra.1+0x38/0xb0 sysfs_remove_group+0x4d/0x100 sysfs_remove_groups+0x31/0x60 __kobject_del+0x23/0xf0 kobject_del+0x17/0x40 blk_mq_unregister_hctx+0x5d/0x80 blk_mq_sysfs_unregister_hctxs+0x94/0xd0 blk_mq_update_nr_hw_queues+0x124/0x760 nullb_update_nr_hw_queues+0x71/0xf0 [null_blk] nullb_device_submit_queues_store+0x92/0x120 [null_blk] kobjct_del() was called unconditionally even if sysfs creation failed. Fix it by checkig the kobject creation statusbefore deleting it. Fixes: 477e19dedc9d ("blk-mq: adjust debugfs and sysfs register when updating nr_hw_queues") Signed-off-by: Li Nan Reviewed-by: Yu Kuai Link: https://lore.kernel.org/r/20250826084854.1030545-1-linan666@huaweicloud.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-mq-sysfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c index 24656980f4431..5c399ac562eae 100644 --- a/block/blk-mq-sysfs.c +++ b/block/blk-mq-sysfs.c @@ -150,9 +150,11 @@ static void blk_mq_unregister_hctx(struct blk_mq_hw_ctx *hctx) return; hctx_for_each_ctx(hctx, ctx, i) - kobject_del(&ctx->kobj); + if (ctx->kobj.state_in_sysfs) + kobject_del(&ctx->kobj); - kobject_del(&hctx->kobj); + if (hctx->kobj.state_in_sysfs) + kobject_del(&hctx->kobj); } static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx) -- 2.51.0