From nobody Fri Nov 29 10:47:18 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DFC61E521 for ; Fri, 20 Sep 2024 15:44:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726847071; cv=none; b=FABHj45mD+sWfRTG3VTuXAu9IZRy3DeTVKmxAdSQrT8n3p6B0R6TZZ0wdHqDBfOTr4Ty5N0VkVkM9LWCsIbRLvu+6jZ3I0hs+ZGFEZMhwnVH66K5rno4TjGJO+/FS+f2E740zL54yPYPZQQf2IcsxRD9/Zh3Z/ZBVaeOPHxnq/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726847071; c=relaxed/simple; bh=L4F9t9eX2mGkrFvAoAO4WcKWW0cmDO9vUJ06dP3REH4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=NhNU2QObrZrNlfBU0AIl7aJ5qsFsyDmCR5K0Yh28vMvoKuRcbtPk5dl3Mb7385UriecGrgnlk/RL3zgp4enXzGtisLyJfS8qNG8gzORf/bGf7y8anpkl67Feko++TlPXurVtJUy3FUjgRT2zd4VW1w2L1aArRGGZEJ1nE3ElQes= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=c6kgXt/a; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c6kgXt/a" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726847068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tuUFCphhzHU/5+RQPnqBt9ZmoF79wTTTNRlLo/sGdJo=; b=c6kgXt/acPGlGfAC1oNRjDmfaJUagMQlm4ZQ+BIEOLJWMRIzxAxKNVznQL0wyUtqJq3BuS g7x/62cPcsYjx4ENdlg8vx398E7YbCC1VnRRqXKX/Az8LXMaV9VZj56738JTc+BqRjg+mX EQXv4++xWoJSWWSay9ba67ph/pwO7B8= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-UyipB_pMMiqs5u6zSbBI3g-1; Fri, 20 Sep 2024 11:44:26 -0400 X-MC-Unique: UyipB_pMMiqs5u6zSbBI3g-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A44BD19137AA; Fri, 20 Sep 2024 15:44:25 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.184]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 90AAA19560AF; Fri, 20 Sep 2024 15:44:23 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Jan Richter , linux-kernel@vger.kernel.org Subject: [PATCH] KVM: selftests: x86: Avoid using SSE/AVX instructions Date: Fri, 20 Sep 2024 17:44:22 +0200 Message-ID: <20240920154422.2890096-1-vkuznets@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Some distros switched gcc to '-march=3Dx86-64-v3' by default and while it's hard to find a CPU which doesn't support it today, many KVM selftests fail with =3D=3D=3D=3D Test Assertion Failure =3D=3D=3D=3D lib/x86_64/processor.c:570: Unhandled exception in guest pid=3D72747 tid=3D72747 errno=3D4 - Interrupted system call Unhandled exception '0x6' at guest RIP '0x4104f7' The failure is easy to reproduce elsewhere with $ make clean && CFLAGS=3D'-march=3Dx86-64-v3' make -j && ./x86_64/kvm_pv= _test The root cause of the problem seems to be that with '-march=3Dx86-64-v3' GCC uses AVX* instructions (VMOVQ in the example above) and without prior XSETBV() in the guest this results in #UD. It is certainly possible to add it there, e.g. the following saves the day as well: diff --git a/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c b/tools/testi= ng/selftests/kvm/x86_64/kvm_pv_test.c index 78878b3a2725..704668adb3bd 100644 --- a/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c +++ b/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c @@ -82,8 +82,17 @@ static void test_hcall(struct hcall_data *hc) static void guest_main(void) { + uint64_t cr4, xcr0; int i; + cr4 =3D get_cr4(); + cr4 |=3D X86_CR4_OSXSAVE; + set_cr4(cr4); + + xcr0 =3D xgetbv(0); + xcr0 |=3D XFEATURE_MASK_SSE | XFEATURE_MASK_YMM; + xsetbv(0x0, xcr0); + for (i =3D 0; i < ARRAY_SIZE(msrs_to_test); i++) { test_msr(&msrs_to_test[i]); } but this needs to be made conditional depending on the compilation target and added to all selftests. Slap a band-aid on the problem by forcing '-march=3Dx86-64-v2' in Makefile. Signed-off-by: Vitaly Kuznetsov --- tools/testing/selftests/kvm/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests= /kvm/Makefile index 48d32c5aa3eb..3f1b24ed7245 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -238,6 +238,7 @@ CFLAGS +=3D -Wall -Wstrict-prototypes -Wuninitialized -= O2 -g -std=3Dgnu99 \ -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ -I$(