From patchwork Tue Sep 12 14:16:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13381812 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD478CA0EEE for ; Tue, 12 Sep 2023 14:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=V0gefxvpGV7cBH8gmSNzcv5smaCT0qdJ7dL0Nqy0KAo=; b=RGAOHTibJhS9Rn0R3SsxLCXcFG JsE6DUNET2DUiTupNbn4ZueO50Utad3C0w3k1xr4JCbABK92C6TUKBPxv6zsfVSWj3oViKLJ9zQQg 7RF/8RWCP77ow6NQUMiTM4v2MAHG6CPmGuv2TnzqIbB14kkzQ3+9Xf5gtNCHQeVwMgnRPDLZSKAap wQbo3RFV5ibgTlCKjA5spb2tjUw0OvU93Ks5LgAKpMSk0Nmr3jAi1ML9ZeAHavIacBU8WdBLCo+E/ ZilfByS8nNtdzktlEAsooJaSc41viqLdRPNWqFzIv0FG0aaMCM2ngLp0e19JUnntQOdUsGiJE2ZiQ PzWjwbjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qg4G4-003YeI-0Q; Tue, 12 Sep 2023 14:20:52 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qg4Em-003XXM-0L for linux-arm-kernel@lists.infradead.org; Tue, 12 Sep 2023 14:19:37 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-3fef3606d8cso45683305e9.1 for ; Tue, 12 Sep 2023 07:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694528369; x=1695133169; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TxbbU4Z6eJ4YLBJfIy3zQLsxMkxV5tTXMRWNfipLzKA=; b=TGfZA+oBsqS1s82hw+YQMFkHHhqzwvDUMiaik1kPx2PJ+Zc8kmPUzpu9U0l+yYy/9V biCsxD+/ZXD3utoJmWKr49IzzkWQpMa+7rUGxZYaaHeVGax/6GLjmKyk4TXWaxwkHIqZ BrBuqpBo1IfYUak0/PUn8jDtVEWktP4KLG7TnE64ACbViWkMhy0YckuP6RwVmbeVWiIB +r+7ZstDrQcREf87OcxhbQryOxVw4Yxfp1WYySJ/olVueRgaYZtJADRZm5+XfPvxA7to /AoyQrl+x5DxnSj8JzcUN/4XaneAzhztzrHNKgGbB2in+azhxB9Q7Esc5/00EG2nVMv4 8PBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694528369; x=1695133169; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TxbbU4Z6eJ4YLBJfIy3zQLsxMkxV5tTXMRWNfipLzKA=; b=gA7LpEH0qhQtuWrEDp6ce0JZYT4TD+RNpCg7WylkJHH2RyYhUwu9JwI5Gi2eky/Vo9 l4PzSdCc8QfuPjMf/TEmcgJVVcfjbjbn9DwTDb+KZzJ6ePM4mcm6IKv5xX7NkHna+IQI O0lz7sfkVzxc89PhQMGqX/vXxoUl7ANCc0bLNfDi3jAgc3A/4cJPyRqyDS8h8XAK5Uyj s5Cjo/YjPmjls5Z+ElbddbLXDxVX8AnzBa8yTx/ByH86ZWAIQ+nFWnhWvpXvlGjnRXS5 vlfgZqQsYxTHc/1kzfl0MxWYn1+Mon9kEBfcGqE15tT6kprNtc2IkXSt1f0+X3NdLZWz DfzA== X-Gm-Message-State: AOJu0YzdbzxcwCmNo9VuMpkZkHRSbuRAaahHNg7xiWPlz+FK9nKhHo7+ SawNPkN6Xaj7hREH0k/mVZhPvdeNtIEETRpcZ5ptUR6R1ldBSyAjoUemgadBjdyPwl76xs1zqai mnHOPRgRWkp4cWyQN/Td+H/3TTaeFEpvYk9h3qOKYacxvSSy/JESzx8ikEnS/afVIrxRNasTQOa Q= X-Google-Smtp-Source: AGHT+IG9H3wn+iYKHzXnTZYY6brjkst5R8QfMGgUC3ZNwScPGFpu66RqMLmgPvOzzkdlAQGE/sJ8TxNp X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:adf:f14f:0:b0:31a:dba9:ecfc with SMTP id y15-20020adff14f000000b0031adba9ecfcmr147249wro.8.1694528369122; Tue, 12 Sep 2023 07:19:29 -0700 (PDT) Date: Tue, 12 Sep 2023 14:16:45 +0000 In-Reply-To: <20230912141549.278777-63-ardb@google.com> Mime-Version: 1.0 References: <20230912141549.278777-63-ardb@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2891; i=ardb@kernel.org; h=from:subject; bh=EE9jwvVf5uskpfPL1qIEu4mvnVMM7BKPb1nRXoijhic=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIZWh6ALvjl2bX99J5jNQf+C5ma1rRf7bNN0sns13fR7OM nkix3C5o5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAExk7h+G/3HTRAzeZaozMxpY xR5ufibfKbJIYY2vRHZZbJz709RP0xn+Oz9g8PuRJup/9dKNTQYnwi/NsP55dOrDX9rsP1JWTn1 uygwA X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230912141549.278777-118-ardb@google.com> Subject: [PATCH v4 55/61] arm64: ptdump: Deal with translation levels folded at runtime From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook , Joey Gouly X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230912_071932_164234_1ADF105F X-CRM114-Status: GOOD ( 20.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ard Biesheuvel Currently, the ptdump code deals with folded PMD or PUD levels at build time, by omitting those levels when invoking note_page. IOW, note_page() is never invoked with level == 1 if P4Ds are folded in the build configuration. With the introduction of LPA2 support, we will defer some of these folding decisions to runtime, so let's take care of this by overriding the 'level' argument when this condition triggers. Substituting the PUD or PMD strings for "PGD" when the level in question is folded at build time is no longer necessary, and so the conditional expressions can be simplified. This also makes the indirection of the 'name' field unnecessary, so change that into a char[] array, and make the whole thing __ro_after_init. Note that the mm_p?d_folded() functions currently ignore their mm pointer arguments, but let's wire them up correctly anyway. Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/ptdump.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 221baaf521fa..53925aa31051 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -48,6 +48,7 @@ struct pg_state { struct ptdump_state ptdump; struct seq_file *seq; const struct addr_marker *marker; + const struct mm_struct *mm; unsigned long start_address; int level; u64 current_prot; @@ -144,12 +145,12 @@ static const struct prot_bits pte_bits[] = { struct pg_level { const struct prot_bits *bits; - const char *name; - size_t num; + char name[4]; + int num; u64 mask; }; -static struct pg_level pg_level[] = { +static struct pg_level pg_level[] __ro_after_init = { { /* pgd */ .name = "PGD", .bits = pte_bits, @@ -159,11 +160,11 @@ static struct pg_level pg_level[] = { .bits = pte_bits, .num = ARRAY_SIZE(pte_bits), }, { /* pud */ - .name = (CONFIG_PGTABLE_LEVELS > 3) ? "PUD" : "PGD", + .name = "PUD", .bits = pte_bits, .num = ARRAY_SIZE(pte_bits), }, { /* pmd */ - .name = (CONFIG_PGTABLE_LEVELS > 2) ? "PMD" : "PGD", + .name = "PMD", .bits = pte_bits, .num = ARRAY_SIZE(pte_bits), }, { /* pte */ @@ -227,6 +228,11 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, static const char units[] = "KMGTPE"; u64 prot = 0; + /* check if the current level has been folded dynamically */ + if ((level == 1 && mm_p4d_folded(st->mm)) || + (level == 2 && mm_pud_folded(st->mm))) + level = 0; + if (level >= 0) prot = val & pg_level[level].mask; @@ -288,6 +294,7 @@ void ptdump_walk(struct seq_file *s, struct ptdump_info *info) st = (struct pg_state){ .seq = s, .marker = info->markers, + .mm = info->mm, .level = -1, .ptdump = { .note_page = note_page,