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 BA809C2BD09 for ; Mon, 1 Jul 2024 14:23:11 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From: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=of8h/yHjfyVd8gobR+fvjPEOrNpXyMTMcmCaItkRWUw=; b=UT90X6qbBi2Sgd+v9LAxudDCHP BjXNLDhN/l//qQLotdjnkYg47vLZXK/KdStdNy9btD0gIkXhdTvfMQCB2ewyCnttGCH7Whca/xfKH pfNaug080GJzt/y6m3BAUQI0G+kt+IWHvAi/gFcrZRR8ZQQXRsiXrjCmk1F2uCrnlHmXCa+bUYRDo RzK87G4s84A05XUeGoQAbv2wgYIT4yxRNY9gDHY7/YvGL314kR2FpxyhgIeWFuGMLr9y5Rb7uuxw5 Pa6ESR3hFsJz8X4tW8P/vI2gHE4Opdo1+IIsVPAVecejk4XHXZwKB1Tz8T5m9WMhwXPhOWLxsIC8j mV7QU6jA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOHvl-00000003i8S-2ZzD; Mon, 01 Jul 2024 14:22:57 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOHva-00000003i6B-33yK for linux-arm-kernel@lists.infradead.org; Mon, 01 Jul 2024 14:22:48 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-424a3cb87f1so88505e9.1 for ; Mon, 01 Jul 2024 07:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719843765; x=1720448565; 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=of8h/yHjfyVd8gobR+fvjPEOrNpXyMTMcmCaItkRWUw=; b=hVrJUICDwlxzXezalS1wpudcCi+yBdRy/qnr1nXrBJxnyG6zqTyYTl9inJvxFXvoB2 wM64H+eAGwBK9Eo6BAA/RTmManrSQ+XL2J+cLW16vNGKogopyAFVfmVpb4rWmuKXQ1t4 hT/tK4F0hDjw0H2dWWkL6D/dZ7Dje9lfRmuNmTLwHpgtrBOiA9Jrk/PTVHkHtAavAUPD +XwcQHot8shpZzIuxJIsWJ0oGyuNfpyu5KQncLlUBUdMOBJZJTv0LIX+EJH+Gf1nZgm/ fp3YH4Kwe6sCi0oOiMv0Bl4vPTIl+fDAzWJ/Pu7uSnWY1+whKrSxEn2BuwSBR/YKwQWb LJeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719843765; x=1720448565; 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=of8h/yHjfyVd8gobR+fvjPEOrNpXyMTMcmCaItkRWUw=; b=KAO5jjKV9bXOJhdhUk54kIqpWIMJWDMEp20bchgkOSPFKHTndUBn1D2bEEIiZRGXAZ g7W7jfkHdGa036KYh61NhfIH1IR2jm+hyeCiMl87J/rkP81/xJl4X7gstgRYOM9JUH0O 9Z2r5hQNubGAHsZ40rsHfqMSQfeyW5DMAw68BbHlCIKKog4WgqTqzw6EmQ8JPvIweaal TWWVAUi5bQaTcDgfa3SXe5W0PaFddsjAYA2AwSKXWkJBN4Dsm2RZjfF2pFaTWo0kT1eW 91kJKOe/jzuayntV/aQBwyHQB+Qy+W7hsQZT5wQBZE9fSTw3uNWrHGhlBl72QL3aDPJ7 t8LA== X-Forwarded-Encrypted: i=1; AJvYcCVIJrcO7gnAYvklb97RCYBSLqnQaNxi5+VdKmrc5BFEj8GQnPA+ppEcu8tHUjhmAS5CoKb0F35+xlFt71lk9Six/J000MIotPxiXhGDaWXhXraUr84= X-Gm-Message-State: AOJu0YwioJxSKT0IfOJYh9Dh/pxSHORfcUD7HXD7vWPO+aibiEmSs/Po sfRbEdglQbyMUiKbG7/c40WUb3s0PAvdX8QlNT8dgjmUr2XEbJ1FBRyuE06xjw== X-Google-Smtp-Source: AGHT+IFAq/GFiNJ0adtx2OIotan4cZfIRVizFxAq75sexqi9Few6MhuACXgBYA4CjeCEBo5vIrjeuQ== X-Received: by 2002:a05:600c:3550:b0:41a:444b:e1d9 with SMTP id 5b1f17b1804b1-425777f8671mr3614145e9.4.1719843765016; Mon, 01 Jul 2024 07:22:45 -0700 (PDT) Received: from google.com (216.131.76.34.bc.googleusercontent.com. [34.76.131.216]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257fc934b2sm59543115e9.44.2024.07.01.07.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 07:22:44 -0700 (PDT) Date: Mon, 1 Jul 2024 14:22:43 +0000 From: Sebastian Ene To: Oliver Upton Cc: 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, rananta@google.com, ryan.roberts@arm.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v7 0/6] arm64: ptdump: View the second stage page-tables Message-ID: References: <20240621123230.1085265-1-sebastianene@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240701_072246_802250_F2943FDD X-CRM114-Status: GOOD ( 45.86 ) 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 On Fri, Jun 28, 2024 at 09:25:26PM +0000, Oliver Upton wrote: Hello Oliver, > Hi Seb, > > I think we're getting closer on this series, thanks for reposting it. In > addition to polishing up the KVM side of things, I'd like to have acks > on the ptdump changes (patches 2-3). > > Will + Catalin, any concerns? > > -- > Thanks, > Oliver Thanks for the feedback, I will spin a v8 later this week if there are no more findings on the remaining patches. Thanks, Sebastian > > On Fri, Jun 21, 2024 at 12:32:24PM +0000, Sebastian Ene wrote: > > Hi, > > > > > > This series extends the ptdump support to allow dumping the guest > > stage-2 pagetables. When CONFIG_PTDUMP_STAGE2_DEBUGFS is enabled, ptdump > > registers '/sys/debug/kvm//stage2_page_tables' entry with debugfs > > upon guest creation. This allows userspace tools (eg. cat) to dump the > > stage-2 pagetables by reading the registered file. > > > > Reading the debugfs file shows stage-2 memory ranges in following format: > > > > > > Below is the output of a guest stage-2 pagetable dump running under Qemu: > > > > ---[ IPA bits 33 start lvl 2 ]--- > > 0x0000000000000000-0x0000000080000000 2G PGD > > 0x0000000080000000-0x0000000080c00000 12M PGD R W AF BLK > > 0x0000000080c00000-0x0000000080e00000 2M PGD XN R W AF BLK > > 0x0000000080e00000-0x0000000081000000 2M PGD R W AF BLK > > 0x0000000081000000-0x0000000081400000 4M PGD XN R W AF BLK > > 0x0000000081400000-0x000000008fe00000 234M PGD > > 0x000000008fe00000-0x0000000090000000 2M PGD XN R W AF BLK > > 0x0000000090000000-0x00000000fa000000 1696M PGD > > 0x00000000fa000000-0x00000000fe000000 64M PGD XN R W AF BLK > > 0x00000000fe000000-0x0000000100000000 32M PGD > > 0x0000000100000000-0x0000000101c00000 28M PGD XN R W AF BLK > > 0x0000000101c00000-0x0000000102000000 4M PGD > > 0x0000000102000000-0x0000000102200000 2M PGD XN R W AF BLK > > 0x0000000102200000-0x000000017b000000 1934M PGD > > 0x000000017b000000-0x0000000180000000 80M PGD XN R W AF BLK > > > > Link to v6: > > https://lore.kernel.org/all/20240220151035.327199-1-sebastianene@google.com/ > > > > Link to v5: > > https://lore.kernel.org/all/20240207144832.1017815-2-sebastianene@google.com/ > > > > Link to v4: > > https://lore.kernel.org/all/20231218135859.2513568-2-sebastianene@google.com/ > > > > Link to v3: > > https://lore.kernel.org/all/20231115171639.2852644-2-sebastianene@google.com/ > > > > Changelog: > > v6 -> v7: > > * Reworded commit for this patch : [PATCH v6 2/6] arm64: ptdump: Expose > > the attribute parsing functionality > > * fixed minor conflicts in the struct pg_state definition > > * moved the kvm_ptdump_guest_registration in the > > * kvm_arch_create_vm_debugfs > > * reset the parse state before walking the pagetables > > * copy the level name to the pg_level buffer > > > > > > v5 -> v6: > > * don't return an error if the kvm_arch_create_vm_debugfs fails to > > initialize (ref. > > https://lore.kernel.org/all/20240216155941.2029458-1-oliver.upton@linux.dev/) > > * fix use-after-free suggested by getting a reference to the > > KVM struct while manipulating the debugfs files > > and put the reference on the file close. > > * do all the allocations at once for the ptdump parser state tracking > > and simplify the initialization. > > * move the ptdump parser state initialization as part of the file_open > > * create separate files for printing the guest stage-2 pagetable > > configuration such as: the start level of the pagetable walk and the > > number of bits used for the IPA space representation. > > * fixed the wrong header format for the newly added file > > * include missing patch which hasn't been posted on the v5: > > "KVM-arm64-Move-pagetable-definitions-to-common-heade.patch" > > > > > > v4 -> v5: > > * refactorization: split the series into two parts as per the feedback > > received from Oliver. Introduce the base support which allows dumping > > of the guest stage-2 pagetables. > > * removed the *ops* struct wrapper built on top of the file_ops and > > simplify the ptdump interface access. > > * keep the page table walker away from the ptdump specific code > > > > v3 -> current_version: > > * refactorization: moved all the **KVM** specific components under > > kvm/ as suggested by Oliver. Introduced a new file > > arm64/kvm/ptdump.c which handled the second stage translation. > > re-used only the display portion from mm/ptdump.c > > * pagetable snapshot creation now uses memory donated from the host. > > The memory is no longer shared with the host as this can pose a security > > risk if the host has access to manipulate the pagetable copy while > > the hypervisor iterates it. > > * fixed a memory leak: while memory was used from the memcache for > > building the snapshot pagetable, it was no longer giving back the > > pages to the host for freeing. A separate array was introduced to > > keep track of the pages allocated from the memcache. > > > > > > v2 -> v3: > > * register the stage-2 debugfs entry for the host under > > /sys/debug/kvm/host_stage2_page_tables and in > > /sys/debug/kvm//stage2_page_tables for guests. > > * don't use a static array for parsing the attributes description, > > generate it dynamically based on the number of pagetable levels > > * remove the lock that was guarding the seq_file private inode data, > > and keep the data private to the open file session. > > * minor fixes & renaming of CONFIG_NVHE_EL2_PTDUMP_DEBUGFS to > > CONFIG_PTDUMP_STAGE2_DEBUGFS > > > > > > v1 -> v2: > > * use the stage-2 pagetable walker for dumping descriptors instead of > > the one provided by ptdump. > > * support for guests pagetables dumping under VHE/nVHE non-protected > > > > Thanks, > > > > Sebastian Ene (6): > > KVM: arm64: Move pagetable definitions to common header > > arm64: ptdump: Expose the attribute parsing functionality > > arm64: ptdump: Use the mask from the state structure > > KVM: arm64: Register ptdump with debugfs on guest creation > > KVM: arm64: Initialize the ptdump parser with stage-2 attributes > > KVM: arm64: Expose guest stage-2 pagetable config to debugfs > > > > arch/arm64/include/asm/kvm_pgtable.h | 42 +++++ > > arch/arm64/include/asm/ptdump.h | 42 ++++- > > arch/arm64/kvm/Kconfig | 14 ++ > > arch/arm64/kvm/Makefile | 1 + > > arch/arm64/kvm/arm.c | 2 + > > arch/arm64/kvm/hyp/pgtable.c | 42 ----- > > arch/arm64/kvm/kvm_ptdump.h | 20 ++ > > arch/arm64/kvm/ptdump.c | 272 +++++++++++++++++++++++++++ > > arch/arm64/mm/ptdump.c | 50 +---- > > 9 files changed, 402 insertions(+), 83 deletions(-) > > create mode 100644 arch/arm64/kvm/kvm_ptdump.h > > create mode 100644 arch/arm64/kvm/ptdump.c > > > > -- > > 2.45.2.741.gdbec12cfda-goog > > > > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >