From patchwork Tue Jan 28 20:28:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 23812 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f199.google.com (mail-vc0-f199.google.com [209.85.220.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 007E4202FA for ; Tue, 28 Jan 2014 20:28:36 +0000 (UTC) Received: by mail-vc0-f199.google.com with SMTP id hu8sf1862902vcb.6 for ; Tue, 28 Jan 2014 12:28:36 -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=EaoJRcZE13ukVbOuSmLhLY3GHNTAnVZTUSF8X7hqbsc=; b=Cq2R97H3QgHJbi0UKP7w14sxlb7Y+OmCA5c9D+LZdmEHTCqb+VVK8JVI77rZ0TlTM+ YbNKZGeQfMC6pHJNTKjQLsSfeqvze0TQCpJ2qJi0Kqjg6be59LKFs9rxBCUaAcMlJmHD XziVdvb4572JC6uxRMrDfXtpdPh5WBUL8wx8gjGKWeKYs3Ziw57OZuz39P8+kCAtGxWn 4Oq0rhZrCGt5/DqF9OxWXX44/TAJdvIIFHRK7TOdhfx649xuXM/pmxWtHnKZQWE8njJF j0vJOGQ6LoXNlAfYmtTAx4gGd9tRqrct2IZX5KEK4SqGJF2S+qFwvdwjjBAgg1dVSIcx dNew== X-Gm-Message-State: ALoCoQla54RfPnC1ntotGEcuTCx+8LOUwIHFGdCyBjTjkzeBdMHTYOPHgLcr5CcaXNvMlB4c+yAd X-Received: by 10.58.238.199 with SMTP id vm7mr167324vec.17.1390940916200; Tue, 28 Jan 2014 12:28:36 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.73 with SMTP id i67ls2164704qgd.97.gmail; Tue, 28 Jan 2014 12:28:36 -0800 (PST) X-Received: by 10.58.29.42 with SMTP id g10mr1672448veh.28.1390940916092; Tue, 28 Jan 2014 12:28:36 -0800 (PST) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id 6si6742103vcu.126.2014.01.28.12.28.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 28 Jan 2014 12:28:36 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.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.128.176; Received: by mail-ve0-f176.google.com with SMTP id oz11so601152veb.35 for ; Tue, 28 Jan 2014 12:28:36 -0800 (PST) X-Received: by 10.52.108.232 with SMTP id hn8mr2254399vdb.29.1390940915950; Tue, 28 Jan 2014 12:28:35 -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.220.174.196 with SMTP id u4csp59279vcz; Tue, 28 Jan 2014 12:28:35 -0800 (PST) X-Received: by 10.68.201.226 with SMTP id kd2mr3518835pbc.157.1390940914627; Tue, 28 Jan 2014 12:28:34 -0800 (PST) Received: from mail-pa0-f47.google.com (mail-pa0-f47.google.com [209.85.220.47]) by mx.google.com with ESMTPS id sj5si16719403pab.81.2014.01.28.12.28.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 28 Jan 2014 12:28:34 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.47 is neither permitted nor denied by best guess record for domain of christoffer.dall@linaro.org) client-ip=209.85.220.47; Received: by mail-pa0-f47.google.com with SMTP id kp14so830427pab.6 for ; Tue, 28 Jan 2014 12:28:34 -0800 (PST) X-Received: by 10.66.231.6 with SMTP id tc6mr3761571pac.68.1390940914259; Tue, 28 Jan 2014 12:28:34 -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 bc4sm45466251pbb.2.2014.01.28.12.28.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 28 Jan 2014 12:28:33 -0800 (PST) From: Christoffer Dall To: qemu-devel@nongnu.org Cc: kvmarm@lists.cs.columbia.edu, patches@linaro.org, Christoffer Dall Subject: [PATCH v4 3/4] kvm: Common device control API functions Date: Tue, 28 Jan 2014 12:28:09 -0800 Message-Id: <1390940890-1868-4-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1390940890-1868-1-git-send-email-christoffer.dall@linaro.org> References: <1390940890-1868-1-git-send-email-christoffer.dall@linaro.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.128.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 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: , 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 a890152..8310c1f 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 1b668d1..cb827ad 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"