From patchwork Mon Apr 13 12:29:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 47111 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 76AA720553 for ; Mon, 13 Apr 2015 12:33:02 +0000 (UTC) Received: by laat2 with SMTP id t2sf17628842laa.2 for ; Mon, 13 Apr 2015 05:33:01 -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=d/8jJNZWLBQ3oETU2AwUMA0oxGEsIorL5zSB+t1Tb3A=; b=b6HyzprBduK180NhL5ScDbokSdCe4HeQa8tQacoQIVPyK2jkrx5lGdClT8/uvyDaXJ K270Br+KrYuksOpjDx7/VirmaGjBPbH/Eg4LyPB5FMGmVwX8MnxD0oX82+gNkO059DzS 1OwfeNqRvi6qzMLHw1H6Z1L69YzCbcL357seomBAXPLd5lmIbAeMrV6wbYQkiT5RKenp UHEvgL29O8a+E5ujgEgx48ghhjVWSywvjMAOmu5thTNNwA8UQNqSrhjhg9CH4k5UeuNP HvOWXtpvx4Mj4mrIlClX6S4K5zoj/QRgRP3whNErl+rvJnGX6oBVsuWbp+P1rLKEKdue 9tFA== X-Gm-Message-State: ALoCoQku5BfVigmToBffUuWFV8AYOA/nIfbBpdq9jObjmkWcoJvFcB9HZmSuiTp3swBOAKQ4RfyT X-Received: by 10.112.98.38 with SMTP id ef6mr2107149lbb.3.1428928381434; Mon, 13 Apr 2015 05:33:01 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.67 with SMTP id o3ls590201laj.67.gmail; Mon, 13 Apr 2015 05:33:01 -0700 (PDT) X-Received: by 10.112.78.105 with SMTP id a9mr13062519lbx.70.1428928381326; Mon, 13 Apr 2015 05:33:01 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id m5si8278295laj.177.2015.04.13.05.33.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2015 05:33:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbbqq2 with SMTP id qq2so57229312lbb.3 for ; Mon, 13 Apr 2015 05:33:01 -0700 (PDT) X-Received: by 10.152.206.75 with SMTP id lm11mr12856562lac.41.1428928381242; Mon, 13 Apr 2015 05:33:01 -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 l1csp1175189lbt; Mon, 13 Apr 2015 05:33:00 -0700 (PDT) X-Received: by 10.194.177.167 with SMTP id cr7mr26284665wjc.19.1428928369766; Mon, 13 Apr 2015 05:32:49 -0700 (PDT) Received: from mail-wg0-f49.google.com (mail-wg0-f49.google.com. [74.125.82.49]) by mx.google.com with ESMTPS id dt10si13790204wib.55.2015.04.13.05.32.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2015 05:32:49 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.49 as permitted sender) client-ip=74.125.82.49; Received: by wgso17 with SMTP id o17so79119183wgs.1 for ; Mon, 13 Apr 2015 05:32:49 -0700 (PDT) X-Received: by 10.194.23.39 with SMTP id j7mr28143322wjf.9.1428928369413; Mon, 13 Apr 2015 05:32:49 -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.47 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Apr 2015 05:32:48 -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 10/16] KVM: kvm-vfio: wrappers to VFIO external API device helpers Date: Mon, 13 Apr 2015 14:29:25 +0200 Message-Id: <1428928171-18884-11-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.172 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: , Provide wrapper functions that allow KVM-VFIO device code to interact with a vfio device: - kvm_vfio_device_get_external_user gets a handle to a struct vfio_device from the vfio device file descriptor and increments its reference counter, - kvm_vfio_device_put_external_user decrements the reference counter to a vfio device, - kvm_vfio_external_base_device returns a handle to the struct device of the vfio device. Also kvm_vfio_get_vfio_device and kvm_vfio_put_vfio_device helpers are introduced. Signed-off-by: Eric Auger --- v3 -> v4: - wrappers are no more exposed in kvm_host and become kvm/vfio.c static functions - added kvm_vfio_get_vfio_device/kvm_vfio_put_vfio_device in that patch file v2 -> v3: - reword the commit message and title v1 -> v2: - kvm_vfio_external_get_base_device renamed into kvm_vfio_external_base_device - kvm_vfio_external_get_type removed --- virt/kvm/vfio.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c index 620e37f..80a45e4 100644 --- a/virt/kvm/vfio.c +++ b/virt/kvm/vfio.c @@ -60,6 +60,80 @@ static void kvm_vfio_group_put_external_user(struct vfio_group *vfio_group) symbol_put(vfio_group_put_external_user); } +static struct vfio_device *kvm_vfio_device_get_external_user(struct file *filep) +{ + struct vfio_device *vdev; + struct vfio_device *(*fn)(struct file *); + + fn = symbol_get(vfio_device_get_external_user); + if (!fn) + return ERR_PTR(-EINVAL); + + vdev = fn(filep); + + symbol_put(vfio_device_get_external_user); + + return vdev; +} + +static void kvm_vfio_device_put_external_user(struct vfio_device *vdev) +{ + void (*fn)(struct vfio_device *); + + fn = symbol_get(vfio_device_put_external_user); + if (!fn) + return; + + fn(vdev); + + symbol_put(vfio_device_put_external_user); +} + +static struct device *kvm_vfio_external_base_device(struct vfio_device *vdev) +{ + struct device *(*fn)(struct vfio_device *); + struct device *dev; + + fn = symbol_get(vfio_external_base_device); + if (!fn) + return NULL; + + dev = fn(vdev); + + symbol_put(vfio_external_base_device); + + return dev; +} + +/** + * kvm_vfio_get_vfio_device - Returns a handle to a vfio-device + * + * Checks it is a valid vfio device and increments its reference counter + * @fd: file descriptor of the vfio platform device + */ +static struct vfio_device *kvm_vfio_get_vfio_device(int fd) +{ + struct fd f = fdget(fd); + struct vfio_device *vdev; + + if (!f.file) + return ERR_PTR(-EINVAL); + vdev = kvm_vfio_device_get_external_user(f.file); + fdput(f); + return vdev; +} + +/** + * kvm_vfio_put_vfio_device: decrements the reference counter of the + * vfio platform * device + * + * @vdev: vfio_device handle to release + */ +static void kvm_vfio_put_vfio_device(struct vfio_device *vdev) +{ + kvm_vfio_device_put_external_user(vdev); +} + static bool kvm_vfio_group_is_coherent(struct vfio_group *vfio_group) { long (*fn)(struct vfio_group *, unsigned long);