Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp354366rdh; Wed, 7 Feb 2024 06:49:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXRpniPL8FxZaPOQOCaJO0L0fX1o0+XAPlrFxOYxeZW5gYVukxtgBwOEbaI+3PJRcBkjYtP/HQwsyQSaxXtmnWSYawZ2klicL9mv+a/zQ== X-Google-Smtp-Source: AGHT+IHhoNjbL7jVsESGqjY6m4VShdFclUitS7WFQHJqMbx2U2espuo91NUB+hPa0NEY0ZeUzQ3a X-Received: by 2002:a92:b751:0:b0:363:b686:5b6e with SMTP id c17-20020a92b751000000b00363b6865b6emr5749591ilm.27.1707317372049; Wed, 07 Feb 2024 06:49:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707317372; cv=pass; d=google.com; s=arc-20160816; b=wt8tNggN8BnD25wOiijH/4Dr2SUhxAgtwPpbAt7WfeMUU/QSblEhAVpyG9rZFk1aTR 3BYYtHW9GMtdgW4CzCNHoCg4UODqXThL8Pu3Wl83n9KF9nboUgaRRkEwXvjGgE3BFGJr JpbMhivDfyIomMJEfzJzJphY5wTLLUdXfVzU/NDdzxEAqIHwa7WYKYUG8STehBwHOf6X +NsJWAbbgtW9R32KEjHzihZmm0a8DM13UkON2htBnDyyxV764bitdFtFFucT3eYKlt7C No0qpCC3FPB21IQkfPzi00IIh1zHltCqP9xIR4Xg2/kdaiC8qmluS1f1Uxk0KYsCfXKl VZ4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=TvegWWdI0OwCbkhac2nall+6RkPi+o6vdVPfpeCUajU=; fh=Ig7qCGpaj437/4eoCOCWSB6IFP5xd4utAqRuAa+aLsU=; b=z8S1tzB7ExZDUwri04+bN9CAgc0GWIMaK1MzYjUTV5g3hXABgdVDxOBwAIc7jn8RM+ 27d1c0vvlBe8wERiilPZt0zP8UwPAwT6jyHDVkA9EGzaDD9Ts3BSfjJqjdkEr58XgNRK HrO4omlpS4ekvEU3QzrOx3INI5JMtmg/KuObpRVZkIb56haSxZvvucCg2opyfMeeD+iY PMVWzy1nLymVtQt9ucmmdU2gRqtRuKGUrN+en8Y7Awp3/zsMFopDWMp+U0VcbiXvYIdc TOKQn0KkB+hxPguc5oCKM90PLpqI/LbajCprY95GRtOhC1CI2StS7nDT1MS4P6NAkgjU xcKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=R2xXr0pa; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-56650-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56650-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCVGs+j/ciGZAA6BzdBjlkCdoroow6EPUc2dqEnMKQA4ZuwypiuqBoCMs57kx6tC8BmOHcic6yb2YoJTrdXwDq8RO2hybXCWG0S3D+IMTw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d64-20020a633643000000b005d8c19ca98dsi1604896pga.137.2024.02.07.06.49.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 06:49:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56650-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=R2xXr0pa; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-56650-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56650-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 307672897DD for ; Wed, 7 Feb 2024 14:49:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F0027E77F; Wed, 7 Feb 2024 14:49:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="R2xXr0pa" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EDC77C09D for ; Wed, 7 Feb 2024 14:49:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707317359; cv=none; b=UlC/c/buLJuvkVymiB4BX0kjUc54d2GYuyBAAFmcltjamADevaoWc8Mt7WQGEOGvO+PZZ7q5aJCZDvnD992YPm1ZeW2avpB6KK6uLljnrCDBzK6yiG8sA61TVxjbxXjU5+Gu4NZKCeXK0yB1ex7FJgtC9ejQWspvZnqJIEBnbwc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707317359; c=relaxed/simple; bh=krJX2wO8be7NQJXlSD1F9IfkFfrvInq26sVU2TNKHxs=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=IpvZbSx+TT8XwA97qBakMBKe/SV47B8hcRgPlwwt27ljp5wm4N8Kz1PxxrPKFcC6mv2qlvfN00QRgRPUkOSgkZ4jEZ4LmYzBI0dTz+99ZTdYcs8sl+animrptaSc+Tjl27/imLzHPZADvwx7OV3/2dl9g26/HCzv3GWSOQndYv8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=R2xXr0pa; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-603c0e020a6so10198107b3.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=vger.kernel.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=R2xXr0parLvm0n0gmqieFjxqiIhlnIfeFuJx5wQuq1yu2eMM9bqjhL4a7vZ+CkLTy0 9N1c8/TtbGVNqrzyQ+6BW3Lri02VeGbqxa2tgPEeiuAsO8KyDjGpbrcS2DCQBW+6JcKj c0nKSWXO1B64OdZihEMTu2A+XKZwaA3PJciek7KI2ZSIowMl9g5MKKfOjTwrARbbT8Wy DRFriUyEbXAr30owz4Hofa1xufCykVXxm38rD91lSmXTA0U5JVzBmUXSUjFLyVkuhvVB grA/GnvwyQkShZH+r72WqLabwj58BzOlecfTTry/Qv0Q/FoHnFB73GhgJGENHXDas4l9 ya0g== 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=ELhVButwJDT258QEzTVA9f0dM8ci/3fcYIeNeYZdHbJjbs5NoK6tAvz0NdqQTBTS0f rjHbk1r+vU/+j4NppY4PkEE/TbBj1BNfPQ+O1YZv/+VRvgX+TnB+ICBpcwJW6xY2BsQL 5xuYhPJNUQKq+hV7xd+8oV8VvRSEKvgmiSPViGM4/OVAB0eyKTTqZPqyE6dcgjjm/u1o 6GtmGHZYMCIyt7ZoYX7gbW8EuY2Sg6+2nd2aACyhe0/7OuyqgFwRz0WDN4G1+IQSD/54 reVlaEadVxny6iguFgQK2GWEDcYePKYMwR62a5a6Yv5GTO4R33Zlp+5iJGcCMmni8xkA Snow== X-Forwarded-Encrypted: i=1; AJvYcCU79DcsHpJ5A+y2GETgVkvFfPIMSYgMvyn6kwAdmRegKTiG3Ge7vTJNq4KyqDeiPp8pLUoobQQ0nwuxtbZUzh0ftUfuYgUDlLYEhfVs X-Gm-Message-State: AOJu0Yy74PAMn/bk0PghtGppoXj2tdeTsls5oAnNVSrmZ7HuCyAamwrA S9yZAd3EdDbpZasxIhAwSXtopOEWEL/AzGthHpMwVCPWhhtLakP8tA7oBFp2tWeQ7CA+p/6vqbb Ran7Zx/gCY7gKaY4iRox8vEHPTw== 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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 -- 2.43.0.594.gd9cf4e227d-goog