From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 080CC22759C for ; Fri, 28 Nov 2025 07:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764314153; cv=none; b=ZolfsTmsRSFggizHzrAjOCtviLpB1TRljztzFpA2VtdLbWYW+gA9nduWrDtN5wib/bE3w5QZeIGuYcBCtCACML2ToBSFOTXi/Kw7/Ohj1YtFXlNDHsiIZbokmK+h6mPERQ4vvBN0dRJdH9rXrvOGzzqAthKB4QCGUU3z0b/kzoM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764314153; c=relaxed/simple; bh=wKEqwnVvAjTuD58sCNEfG6P5K37GceFiyc4OS+2MfWs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=vGXtsbNxK4QQRlaKzrlH3vq318tdCokLvE4hwF2wWUoVsEDfWajL2C//C3TZUi4Vhssl1lkiY7vcr21Ug7tnLxhycnitzGwyqQxwcMZ4k5tArxPvDUYYXZ9TXM3iLFd0HjalEZyeuZZTxLt5q87cBAc/8Q+NBvHflQHEc4KboD8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=UJKda//Q; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="UJKda//Q" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5ARExkbk007523; Fri, 28 Nov 2025 07:15:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=aQuGMB 15sa7zTV9Lz8ovy0Upi60RVwumi/i7z8UIWN8=; b=UJKda//QfEbFhtFnsdWQas Dj4DTAigQomYeeY4VtCfkRDUXw4NG9rjHA39DjFQ/UwRlHt68aax5xYH3kXgJOF8 Z8org8gwhZJje+k6/YXTXQ4FrK77UVWl1MbjeowIInB0HynykWFV+6W11mBTWTT7 KkY9UP1Ef+CpeMAncKcPH4OtwMBrrXzq3AYqZIdrD119JZIgPJG6pzTfsikwBTk1 9SwAxS8oAYnf6PDMMrKjAFWTNbswCgdPG5Kne0mDmP39DlAGH03quXjRZY1XSdvH pcfHryfyHVia9vdYQ1L3z9V6KNE3ZqumKcGTn4kIN8IJ/mZvfcUhT7NH87tOe14A == Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4ak2kqbpxv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Nov 2025 07:15:26 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 5AS30KbM027384; Fri, 28 Nov 2025 07:15:25 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([172.16.1.69]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4anq4hcmy8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Nov 2025 07:15:25 +0000 Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5AS7FOIR11797098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Nov 2025 07:15:24 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9A7E758069; Fri, 28 Nov 2025 07:15:24 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 397E258065; Fri, 28 Nov 2025 07:15:21 +0000 (GMT) Received: from [9.61.122.162] (unknown [9.61.122.162]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 28 Nov 2025 07:15:20 +0000 (GMT) Message-ID: <8ad23abf-b5d2-4a16-a8bd-28df4ab6823f@linux.ibm.com> Date: Fri, 28 Nov 2025 12:45:19 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: CVE-2025-40146: blk-mq: fix potential deadlock while nr_requests grown To: yangerkun , Zheng Qixing , Greg KH Cc: cve@kernel.org, linux-kernel@vger.kernel.org, yukuai@fnnas.com, ming.lei@redhat.com, "zhangyi (F)" , Hou Tao References: <2025111256-CVE-2025-40146-b919@gregkh> <15fb6eed-e107-4ef7-a569-3328a02e2c39@huaweicloud.com> <2025112730-semicolon-verse-164a@gregkh> <82df4ae1-2940-4214-b46e-a2f8242b3582@huaweicloud.com> <813a7d60-6211-4048-9267-ec4bd4a75f73@linux.ibm.com> <9ef3f966-c9bc-2da0-3fbf-a926eee740c9@huawei.com> Content-Language: en-US From: Nilay Shroff In-Reply-To: <9ef3f966-c9bc-2da0-3fbf-a926eee740c9@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTIyMDAwMCBTYWx0ZWRfX6YUS0viClt7j 9sW26jEnFcNeLIqF7kWhXzhWnevLHhh6AfonadU2+gLGivvnt5fF85KblTaXVO9G0GFmpDBG+/d PwBbO3r09mLK3GFS/5gmJ5a2uVPBMcCbkRnrC136I5aqClbf+iP+cWjvN2g/zm2fJKlKIJz/BpV v7E4+v5yZZXkBQeFEVohx5BOYs1K5XvkZEqXfd9PudcBVFYphchoz4p9JBjONWc+CpjaUeynLqM Max5r7TcMKhyteFpoNj4sbDhzFWRdQZGxeWodkVBsH9zLZYWjwxyMeUwUeCPiD7On6ZhDRB3Awp N3DYdQLln9LXute9KuIJgbKKCc6B0VPEmocx3A8OxjcZy22O7Dl8kliQBxXfZFg0jojfUtylT9x Ruc034k/qITHp+DuaOFhw9owrEiWEg== X-Authority-Analysis: v=2.4 cv=fJM0HJae c=1 sm=1 tr=0 ts=69294c0e cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=IkcTkHD0fZMA:10 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=i0EeH86SAAAA:8 a=hMiKrdLIgRPmp82vyjcA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-GUID: uzbtRxTCrFFhCv9DgV5eBV2q-dZtlNyI X-Proofpoint-ORIG-GUID: uzbtRxTCrFFhCv9DgV5eBV2q-dZtlNyI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-25_02,2025-11-27_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2510240000 definitions=main-2511220000 > > commit b86433721f46d934940528f28d49c1dedb690df1 (HEAD -> master) > Author: Yu Kuai > Date:   Wed Sep 10 16:04:43 2025 +0800 > >     blk-mq: fix potential deadlock while nr_requests grown > >     Allocate and free sched_tags while queue is freezed can deadlock[1], >     this is a long term problem, hence allocate memory before freezing >     queue and free memory after queue is unfreezed. > >     [1] https://lore.kernel.org/all/0659ea8d-a463-47c8-9180-43c719e106eb@linux.ibm.com/ >     Fixes: e3a2b3f931f5 ("blk-mq: allow changing of queue depth through sysfs") > >     Signed-off-by: Yu Kuai >     Reviewed-by: Nilay Shroff >     Signed-off-by: Jens Axboe > > We are assume that what's the problem Yu describe is when we update > nr_request, we may need some memory allocation(nr_requests grows). And > the memory allocation may trigger some memory reclaim, and fall into > another I/O process, and since the request_queue has been freezen, there > exist deadlock. > > But after checking the source code, there exist > queue_requests_store->blk_mq_freeze_queue->memalloc_noio_save, the > whole process which may trigger memory allocation won't trigger I/O > process. So deadlock can not happened... And if that's true, this patch > does not fix any problem. > Yes, memalloc_noio_save() is invoked before we freeze the queue (e.g., in elv_iosched_store()), but that does not prevent the deadlock scenario described in the lockdep splat. If you look closely at the splat, the problematic lock is not fs_reclaim (which may be the first impression), but rather ->pcpu_alloc_mutex. From the splat, the chain of dependencies looks like this: thread #0: blocked on q->elevator_lock thread #1: blocked on ->pcpu_alloc_mutex thread #2: blocked on fs-reclaim Here is the key detail: Thread #0 is running under GFP_NOIO scope (due to memalloc_noio_save()). However, it is not blocked on fs_reclaim. Instead, it is blocked on ->elevator_lock. Thread #1 is also running with GFP_NOIO and holds ->elevator_lock while the queue is frozen. It is blocked on ->pcpu_alloc_mutex, which is already held by Thread #2 (the thread that is stuck in fs_reclaim). Thread #2 is running without GFP_NOIO scope. In other words: - GFP_NOIO prevents a thread from entering fs_reclaim, but it does not prevent triggering per-CPU memory allocations, which require taking ->pcpu_alloc_mutex. - This ->pcpu_alloc_mutex is the actual source of contention in the splat, and it sits outside the protections offered by GFP_NOIO. That means: - Even though memalloc_noio_save() avoids fs reclaim recursion, it does not prevent per-CPU allocations from blocking, and thus it cannot prevent the deadlock involving ->pcpu_alloc_mutex. So the reasoning that “memalloc_noio_save() prevents deadlock” is incomplete — GFP_NOIO only handles reclaim, not per-CPU allocations. This is why the patch is still needed: GFP_NOIO scope with freezing the queue and modifying scheduler tags can still lead to a circular dependency involving ->pcpu_alloc_mutex, which the splat clearly shows. If you look at the reasoning described in commit f5a6604f7a44 (“block: fix lockdep warning caused by lock dependency in elv_iosched_store”) and commit 04225d13aef1 (“block: fix potential deadlock while running nr_hw_queue update”), both explicitly explain that the goal is to break the dependency chain between the percpu allocator lock and the elevator lock. The third commit, b86433721f46 (“blk-mq: fix potential deadlock while nr_requests grown”), is less explicit in its explanation, but it addresses the same underlying issue. Taken together, all these commits resolve the deadlock described in the lockdep splat. Thanks, --Nilay