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: Auger Eric X-Patchwork-Id: 41391 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 434172036A for ; Sun, 23 Nov 2014 18:37:44 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id c13sf4849000eek.10 for ; Sun, 23 Nov 2014 10:37:43 -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=rSuMN//+gAHuahCwL/NDDFaYFK1Y2fDvhcLtF8Kj9bw=; b=bwBIdDMBAc8/VUd6yv+MXjjxKYCgVNRPc+xJLyzbdeyOQM+DRGtgld/MCoflXtlXnJ JszbuiciJHSDXia6ZlmRs7HQvNi7hCE0tNUFdxgI1z9myND0EqcF0XGfONNzYWzrN72x CYh9PByt/80MGYG7BqBi8DM5q1h7MWdH42BlRCauWeBjn/YlXHMaViAbgL5u4UZ2dLCx G+j3oIQY03J6xoI4e/BkfcGuAUS5v3cDXEif/kK2CNMxnMYvtLSflkg+tWW6rwp+IVI/ b1iHYZx5PC7sPQFoOrbneT1/JfMEOx6p68TxyZ6FwCJuge6LD+PZ2hYPulp6PfeAwFoV Wu6Q== X-Gm-Message-State: ALoCoQmxiI4nLfloaHCxcN4ihlpgIgKfrTCneRSNT9TUG7gwoIl349RoXbLf5PLaxNnZ7QSw461A X-Received: by 10.180.19.42 with SMTP id b10mr4526592wie.0.1416767863376; Sun, 23 Nov 2014 10:37:43 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.129 with SMTP id w1ls345510lal.34.gmail; Sun, 23 Nov 2014 10:37:43 -0800 (PST) X-Received: by 10.112.16.39 with SMTP id c7mr16338585lbd.19.1416767863087; Sun, 23 Nov 2014 10:37:43 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id kw6si12922592lac.24.2014.11.23.10.37.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:37:42 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id gd6so6569243lab.19 for ; Sun, 23 Nov 2014 10:37:42 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr16218433laz.27.1416767862539; Sun, 23 Nov 2014 10:37:42 -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.184.201 with SMTP id ew9csp156309lbc; Sun, 23 Nov 2014 10:37:42 -0800 (PST) X-Received: by 10.194.52.3 with SMTP id p3mr26945469wjo.93.1416767861791; Sun, 23 Nov 2014 10:37:41 -0800 (PST) Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com. [209.85.212.182]) by mx.google.com with ESMTPS id fr7si8526892wib.99.2014.11.23.10.37.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:37:41 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.182 as permitted sender) client-ip=209.85.212.182; Received: by mail-wi0-f182.google.com with SMTP id h11so3717155wiw.15 for ; Sun, 23 Nov 2014 10:37:41 -0800 (PST) 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> 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.46 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 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