From patchwork Wed Feb 11 08:32:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 44561 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5BC1221527 for ; Wed, 11 Feb 2015 08:35:16 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf1742282wib.2 for ; Wed, 11 Feb 2015 00:35:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=//u3Jf5vCPV/cdWELDlAe1+f1HOGELl589KdWlyoEaA=; b=darHdcJjKioY2sPWeb42O2+OlVvx1UbxkpHwjCyKhzANqWRyTpneDHsI4i/gOPhyNp k1QvYFCqPwCq7gKrUaPdxZQrLR618E4/xPuilkQCwGuvy0Jbj5rxbp+Z+/27ALw0A19+ yQjsTH2K4w2ko6UzamPOr5bZdrDTBhH+pYTuzlT5F4yREGZTBIUVjevIQGYqmQIrKBVt 7QjyeZ9Emrto3aeVdfdAK/28sewgwWp35eRo5hzEVhlXpWD28leBkmcI8DS+DtfQJqvh nmR/LQk+yV7ehkd6QlpBietWstTu0JmiC8x72YRVK1UjmPVKbFizViuvF/By+IIId87x 07Pw== X-Gm-Message-State: ALoCoQnmGORnTmq9j66ZbrlY94JjvyORr4U9kcjhQTkBFJalXTK94xOZBKgJK0DNgQfsZpe9oVbo X-Received: by 10.180.89.194 with SMTP id bq2mr218344wib.4.1423643715670; Wed, 11 Feb 2015 00:35:15 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.232 with SMTP id h8ls33203lam.30.gmail; Wed, 11 Feb 2015 00:35:15 -0800 (PST) X-Received: by 10.152.36.162 with SMTP id r2mr10755803laj.9.1423643715447; Wed, 11 Feb 2015 00:35:15 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id g8si85516laf.55.2015.02.11.00.35.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:35:15 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by labge10 with SMTP id ge10so1822890lab.12 for ; Wed, 11 Feb 2015 00:35:15 -0800 (PST) X-Received: by 10.152.5.167 with SMTP id t7mr27545866lat.32.1423643715380; Wed, 11 Feb 2015 00:35:15 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1110174lbj; Wed, 11 Feb 2015 00:35:14 -0800 (PST) X-Received: by 10.107.161.75 with SMTP id k72mr37353432ioe.46.1423643713894; Wed, 11 Feb 2015 00:35:13 -0800 (PST) Received: from mail-ig0-f176.google.com (mail-ig0-f176.google.com. [209.85.213.176]) by mx.google.com with ESMTPS id g3si1258043icm.47.2015.02.11.00.35.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:35:13 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.213.176 as permitted sender) client-ip=209.85.213.176; Received: by mail-ig0-f176.google.com with SMTP id hl2so29293324igb.3 for ; Wed, 11 Feb 2015 00:35:13 -0800 (PST) X-Received: by 10.50.28.8 with SMTP id x8mr2234440igg.19.1423643712295; Wed, 11 Feb 2015 00:35:12 -0800 (PST) Received: from gnx2579.solutionip.com ([113.28.134.59]) by mx.google.com with ESMTPSA id m38sm62189ioi.39.2015.02.11.00.35.06 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Feb 2015 00:35:10 -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, feng.wu@intel.com Cc: andre.przywara@arm.com, patches@linaro.org, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, b.reynal@virtualopensystems.com, gleb@kernel.org, pbonzini@redhat.com Subject: [RFC v4 05/13] VFIO: external user API for interaction with vfio devices Date: Wed, 11 Feb 2015 09:32:15 +0100 Message-Id: <1423643543-24409-6-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1423643543-24409-1-git-send-email-eric.auger@linaro.org> References: <1423643543-24409-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- v3 -> v4: - change the commit title v2 -> v3: - reword the commit message v1 -> v2: - vfio_external_get_base_device renamed into vfio_external_base_device - vfio_external_get_type removed Signed-off-by: Eric Auger --- 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 5d45081..77c334b 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