From patchwork Tue May 21 11:48:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 13669347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4780C25B75 for ; Tue, 21 May 2024 11:49:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 411B16B00A5; Tue, 21 May 2024 07:49:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C11C6B00A6; Tue, 21 May 2024 07:49:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 288526B00A7; Tue, 21 May 2024 07:49:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 09A316B00A5 for ; Tue, 21 May 2024 07:49:18 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A7BE91A0C2C for ; Tue, 21 May 2024 11:49:17 +0000 (UTC) X-FDA: 82142232354.30.B643E4A Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf28.hostedemail.com (Postfix) with ESMTP id 9434AC0014 for ; Tue, 21 May 2024 11:49:15 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QP7xHTIr; spf=pass (imf28.hostedemail.com: domain of bjorn@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=bjorn@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716292156; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BuXuu2bnylLUwFqILrVy58O+7c/VMKIWm9IXIjW+NvY=; b=R7Bxb5XQdjDSuGQmw8aFTkJ2iPrJh3lF1mMhWSbWEAzjtuE66QYV4tsPEd8cTNFuiutLlX n9JPd925B+YNliuB+AFnqzso2PLVf2RWw4wGaQv9souC9wybkumUOq6xjsJyv3zfEyw/lE uPY4qNvxL0iyv+Wxj85QSC50SaDPHMQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QP7xHTIr; spf=pass (imf28.hostedemail.com: domain of bjorn@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=bjorn@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716292156; a=rsa-sha256; cv=none; b=dOWt8EFlAFb3WnPNVmf1Lq3nKSRc1BRUFSEJYk6UhARw5JmKwrqskwbaamQ7DRJ/7R36Vo DTk+CmejoIkz/5iu1mSDyGRo4R05gbnCGs8BfBrB4XLpFYNs0bvYJGQ33cWwRpMFG0MBkq 09bv383bQJ1uB8HVvz8MyieuuTCIUdM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 9F1EACE0FAA; Tue, 21 May 2024 11:49:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07C0EC4AF09; Tue, 21 May 2024 11:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716292151; bh=zdSV3EpJ/CKXjaWQ8/cD0+JOT+VH5rhvpIEde4YPaWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QP7xHTIroKWAL1koAwZ6jjCgJLvRHG023RGth9xuUk2aAr6xVwWVLbscARU+Pv1ub rE7DpLmED0b0CVDykMK6Zx+Q7jnCMVy2PLYf754MVZMJIdV0GVpwGIlm3I3gUCQ0Q6 2H95BXA0It8CFEHUA2Cu/eAEMYUpIeaDtiemAskbUWoLdUlQdP1W1YSYtVV7ha1mAp T00CEcLQ7pEpSb3jAdqZceJbTnCXDIJ0KCDyF2nAHBRoyXITau6AkUfMqaNoMFbKQN QACCVo7OV9T3gy3HBJuXXKgSubA2i3XC1J2EvODkvPbaXRZ/G6/pdAH3MvgRE1voV6 WqhaCAyjmm6LQ== From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: Alexandre Ghiti , Albert Ou , David Hildenbrand , Palmer Dabbelt , Paul Walmsley , linux-riscv@lists.infradead.org, Oscar Salvador Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Andrew Bresticker , Chethan Seshadri , Lorenzo Stoakes , Santosh Mamila , Sivakumar Munnangi , Sunil V L , linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtualization@lists.linux-foundation.org Subject: [PATCH v3 6/9] riscv: mm: Take memory hotplug read-lock during kernel page table dump Date: Tue, 21 May 2024 13:48:27 +0200 Message-Id: <20240521114830.841660-7-bjorn@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240521114830.841660-1-bjorn@kernel.org> References: <20240521114830.841660-1-bjorn@kernel.org> MIME-Version: 1.0 X-Stat-Signature: qcys36i1aiskw4nmj6uum7zofr9jk69j X-Rspamd-Queue-Id: 9434AC0014 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1716292155-535979 X-HE-Meta: U2FsdGVkX1+DsKdU3i/9/xxFFY0upfZnCEwKvJ0ztigKyLXTh00jatJoUjwxBj8AT+42kh4TtvMTkBYmFccec1PcOFom3uobqrxXl8g/aoq/WdMkIGE2CvYf0h6CQm4Pd2mkYGiec+x7++f+7xs5elZdSaxQg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dk9EDNGwHVtRLJCpvAtp0JuQdqQ3509RrHRqfO5xnbLkRWC01VybjKH+oDknkpMiTvxCg2Yr9BsRUNkfnjqwjUMjCWL2lvSlFW+tUw/pHQP/t8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Björn Töpel During memory hot remove, the ptdump functionality can end up touching stale data. Avoid any potential crashes (or worse), by holding the memory hotplug read-lock while traversing the page table. This change is analogous to arm64's commit bf2b59f60ee1 ("arm64/mm: Hold memory hotplug lock while walking for kernel page table dump"). Reviewed-by: David Hildenbrand Reviewed-by: Oscar Salvador Signed-off-by: Björn Töpel --- arch/riscv/mm/ptdump.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/riscv/mm/ptdump.c b/arch/riscv/mm/ptdump.c index 1289cc6d3700..9d5f657a251b 100644 --- a/arch/riscv/mm/ptdump.c +++ b/arch/riscv/mm/ptdump.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -370,7 +371,9 @@ bool ptdump_check_wx(void) static int ptdump_show(struct seq_file *m, void *v) { + get_online_mems(); ptdump_walk(m, m->private); + put_online_mems(); return 0; }