From patchwork Fri Aug 16 12:39:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13766077 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 6ABF7C52D7D for ; Fri, 16 Aug 2024 12:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fVLGFavEAQJdYF6sohZy6GLteiKbgm4SNZHa6M3Hrik=; b=MNNh9/GGbtav7/JzZBTo8zTXG3 hqaCpQTLRDjTQvBJ2OF8RkUtmO/HAh4pBIPcTRiCQYYeaX1IHuwwrzDhnQ3znmonPynDDnnK2xijG rM9bErjtwW6vuCLJERz/oqFXfOxNq2BzA4FdUV22kzaXd+3mld8lb0NoBRwhlhhCsC5Ibpx6TUv9+ Te7+VPzIPCSBGesvy0I1fHt7WhBgVUCP+TfMxWmusfg8Z738YcgOlU0KS2RgNRtbnEnKsBuvW1oBe 6g39djpXcHouuAZhxSoDTuKOKKFM8tKFCD6Ap0fNPvz+1IK17V+FMyBSBY0BTWMfdllPe7gb2SyPa p7kZzNMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewJ7-0000000Cv8Q-41pO; Fri, 16 Aug 2024 12:43:54 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewEs-0000000Cu5g-27pv for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 12:39:31 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-429097df54bso13399775e9.1 for ; Fri, 16 Aug 2024 05:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723811969; x=1724416769; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fVLGFavEAQJdYF6sohZy6GLteiKbgm4SNZHa6M3Hrik=; b=PYoLGs/fBeE/v+hvwl3Q+9r8WUjN3qUcqRMCMiE3QuSAJHHrzB7it2ERlYZTUJGrLJ AYIpVZbrlZNKc/HcdTiYEEKCk/CzCjNLIa8Y+TKuIPZ1QefehuDN0lYXUYm+KzGTCtM4 A2YdxwhRG612dWSIdSsUqltdUood06D9uMmO0FY0z/TLONhuHUc7SRrPhUHqr5uUAV9j NkQ8DgufZNR5ne8sgpW+T5CF754Sth8mSJTHG//nNwKrpmNSoK5SMfqPe1qpy2Qj0fsb Dx+Uq5gy+nYihApLWinOau+BX0Xeux9FAtY/sxOIGS7QeSMSz4p4u0BIHsaZblUblhip lsXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723811969; x=1724416769; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fVLGFavEAQJdYF6sohZy6GLteiKbgm4SNZHa6M3Hrik=; b=gViUXeXusblu50RLP9uSlAUfMtU9MbUYIMpFWQ0HuBoYdry0iqEQHl2qvjBGyu/i3w AW0bbCq5gG7TbJn/lHivHkkFm51FIuppfbMLbnjT9ZPfpolkak2zYt6VOk+IvwMUsd9A z2JkrZgdSpG5jxOktXdfmvnsNP2Zx8mh3HctHHgARNxxur6moDKZzFUMCyJn3z67Qb3S c7D0jEV9T12sVvYJ6fy9CsVS/ypLivn1/cUM5GmMDGD0QHcTKmnKZM6TceKv+cyIYsM0 J7Xgcij9Q1MH30BQhCyHJqHfBPARYO8gRbuKm3rjcwyLsdFsUzOYn9UaNn+85AIuT7BQ cMRw== X-Forwarded-Encrypted: i=1; AJvYcCUQdJLQMvsmUNqUGcKrV2FhwpRSJYed4XqfMuvB9dKUsibK3TJiBE3AeYkD+K1kuWzGap8JNRwwIh8R9EusHsfBtdH9zno5MbDWFHeNBEq06/7MwnM= X-Gm-Message-State: AOJu0YyHhHYoXbyc9XBDAyNHj4eGHcDjzsgFm2Z18LJnyr6wWBm8H5z+ 2gFlhv+BOBJj7jy/J8FBMBZdUSCz7tX5f9crOxWz6VnDhVlSupdRZBtS/nKoxl0VtRNStZp8ZKS wjdyy3aD4B8ezEfCQ9NrkVVqm4Q== X-Google-Smtp-Source: AGHT+IFGgP1UpKc1nFsMN2cnAW/WNRr3YojR2uI15QJjFmnongfC+MYnDiKQo3s4RWZo8/KjRQyeYn/x04TBgYlZR34= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:6000:1e81:b0:366:ea7c:bed1 with SMTP id ffacd0b85a97d-371943164fbmr3636f8f.1.1723811968492; Fri, 16 Aug 2024 05:39:28 -0700 (PDT) Date: Fri, 16 Aug 2024 12:39:06 +0000 In-Reply-To: <20240816123906.3683425-1-sebastianene@google.com> Mime-Version: 1.0 References: <20240816123906.3683425-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240816123906.3683425-7-sebastianene@google.com> Subject: [PATCH v8 6/6] KVM: arm64: Expose guest stage-2 pagetable config to debugfs From: Sebastian Ene To: akpm@linux-foundation.org, alexghiti@rivosinc.com, ankita@nvidia.com, ardb@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, james.morse@arm.com, vdonnefort@google.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ryan.roberts@arm.com, sebastianene@google.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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240816_053930_569712_E7119F9D X-CRM114-Status: GOOD ( 14.73 ) 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 Make the start level and the IPA bits properties available in the virtual machine debugfs directory. Make sure that the KVM structure doesn't disappear behind our back and keep a reference to the KVM struct while these files are opened. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/ptdump.c | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c index 79be07ec3c3c..b0d55ea3fb2a 100644 --- a/arch/arm64/kvm/ptdump.c +++ b/arch/arm64/kvm/ptdump.c @@ -207,8 +207,56 @@ static const struct file_operations kvm_ptdump_guest_fops = { .release = kvm_ptdump_guest_close, }; +static int kvm_pgtable_debugfs_show(struct seq_file *m, void *unused) +{ + const struct file *file = m->file; + struct kvm_pgtable *pgtable = m->private; + + if (!strcmp(file_dentry(file)->d_iname, "ipa_range")) + seq_printf(m, "%2u\n", pgtable->ia_bits); + else if (!strcmp(file_dentry(file)->d_iname, "stage2_levels")) + seq_printf(m, "%1d\n", KVM_PGTABLE_LAST_LEVEL - pgtable->start_level + 1); + return 0; +} + +static int kvm_pgtable_debugfs_open(struct inode *m, struct file *file) +{ + struct kvm *kvm = m->i_private; + struct kvm_pgtable *pgtable; + int ret; + + if (!kvm_get_kvm_safe(kvm)) + return -ENOENT; + + pgtable = kvm->arch.mmu.pgt; + + ret = single_open(file, kvm_pgtable_debugfs_show, pgtable); + if (ret < 0) + kvm_put_kvm(kvm); + return ret; +} + +static int kvm_pgtable_debugfs_close(struct inode *m, struct file *file) +{ + struct kvm *kvm = m->i_private; + + kvm_put_kvm(kvm); + return single_release(m, file); +} + +static const struct file_operations kvm_pgtable_debugfs_fops = { + .open = kvm_pgtable_debugfs_open, + .read = seq_read, + .llseek = seq_lseek, + .release = kvm_pgtable_debugfs_close, +}; + void kvm_ptdump_guest_register(struct kvm *kvm) { debugfs_create_file("stage2_page_tables", 0400, kvm->debugfs_dentry, kvm, &kvm_ptdump_guest_fops); + debugfs_create_file("ipa_range", 0400, kvm->debugfs_dentry, kvm, + &kvm_pgtable_debugfs_fops); + debugfs_create_file("stage2_levels", 0400, kvm->debugfs_dentry, + kvm, &kvm_pgtable_debugfs_fops); }