From nobody Tue Feb 10 20:28:39 2026 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1694597502; cv=none; d=zohomail.com; s=zohoarc; b=Q+ea25daLTpzdikmJqiamYibFb7HtESM62q+dOhB9itfvT5nNKSKt+YJqqW6SdbMFblb2HzWW0059v4vklS/sdJNXf4zeWMO81nNPfhJMCVoC9VexeqkVJd/H1BBzImjPFv9AryBi1iPvl6NG97n4BNJIySbU1q/Kk7wIgSh3Rs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694597502; 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=ZR4T6NlMHpArLYrHIDyBj0HhdFN73kI81RfJc3c6SLI=; b=Q0rIbd013qJXRC3HjjrBhbmT5z+tts+fA8ppSA6eWfFEVCtOoorpPMisJFru4eRc8DGr/g7P/Um20bsct4yEqjV68CE8JU9CiXnedrpUv8wavfdIXAdKBljznC7p4snS2LzRweLRI97hgWbnvdzA+JkWnJB5dNmb6/7dGOI/gnc= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694597502246891.1335001576567; Wed, 13 Sep 2023 02:31:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgMCn-0001BH-3s; Wed, 13 Sep 2023 05:30:41 -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 1qgMCl-00017A-56 for qemu-devel@nongnu.org; Wed, 13 Sep 2023 05:30:39 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgMCf-0002Fx-H1 for qemu-devel@nongnu.org; Wed, 13 Sep 2023 05:30:37 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-401f68602a8so71489345e9.3 for ; Wed, 13 Sep 2023 02:30:32 -0700 (PDT) Received: from m1x-phil.lan (176-131-211-241.abo.bbox.fr. [176.131.211.241]) by smtp.gmail.com with ESMTPSA id r6-20020a05600c35c600b003fbe791a0e8sm1540652wmq.0.2023.09.13.02.30.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 13 Sep 2023 02:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694597431; x=1695202231; darn=nongnu.org; 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=ZR4T6NlMHpArLYrHIDyBj0HhdFN73kI81RfJc3c6SLI=; b=U0kVmcAyBcPfz8zmlCOxGeiDx+utKPLhh/aADnihlIvJLH5dA+vIEOewQkKrKhLcan jqkoZDYizJuuccbvRoEJj89nnSc6VhiGStwXuXbqDZHfZcdrMq1+bhmdarlLYA4ropYH SkwBiX9m6ha5TEGuwXqrEpgibyGKf12Rw5pMVJx2GrtYshfkbx0uHNIlWF/cGrZv4X4I bUh4oBbqlVtz9MoUcXmb+jeMvbS3TvioQ0vLo5qH++yepHVpQRJsQrsrkOIs+7YjTeEX D8Ceklef0p+aCYPZvufmFkCw0vJby4VELwYSsA6D564jhNlXQ70fTSpitT5TZiKv5qpH eZmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694597431; x=1695202231; 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=ZR4T6NlMHpArLYrHIDyBj0HhdFN73kI81RfJc3c6SLI=; b=s1HUbrbn7t5wyNReFDarEHDqzJ4EfcuDMfQMbPkn3NZeeCncyFHGvogmndyoLvwjFI /yMnkfbhK6J0VM9i13xjvDZN+ZvCl7DDbInK+Uec3HVIJXlGrSzCKoXmJ5JAdz8qRxSR 847kQGmmWiTQyJPapUEE19Dn/Dw22BQkfcr1Pdjyh0YGvc+LcI6lXOFO/hYlIwODhvaf obYzaI4ilc5espL49eHAzpYBTAAkZ+kyTQzyQtUucaAX1b4TEYTdr1UOUU4M1Ej0U2Dv UEUly03n13qxKMsXSD8kEAyRXK4Uod5XpklYITpgcEhu3GgDuhWmV9cn1z90tWYJ1A1Y 0ohg== X-Gm-Message-State: AOJu0YzzKrY4sb2dT1sVaGyPw21vEoDvI9hdN7hWPs0ld8ki5tizHEEl jBePYfnfyW67V1bxCyKH3EJu3aL3l/ATagoAzVg= X-Google-Smtp-Source: AGHT+IEuMwkotR/4nuJtdSguECUmUFieAMVw4UlYscziVUebi6jxfT7Sful3RnFPx8QmcRQyElHHxA== X-Received: by 2002:a1c:7212:0:b0:401:c636:8f4c with SMTP id n18-20020a1c7212000000b00401c6368f4cmr1628404wmc.3.1694597430942; Wed, 13 Sep 2023 02:30:30 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , kvm@vger.kernel.org, Paolo Bonzini , Stefan Hajnoczi , Michael Tokarev , Kevin Wolf , Richard Henderson , Daniel Henrique Barboza , Marcelo Tosatti , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org Subject: [PATCH v5 3/6] target/i386: Call accel-agnostic x86_cpu_get_supported_cpuid() Date: Wed, 13 Sep 2023 11:30:05 +0200 Message-ID: <20230913093009.83520-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230913093009.83520-1-philmd@linaro.org> References: <20230913093009.83520-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.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=unavailable 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 @linaro.org) X-ZM-MESSAGEID: 1694597502730100001 x86_cpu_get_supported_cpuid() is generic and handles the different accelerators. Use it instead of kvm_arch_get_supported_cpuid(). That fixes a link failure introduced by commit 3adce820cf ("target/i386: Remove unused KVM stubs") when QEMU is configured as: $ ./configure --cc=3Dclang \ --target-list=3Dx86_64-linux-user,x86_64-softmmu \ --enable-debug We were getting: [71/71] Linking target qemu-x86_64 FAILED: qemu-x86_64 /usr/bin/ld: libqemu-x86_64-linux-user.fa.p/target_i386_cpu.c.o: in funct= ion `cpu_x86_cpuid': cpu.c:(.text+0x1374): undefined reference to `kvm_arch_get_supported_cpui= d' /usr/bin/ld: libqemu-x86_64-linux-user.fa.p/target_i386_cpu.c.o: in funct= ion `x86_cpu_filter_features': cpu.c:(.text+0x81c2): undefined reference to `kvm_arch_get_supported_cpui= d' /usr/bin/ld: cpu.c:(.text+0x81da): undefined reference to `kvm_arch_get_s= upported_cpuid' /usr/bin/ld: cpu.c:(.text+0x81f2): undefined reference to `kvm_arch_get_s= upported_cpuid' /usr/bin/ld: cpu.c:(.text+0x820a): undefined reference to `kvm_arch_get_s= upported_cpuid' /usr/bin/ld: libqemu-x86_64-linux-user.fa.p/target_i386_cpu.c.o:cpu.c:(.t= ext+0x8225): more undefined references to `kvm_arch_get_supported_cpuid' fo= llow clang: error: linker command failed with exit code 1 (use -v to see invoc= ation) ninja: build stopped: subcommand failed. For the record, this is because '--enable-debug' disables optimizations (CFLAGS=3D-O0). While at this (un)optimization level GCC eliminate the following dead code (CPP output of mentioned build): static void x86_cpu_get_supported_cpuid(uint32_t func, uint32_t index, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { if ((0)) { *eax =3D kvm_arch_get_supported_cpuid(kvm_state, func, index, R_EA= X); *ebx =3D kvm_arch_get_supported_cpuid(kvm_state, func, index, R_EB= X); *ecx =3D kvm_arch_get_supported_cpuid(kvm_state, func, index, R_EC= X); *edx =3D kvm_arch_get_supported_cpuid(kvm_state, func, index, R_ED= X); } else if (0) { *eax =3D 0; *ebx =3D 0; *ecx =3D 0; *edx =3D 0; } else { *eax =3D 0; *ebx =3D 0; *ecx =3D 0; *edx =3D 0; } Clang does not (see commit 2140cfa51d "i386: Fix build by providing stub kvm_arch_get_supported_cpuid()"). Cc: qemu-stable@nongnu.org Fixes: 3adce820cf ("target/i386: Remove unused KVM stubs") Reported-by: Kevin Wolf Suggested-by: Paolo Bonzini Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- target/i386/cpu.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 94b1ba0cf1..b2a20365e1 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6154,6 +6154,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, case 7: /* Structured Extended Feature Flags Enumeration Leaf */ if (count =3D=3D 0) { + uint32_t eax_0_unused, ebx_0, ecx_0, edx_0_unused; + /* Maximum ECX value for sub-leaves */ *eax =3D env->cpuid_level_func7; *ebx =3D env->features[FEAT_7_0_EBX]; /* Feature flags */ @@ -6168,17 +6170,15 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, * support enabling SGX and/or SGX flexible launch control, * then we need to update the VM's CPUID values accordingly. */ - if ((*ebx & CPUID_7_0_EBX_SGX) && - (!kvm_enabled() || - !(kvm_arch_get_supported_cpuid(cs->kvm_state, 0x7, 0, R_E= BX) & - CPUID_7_0_EBX_SGX))) { + x86_cpu_get_supported_cpuid(0x7, 0, + &eax_0_unused, &ebx_0, + &ecx_0, &edx_0_unused); + if ((*ebx & CPUID_7_0_EBX_SGX) && !(ebx_0 & CPUID_7_0_EBX_SGX)= ) { *ebx &=3D ~CPUID_7_0_EBX_SGX; } =20 - if ((*ecx & CPUID_7_0_ECX_SGX_LC) && - (!(*ebx & CPUID_7_0_EBX_SGX) || !kvm_enabled() || - !(kvm_arch_get_supported_cpuid(cs->kvm_state, 0x7, 0, R_E= CX) & - CPUID_7_0_ECX_SGX_LC))) { + if ((*ecx & CPUID_7_0_ECX_SGX_LC) + && (!(*ebx & CPUID_7_0_EBX_SGX) || !(ecx_0 & CPUID_7_0= _ECX_SGX_LC))) { *ecx &=3D ~CPUID_7_0_ECX_SGX_LC; } } else if (count =3D=3D 1) { @@ -7150,14 +7150,14 @@ static void x86_cpu_filter_features(X86CPU *cpu, bo= ol verbose) mark_unavailable_features(cpu, w, unavailable_features, prefix); } =20 - if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) && - kvm_enabled()) { - KVMState *s =3D CPU(cpu)->kvm_state; - uint32_t eax_0 =3D kvm_arch_get_supported_cpuid(s, 0x14, 0, R_EAX); - uint32_t ebx_0 =3D kvm_arch_get_supported_cpuid(s, 0x14, 0, R_EBX); - uint32_t ecx_0 =3D kvm_arch_get_supported_cpuid(s, 0x14, 0, R_ECX); - uint32_t eax_1 =3D kvm_arch_get_supported_cpuid(s, 0x14, 1, R_EAX); - uint32_t ebx_1 =3D kvm_arch_get_supported_cpuid(s, 0x14, 1, R_EBX); + if (env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) { + uint32_t eax_0, ebx_0, ecx_0, edx_0_unused; + uint32_t eax_1, ebx_1, ecx_1_unused, edx_1_unused; + + x86_cpu_get_supported_cpuid(0x14, 0, + &eax_0, &ebx_0, &ecx_0, &edx_0_unused); + x86_cpu_get_supported_cpuid(0x14, 1, + &eax_1, &ebx_1, &ecx_1_unused, &edx_1_= unused); =20 if (!eax_0 || ((ebx_0 & INTEL_PT_MINIMAL_EBX) !=3D INTEL_PT_MINIMAL_EBX) || --=20 2.41.0