From patchwork Tue Nov 19 06:16:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 292290 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9C1032C00B3 for ; Tue, 19 Nov 2013 17:16:22 +1100 (EST) Received: from localhost ([::1]:47292 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Viebk-0005fR-0p for incoming@patchwork.ozlabs.org; Tue, 19 Nov 2013 01:16:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vieb7-0005Tx-ML for qemu-devel@nongnu.org; Tue, 19 Nov 2013 01:15:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vieaz-0004LK-3V for qemu-devel@nongnu.org; Tue, 19 Nov 2013 01:15:41 -0500 Received: from mail-pa0-f53.google.com ([209.85.220.53]:41627) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vieay-0004LC-QK for qemu-devel@nongnu.org; Tue, 19 Nov 2013 01:15:33 -0500 Received: by mail-pa0-f53.google.com with SMTP id hz1so4717031pad.12 for ; Mon, 18 Nov 2013 22:15:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5T8y19N66Nl6U54GBGIWls943K1vD1YoVem2Wog8RFg=; b=QhT9M5HItm3i6jNaH1d3AdNUz6O9cm4MDhkCa/q5MCDOb8P3WPUSgWTHiaxpRZcKAT skAFk9sHvH3XUrThpIBK0ct+4E9bDR8UWuJ1JiYh9NXC29FTb38kqq8n+XNAU3J6zNdJ NmExylxjHv2oap5JrAN2zVqJAqpH5xyPao8joU9C488i1BxGu8Y5CDD1qRIijaWeYGY9 Bb7jC7Ll2PO2Gr8d07mvStTVwe5Q5ZAoZzX0ASSOueuwXR2ISZYI2qyxMaaCwXa7m5Lw 6dj2JPS+KhMezdvzoOcl9cGFLyzDhzACG8DSgvRY+iAF4NcYycFR0X8PUIj4Cu708lfP Y09g== X-Gm-Message-State: ALoCoQkn3d9kWUpEBSOw1Nc4HXERJz1vueGT5apMyfQZyMH7dsnBQ9Oy+YHeqwf9a04o8F91y9zC X-Received: by 10.67.1.101 with SMTP id bf5mr24690191pad.50.1384841731932; Mon, 18 Nov 2013 22:15:31 -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 fk4sm31648068pab.23.2013.11.18.22.15.30 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Nov 2013 22:15:31 -0800 (PST) From: Christoffer Dall To: qemu-devel@nongnu.org Date: Mon, 18 Nov 2013 22:16:35 -0800 Message-Id: <1384841796-19437-4-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1384841796-19437-1-git-send-email-christoffer.dall@linaro.org> References: <1384841796-19437-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.220.53 Cc: kvmarm@lists.cs.columbia.edu, Christoffer Dall , patches@linaro.org Subject: [Qemu-devel] [RFC PATCH v3 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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[v3]: - Changed format for trace-events according to upstream changes Changelog[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 a693945..e436741 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1786,6 +1786,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); @@ -2067,3 +2085,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 8695e9e..652bf31 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"