From patchwork Thu Oct 19 14:40:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13429337 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 C08FECDB482 for ; Thu, 19 Oct 2023 14:41:07 +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=ggJEVJdchYwBY4tg51rUVU4kuKG7QMQ011ctVMvfRv8=; b=ZJf QbT4fh2QhaPaUwX14KYnXfCSyBvFStJKti2k1o911JZFqTIjwDFCakaku60baHIOg2bWDVcZmuQTz ZVQuqWa3KqPzQr6Qr3OOEqkYXZZyQcWUX5qvVg8ovJuOiFMGOCnJDlPUwOYoG7N4RRvksMYu6uHfd R7nBzQWMbs1R1O0UvotL94NhhH7MsCbb9z0wNEs5X5gLRPmR80DPVLEdqUqjlm0NkGnTOVgjV+7hX Jxj2AYqU6J2hLniMmDA4I0dgzX3YibGc017erZcxzx9toUlhYIK0X9a8TRGwaOIih6oZibk+/rJLZ 6NJRYebjpFu2gX0zeKgHLzoibswzWxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtUCZ-0006AJ-0l; Thu, 19 Oct 2023 14:40:43 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtUCW-00069G-26 for linux-arm-kernel@lists.infradead.org; Thu, 19 Oct 2023 14:40:42 +0000 Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-30e3ee8a42eso4778300f8f.1 for ; Thu, 19 Oct 2023 07:40:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726438; x=1698331238; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=VwGo+pxMqRlSrxNR7lfucT+VBcms/xUP2WA4dRFnCj4=; b=q0lR2IdHzaRUpZEdvAEBsSIZDSSjYYVetgwyacN5lj48YLI5NV1utWtzNbTrYsHy6T niiGCPpyEFWDzJNkxNZxjg9SGYuuUb6OhDS2AkbBP5WmmH8HQehiDx0G4yc5L2pCSB7J /V8teIMGl1Jq80nhWYci4CYd61aHLJfTMHVSyv/UPZqQ6AYNL73zejJGlzkUh0OL/1oJ bP5qcLFGtIbZ4BfW36n0Oo6MFzX/K5nOGaBkI4C2MrzXJIw962g2CWJI7bWUhO6JOpeC 4pRJyfE/AruidbCXV1rk38uGWbdSECmTttQefjPfOvaGwpc+r+j9F9CxZkfIwWCfUGEi q9Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726438; x=1698331238; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=VwGo+pxMqRlSrxNR7lfucT+VBcms/xUP2WA4dRFnCj4=; b=RgSt7qRUQehtqub1lMkBqWgfSnLnGTV5+a/0h6XAOtmIi0cLYSVPJv7RlGGwHM/Ran wsdWdfJPFYtmHgBuvoE04QwALS1FlIqis4Gin3+8rUrQFQxUaWYoTuObT2NKwXlGk2OA HfNMlKSaR27J+0RaJp964J8WlIDjfHZAVF8n3hGgH+TIzuj0T/ayUMrXTpnKIgJDIkhD MvzKibNcmyc+K7DF87cmO6xTX/6NCdmXnfnpylEnQ49sMPfo/RPoz/MYgHM6D/63vDM8 dZUX5VI2ZT6DsWOCuRw7Emt2xuAFKlayrVsz3WvLLwFHtlFcyWwZFm/7Yr8Z0/hxsCsr os8Q== X-Gm-Message-State: AOJu0YzDnwRKSRusy6OjyO5zrVACyjEha1j1P2GeOAb9utvNAHielsfG nS8pYIrmc5cBDZeHKEEpS72cXnEj/42qXRQ3zXU= X-Google-Smtp-Source: AGHT+IEdeG3rqm1nPbv+lFnddJa6jldymd4uGysEwA9huT/6yR6SSQkIa3NaWsfM8wQFBToxJRYPLQR/btv3VCqKrcc= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:adf:9d86:0:b0:32d:885e:a0fa with SMTP id p6-20020adf9d86000000b0032d885ea0famr21519wre.10.1697726438121; Thu, 19 Oct 2023 07:40:38 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:21 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-1-sebastianene@google.com> Subject: [PATCH v2 00/11] arm64: ptdump: View the second stage page-tables From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: 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-20231019_074040_687293_DDB8DB68 X-CRM114-Status: GOOD ( 16.13 ) 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 under debugfs. From the previous feedback I re-worked the series and added support for guest page-tables dumping under VHE & nVHE configuration. I extended the list of reviewers as I missed the interested parties in the first round. When CONFIG_NVHE_EL2_PTDUMP_DEBUGFS is enabled under pKVM environment, ptdump registers the 'host_stage2_kernel_page_tables' entry with debugfs. Guests are registering a file named '%u_guest_stage2_page_tables' when they are created. 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. Link to the first version: https://lore.kernel.org/all/20230927112517.2631674-1-sebastianene@google.com/ Changelog: 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 (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: Add hooks on debugfs file operations arm64: ptdump: Register a debugfs entry for the host stage-2 page-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 | 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/kvm/mmu.c | 3 + arch/arm64/mm/ptdump.c | 487 +++++++++++++++++- arch/arm64/mm/ptdump_debugfs.c | 42 +- 11 files changed, 822 insertions(+), 62 deletions(-)