From patchwork Mon Sep 9 12:47:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13796988 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 84B9FECE579 for ; Mon, 9 Sep 2024 12:51:31 +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=SKJ1NP3DrAm45Ot6yL2cReAMG8qo73bbwYgKiOjz384=; b=4PpVRGVPywtbItslSTW0yhqcfs hSe3ofI44B5xYKNobDgyYPOgV5bK3Lm8iytBn8KKU48bIWJLaa3lXv/bM9DVxIr/iHVxzNx9B7Xe4 zMMJCCBgVFFQCCDfKdj8O8r9z3w712pMQ3/TiWnCgtky8lopuGw8lUh+3lzRKRUhGqw1EFfRttz7S xL7wCkljbNdU4Bv7cSJ/fv8HC3ila9hx0dgQjKI/j+zrAUXJ5bvfilyWd9ERL7wUMvF6rESlj/OpO ka/o46RzHGmd8Jx6d8tTQqqQopUaEdMu3fX9USzgCF96LuU2sObYlYnaJAol8EGe/tlTH/Ghg3hzK Lh3tyZRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sndrS-00000001w5c-2PUK; Mon, 09 Sep 2024 12:51:18 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sndnr-00000001uY7-0Bnz for linux-arm-kernel@bombadil.infradead.org; Mon, 09 Sep 2024 12:47:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=SKJ1NP3DrAm45Ot6yL2cReAMG8qo73bbwYgKiOjz384=; b=reNV4y1pkVPFplezSCNr8KDfDL zO55Oz5WsXFveq7plWjqyB/l5rh4cBTb66ST+XKAsGG22k0uJOBBO4b8jBki0RhuIq7JwRgzZDI0m crbm0Db9zfyO+8ar+VEXahdpSj5xdcG/w47+wBoBjbnK9MRxynmiXiOEGfhoMtShs5StT2vK8fwAt Iw9k4RNmU2UKp+I5y6VrRxWE4Twjx1TgZSW4L3F0Vgq7bj3B+KENRCNipbf81G+zE/cdkhSOw6mgL Gwx2A5CKin1bakoS8u1YTB8jALohImUoqHbDgNFkJUW+StdnOsE79kY+SQs4Oj0OLw/EPA1SAhfN/ MexJXxNA==; Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sndnm-00000000Qnq-3BVS for linux-arm-kernel@lists.infradead.org; Mon, 09 Sep 2024 12:47:33 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-42cb635b108so8842855e9.2 for ; Mon, 09 Sep 2024 05:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725886047; x=1726490847; 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=SKJ1NP3DrAm45Ot6yL2cReAMG8qo73bbwYgKiOjz384=; b=g+niqLk7oPUPZ2sMOzvTnHqlYaJCX6MBNkSa7PVWSSBJAA2VlcywK03hsmLJ1vJfWZ YVk+ZV/Wb7/tycvaj3IEQyFwoVtxTOvq6YXpAmk+XoTCnX/JxtzmWKgHzMqvGkmbbTj2 vn+gYqkpJtn5Vfu15LA3bYk82T8a5hInvYv5r2HxeFAIIHfJkuQz697ZdF9UZngFpIa3 m8ymOc0qZq95tdl/3Tp7HB8gvpgDbNkCW2d5KZO71jBzFSgnHazRBWkA+AdKOS2IjcAQ dXu0UX22jBHEEZDxVkLdshThJz9mU1i9DflFjiQTgoQP2nhH2aIU7QrKb+tjAPfouZbN annw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725886047; x=1726490847; 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=SKJ1NP3DrAm45Ot6yL2cReAMG8qo73bbwYgKiOjz384=; b=iwIokklkp2yw8kmOEJ4EY4k0FTMa8Gc0gfIq2U/Bm3+hB+wsV5VODOunChnpW7n4e1 kp8u+i/OwviIKl9kpf4BW4EKG5Yr8uqLd698ENlX5hCj6F83L/b4Mut2z1xadXr7fr9I P7k+yoDrsE4GSTcr1o6FJmPG0IA+ib+fZ14JcG3e/Sa1cyHiW28boYG0qidImfz/+LpZ l8Phn7LQb4XtAuKDhCnrprpqg94Lih9tvAGQkRQLa+GKu1r3GJvAlHSZpmsIgD9hKqFB ycF4clsswK8k6gsGL8RmvXTRJbDr1DzXIzw9613A4LVGcXqQcg2xX/QmOPa5TvvW+lx0 0imw== X-Forwarded-Encrypted: i=1; AJvYcCXSiYKATqegxtlefxYccPeWQ7EDlFROLoR9/Ea5CXKIf/3PAn42oJqgJTZJM6240S28JfMMxptXgRRovGu5Secd@lists.infradead.org X-Gm-Message-State: AOJu0YwaEIvJSe/eNmTPg3K7JWNtKN9/L3vx4OlTZkp115d2u4gUwErw NZ9uso/KxXLf1skIkhTBspflivQHiJs5UOMYW3+9tEWWfKR+qx2HysV5YKF2KMZ2ZTFRGpk7/4h 9o9AOiJXwO7InQm9nJk7/ULdS5A== X-Google-Smtp-Source: AGHT+IGB9bwzA+fwuWPOhmU2PE2PuSrdb0vA8nxugJEsLMz4E+4/m65aP47k2xrfDB7zI8uLZNKmhk8HfA0/HNK+S/I= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:68:fe9:ac10:f1b7]) (user=sebastianene job=sendgmr) by 2002:a05:600c:2d8c:b0:42c:ae30:fc33 with SMTP id 5b1f17b1804b1-42cae30fd4fmr872025e9.4.1725886046868; Mon, 09 Sep 2024 05:47:26 -0700 (PDT) Date: Mon, 9 Sep 2024 12:47:17 +0000 In-Reply-To: <20240909124721.1672199-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240909124721.1672199-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240909124721.1672199-2-sebastianene@google.com> Subject: [PATCH v10 1/5] 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-20240909_134730_903660_3E9D3060 X-CRM114-Status: GOOD ( 12.15 ) 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 Mon Sep 9 12:47:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13796989 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 11367ECE579 for ; Mon, 9 Sep 2024 12:52:31 +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=rOyTNrjRYeC5V1YoJMilLcLgHHeqHqjXzH9wfdwY9sw=; b=aVtavrHlU4gGY+1j3cOZwlf8tI zlRS/A7jIHXojXM4Jyc44rF7vGpfe0qg8BV4zeimabAHiF0xgRgBY8wN9229bMGGB1AOW89dMnRV6 CVSkUJr1T6y1IFTWm8q8X1waNKV2g/GPBaNhzFZRyD06m6voAyE9EUUUKjdV7Wy30/7tv6oSodJtA rEkaLnS+HB3s6lIlqECLWZKSh/mo2JozBpDRiBBxufjtXn+ItAd8+zzBq7tsqDDsGe+Ewp6WS4k2O OzsCqmlT7BJgTOcFbIySjA3v8A5TRpbv5cqZTJsRVT6x9IsW/7c59BkE3dEtXZY18Qg9Wjz3+EJc1 lTxaF6KQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sndsR-00000001wNH-3kEZ; Mon, 09 Sep 2024 12:52:19 +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 1sndno-00000001uV0-35Xc for linux-arm-kernel@lists.infradead.org; Mon, 09 Sep 2024 12:47:37 +0000 Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-374c32158d0so2354894f8f.1 for ; Mon, 09 Sep 2024 05:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725886049; x=1726490849; 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=rOyTNrjRYeC5V1YoJMilLcLgHHeqHqjXzH9wfdwY9sw=; b=GlnxlcmLwRAil+DsXd5fmDy2sUkdBjkYaictRPue7/OXd4OBx+Wo72Wr02xyWBSJ+f RxMw2e8zD1F+e4MUgtJG1Ld7E0G7jSYl6psVh07N+faOmtIJH7S56nArO/HWpQwmx5xP oBAu4FMouXT0WoJxver/1qjzCR2acacMDOQADwL69HzGV3FH+2M46FazNUt6CPdc4wcZ KxRLz2oEhsLrmh6qlXUvkoyXSenfGhhODBVsW60qSsdypMRw5OzZDG/bQmDNZLemK6E+ kj8Xl2n7gAxTsg9CGBD3Y7hATdH2osa5vzS6x0II/hojwqYsTUtMun24Uuf/9ZdEKB2B xUaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725886049; x=1726490849; 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=rOyTNrjRYeC5V1YoJMilLcLgHHeqHqjXzH9wfdwY9sw=; b=mlfxShuzhLaB8fh3vIgVNJCd1iHZv4thSgEgWESZcxiJGyA7mNAQ3DjS+tXY+H4GxT MjlWwlvTXzJc5d3GVNnj0MOJ9CD5rjuJ7OAJGHB8CcKGOqZV1Ty9/4QpoKed9T4gKSB/ oXn2iLw1wqjBZvpLZFwsWpgR/PyikZld35CrSY7mRqAZb4dTf5/hdEjwSpZdahuQ7SnL PKIhvly4S4nxwuoLZQG4DtxOH3FD4fW5sIDxuWljA416VWE985MoX+27eIrledhijCs9 JzihjTKgLifj6WB9m8DfwpiPqm3TJOhqtmn+pG5e+/SpuEUgzwM59cC8uIqBq4chgYke g07A== X-Forwarded-Encrypted: i=1; AJvYcCWWrAtT01bX0QR0y1zxMrxnIFiQ9L2Z+dOoCS+wVBT2A1CvS2WWghK5SriJsbRUXgTrlgYbacEUPADxG6YKPzle@lists.infradead.org X-Gm-Message-State: AOJu0YxjmYiZJfALiO3WEGk6OohkWVmGode4uk0WoJh9lxfJjsP8gH87 1mpnkc4mdAeTo2Nk5aA9IpKwYttn4kux736fmzsdqyrR34pqh4Xsa7bT8KEs5g9f9LEqtkk3AhS Y7E9K87GdQut4Hwe5YFMO/LSURA== X-Google-Smtp-Source: AGHT+IG+ip5lnTk9ayqB7jP8eGKNbUqkVkAL495AT+0kgCNA1tzshuDCmFE76GVP0BcqGg2a70PypynTTnHwd3R29A0= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:68:fe9:ac10:f1b7]) (user=sebastianene job=sendgmr) by 2002:a05:6000:1281:b0:374:cad2:a75e with SMTP id ffacd0b85a97d-378895c2527mr13872f8f.1.1725886049120; Mon, 09 Sep 2024 05:47:29 -0700 (PDT) Date: Mon, 9 Sep 2024 12:47:18 +0000 In-Reply-To: <20240909124721.1672199-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240909124721.1672199-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240909124721.1672199-3-sebastianene@google.com> Subject: [PATCH v10 2/5] 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-20240909_054733_007589_CAB56888 X-CRM114-Status: GOOD ( 20.41 ) 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 Acked-by: Will Deacon --- 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 Mon Sep 9 12:47:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13796991 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 8B485ECE579 for ; Mon, 9 Sep 2024 12:54:35 +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=z5YaerhLrnlA1kDn0gvbQTCDMMWwt29NrOwuLXna95M=; b=iMXfBFmsBEvm0AexE6pG2lsiof iWaeUTVrtnCXq6zTNeNAgprVpGiCuaN1av07mFcUiU+scblOOTnL9KaeKsIJTG9a9oqkSG6LmVUkx TS7tFz2RJdko5L8pmO9Z1C+ciauY5apK5Aw6td00aahYxPC4xTZMukHIwMvqqvxPr85mEDNEOXxs1 LqxVTSASIcV0dRx3oDc+14WFTJQDaEZEPoUVhOKmWLKuC2BQyecqXiSDNdrH+SHZlfARYumexF+UC 5OZ6hINvgnZOAtY+Lrzl9bnEoaxnujzQ+jDeMMjo3vVVwh+zl+djFGwjceHvI54pMX/Z46W+n8vXi sqSDXNjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1snduR-00000001wsG-127S; Mon, 09 Sep 2024 12:54:23 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sndnv-00000001ubf-0IBc for linux-arm-kernel@bombadil.infradead.org; Mon, 09 Sep 2024 12:47:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=z5YaerhLrnlA1kDn0gvbQTCDMMWwt29NrOwuLXna95M=; b=N8OLSpHBrtzkRtxnDeKQ+JSAcI XEzBrgKIHlaWfGMjtY+iHOO/eayBwZSfsews1Sg6HiSKBOaRsRJTrF1gYprMMRTDKEgNUlOOSiRKr kTGbURcjJOV8qPrN1Aul7AUuZN/GfZtOElxGv96xyoZu4/Mifh5/RqTmJ0eZ9W5TAlQe2wb2LYvR8 6Y8YAXYoOWTbfolHrLhER8hQhzEcFFsvX3zyNOFJDHkMSOlnEybh9Hv2sURX4Em0mqIHvI55C7Oo4 DIyZTtGNbk7Dp0OAgcax+75sCCbvuzwq0bqfS2xPG8GZKR1MZyE5dJBdlr6/dMpAaqyZ4neNdbHcu XnlLdlIg==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sndnr-00000000Qot-2SMW for linux-arm-kernel@lists.infradead.org; Mon, 09 Sep 2024 12:47:37 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-42cb857fc7dso6363975e9.0 for ; Mon, 09 Sep 2024 05:47:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725886052; x=1726490852; 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=z5YaerhLrnlA1kDn0gvbQTCDMMWwt29NrOwuLXna95M=; b=m/u7mkVXp0JPw9CaCTTbMlmsnEMhLHwrosSwVn8lgVDLob3l2DQf28bUHgiqUenXiW u5KVqvbf0m1IMfwkY5bSZREGK832RLK53DVpo7wJGUJtooGmWPIKJQKPCtxbDoN3EWNO rQ63MDSKyornrfAqw06G3zAzqo7P4sTjPImOQ0jWnp7TwFLXHGJOX3W6TCe18eQ1ydPu oYDx9T+MLptvaDI26f3kbjoMwjWuW1DZCJjrJT3gtPDu9gvqj5Npaw+CkijR4l1ZbOP1 9iPdlx1fWim5m/un9NbNe6oN8mdup0yTPe7LgQ/eh1tCMiqH1E/Jp0bmx8rEhvyIGMry LZmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725886052; x=1726490852; 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=z5YaerhLrnlA1kDn0gvbQTCDMMWwt29NrOwuLXna95M=; b=s+YBpHwU5ZcUPPcvf0LnFy1f62ILCrzia0hau2gvjTjIuVVpTsUP99oOI9YhchXUeg 5hG/7iYowNi7I0o1IHD2Q6ftAUqvH3ZbT/bBsfH7+jdghy+Ty16sW7mj8ZgT/8yhFBKo fiD6LYOhuEgdQTWbTX4T+shC4hkBptrSpbxmGDiH01hONzlXEKtVIflk0yQuM5gmeXuJ GwnBU3zBenD7jdQvkkUHnApFf8DFgDRXOJkXjBnfj/dkJ3kq5KsvjqShqqJh3/ZBDbWb 8wP5tf9oF/4uYX1P1XAzxk7egwNHUEkPBYHmguQ37El6e8iLmGF6v4k7BFqZuiUQxtTk 3QnQ== X-Forwarded-Encrypted: i=1; AJvYcCXhRw25Ft1i1+xtBa0txHVFJiG9nEIoadLPxs0fQIiSrShsGLqWyiUw6omBiBSINPT79TJ2T5FozYwU5icJ62nP@lists.infradead.org X-Gm-Message-State: AOJu0Yx5+QsmPGqsZaZAv8pWgZE/X3IEwWzHwiInFU4gXwYgqZuouWdB YrEq+g3VDJ1+zObhoQJMVNoeiLZIGwR4NTWn355k5r49aAcBA6yX/RUwk+4wLxYwdxm+woJlV89 2y0cP8tI0VutwmfMrs0XJs8ILlw== X-Google-Smtp-Source: AGHT+IHvFQbj0rKg0Z2E+lg4FZtxEigwOSWg+BND77qixGLBIzbCZ5lpRaiz0wEgqDC0ZzG+egBczPT3YnPFvCYHpdQ= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:68:fe9:ac10:f1b7]) (user=sebastianene job=sendgmr) by 2002:a05:600c:6b6d:b0:42c:8875:95da with SMTP id 5b1f17b1804b1-42c9f9e090emr259485e9.7.1725886051855; Mon, 09 Sep 2024 05:47:31 -0700 (PDT) Date: Mon, 9 Sep 2024 12:47:19 +0000 In-Reply-To: <20240909124721.1672199-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240909124721.1672199-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240909124721.1672199-4-sebastianene@google.com> Subject: [PATCH v10 3/5] arm64: ptdump: Use the ptdump description from a local context 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-20240909_134735_702033_80D79AE6 X-CRM114-Status: GOOD ( 20.23 ) 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 Rename the attributes description array to allow the parsing method to use the description from a local context. To be able to do this, store a pointer to the description array in the state structure. This will allow for the later introduced callers (stage_2 ptdump) to specify their own page table description format to the ptdump parser. Signed-off-by: Sebastian Ene Acked-by: Will Deacon --- 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 Mon Sep 9 12:47:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13796990 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 20EF1ECE57A for ; Mon, 9 Sep 2024 12:53:34 +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=8qvkXCdHWEWBsZylsWm6hwfThTp5oWOCgEDtNeKXpl8=; b=0C4bBDu7L216aJz5O+ZvTTTDwd wUXB5BfTEqmjrPRhy8a5Ey5ghZrYagbc7vYQJ57TUOsOxhCluyqIAD2PnfQlsYnqjL2rIwazlsIK+ NKTivpuPh8GBxn8riq78NfqX4n3QfUooVSN1PIrO11HH2O2Q3hgV8sce18BJRhyQpWoGJpKMqc/cj FkiEKbdK0tTPoWvpsFkzV/swqAJKWECLu86tl+06rxV4M9FbpTI+V0qJM/E5zykbRuj1LkQ9g2AV4 4VIwJnFZoQID1+mfKOuqkS4etmPKNpGEoJoWPOoHyI6ShX9lo0pDvSCuFyqwcBDjrjdv/N/FflKtd FlI8bYJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sndtR-00000001wey-1ceL; Mon, 09 Sep 2024 12:53:21 +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 1sndns-00000001uYj-1IMc for linux-arm-kernel@lists.infradead.org; Mon, 09 Sep 2024 12:47:39 +0000 Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-374c294d841so3244389f8f.1 for ; Mon, 09 Sep 2024 05:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725886054; x=1726490854; 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=8qvkXCdHWEWBsZylsWm6hwfThTp5oWOCgEDtNeKXpl8=; b=v+CqfCKFXramUNM8VXBZ0uvlYXE/QE5kH6PrkjBwGOohaVErSOVv1Ns/yjUwJmbKla WnWJL3YoxsdF/HyTw+4C1XlmeEd+Iocoa4NxJk8qUO6NAMMe+KXR1+RbSaYKRJjYSF2a zQXNZy5RJRPSw80a4534+GSZ1EjZ0T7NVn0itbFUC78vtXyEhq6C8NbmdIzF7xdUtvlT sf/BIwZsd/4lr3vyxCZk5g6wsv02ePXXcSm1Ix505mqHDjinfg3r2pFUSBInvSGWWis6 ZqCUPJPrv8nEwGMK+f8CZixa3h0TtFeVJBDYreKN8Xe9HgdQErYoLEFxibmqYnlnYmqG 5Cug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725886054; x=1726490854; 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=8qvkXCdHWEWBsZylsWm6hwfThTp5oWOCgEDtNeKXpl8=; b=lGQYucBt/bhWn1kGtpEflq1pPoGB24EzomHa8wAZ5IOkuiKDyOqvinoZi4zwypV2eL el4lDhxtL2ivT0rTHzfGcfqLq8Gk5Xw2TvNWil48blLrDn5ARrnkLuEwXn6urA1bU91x JsdOiHLs+2FlxYOHeff90MdEBvJA42GOn3oK1cLwSuFjEwrqxc3Z+kREtP+yvkS/rymQ fFlvhOQJiQZLk5kYi7Tx3xx0ONFA7lGjvtmxPBnwNJkINRcNN5WgcemsR1NirSHpO81C AraXebl/fVxr+UDk/ifAgISZHEh00g5qvGKz5jZZsqqL1nS0a0GNJPFU6Vk+VWdclsWD +SYQ== X-Forwarded-Encrypted: i=1; AJvYcCUyUEgDRK86sHN9G1b9vFCBCkWGV0nc0wh7jE0AkZNnYZa+Zopc4PU4C0DvWqzD59Ls2bjLygEWxBFjAzIS6B7s@lists.infradead.org X-Gm-Message-State: AOJu0YzPQb3qFU0T7bZbl3b0MebY41Spfs0BAvZCU4GBBwEaUGPc35Te UQUaMw7pZ5rwGFS7Nvl49DChMmEKXaWfZMo46kaKQwigvOu9ebcFTyOrKnZJ0YrdemlDmCAS1lE 3ig0/5AuxFewGEKekQaioArhwyw== X-Google-Smtp-Source: AGHT+IHXNUAE7VdC5OTZOKpQ5J1caGnUk0ojDWhw1KiR9y5AZtlPfQlw2THkS+FmwEps5TC/2oefb8PtdRKpmxLL8Qc= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:68:fe9:ac10:f1b7]) (user=sebastianene job=sendgmr) by 2002:adf:f4d0:0:b0:374:badb:3cc0 with SMTP id ffacd0b85a97d-3788969b893mr13963f8f.9.1725886054280; Mon, 09 Sep 2024 05:47:34 -0700 (PDT) Date: Mon, 9 Sep 2024 12:47:20 +0000 In-Reply-To: <20240909124721.1672199-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240909124721.1672199-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240909124721.1672199-5-sebastianene@google.com> Subject: [PATCH v10 4/5] arm64: ptdump: Don't override the level when operating on the stage-2 tables 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-20240909_054736_679693_EBB429E4 X-CRM114-Status: GOOD ( 14.33 ) 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 Ptdump uses the init_mm structure directly to dump the kernel pagetables. When ptdump is called on the stage-2 pagetables, this mm argument is not used. Prevent the level from being overwritten by checking the argument against NULL. Signed-off-by: Sebastian Ene Acked-by: Will Deacon --- arch/arm64/mm/ptdump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index ca53ef274a8b..264c5f9b97d8 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -197,8 +197,8 @@ void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, u64 prot = 0; /* check if the current level has been folded dynamically */ - if ((level == 1 && mm_p4d_folded(st->mm)) || - (level == 2 && mm_pud_folded(st->mm))) + if (st->mm && ((level == 1 && mm_p4d_folded(st->mm)) || + (level == 2 && mm_pud_folded(st->mm)))) level = 0; if (level >= 0) From patchwork Mon Sep 9 12:47:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13796992 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 0021AECE579 for ; Mon, 9 Sep 2024 12:55:34 +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=5Qh0Buj26VPt7o3soq7cdfVmyH4HC9Sx5cxY7g+Xi6I=; b=C+KP/XQdH5TwLtT6sAJVM1hMla baFESKm51kX/HGAlbxeiTEFqYbHSkT2t816wFjV5Mbh6OdAocBSB7V13I1mrPpcDYaA+NoDE6FiSD cZohYAgA5TgMQI0OEJqdkJ/ie3mYdH3BPgY++zAPd1t/aenhhTAkiqvDTCNBpdGMzOrSX9xv4CBWw WMYGfT0KPc67AGtGAW5sQAYZuLjZLSI3RCyy4GjtV0PgX6tOI0mUC7c/OW+V+Nl5spXmfQFbKL1RW 0Biap0wZaQy90HA1/KC3373+FoHLkLG8LPXhmEYaF8vbSu+jw6eJol/tlpNNV0kR0sIFctmJe4CZF e5hI58Ig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sndvP-00000001x8I-2sne; Mon, 09 Sep 2024 12:55:23 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sndnv-00000001ubB-3NOb for linux-arm-kernel@lists.infradead.org; Mon, 09 Sep 2024 12:47:51 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-42cb22d396cso13014645e9.0 for ; Mon, 09 Sep 2024 05:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725886057; x=1726490857; 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=5Qh0Buj26VPt7o3soq7cdfVmyH4HC9Sx5cxY7g+Xi6I=; b=hmzELh4uT95eTL4xrE6vBOUjKsgaTPUNuZWSndD0FRlQewUhDCvyoba3sGHd5hJeGF LHq5XJXq0LlH9LSeDLhvB9Ra6ovf2K+fEHotTAT3GBJ6/lvW3cZePaD9qi9l+dzwKXcP drLhDTB+j58/ZEpXpbQzOX2qFO7NzmqxpiTwAMPetit0tn9TINr25rZWK7Pkx+P8gVoV Jz9WKAVel8cxnE19c1ZENd8c77YbquQarpNeXheHLdW+VbmU7TZHOuE9gMH/BVx0rGYY G2tUwSu6/UQqUWV/k2DgJFBqH5Qt15/YkbOvPpmSF8XhjNoXD3kms3XmY/X2ibLAfIUz Xm7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725886057; x=1726490857; 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=5Qh0Buj26VPt7o3soq7cdfVmyH4HC9Sx5cxY7g+Xi6I=; b=gzsbHFRvbqwy07xp+vcxoo/tRanEt1JNcJhNTE3tM2UYr1Ahe9G0hP+aX9oRt45lYB l/hwJO8yxSt5yHZ/UaAFHU1yjVxqwyRyIcISFyCDiG4zag9RTt2qXF3oJKmjCR9U8mm0 wEPt6EcKDOl0EpzKua/f+2LPNI927/1OT3CH0hQUgAGEFguHPu8o0JZp06WyOpE2w21I q/otk9YsMOVH0dtNv7O92d8lAYw7E2zQIcF0CVXz3wVl0iXwil1BflnviWNzQ1Oh9BY5 +uv5Oi8nUE7ZCyALeRlcK0kgENAkOZPPuL82aQEbp2OPSFgVTwvbreyQiaqPUcvrrPx9 juCg== X-Forwarded-Encrypted: i=1; AJvYcCXICxncgKirlIXH6FBsjkpPdkYElZSmH8choOK1YUzNYwm3KUn/x72lUgSURpuhHYQpBHxwAgLsZnSDPXgUOO9D@lists.infradead.org X-Gm-Message-State: AOJu0Yz429V+JLI6Tt0MAKv0o7BiC+C+CmrMDcn0Hx3BD+QsMwQhpY+f vFbBi4tLVkd43ALQJC8KSWqQel20AZ1IS6FB59glq1Jk7MnAPx9wNnpmOhG9EeY7o92KBYGpLL6 zmSINFAULqedlw8O9MN+U0sXatQ== X-Google-Smtp-Source: AGHT+IFrv0rLDSOUyf6zXDI606xTRZ7fv0Nwzc81o52OBg6AUGVDlns9tuVUU3FDCSkjPXyyiudbP0Q4hvSoN0F+igM= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:68:fe9:ac10:f1b7]) (user=sebastianene job=sendgmr) by 2002:a05:6000:184f:b0:374:cade:3806 with SMTP id ffacd0b85a97d-378895c5256mr15705f8f.2.1725886056876; Mon, 09 Sep 2024 05:47:36 -0700 (PDT) Date: Mon, 9 Sep 2024 12:47:21 +0000 In-Reply-To: <20240909124721.1672199-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240909124721.1672199-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240909124721.1672199-6-sebastianene@google.com> Subject: [PATCH v10 5/5] 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-20240909_054740_303307_EA4C599E X-CRM114-Status: GOOD ( 26.21 ) 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 to show 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. Introduce the PTDUMP_STAGE2_DEBUGFS config. 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 Reviewed-by: Vincent Donnefort --- arch/arm64/include/asm/kvm_host.h | 6 + arch/arm64/kvm/Kconfig | 17 ++ arch/arm64/kvm/Makefile | 1 + arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/ptdump.c | 268 ++++++++++++++++++++++++++++++ 5 files changed, 293 insertions(+) create mode 100644 arch/arm64/kvm/ptdump.c diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index a33f5996ca9f..4acd589f086b 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1473,4 +1473,10 @@ void kvm_set_vm_id_reg(struct kvm *kvm, u32 reg, u64 val); (pa + pi + pa3) == 1; \ }) +#ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS +void kvm_s2_ptdump_create_debugfs(struct kvm *kvm); +#else +static inline void kvm_s2_ptdump_create_debugfs(struct kvm *kvm) {} +#endif /* CONFIG_PTDUMP_STAGE2_DEBUGFS */ + #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 8304eb342be9..ead632ad01b4 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -66,4 +66,21 @@ 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 + depends on DEBUG_KERNEL + depends on DEBUG_FS + depends on GENERIC_PTDUMP + 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..b9fd928d3477 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -228,6 +228,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_s2_ptdump_create_debugfs(kvm); } static void kvm_destroy_mpidr_data(struct kvm *kvm) diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c new file mode 100644 index 000000000000..e29604a864b7 --- /dev/null +++ b/arch/arm64/kvm/ptdump.c @@ -0,0 +1,268 @@ +// 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 +#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) +{ + 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_build_levels(struct ptdump_pg_level *level, u32 start_lvl) +{ + u32 i; + u64 mask; + + if (WARN_ON_ONCE(start_lvl >= KVM_PGTABLE_LAST_LEVEL)) + return -EINVAL; + + mask = 0; + 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++) { + snprintf(level[i].name, sizeof(level[i].name), "%u", i); + + level[i].num = ARRAY_SIZE(stage2_pte_bits); + level[i].bits = stage2_pte_bits; + level[i].mask = mask; + } + + return 0; +} + +static struct kvm_ptdump_guest_state *kvm_ptdump_parser_create(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 ERR_PTR(-ENOMEM); + + 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], + .start_address = 0, + }; + + return st; +} + +static int kvm_ptdump_guest_show(struct seq_file *m, void *unused) +{ + int ret; + 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 = &st->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->seq = m; + + write_lock(&kvm->mmu_lock); + ret = kvm_pgtable_walk(mmu->pgt, 0, BIT(mmu->pgt->ia_bits), &walker); + 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; + struct kvm_ptdump_guest_state *st; + int ret; + + if (!kvm_get_kvm_safe(kvm)) + return -ENOENT; + + st = kvm_ptdump_parser_create(kvm); + if (IS_ERR(st)) { + ret = PTR_ERR(st); + goto err_with_kvm_ref; + } + + ret = single_open(file, kvm_ptdump_guest_show, st); + if (!ret) + return 0; + + kfree(st); +err_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); +} + +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, +}; + +static int kvm_pgtable_range_show(struct seq_file *m, void *unused) +{ + struct kvm_pgtable *pgtable = m->private; + + seq_printf(m, "%2u\n", pgtable->ia_bits); + return 0; +} + +static int kvm_pgtable_levels_show(struct seq_file *m, void *unused) +{ + struct kvm_pgtable *pgtable = m->private; + + seq_printf(m, "%1d\n", KVM_PGTABLE_MAX_LEVELS - pgtable->start_level); + return 0; +} + +static int kvm_pgtable_debugfs_open(struct inode *m, struct file *file, + int (*show)(struct seq_file *, void *)) +{ + 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, show, pgtable); + if (ret < 0) + kvm_put_kvm(kvm); + return ret; +} + +static int kvm_pgtable_range_open(struct inode *m, struct file *file) +{ + return kvm_pgtable_debugfs_open(m, file, kvm_pgtable_range_show); +} + +static int kvm_pgtable_levels_open(struct inode *m, struct file *file) +{ + return kvm_pgtable_debugfs_open(m, file, kvm_pgtable_levels_show); +} + +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_range_fops = { + .open = kvm_pgtable_range_open, + .read = seq_read, + .llseek = seq_lseek, + .release = kvm_pgtable_debugfs_close, +}; + +static const struct file_operations kvm_pgtable_levels_fops = { + .open = kvm_pgtable_levels_open, + .read = seq_read, + .llseek = seq_lseek, + .release = kvm_pgtable_debugfs_close, +}; + +void kvm_s2_ptdump_create_debugfs(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_range_fops); + debugfs_create_file("stage2_levels", 0400, kvm->debugfs_dentry, + kvm, &kvm_pgtable_levels_fops); +}