Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp872108rdb; Fri, 20 Oct 2023 01:40:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERXopZKQt//w2jnkHC7SjNEmff5vp/Ht5/Xskvd7N5bwtkBLzB0UmQsKTpV28syD3KNHpM X-Received: by 2002:a17:902:e844:b0:1c6:25c3:13d3 with SMTP id t4-20020a170902e84400b001c625c313d3mr1309607plg.6.1697791236170; Fri, 20 Oct 2023 01:40:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697791236; cv=none; d=google.com; s=arc-20160816; b=oRAn37srNzRweH8Kt/WMx2OEX+ujnDFDqEbEwrD7pGVCxoT2vM0XN8GXyZs4nsD10K Y26yfKRhPjkz5l3B2CNwX968OxyDKjKlZiEc/PgOVkOkUkKawbZsu6gJ2oFhBRktn56K /9CGThxqAcRPWySs/NBO1rZS8GQEW+qPvXqm0Sm0LF2obk2Qmaz9m3w/TV7alYECtS17 JjpBNyys98RS2eUSAA0evy3BlNRqIyxYG/Zo9RPiVICPILzEWKuq7CZyCeFxqAiZfmLj RtRNGwP91PriYbPtv/irc7pHgjXIrDa6H56Zp3otOHTQzY7KpkgTb/AtH76BLlQdelsh 22oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=cyWHa/QB8NjRGYd7Kdth0egvi9lD9HQW7X6C8NUiI8w=; fh=WXeSuK+gnSEj6KFyZ/hJG6H5V7edjtjoFBUmHd+/dHE=; b=tnmhpAUWY0UasH9FY2cpnT+7zenti3uBuDHgKgA7wo1PuKJjoLB/ic52QjO3Jy0r/V T++pYo7fKQjsHEsQ/6Wvubw90oTP3ciS5NoXtv47eWqoa9FtgIZgDSRoqPWJZUHHIvKO BIogVGbF0ONwBxltJzI+S/yFDEaLaT2fFLl5zriXxs9nZ03EqGY9DZWwSMgES/f95KZH Uo4NnJCi0Z558nucSS7+aEr0eo84KyoLEqrdyXxuXTOIw4tmbtxfegMH3Tpp6TdH/TpI QyvqswQKM4G7nFGQgJtVQpGhkRnk90etFn4bk3TB9jRoQ4ccxog0eP9PaBHIDaGdnUfp W9zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=R6Q9Cvow; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id y1-20020a170902700100b001bdca6456c3si1270660plk.46.2023.10.20.01.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 01:40:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=R6Q9Cvow; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 254BD82271AE; Fri, 20 Oct 2023 01:40:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376486AbjJTIkP (ORCPT + 99 others); Fri, 20 Oct 2023 04:40:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376458AbjJTIkO (ORCPT ); Fri, 20 Oct 2023 04:40:14 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D979D46 for ; Fri, 20 Oct 2023 01:40:12 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4081ccf69dcso9788045e9.0 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=vger.kernel.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=R6Q9CvowKhcmQWW1f2rva1p1n7DN2FMihksDL7sAFzNUe9N4p318YE0L8GeXhZscMJ c0MZdOtzCr+NiOUcbo1QusvUM3k40bdiqTEjn8fOVmZOY8AW3FKn+1fNItDHuDFz9aEg gFW5QbmdAznI6XpAGeM+eyYDw0IkyBPwcK0GVGnQfcVZYEAboxhmPdbMbmXUk0YTduiN HVyp3ALN8aywww0upNGlEmKDZxuKV06gl7wqFVbmJZnYpHYBKNYUxSGdXZgGk7nB0QMS BFVlC7Xq8pInPMZKBwW4tBJZB/KRH5egPWGLgph4jh/Vnnq0Wk3eSrB6nO+6s5AarIuz BJCw== 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=EwG6w3KJ7z4y8xmAovQ6n+o/NH4BlXpIzCy2ib/M/TTq4cVu5t2ykqbGRlxuxDOCdy 40oJDubzJtL66y/kXVOW6gf8eAabmhu401MyxPYvMsiOoGR0Z06jdhdak0BKS/Slzevp 3v66dYmGB0vv/iin+XKgna8G0KuBoD3JDSqRDCXF1xAHXELShV+ir2sUZ+D42pTlparb tp7TWFnZNjAme3Qvfd+iiCtBekfp0H1ZE84ePVYEVRdgW/cG2x0bUfO98ircqLU7jjy3 KCIXUdlua3XZl2ZNpJr1l+EOhJDjsOUtpT3/Y/vuXVef6jK/JwLPXEiUHd2AMzVwY9fP wXlg== X-Gm-Message-State: AOJu0Yx1hlFFc5KEEgRZJMMcQ7WrEkwnFTY8IOLEMfCJS6Q8GcTnTiDQ 5+/VkKJiDN+j5seAs9Qnpzlb+w== 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231019144032.2943044-13-sebastianene@google.com> X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 20 Oct 2023 01:40:33 -0700 (PDT) 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); > } [...]