From patchwork Thu Jun 11 10:51:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Feng" X-Patchwork-Id: 49754 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 69E1F2460E for ; Thu, 11 Jun 2015 11:06:31 +0000 (UTC) Received: by wgez8 with SMTP id z8sf1026498wge.2 for ; Thu, 11 Jun 2015 04:06:30 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=RBaouHK2rMcII7U324nUfyub4Q9TN6AFhTdDqXSeH9k=; b=CHowTUwJZoOd7wP6h2T/YKQpkWjn/u4qY1ntb1ETPvXIzhaw5tnfkzGhm2Od0EaCtD 7pxq7YlwMD1lGPVWlPjsS7kskfJe0qn6q1jJY/RF6bVxmG+0OjVEb+eoiaa7uQGW0X85 rbzQsT1ZV39LlwNSVrqr/dU0lJSnRvQQZQwbLqKe+QTptoKA9b5KCezr9oVQHEy/njOr +eWlZHMxoa3ArvbmiX8fYpRO99gVLZq69m9YA0WO5NpQzJrHBZm5p1KB9v2BzlNTTSS3 6Z2ZEaFdXIy2ESPcKw530BtdkXEuh+w/nE84livRKGFEN4Thrn+XhZwhP+lPxRJDMLhS ViUA== X-Gm-Message-State: ALoCoQmMofnLBvUrz1/USfOOEbpqU12BwtQoDJDQAGSPPAD5hLyERzP/z4Xj8soavDfYynyPk0XC X-Received: by 10.152.9.3 with SMTP id v3mr7957319laa.6.1434020790750; Thu, 11 Jun 2015 04:06:30 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.245.43 with SMTP id xl11ls390570lac.21.gmail; Thu, 11 Jun 2015 04:06:30 -0700 (PDT) X-Received: by 10.112.204.6 with SMTP id ku6mr9219139lbc.73.1434020790568; Thu, 11 Jun 2015 04:06:30 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id jj4si261247lbb.174.2015.06.11.04.06.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2015 04:06:30 -0700 (PDT) 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 lazv15 with SMTP id v15so2570139laz.3 for ; Thu, 11 Jun 2015 04:06:30 -0700 (PDT) X-Received: by 10.112.220.7 with SMTP id ps7mr9124704lbc.72.1434020790470; Thu, 11 Jun 2015 04:06:30 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp3960496lbb; Thu, 11 Jun 2015 04:06:29 -0700 (PDT) X-Received: by 10.70.40.131 with SMTP id x3mr13856545pdk.83.1434020788703; Thu, 11 Jun 2015 04:06:28 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rt8si420306pbb.199.2015.06.11.04.06.27; Thu, 11 Jun 2015 04:06:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933490AbbFKLGV (ORCPT + 28 others); Thu, 11 Jun 2015 07:06:21 -0400 Received: from mga11.intel.com ([192.55.52.93]:24448 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752086AbbFKLBn (ORCPT ); Thu, 11 Jun 2015 07:01:43 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 11 Jun 2015 04:01:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,594,1427785200"; d="scan'208";a="741394214" Received: from feng-bdw-de.bj.intel.com ([10.238.154.75]) by fmsmga002.fm.intel.com with ESMTP; 11 Jun 2015 04:01:41 -0700 From: Feng Wu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, mtosatti@redhat.com, alex.williamson@redhat.com, eric.auger@linaro.org, feng.wu@intel.com Subject: [v4 09/16] VFIO: external user API for interaction Date: Thu, 11 Jun 2015 18:51:45 +0800 Message-Id: <1434019912-15423-10-git-send-email-feng.wu@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1434019912-15423-1-git-send-email-feng.wu@intel.com> References: <1434019912-15423-1-git-send-email-feng.wu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: feng.wu@intel.com 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Eric Auger 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 --- 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 e1278fe..c10b3cb 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1504,6 +1504,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 ddb4409..e120e9a 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -88,6 +88,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