From patchwork Mon Sep 11 21:13:15 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: 721471 Delivered-To: patch@linaro.org Received: by 2002:adf:f64d:0:b0:31d:da82:a3b4 with SMTP id x13csp1314188wrp; Mon, 11 Sep 2023 14:14:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHifVx10W4PNBxqFJL4OSPxeM++ffYqPBnV70N/+Arxd4s/TPQl+6ijOX7yZBM4d/th3BTe X-Received: by 2002:a05:620a:4545:b0:76f:a86:65b6 with SMTP id u5-20020a05620a454500b0076f0a8665b6mr12890109qkp.63.1694466880080; Mon, 11 Sep 2023 14:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694466880; cv=none; d=google.com; s=arc-20160816; b=sCuw2exf9HjNFvnIiu97PJ29OeeYGWKhMOKIuOo500y+mQiST8ueAIfdaJ3Kz8Ila/ suBZZF0d5w470hi5SoXOxLOE+aN6nwrDHECqwHv3YslMuTz4UDn0VBfCol30AFQYpORu qSPpSypeS4Azs0P1q//dFEdeu4NpCXInuQYuhEsP96sPei8JWDWbE++AXuNyKNPKcQpm dLiAddJzPzbzaG+1UVZKZm0OO36aVZt4L3YM99DjWYH+E0JvBS1htj2cLtnWLpnj91S9 ro7QmDbXNl93cnI/Uu3DQVQMMDBxrYyxlMUBjTAocuSySz0hjB5q2PVz0riwXSxKSbFL OzbQ== 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=krYgPPa35VQ/Pn0yOr01dbPDQetUwcBiBN86SxBA8xI=; fh=L5lG5N3YOEji5IZHrCtpjOPIXLZd9oK5uWbK9avwmpY=; b=I2Q5VAklFKRwkq5RJEt8gUsHkrd0er48d14PTktFv1ye5Miwu848lqig45ePVr8Sk0 C50iQ1w+9NdfkIZ4nG+2qVPRqJifkTL8HsybG4KtAqioNqz8y2Z9Ky/5H7NIGxbuS911 vr/Do3kXOBqa6vrLWRCZrp4VrOpvfk6vOIGf1tGHO3ul9Kwo2Nq/E00cWdN66YQUXCTw HwCkBARFxdW/Tt+X2bW7UMuv8/mhteGrygkuzYBB/Shw2PJDL0D8DKWwvh3OkSzTHHTA 6aoqGnr+HnSvWAD77MhCLPBE80r9nw3MTj2uYL7Ypp/SXieJ5zPu+2y+JoAHnJ2jyWCf JmJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DMmtUxDc; 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 v24-20020a05620a0a9800b0076cd8dab5cfsi5187419qkg.190.2023.09.11.14.14.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Sep 2023 14:14:40 -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=DMmtUxDc; 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 1qfoDs-0003dL-1O; Mon, 11 Sep 2023 17:13:32 -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 1qfoDr-0003dB-77 for qemu-devel@nongnu.org; Mon, 11 Sep 2023 17:13:31 -0400 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfoDp-0005Bv-01 for qemu-devel@nongnu.org; Mon, 11 Sep 2023 17:13:30 -0400 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-991c786369cso653480066b.1 for ; Mon, 11 Sep 2023 14:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694466807; x=1695071607; 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=krYgPPa35VQ/Pn0yOr01dbPDQetUwcBiBN86SxBA8xI=; b=DMmtUxDc4vdYzacIveds67u34/IpRIDo/8oqLJ4rntX5q3yUoDQdtUVmWmVbdQF4gJ 11AbQPvobLU1+RwugK5iU3rTx9cR0oBcLposNprkuGqnBPwkRsbKJyC8DJSu7HNqYXLL 4mInct+0A3iswXezTIkTAO1MQmjabcIgdhIH2w0iZAZggqQ4toSFO7J5E8H+yD8maMtO RBYE7iAybRjIcDXOZkAP1NEn58vuEJ4FYZRhweklYu3SIN7e5x+1mBXBjURE89lKF2eD r7A0b3QM/Sl/d2RwKTPr4KBlMBmx7350ZQSaq2t/Cf6BRBJJOCQLeVa5O0z0ZTcBoBIq syOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694466807; x=1695071607; 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=krYgPPa35VQ/Pn0yOr01dbPDQetUwcBiBN86SxBA8xI=; b=ZGpQn0Q60p/araBM9xR181vtpbUSOgc2UKItS6Sq5J4elI10q+T5Gopdy4v+zksQTY 6j8t27MRzwyeSW0MVSb15aB7OgH2HDikvDR3dcvu9eHl/DNFoK706I9CyXf7rFMNZPM+ +HlHbz+6xallfpFNC/Pg7dZ2h5AW2G762NN5X/4O1k+52xQQ5IkeTrPL6N7dz9DUEIlT y3eJqeIkHMJpNGy5WNYSkP9Ud58CJEC3IxqQdEoXM3nhpUudbM6bxdb0UWaU/zIlf8gb 6yQSToeRcjXz8svD3nuEpNOVSu8MAIsU5hs5f5Z0QmEgnwDG69t3Hmvg0OzTZKOZsoHK XjUQ== X-Gm-Message-State: AOJu0YyzNXSfv2ia0Gh/H5RSFfRmyM5TBDZwUXbz6LebfGZgsCX6pTJv 22VsG2sv+yU6i6gufHDJ+0csUpIrKFHRq/NUA04= X-Received: by 2002:a17:906:749b:b0:9a5:852f:10bd with SMTP id e27-20020a170906749b00b009a5852f10bdmr8629126ejl.62.1694466807044; Mon, 11 Sep 2023 14:13:27 -0700 (PDT) Received: from m1x-phil.lan (tfy62-h01-176-171-221-76.dsl.sta.abo.bbox.fr. [176.171.221.76]) by smtp.gmail.com with ESMTPSA id gt34-20020a1709072da200b009ad8796a6aesm33004ejc.56.2023.09.11.14.13.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 Sep 2023 14:13:26 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Daniel Henrique Barboza , Paolo Bonzini , Stefan Hajnoczi , Michael Tokarev , Richard Henderson , Marcelo Tosatti , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v4 1/3] target/i386: Check kvm_hyperv_expand_features() return value Date: Mon, 11 Sep 2023 23:13:15 +0200 Message-ID: <20230911211317.28773-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230911211317.28773-1-philmd@linaro.org> References: <20230911211317.28773-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=philmd@linaro.org; helo=mail-ej1-x631.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Move kvm_hyperv_expand_features() call earlier (this will simplify reviewing the next commit) and check its return value, since it can fail. Signed-off-by: Philippe Mathieu-Daudé --- target/i386/cpu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 24ee67b42d..760428d4dc 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7107,6 +7107,10 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) } } + if (kvm_enabled() && !kvm_hyperv_expand_features(cpu, errp)) { + return; + } + /* Set cpuid_*level* based on cpuid_min_*level, if not explicitly set */ if (env->cpuid_level_func7 == UINT32_MAX) { env->cpuid_level_func7 = env->cpuid_min_level_func7; @@ -7120,10 +7124,6 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) if (env->cpuid_xlevel2 == UINT32_MAX) { env->cpuid_xlevel2 = env->cpuid_min_xlevel2; } - - if (kvm_enabled()) { - kvm_hyperv_expand_features(cpu, errp); - } } /* From patchwork Mon Sep 11 21:13:16 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: 721473 Delivered-To: patch@linaro.org Received: by 2002:adf:f64d:0:b0:31d:da82:a3b4 with SMTP id x13csp1314195wrp; Mon, 11 Sep 2023 14:14:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkpbAsI4U2cMm9TB/HWr6Te9x5kw1HF2fAtadD8EPRardgJfnysjN5+gUwb02eZ9A5wuxT X-Received: by 2002:ac8:7e8b:0:b0:412:1773:8d57 with SMTP id w11-20020ac87e8b000000b0041217738d57mr14351060qtj.58.1694466880624; Mon, 11 Sep 2023 14:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694466880; cv=none; d=google.com; s=arc-20160816; b=rUZwwqs+6WqEUUoh18wBcsYRVoxkTGhnAhfudtNBKY+lnqzIJDCu6arAJWuAhhEu5r F68dxPGMM4Ado43f3KwXhVWF04aIhSfH5+vDg/C2Wa+DI5OewTs/xBchg8NCuJMqaR1N Um6fHN0Hozf9MaxkbFsGyiTLkcXpn9+VmLbYNtudXcPWsoEwo5igrvSS+zDowpeY2EJQ 9LgWhfMDRQg2mGGuneodGjZ4ZGKrU4Fs/wa7O8tcqLGXkPZJMsTmNH2FXpidA8JcLkt7 Q0rmWY6de7DqORM1GrsS0E8OA+iWt4MoChK/MpiddT+Eu1dS4v/VmSFlrfUjVjo3+LTq 58PA== 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=sHvSEfFrQcxmWmTmnxddV4RlJUGQqaNdgjpuMQl5NIM=; fh=fcdlpi58rfvXx0H4Wwhjis4yUZo2oB4+7NC4eFpZ0Zc=; b=d/pNt6vlGiFKakwRbZvO303bwAJH0egVWCZEFQEF5l5YSiXVBMwDk2fNAkdyb1ePx4 wjbePPv8DCu638hICbZU2j2U8xMilzKwcPRVBvV8h0QlcFMOPHtAGlj0VrRi7whMdtMM +jSKC7A02/SjpD8tNClxWuxqi0Mddv3jc8rEMVNdkIyiKRlL1IZTmkfIX3M/UOeGo3El FMnyu9fULjLhu16Q6/JqvVcQlaYolYT0Q5L2Fsi5+1HGOfA20Y22GgjaAkIuwJfUibg8 INB0WWp8/K+TVdoqrcr0z0YHFy8L59NI/vu+yvTJobOjRI2QzH+c7ks7Q4uelwk4i0uZ 6Lgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jyM7MOUx; 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 y11-20020a05622a120b00b004109680d862si5462828qtx.379.2023.09.11.14.14.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Sep 2023 14:14:40 -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=jyM7MOUx; 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 1qfoDz-0003dw-Ia; Mon, 11 Sep 2023 17:13:39 -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 1qfoDy-0003dl-Hi for qemu-devel@nongnu.org; Mon, 11 Sep 2023 17:13:38 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfoDv-0005CP-TB for qemu-devel@nongnu.org; Mon, 11 Sep 2023 17:13:38 -0400 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-52bcd4db4cbso6191495a12.1 for ; Mon, 11 Sep 2023 14:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694466813; x=1695071613; 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=sHvSEfFrQcxmWmTmnxddV4RlJUGQqaNdgjpuMQl5NIM=; b=jyM7MOUx1+bPlAGDC7O4WSn/9ntVn+1t3/LqNyRZaI+iLdMEJCvwgHDwXVJkVvR8Ee n5BxQxxiO86DGnczOYFVp+gfgD1LKlQN2IFppbyreuMym6NJoH8QuoNVGojzYa9/jh5t a2PZoqbkZFttU88uJrvTxE0GRSdhJHPxzngtpDMkaGsY/zK6gz9BD3MnYGC0hXV0dQIX U8sxuJoHOWTypoS1XwUGISoExBzEyrvIY3eepAFiLHV5yQE8VslS3P4eR8oClZDfZ5FS kFu6ZP/doGXyQAk7hsVoZTocg4xZgRtd99I/zHRYHsRld1RR67ai/HsEYgg6btxKm+Y9 Vk1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694466813; x=1695071613; 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=sHvSEfFrQcxmWmTmnxddV4RlJUGQqaNdgjpuMQl5NIM=; b=lifOjaAEAsFw3a4ibschAIIcK2j5yOF2fslo+opOliJihDxPffVl5GqWcCaWknd12d KCIbJvnUCSNDaCYEt+rprJHBx6Sbn5C5ZChZmQyGPJAOjqlSTbCawiTNqpqrxugIDMmi HaB9vPU6gw5nJYWjYXawNT3iBNkRoi9ycGSC66X2euWR1vDPHNXaQcuWFJb8Mq50ffsJ ZQCA0rOjTDSLKjAdKOPQwX9K8jxdx8WPx3pZ442eqvTfAHe8tosmi1oEjczvLcjREpjh FyoTS+Q8gTkNjKyXTEzaGLkOhmX8RCMDza9CHsiIB8eNG0XeLpuB1+E3ilu9WuRo03nw PoSQ== X-Gm-Message-State: AOJu0YyN9o0YtKYK5PiUiPmwS0QAhy5bP025DjvD3YF7ims1eL78I5Xx bxLdQ2qkmx+oaHiLTFjJB3GCHDStO2SdedDK4fc= X-Received: by 2002:a17:906:74c7:b0:9a1:e758:fc6e with SMTP id z7-20020a17090674c700b009a1e758fc6emr9487589ejl.10.1694466813214; Mon, 11 Sep 2023 14:13:33 -0700 (PDT) Received: from m1x-phil.lan (tfy62-h01-176-171-221-76.dsl.sta.abo.bbox.fr. [176.171.221.76]) by smtp.gmail.com with ESMTPSA id hb19-20020a170906b89300b009a1fd22257fsm5820515ejb.207.2023.09.11.14.13.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 Sep 2023 14:13:32 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Daniel Henrique Barboza , Paolo Bonzini , Stefan Hajnoczi , Michael Tokarev , Richard Henderson , Marcelo Tosatti , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , Kevin Wolf Subject: [RFC PATCH v4 2/3] target/i386: Restrict system-specific features from user emulation Date: Mon, 11 Sep 2023 23:13:16 +0200 Message-ID: <20230911211317.28773-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230911211317.28773-1-philmd@linaro.org> References: <20230911211317.28773-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::531; envelope-from=philmd@linaro.org; helo=mail-ed1-x531.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Since commits 3adce820cf ("target/i386: Remove unused KVM stubs") and ef1cf6890f ("target/i386: Allow elision of kvm_hv_vpindex_settable()"), when building on a x86 host configured as: $ ./configure --cc=clang \ --target-list=x86_64-linux-user,x86_64-softmmu \ --enable-debug we get: [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. libqemu-x86_64-linux-user.fa is user emulation specific, so having system emulation code called there is dubious. '--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. Instead of trying to deal with compiler specific checks around __OPTIMIZE__ (see commit 2140cfa51d "i386: Fix build by providing stub kvm_arch_get_supported_cpuid()"), simply restrict code belonging to system emulation, easing user emulation linking. Reported-by: Kevin Wolf Signed-off-by: Philippe Mathieu-Daudé --- RFC: I might have been overzealous in x86_cpu_expand_features(), please double check. --- target/i386/cpu.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 760428d4dc..8b57708604 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1664,6 +1664,7 @@ static inline uint64_t x86_cpu_xsave_xss_components(X86CPU *cpu) cpu->env.features[FEAT_XSAVE_XSS_LO]; } +#ifndef CONFIG_USER_ONLY /* * Returns the set of feature flags that are supported and migratable by * QEMU, for a given FeatureWord. @@ -1686,6 +1687,7 @@ static uint64_t x86_cpu_get_migratable_flags(FeatureWord w) } return r; } +#endif /* !CONFIG_USER_ONLY */ void host_cpuid(uint32_t function, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) @@ -5677,8 +5679,6 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) return cpu_list; } -#endif /* !CONFIG_USER_ONLY */ - uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, bool migratable_only) { @@ -5781,6 +5781,38 @@ static void x86_cpu_get_cache_cpuid(uint32_t func, uint32_t index, } } +#else /* CONFIG_USER_ONLY */ + +uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, + bool migratable_only) +{ + FeatureWordInfo *wi = &feature_word_info[w]; + + return wi->tcg_features; +} + +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) +{ + *eax = 0; + *ebx = 0; + *ecx = 0; + *edx = 0; +} + +static void x86_cpu_get_cache_cpuid(uint32_t func, uint32_t index, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) +{ + *eax = 0; + *ebx = 0; + *ecx = 0; + *edx = 0; +} + +#endif /* !CONFIG_USER_ONLY */ + /* * Only for builtin_x86_defs models initialized with x86_register_cpudef_types. */ @@ -6163,6 +6195,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } *edx = env->features[FEAT_7_0_EDX]; /* Feature flags */ +#ifndef CONFIG_USER_ONLY /* * SGX cannot be emulated in software. If hardware does not * support enabling SGX and/or SGX flexible launch control, @@ -6181,6 +6214,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, CPUID_7_0_ECX_SGX_LC))) { *ecx &= ~CPUID_7_0_ECX_SGX_LC; } +#endif } else if (count == 1) { *eax = env->features[FEAT_7_1_EAX]; *edx = env->features[FEAT_7_1_EDX]; @@ -6876,6 +6910,8 @@ static void mce_init(X86CPU *cpu) } } +#ifndef CONFIG_USER_ONLY + static void x86_cpu_adjust_level(X86CPU *cpu, uint32_t *min, uint32_t value) { if (*min < value) { @@ -6948,6 +6984,8 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu) env->features[FEAT_XSAVE_XSS_HI] = mask >> 32; } +#endif /* !CONFIG_USER_ONLY */ + /***** Steps involved on loading and filtering CPUID data * * When initializing and realizing a CPU object, the steps @@ -7040,6 +7078,7 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) } } +#ifndef CONFIG_USER_ONLY if (!kvm_enabled() || !cpu->expose_kvm) { env->features[FEAT_KVM] = 0; } @@ -7111,6 +7150,8 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) return; } +#endif /* !CONFIG_USER_ONLY */ + /* Set cpuid_*level* based on cpuid_min_*level, if not explicitly set */ if (env->cpuid_level_func7 == UINT32_MAX) { env->cpuid_level_func7 = env->cpuid_min_level_func7; @@ -7152,6 +7193,7 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool verbose) mark_unavailable_features(cpu, w, unavailable_features, prefix); } +#ifndef CONFIG_USER_ONLY if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) && kvm_enabled()) { KVMState *s = CPU(cpu)->kvm_state; @@ -7179,6 +7221,7 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool verbose) mark_unavailable_features(cpu, FEAT_7_0_EBX, CPUID_7_0_EBX_INTEL_PT, prefix); } } +#endif } static void x86_cpu_hyperv_realize(X86CPU *cpu) From patchwork Mon Sep 11 21:13:17 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: 721472 Delivered-To: patch@linaro.org Received: by 2002:adf:f64d:0:b0:31d:da82:a3b4 with SMTP id x13csp1314205wrp; Mon, 11 Sep 2023 14:14:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLSD3+nsT7VFCwe219g95K5AJVGBTRjVXUsfDKYcJIgXdJzsTEGsq/Pcbu+0yNtbS1cQmh X-Received: by 2002:a05:620a:46a9:b0:767:1b8e:811e with SMTP id bq41-20020a05620a46a900b007671b8e811emr13211435qkb.17.1694466883149; Mon, 11 Sep 2023 14:14:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694466883; cv=none; d=google.com; s=arc-20160816; b=iynFVUpSyNGIMC2sESGkIna4kpbSbEyRZEDAoS0ycqOc5YZ8g93YpuhZEtCiiro8eD DbHasCYAm46n8DYdbMkBAVDVjQLCb5wkK8z9iNYA9PqPJwJEiVCjtDfwYkW1OrX8yCqT 9EnSTbS5xZzrmtH8DORIkko8P7ZowyoXZbpFD/YrLK6oJfA2hnHfCOh12lbPIlL1iL+F 5vwtw/Zajf+zA4pzjqnYYznVEtwFSc2uJTcQg44j6XYC07+Vjfe497q4IlrH8S1SXakl QhLmu7/AYaSLgLXqDZ7bBKtwW11Cvwr/FVYmuACafwcT1P3HIzJ/+o9JZTYNes+qK7fh SxVA== 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=+fItrFBqz4pCpmjDHSDhxOZeNtPLgdWkJxbwSRsqucM=; fh=fcdlpi58rfvXx0H4Wwhjis4yUZo2oB4+7NC4eFpZ0Zc=; b=lTpo0BUsvV6A6VLtFpqWNY2Hjip3QuszxMnnb6RDclOtacCLO3kxBD3ZJ0nb+j1+tW T6OIg9BahuFlM/cfDtvNOjuv2MXClSnIB7FrRw0XpAFAACzSWwFqrklH8BQP7a18CGQz 4bcttRyUzrbY6oC8rn5sTzvNptcXUGGqEeyhMvmRcT0I0qbcu3mfmBD1Jzcv4PA6ndky YG3y3M8DKAiqqTdZkdJ84nS3ZMpSGKYTjHtQbWKI6XBHBnzYzoT4pZJV5hTIBeAQhybY 6q3y1LHxsGF9r0Fqa0p9UBBbhn4Sxa7pqCwkjzXJPiC6QYL2YabzE4c9TLquSVKpGn3g CvSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UKsqnR/n"; 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 a23-20020a05620a439700b0076daec99772si5578086qkp.36.2023.09.11.14.14.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Sep 2023 14:14:43 -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="UKsqnR/n"; 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 1qfoE5-0003fl-7o; Mon, 11 Sep 2023 17:13:45 -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 1qfoE4-0003eq-3t for qemu-devel@nongnu.org; Mon, 11 Sep 2023 17:13:44 -0400 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfoE1-0005Cy-TA for qemu-devel@nongnu.org; Mon, 11 Sep 2023 17:13:43 -0400 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-51e28cac164so12881617a12.1 for ; Mon, 11 Sep 2023 14:13:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694466819; x=1695071619; 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=+fItrFBqz4pCpmjDHSDhxOZeNtPLgdWkJxbwSRsqucM=; b=UKsqnR/nr+ZD4w7SdKYkNZDKI2dcOqQCU4FZ6i9sqw03G9LKmeIvVsWVHalud1fNw6 gfdMCEbPBdOb7+Aor06tLUEMyFe7SX09VdVNyNZ0I1q/KodCQZWSyXuYTdR0yGOgN7XL UhQYDKu4pjX3HBDgb+s0eKa6xGWBSgnmk5VFE/yZhBFLVAZ6dp1m4P/ZPMqsnbG73yeF 1BIqBm0aX+s7C9o+Qdxetl2Fw+QvlrN622qAFFXOXlqy8EAioGlrw4bnynqs2IfelqM6 7BYrYfQRTh6Z+G0uEbkPfyu8JzPmR67X85tCrUUmqCJF1J/EpZ8e0FxL4imgGLXnoSB5 xxpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694466819; x=1695071619; 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=+fItrFBqz4pCpmjDHSDhxOZeNtPLgdWkJxbwSRsqucM=; b=PuSQwl7azhZAK8tpVLPQ5TgAdURjH/WMUSACikLAzipYw53upTdJhmYZ7drLpK6GR9 XOd2rK9p1aI2eYf4Dj6zaUsYyMy0veDEFbezt3OkOX0sfCbv44YuDCWqYjdYFiQtzMJu s9aocqU8W0oMPeG1MjLA9o6W2zcd4xpDHMLDpS8XW8lBK9/gRU/7U88zAmDykUxf4y7Q iFB0IkFuj1mtdyyNddS2deJRmvj/xL+i0H6rRivO5pcBa4oxwmZ65y13If38pCC/X+yh tznuC1vu+CC1GUtW/d75LQgvSM4t/VVuzPW7QxR/UOiACIntsu2NFzdQozjDXudR+8RK +WPQ== X-Gm-Message-State: AOJu0Yy+LFr9xJT17y9j3l004AHZaQxusuDeaNfszyrDKbLta9uDICaC aF/9y7hj+qrJojFhxHs0j2Qo7BYL1SYXCVRA8Vo= X-Received: by 2002:a50:ee89:0:b0:523:37f0:2d12 with SMTP id f9-20020a50ee89000000b0052337f02d12mr1117871edr.17.1694466819175; Mon, 11 Sep 2023 14:13:39 -0700 (PDT) Received: from m1x-phil.lan (tfy62-h01-176-171-221-76.dsl.sta.abo.bbox.fr. [176.171.221.76]) by smtp.gmail.com with ESMTPSA id c18-20020aa7d612000000b005254b41f507sm5126392edr.32.2023.09.11.14.13.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 Sep 2023 14:13:38 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Daniel Henrique Barboza , Paolo Bonzini , Stefan Hajnoczi , Michael Tokarev , Richard Henderson , Marcelo Tosatti , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , Kevin Wolf Subject: [PATCH v4 3/3] target/i386: Prohibit target specific KVM prototypes on user emulation Date: Mon, 11 Sep 2023 23:13:17 +0200 Message-ID: <20230911211317.28773-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230911211317.28773-1-philmd@linaro.org> References: <20230911211317.28773-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=philmd@linaro.org; helo=mail-ed1-x536.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org None of these target-specific prototypes should be used by user emulation. Remove their declaration there, so we get a compile failure if ever used (instead of having to deal with linker and its possible optimizations, such dead code removal). Suggested-by: Kevin Wolf Signed-off-by: Philippe Mathieu-Daudé --- target/i386/kvm/kvm_i386.h | 4 ++++ target/i386/cpu.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index 55d4e68c34..5ef73f0a1c 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -13,6 +13,10 @@ #include "sysemu/kvm.h" +#ifdef CONFIG_USER_ONLY +#error Cannot include kvm_i386.h from user emulation +#endif + #ifdef CONFIG_KVM #define kvm_pit_in_kernel() \ diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 8b57708604..6be59c7b2b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -26,7 +26,7 @@ #include "tcg/helper-tcg.h" #include "sysemu/reset.h" #include "sysemu/hvf.h" -#include "kvm/kvm_i386.h" +#include "sysemu/kvm.h" #include "sev.h" #include "qapi/error.h" #include "qemu/error-report.h" @@ -40,6 +40,7 @@ #include "exec/address-spaces.h" #include "hw/boards.h" #include "hw/i386/sgx-epc.h" +#include "kvm/kvm_i386.h" #endif #include "disas/capstone.h"