From nobody Thu Nov 14 07:15:00 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 ARC-Seal: i=1; a=rsa-sha256; t=1692139138; cv=none; d=zohomail.com; s=zohoarc; b=aMeGUdQ3YXzCxCheTXnH1ANA6fClacg0oP1+nKlx0uQqjNfys4JtGvtwIHCVh6FAVmMSqFQgekK/OYUBtOc1u8eLGnUy7OZ4yt1Vev6V9XNWj4MvC6Cce1dP6tuvCjxi71hrd6nCp7nQod86ahVBCHTQ0u2juX57vZydKXLl8H4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692139138; h=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=HKxo5YuCZUjw8nEJxLWI8Q+BuLO4vaQHkEhOsQ8xDE0=; b=CBnWc40G4j1AbvND35Cr1EYsB73MHkm3H+SZi/tyNod0nHf0Ogi5cktrjsOREXjdbojUVMegdrjc0z1o3l+uWHslFgMSpdewTngxd7PQAYM/3zt2Kw1fKERR3G/KbKHX2SiwXHzf3Fa2vRNb7SO5gSxgeFS5kLcfVD0eParTI50= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692139138261953.5885360688573; Tue, 15 Aug 2023 15:38:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qW2fs-0004qi-O3; Tue, 15 Aug 2023 18:38:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qW2fq-0004q3-OR for qemu-devel@nongnu.org; Tue, 15 Aug 2023 18:38:02 -0400 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qW2fn-00067W-Bq for qemu-devel@nongnu.org; Tue, 15 Aug 2023 18:38:02 -0400 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3a7aedc57ffso4613691b6e.2 for ; Tue, 15 Aug 2023 15:37:58 -0700 (PDT) Received: from grind.. (189-69-160-189.dial-up.telesp.net.br. [189.69.160.189]) by smtp.gmail.com with ESMTPSA id be15-20020a056808218f00b003a40b3fce01sm5903418oib.10.2023.08.15.15.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 15:37:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1692139078; x=1692743878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HKxo5YuCZUjw8nEJxLWI8Q+BuLO4vaQHkEhOsQ8xDE0=; b=LLEcLBfR4nYoIkaeN70AUS2oKQeb5NoUB22Wau3Lrcc02o7mGFG+a6KjluFf7Ifb/q y6CauNefmQ+u79fIiDg6WtT4ZQVzAXIGavuqWMX0/nQmO8RWKZxhrUI+RkKhvnzUBlT/ 1MvwwtTUWy94r4KAy2Z3UJfJcb0Ou+gNVKXQ0kZWVOLxPUqwyBtVUUnKLBJCPiQD6Y3y KuTsqw+yEfAbMpbjwsKx13Qp7GcpBP5orAvzm5CIkCjIjBymL3x0rh6jkln6SGq0itqy AnnMp3KjtdHMbD6S55HBf/JommymXyLGomC2hYe7UG15KSSZc2kq44n72NtI59JdVOHS sZEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692139078; x=1692743878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HKxo5YuCZUjw8nEJxLWI8Q+BuLO4vaQHkEhOsQ8xDE0=; b=IuJf1UUEUqoS/VfWsCZe51gctFR9Kztqt/2vi3Y1MTgkilE3NJu5buJZtiBFsnZy9o MDg0M5Ng82GOvgmOsLgyb4kPOVgCoz+pvf4KPJi5dwHwEOjSreTigCYFi/QSZclc9aJF y350Gh+eJOzWo4eY0UYDXzX9lvwzK9L7CemzUYBGglHjU1ZyIvF3IubXv+SI4rCNtDE1 3CtNOpel3K/6R9c8u+Yp1eY6tbP+6UrygRrdwxPjukxQUl5MZOO+V69BWnb1t8K4wYyF b4uugyjjrXftiXzeCUNijpBzEyVIS3ywqW1ZcTP+v8KqvpKnTQy0meebciLQFP/Y4OqD aPrg== X-Gm-Message-State: AOJu0YxvVB5J6Hxodrvcna6tw+NxAfFmGPUYCkS8u/yhzabe00+eJIYd RpQTh02kN9uep66MXDnS7TyeVAyuNM4KyQVtyeM= X-Google-Smtp-Source: AGHT+IGc0Xhb3RIqACyDhf4xBdspDRJECTbPkQKhsUngL0xFxlhyZj2r9LjXdqzPgPvAun9/VIFIfQ== X-Received: by 2002:a05:6808:209a:b0:3a7:b5ea:f5e5 with SMTP id s26-20020a056808209a00b003a7b5eaf5e5mr93572oiw.10.1692139077847; Tue, 15 Aug 2023 15:37:57 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v8 03/12] target/riscv/cpu.c: split kvm prop handling to its own helper Date: Tue, 15 Aug 2023 19:37:32 -0300 Message-ID: <20230815223741.433763-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230815223741.433763-1-dbarboza@ventanamicro.com> References: <20230815223741.433763-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 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=2607:f8b0:4864:20::235; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x235.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1692139140126100003 Content-Type: text/plain; charset="utf-8" Future patches will split the existing Property arrays even further, and the existing code in riscv_cpu_add_user_properties() will start to scale bad with it because it's dealing with KVM constraints mixed in with TCG constraints. We're going to pay a high price to share a couple of common lines of code between the two. Create a new riscv_cpu_add_kvm_properties() that will be forked from riscv_cpu_add_user_properties() if we're running KVM. The helper includes all properties that a KVM CPU will add. The rest of riscv_cpu_add_user_properties() body will then be relieved from having to deal with KVM constraints. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Weiwei Li Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 65 ++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index f10d40733a..7f0852a14e 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1874,6 +1874,46 @@ static void cpu_set_cfg_unavailable(Object *obj, Vis= itor *v, } #endif =20 +#ifndef CONFIG_USER_ONLY +static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_n= ame) +{ + /* Check if KVM created the property already */ + if (object_property_find(obj, prop_name)) { + return; + } + + /* + * Set the default to disabled for every extension + * unknown to KVM and error out if the user attempts + * to enable any of them. + */ + object_property_add(obj, prop_name, "bool", + NULL, cpu_set_cfg_unavailable, + NULL, (void *)prop_name); +} + +static void riscv_cpu_add_kvm_properties(Object *obj) +{ + Property *prop; + DeviceState *dev =3D DEVICE(obj); + + kvm_riscv_init_user_properties(obj); + riscv_cpu_add_misa_properties(obj); + + for (prop =3D riscv_cpu_extensions; prop && prop->name; prop++) { + riscv_cpu_add_kvm_unavail_prop(obj, prop->name); + } + + for (int i =3D 0; i < ARRAY_SIZE(riscv_cpu_options); i++) { + /* Check if KVM created the property already */ + if (object_property_find(obj, riscv_cpu_options[i].name)) { + continue; + } + qdev_property_add_static(dev, &riscv_cpu_options[i]); + } +} +#endif + /* * Add CPU properties with user-facing flags. * @@ -1889,39 +1929,18 @@ static void riscv_cpu_add_user_properties(Object *o= bj) riscv_add_satp_mode_properties(obj); =20 if (kvm_enabled()) { - kvm_riscv_init_user_properties(obj); + riscv_cpu_add_kvm_properties(obj); + return; } #endif =20 riscv_cpu_add_misa_properties(obj); =20 for (prop =3D riscv_cpu_extensions; prop && prop->name; prop++) { -#ifndef CONFIG_USER_ONLY - if (kvm_enabled()) { - /* Check if KVM created the property already */ - if (object_property_find(obj, prop->name)) { - continue; - } - - /* - * Set the default to disabled for every extension - * unknown to KVM and error out if the user attempts - * to enable any of them. - */ - object_property_add(obj, prop->name, "bool", - NULL, cpu_set_cfg_unavailable, - NULL, (void *)prop->name); - continue; - } -#endif qdev_property_add_static(dev, prop); } =20 for (int i =3D 0; i < ARRAY_SIZE(riscv_cpu_options); i++) { - /* Check if KVM created the property already */ - if (object_property_find(obj, riscv_cpu_options[i].name)) { - continue; - } qdev_property_add_static(dev, &riscv_cpu_options[i]); } } --=20 2.41.0