Received: by 2002:adf:c793:0:0:0:0:0 with SMTP id l19csp203999wrg; Fri, 7 Jun 2019 06:37:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzW2xr4hC4iEFcpXMWnVyJQvC9/gdkPMre8bYLNyGYCwOigyZ3cXYqP8ZiK6zwzkkai4Vsg X-Received: by 2002:aed:2fa7:: with SMTP id m36mr18135353qtd.344.1559914650971; Fri, 07 Jun 2019 06:37:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559914650; cv=none; d=google.com; s=arc-20160816; b=cCyzBzi4FFcYqmIYo9NXjiTBfeTIqDSe6wW9ZdZxsyp4Sp18LRukPQJGaIJloeAb3I vO0Sm/IHZUVIQVniKZruqVOzUHz/ZRp6IJfn9gIaEi02QTp8WPLe0uxuDSahvhz/LRMT /JckVk597jZDQf2FucLjVFzvLnkt1+H+/hZecgpKpKZxF+UktfsvMeRHCnpzeXao5bcz GAbgDBY7NZrSmgRUVf/2gwMFeeQfLUtRzzGBq5U6OjGPNVi1uFcbSRAD+pEqVWj65h4p 9+BCrl0+sEhgPcHBKDx8Nz9SPaxx6c8Tsql/d7W6IqgrOysgPGQwTdA0cj06REaaxsNd 7pRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:openpgp:from:references:to; bh=BTSgfAfKiPw52zAQi1EVAPSp7Wl8ml8g5jEZmS5OajA=; b=SpwJOs8zKfJyS1fRgFtPdxHUKjqMexwQQYyYk3PClswigvg+tdMzMxQ02xpEnh19nf vgAKdOGjS3RlsavH4uZe9wEM3qZlBtLSL8nLRYEHsUUD4U1nfR+lFlW165+aUd9wWCdj vVRwTMTIA1JwHqUY0YNhxFyYl8/nUIRwdIyqKfElsLuQB1I6VXyI3zQvA8Kgvd+ecMY8 0povvnY9jGRcFuFrnc06nawW7WBTk/KifVPdkz7s58y+W/mheps7cAEPp+SdjCP8xB6B qFFRCaOuJdJ1mCPiwwRDFAc32iuy8gID+p2FIg4pcnPnFjC9EyFrKVbYkS4iZQxP1SR6 m54g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.47 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.47]) by mx.google.com with ESMTPS id u20si401999qka.162.2019.06.07.06.37.30 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jun 2019 06:37:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.47 as permitted sender) client-ip=209.51.188.47; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.47 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:51200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hZF3i-0003aG-G1 for alex.bennee@linaro.org; Fri, 07 Jun 2019 09:37:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39624) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hZF3X-0003Pu-3k for qemu-arm@nongnu.org; Fri, 07 Jun 2019 09:37:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hZF3U-0007bQ-Sb for qemu-arm@nongnu.org; Fri, 07 Jun 2019 09:37:19 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:39692) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hZF3S-0007ZT-Sb for qemu-arm@nongnu.org; Fri, 07 Jun 2019 09:37:16 -0400 Received: by mail-wr1-f65.google.com with SMTP id x4so2203464wrt.6 for ; Fri, 07 Jun 2019 06:37:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=BTSgfAfKiPw52zAQi1EVAPSp7Wl8ml8g5jEZmS5OajA=; b=sqZloO36SZNIwBc8ubCc/PAAE02/YWeJGIhcYOy9siPF8Cd/TuOGMqLh10o1eCMzRT GqwPzMH+gsMu3j35kpAPpTKQlbWOg0NBk0SS6c2Ujx+VrYUhALZj1mZp8+oXu3Y0NThK ODQ7UzqE/xSm76qtiGBcuRFHG8o1W/qguW//qZDgmUwwjhoO5jnkQsuZDbiWpEzKPJep d9ctwrrX8FYSm0EH7mFVSU23bLv/pHrlRDVkdGzmaqiGPPEoXxqh4umL84OLxac/s/+o OpoBScbHxR5pkzoaKdpXd/1Ipput4PdVn4VSohmKrKpINCcGWKXziJM7Tc1xuuvvUiYJ 02aQ== X-Gm-Message-State: APjAAAVGbTUFqsUOSSFValblIvH5MWaz921P1CACmjtvbi6kM70Em4XF 5upg8RRpIjMg6TKt+g9dmQ9qjg== X-Received: by 2002:adf:80e1:: with SMTP id 88mr25517544wrl.346.1559914633589; Fri, 07 Jun 2019 06:37:13 -0700 (PDT) Received: from [192.168.0.156] ([78.192.181.46]) by smtp.gmail.com with ESMTPSA id x129sm2631533wmg.44.2019.06.07.06.37.12 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 06:37:13 -0700 (PDT) To: Peter Maydell , qemu-arm@nongnu.org, qemu-devel@nongnu.org References: <20190517174046.11146-1-peter.maydell@linaro.org> <20190517174046.11146-2-peter.maydell@linaro.org> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Openpgp: id=89C1E78F601EE86C867495CBA2A3FD6EDEADC0DE; url=http://pgp.mit.edu/pks/lookup?op=get&search=0xA2A3FD6EDEADC0DE Message-ID: <329c104e-c5b8-2faa-53a5-b89db9b009f9@redhat.com> Date: Fri, 7 Jun 2019 15:37:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190517174046.11146-2-peter.maydell@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.221.65 Subject: Re: [Qemu-arm] [Qemu-devel] [PATCH 1/4] target/arm: Allow VFP and Neon to be disabled via a CPU property X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: CGi+Xt0/H0Ua On 5/17/19 7:40 PM, Peter Maydell wrote: > Allow VFP and neon to be disabled via a CPU property. As with > the "pmu" property, we only allow these features to be removed > from CPUs which have it by default, not added to CPUs which > don't have it. > > The primary motivation here is to be able to optionally > create Cortex-M33 CPUs with no FPU, but we provide switches > for both VFP and Neon because the two interact: > * AArch64 can't have one without the other > * Some ID register fields only change if both are disabled > > Signed-off-by: Peter Maydell > --- > target/arm/cpu.h | 4 ++ > target/arm/cpu.c | 150 +++++++++++++++++++++++++++++++++++++++++++++-- > 2 files changed, 148 insertions(+), 6 deletions(-) > > diff --git a/target/arm/cpu.h b/target/arm/cpu.h > index 733b840a712..778fb293e7c 100644 > --- a/target/arm/cpu.h > +++ b/target/arm/cpu.h > @@ -797,6 +797,10 @@ struct ARMCPU { > bool has_el3; > /* CPU has PMU (Performance Monitor Unit) */ > bool has_pmu; > + /* CPU has VFP */ > + bool has_vfp; > + /* CPU has Neon */ > + bool has_neon; > > /* CPU has memory protection unit */ > bool has_mpu; > diff --git a/target/arm/cpu.c b/target/arm/cpu.c > index 8eee1d8c59a..406fd360a2a 100644 > --- a/target/arm/cpu.c > +++ b/target/arm/cpu.c > @@ -763,6 +763,12 @@ static Property arm_cpu_cfgend_property = > static Property arm_cpu_has_pmu_property = > DEFINE_PROP_BOOL("pmu", ARMCPU, has_pmu, true); > > +static Property arm_cpu_has_vfp_property = > + DEFINE_PROP_BOOL("vfp", ARMCPU, has_vfp, true); > + > +static Property arm_cpu_has_neon_property = > + DEFINE_PROP_BOOL("neon", ARMCPU, has_neon, true); > + > static Property arm_cpu_has_mpu_property = > DEFINE_PROP_BOOL("has-mpu", ARMCPU, has_mpu, true); > > @@ -803,6 +809,13 @@ void arm_cpu_post_init(Object *obj) > if (arm_feature(&cpu->env, ARM_FEATURE_M)) { > set_feature(&cpu->env, ARM_FEATURE_PMSA); > } > + /* Similarly for the VFP feature bits */ > + if (arm_feature(&cpu->env, ARM_FEATURE_VFP4)) { > + set_feature(&cpu->env, ARM_FEATURE_VFP3); > + } > + if (arm_feature(&cpu->env, ARM_FEATURE_VFP3)) { > + set_feature(&cpu->env, ARM_FEATURE_VFP); > + } > > if (arm_feature(&cpu->env, ARM_FEATURE_CBAR) || > arm_feature(&cpu->env, ARM_FEATURE_CBAR_RO)) { > @@ -847,6 +860,27 @@ void arm_cpu_post_init(Object *obj) > &error_abort); > } > > + /* > + * Allow user to turn off VFP and Neon support, but only for TCG -- > + * KVM does not currently allow us to lie to the guest about its > + * ID/feature registers, so the guest always sees what the host has. > + */ I wondered about that last week when refreshing Samuel TCG/KVM split, because the VFP code pulls a lot of unnecessary code on KVM (in particular the softfloat lib). > + if (arm_feature(&cpu->env, ARM_FEATURE_VFP)) { > + cpu->has_vfp = true; > + if (!kvm_enabled()) { > + qdev_property_add_static(DEVICE(obj), &arm_cpu_has_vfp_property, > + &error_abort); > + } > + } > + > + if (arm_feature(&cpu->env, ARM_FEATURE_NEON)) { > + cpu->has_neon = true; > + if (!kvm_enabled()) { > + qdev_property_add_static(DEVICE(obj), &arm_cpu_has_neon_property, > + &error_abort); > + } > + } > + > if (arm_feature(&cpu->env, ARM_FEATURE_PMSA)) { > qdev_property_add_static(DEVICE(obj), &arm_cpu_has_mpu_property, > &error_abort); > @@ -956,6 +990,116 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) > return; > } > > + if (arm_feature(env, ARM_FEATURE_AARCH64) && > + cpu->has_vfp != cpu->has_neon) { > + /* > + * This is an architectural requirement for AArch64; AArch32 is > + * more flexible and permits VFP-no-Neon and Neon-no-VFP. > + */ > + error_setg(errp, > + "AArch64 CPUs must have both VFP and Neon or neither"); > + return; > + } > + > + if (!cpu->has_vfp) { > + uint64_t t; > + uint32_t u; > + > + unset_feature(env, ARM_FEATURE_VFP); > + unset_feature(env, ARM_FEATURE_VFP3); > + unset_feature(env, ARM_FEATURE_VFP4); > + > + t = cpu->isar.id_aa64isar1; > + t = FIELD_DP64(t, ID_AA64ISAR1, JSCVT, 0); > + cpu->isar.id_aa64isar1 = t; > + > + t = cpu->isar.id_aa64pfr0; > + t = FIELD_DP64(t, ID_AA64PFR0, FP, 0xf); > + cpu->isar.id_aa64pfr0 = t; > + > + u = cpu->isar.id_isar6; > + u = FIELD_DP32(u, ID_ISAR6, JSCVT, 0); > + cpu->isar.id_isar6 = u; > + > + u = cpu->isar.mvfr0; > + u = FIELD_DP32(u, MVFR0, FPSP, 0); > + u = FIELD_DP32(u, MVFR0, FPDP, 0); > + u = FIELD_DP32(u, MVFR0, FPTRAP, 0); > + u = FIELD_DP32(u, MVFR0, FPDIVIDE, 0); > + u = FIELD_DP32(u, MVFR0, FPSQRT, 0); > + u = FIELD_DP32(u, MVFR0, FPSHVEC, 0); > + u = FIELD_DP32(u, MVFR0, FPROUND, 0); > + cpu->isar.mvfr0 = u; > + > + u = cpu->isar.mvfr1; > + u = FIELD_DP32(u, MVFR1, FPFTZ, 0); > + u = FIELD_DP32(u, MVFR1, FPDNAN, 0); > + u = FIELD_DP32(u, MVFR1, FPHP, 0); > + cpu->isar.mvfr1 = u; > + > + u = cpu->isar.mvfr2; > + u = FIELD_DP32(u, MVFR2, FPMISC, 0); > + cpu->isar.mvfr2 = u; > + } > + > + if (!cpu->has_neon) { > + uint64_t t; > + uint32_t u; > + > + unset_feature(env, ARM_FEATURE_NEON); > + > + t = cpu->isar.id_aa64isar0; > + t = FIELD_DP64(t, ID_AA64ISAR0, DP, 0); > + cpu->isar.id_aa64isar0 = t; > + > + t = cpu->isar.id_aa64isar1; > + t = FIELD_DP64(t, ID_AA64ISAR1, FCMA, 0); > + cpu->isar.id_aa64isar1 = t; > + > + t = cpu->isar.id_aa64pfr0; > + t = FIELD_DP64(t, ID_AA64PFR0, ADVSIMD, 0xf); > + cpu->isar.id_aa64pfr0 = t; > + > + u = cpu->isar.id_isar5; > + u = FIELD_DP32(u, ID_ISAR5, RDM, 0); > + u = FIELD_DP32(u, ID_ISAR5, VCMA, 0); > + cpu->isar.id_isar5 = u; > + > + u = cpu->isar.id_isar6; > + u = FIELD_DP32(u, ID_ISAR6, DP, 0); > + u = FIELD_DP32(u, ID_ISAR6, FHM, 0); > + cpu->isar.id_isar6 = u; > + > + u = cpu->isar.mvfr1; > + u = FIELD_DP32(u, MVFR1, SIMDLS, 0); > + u = FIELD_DP32(u, MVFR1, SIMDINT, 0); > + u = FIELD_DP32(u, MVFR1, SIMDSP, 0); > + u = FIELD_DP32(u, MVFR1, SIMDHP, 0); > + u = FIELD_DP32(u, MVFR1, SIMDFMAC, 0); > + cpu->isar.mvfr1 = u; > + > + u = cpu->isar.mvfr2; > + u = FIELD_DP32(u, MVFR2, SIMDMISC, 0); > + cpu->isar.mvfr2 = u; > + } > + > + if (!cpu->has_neon && !cpu->has_vfp) { > + uint64_t t; > + uint32_t u; > + > + t = cpu->isar.id_aa64isar0; > + t = FIELD_DP64(t, ID_AA64ISAR0, FHM, 0); > + cpu->isar.id_aa64isar0 = t; > + > + t = cpu->isar.id_aa64isar1; > + t = FIELD_DP64(t, ID_AA64ISAR1, FRINTTS, 0); > + cpu->isar.id_aa64isar1 = t; > + > + u = cpu->isar.mvfr0; > + u = FIELD_DP32(u, MVFR0, SIMDREG, 0); > + cpu->isar.mvfr0 = u; > + } > + > /* Some features automatically imply others: */ > if (arm_feature(env, ARM_FEATURE_V8)) { > if (arm_feature(env, ARM_FEATURE_M)) { > @@ -1016,12 +1160,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) > if (arm_feature(env, ARM_FEATURE_V5)) { > set_feature(env, ARM_FEATURE_V4T); > } > - if (arm_feature(env, ARM_FEATURE_VFP4)) { > - set_feature(env, ARM_FEATURE_VFP3); > - } > - if (arm_feature(env, ARM_FEATURE_VFP3)) { > - set_feature(env, ARM_FEATURE_VFP); > - } > if (arm_feature(env, ARM_FEATURE_LPAE)) { > set_feature(env, ARM_FEATURE_V7MP); > set_feature(env, ARM_FEATURE_PXN); > I really like the *_feature() API, it is very clean and powerful. Reviewed-by: Philippe Mathieu-Daudé