From mboxrd@z Thu Jan 1 00:00:00 1970 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 E1D7EC004C0 for ; Mon, 23 Oct 2023 14:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5Z3y05lBsalZbV2WPeQcDW9Hb8wYtiqxYcJR+dF06GM=; b=gUGhM23LI0yRpk 5k/mTNUSfoNoi0S9OD+0iHVHrK+kinsSR+7N16KMzpRxbQdTY+ozCiR74Soox4KgIe14WRdptXXGW dGfUBahu3qxo6wpfyxQu9uLAF+jzkrqsNdtNwxPjUXHc/KQBbqgAeDBRCnABk3GiLmURr+4itmdIP t4TfxPHD9X0grskkfstCRKL9yN9R4VBojal64EMNV9FgkOw6enHgKylXSS3g/fSLniVpJcIw83Ph+ u1RYjKx9L6AyxXW15/PtAA7xTBaU3lxPWS/eEcfCTI89h5DsrzS6fygomYOdOiY141sOYIMkxiO4O EyEm0Azy0Wsd6J8J41lQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1quwBh-007c93-1V; Mon, 23 Oct 2023 14:45:49 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1quwBe-007c82-1B for linux-arm-kernel@lists.infradead.org; Mon, 23 Oct 2023 14:45:47 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4078fe6a063so108225e9.1 for ; Mon, 23 Oct 2023 07:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698072343; x=1698677143; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=fuPb49Nb7aOChMQEH9g60s/ZbKYpeY4nlEVZ7HXBAiA=; b=1QmDabmBfJHwA2MDFOi9qDaReuk8E3nV98S7Bnme6TqYVrIP7qgGqw0uZnzUl23ILK HOrcxdMV+W2oMLPx/xwiYMX8JaJrXHx/H6nGcL+D46ncTJkVVUYSu5Xp7DiedO2CwLoU //WTwogn2YZtX3WLUEZwuxDHUUtHn3ic2H0IZtCxo4b18nA+Baa5UebPxqdV4SXMShDf AN2Sok+qQJ88X3riYA1bLnSLH5NQV3OnzRMmW7MvBieQdkVnSII9M10nBk8PgQnn6wCg V9tipq4CtzJ4YUEZbP8utf/tQxHuNXixOFEZuHZ58iELmIF/LBoN6uMjGbiiiW6AbEyo bPdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698072343; x=1698677143; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fuPb49Nb7aOChMQEH9g60s/ZbKYpeY4nlEVZ7HXBAiA=; b=FHu79zXHakTltkenR3MmcWAZU4jGfpJFkwtukVfs9Fz9CsvVfF1fLm+8QiFTnDhTMB Rtdlo2xbyjXVhUbpGrHQK4M6ldhWT3GbCRDD7Y+jk7PvB8SPVMVfGXTLfUP041G8tj1l Ou2Dh8y4lkJfCHzizwrJuEmCsYujyW5GWPgcsI+C1VcercvM5nUSI/dX0ZXrKTmsOYKO K+EZtnW5u228xSnk+Mgg06G86qOLMlV2+1+1kXj8HbPcRlQJ9IUlRtlPXBCzsiAWU+t8 q+phqkMcY3npiw07EcSfNlV/cRXSUYbk78NKzH6WYdKyWwq8mpa6mTmLtntgqVXJ3Phd IrLw== X-Gm-Message-State: AOJu0YyAXQDGOw95pLATXSeZdk7BUFCxAFy9YYLruZjUU+cth0KfEE9m 2aX9kHdXG2EOJabRXdrEFb8t6g== X-Google-Smtp-Source: AGHT+IHqwhVuneopgxfquyjAU4kAvXwPMoACOMfUTgtwjupQH4aGGKknxjAFoNKlkarZI9e6tEFHlg== X-Received: by 2002:a05:600c:3b97:b0:408:3725:b96a with SMTP id n23-20020a05600c3b9700b004083725b96amr275253wms.0.1698072343243; Mon, 23 Oct 2023 07:45:43 -0700 (PDT) Received: from google.com (105.168.195.35.bc.googleusercontent.com. [35.195.168.105]) by smtp.gmail.com with ESMTPSA id r9-20020a056000014900b003232f167df5sm7888468wrx.108.2023.10.23.07.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 07:45:42 -0700 (PDT) Date: Mon, 23 Oct 2023 14:45:41 +0000 From: Sebastian Ene To: Vincent Donnefort Cc: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, qperret@google.com, smostafa@google.com Subject: Re: [PATCH v2 11/11] arm64: ptdump: Add support for guest stage-2 pagetables dumping Message-ID: References: <20231019144032.2943044-1-sebastianene@google.com> <20231019144032.2943044-13-sebastianene@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231023_074546_409116_9900D252 X-CRM114-Status: GOOD ( 39.10 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Oct 20, 2023 at 09:40:06AM +0100, Vincent Donnefort wrote: > On Thu, Oct 19, 2023 at 02:40:33PM +0000, Sebastian Ene wrote: > > Register a debugfs file on guest creation to be able to view their > > second translation tables with ptdump. This assumes that the host is in > > control of the guest stage-2 and has direct access to the pagetables. > > What about pKVM? The walker you wrote for the host stage-2 should be > reusable in that case? > Yes, when pKVM will be ready upstream the walker which duplicates the pagetables for the host will be re-used for the guests. We will have to add a separate HVC for this which receives as an argument the guest vmid. > > > > Signed-off-by: Sebastian Ene > > --- > > arch/arm64/include/asm/ptdump.h | 21 +++++++-- > > arch/arm64/kvm/mmu.c | 3 ++ > > arch/arm64/mm/ptdump.c | 84 +++++++++++++++++++++++++++++++++ > > arch/arm64/mm/ptdump_debugfs.c | 5 +- > > 4 files changed, 108 insertions(+), 5 deletions(-) > > > > diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h > > index 35b883524462..be86244d532b 100644 > > --- a/arch/arm64/include/asm/ptdump.h > > +++ b/arch/arm64/include/asm/ptdump.h > > @@ -5,6 +5,8 @@ > > #ifndef __ASM_PTDUMP_H > > #define __ASM_PTDUMP_H > > > > +#include > > + > > #ifdef CONFIG_PTDUMP_CORE > > > > #include > > @@ -30,14 +32,27 @@ struct ptdump_info { > > void ptdump_walk(struct seq_file *s, struct ptdump_info *info); > > #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); > > +struct dentry *ptdump_debugfs_register(struct ptdump_info *info, > > + const char *name); > > #else > > -static inline void ptdump_debugfs_register(struct ptdump_info *info, > > - const char *name) { } > > +static inline struct dentry *ptdump_debugfs_register(struct ptdump_info *info, > > + const char *name) > > +{ > > + return NULL; > > +} > > #endif > > void ptdump_check_wx(void); > > #endif /* CONFIG_PTDUMP_CORE */ > > > > +#ifdef CONFIG_NVHE_EL2_PTDUMP_DEBUGFS > > +void ptdump_register_guest_stage2(struct kvm_pgtable *pgt, void *lock); > > +void ptdump_unregister_guest_stage2(struct kvm_pgtable *pgt); > > +#else > > +static inline void ptdump_register_guest_stage2(struct kvm_pgtable *pgt, > > + void *lock) { } > > +static inline void ptdump_unregister_guest_stage2(struct kvm_pgtable *pgt) { } > > +#endif /* CONFIG_NVHE_EL2_PTDUMP_DEBUGFS */ > > I believe this should be compatible with VHE as well, that option should be > renamed. > Good point, I will rename this. > > + > > #ifdef CONFIG_DEBUG_WX > > #define debug_checkwx() ptdump_check_wx() > > #else > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > > index 482280fe22d7..e47988dba34d 100644 > > --- a/arch/arm64/kvm/mmu.c > > +++ b/arch/arm64/kvm/mmu.c > > @@ -11,6 +11,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -908,6 +909,7 @@ int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu, unsigned long t > > if (err) > > goto out_free_pgtable; > > > > + ptdump_register_guest_stage2(pgt, &kvm->mmu_lock); > > mmu->last_vcpu_ran = alloc_percpu(typeof(*mmu->last_vcpu_ran)); > > if (!mmu->last_vcpu_ran) { > > err = -ENOMEM; > > @@ -1021,6 +1023,7 @@ void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu) > > write_unlock(&kvm->mmu_lock); > > > > if (pgt) { > > + ptdump_unregister_guest_stage2(pgt); > > kvm_pgtable_stage2_destroy(pgt); > > kfree(pgt); > > } > > diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c > > index 4687840dcb69..facfb15468f5 100644 > > --- a/arch/arm64/mm/ptdump.c > > +++ b/arch/arm64/mm/ptdump.c > > @@ -26,6 +26,7 @@ > > #include > > #include > > #include > > +#include > > > > > > enum address_markers_idx { > > @@ -543,6 +544,22 @@ void ptdump_check_wx(void) > > #ifdef CONFIG_NVHE_EL2_PTDUMP_DEBUGFS > > static struct ptdump_info stage2_kernel_ptdump_info; > > > > +#define GUEST_NAME_LEN (32U) > > + > > +struct ptdump_registered_guest { > > + struct list_head reg_list; > > + struct ptdump_info info; > > + struct mm_struct mem; > > + struct kvm_pgtable_snapshot snapshot; > > + struct dentry *dentry; > > + rwlock_t *lock; > > + char reg_name[GUEST_NAME_LEN]; > > +}; > > + > > +static LIST_HEAD(ptdump_guest_list); > > +static DEFINE_MUTEX(ptdump_list_lock); > > +static u16 guest_no; > > This is not robust enough: If 1 VM starts then 65535 others which are killed. > guest_no overflows. The next number is 0 which is already taken. > Yes, I guess this should be improved. In the case you described we won't register any debugfs file because of the name clash. > Linux has and ID allocation to solve this problem, but I don't think this is > necessary anyway. This should simply reuse the struct kvm->debugfs_dentry. > > Also probably most of the informations contained in ptdump_registered_guest can > be found in struct kvm. The debugfs should then probably simply take struct kvm > for the private argument. > I would prefer to keep it as a separate struct here as it gives some flexibility if we need to extend it for guests pKVM support. I think we can drop the struct mm_struct from here. Thanks, Sebastian > > + > > static phys_addr_t ptdump_host_pa(void *addr) > > { > > return __pa(addr); > > @@ -740,6 +757,73 @@ static void stage2_ptdump_walk(struct seq_file *s, struct ptdump_info *info) > > > > kvm_pgtable_walk(pgtable, start_ipa, end_ipa, &walker); > > } > > [...] _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel