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 CBD7ECDB474 for ; Fri, 20 Oct 2023 08:40:40 +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=0LxmcZDlNjX5a5nUjcgJ1L6yYybRaTk+0vJ73VmDDFs=; b=z5kkvZHijn/lbV 6fYljRFko5jGkqpeFpYfnOoiB/27admKBgbUHoYeKXWfYPsgs9yFSSCD7C9HI1cBCFlY0VGed/AI9 bz8QeIgWBAJuJwrsCz0ZYij1lm48KBBYKROWwvFaKzvVZy9dZCSvFJIhLXPwHKkV9FUu3ESEGwTmX /H5sOhLg2LZf8ce3Hp6WJGRRVIsCi5D0OxWxoNhq5i6d5b6hUwECLfSne6DlM8xIR4Ama69F8zX4E Qiq1i1Xf0vXxibeOSJJO8Aq1kUdV0wIsNziyWSI0YoW8x51hHNpJ9PMAepw9XicfpS1OAdxE8a10J 7o3k0EK+GOvncieVAQlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtl3J-001a8X-0S; Fri, 20 Oct 2023 08:40:17 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtl3F-001a7f-2D for linux-arm-kernel@lists.infradead.org; Fri, 20 Oct 2023 08:40:15 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40675f06f1fso9706785e9.1 for ; Fri, 20 Oct 2023 01:40:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697791211; x=1698396011; 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=cyWHa/QB8NjRGYd7Kdth0egvi9lD9HQW7X6C8NUiI8w=; b=vn75qmWJhqNw3AePR8dKqcZzYb/K2n2NK0GgMhhKpY8frHc3DjnhAONLupV5GE/fdC X5XGjxd9Opnl7tUMc907C6DSRFR/lvIlC3oBBEmmefJDUVAcwavQ0uM8S2Ep8MjMG2Aw XsAIyHm8IWOhST3rrzNwPsxQUrJ1rDLpuv9QEXXna4JJLU/FtZbUN5pLSL3YCEliACft bFgoNR2/Vj+VUfWZojqd8srHkZExDWJfDRYuxVNl1NOoIapw6EP2b9KLQwgoPrZfVQqe EaFryPWgzar1PlkcsJa/6d2AXZFvokyEp/ANQqHJ5UaGV3/vQ2lbFvjJMkf7/htuj2vX 3fRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697791211; x=1698396011; 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=cyWHa/QB8NjRGYd7Kdth0egvi9lD9HQW7X6C8NUiI8w=; b=lbrVuULoGQ6nFmh1ZO9IHDg1ltRaGhudtRK4Qzm818l4djWGX/lnAude1JBFAHAcA3 1bmXzzc7oWsn70Kk412at9vpRlUjplUm2+oeX/+UvRybuK1kwXzjpxTuHnn4iK5xTE4o UAjwtS9hBgDypTjCHXzpMsOHgCgOND/SFVSoJI3ZbOmzZniGdXRh30Ka+QyrHyVBCkqN CwmRkiA7fOsMsntcCMkAV/kKq0YwZ/naE4CQMPycUpwVmzJhdyw3vnaa2/I3PEWx9lO7 rQadCg1aS8tLpsMYmEitb6ibhnUAfQnMy5c8187uv5X51+pOEuy/9lk/52BXRKzR8b7Y JTsg== X-Gm-Message-State: AOJu0YxqpFXHXlsoG5nLyFh5mUlzbVNgMti+f0EQjoNM4SIlgYkutmt/ hY7i99OAK++tP0qgYWO31dX2Zw== X-Google-Smtp-Source: AGHT+IGe62Ste2VstOvjYH0ZAedP5PLzGr5YmyGE8u3E0mTEelJwHqktcfhkfiSIxhwAUpDgwHnIjQ== X-Received: by 2002:a05:600c:b4d:b0:408:33ba:569a with SMTP id k13-20020a05600c0b4d00b0040833ba569amr4301728wmr.8.1697791210584; Fri, 20 Oct 2023 01:40:10 -0700 (PDT) Received: from google.com (65.0.187.35.bc.googleusercontent.com. [35.187.0.65]) by smtp.gmail.com with ESMTPSA id i21-20020a05600c355500b00405bbfd5d16sm1635616wmq.7.2023.10.20.01.40.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 01:40:10 -0700 (PDT) Date: Fri, 20 Oct 2023 09:40:06 +0100 From: Vincent Donnefort To: Sebastian Ene 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: <20231019144032.2943044-13-sebastianene@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231020_014013_729111_A87D084A X-CRM114-Status: GOOD ( 29.59 ) 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 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? > > 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. > + > #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. 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. > + > 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