From patchwork Thu Mar 19 14:55:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 46041 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EB1BC21515 for ; Thu, 19 Mar 2015 14:58:37 +0000 (UTC) Received: by wivr20 with SMTP id r20sf13450564wiv.0 for ; Thu, 19 Mar 2015 07:58:37 -0700 (PDT) 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=J75PTyWKq4OE1hoDicZ+1xgB5UTTsubU+CPLJ81pT0g=; b=eK5w/0JbmayyBVT02F1WWE0p/jUUk3VRI1bE2vGLHfS4MJ0g49QpvOgDkSsFXTd4Cg tC02KQwLtTZs4EBSt0RcdMLD1FTWMR5Iq+0nE3aEYM3WaonlWJJcn7exkAiEqV6clzm5 7gkqxH7FGXxm/shcS98w4OwyBluIQQ66TEUesAb/4NfVQGQMWcs4W7HhH+uBdWHiFlDb cpYHs5BrFOvslU6P7PjY+luZHS4XUPs6KBpWUBZSOY02hZbFIy7wFf/TCXrrDb8PB1IT EWRkTLYwp37Xok2nIMWJRUgoWP074dcf84Y5R5NrYLzQJ4vBWR8hKvSZ+8P/LFguniVG sBzA== X-Gm-Message-State: ALoCoQmmMAMfP06hmOPk2oyk8OIlm/agcHiIrzuhl8jqUY0Nyhb7blwpSShZZZL1aUSgU8dwMa1p X-Received: by 10.180.80.132 with SMTP id r4mr1832560wix.4.1426777117270; Thu, 19 Mar 2015 07:58:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.98 with SMTP id m2ls319797lae.5.gmail; Thu, 19 Mar 2015 07:58:37 -0700 (PDT) X-Received: by 10.112.12.196 with SMTP id a4mr69368977lbc.8.1426777117111; Thu, 19 Mar 2015 07:58:37 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id u2si1140682laj.129.2015.03.19.07.58.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 07:58:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by lbbsy1 with SMTP id sy1so54763019lbb.1 for ; Thu, 19 Mar 2015 07:58:37 -0700 (PDT) X-Received: by 10.112.162.232 with SMTP id yd8mr2692569lbb.41.1426777117024; Thu, 19 Mar 2015 07:58:37 -0700 (PDT) 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 h5csp441422lbj; Thu, 19 Mar 2015 07:58:36 -0700 (PDT) X-Received: by 10.194.8.2 with SMTP id n2mr150479089wja.46.1426777114102; Thu, 19 Mar 2015 07:58:34 -0700 (PDT) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com. [209.85.212.176]) by mx.google.com with ESMTPS id s9si2559924wjs.200.2015.03.19.07.58.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 07:58:34 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.176 as permitted sender) client-ip=209.85.212.176; Received: by wibdy8 with SMTP id dy8so120195359wib.0 for ; Thu, 19 Mar 2015 07:58:33 -0700 (PDT) X-Received: by 10.194.63.16 with SMTP id c16mr155535700wjs.117.1426777113852; Thu, 19 Mar 2015 07:58:33 -0700 (PDT) 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 a6sm1695350wiy.17.2015.03.19.07.58.32 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Mar 2015 07:58:33 -0700 (PDT) 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, kvm@vger.kernel.org, alex.williamson@redhat.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org, pbonzini@redhat.com, kim.phillips@freescale.com, b.reynal@virtualopensystems.com, feng.wu@intel.com Subject: [RFC v5 05/13] VFIO: external user API for interaction with vfio devices Date: Thu, 19 Mar 2015 15:55:43 +0100 Message-Id: <1426776951-24901-6-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426776951-24901-1-git-send-email-eric.auger@linaro.org> References: <1426776951-24901-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.217.179 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 23ba12a..33ae8c5 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1490,6 +1490,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 683b514..b18c38f 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -101,6 +101,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