From patchwork Wed Feb 14 12:29:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13556550 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 E378BC48BEE for ; Wed, 14 Feb 2024 13:46:03 +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=Tn5H5NmtcsXRGhQP1Wh5JVUKx9hDeji/qwMI4A+/Hh8=; b=vnnLl8ov5GT+v3JTcJsfdhN7BQ He5b1eLo6Qc6lpKQr4hwHtT+DnyoWcGBAADrBkrv1bKZMvlPhtohpne1DuYdb7uOE7WYogj3Q7Xfo ifc7NthTALI3Ic4trs2wttu8hdCsXmy+FIwXKObeRt9lxgtJiVRn6S7pWBb7w/isfaeE0engwicWZ ahT+z7KmNUyqdH7BBMK9mwA7ysAGMAuXWIMqHTSvDAVtBWSqDet3gzOLy39Fr4d1A5zfK+0UKBNNE Um5PQOXHXH6ZOCjbH7tebkD/mUbLMFzCQGydchfZrzJOWOcY3oDWmLoN3AT5ov/i3OCIfG0QqvV8x uStasvDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raFaA-0000000D3ip-46ol; Wed, 14 Feb 2024 13:45:50 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1raEPy-0000000Cp92-1RPu for linux-arm-kernel@bombadil.infradead.org; Wed, 14 Feb 2024 12:31:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=nim3c2gTM7nh9rCbkF9XqrGKHEjAQ3AiMPielUv+s5w=; b=WUidQBhnXvLvTgdzPyaVs9mxQ+ k2pVcy5ZZwiKQq5ms0aDyktvSA9+pZfFc70YWA7tubnIXIBC2lWdycZxS28BaXRp7V4ksnTdy2eyi RX8YjCz1qM/YqF/czwHJRD80/7HIe6WPdWD9XEh490hSpE5J15urCVhi+l2sO52JOwN+uJHCd/wdu cw+oVjo4+e1GmgYSdk9qeRnPkGo4FwtZ1ESxiahsvHNpZ/zRhiV9azfH+xB/aDmSheV/WbRTU7xpD Psd+xwDwsR2r1MyzR3SExB4Tl4bIJCSeYiJw+AFU5UHusz/7vvOpyVPOHbQN7RpzPzhmH78D+GvSi v+E4Zbgw==; Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1raEPs-0000000GEEE-1qb1 for linux-arm-kernel@lists.infradead.org; Wed, 14 Feb 2024 12:31:12 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dc3645a6790so9889499276.0 for ; Wed, 14 Feb 2024 04:31:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707913866; x=1708518666; 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=nim3c2gTM7nh9rCbkF9XqrGKHEjAQ3AiMPielUv+s5w=; b=Vz/dgE+5lJJzzAXABGSf9YhHyqmh/sCf286HGHL95gUXE9E1DwJ7wrtqevK3UdA3yE sQ8QmZpUTANWcgeYQp9gfydiRnef+I+q54oH0JpuxoSHvENZbqb5Vge0U2jC/TjfhQ7P 4KH31BM5MAVEfc5qd6KT6PTnXyjrVbheX+wjKdvmU6gdcL+EPHpGGevwgyG3mt6XuSM7 aK0FqP3OeYV4ruhXGDdXBr8g+6AFfBuMtGduldGDNPCT+fVNjHCvIiipbhagSZRUH45j zMB2gNyqSiSJJlcQcKEcABLKPYydCYw2cNepf52am+nrGwfkR62EQ26mKSGVExdcpMIS NVkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707913866; x=1708518666; 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=nim3c2gTM7nh9rCbkF9XqrGKHEjAQ3AiMPielUv+s5w=; b=Up8IJiNemq1tkGMKi5VuM4DVlRzeRDtOeWWMzfBSvGyLUIJWlBEJUFgDhkGIhLA2s7 n1iHnty8sz/rO4LRxJPiMc/O08+zOd/qaxjSyND6CWSVTgLG5ELBxMJXgie7vjODhT8Q h8h2YD5efRoABFaiV1FD3CLh+ckVbmMQjTjg7LdEOkQQFHVXlvQtvUHW0MLrNOifAEEM EDMvzEo4DVIdPWniId6kkXRaI//t8t8T1kddrc3/+QqM8zcMqDKcWtGAC8bbz2fD3HpQ ZuCzeC8TC/pRdAEk8qxGMYpmjaoUBn7zGP/5RLjzNoRkHHCNOCjoGdZPANbu0VIiS8eu ROJg== X-Gm-Message-State: AOJu0YwAxxOPEzRy0hBUBK+jxvefqKT18RF0en/EKAhk/SmAhKEmkp2o 7z/6ZLAh+zrtF98JRxZHcRjdQs/bFTVjYSlFZlYtSx2QTwoGAEh1MvQfkl3/qsAlNwmO/373mw7 TMLsG8iw5l5ZqxxPlisWhA1NtEgton1v7Bk55F/8ULEbHLSdj9QjmhjFLvcc7R3C6bTsJoVcJb4 DibOhbt0gB6amTcry4dhG5UWHD9f2s208sKRtjCEgq X-Google-Smtp-Source: AGHT+IHB0JANakyodDNczMw88qFBA3HYj/BIyZyWpSgCjgAui1HyVFg6ldJiPwAwd18NMF4sOT92ow3v X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a25:dc02:0:b0:dcb:b9d7:2760 with SMTP id y2-20020a25dc02000000b00dcbb9d72760mr490452ybe.13.1707913866351; Wed, 14 Feb 2024 04:31:06 -0800 (PST) Date: Wed, 14 Feb 2024 13:29:24 +0100 In-Reply-To: <20240214122845.2033971-45-ardb+git@google.com> Mime-Version: 1.0 References: <20240214122845.2033971-45-ardb+git@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=YjhX0rklZvJzAi6YOz38nWlFpNJR9o+uJt31nCu8kg8=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXMJvUfide9H92XLJEsXPOhrbt4szRnyVoZv2OLW+blH cv48TWzo5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAExEQp+R4Yxof4V34T6TrXfW xh/T+P8l4MwhjeaQ0mmLLK/P+ZT67DfDT8bHU5nez/pwKkfTo+nslyWM6+aw7Jz75MT8nY1HD2Z LaDACAA== X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240214122845.2033971-83-ardb+git@google.com> Subject: [PATCH v8 38/43] 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240214_123108_817433_98DB937B X-CRM114-Status: GOOD ( 19.57 ) 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 16d0cf1d85c4..5b87f8d623f7 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,