From patchwork Sun Nov 23 18:35:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 41392 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0802F2036A for ; Sun, 23 Nov 2014 18:37:47 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id l15sf1212215wiw.8 for ; Sun, 23 Nov 2014 10:37:46 -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=j5xHRkn+JHWjYctM485op4toFsvhZiU/bKlVGoAhrNw=; b=m7P70Spvh2aG8gM9rhXhu3Qo6ndrxpJGXCMAR/anZRf3s1T41x7G8Ln2dc1hKaOQ7T 3DZEnWVooXHAvAbb6DBH36zSPP0SnBXNibfOZMU9Uj/7sZiuP/cGvEA481aclfbvaQBO QnYZo1Gh7z40XJxbrcaQmWL/i6CA7mxrsaZFRyPo0rI9RQPKGxz3jOQ9yS/XB+GNUs6t tJp37i2QMWTshRNJsByLWHLYV8hhTR9FE4Dtl1Q3t56eE+hWJLx3HdKhPGQcTIw7DGc+ jHdov28aOk+Swywz0N97wVSkT7a6khzL1BzHe/k+cLxalBDqG7lia4HzzUQA37QkJy9g I0jQ== X-Gm-Message-State: ALoCoQnXB+/pTlWKwDN3JY3kfXtQlqhfa9JkEpS9+l4DvKJN/rZKUX+ygVAZJ5DSWne2rQUtuGR+ X-Received: by 10.180.24.35 with SMTP id r3mr549683wif.0.1416767866339; Sun, 23 Nov 2014 10:37:46 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.227 with SMTP id v3ls392725lav.91.gmail; Sun, 23 Nov 2014 10:37:45 -0800 (PST) X-Received: by 10.112.150.102 with SMTP id uh6mr16849752lbb.50.1416767865706; Sun, 23 Nov 2014 10:37:45 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id ap1si12886331lac.54.2014.11.23.10.37.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:37:45 -0800 (PST) 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 mail-lb0-f182.google.com with SMTP id f15so5263130lbj.41 for ; Sun, 23 Nov 2014 10:37:45 -0800 (PST) X-Received: by 10.153.7.170 with SMTP id dd10mr16409326lad.44.1416767865611; Sun, 23 Nov 2014 10:37:45 -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.184.201 with SMTP id ew9csp156323lbc; Sun, 23 Nov 2014 10:37:45 -0800 (PST) X-Received: by 10.180.11.140 with SMTP id q12mr15066474wib.45.1416767864952; Sun, 23 Nov 2014 10:37:44 -0800 (PST) Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com. [209.85.212.182]) by mx.google.com with ESMTPS id u2si8506881wiw.103.2014.11.23.10.37.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:37:44 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.182 as permitted sender) client-ip=209.85.212.182; Received: by mail-wi0-f182.google.com with SMTP id h11so3764468wiw.3 for ; Sun, 23 Nov 2014 10:37:44 -0800 (PST) X-Received: by 10.180.93.195 with SMTP id cw3mr14858714wib.68.1416767864736; Sun, 23 Nov 2014 10:37:44 -0800 (PST) Received: from gnx2579.gnb.st.com (weg38-3-78-232-41-119.fbx.proxad.net. [78.232.41.119]) by mx.google.com with ESMTPSA id hk9sm17535471wjb.46.2014.11.23.10.37.42 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:37:44 -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, joel.schopp@amd.com, kim.phillips@freescale.com, paulus@samba.org, gleb@kernel.org, pbonzini@redhat.com, agraf@suse.de Cc: linux-kernel@vger.kernel.org, patches@linaro.org, will.deacon@arm.com, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, john.liuli@huawei.com, ming.lei@canonical.com, feng.wu@intel.com Subject: [PATCH v3 6/8] KVM: kvm-vfio: wrapper to VFIO external API device helpers Date: Sun, 23 Nov 2014 19:35:58 +0100 Message-Id: <1416767760-14487-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416767760-14487-1-git-send-email-eric.auger@linaro.org> References: <1416767760-14487-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: , 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. The KVM-VFIO device uses the VFIO external API device functions. Signed-off-by: Eric Auger --- 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 --- arch/arm/include/asm/kvm_host.h | 5 +++++ virt/kvm/vfio.c | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 53036e2..bca5b79 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -169,6 +169,11 @@ void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu); int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices); +struct vfio_device; +struct vfio_device *kvm_vfio_device_get_external_user(struct file *filep); +void kvm_vfio_device_put_external_user(struct vfio_device *vdev); +struct device *kvm_vfio_external_base_device(struct vfio_device *vdev); + /* We do not have shadow page tables, hence the empty hooks */ static inline int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end) diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c index 620e37f..6f0cc34 100644 --- a/virt/kvm/vfio.c +++ b/virt/kvm/vfio.c @@ -60,6 +60,51 @@ static void kvm_vfio_group_put_external_user(struct vfio_group *vfio_group) symbol_put(vfio_group_put_external_user); } +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; +} + +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); +} + +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; +} + static bool kvm_vfio_group_is_coherent(struct vfio_group *vfio_group) { long (*fn)(struct vfio_group *, unsigned long);