From patchwork Wed Nov 15 17:16:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 165522 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2687594vqg; Wed, 15 Nov 2023 09:18:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IF09BUDkHNJ736ecZPbAFJMRt58KtIP41jMdtbmsdvYJRU5/NiXxfybelQ4oT/wyhoH61WL X-Received: by 2002:a05:6a00:348d:b0:6c0:4006:4195 with SMTP id cp13-20020a056a00348d00b006c040064195mr18038120pfb.0.1700068688349; Wed, 15 Nov 2023 09:18:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700068688; cv=none; d=google.com; s=arc-20160816; b=0R/ZUnHiq3Sx9x4TsOggORGSuIQ+rMAmACCqUcLFnmMECZpKjiD/IBoDEOVo0030qh 7kpC3PXSJiCjrd4h3+sqHMmP3bFtaPBwHg5m4VXOuwuAVP7BasxrfxHZJZJV35zYSlC7 VC2SyKoarFe3TBFN7b+/1V4ZJDAYXwRovXvlDRYgKNw/he9sy3ZgZuwYJUjg0hKTQgrG Ah/eYe4ufLELP0L21FL4l3PjM6RTsVQgiUEasejFqtYXswXKNxYj7dxwT4TNV2cSlog7 mvHasBwMSYCZahvk11eLaef6nlApVbs2NcvMWYZmIe5/B0/VzK3lcnHHEz9Sm5BVQCTh ulbQ== 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=Qy3zX0s6ALtK+DaG4wUXBjQ8F6aHRpWpiFcWV1cr/U0=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=jZk2N6UPZEK3xoALCCyS3e+SXqErUdTl+4GLLTLMkaBSH+DmX/MewPYL8EA6Thnbmt Bkbmd+O2Y/ON/223GBrpDsakHHCKvttxSxq7zKTm7VVNsxwYq7/GTFlPtkzeExI9s+eh 4j5JQ8/ZVl4heUaGtU0Vzdp99d/0KYRxBBNyffSXlb4cWcpZScZXgW51JLz4QoPoWzNk N4xuB89gBCGpzY5zgoeIIEEYL1slZCtdPSybChAh7cFmPAnr8yvdrmcoIyqg3F3JBkWn 9VNOrpvYJ28fGeeLFnpQdzDeZmK/hkX3MXc6EEadMMus0tJJeHNu5HwhO36hD8DCm/mR t1TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="nR6PK/+0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id k20-20020a056a00135400b006c34028e37dsi10597895pfu.219.2023.11.15.09.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:18:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="nR6PK/+0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id E22E5816EBD1; Wed, 15 Nov 2023 09:18:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232401AbjKORRe (ORCPT + 29 others); Wed, 15 Nov 2023 12:17:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232740AbjKORRU (ORCPT ); Wed, 15 Nov 2023 12:17:20 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1326AD6D for ; Wed, 15 Nov 2023 09:17:13 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5afa071d100so148844227b3.1 for ; Wed, 15 Nov 2023 09:17:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068633; x=1700673433; 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=Qy3zX0s6ALtK+DaG4wUXBjQ8F6aHRpWpiFcWV1cr/U0=; b=nR6PK/+008SAq1seEfnKT0/2+xngpAiBhIDUKWLk9c1hrMWjUTVQYqYRgJPk4tVW2X izvzNx860G2ZjZzxR0ovojefWBqeKkw/Xb38sxkommQqbLg0oLn1R6Pe4ktjQ0igd5ny X9iSg79JjqQII7PDb8NorG8pxLRsl/ieLWAtGaetNLzdyiLB+55rUvJyH7GRZCjkD1wG J3U+DHc2ngwQ5MHrTmAu+z1qGuMymab3Bni8qMG0Lm376qooO7uV/cOps0YK90h0KXUi FJSkFrS5qM3jXwktXZORAD8rzUAV7KhHNFoT/IXxBvWM+nydqE5Ozcn8w5zZEnBXQbly VYjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068633; x=1700673433; 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=Qy3zX0s6ALtK+DaG4wUXBjQ8F6aHRpWpiFcWV1cr/U0=; b=LCqowOE5zxCwDybV+7YiLP6yQr7fyMdepqrmRImy75iQYxiz66mgXA8DDid2/JqYER w2BZCtYArvj0Ed3gycXbuceR6lpvF6a5uxfqKo/2+zOUGp9KERFYvw4hqpHfM/5dMqCd pZm2x8cozquyDU4r4Z0paXoZRqmkv7fq/lv20y7OXOcvYfO7B/e9jXcEncJa25gvWsMi OLqW8md3dN7m5wKuo92qR3D1VPM+wGCACnntEtKUsQHJ5qt3In6Pgz9VuEj9wRvGXafJ cGBs8jaZtkMoc0EfU46Ke/TM9/Qa+5bV9hkCfHtk/LpQwPfNmEVgrAziAVSPLaC4yB6l 0KFw== X-Gm-Message-State: AOJu0YxoQZ7ElQGQ6IW1XEF+/WagcK1h/Q83A21friVyG4SXYfrC95Tq 0g/G+3NL3A2XvprZ6FF6vQtKq7E/FSHk+2fpb7w= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a0d:d7c3:0:b0:5a7:b672:4d88 with SMTP id z186-20020a0dd7c3000000b005a7b6724d88mr356731ywd.0.1700068633096; Wed, 15 Nov 2023 09:17:13 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:38 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-10-sebastianene@google.com> Subject: [PATCH v3 08/10] arm64: ptdump: Interpret memory attributes based on runtime configuration From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, 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-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,T_SCC_BODY_TEXT_LINE, 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 09:18:05 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782651224665090306 X-GMAIL-MSGID: 1782651224665090306 When FWB is used the memory attributes stored in the descriptors have a different bitfield layout. Introduce two callbacks that verify the current runtime configuration before parsing the attribute fields. Add support for parsing the memory attribute fields from the page table descriptors. Signed-off-by: Sebastian Ene --- arch/arm64/mm/ptdump.c | 65 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 9f88542d5312..ec7f6430f6d7 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -89,11 +89,19 @@ struct pg_state { struct ptdump_info_file_priv *f_priv; }; +/* + * This callback checks the runtime configuration before interpreting the + * attributes defined in the prot_bits. + */ +typedef bool (*is_feature_cb)(const void *ctx); + struct prot_bits { u64 mask; u64 val; const char *set; const char *clear; + is_feature_cb feature_on; /* bit ignored if the callback returns false */ + is_feature_cb feature_off; /* bit ignored if the callback returns true */ }; static const struct prot_bits pte_bits[] = { @@ -175,6 +183,34 @@ static const struct prot_bits pte_bits[] = { } }; +static bool is_fwb_enabled(const void *ctx) +{ + const struct pg_state *st = ctx; + struct ptdump_info_file_priv *f_priv = st->f_priv; + struct kvm_pgtable_snapshot *snapshot = f_priv->file_priv; + struct kvm_pgtable *pgtable = &snapshot->pgtable; + + bool fwb_enabled = false; + + if (cpus_have_final_cap(ARM64_HAS_STAGE2_FWB)) + fwb_enabled = !(pgtable->flags & KVM_PGTABLE_S2_NOFWB); + + return fwb_enabled; +} + +static bool is_table_bit_ignored(const void *ctx) +{ + const struct pg_state *st = ctx; + + if (!(st->current_prot & PTE_VALID)) + return true; + + if (st->level == CONFIG_PGTABLE_LEVELS) + return true; + + return false; +} + static const struct prot_bits stage2_pte_bits[] = { { .mask = PTE_VALID, @@ -216,6 +252,27 @@ static const struct prot_bits stage2_pte_bits[] = { .val = PTE_TABLE_BIT, .set = " ", .clear = "BLK", + .feature_off = is_table_bit_ignored, + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR | PTE_VALID, + .val = PTE_S2_MEMATTR(MT_S2_DEVICE_nGnRE) | PTE_VALID, + .set = "DEVICE/nGnRE", + .feature_off = is_fwb_enabled, + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR | PTE_VALID, + .val = PTE_S2_MEMATTR(MT_S2_FWB_DEVICE_nGnRE) | PTE_VALID, + .set = "DEVICE/nGnRE FWB", + .feature_on = is_fwb_enabled, + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR | PTE_VALID, + .val = PTE_S2_MEMATTR(MT_S2_NORMAL) | PTE_VALID, + .set = "MEM/NORMAL", + .feature_off = is_fwb_enabled, + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR | PTE_VALID, + .val = PTE_S2_MEMATTR(MT_S2_FWB_NORMAL) | PTE_VALID, + .set = "MEM/NORMAL FWB", + .feature_on = is_fwb_enabled, }, { .mask = KVM_PGTABLE_PROT_SW0, .val = KVM_PGTABLE_PROT_SW0, @@ -267,13 +324,19 @@ static struct pg_level pg_level[] = { }; static void dump_prot(struct pg_state *st, const struct prot_bits *bits, - size_t num) + size_t num) { unsigned i; for (i = 0; i < num; i++, bits++) { const char *s; + if (bits->feature_on && !bits->feature_on(st)) + continue; + + if (bits->feature_off && bits->feature_off(st)) + continue; + if ((st->current_prot & bits->mask) == bits->val) s = bits->set; else