From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (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 AC97D45D921 for ; Mon, 21 Sep 2026 09:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981484; cv=none; b=Qan16o5T1VxKHsamg9ld8OoGEdqmQVGNTceqS4dB9YP98saRkwZSzAm8Qr78fpr1l39PxUi48t0YgKAk6fFAgVQpxe5NG6S+BNdLcHimEY57KzRaboWkdmP+P5L4O874sVemWJwhZNP4C7pgKF+x24qRbhOPZ5/LVeLwQs7a7a4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981484; c=relaxed/simple; bh=KhKa8DVQaDkX5yqLgcINt9w9yBbAaKqcrPXHUwXdLVs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LafTexldHhSV+3HBauIQTH0gRXwhmRE8Nx/3P7u9zs1ixn/7yiEzKooAU2dAoUJWVqvKVmo/mjcS1TyAODpyLEPDpvQvq5PQm40/smzyAjxYW4zjsdjTLc4MyqBIO0P8NPG9V0QifF/6Q4psVutZbAZNuwyZBGCcV9Tyh9C+0v4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=NLfB55gt; arc=none smtp.client-ip=113.46.200.222 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="NLfB55gt" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=7Gly1btZ/qtetqt6PZXoWzbx2dJha17PF7md6d6YHEg=; b=NLfB55gt4vcsyPjJv21R+FR/t3i0Zfpu9+ajOViW02naV5Sz3HgaYwJgkq03z4u4M068FVcuf v6HCRypcJ9fT+TroC7eKOYwp9DB7wJNdWeXuUop0ibOhPKdLIrdyTrXZnTAIan70wbc0IB+MKEM pjgvJWFJlJ9pg7owuY6S8R8= Received: from mail.maildlp.com (unknown [172.19.163.15]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4hpH7w69Z7zLlTm; Mon, 21 Sep 2026 16:53:32 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 91E6B4058E; Mon, 21 Sep 2026 17:04:34 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Mon, 21 Sep 2026 17:04:18 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v6 13/14] driver core: Add device_hotplug_lock_assert_held() helper Date: Mon, 21 Sep 2026 17:04:49 +0800 Message-ID: <20260921090450.807575-14-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260921090450.807575-1-ruanjinjie@huawei.com> References: <20260921090450.807575-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemk200008.china.huawei.com (7.202.194.74) crash_get_memory_ranges() walks memblock, which memory hotplug modifies under device_hotplug_lock. A caller that does not hold the lock can race with memblock_double_array() and iterate a freed regions array. Add device_hotplug_lock_assert_held() so that crash code can use it to catch such unsafe callers via lockdep. Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: Danilo Krummrich Signed-off-by: Jinjie Ruan --- drivers/base/core.c | 5 +++++ include/linux/device.h | 1 + 2 files changed, 6 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 4c0c373998a1..c04adc457a96 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2420,6 +2420,11 @@ void unlock_device_hotplug(void) mutex_unlock(&device_hotplug_lock); } +void device_hotplug_lock_assert_held(void) +{ + lockdep_assert_held(&device_hotplug_lock); +} + int lock_device_hotplug_sysfs(void) { if (mutex_trylock(&device_hotplug_lock)) diff --git a/include/linux/device.h b/include/linux/device.h index aee79fd6b32b..9cca8c8bd372 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1261,6 +1261,7 @@ do { \ void lock_device_hotplug(void); void unlock_device_hotplug(void); int lock_device_hotplug_sysfs(void); +void device_hotplug_lock_assert_held(void); int device_offline(struct device *dev); int device_online(struct device *dev); -- 2.34.1