I went through a situation where a developer attempted to enable an
extension X when using a vendor CPU, and he got shutdown by the "<name>
CPU does not allow enabling extensions" message. I explained that he
couldn't run this simple test using a vendor CPU because, by doing so,
the vendor CPU is no longer the vendor CPU. As a reply I got "yes, I am
aware of that, I am explicitly adding X to it in the command line". I
then elaborated that an alternative would be to use rv64i and add each
CPU extension manually in the cmd line, or maybe use 'rv64' or 'max' CPU
and enable/disable a bunch of stuff to match the vendor CPU + X. And I
felt annoyed by my own explanation.

The distinction between vendor CPU and generic CPUs goes back 3-4 years.
Back then every new extension added in QEMU was also being enabled in
the 'rv64' CPU, along with validation logic to enable more extensions as
dependencies, and vendor CPUs of that time were being affected by it.
Guardrails were added to prevent vendor CPUs from changing due to the
influx of new exts added in rv64.

The code is more mature and stable now and I believe the concept of
vendor vs generic CPUs is no longer needed. We could get rid of the
distinction altogether, treat rv64 as a vendor CPU with all its current
extensions enabled by default, and every CPU can do anything. Users can
then have full control of the CPU they want to use and we'll have less
code to deal with.

A lot of refactor and code juggling will be required before making that
happen though. For now let's allow vendor CPUs to enable extensions.
We're keeping all other restrictions in place (pmp, mmu, vlen, block
sizes ...) because each restriction lifted can have side effects and
should be handled separately.

Signed-off-by: Daniel Henrique Barboza <[email protected]>
---
 target/riscv/tcg/tcg-cpu.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index d3968251fa..122b8b52a7 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -1478,7 +1478,6 @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor 
*v, const char *name,
 {
     const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque;
     RISCVCPU *cpu = RISCV_CPU(obj);
-    bool vendor_cpu = riscv_cpu_is_vendor(obj);
     bool prev_val, value;
 
     if (!visit_type_bool(v, name, &value, errp)) {
@@ -1493,13 +1492,6 @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor 
*v, const char *name,
         return;
     }
 
-    if (value && vendor_cpu) {
-        g_autofree char *cpuname = riscv_cpu_get_name(cpu);
-        error_setg(errp, "'%s' CPU does not allow enabling extensions",
-                   cpuname);
-        return;
-    }
-
     if (value) {
         cpu_bump_multi_ext_priv_ver(&cpu->env, multi_ext_cfg->offset);
     }
-- 
2.51.1


Reply via email to