From nobody Tue Apr 16 11:59:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600248472; cv=none; d=zohomail.com; s=zohoarc; b=Lio5zwKWP03WAy7gD35Jqw8LgMb8CnwsZqMS/Zx2V+E48ikBhz4Mqdd/MtiYZqz2xz85AxAiKFZMlx94xxVQGjTanT8ywdhUwW5RBfBDuZ0hNtn5sHvkHMq0ALqJj5R/5ZUGp3cQuhA3eri93TUHbJnI2D9vXG4+FegjEFP5JMU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600248472; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JYA+zFKDmKH8V8HXIMs/oeL/JdVQqc9A9vJ3k5IO9KY=; b=ed2tkxP5VZOiS2oGYUYWgYcOmizKU44HNnxNLv+PC3DyJ0lq2UKlfefXipN1p5kQmQh7XP7OAxvmls2Hv6+AR0BiqvSlfes6spvBsSGZ3nFXFTQSQQ1ByHbNv3S2GzbP3PXTgSZSulBj5DpfvRI2nyO8ff80ZSwOmpwcw0LFBJE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600248472167651.2372763250686; Wed, 16 Sep 2020 02:27:52 -0700 (PDT) Received: from localhost ([::1]:54664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kITjD-0001cl-05 for importer@patchew.org; Wed, 16 Sep 2020 05:27:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kITi5-0008Rv-4M for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:26:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56253) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIThy-0005Ev-PT for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:26:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-578-JY-Yn2hBNVOsGrQIge6Ekw-1; Wed, 16 Sep 2020 05:26:30 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 36873801ABD; Wed, 16 Sep 2020 09:26:29 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB8855DE86; Wed, 16 Sep 2020 09:26:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600248394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JYA+zFKDmKH8V8HXIMs/oeL/JdVQqc9A9vJ3k5IO9KY=; b=hmH6G1a7mXYelZZ1VpquNcjkbkHrL5ls2U39tciaDX/fyHq1FHOJM8Ls7KUfCVXlh5xtph /PVJZjyDInj+VHHOI32ffhndt30c2i0ghjs4mwBYpzHmlyssVEK1B/mo4DRLlMfJoFMIp4 Az7tO9WsTF3+yhMj3jKGkcITppKvagw= X-MC-Unique: JY-Yn2hBNVOsGrQIge6Ekw-1 From: Andrew Jones To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [PATCH v3 1/5] target/arm/kvm: Make uncalled stubs explicitly unreachable Date: Wed, 16 Sep 2020 11:26:16 +0200 Message-Id: <20200916092620.19161-2-drjones@redhat.com> In-Reply-To: <20200916092620.19161-1-drjones@redhat.com> References: <20200916092620.19161-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=drjones@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=drjones@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/16 02:35:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, eric.auger@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When we compile without KVM support !defined(CONFIG_KVM) we generate stubs for functions that the linker will still encounter. Sometimes these stubs can be executed safely and are placed in paths where they get executed with or without KVM. Other functions should never be called without KVM. Those functions should be guarded by kvm_enabled(), but should also be robust to refactoring mistakes. Putting a g_assert_not_reached() in the function should help. Additionally, the g_assert_not_reached() calls may actually help the linker remove some code. We remove the stubs for kvm_arm_get/put_virtual_time(), as they aren't necessary at all - the only caller is in kvm.c Reviewed-by: Eric Auger Signed-off-by: Andrew Jones --- target/arm/kvm_arm.h | 51 +++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h index bc178eeb84c0..f513702176a7 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -344,18 +344,10 @@ int kvm_arm_set_irq(int cpu, int irqtype, int irq, in= t level); =20 #else =20 -static inline void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu) -{ - /* - * This should never actually be called in the "not KVM" case, - * but set up the fields to indicate an error anyway. - */ - cpu->kvm_target =3D QEMU_KVM_ARM_TARGET_NONE; - cpu->host_cpu_probe_failed =3D true; -} - -static inline void kvm_arm_add_vcpu_properties(Object *obj) {} - +/* + * It's safe to call these functions without KVM support. + * They should either do nothing or return "not supported". + */ static inline bool kvm_arm_aarch32_supported(void) { return false; @@ -371,23 +363,44 @@ static inline bool kvm_arm_sve_supported(void) return false; } =20 +/* + * These functions should never actually be called without KVM support. + */ +static inline void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu) +{ + g_assert_not_reached(); +} + +static inline void kvm_arm_add_vcpu_properties(Object *obj) +{ + g_assert_not_reached(); +} + static inline int kvm_arm_get_max_vm_ipa_size(MachineState *ms) { - return -ENOENT; + g_assert_not_reached(); } =20 static inline int kvm_arm_vgic_probe(void) { - return 0; + g_assert_not_reached(); } =20 -static inline void kvm_arm_pmu_set_irq(CPUState *cs, int irq) {} -static inline void kvm_arm_pmu_init(CPUState *cs) {} +static inline void kvm_arm_pmu_set_irq(CPUState *cs, int irq) +{ + g_assert_not_reached(); +} =20 -static inline void kvm_arm_sve_get_vls(CPUState *cs, unsigned long *map) {} +static inline void kvm_arm_pmu_init(CPUState *cs) +{ + g_assert_not_reached(); +} + +static inline void kvm_arm_sve_get_vls(CPUState *cs, unsigned long *map) +{ + g_assert_not_reached(); +} =20 -static inline void kvm_arm_get_virtual_time(CPUState *cs) {} -static inline void kvm_arm_put_virtual_time(CPUState *cs) {} #endif =20 static inline const char *gic_class_name(void) --=20 2.26.2 From nobody Tue Apr 16 11:59:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600248478; cv=none; d=zohomail.com; s=zohoarc; b=YiQSRxM/Hbk4uxyktRqycrACI+mX2IER8iHacWFofZJ3Ty97BXEILHfCtLDmRd3k8NBwTZ43ObFpZlFsQ4rvST8NTU3xNtrAHMQMMaGR0mqvZ+xLjJ0dx4V2pzg7ZaNcGLJ3QpLQHuqeT6ZkHldbHkXj+FUMuh0cbQ20tu89ZuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600248478; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hhsaugpWiFwFc4SoYUPLxMZx9qgqTYv00DKouNTKEiM=; b=QY/vFB2HQkFMlLEhL8K0VdzYfuNF+E04Ft2dEnjYPWDJ0kz5Hkm1Xd73ZQfW+NpWV8Ge8BkgdUqqhRQV+ASUV3bP1KmEMZ6hCTOVr7xBJJkuEpYYiaaGgcG7Ga/yJKcEv4n/mzFJoxXjNIrR/K7zsDDVMfe4WKYscd8tC09I8ik= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600248478187856.8798286678533; Wed, 16 Sep 2020 02:27:58 -0700 (PDT) Received: from localhost ([::1]:55206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kITjI-0001qX-UN for importer@patchew.org; Wed, 16 Sep 2020 05:27:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kITi3-0008Qz-Dy for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:26:40 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:48625 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIThy-0005Et-F8 for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:26:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-449-Y1n4RPRcNAmlndGaM9zJkA-1; Wed, 16 Sep 2020 05:26:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA907186DD3A; Wed, 16 Sep 2020 09:26:30 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A3E3607A1; Wed, 16 Sep 2020 09:26:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600248393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hhsaugpWiFwFc4SoYUPLxMZx9qgqTYv00DKouNTKEiM=; b=VVjT7aTTLF/gXCatNWKcS333GlbOnkckpb7sR2xrg5IYyMbN/44o9Yr3+AHNcC2R2wQqx4 0mVpItVMygSTXHwNFdEv02DxVQEeHD/3jJVHn452jNbtuz0c1xfOTVo/OOW92IVjadAHg/ sFF1ZxWyN8bWSi6fFA/kBCPhoPbeb/I= X-MC-Unique: Y1n4RPRcNAmlndGaM9zJkA-1 From: Andrew Jones To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [PATCH v3 2/5] hw/arm/virt: Move post cpu realize check into its own function Date: Wed, 16 Sep 2020 11:26:17 +0200 Message-Id: <20200916092620.19161-3-drjones@redhat.com> In-Reply-To: <20200916092620.19161-1-drjones@redhat.com> References: <20200916092620.19161-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=drjones@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=drjones@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/16 02:41:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, eric.auger@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We'll add more to this new function in coming patches so we also state the gic must be created and call it below create_gic(). No functional change intended. Reviewed-by: Eric Auger Reviewed-by: Peter Maydell Signed-off-by: Andrew Jones --- hw/arm/virt.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index acf9bfbeceaf..2cba21fe3ad9 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1672,6 +1672,31 @@ static void finalize_gic_version(VirtMachineState *v= ms) } } =20 +/* + * virt_cpu_post_init() must be called after the CPUs have + * been realized and the GIC has been created. + */ +static void virt_cpu_post_init(VirtMachineState *vms) +{ + bool aarch64; + + aarch64 =3D object_property_get_bool(OBJECT(first_cpu), "aarch64", NUL= L); + + if (!kvm_enabled()) { + if (aarch64 && vms->highmem) { + int requested_pa_size =3D 64 - clz64(vms->highest_gpa); + int pamax =3D arm_pamax(ARM_CPU(first_cpu)); + + if (pamax < requested_pa_size) { + error_report("VCPU supports less PA bits (%d) than " + "requested by the memory map (%d)", + pamax, requested_pa_size); + exit(1); + } + } + } +} + static void machvirt_init(MachineState *machine) { VirtMachineState *vms =3D VIRT_MACHINE(machine); @@ -1886,22 +1911,6 @@ static void machvirt_init(MachineState *machine) fdt_add_timer_nodes(vms); fdt_add_cpu_nodes(vms); =20 - if (!kvm_enabled()) { - ARMCPU *cpu =3D ARM_CPU(first_cpu); - bool aarch64 =3D object_property_get_bool(OBJECT(cpu), "aarch64", = NULL); - - if (aarch64 && vms->highmem) { - int requested_pa_size, pamax =3D arm_pamax(cpu); - - requested_pa_size =3D 64 - clz64(vms->highest_gpa); - if (pamax < requested_pa_size) { - error_report("VCPU supports less PA bits (%d) than request= ed " - "by the memory map (%d)", pamax, requested_pa_= size); - exit(1); - } - } - } - memory_region_add_subregion(sysmem, vms->memmap[VIRT_MEM].base, machine->ram); if (machine->device_memory) { @@ -1913,6 +1922,8 @@ static void machvirt_init(MachineState *machine) =20 create_gic(vms); =20 + virt_cpu_post_init(vms); + fdt_add_pmu_nodes(vms); =20 create_uart(vms, VIRT_UART, sysmem, serial_hd(0)); --=20 2.26.2 From nobody Tue Apr 16 11:59:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600248556; cv=none; d=zohomail.com; s=zohoarc; b=TD6axzXKwJbq/J1tKL71TUdLbfc2FRydZIw81k4VE5MY+VZTTyP6itgZeDO7P4AdXJ46JK3fYeD2D3MiJ3QaCZmdw+yyiDcNoxIL57Rva5dcCJYgVOzbUCSFkQLB3TAoHf4YsDhPAL+PMdI8MvXqeutQwkNBjmCr99J9Tesdb1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600248556; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0noMqEEwXEQCXdwYxIBfUrKdLiJaDdhoPitQpm3ruXQ=; b=bAahRZpSgpUf+MsYJH9pZXhu7CM7fcS3TRySBNMMPuITqkqcuuay1J8rPlCUfKmuhFjltx0EI98fneLSIcmZERSEY8Ba6uYIbnCfJLmwo6UKIhx8TpZZtEj8BNeHKq5Fp1C/9nPsT/gtqUhM0jadTPhUGZ9puTqm4nqSMTYodO4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600248556072649.1249112587075; Wed, 16 Sep 2020 02:29:16 -0700 (PDT) Received: from localhost ([::1]:60948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kITkY-0004Ao-Sj for importer@patchew.org; Wed, 16 Sep 2020 05:29:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46104) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kITi5-0008S2-6D for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:26:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40407) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kITi1-0005F9-1Q for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:26:40 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-333-_1ctEnYQMfeM3YnoTtf6qw-1; Wed, 16 Sep 2020 05:26:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B368A84E244; Wed, 16 Sep 2020 09:26:32 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43DAD5DE4A; Wed, 16 Sep 2020 09:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600248395; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0noMqEEwXEQCXdwYxIBfUrKdLiJaDdhoPitQpm3ruXQ=; b=cO42soS8LsaWYI24OVz8IMAJm9b9CjVzFenHh6Q3DRK0qP/K82on2i6noulxQdy6cx6BBU R9e7+Y3k0aR9GjfoKUaF8jPqSRNBootQ0Md8OGcdUQfDTxrQssEZo8RCjiWfeAJMgHfehn QcmENeTCqhoBIMfu8gojc7eeD7rllmA= X-MC-Unique: _1ctEnYQMfeM3YnoTtf6qw-1 From: Andrew Jones To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [PATCH v3 3/5] hw/arm/virt: Move kvm pmu setup to virt_cpu_post_init Date: Wed, 16 Sep 2020 11:26:18 +0200 Message-Id: <20200916092620.19161-4-drjones@redhat.com> In-Reply-To: <20200916092620.19161-1-drjones@redhat.com> References: <20200916092620.19161-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=drjones@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=drjones@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/16 02:16:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, eric.auger@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Move the KVM PMU setup part of fdt_add_pmu_nodes() to virt_cpu_post_init(), which is a more appropriate location. Now fdt_add_pmu_nodes() is also named more appropriately, because it no longer does anything but fdt node creation. No functional change intended. Reviewed-by: Peter Maydell Signed-off-by: Andrew Jones Reviewed-by: Eric Auger --- hw/arm/virt.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 2cba21fe3ad9..6797eb397a7a 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -521,21 +521,12 @@ static void fdt_add_gic_node(VirtMachineState *vms) =20 static void fdt_add_pmu_nodes(const VirtMachineState *vms) { - CPUState *cpu; - ARMCPU *armcpu; + ARMCPU *armcpu =3D ARM_CPU(first_cpu); uint32_t irqflags =3D GIC_FDT_IRQ_FLAGS_LEVEL_HI; =20 - CPU_FOREACH(cpu) { - armcpu =3D ARM_CPU(cpu); - if (!arm_feature(&armcpu->env, ARM_FEATURE_PMU)) { - return; - } - if (kvm_enabled()) { - if (kvm_irqchip_in_kernel()) { - kvm_arm_pmu_set_irq(cpu, PPI(VIRTUAL_PMU_IRQ)); - } - kvm_arm_pmu_init(cpu); - } + if (!arm_feature(&armcpu->env, ARM_FEATURE_PMU)) { + assert(!object_property_get_bool(OBJECT(armcpu), "pmu", NULL)); + return; } =20 if (vms->gic_version =3D=3D VIRT_GIC_VERSION_2) { @@ -544,7 +535,6 @@ static void fdt_add_pmu_nodes(const VirtMachineState *v= ms) (1 << vms->smp_cpus) - 1); } =20 - armcpu =3D ARM_CPU(qemu_get_cpu(0)); qemu_fdt_add_subnode(vms->fdt, "/pmu"); if (arm_feature(&armcpu->env, ARM_FEATURE_V8)) { const char compat[] =3D "arm,armv8-pmuv3"; @@ -1678,11 +1668,23 @@ static void finalize_gic_version(VirtMachineState *= vms) */ static void virt_cpu_post_init(VirtMachineState *vms) { - bool aarch64; + bool aarch64, pmu; + CPUState *cpu; =20 aarch64 =3D object_property_get_bool(OBJECT(first_cpu), "aarch64", NUL= L); + pmu =3D object_property_get_bool(OBJECT(first_cpu), "pmu", NULL); =20 - if (!kvm_enabled()) { + if (kvm_enabled()) { + CPU_FOREACH(cpu) { + if (pmu) { + assert(arm_feature(&ARM_CPU(cpu)->env, ARM_FEATURE_PMU)); + if (kvm_irqchip_in_kernel()) { + kvm_arm_pmu_set_irq(cpu, PPI(VIRTUAL_PMU_IRQ)); + } + kvm_arm_pmu_init(cpu); + } + } + } else { if (aarch64 && vms->highmem) { int requested_pa_size =3D 64 - clz64(vms->highest_gpa); int pamax =3D arm_pamax(ARM_CPU(first_cpu)); --=20 2.26.2 From nobody Tue Apr 16 11:59:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600248555; cv=none; d=zohomail.com; s=zohoarc; b=MOvfy7A3WyF1/+8rouSR0gg+q/PtEOQiplicGkg9Cqye+nhGSiKzmoOc6R+8gjcrHWX6uQQ5Qs7WmP7KsGnwZVnj/kL3zidd7x7jdwPlHPAtBS38Mdba9kfoJuJbC4a1mAEWNJJGR+dsGteMmgxJeXm6PqPVhstUrw5YBqLSiMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600248555; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gTO/SQ9vshib7GcatEkVOzEDRKcf41wNlPhOxTVqARc=; b=MImYo2+v4aGAb25SWFZjieEwJrQxbTcMpru6OGc+IYzNzdex1IEhA0ZYbZ8DNcAej/Yz7a0Okx3qpDO2kMHzP67e+ryc0tXnoNhHXHM1ABxhAIPHRTRGHT9jWj5b919dO0zukQUHf5KMgThI31kH3Sko0J1ldX8FcEbT1KVm+N4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600248555222630.3421071219504; Wed, 16 Sep 2020 02:29:15 -0700 (PDT) Received: from localhost ([::1]:60840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kITkX-000489-W2 for importer@patchew.org; Wed, 16 Sep 2020 05:29:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kITi5-0008SE-Jh for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:26:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23669) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kITi3-0005FQ-4e for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:26:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-443--JT9L-EbOSyJUwnSRqmltQ-1; Wed, 16 Sep 2020 05:26:35 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E6C1EA1CA; Wed, 16 Sep 2020 09:26:34 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DA325DE46; Wed, 16 Sep 2020 09:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600248398; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gTO/SQ9vshib7GcatEkVOzEDRKcf41wNlPhOxTVqARc=; b=Jqxd0DvuGa/8tD5hsKvTzT0ONuBFlAi/AH3jQOpwTtzgSPPLnPEv+tOFzEoW7b5zARIVCb Kh5LANxA2c1Pi0DmkaOM/RxWW3Zio+K8AGYwILU8kCxFcCPmuJUahQQLXPRsoNnR/w184T YM4QwfHR5IXmT1vWKPXrmwPXWwEhUpw= X-MC-Unique: -JT9L-EbOSyJUwnSRqmltQ-1 From: Andrew Jones To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [PATCH v3 4/5] DO NOT MERGE: HACK: Add steal time KVM cap to kvm.h Date: Wed, 16 Sep 2020 11:26:19 +0200 Message-Id: <20200916092620.19161-5-drjones@redhat.com> In-Reply-To: <20200916092620.19161-1-drjones@redhat.com> References: <20200916092620.19161-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=drjones@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=drjones@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/16 02:16:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, eric.auger@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" --- linux-headers/linux/kvm.h | 1 + 1 file changed, 1 insertion(+) diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index a28c3667370b..924672cca1f1 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -1031,6 +1031,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_PPC_SECURE_GUEST 181 #define KVM_CAP_HALT_POLL 182 #define KVM_CAP_ASYNC_PF_INT 183 +#define KVM_CAP_STEAL_TIME 187 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 --=20 2.26.2 From nobody Tue Apr 16 11:59:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600248666; cv=none; d=zohomail.com; s=zohoarc; b=XBFGgon8uVvpLC0qZkR2jJubeWygbzsjri5hzjvlrKNsF583FiFXK/Jcpebv9T20zPZjk9sVIXLvyhPXCjjuZrOdy59QRhphyBl5CCGU3IZqssyS0iqQfo20byzCq1GAYcI85R/x9RuyrX6nQmzQDHEA35W4DD0I77vqXFgHZlY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600248666; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=adPBhm+w9nnZWNoFU2XxVph6shm6Gu8VNDpI5VTbkGs=; b=CxYA/jLqDR/KUBQSMM67PXVjdfq+a5bdRCVXwxfDyjMHqzM851vJz1fkR++HTd4NApxFrB5ghRmYjkjGlgKO1bLHZNWxYaAcUGDM9kvjVW7UK5ok5mPwHa83TovQWP4f15CS61FG++M+M6Yu4ekOZ7XC+yWzg9fNQyRhBTbHGlA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600248666657822.1043285895342; Wed, 16 Sep 2020 02:31:06 -0700 (PDT) Received: from localhost ([::1]:36980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kITmL-00064v-Bk for importer@patchew.org; Wed, 16 Sep 2020 05:31:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kITi9-000061-IV for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:26:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32360) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kITi6-0005GP-8z for qemu-devel@nongnu.org; Wed, 16 Sep 2020 05:26:44 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-461-JdmAqAeEMHKnWLDyhpyPsQ-1; Wed, 16 Sep 2020 05:26:37 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 98A7681F004; Wed, 16 Sep 2020 09:26:36 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB6155DE4A; Wed, 16 Sep 2020 09:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600248401; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=adPBhm+w9nnZWNoFU2XxVph6shm6Gu8VNDpI5VTbkGs=; b=JMxqRUJegsVU687dKa/FyQZyCDpcc4HCOPguKByv5YnH0Da66Wzk8nxTwWqbLP3dmRNY3w ECBq3FKuzX2wT2N+dxTa1Jq9qHqyhKcfV9UyDPMOdPn/UpvGY4WnEnmtSIRdnEB76GM3Op dbUQaljYk/cS+86+icr0k2xny9FXAak= X-MC-Unique: JdmAqAeEMHKnWLDyhpyPsQ-1 From: Andrew Jones To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [PATCH v3 5/5] hw/arm/virt: Implement kvm-steal-time Date: Wed, 16 Sep 2020 11:26:20 +0200 Message-Id: <20200916092620.19161-6-drjones@redhat.com> In-Reply-To: <20200916092620.19161-1-drjones@redhat.com> References: <20200916092620.19161-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=drjones@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=drjones@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/16 02:16:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, eric.auger@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We add the kvm-steal-time CPU property and implement it for machvirt. A tiny bit of refactoring was also done to allow pmu and pvtime to use the same vcpu device helper functions. Signed-off-by: Andrew Jones Reviewed-by: Eric Auger --- docs/system/arm/cpu-features.rst | 11 ++++++ hw/arm/virt.c | 43 +++++++++++++++++++-- include/hw/arm/virt.h | 5 +++ target/arm/cpu.c | 8 ++++ target/arm/cpu.h | 4 ++ target/arm/kvm.c | 16 ++++++++ target/arm/kvm64.c | 64 +++++++++++++++++++++++++++++--- target/arm/kvm_arm.h | 43 +++++++++++++++++++++ target/arm/monitor.c | 2 +- tests/qtest/arm-cpu-features.c | 25 +++++++++++-- 10 files changed, 208 insertions(+), 13 deletions(-) diff --git a/docs/system/arm/cpu-features.rst b/docs/system/arm/cpu-feature= s.rst index 2d5c06cd016b..35196a6b759d 100644 --- a/docs/system/arm/cpu-features.rst +++ b/docs/system/arm/cpu-features.rst @@ -200,6 +200,17 @@ the list of KVM VCPU features and their descriptions. adjustment, also restoring the legacy (pre-5.0) behavior. =20 + kvm-steal-time Since v5.2, kvm-steal-time is enabled by + default when KVM is enabled, the feature is + supported, and the guest is 64-bit. + + When kvm-steal-time is enabled a 64-bit guest + can account for time its CPUs were not running + due to the host not scheduling the corresponding + VCPU threads. The accounting statistics may + influence the guest scheduler behavior and/or be + exposed to the guest userspace. + SVE CPU Properties =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 6797eb397a7a..12efc2f095cb 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -151,6 +151,7 @@ static const MemMapEntry base_memmap[] =3D { [VIRT_PCDIMM_ACPI] =3D { 0x09070000, MEMORY_HOTPLUG_IO_LEN }, [VIRT_ACPI_GED] =3D { 0x09080000, ACPI_GED_EVT_SEL_LEN }, [VIRT_NVDIMM_ACPI] =3D { 0x09090000, NVDIMM_ACPI_IO_LEN}, + [VIRT_PVTIME] =3D { 0x090a0000, 0x00010000 }, [VIRT_MMIO] =3D { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that siz= e */ [VIRT_PLATFORM_BUS] =3D { 0x0c000000, 0x02000000 }, @@ -1666,15 +1667,39 @@ static void finalize_gic_version(VirtMachineState *= vms) * virt_cpu_post_init() must be called after the CPUs have * been realized and the GIC has been created. */ -static void virt_cpu_post_init(VirtMachineState *vms) +static void virt_cpu_post_init(VirtMachineState *vms, int max_cpus, + MemoryRegion *sysmem) { - bool aarch64, pmu; + bool aarch64, pmu, steal_time; CPUState *cpu; =20 aarch64 =3D object_property_get_bool(OBJECT(first_cpu), "aarch64", NUL= L); pmu =3D object_property_get_bool(OBJECT(first_cpu), "pmu", NULL); + steal_time =3D object_property_get_bool(OBJECT(first_cpu), + "kvm-steal-time", NULL); =20 if (kvm_enabled()) { + hwaddr pvtime_reg_base =3D vms->memmap[VIRT_PVTIME].base; + hwaddr pvtime_reg_size =3D vms->memmap[VIRT_PVTIME].size; + + if (steal_time) { + MemoryRegion *pvtime =3D g_new(MemoryRegion, 1); + hwaddr pvtime_size =3D max_cpus * PVTIME_SIZE_PER_CPU; + + /* The memory region size must be a multiple of host page size= . */ + pvtime_size =3D REAL_HOST_PAGE_ALIGN(pvtime_size); + + if (pvtime_size > pvtime_reg_size) { + error_report("pvtime requires a %ld byte memory region for= " + "%d CPUs, but only %ld has been reserved", + pvtime_size, max_cpus, pvtime_reg_size); + exit(1); + } + + memory_region_init_ram(pvtime, NULL, "pvtime", pvtime_size, NU= LL); + memory_region_add_subregion(sysmem, pvtime_reg_base, pvtime); + } + CPU_FOREACH(cpu) { if (pmu) { assert(arm_feature(&ARM_CPU(cpu)->env, ARM_FEATURE_PMU)); @@ -1683,6 +1708,10 @@ static void virt_cpu_post_init(VirtMachineState *vms) } kvm_arm_pmu_init(cpu); } + if (steal_time) { + kvm_arm_pvtime_init(cpu, pvtime_reg_base + + cpu->cpu_index * PVTIME_SIZE_PER_= CPU); + } } } else { if (aarch64 && vms->highmem) { @@ -1853,6 +1882,11 @@ static void machvirt_init(MachineState *machine) object_property_set_bool(cpuobj, "kvm-no-adjvtime", true, NULL= ); } =20 + if (vmc->no_kvm_steal_time && + object_property_find(cpuobj, "kvm-steal-time", NULL)) { + object_property_set_bool(cpuobj, "kvm-steal-time", false, NULL= ); + } + if (vmc->no_pmu && object_property_find(cpuobj, "pmu", NULL)) { object_property_set_bool(cpuobj, "pmu", false, NULL); } @@ -1924,7 +1958,7 @@ static void machvirt_init(MachineState *machine) =20 create_gic(vms); =20 - virt_cpu_post_init(vms); + virt_cpu_post_init(vms, possible_cpus->len, sysmem); =20 fdt_add_pmu_nodes(vms); =20 @@ -2566,8 +2600,11 @@ DEFINE_VIRT_MACHINE_AS_LATEST(5, 2) =20 static void virt_machine_5_1_options(MachineClass *mc) { + VirtMachineClass *vmc =3D VIRT_MACHINE_CLASS(OBJECT_CLASS(mc)); + virt_machine_5_2_options(mc); compat_props_add(mc->compat_props, hw_compat_5_1, hw_compat_5_1_len); + vmc->no_kvm_steal_time =3D true; } DEFINE_VIRT_MACHINE(5, 1) =20 diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 392b0bd57188..e0c59cc2aa75 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -54,6 +54,9 @@ =20 #define PPI(irq) ((irq) + 16) =20 +/* See Linux kernel arch/arm64/include/asm/pvclock-abi.h */ +#define PVTIME_SIZE_PER_CPU 64 + enum { VIRT_FLASH, VIRT_MEM, @@ -81,6 +84,7 @@ enum { VIRT_PCDIMM_ACPI, VIRT_ACPI_GED, VIRT_NVDIMM_ACPI, + VIRT_PVTIME, VIRT_LOWMEMMAP_LAST, }; =20 @@ -126,6 +130,7 @@ struct VirtMachineClass { bool no_highmem_ecam; bool no_ged; /* Machines < 4.2 has no support for ACPI GED device */ bool kvm_no_adjvtime; + bool no_kvm_steal_time; bool acpi_expose_flash; }; typedef struct VirtMachineClass VirtMachineClass; diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 7b5ea65fab95..972768a7ee9d 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1310,6 +1310,14 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **= errp) return; } } + + if (kvm_enabled()) { + kvm_arm_steal_time_finalize(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + } } =20 static void arm_cpu_realizefn(DeviceState *dev, Error **errp) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 6036f61d60b3..dcabd6ce2d97 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -24,6 +24,7 @@ #include "hw/registerfields.h" #include "cpu-qom.h" #include "exec/cpu-defs.h" +#include "qapi/qapi-types-common.h" =20 /* ARM processors have a weak memory model */ #define TCG_GUEST_DEFAULT_MO (0) @@ -863,6 +864,9 @@ struct ARMCPU { bool kvm_vtime_dirty; uint64_t kvm_vtime; =20 + /* KVM steal time */ + OnOffAuto kvm_steal_time; + /* Uniprocessor system with MP extensions */ bool mp_is_up; =20 diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 2eae73315d6e..f30c16f23d4a 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -192,6 +192,16 @@ static void kvm_no_adjvtime_set(Object *obj, bool valu= e, Error **errp) ARM_CPU(obj)->kvm_adjvtime =3D !value; } =20 +static bool kvm_steal_time_get(Object *obj, Error **errp) +{ + return ARM_CPU(obj)->kvm_steal_time !=3D ON_OFF_AUTO_OFF; +} + +static void kvm_steal_time_set(Object *obj, bool value, Error **errp) +{ + ARM_CPU(obj)->kvm_steal_time =3D value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_= OFF; +} + /* KVM VCPU properties should be prefixed with "kvm-". */ void kvm_arm_add_vcpu_properties(Object *obj) { @@ -207,6 +217,12 @@ void kvm_arm_add_vcpu_properties(Object *obj) "the virtual counter. VM stopped t= ime " "will be counted."); } + + cpu->kvm_steal_time =3D ON_OFF_AUTO_AUTO; + object_property_add_bool(obj, "kvm-steal-time", kvm_steal_time_get, + kvm_steal_time_set); + object_property_set_description(obj, "kvm-steal-time", + "Set off to disable KVM steal time."); } =20 bool kvm_arm_pmu_supported(void) diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index 987b35e33fea..92768166809d 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -17,6 +17,7 @@ #include =20 #include "qemu-common.h" +#include "qapi/error.h" #include "cpu.h" #include "qemu/timer.h" #include "qemu/error-report.h" @@ -397,19 +398,20 @@ static CPUWatchpoint *find_hw_watchpoint(CPUState *cp= u, target_ulong addr) return NULL; } =20 -static bool kvm_arm_pmu_set_attr(CPUState *cs, struct kvm_device_attr *att= r) +static bool kvm_arm_set_device_attr(CPUState *cs, struct kvm_device_attr *= attr, + const char *name) { int err; =20 err =3D kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr); if (err !=3D 0) { - error_report("PMU: KVM_HAS_DEVICE_ATTR: %s", strerror(-err)); + error_report("%s: KVM_HAS_DEVICE_ATTR: %s", name, strerror(-err)); return false; } =20 err =3D kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, attr); if (err !=3D 0) { - error_report("PMU: KVM_SET_DEVICE_ATTR: %s", strerror(-err)); + error_report("%s: KVM_SET_DEVICE_ATTR: %s", name, strerror(-err)); return false; } =20 @@ -426,7 +428,7 @@ void kvm_arm_pmu_init(CPUState *cs) if (!ARM_CPU(cs)->has_pmu) { return; } - if (!kvm_arm_pmu_set_attr(cs, &attr)) { + if (!kvm_arm_set_device_attr(cs, &attr, "PMU")) { error_report("failed to init PMU"); abort(); } @@ -443,12 +445,29 @@ void kvm_arm_pmu_set_irq(CPUState *cs, int irq) if (!ARM_CPU(cs)->has_pmu) { return; } - if (!kvm_arm_pmu_set_attr(cs, &attr)) { + if (!kvm_arm_set_device_attr(cs, &attr, "PMU")) { error_report("failed to set irq for PMU"); abort(); } } =20 +void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa) +{ + struct kvm_device_attr attr =3D { + .group =3D KVM_ARM_VCPU_PVTIME_CTRL, + .attr =3D KVM_ARM_VCPU_PVTIME_IPA, + .addr =3D (uint64_t)&ipa, + }; + + if (ARM_CPU(cs)->kvm_steal_time =3D=3D ON_OFF_AUTO_OFF) { + return; + } + if (!kvm_arm_set_device_attr(cs, &attr, "PVTIME IPA")) { + error_report("failed to init PVTIME IPA"); + abort(); + } +} + static int read_sys_reg32(int fd, uint32_t *pret, uint64_t id) { uint64_t ret; @@ -651,6 +670,36 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures = *ahcf) return true; } =20 +void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp) +{ + bool has_steal_time =3D kvm_arm_steal_time_supported(); + + if (cpu->kvm_steal_time =3D=3D ON_OFF_AUTO_AUTO) { + if (!has_steal_time || !arm_feature(&cpu->env, ARM_FEATURE_AARCH64= )) { + cpu->kvm_steal_time =3D ON_OFF_AUTO_OFF; + } else { + cpu->kvm_steal_time =3D ON_OFF_AUTO_ON; + } + } else if (cpu->kvm_steal_time =3D=3D ON_OFF_AUTO_ON) { + if (!has_steal_time) { + error_setg(errp, "'kvm-steal-time' cannot be enabled " + "on this host"); + return; + } else if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { + /* + * DEN0057A chapter 2 says "This specification only covers + * systems in which the Execution state of the hypervisor + * as well as EL1 of virtual machines is AArch64.". And, + * to ensure that, the smc/hvc calls are only specified as + * smc64/hvc64. + */ + error_setg(errp, "'kvm-steal-time' cannot be enabled " + "for AArch32 guests"); + return; + } + } +} + bool kvm_arm_aarch32_supported(void) { return kvm_check_extension(kvm_state, KVM_CAP_ARM_EL1_32BIT); @@ -661,6 +710,11 @@ bool kvm_arm_sve_supported(void) return kvm_check_extension(kvm_state, KVM_CAP_ARM_SVE); } =20 +bool kvm_arm_steal_time_supported(void) +{ + return kvm_check_extension(kvm_state, KVM_CAP_STEAL_TIME); +} + QEMU_BUILD_BUG_ON(KVM_ARM64_SVE_VQ_MIN !=3D 1); =20 void kvm_arm_sve_get_vls(CPUState *cs, unsigned long *map) diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h index f513702176a7..eb81b7059eb1 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -267,6 +267,24 @@ void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu); */ void kvm_arm_add_vcpu_properties(Object *obj); =20 +/** + * kvm_arm_steal_time_finalize: + * @cpu: ARMCPU for which to finalize kvm-steal-time + * @errp: Pointer to Error* for error propagation + * + * Validate the kvm-steal-time property selection and set its default + * based on KVM support and guest configuration. + */ +void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp); + +/** + * kvm_arm_steal_time_supported: + * + * Returns: true if KVM can enable steal time reporting + * and false otherwise. + */ +bool kvm_arm_steal_time_supported(void); + /** * kvm_arm_aarch32_supported: * @@ -340,6 +358,16 @@ int kvm_arm_vgic_probe(void); =20 void kvm_arm_pmu_set_irq(CPUState *cs, int irq); void kvm_arm_pmu_init(CPUState *cs); + +/** + * kvm_arm_pvtime_init: + * @cs: CPUState + * @ipa: Per-vcpu guest physical base address of the pvtime structures + * + * Initializes PVTIME for the VCPU, setting the PVTIME IPA to @ipa. + */ +void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa); + int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level); =20 #else @@ -363,6 +391,11 @@ static inline bool kvm_arm_sve_supported(void) return false; } =20 +static inline bool kvm_arm_steal_time_supported(void) +{ + return false; +} + /* * These functions should never actually be called without KVM support. */ @@ -396,6 +429,16 @@ static inline void kvm_arm_pmu_init(CPUState *cs) g_assert_not_reached(); } =20 +static inline void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa) +{ + g_assert_not_reached(); +} + +static inline void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp) +{ + g_assert_not_reached(); +} + static inline void kvm_arm_sve_get_vls(CPUState *cs, unsigned long *map) { g_assert_not_reached(); diff --git a/target/arm/monitor.c b/target/arm/monitor.c index ba6e01abd037..bd3590604a71 100644 --- a/target/arm/monitor.c +++ b/target/arm/monitor.c @@ -103,7 +103,7 @@ static const char *cpu_model_advertised_features[] =3D { "sve128", "sve256", "sve384", "sve512", "sve640", "sve768", "sve896", "sve1024", "sve1152", "sve1280", "sve1408", "sve1536", "sve1664", "sve1792", "sve1920", "sve2048", - "kvm-no-adjvtime", + "kvm-no-adjvtime", "kvm-steal-time", NULL }; =20 diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c index 77b5e30a9cf5..d20094d5a709 100644 --- a/tests/qtest/arm-cpu-features.c +++ b/tests/qtest/arm-cpu-features.c @@ -452,6 +452,7 @@ static void test_query_cpu_model_expansion(const void *= data) assert_set_feature(qts, "max", "pmu", true); =20 assert_has_not_feature(qts, "max", "kvm-no-adjvtime"); + assert_has_not_feature(qts, "max", "kvm-steal-time"); =20 if (g_str_equal(qtest_get_arch(), "aarch64")) { assert_has_feature_enabled(qts, "max", "aarch64"); @@ -493,6 +494,7 @@ static void test_query_cpu_model_expansion_kvm(const vo= id *data) assert_set_feature(qts, "host", "kvm-no-adjvtime", false); =20 if (g_str_equal(qtest_get_arch(), "aarch64")) { + bool kvm_supports_steal_time; bool kvm_supports_sve; char max_name[8], name[8]; uint32_t max_vq, vq; @@ -500,6 +502,10 @@ static void test_query_cpu_model_expansion_kvm(const v= oid *data) QDict *resp; char *error; =20 + assert_error(qts, "cortex-a15", + "We cannot guarantee the CPU type 'cortex-a15' works " + "with KVM on this host", NULL); + assert_has_feature_enabled(qts, "host", "aarch64"); =20 /* Enabling and disabling pmu should always work. */ @@ -507,16 +513,26 @@ static void test_query_cpu_model_expansion_kvm(const = void *data) assert_set_feature(qts, "host", "pmu", false); assert_set_feature(qts, "host", "pmu", true); =20 - assert_error(qts, "cortex-a15", - "We cannot guarantee the CPU type 'cortex-a15' works " - "with KVM on this host", NULL); - + /* + * Some features would be enabled by default, but they're disabled + * because this instance of KVM doesn't support them. Test that the + * features are present, and, when enabled, issue further tests. + */ + assert_has_feature(qts, "host", "kvm-steal-time"); assert_has_feature(qts, "host", "sve"); + resp =3D do_query_no_props(qts, "host"); + kvm_supports_steal_time =3D resp_get_feature(resp, "kvm-steal-time= "); kvm_supports_sve =3D resp_get_feature(resp, "sve"); vls =3D resp_get_sve_vls(resp); qobject_unref(resp); =20 + if (kvm_supports_steal_time) { + /* If we have steal-time then we should be able to toggle it. = */ + assert_set_feature(qts, "host", "kvm-steal-time", false); + assert_set_feature(qts, "host", "kvm-steal-time", true); + } + if (kvm_supports_sve) { g_assert(vls !=3D 0); max_vq =3D 64 - __builtin_clzll(vls); @@ -577,6 +593,7 @@ static void test_query_cpu_model_expansion_kvm(const vo= id *data) assert_has_not_feature(qts, "host", "aarch64"); assert_has_not_feature(qts, "host", "pmu"); assert_has_not_feature(qts, "host", "sve"); + assert_has_not_feature(qts, "host", "kvm-steal-time"); } =20 qtest_quit(qts); --=20 2.26.2