From patchwork Tue May 13 15:00:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Mueller X-Patchwork-Id: 348383 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 287281400B8 for ; Wed, 14 May 2014 01:04:32 +1000 (EST) Received: from localhost ([::1]:45655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkEFp-0003ZE-UP for incoming@patchwork.ozlabs.org; Tue, 13 May 2014 11:04:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkEC9-0007ED-T0 for qemu-devel@nongnu.org; Tue, 13 May 2014 11:00:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkEC0-0002hI-Nl for qemu-devel@nongnu.org; Tue, 13 May 2014 11:00:41 -0400 Received: from e06smtp18.uk.ibm.com ([195.75.94.114]:41029) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkEC0-0002fu-FZ for qemu-devel@nongnu.org; Tue, 13 May 2014 11:00:32 -0400 Received: from /spool/local by e06smtp18.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 May 2014 16:00:31 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp18.uk.ibm.com (192.168.101.148) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 13 May 2014 16:00:28 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 0A8011B0805F for ; Tue, 13 May 2014 16:00:42 +0100 (BST) Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by b06cxnps4075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s4DF0S4Q61145302 for ; Tue, 13 May 2014 15:00:28 GMT Received: from d06av09.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s4DF0Rdl007602 for ; Tue, 13 May 2014 09:00:27 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s4DF0Ndn007382; Tue, 13 May 2014 09:00:26 -0600 From: Michael Mueller To: qemu-devel@nongnu.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 13 May 2014 17:00:18 +0200 Message-Id: <1399993222-16339-7-git-send-email-mimu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.5.5 In-Reply-To: <1399993222-16339-1-git-send-email-mimu@linux.vnet.ibm.com> References: <1399993222-16339-1-git-send-email-mimu@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14051315-6892-0000-0000-000008C5CADA X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.114 Cc: mimu@linux.vnet.ibm.com, Gleb Natapov , Alexander Graf , Christian Borntraeger , "Jason J. Herne" , Cornelia Huck , Paolo Bonzini , Andreas Faerber , Richard Henderson Subject: [Qemu-devel] [PATCH v1 RFC 06/10] QEMU: s390: cpu model kvm VM attr interface routines 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 The patch implements routines to set and retrieve processor configuration data and to retrieve machine configuration data. The machine related data will be used to determine the list of supported cpu models of this host. Signed-off-by: Michael Mueller --- target-s390x/cpu-models.h | 21 +++++++++++++++ target-s390x/cpu.c | 2 ++ target-s390x/kvm.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h index f5c8112..3533c96 100644 --- a/target-s390x/cpu-models.h +++ b/target-s390x/cpu-models.h @@ -55,6 +55,27 @@ typedef struct S390CPUAlias { } S390CPUAlias; extern GSList *s390_cpu_aliases; +typedef struct S390ProcessorProps { + uint64_t cpuid; + uint16_t ibc; + uint8_t pad[6]; + uint64_t fac_list[S390_ARCH_FAC_LIST_SIZE_UINT64]; +} S390ProcessorProps; + +typedef struct S390MachineProps { + uint64_t cpuid; + uint32_t ibc_range; + uint8_t pad[4]; + uint64_t fac_mask[S390_ARCH_FAC_MASK_SIZE_UINT64]; + uint64_t hard_fac_list[S390_ARCH_FAC_LIST_SIZE_UINT64]; + uint64_t soft_fac_list[S390_ARCH_FAC_LIST_SIZE_UINT64]; +} S390MachineProps; + +int kvm_s390_has_cpu_model_call(uint64_t attr); +int kvm_s390_get_processor_props(S390ProcessorProps *prob); +int kvm_s390_set_processor_props(S390ProcessorProps *prob); +int kvm_s390_get_machine_props(S390MachineProps *prob); + /* * bits 0-7 : CMOS generation * bits 8-9 : reserved diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c index 10a03f9..5e292e7 100644 --- a/target-s390x/cpu.c +++ b/target-s390x/cpu.c @@ -28,6 +28,8 @@ #include "qemu-common.h" #include "qemu/timer.h" #include "hw/hw.h" +#include "cpu-qom.h" +#include "cpu-models.h" #ifndef CONFIG_USER_ONLY #include "sysemu/arch_init.h" #endif diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index b7b0edc..b69d5d0 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -33,6 +33,7 @@ #include "sysemu/sysemu.h" #include "sysemu/kvm.h" #include "cpu.h" +#include "cpu-models.h" #include "sysemu/device_tree.h" #include "qapi/qmp/qjson.h" #include "monitor/monitor.h" @@ -93,6 +94,8 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = { static int cap_sync_regs; static int cap_async_pf; +static uint64_t cpu_model_call_cache; + static void *legacy_s390_alloc(size_t size); int kvm_arch_init(KVMState *s) @@ -959,3 +962,66 @@ int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch, } return kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &kick); } + +static int cpu_model_get(uint64_t attr, uint64_t addr) +{ + struct kvm_device_attr dev_attr = { + .group = KVM_S390_VM_CPU_MODEL, + .attr = attr, + .addr = addr, + }; + + return kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &dev_attr); +} + +static int cpu_model_set(uint64_t attr, uint64_t addr) +{ + struct kvm_device_attr dev_attr = { + .group = KVM_S390_VM_CPU_MODEL, + .attr = attr, + .addr = addr, + }; + + return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &dev_attr); +} + +int kvm_s390_has_cpu_model_call(uint64_t attr) +{ + int rc; + struct kvm_device_attr dev_attr = { + .group = KVM_S390_VM_CPU_MODEL, + .attr = attr, + }; + + if (dev_attr.attr >= sizeof(cpu_model_call_cache)) { + return 0; + } + + if (cpu_model_call_cache & (1UL << dev_attr.attr)) { + return 1; + } + + rc = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &dev_attr); + if (rc == 0) { + cpu_model_call_cache |= (1UL << dev_attr.attr); + return 1; + } + + return 0; +} + +int kvm_s390_get_processor_props(S390ProcessorProps *prop) +{ + return cpu_model_get(KVM_S390_VM_CPU_PROCESSOR, (uint64_t) prop); +} + +int kvm_s390_set_processor_props(S390ProcessorProps *prop) +{ + return cpu_model_set(KVM_S390_VM_CPU_PROCESSOR, (uint64_t) prop); +} + +int kvm_s390_get_machine_props(S390MachineProps *prop) +{ + return cpu_model_get(KVM_S390_VM_CPU_MACHINE, (uint64_t) prop); +} +