From patchwork Sun Nov 23 18:35:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 5362321 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8E115C11AC for ; Sun, 23 Nov 2014 18:39:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C0DA92028D for ; Sun, 23 Nov 2014 18:39:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D9FB520274 for ; Sun, 23 Nov 2014 18:39:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752294AbaKWSho (ORCPT ); Sun, 23 Nov 2014 13:37:44 -0500 Received: from mail-wi0-f169.google.com ([209.85.212.169]:58591 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752277AbaKWShm (ORCPT ); Sun, 23 Nov 2014 13:37:42 -0500 Received: by mail-wi0-f169.google.com with SMTP id r20so7177842wiv.0 for ; Sun, 23 Nov 2014 10:37:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rSuMN//+gAHuahCwL/NDDFaYFK1Y2fDvhcLtF8Kj9bw=; b=UWGF4FoLiyeA7ZFrGN6/5E2I70avuXBYrbS8Zy7neuc+4cV/l+6ATq/02/lSQKLdMn +uh2+sZt5Lf7y7dA+fJ2ro8t1qdgC48ZGQA3/QJOPk84S+0YHTO1R05XpKtNBXuwJo1X 0/gLewRgnFU2qiH0umqa1jwsPB5Jb7GbzgvB9qwwu75yLeQC0R2he/1hHRtA4NwsfxrZ dG7vZ8b6xiYRkIcigtvlDBh7mqOJJ3L4VpsmDew3bUPUpziN74JvxxMDaI8ptHmPfM47 M9bnOzFXl9oZCt4nvU+7H+Ob6Vstv4UnhtxYTdEQ24eZuzQQ20z/d3XHHezUsyAmOXAO fMkw== X-Gm-Message-State: ALoCoQmwYhyjxQOp2+kHzlsNYS0MBUlkL7BRONOefuwKuY+lSERo4a/UBiItInalXeB3FhL+nJiA X-Received: by 10.180.76.201 with SMTP id m9mr14795353wiw.52.1416767861583; Sun, 23 Nov 2014 10:37:41 -0800 (PST) Received: from gnx2579.gnb.st.com (weg38-3-78-232-41-119.fbx.proxad.net. [78.232.41.119]) by mx.google.com with ESMTPSA id hk9sm17535471wjb.46.2014.11.23.10.37.39 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:37:40 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, alex.williamson@redhat.com, joel.schopp@amd.com, kim.phillips@freescale.com, paulus@samba.org, gleb@kernel.org, pbonzini@redhat.com, agraf@suse.de Cc: linux-kernel@vger.kernel.org, patches@linaro.org, will.deacon@arm.com, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, john.liuli@huawei.com, ming.lei@canonical.com, feng.wu@intel.com Subject: [PATCH v3 5/8] VFIO: External user API device helpers Date: Sun, 23 Nov 2014 19:35:57 +0100 Message-Id: <1416767760-14487-6-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416767760-14487-1-git-send-email-eric.auger@linaro.org> References: <1416767760-14487-1-git-send-email-eric.auger@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The VFIO external user API is enriched with 3 new functions that allows a kernel user external to VFIO to retrieve some information from a VFIO device. - vfio_device_get_external_user enables to get a vfio device from its fd and increments its reference counter - vfio_device_put_external_user decrements the reference counter - vfio_external_base_device returns a handle to the struct device Signed-off-by: Eric Auger --- v2 -> v3: - reword the commit message v1 -> v2: - vfio_external_get_base_device renamed into vfio_external_base_device - vfio_external_get_type removed --- drivers/vfio/vfio.c | 24 ++++++++++++++++++++++++ include/linux/vfio.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 8e84471..282814e 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1401,6 +1401,30 @@ void vfio_group_put_external_user(struct vfio_group *group) } EXPORT_SYMBOL_GPL(vfio_group_put_external_user); +struct vfio_device *vfio_device_get_external_user(struct file *filep) +{ + struct vfio_device *vdev = filep->private_data; + + if (filep->f_op != &vfio_device_fops) + return ERR_PTR(-EINVAL); + + vfio_device_get(vdev); + return vdev; +} +EXPORT_SYMBOL_GPL(vfio_device_get_external_user); + +void vfio_device_put_external_user(struct vfio_device *vdev) +{ + vfio_device_put(vdev); +} +EXPORT_SYMBOL_GPL(vfio_device_put_external_user); + +struct device *vfio_external_base_device(struct vfio_device *vdev) +{ + return vdev->dev; +} +EXPORT_SYMBOL_GPL(vfio_external_base_device); + int vfio_external_user_iommu_id(struct vfio_group *group) { return iommu_group_id(group->iommu_group); diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 2fb2e30..08e33ec 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -99,6 +99,9 @@ extern void vfio_group_put_external_user(struct vfio_group *group); extern int vfio_external_user_iommu_id(struct vfio_group *group); extern long vfio_external_check_extension(struct vfio_group *group, unsigned long arg); +extern struct vfio_device *vfio_device_get_external_user(struct file *filep); +extern void vfio_device_put_external_user(struct vfio_device *vdev); +extern struct device *vfio_external_base_device(struct vfio_device *vdev); struct pci_dev; #ifdef CONFIG_EEH