Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp113660rdh; Mon, 18 Dec 2023 06:02:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGASJD0fDSkFghtfeEtCCEGxZgfvujwXi9vQcT2cfXu+0jkz7Kiu9LsFuodv71VHVWenP64 X-Received: by 2002:a05:6358:9986:b0:170:b02a:d38d with SMTP id j6-20020a056358998600b00170b02ad38dmr19573704rwb.0.1702908160650; Mon, 18 Dec 2023 06:02:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702908160; cv=none; d=google.com; s=arc-20160816; b=WSQUWjAgwS1yWU7/D0Da9eOdaHYmRMkpenY4oMjNdFqOdiJ0tTCaZbWc+ryfd9BJc1 V51/Cooc157Ge0nIEmMHNCUSErv9avnwDzUTwHUdgrsLKxxzll5agM1g59voluhgoZwu ew8nai3XslA9R2d+YYy2JcFCtLtd0mX4FxnjflC5qbAti+P5e//DgFMLg9HdIf/eqUVp elqU6cweOdoL6NgryiVNuum129CHshcJaXXzgrpiisczaGTUUq+b+OQO7pJiqu14k7Xj T0mxIpCRdCYgr0Z5yoLgovaxne7KLl8EHZ1S25K4P2QlUhp7HweFUP/rZ4iDJ7nFT1fg wM2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=/DzJPItky+7MIXN0FJdMX89fRzHYJTFATAafmjRyPww=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=DuBleL7TRu6TuzIdWz75syBYp7qTNc/DN7bGJARXjxSp5TCHWBmz4S/TXB39jKoxnr KlSjdvmzlUXh/WgXiiVuD34OhzcIeXplWoeP5Y+A8k3kVUXoNqNNhMET5MayRpJY/CKL Mh+B8OKT3YBnM9hPYAMsLYqfw/DsS9gomqquGriyTEPErwcV0WD4OOUFEWJcJFNX8QMd 7gD7bkbfoQiD+jkcz1Y7sks/1moTHLfjqx4I2Zmn1w2ktNaW34wUBMxfLkymztIqXAX6 dY0vWIOzhEp3qNK4CXeckd9cHVg1pJfg4zxqprX3xG0ACkDOqEHPJFnIlcNUppBZ2Pum tkoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="ir/j0z0d"; spf=pass (google.com: domain of linux-kernel+bounces-3796-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3796-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k190-20020a633dc7000000b005cd786d8e3bsi4492802pga.249.2023.12.18.06.02.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 06:02:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3796-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="ir/j0z0d"; spf=pass (google.com: domain of linux-kernel+bounces-3796-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3796-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8B32A284242 for ; Mon, 18 Dec 2023 14:02:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9DFA94FF7E; Mon, 18 Dec 2023 14:00:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ir/j0z0d" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD948498AD for ; Mon, 18 Dec 2023 14:00:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-336695c701eso527279f8f.0 for ; Mon, 18 Dec 2023 06:00:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702908005; x=1703512805; 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=/DzJPItky+7MIXN0FJdMX89fRzHYJTFATAafmjRyPww=; b=ir/j0z0dfCwLrjL6VlNGzyXRJSCry/oaieIvElgp7D+iblDakg8S2AOLx946fLvW9i Wfl2oEZsllrUKn9dsDmwPBGLnz/7HZ/x75q2Mokzxt9zw+MetyaHbcXHlgipaLDf5Rk6 4YOnas1WTwhaVDvCK41ckx2Nk+dCmiUKrJ0Zt3Nc6iXhuFl3bDm/zbQJsDwKz2i1ieEu dbswrlHceEeICRQuTbsDthdsnNXo92DxDnMZqFz52HbSx2f6zvAAk6Z8ei3Z5mqXlJQI v/1pp23zZRtEDmVnr3V8O0w7Q0QDWsYFjeozLp7sSuCrd8tyrCjNkj4bHFswJBn7amOW 8oLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702908005; x=1703512805; 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=/DzJPItky+7MIXN0FJdMX89fRzHYJTFATAafmjRyPww=; b=X2pc8V7a5/aYlrJGDMh94FlMg44JaL6xyz2WMpnxaReO/NaiL9yYm/CXRkheUMUp2r IbLLVSOl8vChLggCwmXg1kH9iC1/FnEVRl9w9k1Nv4adtIr8GkedwfSYnR9vcUE9WYzg aFCtHbbyEKL5c3BMHhGVZrwcL0m/G86gfBsWFcP0UUHNYZoka23mCTZnIhlCKb2BBTEf WTrV1RX9S4JKn6la3A+fsekvFAJ53GRO59PYmNtiDy2z9F6mA3NJ1ntYuK5D9Nr6Zkj1 Hg+J5TF8DYKzxVXOdQH9uiUkRAqDk0GKvmqlhNLvrH6o5KBINVWUFXyb7Q4+UjhiSyUg BIHw== X-Gm-Message-State: AOJu0YzD7ugyZpElR2Wu45c1DCEp3X1H11MIykdpGU5bqZjok4bK2APB V52PqpnKlAi8YzscCLv2T4W+ktJ1CCqLBa3Zzi0= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:adf:d1cf:0:b0:333:5232:d7f5 with SMTP id b15-20020adfd1cf000000b003335232d7f5mr91065wrd.8.1702908005046; Mon, 18 Dec 2023 06:00:05 -0800 (PST) Date: Mon, 18 Dec 2023 13:58:58 +0000 In-Reply-To: <20231218135859.2513568-2-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231218135859.2513568-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231218135859.2513568-10-sebastianene@google.com> Subject: [PATCH v4 08/10] arm64: ptdump: Interpret memory attributes based on the runtime config 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 Content-Type: text/plain; charset="UTF-8" Introduce two callbacks that verify the current runtime configuration before parsing the attribute fields. This is used to check when FWB is enabled which changes the interpretation of the descriptor bits. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 7 +++++++ arch/arm64/kvm/ptdump.c | 32 ++++++++++++++++++++++++++++++++ arch/arm64/mm/ptdump.c | 6 ++++++ 3 files changed, 45 insertions(+) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 4e728d2a1..e150fc21f 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -23,11 +23,18 @@ struct ptdump_info { unsigned long base_addr; }; +/* Forward declaration */ +struct pg_state; + struct prot_bits { u64 mask; u64 val; const char *set; const char *clear; + /* bit ignored if the callback returns false */ + bool (*feature_on)(const struct pg_state *ctxt); + /* bit ignored if the callback returns true */ + bool (*feature_off)(const struct pg_state *ctxt); }; struct pg_level { diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c index 80c338e03..0ad7944e5 100644 --- a/arch/arm64/kvm/ptdump.c +++ b/arch/arm64/kvm/ptdump.c @@ -40,6 +40,18 @@ static struct kvm_pgtable_mm_ops ptdump_host_mmops = { .virt_to_phys = get_host_pa, }; +static bool is_fwb_enabled(const struct pg_state *m) +{ + struct kvm_pgtable_snapshot *snapshot = m->seq->private; + 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 const struct prot_bits stage2_pte_bits[] = { { .mask = PTE_VALID, @@ -81,6 +93,26 @@ static const struct prot_bits stage2_pte_bits[] = { .val = PTE_TABLE_BIT, .set = " ", .clear = "BLK", + }, { + .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, diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 015ed65d3..6c7208f66 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -177,6 +177,12 @@ static void dump_prot(struct pg_state *st, const struct prot_bits *bits, 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 -- 2.43.0.472.g3155946c3a-goog