From patchwork Fri Aug 16 12:39:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13766067 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 8C636C52D7D for ; Fri, 16 Aug 2024 12:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nI6i7YX14nljpUXmJtSY/UgyOMgnkcqXo7+aUg8YmfE=; b=N6z9hNX8E653yTUHLrDaglP+Gt mKo3QLFzimnN+FDurW0+h4UFkEhH1QjpmT5m1tI65/mIhlkVWOY4jCg/c2UBUmILzbbmaaF3lSwOI NNo/oP3VxZrBHeD1B2Gq0Gj4jbDWPR+njdo3KQ3l+Cg1P4UURwZkS7628gzLEDGIwKn3p8e9Yg3vH pyFsKKd+NbmkruqsXh6MMcYdf2YNQBekQtW4WvPkAmYWDg1LY3Ws6CK38kHRSUObhMS27BCk2QZGz d3pusx2fzGos9zzgVKDccpithI3LDEi1jUR2NW86qnYolSej3SVPkZXv6xswgPRJMUtYfmB8Y5pW9 1wo+q17A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewFz-0000000CuOW-1JVJ; Fri, 16 Aug 2024 12:40:39 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewEg-0000000Cu2J-1Y8R for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 12:39:19 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6b052c5939cso15706867b3.1 for ; Fri, 16 Aug 2024 05:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723811956; x=1724416756; 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=nI6i7YX14nljpUXmJtSY/UgyOMgnkcqXo7+aUg8YmfE=; b=tpd7B73AYgeSNMqk5+XaNbqaQ/xhQ4tbEFz+ab5YTKuHiibZrQOsJIs7Sf5ukbz+Fu bBOr6tgR+Nv7NuRIqxs6Ql5bml4SITdKPVrwPhPwO5zlbN3ARQl9PBpd9zqMIbdZVEOf 83RI9NroO3FGxbR9xfOc8eaQqG2ljbX7TYbnMtuWsmsEmZnn+Dna0Kid0sc+5mhOjQrq 3cQJDf23u+krvuSJBpC2upl1btQ0rExy8pzXJepR1sY+vdWK0hpRZSBrK559BoYYVtGD Gre7Vob94H1cZffaIF3/qF5lJIqJ87hTzLe4p8yVMV3KwJS+qzHg7hqaFanR/UVMqwlE t5Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723811956; x=1724416756; 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=nI6i7YX14nljpUXmJtSY/UgyOMgnkcqXo7+aUg8YmfE=; b=Jo6ZC6ctI/HLoEecQER4QYBluI2WaYyos4dG4Xc9niHkFZRilIPZqKVMFRoe/NlnUB YULE6TiItHhNsqIzC8T9SvsGjU0LQrbokSSBYspfCQd3XTlJWAji2mQwKFuyRQ9pOUk8 mQwYkphp23jr4utItq1MliKacvyIsisergZIuvvaL9uKs/4RGUmo95F7QxArZBcaj+ux NDnhY72jUObo4ycZjLBxTSgV3yd5WSPyfAOXokPTXXGcFUYidPsDAifRyLEXnLr4LA1F Aq9G96dVyl883ZwtMzeeWre+6ckA5T8Wtc5p6+qKHwRQcjFsiKECQ86DUPacv8BIUy8b VpGg== X-Forwarded-Encrypted: i=1; AJvYcCUyrkjfpy4cZxF83nh4rz8KyNarmZrOCw272Io3ZT+ge52ABR+ro8y0yAzxy063VjljpTD61M+BJ4iYd3zh1v7YtyYnp7knXYSwr8UFEHonkvOWbGk= X-Gm-Message-State: AOJu0Yy9qR3oyWCBl57NbQEf/2kPMW0G3wubQ3wt/2E5XqysettZfjqz irNk5nb4xrcD8D87ceBZdQYL4Ax514e6azawbZ7OeNBRobMZskh9U3L2kKvYY9pv8lTxHM+yLp5 K0vOVVE0b+Kip1KZVkFYeEV+fTg== X-Google-Smtp-Source: AGHT+IGBZXo0joGkpRiMwmJyr97s6u1s6BZU4K3nLmENh0HF/8kX9FtEm3bAcQpjCF+W1kNezc9xW+sgWbb25EB7K5s= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:690c:3405:b0:691:a38c:a61d with SMTP id 00721157ae682-6b1d7ef3527mr730297b3.3.1723811956425; Fri, 16 Aug 2024 05:39:16 -0700 (PDT) Date: Fri, 16 Aug 2024 12:39:01 +0000 In-Reply-To: <20240816123906.3683425-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240816123906.3683425-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240816123906.3683425-2-sebastianene@google.com> Subject: [PATCH v8 1/6] KVM: arm64: Move pagetable definitions to common header From: Sebastian Ene To: akpm@linux-foundation.org, alexghiti@rivosinc.com, ankita@nvidia.com, ardb@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, james.morse@arm.com, vdonnefort@google.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ryan.roberts@arm.com, sebastianene@google.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240816_053918_432046_3797A536 X-CRM114-Status: GOOD ( 11.42 ) 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 In preparation for using the stage-2 definitions in ptdump, move some of these macros in the common header. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/kvm_pgtable.h | 42 ++++++++++++++++++++++++++++ arch/arm64/kvm/hyp/pgtable.c | 42 ---------------------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 19278dfe7978..03f4c3d7839c 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -59,6 +59,48 @@ typedef u64 kvm_pte_t; #define KVM_PHYS_INVALID (-1ULL) +#define KVM_PTE_LEAF_ATTR_LO GENMASK(11, 2) + +#define KVM_PTE_LEAF_ATTR_LO_S1_ATTRIDX GENMASK(4, 2) +#define KVM_PTE_LEAF_ATTR_LO_S1_AP GENMASK(7, 6) +#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RO \ + ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 2 : 3; }) +#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RW \ + ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 0 : 1; }) +#define KVM_PTE_LEAF_ATTR_LO_S1_SH GENMASK(9, 8) +#define KVM_PTE_LEAF_ATTR_LO_S1_SH_IS 3 +#define KVM_PTE_LEAF_ATTR_LO_S1_AF BIT(10) + +#define KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR GENMASK(5, 2) +#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R BIT(6) +#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W BIT(7) +#define KVM_PTE_LEAF_ATTR_LO_S2_SH GENMASK(9, 8) +#define KVM_PTE_LEAF_ATTR_LO_S2_SH_IS 3 +#define KVM_PTE_LEAF_ATTR_LO_S2_AF BIT(10) + +#define KVM_PTE_LEAF_ATTR_HI GENMASK(63, 50) + +#define KVM_PTE_LEAF_ATTR_HI_SW GENMASK(58, 55) + +#define KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54) + +#define KVM_PTE_LEAF_ATTR_HI_S2_XN BIT(54) + +#define KVM_PTE_LEAF_ATTR_HI_S1_GP BIT(50) + +#define KVM_PTE_LEAF_ATTR_S2_PERMS (KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \ + KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \ + KVM_PTE_LEAF_ATTR_HI_S2_XN) + +#define KVM_INVALID_PTE_OWNER_MASK GENMASK(9, 2) +#define KVM_MAX_OWNER_ID 1 + +/* + * Used to indicate a pte for which a 'break-before-make' sequence is in + * progress. + */ +#define KVM_INVALID_PTE_LOCKED BIT(10) + static inline bool kvm_pte_valid(kvm_pte_t pte) { return pte & KVM_PTE_VALID; diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 9e2bbee77491..c3e9d77bba23 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -17,48 +17,6 @@ #define KVM_PTE_TYPE_PAGE 1 #define KVM_PTE_TYPE_TABLE 1 -#define KVM_PTE_LEAF_ATTR_LO GENMASK(11, 2) - -#define KVM_PTE_LEAF_ATTR_LO_S1_ATTRIDX GENMASK(4, 2) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP GENMASK(7, 6) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RO \ - ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 2 : 3; }) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RW \ - ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 0 : 1; }) -#define KVM_PTE_LEAF_ATTR_LO_S1_SH GENMASK(9, 8) -#define KVM_PTE_LEAF_ATTR_LO_S1_SH_IS 3 -#define KVM_PTE_LEAF_ATTR_LO_S1_AF BIT(10) - -#define KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR GENMASK(5, 2) -#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R BIT(6) -#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W BIT(7) -#define KVM_PTE_LEAF_ATTR_LO_S2_SH GENMASK(9, 8) -#define KVM_PTE_LEAF_ATTR_LO_S2_SH_IS 3 -#define KVM_PTE_LEAF_ATTR_LO_S2_AF BIT(10) - -#define KVM_PTE_LEAF_ATTR_HI GENMASK(63, 50) - -#define KVM_PTE_LEAF_ATTR_HI_SW GENMASK(58, 55) - -#define KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54) - -#define KVM_PTE_LEAF_ATTR_HI_S2_XN BIT(54) - -#define KVM_PTE_LEAF_ATTR_HI_S1_GP BIT(50) - -#define KVM_PTE_LEAF_ATTR_S2_PERMS (KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \ - KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \ - KVM_PTE_LEAF_ATTR_HI_S2_XN) - -#define KVM_INVALID_PTE_OWNER_MASK GENMASK(9, 2) -#define KVM_MAX_OWNER_ID 1 - -/* - * Used to indicate a pte for which a 'break-before-make' sequence is in - * progress. - */ -#define KVM_INVALID_PTE_LOCKED BIT(10) - struct kvm_pgtable_walk_data { struct kvm_pgtable_walker *walker; From patchwork Fri Aug 16 12:39:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13766073 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 67CBDC3DA4A for ; Fri, 16 Aug 2024 12:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=j47oMByzJ24KyTFsD9yy6iWyScsZt9QoCMZTVk2qdfo=; b=W8GYSVKYuQzVM/Csfe8W8I9ZeW fWtX30JyrkzuPjBBj4DMMzdQubZRjAZnZ+OdpoikrCDw4RKF1g9Ux39nLplmV3d4MgyBp7Qc/MEqA 1UOYi183ubp3msDtsRr2QRNj97WsH1ricbghcrjAPHvGvcmaoOKt7ADpxNjGRANdLCqTIzh7R1gdj Ew15qLBCNWMWzJoMfyX6XLb9ozjMyvtrOjSnl3nPaZMVehj46C5MDfZlxUteGtGt5wGYud3Ts4WgL J0PelwyJ0bpFPGSYQds8fAfvybX5slND5j170X8hQs7Xq+ZvzoO5zQLM+DKRqmPuhHcI8t9chmjNT n1tCSJKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewGb-0000000CuW1-0xUb; Fri, 16 Aug 2024 12:41:17 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewEj-0000000Cu2m-14QU for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 12:39:22 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-4280645e3e0so13602985e9.1 for ; Fri, 16 Aug 2024 05:39:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723811959; x=1724416759; 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=j47oMByzJ24KyTFsD9yy6iWyScsZt9QoCMZTVk2qdfo=; b=W/za2hysDVAYzN8evqiwykmzBvIMwLWYDE71JJbD19ok17B9Fa7xlvJD3WZVCeJhx1 4BX7bOgB+o4DhemB8e7Ufhzaw3sZZHeJcez37c2/MHOEOQgvPugqXJddFHWXF4SQanCI 4owwRMKdTaatkPl0Ndc620nzO82RDR410XB1ViaGAioPLiVUv3JZl5D8YCsV+HfkcjN1 007oTIQ4+1mjxafVKMgAAQITXLpuPi6t4iObmgnExNDqrMh4TjoolBr8tU0AIO1xc8YH +0EA7k2v7Wam/xQLlrxa+7oKks+k1hReZqQVr7d7X9ZjWt3kolxqjYXq7QrvjtHTvW/C vikg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723811959; x=1724416759; 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=j47oMByzJ24KyTFsD9yy6iWyScsZt9QoCMZTVk2qdfo=; b=TexaYmL92k0+WPDEcJ26poc3u2nm2McBId0AqlO0go9yb7eCdNQN3ngsN66g7fs26k LqFsg1/6xLFfy8FvZMzX1g85ZIDlR0IIOs6OdXjr5UFL6TU6faR4nLCVdHKmoGuUUtsd AD2gowhukb3MTswbMbz4YdKk3JOdyeb4HVWeaTGQEXH8tUPjw9+xmYuticZnRs5SuEdb 9aSex6oIBOsp8GTyOfGBAxduPY26y/AiUYP2vwviH139ShzhvrJiw5l+NU2TEBrBmckz buuQwRKHB6vz0jqPT+WwIsYsAFoSxF1/pl97ZjgaUhfSHlk0m/RyV4XiWkNosIYR1rCI ZXiA== X-Forwarded-Encrypted: i=1; AJvYcCX/giflybJysSWZk1XtdYs8O/jiwnvguXXUuD48ZAPrhEhqXVGcRmFo7fAzwQaCZi8sR0VbANCU1s+V3hBd4Tinn2MNDJlmwLRJgkaYsPaC+0cUfGM= X-Gm-Message-State: AOJu0Ywi8WP85VB/3i5Tvr3x+Nm3Xar4n212rIDzZYlVU84nn7L4Evrz 9zOx2U6/lWmRYJHIIraz3G6Dgiakdfnv9uFBEbmjgPEWxCBf5r0wRzBsI177WDcKyUwzXXsUoRe 2Gq/VR82bg66tqbvIPYzLNzjrFQ== X-Google-Smtp-Source: AGHT+IHY+evZi+M0pBKraTT8P2CDheqGUjf1GzHxhiMrm6b9MgqKZzrCDiy/xU7sxesCTtcgx0h+YUSn4Xyp/2hiU3k= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:600c:3b09:b0:429:d0bb:e3f3 with SMTP id 5b1f17b1804b1-429ed7e38d2mr149595e9.7.1723811958600; Fri, 16 Aug 2024 05:39:18 -0700 (PDT) Date: Fri, 16 Aug 2024 12:39:02 +0000 In-Reply-To: <20240816123906.3683425-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240816123906.3683425-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240816123906.3683425-3-sebastianene@google.com> Subject: [PATCH v8 2/6] arm64: ptdump: Expose the attribute parsing functionality From: Sebastian Ene To: akpm@linux-foundation.org, alexghiti@rivosinc.com, ankita@nvidia.com, ardb@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, james.morse@arm.com, vdonnefort@google.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ryan.roberts@arm.com, sebastianene@google.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240816_053921_320752_E4A04FD5 X-CRM114-Status: GOOD ( 19.83 ) 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 Reuse the descriptor parsing functionality to keep the same output format as the original ptdump code. In order for this to happen, move the state tracking objects into a common header. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 41 +++++++++++++++++++++++- arch/arm64/mm/ptdump.c | 55 +++++++-------------------------- 2 files changed, 51 insertions(+), 45 deletions(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 5b1701c76d1c..bd5d3ee3e8dc 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -9,6 +9,7 @@ #include #include +#include struct addr_marker { unsigned long start_address; @@ -21,14 +22,52 @@ struct ptdump_info { unsigned long base_addr; }; +struct ptdump_prot_bits { + u64 mask; + u64 val; + const char *set; + const char *clear; +}; + +struct ptdump_pg_level { + const struct ptdump_prot_bits *bits; + char name[4]; + int num; + u64 mask; +}; + +/* + * The page dumper groups page table entries of the same type into a single + * description. It uses pg_state to track the range information while + * iterating over the pte entries. When the continuity is broken it then + * dumps out a description of the range. + */ +struct ptdump_pg_state { + struct ptdump_state ptdump; + struct seq_file *seq; + const struct addr_marker *marker; + const struct mm_struct *mm; + unsigned long start_address; + int level; + u64 current_prot; + bool check_wx; + unsigned long wx_pages; + unsigned long uxn_pages; +}; + void ptdump_walk(struct seq_file *s, struct ptdump_info *info); +void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, + u64 val); #ifdef CONFIG_PTDUMP_DEBUGFS #define EFI_RUNTIME_MAP_END DEFAULT_MAP_WINDOW_64 void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name); #else static inline void ptdump_debugfs_register(struct ptdump_info *info, const char *name) { } -#endif +#endif /* CONFIG_PTDUMP_DEBUGFS */ +#else +static inline void note_page(void *pt_st, unsigned long addr, + int level, u64 val) { } #endif /* CONFIG_PTDUMP_CORE */ #endif /* __ASM_PTDUMP_H */ diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 6986827e0d64..404751fd30fe 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -38,33 +38,7 @@ seq_printf(m, fmt); \ }) -/* - * The page dumper groups page table entries of the same type into a single - * description. It uses pg_state to track the range information while - * iterating over the pte entries. When the continuity is broken it then - * dumps out a description of the range. - */ -struct pg_state { - struct ptdump_state ptdump; - struct seq_file *seq; - const struct addr_marker *marker; - const struct mm_struct *mm; - unsigned long start_address; - int level; - u64 current_prot; - bool check_wx; - unsigned long wx_pages; - unsigned long uxn_pages; -}; - -struct prot_bits { - u64 mask; - u64 val; - const char *set; - const char *clear; -}; - -static const struct prot_bits pte_bits[] = { +static const struct ptdump_prot_bits pte_bits[] = { { .mask = PTE_VALID, .val = PTE_VALID, @@ -143,14 +117,7 @@ static const struct prot_bits pte_bits[] = { } }; -struct pg_level { - const struct prot_bits *bits; - char name[4]; - int num; - u64 mask; -}; - -static struct pg_level pg_level[] __ro_after_init = { +static struct ptdump_pg_level pg_level[] __ro_after_init = { { /* pgd */ .name = "PGD", .bits = pte_bits, @@ -174,7 +141,7 @@ static struct pg_level pg_level[] __ro_after_init = { }, }; -static void dump_prot(struct pg_state *st, const struct prot_bits *bits, +static void dump_prot(struct ptdump_pg_state *st, const struct ptdump_prot_bits *bits, size_t num) { unsigned i; @@ -192,7 +159,7 @@ static void dump_prot(struct pg_state *st, const struct prot_bits *bits, } } -static void note_prot_uxn(struct pg_state *st, unsigned long addr) +static void note_prot_uxn(struct ptdump_pg_state *st, unsigned long addr) { if (!st->check_wx) return; @@ -206,7 +173,7 @@ static void note_prot_uxn(struct pg_state *st, unsigned long addr) st->uxn_pages += (addr - st->start_address) / PAGE_SIZE; } -static void note_prot_wx(struct pg_state *st, unsigned long addr) +static void note_prot_wx(struct ptdump_pg_state *st, unsigned long addr) { if (!st->check_wx) return; @@ -221,10 +188,10 @@ static void note_prot_wx(struct pg_state *st, unsigned long addr) st->wx_pages += (addr - st->start_address) / PAGE_SIZE; } -static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, - u64 val) +void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, + u64 val) { - struct pg_state *st = container_of(pt_st, struct pg_state, ptdump); + struct ptdump_pg_state *st = container_of(pt_st, struct ptdump_pg_state, ptdump); static const char units[] = "KMGTPE"; u64 prot = 0; @@ -286,12 +253,12 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, void ptdump_walk(struct seq_file *s, struct ptdump_info *info) { unsigned long end = ~0UL; - struct pg_state st; + struct ptdump_pg_state st; if (info->base_addr < TASK_SIZE_64) end = TASK_SIZE_64; - st = (struct pg_state){ + st = (struct ptdump_pg_state){ .seq = s, .marker = info->markers, .mm = info->mm, @@ -324,7 +291,7 @@ static struct ptdump_info kernel_ptdump_info __ro_after_init = { bool ptdump_check_wx(void) { - struct pg_state st = { + struct ptdump_pg_state st = { .seq = NULL, .marker = (struct addr_marker[]) { { 0, NULL}, From patchwork Fri Aug 16 12:39:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13766074 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 25A85C52D7D for ; Fri, 16 Aug 2024 12:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TOVsSjbkFKkupVHDdUClsSrj3QZ/4GeILHKaUawEmW8=; b=A2N5YUpJPDBbbDfp4ik7+WVdTV cL1/wd/JvxrHz2RMc7Ehd6lBskic3BZND8SsVpd3gxi/rNjeafZMWjrd5thHUc7Jgg51DmsMDDYJn jimMStZ+a1NO5JZl07RmP8X19adYByJXTI/jQKCHEuAilmsVs+FvFyPhEin3BjbnbrqZES0BatAzq Xed6xz+gLdrgvv7ZmssWQuMLBwk57MAcalPwmxNWmrUNxn8dEvKnjsAVRdt1e2HiFCUd8GbtEyMm2 uaGxxD7Caug2MMMFlolY2DkkOuMK/h6ekeqoehruoQf9wCD8kmvlBGOBQRIzf0ZcpqAb2Z4aPDoel d5cE5o8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewHD-0000000CubR-0zq3; Fri, 16 Aug 2024 12:41:55 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewEm-0000000Cu3F-4188 for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 12:39:26 +0000 Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-3719ee7c72eso98163f8f.0 for ; Fri, 16 Aug 2024 05:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723811961; x=1724416761; 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=TOVsSjbkFKkupVHDdUClsSrj3QZ/4GeILHKaUawEmW8=; b=O4VZDn+jgTyKw0jw4CULKqiZvSAMyLSNbw0vjfswCiMCeM+gMPSF4auRbkdjYTi2aB raBsQWHIXC2ChXpfiEcwUzaZB665smZSVfHx2eckVKy4VxG8IJNopPp/UcMd/QmBa/6e vGzMFh+rIy0Jf2nRZ9vPmD3WAk1lvE/kFT7H7XFyZ3GR/4NbuGXMpLbbXlRiV2ub+9e0 YGFwmt9HL0VQMbjpww21SUllulGkKXLnKKNSiF0favRio1lWDCD5Xu+J1OnpIv4ZQzgt m3j3WUi+IvpDAZGinGeIZzSskqrW4GwjmZZz2Fy/pMcAiilidt0aErSE299CaGC8vsrt WUQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723811961; x=1724416761; 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=TOVsSjbkFKkupVHDdUClsSrj3QZ/4GeILHKaUawEmW8=; b=mOEhT677y2kvH8ge58hJBvMfgjICZjTeVVbqxrCZgYXZK1MtD3Q9ZWUOZ8BlOtRtft NcR69hl6KBiqGEE5CPv53ylhnTOJ2tOGVSGJv8u2lL2/I65zx6+kPw0lOdR1EwZTFvEb CnLM+P3grWI8SmNCOkb5XslAE0P9ALD0n1Y+HIJ/Qyx8+FGKT3fKFL3/BpDn/FoEScTH lfKxEywLCF+UeSNd1niD7FiNxOb7j+pyddmqYQCGyUCj4URjyxZRXq0Odr6ztJ+0yawI q4XWqwnYCd+6ayTW0vtU5SxngZNyKxBKHURDKcgzPrHSA95QO4KJta78DnF9Pm4GRyGe WrSw== X-Forwarded-Encrypted: i=1; AJvYcCWGfM+Y53bM7Fhqk7YZzKWfqZMDmM3xuti1snOKiKzVcBy87GOSGYLpfbk3HH61YTfTwvs5BAUksNj3ovl33l8e5fZjfeqJcw3P89EiVJ526GYaywA= X-Gm-Message-State: AOJu0YxldxUjmOxBNoz/VwHRrvjeKQleFU8WkK/uuj1o5gAHlNbvupXY HbfYxCPE+9+FCIDqZDQyZK8eXK4kl3q5VnqxtshNm8Ykn1faTpfdp83Cm7CaVoGDaaqe7GpDmat YljodjAVfpVVp7squcnti0+kq8g== X-Google-Smtp-Source: AGHT+IHcICbWJmK89n8rtw3CIsZCVnNXfh2Wfm6YpkzCdhB56aOnbSeNarXn8GFhkvmcCHzcvJ1/hlKucHN9pFgTZco= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a5d:6449:0:b0:371:8685:846 with SMTP id ffacd0b85a97d-3719465d24fmr4614f8f.8.1723811960947; Fri, 16 Aug 2024 05:39:20 -0700 (PDT) Date: Fri, 16 Aug 2024 12:39:03 +0000 In-Reply-To: <20240816123906.3683425-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240816123906.3683425-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240816123906.3683425-4-sebastianene@google.com> Subject: [PATCH v8 3/6] arm64: ptdump: Use the mask from the state structure From: Sebastian Ene To: akpm@linux-foundation.org, alexghiti@rivosinc.com, ankita@nvidia.com, ardb@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, james.morse@arm.com, vdonnefort@google.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ryan.roberts@arm.com, sebastianene@google.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240816_053925_023164_FAB2B0BC X-CRM114-Status: GOOD ( 20.27 ) 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 Printing the descriptor attributes requires accessing a mask which has a different set of attributes for stage-2. In preparation for adding support for the stage-2 pagetables dumping, use the mask from the local context and not from the globally defined pg_level array. Store a pointer to the pg_level array in the ptdump state structure. This will allow us to extract the mask which is wrapped in the pg_level array and use it for descriptor parsing in the note_page. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 1 + arch/arm64/mm/ptdump.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index bd5d3ee3e8dc..71a7ed01153a 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -44,6 +44,7 @@ struct ptdump_pg_level { */ struct ptdump_pg_state { struct ptdump_state ptdump; + struct ptdump_pg_level *pg_level; struct seq_file *seq; const struct addr_marker *marker; const struct mm_struct *mm; diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 404751fd30fe..ca53ef274a8b 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -117,7 +117,7 @@ static const struct ptdump_prot_bits pte_bits[] = { } }; -static struct ptdump_pg_level pg_level[] __ro_after_init = { +static struct ptdump_pg_level kernel_pg_levels[] __ro_after_init = { { /* pgd */ .name = "PGD", .bits = pte_bits, @@ -192,6 +192,7 @@ void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, u64 val) { struct ptdump_pg_state *st = container_of(pt_st, struct ptdump_pg_state, ptdump); + struct ptdump_pg_level *pg_level = st->pg_level; static const char units[] = "KMGTPE"; u64 prot = 0; @@ -262,6 +263,7 @@ void ptdump_walk(struct seq_file *s, struct ptdump_info *info) .seq = s, .marker = info->markers, .mm = info->mm, + .pg_level = &kernel_pg_levels[0], .level = -1, .ptdump = { .note_page = note_page, @@ -279,10 +281,10 @@ static void __init ptdump_initialize(void) { unsigned i, j; - for (i = 0; i < ARRAY_SIZE(pg_level); i++) - 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(kernel_pg_levels); i++) + if (kernel_pg_levels[i].bits) + for (j = 0; j < kernel_pg_levels[i].num; j++) + kernel_pg_levels[i].mask |= kernel_pg_levels[i].bits[j].mask; } static struct ptdump_info kernel_ptdump_info __ro_after_init = { @@ -297,6 +299,7 @@ bool ptdump_check_wx(void) { 0, NULL}, { -1, NULL}, }, + .pg_level = &kernel_pg_levels[0], .level = -1, .check_wx = true, .ptdump = { From patchwork Fri Aug 16 12:39:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13766075 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 B84F7C3DA4A for ; Fri, 16 Aug 2024 12:42:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=czjtgk0THntC/xnLf2aWE5vi1aKv5GZ9fmo01l7czSk=; b=w/q7zTwglRzAzzt9N6HG7mgoR9 pmnAYLf9koA+x7iLJ+Zd5u9CAYnSKmiHUbuyShLbdvHl9B41Ddyiv+7MRuVHNTbscDlsCNq4xMZPQ QibHYipGn+gGKBN7wlR0bssvHpwIcJMypsUJ6T4LtVIWSS+GENlu+gR8w63/b3zWKoqTaiGo8F492 PhBpwDX26rQjXsFq3kJNn/Pu9fY2om+h4i8Icyc3hkEb5cx+1dkaw43EjhKu0+aTYfOSITzOVikMN E4FRuPmMbaX/FgYldvCdSQyJoCe2Q9K/4LaI3H5XTgJaEXbxzTVpp4zdcJtwZErwJ7i3s+2TGQEoB lw5glgzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewHq-0000000Cuic-06wi; Fri, 16 Aug 2024 12:42:34 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewEn-0000000Cu3P-3oID for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 12:39:28 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e02fff66a83so3337801276.0 for ; Fri, 16 Aug 2024 05:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723811964; x=1724416764; 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=czjtgk0THntC/xnLf2aWE5vi1aKv5GZ9fmo01l7czSk=; b=kLklHGx93LszVrNrKJHKL7YyGIojs7RlvXDK25War6ASOZPC5mVoh9mOE5rDTiMZdz JRTAlezWDMFDCVLXFksZkfus4wy2b4Bqx2srkfTN1NH8LMdwjdzr2zBVfJm86OGkcfkc i3Cx4ho+BZeC38+jglbWFbvQpqqs4zzvs4EuX8jYat0PoC9xhWtrJGVT/K8+pLVqgmTL 0MzlpGg8FmBvLIuvuF3QpTzzadXolXyP+SVb4Cny07VzQsvh0XoMCXQZg4gPoy5MaOe1 hZLs+fdjRkfK7ypzqAq92ib3K7TQyB2QatN7c4JG2Ek/S7MAzGLvtRI45KJi7Rpm1GR3 YxYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723811964; x=1724416764; 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=czjtgk0THntC/xnLf2aWE5vi1aKv5GZ9fmo01l7czSk=; b=t+Z3XBXvY8yJeE83lPWP73OCnY3UcB71q5vQ9MXSfDA1SVM7zYswDNnpq66/qApIpy tReWdCbVTNDp1iSRiMmkUtsPazN/2ea+LOs3Y7mwaVXfvZs7mPqPfkkuseDnDr5WO4xU MXs0G23og6srZmpLti+lc3T/vT+Q9L6eHvGNQpSCU3w4iFJauFlS2rMNOWT21t+gDvuU W1PRxI5IDhW/u10/91kBLKeCaTDtTN4ax28AfnJS/kSep6OsRhX0buXouH/ri++WfS2j s2j6uXsXN8NZJHSfmUUlmXn1ay3lI9qnKo5EWwIH4JAS/3GDJDKa0T9N6RIddELqbNr+ NAkA== X-Forwarded-Encrypted: i=1; AJvYcCUAtEpROOM4BIfg3ApCljeCVadROlJU+uwcXxFE+ORFpnQsbfYP5mectsXFUZcCSgQUmnezHevUH8oaLypIitNpevO9Z3C5Ofj29jC6kjN1stCCQX8= X-Gm-Message-State: AOJu0YzYG0Te0XR9d9IjefE/lXp78BsTX02x28/SybYAelA5FLySaHU2 NJEwN8zeqOJ8B7gxTgJFud/HDoKpzuBZgFFJeu5XcrbtxH16f8UqZsggJOwroU0yKvksDqQBbHs llKPlwGC0aBCqgbeoTvwXNQY7MA== X-Google-Smtp-Source: AGHT+IEBl2Jwr492NkaB67XJngVIdAPNlygBC/0Vw/Bc+AHOUtSwJrRm/7vBBySziaJP1f/tml+FbOFt7tZsvUVVL0c= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a25:910e:0:b0:e03:59e2:e82 with SMTP id 3f1490d57ef6-e1180fb2b4dmr4115276.10.1723811963785; Fri, 16 Aug 2024 05:39:23 -0700 (PDT) Date: Fri, 16 Aug 2024 12:39:04 +0000 In-Reply-To: <20240816123906.3683425-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240816123906.3683425-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240816123906.3683425-5-sebastianene@google.com> Subject: [PATCH v8 4/6] KVM: arm64: Register ptdump with debugfs on guest creation From: Sebastian Ene To: akpm@linux-foundation.org, alexghiti@rivosinc.com, ankita@nvidia.com, ardb@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, james.morse@arm.com, vdonnefort@google.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ryan.roberts@arm.com, sebastianene@google.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240816_053925_988953_641F4FE7 X-CRM114-Status: GOOD ( 23.36 ) 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 While arch/*/mem/ptdump handles the kernel pagetable dumping code, introduce KVM/ptdump which shows the guest stage-2 pagetables. The separation is necessary because most of the definitions from the stage-2 pagetable reside in the KVM path and we will be invoking functionality **specific** to KVM. When a guest is created, register a new file entry under the guest debugfs dir which allows userspace to show the contents of the guest stage-2 pagetables when accessed. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/Kconfig | 14 ++++++ arch/arm64/kvm/Makefile | 1 + arch/arm64/kvm/arm.c | 2 + arch/arm64/kvm/kvm_ptdump.h | 20 ++++++++ arch/arm64/kvm/ptdump.c | 91 +++++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+) create mode 100644 arch/arm64/kvm/kvm_ptdump.h create mode 100644 arch/arm64/kvm/ptdump.c diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 8304eb342be9..fcc41e58ede6 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -66,4 +66,18 @@ config PROTECTED_NVHE_STACKTRACE If unsure, or not using protected nVHE (pKVM), say N. +config PTDUMP_STAGE2_DEBUGFS + bool "Present the stage-2 pagetables to debugfs" + depends on KVM + select PTDUMP_CORE + default n + help + Say Y here if you want to show the stage-2 kernel pagetables + layout in a debugfs file. This information is only useful for kernel developers + who are working in architecture specific areas of the kernel. + It is probably not a good idea to enable this feature in a production + kernel. + + If in doubt, say N. + endif # VIRTUALIZATION diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile index 86a629aaf0a1..e4233b323a73 100644 --- a/arch/arm64/kvm/Makefile +++ b/arch/arm64/kvm/Makefile @@ -27,6 +27,7 @@ kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \ kvm-$(CONFIG_HW_PERF_EVENTS) += pmu-emul.o pmu.o kvm-$(CONFIG_ARM64_PTR_AUTH) += pauth.o +kvm-$(CONFIG_PTDUMP_STAGE2_DEBUGFS) += ptdump.o always-y := hyp_constants.h hyp-constants.s diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 9bef7638342e..60fed2146763 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -45,6 +45,7 @@ #include #include #include +#include static enum kvm_mode kvm_mode = KVM_MODE_DEFAULT; @@ -228,6 +229,7 @@ vm_fault_t kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf) void kvm_arch_create_vm_debugfs(struct kvm *kvm) { kvm_sys_regs_create_debugfs(kvm); + kvm_ptdump_guest_register(kvm); } static void kvm_destroy_mpidr_data(struct kvm *kvm) diff --git a/arch/arm64/kvm/kvm_ptdump.h b/arch/arm64/kvm/kvm_ptdump.h new file mode 100644 index 000000000000..0a62b0e2908c --- /dev/null +++ b/arch/arm64/kvm/kvm_ptdump.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) Google, 2024 + * Author: Sebastian Ene + */ + +#ifndef __KVM_PTDUMP_H +#define __KVM_PTDUMP_H + +#include +#include + + +#ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS +void kvm_ptdump_guest_register(struct kvm *kvm); +#else +static inline void kvm_ptdump_guest_register(struct kvm *kvm) {} +#endif /* CONFIG_PTDUMP_STAGE2_DEBUGFS */ + +#endif /* __KVM_PTDUMP_H */ diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c new file mode 100644 index 000000000000..52483d56be2e --- /dev/null +++ b/arch/arm64/kvm/ptdump.c @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Debug helper used to dump the stage-2 pagetables of the system and their + * associated permissions. + * + * Copyright (C) Google, 2024 + * Author: Sebastian Ene + */ +#include +#include +#include + +#include +#include + + +static int kvm_ptdump_visitor(const struct kvm_pgtable_visit_ctx *ctx, + enum kvm_pgtable_walk_flags visit) +{ + struct ptdump_pg_state *st = ctx->arg; + struct ptdump_state *pt_st = &st->ptdump; + + note_page(pt_st, ctx->addr, ctx->level, ctx->old); + return 0; +} + +static int kvm_ptdump_show_common(struct seq_file *m, + struct kvm_pgtable *pgtable, + struct ptdump_pg_state *parser_state) +{ + struct kvm_pgtable_walker walker = (struct kvm_pgtable_walker) { + .cb = kvm_ptdump_visitor, + .arg = parser_state, + .flags = KVM_PGTABLE_WALK_LEAF, + }; + + parser_state->level = -1; + parser_state->start_address = 0; + + return kvm_pgtable_walk(pgtable, 0, BIT(pgtable->ia_bits), &walker); +} + +static int kvm_ptdump_guest_show(struct seq_file *m, void *unused) +{ + struct kvm *kvm = m->private; + struct kvm_s2_mmu *mmu = &kvm->arch.mmu; + struct ptdump_pg_state parser_state = {0}; + int ret; + + write_lock(&kvm->mmu_lock); + ret = kvm_ptdump_show_common(m, mmu->pgt, &parser_state); + write_unlock(&kvm->mmu_lock); + + return ret; +} + +static int kvm_ptdump_guest_open(struct inode *m, struct file *file) +{ + struct kvm *kvm = m->i_private; + int ret; + + if (!kvm_get_kvm_safe(kvm)) + return -ENOENT; + + ret = single_open(file, kvm_ptdump_guest_show, m->i_private); + if (ret < 0) + kvm_put_kvm(kvm); + + return ret; +} + +static int kvm_ptdump_guest_close(struct inode *m, struct file *file) +{ + struct kvm *kvm = m->i_private; + + kvm_put_kvm(kvm); + return single_release(m, file); +} + +static const struct file_operations kvm_ptdump_guest_fops = { + .open = kvm_ptdump_guest_open, + .read = seq_read, + .llseek = seq_lseek, + .release = kvm_ptdump_guest_close, +}; + +void kvm_ptdump_guest_register(struct kvm *kvm) +{ + debugfs_create_file("stage2_page_tables", 0400, kvm->debugfs_dentry, + kvm, &kvm_ptdump_guest_fops); +} From patchwork Fri Aug 16 12:39:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13766076 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 C0089C52D7D for ; Fri, 16 Aug 2024 12:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=i5eauNhTcQzE72bplFQ4XGy8D3RpEmD9MyGnD7LBaN4=; b=rdmzYaEG8icmimpgaPrZwMqmPc NecNp4KZioHzRMUE1NU3uhYsxHr5Q1Lolbqw/qaX11nqcgGKL7BAzoNxVXzcD3r6/otpE8yHrsHmN 7FUOPzmMy115BJsoBzFff97g1t3IGEYw4bLHg+xCd0/XM7sY6lYVeDzDxVeFAEeHpYYd27+ewcV2Q g7HtFbHrIqteMS281F+KyXZ798kife7DpIJB84KPP8mguil+AO9jJs1+mG9TWf4TYKB1T/9FYtYj4 /CAyrL3FIR85Y4qHgsLLd6ULtKRj4zKjFn54gB2FTncdX1efNMWbvsRGKlwDsSI+B71R4BcLeB8vJ P71+kmMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewIT-0000000Cuwe-3rVN; Fri, 16 Aug 2024 12:43:13 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewEq-0000000Cu4a-2Dh8 for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 12:39:30 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-4280e1852f3so14598895e9.3 for ; Fri, 16 Aug 2024 05:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723811966; x=1724416766; 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=i5eauNhTcQzE72bplFQ4XGy8D3RpEmD9MyGnD7LBaN4=; b=20vPUT79u96kfunawQEn7q+pP8TyC8pM05lG0Fr6tWV6vcN6myCzA/kLnbqofHfgRx jtpDe6BnczodEtK3hgJv8Co6orShZ8foC/5C/TkhRUqw46l8odH12iCY63wnyH/3yM1V T1ewsJRFUTp1Tv+AOqabQhSyXDM6jwFER7oWgsac64VbSeVRl2VIINhCoGLyWzfbJPeT ZfGl39Elk5BlDt6GRL9wuifY+79zGjjrtgKo+qXNATMczaIIHa1muTDT7b/wPAc38JjU tvIF5pX6LuITKkLkolIfCWft9nJQphtiuRNXrHXwNUuuQ6EabgyiSEbfV+XPEr/VB8pW aEJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723811966; x=1724416766; 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=i5eauNhTcQzE72bplFQ4XGy8D3RpEmD9MyGnD7LBaN4=; b=LpiCgZ3tl/WxYNe9wyu50bwsi46y1eL6vJ2Tb2uFkjfiGkqhUfJHWhSl00g6TenhwI arbMfrfm9XNZYQhhRyyncSSedsBTgpvAMBQTtEt6HJGdX208DQPD2ob03ZhDc2UDtoyi rq5guyCVtXcN2F79ruMXBVQYHrG68zeplooJVNGL+pkR/bG/OpIJqv4+yxsxnbMEws3u CwCdRx6mWiSe1OjLIIekYdYgc/E6JhIe6XaVXW46aqxMjz4uRHRIZ2ZCQxjapWF6w/OA fEcfCvSWmqQxJDG4horVsGaDqSBZJWL+s12Y7AWWFMXxxo6NffMOdLddiRdE+tMaLIha awHw== X-Forwarded-Encrypted: i=1; AJvYcCU1Dim1e2wPCzJ4iIGWVqtqhTQXt/1/dr8tEy1qm//+hy8DrPYVSP2fTHrInXKITTJZAtjPZ9t29HyVIrBygKABZHCn0hRZapwpa40Qb7/N5YdJCqw= X-Gm-Message-State: AOJu0Yxs+9W2PkbBZR7Ww9LNi+WD4SbKVx7x62n6CrP+mFrVYnAL7wM1 TraPOrtU21RPu8aZSp+IdU/Ug3+QqO5QWIqjEtUL4DhIq286R86gkmUJ0p2YYGJsjpDCkbDLvD1 NOAAKv1r30aAup5NUDwRFCBfzrA== X-Google-Smtp-Source: AGHT+IG1VARFxBSm1/RC48H0ZjztqDQmLfmamJgW5HCygZC+rMZkIMsZGB0I2wgNiB3LORe0b8lZmKSxQJdbF5eeByQ= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a5d:6691:0:b0:366:ec30:add3 with SMTP id ffacd0b85a97d-37194314665mr4594f8f.1.1723811966138; Fri, 16 Aug 2024 05:39:26 -0700 (PDT) Date: Fri, 16 Aug 2024 12:39:05 +0000 In-Reply-To: <20240816123906.3683425-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240816123906.3683425-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240816123906.3683425-6-sebastianene@google.com> Subject: [PATCH v8 5/6] KVM: arm64: Initialize the ptdump parser with stage-2 attributes From: Sebastian Ene To: akpm@linux-foundation.org, alexghiti@rivosinc.com, ankita@nvidia.com, ardb@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, james.morse@arm.com, vdonnefort@google.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ryan.roberts@arm.com, sebastianene@google.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240816_053928_676889_0BF39315 X-CRM114-Status: GOOD ( 18.77 ) 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 Define a set of attributes used by the ptdump parser to display the properties of a guest memory region covered by a pagetable descriptor. Build a description of the pagetable levels and initialize the parser with this configuration. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/ptdump.c | 135 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c index 52483d56be2e..79be07ec3c3c 100644 --- a/arch/arm64/kvm/ptdump.c +++ b/arch/arm64/kvm/ptdump.c @@ -14,6 +14,51 @@ #include +#define MARKERS_LEN (2) +#define KVM_PGTABLE_MAX_LEVELS (KVM_PGTABLE_LAST_LEVEL + 1) + +struct kvm_ptdump_guest_state { + struct kvm *kvm; + struct ptdump_pg_state parser_state; + struct addr_marker ipa_marker[MARKERS_LEN]; + struct ptdump_pg_level level[KVM_PGTABLE_MAX_LEVELS]; + struct ptdump_range range[MARKERS_LEN]; +}; + +static const struct ptdump_prot_bits stage2_pte_bits[] = { + { + .mask = PTE_VALID, + .val = PTE_VALID, + .set = " ", + .clear = "F", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | PTE_VALID, + .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | PTE_VALID, + .set = "R", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | PTE_VALID, + .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | PTE_VALID, + .set = "W", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_HI_S2_XN | PTE_VALID, + .val = PTE_VALID, + .set = " ", + .clear = "X", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_AF | PTE_VALID, + .val = KVM_PTE_LEAF_ATTR_LO_S2_AF | PTE_VALID, + .set = "AF", + .clear = " ", + }, { + .mask = PTE_TABLE_BIT | PTE_VALID, + .val = PTE_VALID, + .set = "BLK", + .clear = " ", + }, +}; + static int kvm_ptdump_visitor(const struct kvm_pgtable_visit_ctx *ctx, enum kvm_pgtable_walk_flags visit) { @@ -40,15 +85,81 @@ static int kvm_ptdump_show_common(struct seq_file *m, return kvm_pgtable_walk(pgtable, 0, BIT(pgtable->ia_bits), &walker); } +static int kvm_ptdump_build_levels(struct ptdump_pg_level *level, u32 start_lvl) +{ + static const char * const level_names[] = {"PGD", "PUD", "PMD", "PTE"}; + u32 i = 0; + u64 mask = 0; + + if (start_lvl > 2) { + pr_err("invalid start_lvl %u\n", start_lvl); + return -EINVAL; + } + + if (WARN_ON_ONCE(start_lvl >= KVM_PGTABLE_LAST_LEVEL)) + return -EINVAL; + + for (i = 0; i < ARRAY_SIZE(stage2_pte_bits); i++) + mask |= stage2_pte_bits[i].mask; + + for (i = start_lvl; i < KVM_PGTABLE_MAX_LEVELS; i++) { + strscpy(level[i].name, level_names[i], sizeof(level[i].name)); + + level[i].num = ARRAY_SIZE(stage2_pte_bits); + level[i].bits = stage2_pte_bits; + level[i].mask = mask; + } + + if (start_lvl > 0) + strscpy(level[start_lvl].name, "PGD", sizeof(level[start_lvl].name)); + + return 0; +} + +static struct kvm_ptdump_guest_state +*kvm_ptdump_parser_init(struct kvm *kvm) +{ + struct kvm_ptdump_guest_state *st; + struct kvm_s2_mmu *mmu = &kvm->arch.mmu; + struct kvm_pgtable *pgtable = mmu->pgt; + int ret; + + st = kzalloc(sizeof(struct kvm_ptdump_guest_state), GFP_KERNEL_ACCOUNT); + if (!st) + return NULL; + + ret = kvm_ptdump_build_levels(&st->level[0], pgtable->start_level); + if (ret) { + kfree(st); + return ERR_PTR(ret); + } + + st->ipa_marker[0].name = "Guest IPA"; + st->ipa_marker[1].start_address = BIT(pgtable->ia_bits); + st->range[0].end = BIT(pgtable->ia_bits); + + st->kvm = kvm; + st->parser_state = (struct ptdump_pg_state) { + .marker = &st->ipa_marker[0], + .level = -1, + .pg_level = &st->level[0], + .ptdump.range = &st->range[0], + }; + + return st; +} + static int kvm_ptdump_guest_show(struct seq_file *m, void *unused) { - struct kvm *kvm = m->private; + struct kvm_ptdump_guest_state *st = m->private; + struct kvm *kvm = st->kvm; struct kvm_s2_mmu *mmu = &kvm->arch.mmu; - struct ptdump_pg_state parser_state = {0}; int ret; + st->parser_state.seq = m; + write_lock(&kvm->mmu_lock); - ret = kvm_ptdump_show_common(m, mmu->pgt, &parser_state); + ret = kvm_ptdump_show_common(m, mmu->pgt, &st->parser_state); write_unlock(&kvm->mmu_lock); return ret; @@ -57,22 +168,34 @@ static int kvm_ptdump_guest_show(struct seq_file *m, void *unused) static int kvm_ptdump_guest_open(struct inode *m, struct file *file) { struct kvm *kvm = m->i_private; + struct kvm_ptdump_guest_state *st; int ret; if (!kvm_get_kvm_safe(kvm)) return -ENOENT; - ret = single_open(file, kvm_ptdump_guest_show, m->i_private); - if (ret < 0) - kvm_put_kvm(kvm); + st = kvm_ptdump_parser_init(kvm); + if (IS_ERR(st)) { + ret = PTR_ERR(st); + goto free_with_kvm_ref; + } + + ret = single_open(file, kvm_ptdump_guest_show, st); + if (!ret) + return 0; + kfree(st); +free_with_kvm_ref: + kvm_put_kvm(kvm); return ret; } static int kvm_ptdump_guest_close(struct inode *m, struct file *file) { struct kvm *kvm = m->i_private; + void *st = ((struct seq_file *)file->private_data)->private; + kfree(st); kvm_put_kvm(kvm); return single_release(m, file); } From patchwork Fri Aug 16 12:39:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13766077 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 6ABF7C52D7D for ; Fri, 16 Aug 2024 12:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fVLGFavEAQJdYF6sohZy6GLteiKbgm4SNZHa6M3Hrik=; b=MNNh9/GGbtav7/JzZBTo8zTXG3 hqaCpQTLRDjTQvBJ2OF8RkUtmO/HAh4pBIPcTRiCQYYeaX1IHuwwrzDhnQ3znmonPynDDnnK2xijG rM9bErjtwW6vuCLJERz/oqFXfOxNq2BzA4FdUV22kzaXd+3mld8lb0NoBRwhlhhCsC5Ibpx6TUv9+ Te7+VPzIPCSBGesvy0I1fHt7WhBgVUCP+TfMxWmusfg8Z738YcgOlU0KS2RgNRtbnEnKsBuvW1oBe 6g39djpXcHouuAZhxSoDTuKOKKFM8tKFCD6Ap0fNPvz+1IK17V+FMyBSBY0BTWMfdllPe7gb2SyPa p7kZzNMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewJ7-0000000Cv8Q-41pO; Fri, 16 Aug 2024 12:43:54 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewEs-0000000Cu5g-27pv for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 12:39:31 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-429097df54bso13399775e9.1 for ; Fri, 16 Aug 2024 05:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723811969; x=1724416769; 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=fVLGFavEAQJdYF6sohZy6GLteiKbgm4SNZHa6M3Hrik=; b=PYoLGs/fBeE/v+hvwl3Q+9r8WUjN3qUcqRMCMiE3QuSAJHHrzB7it2ERlYZTUJGrLJ AYIpVZbrlZNKc/HcdTiYEEKCk/CzCjNLIa8Y+TKuIPZ1QefehuDN0lYXUYm+KzGTCtM4 A2YdxwhRG612dWSIdSsUqltdUood06D9uMmO0FY0z/TLONhuHUc7SRrPhUHqr5uUAV9j NkQ8DgufZNR5ne8sgpW+T5CF754Sth8mSJTHG//nNwKrpmNSoK5SMfqPe1qpy2Qj0fsb Dx+Uq5gy+nYihApLWinOau+BX0Xeux9FAtY/sxOIGS7QeSMSz4p4u0BIHsaZblUblhip lsXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723811969; x=1724416769; 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=fVLGFavEAQJdYF6sohZy6GLteiKbgm4SNZHa6M3Hrik=; b=gViUXeXusblu50RLP9uSlAUfMtU9MbUYIMpFWQ0HuBoYdry0iqEQHl2qvjBGyu/i3w AW0bbCq5gG7TbJn/lHivHkkFm51FIuppfbMLbnjT9ZPfpolkak2zYt6VOk+IvwMUsd9A z2JkrZgdSpG5jxOktXdfmvnsNP2Zx8mh3HctHHgARNxxur6moDKZzFUMCyJn3z67Qb3S c7D0jEV9T12sVvYJ6fy9CsVS/ypLivn1/cUM5GmMDGD0QHcTKmnKZM6TceKv+cyIYsM0 J7Xgcij9Q1MH30BQhCyHJqHfBPARYO8gRbuKm3rjcwyLsdFsUzOYn9UaNn+85AIuT7BQ cMRw== X-Forwarded-Encrypted: i=1; AJvYcCUQdJLQMvsmUNqUGcKrV2FhwpRSJYed4XqfMuvB9dKUsibK3TJiBE3AeYkD+K1kuWzGap8JNRwwIh8R9EusHsfBtdH9zno5MbDWFHeNBEq06/7MwnM= X-Gm-Message-State: AOJu0YyHhHYoXbyc9XBDAyNHj4eGHcDjzsgFm2Z18LJnyr6wWBm8H5z+ 2gFlhv+BOBJj7jy/J8FBMBZdUSCz7tX5f9crOxWz6VnDhVlSupdRZBtS/nKoxl0VtRNStZp8ZKS wjdyy3aD4B8ezEfCQ9NrkVVqm4Q== X-Google-Smtp-Source: AGHT+IFGgP1UpKc1nFsMN2cnAW/WNRr3YojR2uI15QJjFmnongfC+MYnDiKQo3s4RWZo8/KjRQyeYn/x04TBgYlZR34= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:6000:1e81:b0:366:ea7c:bed1 with SMTP id ffacd0b85a97d-371943164fbmr3636f8f.1.1723811968492; Fri, 16 Aug 2024 05:39:28 -0700 (PDT) Date: Fri, 16 Aug 2024 12:39:06 +0000 In-Reply-To: <20240816123906.3683425-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240816123906.3683425-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240816123906.3683425-7-sebastianene@google.com> Subject: [PATCH v8 6/6] KVM: arm64: Expose guest stage-2 pagetable config to debugfs From: Sebastian Ene To: akpm@linux-foundation.org, alexghiti@rivosinc.com, ankita@nvidia.com, ardb@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, james.morse@arm.com, vdonnefort@google.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ryan.roberts@arm.com, sebastianene@google.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240816_053930_569712_E7119F9D X-CRM114-Status: GOOD ( 14.73 ) 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 Make the start level and the IPA bits properties available in the virtual machine debugfs directory. Make sure that the KVM structure doesn't disappear behind our back and keep a reference to the KVM struct while these files are opened. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/ptdump.c | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c index 79be07ec3c3c..b0d55ea3fb2a 100644 --- a/arch/arm64/kvm/ptdump.c +++ b/arch/arm64/kvm/ptdump.c @@ -207,8 +207,56 @@ static const struct file_operations kvm_ptdump_guest_fops = { .release = kvm_ptdump_guest_close, }; +static int kvm_pgtable_debugfs_show(struct seq_file *m, void *unused) +{ + const struct file *file = m->file; + struct kvm_pgtable *pgtable = m->private; + + if (!strcmp(file_dentry(file)->d_iname, "ipa_range")) + seq_printf(m, "%2u\n", pgtable->ia_bits); + else if (!strcmp(file_dentry(file)->d_iname, "stage2_levels")) + seq_printf(m, "%1d\n", KVM_PGTABLE_LAST_LEVEL - pgtable->start_level + 1); + return 0; +} + +static int kvm_pgtable_debugfs_open(struct inode *m, struct file *file) +{ + struct kvm *kvm = m->i_private; + struct kvm_pgtable *pgtable; + int ret; + + if (!kvm_get_kvm_safe(kvm)) + return -ENOENT; + + pgtable = kvm->arch.mmu.pgt; + + ret = single_open(file, kvm_pgtable_debugfs_show, pgtable); + if (ret < 0) + kvm_put_kvm(kvm); + return ret; +} + +static int kvm_pgtable_debugfs_close(struct inode *m, struct file *file) +{ + struct kvm *kvm = m->i_private; + + kvm_put_kvm(kvm); + return single_release(m, file); +} + +static const struct file_operations kvm_pgtable_debugfs_fops = { + .open = kvm_pgtable_debugfs_open, + .read = seq_read, + .llseek = seq_lseek, + .release = kvm_pgtable_debugfs_close, +}; + void kvm_ptdump_guest_register(struct kvm *kvm) { debugfs_create_file("stage2_page_tables", 0400, kvm->debugfs_dentry, kvm, &kvm_ptdump_guest_fops); + debugfs_create_file("ipa_range", 0400, kvm->debugfs_dentry, kvm, + &kvm_pgtable_debugfs_fops); + debugfs_create_file("stage2_levels", 0400, kvm->debugfs_dentry, + kvm, &kvm_pgtable_debugfs_fops); }