From patchwork Wed Feb 7 14:48:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13548613 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 DF9DBC4828F for ; Wed, 7 Feb 2024 14:49:34 +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=y0h01oGSgPSyfI/XyFiwSIjHvThDWlH8c+mU4Hxb29o=; b=gFW HZq/JE0Z1uPdt55FvmePnguDdkxxQkNWm0lrAmL743RzcYVCAizihwlp9epUH7SZ6SGvv0QAJidSG wJD0Uis+ubiIAYc26hQlorH9iqNobG3qOQMdJ4/lxM9E6htwlZ+t12hOwjCxYmIU6z3GGD0rFS2zV HdkNrq6hA5UauvEbuZvWFYAc04uc+ThAy9LrJyN+PMIFcGG+zMW9rZPuP32mVIaOUxjzM3hqHXvRY cSxwo3KTMWrEBShjysBoGoF6EC0jhnhUxykFhJeKFt1I36pbDzhpHIdpmZVwHfO0RwtTvsCB9JHJn yLuDckGNFx5VgOL7drfSJsQgujnvJSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXjEr-0000000AxkI-42Ex; Wed, 07 Feb 2024 14:49:25 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXjEn-0000000Axif-1PSj for linux-arm-kernel@lists.infradead.org; Wed, 07 Feb 2024 14:49:22 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dc6b26783b4so904786276.0 for ; Wed, 07 Feb 2024 06:49:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707317357; x=1707922157; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=TvegWWdI0OwCbkhac2nall+6RkPi+o6vdVPfpeCUajU=; b=i/EdAUsLurFkg1HSXrYnJtG1Yqvo7Epqe1C/9h7QEBlFioAlnXWP8yhAHOk7dvEgrA YGp5CNfufshhG3n8oxAyV+PmAwqX5o/gkQ5ibqk3rEmoHwKwqH6pq7pnrhIWypCFMyK4 k7MTpPDWn46sKMP0qSxv/B7Emf01L4f92S3wXlwgaHz/Cr7eQYrFdWxLGD/vrKoRPSeA GDgCEYSdaw2vK01XVb6a17EaWLPON98mjOpgEPiWZm8+5lJukD3jPNRmlQdW4N6G5uYZ YdGz/pvdqfw3oCBuPMYB9SZliYVh9EJk3IW+PwxcKz1+gE69CcHzaWjmiGwXxFhN+0hw ITfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707317357; x=1707922157; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TvegWWdI0OwCbkhac2nall+6RkPi+o6vdVPfpeCUajU=; b=BdsWOQ/xEnI0SDKJ4i3nILwbgNqEfsK3vLIIR5BqYI0jewYW/1V5hZ9csZlyjunvn6 fz3I0TEPDbYAW6Qaoxy4V9kQYV7wa05D4r9J9klTyMpTH3Y5vY2Aai67N7bLfJrTOWzY B+uJzPzVDQEv0BKxBotj0gCw1qyKP1nZHJWnRm/tEZPQRANk4mB42CnLeN2Dqo399Bhs TlgakdLeNbb0pvXfnpwo6h+4u2E/i01rNMJZNoOerLPPhg8ILPR4PNpcnM+FnQkVe66E kwzp2cj2sTQpRR6TZafOhvAC8mX5KbRIJKpdeG+AsHQ8m2cVeeQbiXNQUQ9cO0s9Zavz ftPQ== X-Forwarded-Encrypted: i=1; AJvYcCUVtcapwcTuPBD1INyl0EFULePvtcDk95jH9BGyn/rUlvFrgoeKB/YI4qRSvbfh7i5anqtnEG61Gj2U5xrRv4vJDLxUqnHgRChIw6aMR4/zG7LZWiw= X-Gm-Message-State: AOJu0YxQIE9Bwyo74Q09Nr+8WprdvR64AA2YUlt6eh+WqFrRno23WTGX Msm6vkKqJIeVpjcMP8b2X3873v90w2EAbNOa8r6dk9cml4yGzn0mmeE326iwbnPCdrvS5L9iVwc J9TWY6lXniWv5vK7KBvbZZEl0pA== X-Google-Smtp-Source: AGHT+IHsVGJFxNmDhsKxmS2lrYPhk6GujJhV1UK7jEEId4g4rPm9A+7WF09PvN/kfQINfrelSokR/4V2F8FfP1X7dG0= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:6902:118f:b0:dc6:c623:ce6f with SMTP id m15-20020a056902118f00b00dc6c623ce6fmr158528ybu.13.1707317356952; Wed, 07 Feb 2024 06:49:16 -0800 (PST) Date: Wed, 7 Feb 2024 14:48:29 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Message-ID: <20240207144832.1017815-2-sebastianene@google.com> Subject: [PATCH v5 0/4] arm64: ptdump: View the second stage page-tables From: Sebastian Ene To: catalin.marinas@arm.com, gshan@redhat.com, james.morse@arm.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ricarkol@google.com, ryan.roberts@arm.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, Sebastian Ene X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240207_064921_402380_D3C43CE3 X-CRM114-Status: GOOD ( 20.32 ) 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 is the first part of the series which enables dumping of the guest stage-2 pagetables. The support for dumping the host stage-2 pagetables which is pKVM specific will be part of a follow-up series as per the feedback received in v4. 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 mappings 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 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: v4 -> current_version: * 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 (4): 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 arch/arm64/include/asm/ptdump.h | 42 +++++- arch/arm64/kvm/Kconfig | 13 ++ arch/arm64/kvm/Makefile | 1 + arch/arm64/kvm/debug.c | 7 + arch/arm64/kvm/kvm_ptdump.h | 20 +++ arch/arm64/kvm/ptdump.c | 235 ++++++++++++++++++++++++++++++++ arch/arm64/mm/ptdump.c | 49 ++----- 7 files changed, 327 insertions(+), 40 deletions(-) create mode 100644 arch/arm64/kvm/kvm_ptdump.h create mode 100644 arch/arm64/kvm/ptdump.c