From patchwork Tue Feb 18 01:41:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 24810 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B685D20143 for ; Tue, 18 Feb 2014 01:43:25 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id h16sf67246509oag.8 for ; Mon, 17 Feb 2014 17:43: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:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=x1tSMrRwi6mXx8ottcjva92xatoGMhvZ8erHgivcvLw=; b=fgkwalJKbk7A/gYj7xm2CM7HZMsiXYf1YcKv5fi+LQv3o3xLdY0Mx5Yp+zZE98FTSw ijsL7k2Zo7gAGB1Oqb+6Lw05zrXV+AgGVLeto26bc5itgPh8aJwqQOzeyG6c0FiS7k2B dDoOEvBAx9hJjRWYlNMcoocqm6XLhSLjAIxiAzuL4RQALyTj13giG2VBeX/n/h9zYuFf jZ+fm99OcI+z/7zu678O0mGKYg4xVB0yM+BVnIi2ctluA2g0JRgOxb/Pi05/w2FYVJ4r L6a8D6xijcK+ZC2lVC0/IOpgPHRgHM6BZslnPqFOWfgINkgh300X+izSx+woieaGNTl3 68NA== X-Gm-Message-State: ALoCoQlQVERiCHA6AX1mw3n4tkqnLJz3li1H4zso9xkZJelPtVuQqFUwLXg81CFhk59OdjQayD67 X-Received: by 10.182.104.70 with SMTP id gc6mr11678858obb.35.1392687804630; Mon, 17 Feb 2014 17:43:24 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.37 with SMTP id u34ls1103295qgu.37.gmail; Mon, 17 Feb 2014 17:43:24 -0800 (PST) X-Received: by 10.52.164.137 with SMTP id yq9mr12659195vdb.33.1392687804539; Mon, 17 Feb 2014 17:43:24 -0800 (PST) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id l2si5033856vcf.43.2014.02.17.17.43.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 17:43:24 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id la4so12495700vcb.35 for ; Mon, 17 Feb 2014 17:43:24 -0800 (PST) X-Received: by 10.221.37.1 with SMTP id tc1mr6720988vcb.32.1392687804420; Mon, 17 Feb 2014 17:43:24 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp180085vcz; Mon, 17 Feb 2014 17:43:24 -0800 (PST) X-Received: by 10.224.103.129 with SMTP id k1mr6520438qao.97.1392687803790; Mon, 17 Feb 2014 17:43:23 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id mq7si4181008qcb.114.2014.02.17.17.43.23 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 17 Feb 2014 17:43:23 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:45582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFZiV-0004Di-Dg for patch@linaro.org; Mon, 17 Feb 2014 20:43:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFZhY-0003Ba-GQ for qemu-devel@nongnu.org; Mon, 17 Feb 2014 20:42:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFZhS-0005zK-IB for qemu-devel@nongnu.org; Mon, 17 Feb 2014 20:42:24 -0500 Received: from mail-pd0-f169.google.com ([209.85.192.169]:60031) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFZhS-0005yR-4g for qemu-devel@nongnu.org; Mon, 17 Feb 2014 20:42:18 -0500 Received: by mail-pd0-f169.google.com with SMTP id v10so15616579pde.28 for ; Mon, 17 Feb 2014 17:42:17 -0800 (PST) X-Received: by 10.68.197.40 with SMTP id ir8mr11872988pbc.138.1392687737400; Mon, 17 Feb 2014 17:42:17 -0800 (PST) Received: from localhost.localdomain (c-67-169-181-221.hsd1.ca.comcast.net. [67.169.181.221]) by mx.google.com with ESMTPSA id vx10sm129526828pac.17.2014.02.17.17.42.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 17:42:16 -0800 (PST) From: Christoffer Dall To: qemu-devel@nongnu.org Date: Mon, 17 Feb 2014 17:41:59 -0800 Message-Id: <1392687720-26806-4-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1392687720-26806-1-git-send-email-christoffer.dall@linaro.org> References: <1392687720-26806-1-git-send-email-christoffer.dall@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.169 Cc: kvmarm@lists.cs.columbia.edu, Christoffer Dall Subject: [Qemu-devel] [PATCH v6 3/4] kvm: Common device control API functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christoffer.dall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Introduces two simple functions: int kvm_device_ioctl(int fd, int type, ...); int kvm_create_device(KVMState *s, uint64_t type, bool test); These functions wrap the basic ioctl-based interactions with KVM in a way similar to other KVM ioctl wrappers. Reviewed-by: Peter Maydell Signed-off-by: Christoffer Dall --- Changelog[v2 -> v3]: - Changed format for trace-events according to upstream changes Changelog[v1 -> v2]: - Added function docs and adjust code formatting - Return proper error value from kvm_create_device include/sysemu/kvm.h | 22 ++++++++++++++++++++++ kvm-all.c | 39 +++++++++++++++++++++++++++++++++++++++ trace-events | 1 + 3 files changed, 62 insertions(+) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index e4e43b8..a02d67c 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -194,6 +194,28 @@ int kvm_vm_ioctl(KVMState *s, int type, ...); int kvm_vcpu_ioctl(CPUState *cpu, int type, ...); +/** + * kvm_device_ioctl - call an ioctl on a kvm device + * @fd: The KVM device file descriptor as returned from KVM_CREATE_DEVICE + * @type: The device-ctrl ioctl number + * + * Returns: -errno on error, nonnegative on success + */ +int kvm_device_ioctl(int fd, int type, ...); + +/** + * kvm_create_device - create a KVM device for the device control API + * @KVMState: The KVMState pointer + * @type: The KVM device type (see Documentation/virtual/kvm/devices in the + * kernel source) + * @test: If true, only test if device can be created, but don't actually + * create the device. + * + * Returns: -errno on error, nonnegative on success: @test ? 0 : device fd; + */ +int kvm_create_device(KVMState *s, uint64_t type, bool test); + + /* Arch specific hooks */ extern const KVMCapabilityInfo kvm_arch_required_capabilities[]; diff --git a/kvm-all.c b/kvm-all.c index 8670878..290e726 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1784,6 +1784,24 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...) return ret; } +int kvm_device_ioctl(int fd, int type, ...) +{ + int ret; + void *arg; + va_list ap; + + va_start(ap, type); + arg = va_arg(ap, void *); + va_end(ap); + + trace_kvm_device_ioctl(fd, type, arg); + ret = ioctl(fd, type, arg); + if (ret == -1) { + ret = -errno; + } + return ret; +} + int kvm_has_sync_mmu(void) { return kvm_check_extension(kvm_state, KVM_CAP_SYNC_MMU); @@ -2065,3 +2083,24 @@ int kvm_on_sigbus(int code, void *addr) { return kvm_arch_on_sigbus(code, addr); } + +int kvm_create_device(KVMState *s, uint64_t type, bool test) +{ + int ret; + struct kvm_create_device create_dev; + + create_dev.type = type; + create_dev.fd = -1; + create_dev.flags = test ? KVM_CREATE_DEVICE_TEST : 0; + + if (!kvm_check_extension(s, KVM_CAP_DEVICE_CTRL)) { + return -ENOTSUP; + } + + ret = kvm_vm_ioctl(s, KVM_CREATE_DEVICE, &create_dev); + if (ret) { + return ret; + } + + return test ? 0 : create_dev.fd; +} diff --git a/trace-events b/trace-events index ab11f97..1d5f5aa 100644 --- a/trace-events +++ b/trace-events @@ -1170,6 +1170,7 @@ kvm_ioctl(int type, void *arg) "type 0x%x, arg %p" kvm_vm_ioctl(int type, void *arg) "type 0x%x, arg %p" kvm_vcpu_ioctl(int cpu_index, int type, void *arg) "cpu_index %d, type 0x%x, arg %p" kvm_run_exit(int cpu_index, uint32_t reason) "cpu_index %d, reason %d" +kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type 0x%x, arg %p" # memory.c memory_region_ops_read(void *mr, uint64_t addr, uint64_t value, unsigned size) "mr %p addr %#"PRIx64" value %#"PRIx64" size %u"