From patchwork Thu Sep 26 19:56:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 20647 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 2AAC624687 for ; Thu, 26 Sep 2013 19:56:56 +0000 (UTC) Received: by mail-vc0-f199.google.com with SMTP id lf12sf1477181vcb.2 for ; Thu, 26 Sep 2013 12:56:55 -0700 (PDT) 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=IGazoV57VJg48dfba0J4Y87LcyCs8il/mNb1khIY900=; b=ktTCsHT3snG5wuGxs9/CnP66pBHbhPgPEax/22SgF5mz8ZyeQlVM0ASpEvRkOp1BUt cWliXaLwecJqdxEtsSqcxl7/1mqwdw5PhwuN1vZpeL5BQfJ1IUNgTc89oZNnsUOQLcfI eUQ/DKxBrM9p7UcTBKV66Z+BRbcHfz/8+uWqz6udEIKOa4qpPocd5lOfVebFSpwUHIZh CwLHyWHymheBQigYQA4iP0waRgQmkk1JBPDixf0KGbI+jyd2uCYpp7et5LnMV1NPu+qt orb7nEXZ32Llk8h/M6U20BqqcJNoyyLQvHAd27P9UQ25vXMknI0l8mi5tJpKtTKSCiVu FRPA== X-Gm-Message-State: ALoCoQn3PHfQeYJHR/beTayq9MjEIPi3FDdUpt2uCQ2Hj/dHrt+evuIKHBMuWf6rgNfpiqiCuiBg X-Received: by 10.236.101.103 with SMTP id a67mr548302yhg.25.1380225415923; Thu, 26 Sep 2013 12:56:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.41.5 with SMTP id b5ls1100089qel.70.gmail; Thu, 26 Sep 2013 12:56:55 -0700 (PDT) X-Received: by 10.58.179.104 with SMTP id df8mr2242541vec.26.1380225415809; Thu, 26 Sep 2013 12:56:55 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id xs13si825073veb.28.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 26 Sep 2013 12:56:55 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.169 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.169; Received: by mail-ve0-f169.google.com with SMTP id db12so1342532veb.28 for ; Thu, 26 Sep 2013 12:56:25 -0700 (PDT) X-Received: by 10.58.208.130 with SMTP id me2mr2204306vec.13.1380225385687; Thu, 26 Sep 2013 12:56:25 -0700 (PDT) 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 u4csp385943vcz; Thu, 26 Sep 2013 12:56:25 -0700 (PDT) X-Received: by 10.66.146.199 with SMTP id te7mr7456929pab.106.1380225384758; Thu, 26 Sep 2013 12:56:24 -0700 (PDT) Received: from mail-pb0-f47.google.com (mail-pb0-f47.google.com [209.85.160.47]) by mx.google.com with ESMTPS id yl2si787518pab.263.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 26 Sep 2013 12:56:24 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.47 is neither permitted nor denied by best guess record for domain of christoffer.dall@linaro.org) client-ip=209.85.160.47; Received: by mail-pb0-f47.google.com with SMTP id rr4so1568257pbb.20 for ; Thu, 26 Sep 2013 12:56:24 -0700 (PDT) X-Received: by 10.67.5.132 with SMTP id cm4mr5173857pad.186.1380225384345; Thu, 26 Sep 2013 12:56:24 -0700 (PDT) Received: from localhost.localdomain (c-67-169-181-221.hsd1.ca.comcast.net. [67.169.181.221]) by mx.google.com with ESMTPSA id l8sm4026272pbl.22.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 26 Sep 2013 12:56:23 -0700 (PDT) From: Christoffer Dall To: qemu-devel@nongnu.org Cc: kvmarm@lists.cs.columbia.edu, patches@linaro.org, Christoffer Dall Subject: [RFC PATCH v2 3/4] kvm: Common device control API functions Date: Thu, 26 Sep 2013 12:56:12 -0700 Message-Id: <1380225373-22132-4-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1380225373-22132-1-git-send-email-christoffer.dall@linaro.org> References: <1380225373-22132-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.169 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. Signed-off-by: Christoffer Dall Reviewed-by: Peter Maydell --- 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 fbb2776..7227a81 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -190,6 +190,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 fe64f3b..0899c9d 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1770,6 +1770,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); @@ -2064,3 +2082,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 3856b5c..5372c6e 100644 --- a/trace-events +++ b/trace-events @@ -1163,6 +1163,7 @@ migrate_set_state(int new_state) "new state %d" kvm_ioctl(int type, void *arg) "type %d, arg %p" kvm_vm_ioctl(int type, void *arg) "type %d, arg %p" kvm_vcpu_ioctl(int cpu_index, int type, void *arg) "cpu_index %d, type %d, arg %p" +kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type %d, arg %p" kvm_run_exit(int cpu_index, uint32_t reason) "cpu_index %d, reason %d" # memory.c