From patchwork Wed Sep 27 11:25:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 145333 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2562447vqu; Wed, 27 Sep 2023 04:37:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuCUvbDRaiM6No0Xtm2CS/QAMCNir6PFKQ3U57cH6RMfUvt6RlnQE2l8dkAYVs0Lud2fGm X-Received: by 2002:a05:6358:991e:b0:13f:2833:bf41 with SMTP id w30-20020a056358991e00b0013f2833bf41mr2141568rwa.23.1695814647367; Wed, 27 Sep 2023 04:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695814647; cv=none; d=google.com; s=arc-20160816; b=n8r5k28Z0ubZRiSHouRKzlj5atgApkDlRaWAxupzlrVouRlTdGApI/hknX/IRXmLNV 9EQddrDHjEa7Rg7/9hZqjlEDVO2PufUFfDhuFG34kiPbfDQhW7EzGMnv6weG/zcjF+sd rXVJPydAEP9MvddcD8cWswKErhPF6Q9jQFFnjsMdDVRIaQtY/+Rv6RlZow2RRcKCLV+O ebTP8T5w8QsogeCCHvC9CNQl+q2KEWEc0YRJqBOy5S6XYISOjTYue2IOqaGJjuEp6YkN NPB3ImYy1sjYSIKeUw3Z+lkorrliYwHkHpELyrUHEQZHowsZcUFdkulF9aGIziZBQa84 Zz5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=sg+l4AZqIjzZdAaAwEVRBA1XU/OEUMwb2p3CABcyD1c=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=bPLtXD2VvWhteMfzL3vVrYilPkHDlzczGN1LU+7MGWnOZjVVUC3OtgW+vfKrXuFNB8 ld7HWUSRmDYb7zDg3Iz2673aRU3ujELNFoo9wbxI45zb5GN5upANoiX6dBJBMjlnAcum hYOSZvra7a6YntIiA5mbnhyhd3iKIRQLzpjUU4+NL/FBSHjFaODLnSiMz5PPowseOP27 934s5ELRIGoY9XU5v4MJbrDfMPJfCbfZ4GGG3g3wKfSuPh8djDUTiEFT1HDcoQKZRqka l2P/POrVCiN5geQHzeg+iNbheo2eR5kC254qdbmSfS+D6i0ALPommxUZ0o0hW8F1HQuS pR8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jOKDwqBt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id s16-20020a656450000000b0056c4189d6d9si15396015pgv.836.2023.09.27.04.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 04:37:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jOKDwqBt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 01A5180AF25A; Wed, 27 Sep 2023 04:26:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231520AbjI0L0J (ORCPT + 22 others); Wed, 27 Sep 2023 07:26:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231477AbjI0LZx (ORCPT ); Wed, 27 Sep 2023 07:25:53 -0400 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 505B71B6 for ; Wed, 27 Sep 2023 04:25:49 -0700 (PDT) Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-3200597bfc5so8329904f8f.2 for ; Wed, 27 Sep 2023 04:25:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813947; x=1696418747; darn=vger.kernel.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=sg+l4AZqIjzZdAaAwEVRBA1XU/OEUMwb2p3CABcyD1c=; b=jOKDwqBtMbeCeYiTjWu4QKR1urFyjADm+DhAq3yU9D4EPymCSj0CyrZ5D8ZeCsHRSA rcu+dZD9uWUoVPRF0V80XsleivemJAe3tu/OirdbOXXT75G4bNTChWBfD61VpjKvs7r/ ThOb/17hfeG1Y9KFoNxIUILqtoby/UwdjCGGWeskQ0IYnRNZOhCTiR1EXTQ9+YoDLkVv tZkD5qyC/PI3kROAvBY9hu2edJV1JdvnXp3WPgwUnwSZOp6+00QgjCF3VjFCa1+XP1nY 4huVFdcllD21Hej5vR0zo6TywNjcRWXhXilFx+To1A6mjVby2/WAN2MV22hAe6NrkzAw 9+bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813947; x=1696418747; 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=sg+l4AZqIjzZdAaAwEVRBA1XU/OEUMwb2p3CABcyD1c=; b=KHNW3sMgZQEvPrWuHMQgZmdpuqBv2pS3hIJoddPirBoQ3EwjFAlNUIrVJyfvvAnkxR VnmDX4vWCNjj2dTH2RcETmIXb0SB1/CA+ps0hBA8ZGlv2/Zh3GKq9hFriVQx3brwE4dU k6pl+SpWrCXoIFSBHHs7tkwZRbPTZC8vQ18lRDjg8VE8eT7S0eJxD73rFdwDzzWb5Bqc g/Uk1vhGHD9ufAItKyoRtjJ0qo5BNwB6wslsKkYCGdLto6Fo59GiOPMB/xRPE+dk3w4T OnFBFqT3kztB2Ljgq+wMaS5YMPTix2kPO7PwPMu7fMhqIUBIfu4IXqrl/XenKeLqMRB5 NAgw== X-Gm-Message-State: AOJu0YzGNb6Hg7diXHR5M536fxTsBkBBuPCG49/nmS771rXnarY27l3W tS3bd3AiiAcsiH2INhhLYgdoYmL+HBlBTxU/Xcsw0aFhyXtNHCX16zpT0jiuYuwHmG0oAuox5nB qs+Ig5mhwySuADWB4al/AbxqKJUq29eTIbKgZwdqsaKBn9Tv/nZWEy9pPVeoYO9kJsK+SfSrBat KSJwjg1KFV3Q== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a5d:4145:0:b0:31f:f72b:520c with SMTP id c5-20020a5d4145000000b0031ff72b520cmr7783wrq.6.1695813947441; Wed, 27 Sep 2023 04:25:47 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:11 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-6-sebastianene@google.com> Subject: [PATCH 05/11] arm64: ptdump: Introduce stage-2 pagetables format description From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778190539797660512 X-GMAIL-MSGID: 1778190539797660512 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 | 91 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index d531e24ea0b2..8c4f06ca622a 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,30 @@ 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), + }, { /* p4d */ + .name = "P4D", + .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 +425,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 = {