From patchwork Sat Oct 29 20:05:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jike Song X-Patchwork-Id: 9404089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 53CFC60588 for ; Sat, 29 Oct 2016 20:11:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46918291BB for ; Sat, 29 Oct 2016 20:11:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B4E8291C0; Sat, 29 Oct 2016 20:11:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6FE5291BB for ; Sat, 29 Oct 2016 20:11:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754396AbcJ2ULO (ORCPT ); Sat, 29 Oct 2016 16:11:14 -0400 Received: from mga02.intel.com ([134.134.136.20]:40163 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752485AbcJ2ULN (ORCPT ); Sat, 29 Oct 2016 16:11:13 -0400 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP; 29 Oct 2016 13:11:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,565,1473145200"; d="scan'208";a="25569151" Received: from kvmgt1.bj.intel.com ([10.238.154.158]) by orsmga004.jf.intel.com with ESMTP; 29 Oct 2016 13:11:11 -0700 From: Jike Song To: pbonzini@redhat.com, alex.williamson@redhat.com, guangrong.xiao@linux.intel.com Cc: kwankhede@nvidia.com, cjia@nvidia.com, kevin.tian@intel.com, jike.song@intel.com, kvm@vger.kernel.org Subject: [v2 2/5] vfio: export functions to get vfio_group from device and put it Date: Sun, 30 Oct 2016 04:05:12 +0800 Message-Id: <1477771515-18015-3-git-send-email-jike.song@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477771515-18015-1-git-send-email-jike.song@intel.com> References: <1477771515-18015-1-git-send-email-jike.song@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP External users might want to get the vfio_group from a given device, and put it after the usage. Signed-off-by: Jike Song --- drivers/vfio/vfio.c | 6 ++++-- include/linux/vfio.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 23bc86c..e3e58e3 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -414,10 +414,11 @@ static void vfio_group_release(struct kref *kref) iommu_group_put(iommu_group); } -static void vfio_group_put(struct vfio_group *group) +void vfio_group_put(struct vfio_group *group) { kref_put_mutex(&group->kref, vfio_group_release, &vfio.group_lock); } +EXPORT_SYMBOL_GPL(vfio_group_put); /* Assume group_lock or group reference is held */ static void vfio_group_get(struct vfio_group *group) @@ -480,7 +481,7 @@ static struct vfio_group *vfio_group_get_from_minor(int minor) return group; } -static struct vfio_group *vfio_group_get_from_dev(struct device *dev) +struct vfio_group *vfio_group_get_from_dev(struct device *dev) { struct iommu_group *iommu_group; struct vfio_group *group; @@ -494,6 +495,7 @@ static struct vfio_group *vfio_group_get_from_dev(struct device *dev) return group; } +EXPORT_SYMBOL_GPL(vfio_group_get_from_dev); /** * Device objects - create, release, get, put, search diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 0ecae0b..ad9b857 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -92,6 +92,9 @@ extern void vfio_unregister_iommu_driver( extern long vfio_external_check_extension(struct vfio_group *group, unsigned long arg); +extern struct vfio_group *vfio_group_get_from_dev(struct device *dev); +extern void vfio_group_put(struct vfio_group *group); + /* * Sub-module helpers */