From patchwork Wed Nov 15 17:16:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13457132 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 5C70DC54FB9 for ; Wed, 15 Nov 2023 17:17:24 +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:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=K0J2z3+EtaV/Y9VD03OQBj0pwONxRunnvxuvN7yM8YM=; b=i6F fq7uuseDsbC84Jex8Qk0nWGW89J3H5ZpNQVb3uo3DjDYyE8j/0jtJ5CKRekXKxlXIsJsjYhgE+zOQ zrcdc0ABN7K5xvJ4D73aISnCFvXFy4wfnWw6RURysO/ETxs/iWC1KZcRa7ZSR/c0YQH2YU3k7v5h8 /6zFNYypMSjXJdY1a2GiGBO0vSR3shjYyxCCukaNbqrVBr7BWBcNjfRtAn/6ztkXjy3fehrswXo0W xXzIlH3gLabQP3Eh0mNkiUZSrLz0ykPinRJK9AVeuDapmtjhrrSLcAKJOkQj+2p6QojfFU0jrgFmT xxHjsPcDhkDr9HhjxQnP/eaA3BOp1Bw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r3JVb-001PRH-1X; Wed, 15 Nov 2023 17:16:59 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r3JVY-001PQJ-2F for linux-arm-kernel@lists.infradead.org; Wed, 15 Nov 2023 17:16:58 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-da307fb7752so8929606276.0 for ; Wed, 15 Nov 2023 09:16:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068613; x=1700673413; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=jvaWmO0FnVQSvQa+hPtEgtYlB7ewMwZZNTNrDNriGoM=; b=PAovyjGVziHdyCXKkHEJ2cZb3ctGHpvSK9VFA6t3ax/DjAftF0prWXmgoyW9jz5FRE MHzha4IYEhVpUSjcVzw44z0lP6KADmkhnNllZvdq7TEs2bfDcDQq12aSAR6ISRdf2v9O sei9XEtap/8U+x61EGoC/yo/YeX+mXOYWbPF7QdChXP3/diXpkruI42UQ1OR2hdT4SJ3 PBkQzxLp1Xv5/JkzZcqXOn1g29/lfoSvfQNoYCpT9hd8H9cD/7k+TLi5sX75LFJRdTvZ IYA8hdcMhuNXOYERif6DoHy72jrNo+U2kwLqryT6YklXaZ29LMgPnZ06y0otumZxxtta X5RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068613; x=1700673413; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jvaWmO0FnVQSvQa+hPtEgtYlB7ewMwZZNTNrDNriGoM=; b=RygdDlYaiEliJFnvJt/OAjO2qvKOZN3+rTSbJt4Vd9+q1zsh+IgR/8+/aMTsDAxTMd m5BtWXOgePOP+Hbi2qO1tMKZtSm5EIqVRnKdk0YAQU1Yh8W9ul+f3F+QL+P5pTxqtAmx 3kw5qaCZz/v2SX8MLJQXzeB8lIXH5aQ23VLa+c7vmiWOHRgv17QOmxTBRYfG/MSc5qY4 OFIp6mLlbZ1oc/0G5PJVmfJTY3TNdFRw0nwBoWIWusOgaZWNd8AypNTcgmMz8SoqsEsC B3suBNwk2vQy+1L8EJPydHCujJPpbGXKNgD1HlIv+TFw01KE2E+q+Sk7zBanWxZnk/FA FhVQ== X-Gm-Message-State: AOJu0YyTSruVFhzviTPZ3cbfIx6Lhdlh0fIn2f+1EN6A7QL0ANLydpi1 FX/LCE68n0XS91O1j/c35I/0ASXm+1MJowbQlUg= X-Google-Smtp-Source: AGHT+IGpTPHEt6mqVGX4OcHH3rw9Bhky+H2JiZ2u6YBAqgXzSwAP/9U1Wj0MXTkRRyqmx1wx/ooeavPE5/IIuxO7qck= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a25:24c7:0:b0:daf:660e:9bdb with SMTP id k190-20020a2524c7000000b00daf660e9bdbmr176609ybk.6.1700068613223; Wed, 15 Nov 2023 09:16:53 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:30 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-2-sebastianene@google.com> Subject: [PATCH v3 00/10] arm64: ptdump: View the second stage page-tables From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231115_091656_754899_CDC296E7 X-CRM114-Status: GOOD ( 16.01 ) 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 Hi, This can be used as a debugging tool for dumping the second stage page-tables. 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: Under pKVM configuration(kvm-arm.mode=protected) ptdump registers an entry for the host stage-2 pagetables in the following path: /sys/debug/kvm/host_stage2_page_tables/ 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. Link to the second version: https://lore.kernel.org/all/20231019144032.2943044-1-sebastianene@google.com/#r Link to the first version: https://lore.kernel.org/all/20230927112517.2631674-1-sebastianene@google.com/ Changelog: 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 (10): 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: Add hooks on debugfs file operations arm64: ptdump: Register a debugfs entry for the host stage-2 tables 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: Add support for guest stage-2 pagetables dumping arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_pgtable.h | 85 +++ arch/arm64/include/asm/ptdump.h | 27 + arch/arm64/kvm/Kconfig | 13 + arch/arm64/kvm/arm.c | 2 + arch/arm64/kvm/debug.c | 6 + arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 8 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 20 + arch/arm64/kvm/hyp/nvhe/mem_protect.c | 102 ++++ arch/arm64/kvm/hyp/pgtable.c | 98 ++-- arch/arm64/kvm/mmu.c | 2 + arch/arm64/mm/ptdump.c | 483 +++++++++++++++++- arch/arm64/mm/ptdump_debugfs.c | 64 ++- 13 files changed, 852 insertions(+), 59 deletions(-)