From patchwork Mon Apr 13 12:29:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 47106 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7E2DD21550 for ; Mon, 13 Apr 2015 12:32:42 +0000 (UTC) Received: by wiun10 with SMTP id n10sf9718152wiu.1 for ; Mon, 13 Apr 2015 05:32:41 -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=Xph/WUs6mqMJbP/QEsf+sM1rtCBsnow65+5x6+KebqddAiYBruNZRzFP5kyLrAIiK9 4xAxoptfUm/NCkwJMEOJAxo60FUx1lfkeEoSRROR0shKP7+LGdzAYzdlzyoiFdnRJx7O JvH5pFJRWpqV0jfqCOD4BVApzg4MntE3zsDyGB6KjbfZWYIaeFe5wx2n1aKofHsQSW4U lhvIDGuRMbQCPx1UagDOMb8wOluqiPapzg7uFcA7Mq9u3p/aIa5dmdtgi9+kx9FcXmR0 +XipE+jDAVNb1EOc4Hd6RP3/FhB4ngharh6T7179WPsOidvyRseK2eMgmo3AotyBPZtJ UvyA== X-Gm-Message-State: ALoCoQnMYxr/KKSUbymPdL9rLyWg1XHKBp2BmH0yzpUZReRH9ZRmm6jSRA/cZUrM/098jBOq7jxm X-Received: by 10.112.98.38 with SMTP id ef6mr2106918lbb.3.1428928361804; Mon, 13 Apr 2015 05:32:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.162 with SMTP id z2ls658962laj.75.gmail; Mon, 13 Apr 2015 05:32:41 -0700 (PDT) X-Received: by 10.112.97.202 with SMTP id ec10mr13037139lbb.4.1428928361661; Mon, 13 Apr 2015 05:32:41 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id r7si8299961laa.83.2015.04.13.05.32.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2015 05:32:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbbzk7 with SMTP id zk7so57323389lbb.0 for ; Mon, 13 Apr 2015 05:32:41 -0700 (PDT) X-Received: by 10.112.141.202 with SMTP id rq10mr13167460lbb.88.1428928361395; Mon, 13 Apr 2015 05:32:41 -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.67.65 with SMTP id l1csp1174986lbt; Mon, 13 Apr 2015 05:32:41 -0700 (PDT) X-Received: by 10.194.235.71 with SMTP id uk7mr27750801wjc.13.1428928360803; Mon, 13 Apr 2015 05:32:40 -0700 (PDT) Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com. [209.85.212.172]) by mx.google.com with ESMTPS id el1si13740592wib.120.2015.04.13.05.32.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2015 05:32:40 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.172 as permitted sender) client-ip=209.85.212.172; Received: by wiun10 with SMTP id n10so64592147wiu.1 for ; Mon, 13 Apr 2015 05:32:40 -0700 (PDT) X-Received: by 10.194.123.67 with SMTP id ly3mr27863634wjb.105.1428928360537; Mon, 13 Apr 2015 05:32:40 -0700 (PDT) Received: from gnx2579.gnb.st.com (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by mx.google.com with ESMTPSA id fl14sm2879910wjc.11.2015.04.13.05.32.38 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Apr 2015 05:32:39 -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, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, alex.williamson@redhat.com, pbonzini@redhat.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org, feng.wu@intel.com, b.reynal@virtualopensystems.com Subject: [RFC v6 05/16] VFIO: external user API for interaction with vfio devices Date: Mon, 13 Apr 2015 14:29:20 +0200 Message-Id: <1428928171-18884-6-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428928171-18884-1-git-send-email-eric.auger@linaro.org> References: <1428928171-18884-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.182 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