From patchwork Thu Oct 19 14:40:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13429342 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 2DD8ACDB483 for ; Thu, 19 Oct 2023 14:41:41 +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=f/XDjnXUN4I4eGFH10TBXV7mj3e85KSNIUB+iSW0pVA=; b=qXxHwiKLmeYq03bESHNbtH7Y3/ H54E3oJX/x6YQpMjKtRtbXdaKp9DMM8AuRUReYOxK4hc/RIb/oyTW9pKCTsL3BV5ePwGkLllVAE86 Y9OYtHEmDkDhqagVdNKTX1bhIs+UZB0jpIx4YeJyW0TcrxoOyVN0j++Yhw1HaX9kuYUngBLj49/19 Cra4xTPlLXXG9Ux940bSjJOFTmoM2VjGbYZ1p+7SSHhkL38PCnFj/eRPsfwMnjr8zO7PRTAoh7py5 WPf/nr9SHqkMfzTse3ZsIPp9e65toSrGodzFv6O5bnVZzQBmbovdd6RQlXvxp3ZagQaiNwgjX7AVv 2j4VKemQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtUD7-0006RU-18; Thu, 19 Oct 2023 14:41:17 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtUCn-0006Gh-34 for linux-arm-kernel@lists.infradead.org; Thu, 19 Oct 2023 14:40:59 +0000 Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-32d83fd3765so4800511f8f.3 for ; Thu, 19 Oct 2023 07:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726456; x=1698331256; 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=irFQ7vIeF55X7D9u5W+RRcx8opaM8C3jS63aHLA7bAc=; b=l0h1rNzYn73roaLhCbr1asRsrsoXgRwcsb+ixIiAS+ni3ju2HR2SqHJdEMugBC+d/S qUxEm7BglntvqvBP4JwfwD+oN2BOGG4tLgkdSl3Eyv/JZFGxdoT5KYkHFFZitiKmh3Ys RBf55gTx+FLjooKEMDbik+62eX1+jcs60PusD5vp5QWfQ7xiAAuuR5TTGDe47Bz2pSGa FUMGV/bDCojd2Fmsr6rLsXcsmp1o7ndfOVIqrNoWiksSTFzqwS44x5ezvaxVf1T7+UVU 36NnSK0WxvOjburo85C+gqkb7zQsB9acRPrE2ISPaGR38+DWFMo4MrWCM38H+nrDHWgE acig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726456; x=1698331256; 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=irFQ7vIeF55X7D9u5W+RRcx8opaM8C3jS63aHLA7bAc=; b=vMTnMMD+DlkiggcRKakt+k+K0Fo30sy0uYJTe4NOlU3DrSIOfvBExLWMa7FxmXCNiE C6nBzuGMrbITyKP88C8OpLnQE3O2Qg5uEcDMqwwDkr7h/CzCB/5POxzclX4CLE9KjA8N kPrb7hBjXHn8Yx4nDG1L+FnOi5riK9rt0a2tTQsAFK6cbhPn7B6hZDuwPQFzBxIHQYn7 6Oo+g+gS5mRdGaWSReTI6XeNV5HgTIBLJ2h1ake4nHPc1y/cGq6bRUDwqYAHYsT38O7c 1KaklOt3Wf200kNPP/XvppWsoyBbAySsVsiVtVyHAA4zH3tx+oIZhpDiJ7bESurfamIW vRzg== X-Gm-Message-State: AOJu0YwIs+qytTCUBtPOFScYiiNTRUW1sLM3528vLHOOL+E7CoMfLS8s YwvAS6hxoai21RVODhzVjTAwHhCTfteRF8eVK5o= X-Google-Smtp-Source: AGHT+IF3GoLo/wBW4dX66SazO0VPZ6uH7fDzq+LUToDEwWy58v8WzEAJKiwN+7yzyFy+eCcQyInhEjV76d/RlRrkn68= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a05:6000:1372:b0:32d:a860:3257 with SMTP id q18-20020a056000137200b0032da8603257mr19560wrz.13.1697726456175; Thu, 19 Oct 2023 07:40:56 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:27 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-7-sebastianene@google.com> Subject: [PATCH v2 05/11] arm64: ptdump: Introduce stage-2 pagetables format description From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_074057_994156_2B779675 X-CRM114-Status: GOOD ( 16.12 ) 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 Add an array which holds human readable information about the format of a stage-2 descriptor. The array is then used by the descriptor parser to extract information about the memory attributes. Signed-off-by: Sebastian Ene --- arch/arm64/mm/ptdump.c | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index d531e24ea0b2..58a4ea975497 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -24,6 +24,7 @@ #include #include #include +#include enum address_markers_idx { @@ -171,6 +172,66 @@ static const struct prot_bits pte_bits[] = { } }; +static const struct prot_bits stage2_pte_bits[] = { + { + .mask = PTE_VALID, + .val = PTE_VALID, + .set = " ", + .clear = "F", + }, { + .mask = KVM_PTE_LEAF_ATTR_HI_S2_XN, + .val = KVM_PTE_LEAF_ATTR_HI_S2_XN, + .set = "XN", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R, + .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R, + .set = "R", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W, + .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W, + .set = "W", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_AF, + .val = KVM_PTE_LEAF_ATTR_LO_S2_AF, + .set = "AF", + .clear = " ", + }, { + .mask = PTE_NG, + .val = PTE_NG, + .set = "FnXS", + .clear = " ", + }, { + .mask = PTE_CONT, + .val = PTE_CONT, + .set = "CON", + .clear = " ", + }, { + .mask = PTE_TABLE_BIT, + .val = PTE_TABLE_BIT, + .set = " ", + .clear = "BLK", + }, { + .mask = KVM_PGTABLE_PROT_SW0, + .val = KVM_PGTABLE_PROT_SW0, + .set = "SW0", /* PKVM_PAGE_SHARED_OWNED */ + }, { + .mask = KVM_PGTABLE_PROT_SW1, + .val = KVM_PGTABLE_PROT_SW1, + .set = "SW1", /* PKVM_PAGE_SHARED_BORROWED */ + }, { + .mask = KVM_PGTABLE_PROT_SW2, + .val = KVM_PGTABLE_PROT_SW2, + .set = "SW2", + }, { + .mask = KVM_PGTABLE_PROT_SW3, + .val = KVM_PGTABLE_PROT_SW3, + .set = "SW3", + }, +}; + struct pg_level { const struct prot_bits *bits; const char *name; @@ -202,6 +263,26 @@ static struct pg_level pg_level[] = { }, }; +static struct pg_level stage2_pg_level[] = { + { /* pgd */ + .name = "PGD", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, { /* pud */ + .name = (CONFIG_PGTABLE_LEVELS > 3) ? "PUD" : "PGD", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, { /* pmd */ + .name = (CONFIG_PGTABLE_LEVELS > 2) ? "PMD" : "PGD", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, { /* pte */ + .name = "PTE", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, +}; + static void dump_prot(struct pg_state *st, const struct prot_bits *bits, size_t num) { @@ -340,6 +421,12 @@ static void __init ptdump_initialize(void) if (pg_level[i].bits) for (j = 0; j < pg_level[i].num; j++) pg_level[i].mask |= pg_level[i].bits[j].mask; + + for (i = 0; i < ARRAY_SIZE(stage2_pg_level); i++) + if (stage2_pg_level[i].bits) + for (j = 0; j < stage2_pg_level[i].num; j++) + stage2_pg_level[i].mask |= + stage2_pg_level[i].bits[j].mask; } static struct ptdump_info kernel_ptdump_info = {