From patchwork Thu Oct 19 14:40:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155613 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432229vqb; Thu, 19 Oct 2023 07:41:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFl0AGXc04uLgBTtwoB4YXO5oda4UG+kTZfFocN2x/dlU7pr0S+yg5+/Beo1YJdz24TZHOK X-Received: by 2002:a17:90b:1495:b0:27d:3d1e:1a98 with SMTP id js21-20020a17090b149500b0027d3d1e1a98mr3140004pjb.16.1697726489275; Thu, 19 Oct 2023 07:41:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726489; cv=none; d=google.com; s=arc-20160816; b=i5yggXLmSoxv/uo0PmnQR6n3J7R4mSIw5A/Kj3c+pmSgELhfGWdyM4priY/o4NmCpO nGM444G3Yz1fvHxuhNhGrHEHyt7QupLDHjSSM/RYdyaA1S8XAFTAJT/29goJU2NJdRf8 AOrQ+9cFzKltrx/eLcXqnqdi+sbXEYUMBt+aVoiCWhkqSD0SNcznz/La9jwo5o/Ibwl5 t/GBOFtwsagUOs9kGfCouhcuziseIgLgMj2yMhnvKfmMbp8Epj5KjicXGf0er5oiVJ1u ZI4V5tNoRrxUZ1ON2EN3E6TG7+cevtxIUyQvkJtEfWxG0c/kAG/Wy2HA1FU8uskkIlkp IVCg== 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=irFQ7vIeF55X7D9u5W+RRcx8opaM8C3jS63aHLA7bAc=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=0eZivtj73CwsnLXBYQn/txf7Wv1wfG+eIiBEiZaOMzDlhb+3bIQCam6AArymuYs4Xj UFTBXnpbZQC6kMqtSfCnzRluDh0kuJr5VU2+y/cJplQCC2l5ZG+O7J8vOdcyvZkT6IlR 8/6O2z6GN6ewACpJc7OSM4NaRFXSuws6Uhv+qF9/zHj5dKinmmlHoZQkkFHfHtY6ViUU TEcG/GAx02yDz5gWpSfC60pnO/4XEzuAbE7QX165LKQ+b38pLRwQkUrk2wX+ieWlsErH WSgyurNHr8JLkcO8/wDxxIhZaf4q21GVWLOfyT8plReAjzu5lG7acUojzoje2lAIbxl+ 7mPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dw6M0l9V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id pi13-20020a17090b1e4d00b0027d37bb12a6si2269973pjb.49.2023.10.19.07.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:41:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dw6M0l9V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 B11D8831D008; Thu, 19 Oct 2023 07:41:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346184AbjJSOlU (ORCPT + 25 others); Thu, 19 Oct 2023 10:41:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346244AbjJSOlC (ORCPT ); Thu, 19 Oct 2023 10:41:02 -0400 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D767819F for ; Thu, 19 Oct 2023 07:40:58 -0700 (PDT) Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-32da47641b5so3245237f8f.0 for ; Thu, 19 Oct 2023 07:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726456; x=1698331256; 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=irFQ7vIeF55X7D9u5W+RRcx8opaM8C3jS63aHLA7bAc=; b=dw6M0l9Vn5e5um04nwj+TMG74kz79Jt3XloJl1liicKmNTg4H9BmhepT/fTpiEY2m9 bM2cWQ4utXql0EGd5P6FP76FKn/6HjU7mtlZMwNPbARqBsR3Q/1HhmnbcoUwT+Kx7TqG L4WCyJFOIp7hNZYSyv12uLjYBPo5chFO0eemstPBzD9EKuHa+kR5uqrCllQgFSTYAVco BG1rryErxuVQRJBg2nl/eHFZA0nmE2ptzOAM5l3QKVVREHkd/M4+tO3fKswV7yaaFaOO 7Cnb1Ot4Vnjwst8T5kSZE/ZM9q9PawZqVK+1xHWiGYidTFF4nJq6+B5VqJqpu/52eIRa iPfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726456; x=1698331256; 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=irFQ7vIeF55X7D9u5W+RRcx8opaM8C3jS63aHLA7bAc=; b=LTdER/fz5BgM/iIsoU4u2kL3he2XxsS+BYEj7KCefVPfogP+jrF8GG0nrDJDXXOOXG brV1/ZjQ6SQDXHJEvpLAQ6CBiDrDOjEPOXbBBv8Ja6NqLEDpkm/XEQ7oNbMgFptMSdRd dUfg92opHa2lJCUkhNaZyY8M1Du4t43GmuKFVQmcXagYNB8Spb4OWOSZQnuiI4XkJz7d 3ca88+VTRnyL93OWqyX0P6ZXQHChcwV82J+G8rFuVHPh6H2RZRsJW910c0V4bItVHGTF /I7BlOWMAHs3pnpVhQo0XsnT5ryp3dGiNxc5AmrzjyR70daAsjuz9D6QmGcLV0w3UQEQ jARw== X-Gm-Message-State: AOJu0Yxwh8KBbSEvCrjUjEGmJkXfDipwfzdyZBzEKEaCQI26wxvQzZTS IRmLNr1/W6b5lZnmzTcb1N0flnbxwqKYccHSnFE= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a05:6000:1372:b0:32d:a860:3257 with SMTP id q18-20020a056000137200b0032da8603257mr19560wrz.13.1697726456175; Thu, 19 Oct 2023 07:40:56 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:27 +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-7-sebastianene@google.com> Subject: [PATCH v2 05/11] arm64: ptdump: Introduce stage-2 pagetables format description 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-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,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]); Thu, 19 Oct 2023 07:41:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195251463238455 X-GMAIL-MSGID: 1780195251463238455 Add an array which holds human readable information about the format of a stage-2 descriptor. The array is then used by the descriptor parser to extract information about the memory attributes. Signed-off-by: Sebastian Ene --- arch/arm64/mm/ptdump.c | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index d531e24ea0b2..58a4ea975497 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -24,6 +24,7 @@ #include #include #include +#include enum address_markers_idx { @@ -171,6 +172,66 @@ static const struct prot_bits pte_bits[] = { } }; +static const struct prot_bits stage2_pte_bits[] = { + { + .mask = PTE_VALID, + .val = PTE_VALID, + .set = " ", + .clear = "F", + }, { + .mask = KVM_PTE_LEAF_ATTR_HI_S2_XN, + .val = KVM_PTE_LEAF_ATTR_HI_S2_XN, + .set = "XN", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R, + .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R, + .set = "R", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W, + .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W, + .set = "W", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_AF, + .val = KVM_PTE_LEAF_ATTR_LO_S2_AF, + .set = "AF", + .clear = " ", + }, { + .mask = PTE_NG, + .val = PTE_NG, + .set = "FnXS", + .clear = " ", + }, { + .mask = PTE_CONT, + .val = PTE_CONT, + .set = "CON", + .clear = " ", + }, { + .mask = PTE_TABLE_BIT, + .val = PTE_TABLE_BIT, + .set = " ", + .clear = "BLK", + }, { + .mask = KVM_PGTABLE_PROT_SW0, + .val = KVM_PGTABLE_PROT_SW0, + .set = "SW0", /* PKVM_PAGE_SHARED_OWNED */ + }, { + .mask = KVM_PGTABLE_PROT_SW1, + .val = KVM_PGTABLE_PROT_SW1, + .set = "SW1", /* PKVM_PAGE_SHARED_BORROWED */ + }, { + .mask = KVM_PGTABLE_PROT_SW2, + .val = KVM_PGTABLE_PROT_SW2, + .set = "SW2", + }, { + .mask = KVM_PGTABLE_PROT_SW3, + .val = KVM_PGTABLE_PROT_SW3, + .set = "SW3", + }, +}; + struct pg_level { const struct prot_bits *bits; const char *name; @@ -202,6 +263,26 @@ static struct pg_level pg_level[] = { }, }; +static struct pg_level stage2_pg_level[] = { + { /* pgd */ + .name = "PGD", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, { /* pud */ + .name = (CONFIG_PGTABLE_LEVELS > 3) ? "PUD" : "PGD", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, { /* pmd */ + .name = (CONFIG_PGTABLE_LEVELS > 2) ? "PMD" : "PGD", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, { /* pte */ + .name = "PTE", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, +}; + static void dump_prot(struct pg_state *st, const struct prot_bits *bits, size_t num) { @@ -340,6 +421,12 @@ static void __init ptdump_initialize(void) if (pg_level[i].bits) for (j = 0; j < pg_level[i].num; j++) pg_level[i].mask |= pg_level[i].bits[j].mask; + + for (i = 0; i < ARRAY_SIZE(stage2_pg_level); i++) + if (stage2_pg_level[i].bits) + for (j = 0; j < stage2_pg_level[i].num; j++) + stage2_pg_level[i].mask |= + stage2_pg_level[i].bits[j].mask; } static struct ptdump_info kernel_ptdump_info = {