Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2496564rdh; Wed, 27 Sep 2023 04:40:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFv5ou+MMODEWNnaC2kmVLUB1kMkN6Pw5oIakvNbLTEDhtjoQBZhNgUtE25rfFRjA3rOu8S X-Received: by 2002:a17:902:e548:b0:1c3:9632:f144 with SMTP id n8-20020a170902e54800b001c39632f144mr1611727plf.31.1695814812318; Wed, 27 Sep 2023 04:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695814812; cv=none; d=google.com; s=arc-20160816; b=FzH6anSYJ1NMWD4XW+pRYrQjA8Jtoo5LmngFz1+8NV5i0N/OX/LFofL1DQZzN36YkH c4RuQVQnthfzu2weJfVJi1yaxJIGrxslSrZgSqNrtiaZmU75LN8nxrHUIRB2x4fXU43j uobdOdkF5WotvZmuP3+OU/cGrK8eWH0n4Y0XHjW3glU7M8frKU9UyHDfqBXtmglj2V73 LieJDp//3mztE1eNg1fg62iO/ux/SoXd4aNw/S9WJvepfrlpBKQV/ZQvXBqTs55D/bBI bC1sCs3/QCP4lwlykUbWjC4yJcMF2rXnAL2IDFkBtyrBykhS6Z7knk57n7riqblzi+g6 F7Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=mpo8HY1lxvqmx97jvOfRTD6LY/4QndhKsDHjqUrtCfE=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=TagdlX4Od6LyNoV1lQSbRCXR2cokb/s3ak1iCvSr5C8F6qvz0eZpiYkCwdsCeLd2ac ynOlRINIrd1pPArUy4Vsh8AL30BeXQm+bFiMB1K6eM5p3D5Gqg1sq6hNg0WKcaAwxQ9e TDwQTa47Ch1+uLtd+gtON7aYkhRL2S8RUAPM5Rw51OFcdtwaKSuXI9bFDsvgpvkh+/wU UHAQcJerUbWGPldw7IkhORj6NY00cpLdC3/njyqxbvwrc5mROlF2JTqDd1S8LE6jLTP5 RQITwYg4cw4GNTUN1mgHHymQ7oOQETWu/NBgV8u/o8P1oE66wJ5TUPz/azCxbObgZENt WX0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MkJaiaJb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id ay6-20020a1709028b8600b001bbd81eaabasi14969994plb.57.2023.09.27.04.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 04:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MkJaiaJb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 457C8809F3AD; Wed, 27 Sep 2023 04:26:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231423AbjI0LZm (ORCPT + 99 others); Wed, 27 Sep 2023 07:25:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231376AbjI0LZk (ORCPT ); Wed, 27 Sep 2023 07:25:40 -0400 Received: from mail-lf1-x14a.google.com (mail-lf1-x14a.google.com [IPv6:2a00:1450:4864:20::14a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BA50180 for ; Wed, 27 Sep 2023 04:25:38 -0700 (PDT) Received: by mail-lf1-x14a.google.com with SMTP id 2adb3069b0e04-5041ea5abb6so15482450e87.2 for ; Wed, 27 Sep 2023 04:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813936; x=1696418736; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=mpo8HY1lxvqmx97jvOfRTD6LY/4QndhKsDHjqUrtCfE=; b=MkJaiaJbBLYotnvrRbk6Rjo9stHVueN71k5Xcwazk/ZA7ZdUukTgpZ/QsiZIEhs1ec UsIt8iIipJ+FdzDw1FANyDEp+BsYqy60m0Q7IybsXnVY4Z5wjO1CY5WY++vjFUT7lmIh Bh7N/0GBnG5vsl6qHYZNTHpk6SAEhGKykTXtA1O2GBpDFSufpOoV2qII7bj6mBtsJrxY LKHl8oHjdG4QQ9zCt1xOJsqcclsWqDoaERfkvDTKWEn1nSZrK367y6afkEhw7GR4VFhc UG4l1AUZqfcLLtyzlgNicfJd8lhgZpBRewUPsebgg+Lk8jjs9U0HZYKb0Rb+m5ZCl9zr GnoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813936; x=1696418736; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mpo8HY1lxvqmx97jvOfRTD6LY/4QndhKsDHjqUrtCfE=; b=AhVT6l0yS0dcPUsSkl4c9hG9YnnhVGuvQWkPntwfSAbeNEcqTHlaJVcZS95L8ckmKa B7aZz+prlHv8BpD13hV0i2rDsbhTYLf/VFFfAlH9fN5toucvp+yv1tm1vAFqrGonF9Iy N0UlwUXEPLjnajogPjBe8BQ2yc5YTIGCMHtdSNsfuxCfEM3wHb60zc306tWqjEoOAxQN h/4p+/Q7Z7NU7qbCRJ3n5GAS+h8cdKiJkSHkfc/O7PbKcWcf6btFPBeVPCqyToUa8vsM OcizjSLDD1IrL2ncxzmS3GWg5kzDZFzsZwcbQ4E44oEx8i98V2UPPFoPnHuP+NNsA/ol UIjg== X-Gm-Message-State: AOJu0YyTLHqgn6P914qDE6qvl8ob9lPdx2Kz636nB/BLqLBy6zlxgJjm 63h7Wo3N4DGykAd7Mrh+FZrWfWlvhZ+xtee3xt3jcb7v7ZM0MT4LnBR3UEun8Nx1aKu2SrM0GwB XnIbzIbQMJPbIk2AqXKU003kndyBocfzSARJycFHXeYQ5MbkDqBRK7cK+kayMS+qM80GG25JcTN GQoOr/dekbIw== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:ac2:43b5:0:b0:503:2e24:5692 with SMTP id t21-20020ac243b5000000b005032e245692mr8242lfl.5.1695813936285; Wed, 27 Sep 2023 04:25:36 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:06 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-1-sebastianene@google.com> Subject: [PATCH 00/11] arm64: ptdump: View the host stage-2 page-tables From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene Content-Type: text/plain; charset="UTF-8" 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 groat.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 (groat.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:04 -0700 (PDT) Hi, This can be used as a debugging tool for dumping the host stage-2 page-tables under pKVM envinronment. When CONFIG_NVHE_EL2_PTDUMP_DEBUGFS is enabled, ptdump registers the 'host_stage2_kernel_page_tables' entry with debugfs and this allows us to dump the host stage-2 page-tables with the following command: cat /sys/kernel/debug/host_stage2_kernel_page_tables The output is showing the entries in the following format: The tool interprets the pKVM ownership annotation stored in the invalid entries and dumps to the console the ownership information. To be able to access the host stage-2 page-tables from the kernel, a new hypervisor call was introduced which allows us to snapshot the page-tables in a host provided buffer. The hypervisor call is hidden behind CONFIG_NVHE_EL2_DEBUG as this should be used under debugging environment. I verified this series with Qemu and Pixel 6 both using kvm-arm.mode=protected. Thanks, Sebastian Ene (11): KVM: arm64: Add snap shooting the host stage-2 pagetables arm64: ptdump: Use the mask from the state structure arm64: ptdump: Add the walker function to the ptdump info structure KVM: arm64: Move pagetable definitions to common header arm64: ptdump: Introduce stage-2 pagetables format description arm64: ptdump: Register a debugfs entry for the host stage-2 page-tables arm64: ptdump: Snapshot the host stage-2 pagetables arm64: ptdump: Parse the host stage-2 page-tables from the snapshot arm64: ptdump: Interpret memory attributes based on runtime configuration arm64: ptdump: Interpret pKVM ownership annotations arm64: ptdump: Fix format output during stage-2 pagetable dumping arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_pgtable.h | 85 ++++ arch/arm64/include/asm/ptdump.h | 6 + arch/arm64/kvm/Kconfig | 12 + arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 8 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 18 + arch/arm64/kvm/hyp/nvhe/mem_protect.c | 103 +++++ arch/arm64/kvm/hyp/pgtable.c | 98 +++-- arch/arm64/mm/ptdump.c | 405 +++++++++++++++++- arch/arm64/mm/ptdump_debugfs.c | 37 +- 10 files changed, 716 insertions(+), 57 deletions(-) -- 2.42.0.515.g380fc7ccd1-goog