From patchwork Wed Sep 13 09:30:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 722119 Delivered-To: patch@linaro.org Received: by 2002:a5d:4387:0:b0:31d:da82:a3b4 with SMTP id i7csp192581wrq; Wed, 13 Sep 2023 02:31:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7UcDEwCCePLKGtyzMdx52KcqfqJHRWLVIGd2d/K8pOGC+4WMlyZKdsO1DxmIad5qYCOf3 X-Received: by 2002:ad4:4a70:0:b0:647:122f:84ee with SMTP id cn16-20020ad44a70000000b00647122f84eemr1884673qvb.56.1694597502000; Wed, 13 Sep 2023 02:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694597501; cv=none; d=google.com; s=arc-20160816; b=lBwNk5lp3oJgC3Q5PGvBKg2VTS5bG5hBCpnI10uOYainckFIgJM2HA55MDPbgBrhmF 7CJqugwGzTpK0vX9sjTBkTOXXMs2dCfyFQVx4nIHF0edlTMPWWI+AStH0pNPE0Qvrd5E yR71nN4uBO6hRG2AUQPGLvg/ua4TXwFkHzris5A3eH6yaKoSn5TpAOH+6W9IhjaPcnmA Sbw4B8UmQjbXDjsvlbi5PW+wcOXlpDyfayiEjdTcYIcO3a9GgpeLzEKn+O3GozC+vZzr PvYd4xoVOZYzpTCm1wTcxaaO1gGc+Qu6DeRY1Jk2rUs7gzh0GBIgnMhHobw4sEUppReH kW9Q== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZR4T6NlMHpArLYrHIDyBj0HhdFN73kI81RfJc3c6SLI=; fh=Tcvj3E2v34C1uTif5zEEStTNZmONfYtXvHGBHAnde9s=; b=mSOzBPF2lduXnTJ2rhJtMUlTlu34NCR1rPsTafza9eRlG7csFfyDE7SEX8m0vv6qos XjxlrQzoDZ8LGDYp1ZLac32rISsOq5DFaFfqqxg1fpD+yOblc2svlIdaWqzBIRG1v3iA IWghQQnVvI7UB8i5vJVaNi6b3EJO5jbQJjjtnWRWLAHRJisKyDCYfUAnQQJ1Ki6z2HOX H9utPtYrKAz+7ITnd9Ep34DBoatFF7b7lTNcJVWG/nhubSACGsv/h64riG9+t8MIjqe8 HFp5prKoHl8r/+fEpxGnW4vAirqkG9lYl2Q6CsahS0L34fwgn1ZiKqz6wvNAad5hRRxD 4yow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U0kVmcAy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t8-20020a0cef08000000b00655dd867231si4987095qvr.104.2023.09.13.02.31.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Sep 2023 02:31:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U0kVmcAy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=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_Mathieu-Daud?= =?utf-8?q?=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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=clang \ --target-list=x86_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 function `cpu_x86_cpuid': cpu.c:(.text+0x1374): undefined reference to `kvm_arch_get_supported_cpuid' /usr/bin/ld: libqemu-x86_64-linux-user.fa.p/target_i386_cpu.c.o: in function `x86_cpu_filter_features': cpu.c:(.text+0x81c2): undefined reference to `kvm_arch_get_supported_cpuid' /usr/bin/ld: cpu.c:(.text+0x81da): undefined reference to `kvm_arch_get_supported_cpuid' /usr/bin/ld: cpu.c:(.text+0x81f2): undefined reference to `kvm_arch_get_supported_cpuid' /usr/bin/ld: cpu.c:(.text+0x820a): undefined reference to `kvm_arch_get_supported_cpuid' /usr/bin/ld: libqemu-x86_64-linux-user.fa.p/target_i386_cpu.c.o:cpu.c:(.text+0x8225): more undefined references to `kvm_arch_get_supported_cpuid' follow clang: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed. For the record, this is because '--enable-debug' disables optimizations (CFLAGS=-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 = kvm_arch_get_supported_cpuid(kvm_state, func, index, R_EAX); *ebx = kvm_arch_get_supported_cpuid(kvm_state, func, index, R_EBX); *ecx = kvm_arch_get_supported_cpuid(kvm_state, func, index, R_ECX); *edx = kvm_arch_get_supported_cpuid(kvm_state, func, index, R_EDX); } else if (0) { *eax = 0; *ebx = 0; *ecx = 0; *edx = 0; } else { *eax = 0; *ebx = 0; *ecx = 0; *edx = 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é --- 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 == 0) { + uint32_t eax_0_unused, ebx_0, ecx_0, edx_0_unused; + /* Maximum ECX value for sub-leaves */ *eax = env->cpuid_level_func7; *ebx = 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_EBX) & - 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 &= ~CPUID_7_0_EBX_SGX; } - 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_ECX) & - 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 &= ~CPUID_7_0_ECX_SGX_LC; } } else if (count == 1) { @@ -7150,14 +7150,14 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool verbose) mark_unavailable_features(cpu, w, unavailable_features, prefix); } - if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) && - kvm_enabled()) { - KVMState *s = CPU(cpu)->kvm_state; - uint32_t eax_0 = kvm_arch_get_supported_cpuid(s, 0x14, 0, R_EAX); - uint32_t ebx_0 = kvm_arch_get_supported_cpuid(s, 0x14, 0, R_EBX); - uint32_t ecx_0 = kvm_arch_get_supported_cpuid(s, 0x14, 0, R_ECX); - uint32_t eax_1 = kvm_arch_get_supported_cpuid(s, 0x14, 1, R_EAX); - uint32_t ebx_1 = 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); if (!eax_0 || ((ebx_0 & INTEL_PT_MINIMAL_EBX) != INTEL_PT_MINIMAL_EBX) ||