From patchwork Wed Feb 11 08:32:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 44563 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 95F3F21527 for ; Wed, 11 Feb 2015 08:35:25 +0000 (UTC) Received: by labge10 with SMTP id ge10sf1027943lab.3 for ; Wed, 11 Feb 2015 00:35:24 -0800 (PST) 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=bXZuPZiHMeGszXrQ/XMmK3XmBiwcQ30EAxIV2tRn34FDEFWsusYvxWw7e2Bn1CTeVU iuqFsow+erYnzx20aqQTQrtq3OX0O0gekt1OQ+y7yNOSXK2+y0Ye45g49sfJJk18+7oW Iw8+BsHccTuCFZhcp06DQX8OCMhrpufH5wGDyaniXPFa4oj2zMDgVuj3qBC1U+w4iIP4 66N+mMqtAll2W5FgnNjOT4oR2ludwiJDOZxAdn74GYps1CtrN9tOsXXiLcDJBpSsfSdL u0yEPKCow4XbKyAa9w6Ohb2jZPH/U/M8azqcI0Ojj5B8rGI7PDqXdrN0w9r7isfhj2J7 qWnQ== X-Gm-Message-State: ALoCoQm1ftG/0Leqo0Y/jECSzc6UKZvVsv6HpvIcdQ0qZyxsjAT1oe5Z/Ae4s7XZ87jRzYa1bFCT X-Received: by 10.112.90.226 with SMTP id bz2mr3248518lbb.6.1423643724571; Wed, 11 Feb 2015 00:35:24 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.99 with SMTP id 3ls35944lat.107.gmail; Wed, 11 Feb 2015 00:35:24 -0800 (PST) X-Received: by 10.112.162.167 with SMTP id yb7mr26256401lbb.76.1423643724435; Wed, 11 Feb 2015 00:35:24 -0800 (PST) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id xe8si44384lbb.109.2015.02.11.00.35.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:35:24 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by lamq1 with SMTP id q1so1881982lam.5 for ; Wed, 11 Feb 2015 00:35:24 -0800 (PST) X-Received: by 10.112.213.38 with SMTP id np6mr26746083lbc.36.1423643724361; Wed, 11 Feb 2015 00:35:24 -0800 (PST) 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 h5csp1110250lbj; Wed, 11 Feb 2015 00:35:23 -0800 (PST) X-Received: by 10.107.169.233 with SMTP id f102mr14044630ioj.6.1423643722922; Wed, 11 Feb 2015 00:35:22 -0800 (PST) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com. [209.85.223.180]) by mx.google.com with ESMTPS id g133si69819ioe.78.2015.02.11.00.35.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:35:22 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.223.180 as permitted sender) client-ip=209.85.223.180; Received: by iebtr6 with SMTP id tr6so2366929ieb.4 for ; Wed, 11 Feb 2015 00:35:22 -0800 (PST) X-Received: by 10.50.79.230 with SMTP id m6mr2198546igx.33.1423643722153; Wed, 11 Feb 2015 00:35:22 -0800 (PST) Received: from gnx2579.solutionip.com ([113.28.134.59]) by mx.google.com with ESMTPSA id m38sm62189ioi.39.2015.02.11.00.35.17 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Feb 2015 00:35:21 -0800 (PST) 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, feng.wu@intel.com Cc: andre.przywara@arm.com, patches@linaro.org, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, b.reynal@virtualopensystems.com, gleb@kernel.org, pbonzini@redhat.com Subject: [RFC v4 07/13] KVM: kvm-vfio: wrappers to VFIO external API device helpers Date: Wed, 11 Feb 2015 09:32:17 +0100 Message-Id: <1423643543-24409-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1423643543-24409-1-git-send-email-eric.auger@linaro.org> References: <1423643543-24409-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.215.50 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);