From patchwork Thu Jul 12 07:30:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 942831 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41R71t2vbrz9ryt for ; Thu, 12 Jul 2018 17:32:34 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41R71t1jTVzF35c for ; Thu, 12 Jul 2018 17:32:34 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=ozlabs.ru (client-ip=107.173.13.209; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru Received: from ozlabs.ru (unknown [107.173.13.209]) by lists.ozlabs.org (Postfix) with ESMTP id 41R7070qy8zF35P for ; Thu, 12 Jul 2018 17:31:02 +1000 (AEST) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 04955AE8001F; Thu, 12 Jul 2018 03:29:12 -0400 (EDT) From: Alexey Kardashevskiy To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH kernel] KVM: PPC: Expose userspace mm context id via debugfs Date: Thu, 12 Jul 2018 17:30:26 +1000 Message-Id: <20180712073026.19463-1-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , kvm-ppc@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This adds a debugfs entry with mm context id of a process which is using KVM. This id is an index in the process table so the userspace can dump that tree provided it is granted access to /dev/mem. Signed-off-by: Alexey Kardashevskiy --- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kvm/book3s_64_mmu_hv.c | 58 +++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index fa4efa7..bb72667 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -284,6 +284,7 @@ struct kvm_arch { u64 process_table; struct dentry *debugfs_dir; struct dentry *htab_dentry; + struct dentry *mm_ctxid_dentry; struct kvm_resize_hpt *resize_hpt; /* protected by kvm->lock */ #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c index 7f3a8cf..3b9eb17 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -2138,11 +2138,69 @@ static const struct file_operations debugfs_htab_fops = { .llseek = generic_file_llseek, }; +static int debugfs_mm_ctxid_open(struct inode *inode, struct file *file) +{ + struct kvm *kvm = inode->i_private; + + kvm_get_kvm(kvm); + file->private_data = kvm; + + return nonseekable_open(inode, file); +} + +static int debugfs_mm_ctxid_release(struct inode *inode, struct file *file) +{ + struct kvm *kvm = file->private_data; + + kvm_put_kvm(kvm); + return 0; +} + +static ssize_t debugfs_mm_ctxid_read(struct file *file, char __user *buf, + size_t len, loff_t *ppos) +{ + struct kvm *kvm = file->private_data; + ssize_t n, left, ret; + char tmp[64]; + + if (!kvm_is_radix(kvm)) + return 0; + + ret = snprintf(tmp, sizeof(tmp) - 1, "%lu\n", kvm->mm->context.id); + if (*ppos >= ret) + return 0; + + left = min_t(ssize_t, ret - *ppos, len); + n = copy_to_user(buf, tmp + *ppos, left); + ret = left - n; + *ppos += ret; + + return ret; +} + +static ssize_t debugfs_mm_ctxid_write(struct file *file, const char __user *buf, + size_t len, loff_t *ppos) +{ + return -EACCES; +} + +static const struct file_operations debugfs_mm_ctxid_fops = { + .owner = THIS_MODULE, + .open = debugfs_mm_ctxid_open, + .release = debugfs_mm_ctxid_release, + .read = debugfs_mm_ctxid_read, + .write = debugfs_mm_ctxid_write, + .llseek = generic_file_llseek, +}; + void kvmppc_mmu_debugfs_init(struct kvm *kvm) { kvm->arch.htab_dentry = debugfs_create_file("htab", 0400, kvm->arch.debugfs_dir, kvm, &debugfs_htab_fops); + kvm->arch.mm_ctxid_dentry = debugfs_create_file("mm_ctxid", 0400, + kvm->arch.debugfs_dir, kvm, + &debugfs_mm_ctxid_fops); } void kvmppc_mmu_book3s_hv_init(struct kvm_vcpu *vcpu)