From patchwork Wed Jun 5 11:40:50 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: 13686706 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 8F306C27C5F for ; Wed, 5 Jun 2024 11:41:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 10CEA6B009E; Wed, 5 Jun 2024 07:41:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BD296B00A0; Wed, 5 Jun 2024 07:41:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC7156B00A1; Wed, 5 Jun 2024 07:41:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CD68B6B009E for ; Wed, 5 Jun 2024 07:41:53 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8A237A0FD3 for ; Wed, 5 Jun 2024 11:41:53 +0000 (UTC) X-FDA: 82196645706.28.FD9C010 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf07.hostedemail.com (Postfix) with ESMTP id 871AB40008 for ; Wed, 5 Jun 2024 11:41:51 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=actIwcGK; spf=pass (imf07.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=1717587712; 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=q//qbYvUf5ZweB0+VVWPtHbCbaK2TrYguToZahahUIk=; b=DDrAkImhNkiqy+dCB8lT+rqnMrPSZVQrjluw5YF74cioe9MCQe5gr/v3HHxSbx+1pWKhT6 ZHCWPVnPbR6MXRjqK6R6WyDu+hxjrzhEzFW+QpvajuwFAU7tvZGWoN6bQX4VCG7jlF12+2 U7gV/OFQk+nVLKCo0vqOjjNXGLt41iQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717587712; a=rsa-sha256; cv=none; b=yUurc42UuzShdM0I9akMyZSE/1vfDPfFU11DM6bTmVdP1C4ome3xKnvfVJMjskAc0Hysqj EXJbpcFXqJF0emoJjM2BMF0HXvbyRHVPEkwvXWx91MHc2jZ1Fe2hb2IB7gip1xTmMkqWpu MEe3YS6yVt+ZtwYu68fjRe/2Nm0NAHU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=actIwcGK; spf=pass (imf07.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id E9ED0CE1779; Wed, 5 Jun 2024 11:41:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADA0FC32786; Wed, 5 Jun 2024 11:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717587708; bh=tu3HoOPPrk12D/HHChqAMB+6RlcJ+H95I8FoF9tFiiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=actIwcGKL7lMw7iHm/kYeLU0Im0MKA4ATYjc0eCD0iqFPQA3+RyZqVf1nydSeSUj0 gF9ZhAi8Cz89TfrWUuVf9dhYSzuUycsqYPT4dufEA7HfktKoCVWT5gVywjFH44bLxq FNTCqSW9+FkXOpJ/wxpC8P41lR4dMjOqX+wX6c6+uyD4sHqI51jkPKWdIKeosTC0K2 WSBy6vQk9sC3vPE9M08ir3qL9i3FzdGxn8iAQdWQ8EjWNitOO9u8IfVkxzec9k0tt9 kNzLKT3wBJLZ8wQiEitzX09XtnmJ30P5wj/gY3ges2Va9UAhUDJXEgw+464CKsyQPH ZFrpv32CPOuLg== 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 v4 07/11] riscv: mm: Take memory hotplug read-lock during kernel page table dump Date: Wed, 5 Jun 2024 13:40:50 +0200 Message-ID: <20240605114100.315918-8-bjorn@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605114100.315918-1-bjorn@kernel.org> References: <20240605114100.315918-1-bjorn@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: new91aj94iyaeogyr95mixf4qsuc8n4p X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 871AB40008 X-HE-Tag: 1717587711-665604 X-HE-Meta: U2FsdGVkX1/WnsXqXQP2iTI38nOTdQMAw9Oyzfu/CKS+ioh/BwKrfvHm7rlb4K3KqGRkfPmptM8SfxZd+kxthCXqaX+KqcM9TuKjW50KUzRJy5beJ1r2tEv0aR6m+J+7MuPA3IvD+kd3kU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38b9hKTAiL50VrCFyV3V6rKXPUi+NFzlSN30Gw0p+hTMFHpvO4xfz3zATA5lfzgQFxYulTUm+nuJaOoSWsZrupB/J4TfhYY7uXuSGe6UGpu+T57kvF8WCvcfs/5nyc53f3hUBQRZo9OQ7ud+fEi1w= 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; }