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: 13457140 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 7B684C54FB9 for ; Wed, 15 Nov 2023 17:17:49 +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=D/NXJafVjrgzDN3joKxXqMhdlwIfducwvk0rW+JIXhk=; b=MAL2S6cHEqqKOdT9Al2sSU3Gxt rYqHxU/458YuvlO/xubGqXXf3QQktOFxoGK/jFHQe/vOw1URExmY6sA7rbXBbT/04vAhZrCAsvClr 4PM5cwZwPzGC/YqPDIwhnh8p5kvOPpVNZrixT3131UeaZAuoQat1UvZ3CCeLXQ9KcTZ84+w6hpjrC 40P6+55UwGrljy/xGfFOq0al02t9yas/CIGqSBeOPCFRWXoJY5k26/n/rx9j77AzAzyisOUS24zZu OuAAkNpO5+8mhGzmgTKrpqiWCfuRYMGxSe2ozJ4I1FmNBiLUlR26tO/R73LC4SQctY9XsHPp55BAs w32WHA/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r3JVz-001PeR-0w; Wed, 15 Nov 2023 17:17:23 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r3JVq-001PXl-0t for linux-arm-kernel@lists.infradead.org; Wed, 15 Nov 2023 17:17:15 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a8d9dcdd2bso148758297b3.2 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=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=Qy3zX0s6ALtK+DaG4wUXBjQ8F6aHRpWpiFcWV1cr/U0=; b=dBAKMRC4rvg8M47TUdixus4hW3dO9mtMKShyNyJoo5JxDLXbSjqg8LzEwJWhjIXgUJ 0Sk4uzLfv6E86VZybQ8Wa5Z6uZSgKxNm9CuldVjvFXNGccDckeHP204LpgBVdEobKm1Y ioc1/Zj92STDfaDoaq5hhdhAYa9NOXEHelJ+Q83UiYBZM8buW86vyqpQECy/5EQ3VKA5 Li3/jGmv8/7uiDxwovmPNOALAHf6K9X05ZuooTWr56VZPHCjZaGTIKhz3dzEF31/g2CH fIMYm5/ua7/p4OeZIs9ccERNVHLGWbpTkXysU1v5+lBJ9oXICANiIcamXEkYYQGhW9BL hGIg== 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=KKZb11DZiYBAskYyS3b9WQEY/9MIzC9cnOH9G3yFlweEH1tuf7QitxxTDjt4Dq5qPs RFEIlSkKlIeS+hZCt37ISpvLg7F3rtvtC55xHAGpZw6j/dM8znYrcP1+ELTM2+/SrOtu CAfAh1h+O5fCTmHnrQugMymgcDmar5xHbEwlZPb8UXK9E73smqHqitrwoh1j/3BilvRv F550roXLNjo7faZgGAtTeY2q7uEu6MUyWMov4OY8HwfOMv4O3rb4B4TNV72b4HG1VDxs PsepnnykckytrUt19e/h2isNaDJHEzBPw89NfpADEH9zhYibPIAw5K6aUHy5Ubc4iVv5 c5Xg== X-Gm-Message-State: AOJu0YykIB9Lhbd3pB9+g1RMWYe9Ly2u4QlWwaLEb1ngwTZdl4Ko9Sb8 yN439fqFMyvBey/kdCMp46Lvfai5btKdU0cBomQ= X-Google-Smtp-Source: AGHT+IH15zotRvXqa3gGL+erJN8kJ8qtR4AedLWdqyhduoqwJwWiS5LNpUVQnjgpQUblW7SZJCRmmCsMHRZC6boVABk= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231115_091714_322956_E9048EC1 X-CRM114-Status: GOOD ( 19.04 ) 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 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