From patchwork Mon Dec 18 13:58:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 180444 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1259825dyi; Mon, 18 Dec 2023 06:03:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtqPkHHRYe4rec9J13IhR5xEu8F1Egse00e+w0R5alhlTva81CwmPoKvbNbw0w0IHIrgDR X-Received: by 2002:a17:90b:4a12:b0:28b:2aa5:6003 with SMTP id kk18-20020a17090b4a1200b0028b2aa56003mr1740427pjb.69.1702908184021; Mon, 18 Dec 2023 06:03:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702908184; cv=none; d=google.com; s=arc-20160816; b=0sLCYtvqjndGv04+cQ7FIfbPHMELYgM6QV/VTLuOi9rrIbDvtJbnZlES6QSINT0UR4 dFQQdDMd4uSDklfE9pBvq3oU2eLizGwUo1oCk+QKdNtSkWu/+B8noUfNtGEoY/qa+nb1 3LIJoj3RjIqhdglQvyVjUdEK6quJtdtOlKuZJ/QJglnuJ7n38eEN6vdL2wC+C5r5tuFD BydSUdsqor/UYRnrPAQmK1PqSWU/tw3ddmGr/U9NGg6W+xV8skyRChTOiVkb/gndK3cZ CImKJgzC/WKSheFNydOL9v82KH/ewP/9qnPyvLAD5AFodQtmdqpVw0y2j3RsQhgECrk1 IdiQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3796-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id sh3-20020a17090b524300b0028a30507ff6si18121118pjb.150.2023.12.18.06.03.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 06:03:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3796-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3796-ouuuleilei=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 9B8E7283189 for ; Mon, 18 Dec 2023 14:02:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A544E5A84D; Mon, 18 Dec 2023 14:00:11 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785628651844156570 X-GMAIL-MSGID: 1785628651844156570 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