From mboxrd@z Thu Jan 1 00:00:00 1970 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 A0C58C41535 for ; Tue, 19 Dec 2023 11:48:14 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MgJ8SQRsidJGsHVivhQWbPCM1rJsOkS72Wc4M+JAC3g=; b=W5t7ibDi2l0B/P KSzybTE6Y5u/T7C3xLMekLmrfqmw/m9ah0Yq/aVpC5CcybmrImiNXy2yuPxrV77nk5NCWJBnLPBDo N8WoRHmY/JC8VVl04oDkt9RIqdcPIfzA+H3hEyrHyW4+MNgQgcQhBOqu/pSOFqhzDW6YZZ0bl4Xsx BZc/Dw6JCRDhCDLEmJ6FES01/P53ut82jIPGVk9XgK3cj4YwN+riujLEU2ePTYeJKRNmcF3Xcjtz+ q0hMEVe5fY5BoL6uG0dYge3rOCosVlt0WV2+e/kVuaZfnr7gGTDT1aTVXcZ/h0XdC5J5fI9Enn8QC zGSnh7HtoXiVRJd31Bgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFYZg-00DtwE-0w; Tue, 19 Dec 2023 11:47:48 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFYZd-00DtuB-11 for linux-arm-kernel@lists.infradead.org; Tue, 19 Dec 2023 11:47:47 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40c3963f9fcso35175e9.1 for ; Tue, 19 Dec 2023 03:47:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702986463; x=1703591263; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=WKYUS8nd9z/w82LwXMjmDphAjvYpl6ryuYSpgDd10Z4=; b=mtZYK05dR7klbauAgipEjpGoMvR+HGhF2/s8ByjyB9Fz+RaB3T7RYJlMQeXyRHbhrQ jC7JmOJXDwlK59beRhcecXBEc6RfOXUcEkKOx8I7AfJGL7eApMREHyumihqQATb2pVP4 8CrOomd6hrpJivM+4ELLgzYXzSrKLZQcpw7YbtTP/aw2Z+eP82eh5TpC2oq3GG/uZZvQ yQ8kkIIhriaK0/ycS8RTZ6atwryRjVl2giA+QhVZJfRcFUsJvI6VCCdjPp/eqIUbSoIc A0A0iqckk7kRHDQ3zx/Xx1zEeb5T9bWKa+Z72PMeFhi7RCP6f99fYA4Of0znU4CeFlzt La7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702986463; x=1703591263; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WKYUS8nd9z/w82LwXMjmDphAjvYpl6ryuYSpgDd10Z4=; b=SXUfuRtXlRUPV4arQca3c0StwFZlUTuoR+KxbXspCgTRlVC188l0gKF8djgFsL6F+0 LoAXF8sYDK40VtjIwEV1PXiHw1KUCw+B5XmAQOckN4F39elAdf7gBTJj75Je3KhfYWfA fG/zsBL53MCz18sDtXlrvCMeDNwrFaFeDs3zPJB24S/HlLB63eWqQnjP20SA0N8L+Xb9 KJsemDAw4NfZUgG7BwYDbo+lkW40i2x+xnUQPXZ9+8sh2qCvoYwIrKRahPx6UGOf9pTI H9xuDk+ZidN7BLi2eCEYKke/dVGwmNCYgbq7xoiu8Tmzs/bMtpLu6OVVRzVlcBF5qaDa TXUg== X-Gm-Message-State: AOJu0Yz60ysgWO9ckAUXD1yA/eyUC9SqyPOkcIunRQ/JuxIIfuiBMnDE e1chSMWhGattobiwcsL1U412kJo1BA3Q X-Google-Smtp-Source: AGHT+IHuJBXW+M/1WdVf9NpQ6RzHQn7JcJLP1l/MFWfAJ2aC36CcAsttwAa+T6KS3V/tlBWUunX8qQ== X-Received: by 2002:a05:600c:3ba8:b0:40d:2bc7:e9b with SMTP id n40-20020a05600c3ba800b0040d2bc70e9bmr36857wms.4.1702986462970; Tue, 19 Dec 2023 03:47:42 -0800 (PST) Received: from google.com (185.83.140.34.bc.googleusercontent.com. [34.140.83.185]) by smtp.gmail.com with ESMTPSA id y15-20020a056000108f00b003366464cae9sm6662436wrw.100.2023.12.19.03.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 03:47:42 -0800 (PST) Date: Tue, 19 Dec 2023 11:47:40 +0000 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 Subject: Re: [PATCH v4 02/10] KVM: arm64: Add ptdump registration with debugfs for the stage-2 pagetables Message-ID: References: <20231218135859.2513568-2-sebastianene@google.com> <20231218135859.2513568-4-sebastianene@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231218135859.2513568-4-sebastianene@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231219_034745_542953_ED9A41D3 X-CRM114-Status: GOOD ( 33.65 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Dec 18, 2023 at 01:58:52PM +0000, Sebastian Ene wrote: > While arch/*/mem/ptdump handles the kernel pagetable dumping code, > introduce KVM/ptdump which deals with the stage-2 pagetables. The > separation is necessary because most of the definitions from the > stage-2 pagetable reside in the KVM path and we will be invoking > functionality **specific** to KVM. > > This registers a wrapper on top of debugfs_create_file which allows us > to hook callbacks on the debugfs open/show/close. The callbacks are used > to prepare the display portion of the pagetable dumping code. > Guard this functionality under the newly introduced PTDUMP_STAGE2_DEBUGFS. > > Signed-off-by: Sebastian Ene > --- > arch/arm64/kvm/Kconfig | 13 +++++ > arch/arm64/kvm/Makefile | 1 + > arch/arm64/kvm/arm.c | 2 + > arch/arm64/kvm/kvm_ptdump.h | 18 +++++++ > arch/arm64/kvm/ptdump.c | 96 +++++++++++++++++++++++++++++++++++++ > 5 files changed, 130 insertions(+) > create mode 100644 arch/arm64/kvm/kvm_ptdump.h > create mode 100644 arch/arm64/kvm/ptdump.c > > diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig > index 83c1e09be..0014e55e2 100644 > --- a/arch/arm64/kvm/Kconfig > +++ b/arch/arm64/kvm/Kconfig > @@ -71,4 +71,17 @@ config PROTECTED_NVHE_STACKTRACE > > If unsure, or not using protected nVHE (pKVM), say N. > > +config PTDUMP_STAGE2_DEBUGFS > + bool "Present the stage-2 pagetables to debugfs" > + depends on PTDUMP_DEBUGFS && KVM > + default n > + help > + Say Y here if you want to show the stage-2 kernel pagetables > + layout in a debugfs file. This information is only useful for kernel developers > + who are working in architecture specific areas of the kernel. > + It is probably not a good idea to enable this feature in a production > + kernel. > + > + If in doubt, say N. > + > endif # VIRTUALIZATION > diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile > index c0c050e53..190eac175 100644 > --- a/arch/arm64/kvm/Makefile > +++ b/arch/arm64/kvm/Makefile > @@ -23,6 +23,7 @@ kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \ > vgic/vgic-its.o vgic/vgic-debug.o > > kvm-$(CONFIG_HW_PERF_EVENTS) += pmu-emul.o pmu.o > +kvm-$(CONFIG_PTDUMP_STAGE2_DEBUGFS) += ptdump.o > > always-y := hyp_constants.h hyp-constants.s > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index e5f75f1f1..ee8d7cb67 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -40,6 +40,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -2592,6 +2593,7 @@ static __init int kvm_arm_init(void) > if (err) > goto out_subs; > > + kvm_ptdump_register_host(); > kvm_arm_initialised = true; > > return 0; > diff --git a/arch/arm64/kvm/kvm_ptdump.h b/arch/arm64/kvm/kvm_ptdump.h > new file mode 100644 > index 000000000..98b595ce8 > --- /dev/null > +++ b/arch/arm64/kvm/kvm_ptdump.h > @@ -0,0 +1,18 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +// > +// Copyright (C) Google, 2023 > +// Author: Sebastian Ene > + > +#ifndef __KVM_PTDUMP_H > +#define __KVM_PTDUMP_H > + > +#include > + > + > +#ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS > +void kvm_ptdump_register_host(void); > +#else > +static inline void kvm_ptdump_register_host(void) { } > +#endif /* CONFIG_PTDUMP_STAGE2_DEBUGFS */ > + > +#endif /* __KVM_PTDUMP_H */ > diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c > new file mode 100644 > index 000000000..5816fc632 > --- /dev/null > +++ b/arch/arm64/kvm/ptdump.c > @@ -0,0 +1,96 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +// > +// Debug helper used to dump the stage-2 pagetables of the system and their > +// associated permissions. > +// > +// Copyright (C) Google, 2023 > +// Author: Sebastian Ene > + > +#include > +#include > +#include > + > +#include > +#include > + > + > +struct kvm_ptdump_register { > + void *(*get_ptdump_info)(struct kvm_ptdump_register *reg); > + void (*put_ptdump_info)(void *priv); > + int (*show_ptdump_info)(struct seq_file *m, void *v); > + void *priv; > +}; > + > +static int kvm_ptdump_open(struct inode *inode, struct file *file); > +static int kvm_ptdump_release(struct inode *inode, struct file *file); > +static int kvm_ptdump_show(struct seq_file *m, void *); > + > +static const struct file_operations kvm_ptdump_fops = { > + .open = kvm_ptdump_open, > + .read = seq_read, > + .llseek = seq_lseek, > + .release = kvm_ptdump_release, > +}; > + > +static int kvm_ptdump_open(struct inode *inode, struct file *file) > +{ > + struct kvm_ptdump_register *reg = inode->i_private; > + void *info = NULL; > + int ret; > + > + if (reg->get_ptdump_info) { > + info = reg->get_ptdump_info(reg); > + if (!info) > + return -ENOMEM; > + } > + > + if (!reg->show_ptdump_info) > + reg->show_ptdump_info = kvm_ptdump_show; > + > + ret = single_open(file, reg->show_ptdump_info, info); > + if (ret && reg->put_ptdump_info) > + reg->put_ptdump_info(info); > + > + return ret; > +} > + > +static int kvm_ptdump_release(struct inode *inode, struct file *file) > +{ > + struct kvm_ptdump_register *reg = inode->i_private; > + struct seq_file *seq_file = file->private_data; > + > + if (reg->put_ptdump_info) > + reg->put_ptdump_info(seq_file->private); > + Call single_release here. > + return 0; > +} > + > +static int kvm_ptdump_show(struct seq_file *m, void *) > +{ > + return -EINVAL; > +} > + > +static void kvm_ptdump_debugfs_register(struct kvm_ptdump_register *reg, > + const char *name, struct dentry *parent) > +{ > + debugfs_create_file(name, 0400, parent, reg, &kvm_ptdump_fops); > +} > + > +static struct kvm_ptdump_register host_reg; > + > +void kvm_ptdump_register_host(void) > +{ > + if (!is_protected_kvm_enabled()) > + return; > + > + kvm_ptdump_debugfs_register(&host_reg, "host_page_tables", > + kvm_debugfs_dir); > +} > + > +static int __init kvm_host_ptdump_init(void) > +{ > + host_reg.priv = (void *)host_s2_pgtable_pages(); > + return 0; > +} > + > +device_initcall(kvm_host_ptdump_init); > -- > 2.43.0.472.g3155946c3a-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel