From patchwork Thu Oct 19 14:40:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13429345 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 8428ECDB482 for ; Thu, 19 Oct 2023 14:41:46 +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=DuTpX+fqVFpqNEIwLl22kzE/CgUBYOgbmtmyFEa5uVM=; b=tH5uMPsJwciOqht81LfjpfKdSR 46Ha3vVIUkfThPYsP/3Svl2qlCxZf3ZW+eZWEhZ4FOu7Ri7ZDp/xy01a4L+v4fAy4jDaHJU5Lldq3 7FuDOv7KhpzZEWUvS1EEIRjx5+wIEEGS8y4GMPatsAe77zPN0NI5aFoJK3JgMtBLUH9FUOG5oB8WJ 7N1NDNKc1s5LZXXWrrJfXrIRtTWCpiGnLuOuEUv9xhUczk9YRMU8H64gWFE1gwLGOEaiK+PzXzRB6 smtvCTep6WzwOpB7rKzOHxoDmG4Ugm4P4YVwsjwTXTUz6lmhi8D1h2Y3xzB3njmHvYyp0Ico+2hO4 QC+6MHeQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtUDC-0006Ur-0a; Thu, 19 Oct 2023 14:41:22 +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 1qtUCx-0006MQ-1D for linux-arm-kernel@lists.infradead.org; Thu, 19 Oct 2023 14:41:08 +0000 Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-32da215295fso3218358f8f.2 for ; Thu, 19 Oct 2023 07:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726465; x=1698331265; 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=CvJdm3IKmCA+/1ICly/hVREi8jIoDHSAqzssbPm75pQ=; b=t8HxmSSK7A3BK426ToZBE2CpioZQd+fI5L+kDS0rvjuyqFMT2h30N3Ay/jjN1j/mkh SXcu1fXP1xa9dVUkrVJBk81sq7/im+xWPDU4VTCRIQLt1ut1IQKR6zmIShMopbmVZQl1 GFPfg+1xHnqblrDCa7VPJPLoBewrNNuohasGKDIaAsdOKSlMucoHgpvjqd90YGbF7D/X d2NRAVXw8rcU97uINW2z7sjJhS5U+HXUndtRLAfMZ5tvTxyONSMn3pAwJrxKGXUOI3zm 8T8/nQL9mRyl+sCa8hirj/vcYQL0H5VZ1N4X60yQtIfgYyH6oXWOAR30qUWxI86GctH6 7rkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726465; x=1698331265; 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=CvJdm3IKmCA+/1ICly/hVREi8jIoDHSAqzssbPm75pQ=; b=rRsDJywhxytE+shVYMlLylkRdf67ZG30+x1OUnjuUuYGyffwQZjxrccAgy/+HKt8qO 1Edkoz2cQZVa7YUVRdJL6VUzocX9U3eBr1cZH90ainu8vWv6bm4YHjn4QnWHwIu9p4il 6OJC2A9B2YvpkLMK++MsyKE1ljIolL+HPttSPT3j41Ss3EqBQLEm8zGbVE5acoJe8xIH H1M/ddHbU/W8nj2fQy6PLSwCULcytAoCTTPWQNGEtxDQg++fTuOQz2i9pIkZZ3/g0IRF GIccb4K3IJQwfmAHHuN8Ht7rSW+qFRqdOVbHA/nfOEZ8HqeBCR54U6p9aK3CrGleqvfI yrlA== X-Gm-Message-State: AOJu0Yz0XEthuW7hoBG1+qc16hAtoQWJKEvnzKOV3iXMcjYFdL+F3rcd EEmu/DBh0x+Z7JFxG6fqSZ74HJcr7VPoCJLY/7w= X-Google-Smtp-Source: AGHT+IHd3XOdzZVQWrUJjDNXs2PGDHCNNjcdi3ZWTk5PP9acOL/8DnwH2AUd6D9476w0yP3WM6aezjeueor84uThLIA= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a5d:69c8:0:b0:32d:8188:6221 with SMTP id s8-20020a5d69c8000000b0032d81886221mr22460wrw.0.1697726465577; Thu, 19 Oct 2023 07:41:05 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:31 +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-11-sebastianene@google.com> Subject: [PATCH v2 09/11] arm64: ptdump: Interpret memory attributes based on runtime configuration 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_074107_416233_0BC87275 X-CRM114-Status: GOOD ( 18.72 ) 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 | 66 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 3ba4848272df..5f9a334b0f0c 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -85,13 +85,22 @@ struct pg_state { bool check_wx; unsigned long wx_pages; unsigned long uxn_pages; + struct ptdump_info *info; }; +/* + * 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[] = { @@ -173,6 +182,34 @@ static const struct prot_bits pte_bits[] = { } }; +static bool is_fwb_enabled(const void *ctx) +{ + const struct pg_state *st = ctx; + const struct ptdump_info *info = st->info; + struct kvm_pgtable_snapshot *snapshot = info->priv; + struct kvm_pgtable *pgtable = &snapshot->pgtable; + + bool fwb_enabled = false; + + if (cpus_have_const_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, @@ -214,6 +251,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, @@ -285,13 +343,19 @@ static struct pg_level stage2_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