Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp794889rdb; Fri, 26 Jan 2024 10:49:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IENURJMyXJkI85BlybmQVWKSl5r+T4aNwhwbNENfJwtEzN/vgelQh9AA8xxiUPCpQPC2XEs X-Received: by 2002:a17:903:11cc:b0:1d7:5d88:f993 with SMTP id q12-20020a17090311cc00b001d75d88f993mr430455plh.41.1706294979332; Fri, 26 Jan 2024 10:49:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706294979; cv=pass; d=google.com; s=arc-20160816; b=wOb5iYpq0AGQcA85u+N5NuATgkTguyeTTYG0XboJ3k6cgEf6Oppho26wWUW6LQsKcE BxgWEB19xdPMA3p4kpu+kWnhwWL4XFfM05V2cFlK9UzFYCukUTxegwkSUdv4JY+l8b20 xSjvuYkNXv5Pf3JElsAQsdALq076LV3Zo9fnmyNrUJxIifH1WZoWepoSiwb7w2Sk1LDo H1fQHV9IfRXeh/vfNcxri36e2Obr1ogqk2HvRiCb6zacsgHOnJYcTBzjkUurg0/Md/5M DxBgN8KZ5uYsnSq9yDexzoWQTK2nq2unSbRykeqBKGmnff0R1CEjzdDOEETjb1FVNxtI K+1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:disposition-notification-to :autocrypt:from:references:cc:to:content-language:subject:user-agent :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:message-id; bh=9TspBo3RhVjMfjchwb/HEQE7GNgVHzgBdWI5bAMSRUs=; fh=YS3w2xFVLBOtEK8jmDIoD24/3sffbYFyPJFoIXH2QM0=; b=JmW6WfyTlwV6tFJmSeJH9p/iFNR2o5wRHolF0ELyfdXoOlG+oqiVmb6yg4C9FnwpwA 38sAcnNulglchmK96J0pzy2VKsqL0e+hOl6fg0UfZQLs6BOJrouZDN6Frg0D7Ci0OkZr qg/xMeqpTb6XEXTu0cfeRkbQ45fI2fU68wAlmBePsrd7VnHWvahAzrQpy8hksLDnT2By ifL6kaDKgyowyJQwhjeTTZnyGbwU82x8/o2Wa9AdlRLbOjeY6ePC+HJ4XxBD6xf1G4RU bdk3nTlxccncfzb/1aVbtKdJbrw+ELeW7bb8ZFQKTcjlTPvz/VZtT6R/0IqdCKSzrlFq a/zg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=maciej.szmigiero.name); spf=pass (google.com: domain of linux-kernel+bounces-40529-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40529-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l15-20020a170903244f00b001d7162d62d2si1544966pls.283.2024.01.26.10.49.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 10:49:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40529-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=maciej.szmigiero.name); spf=pass (google.com: domain of linux-kernel+bounces-40529-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40529-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E8E6B281078 for ; Fri, 26 Jan 2024 18:49:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2705224CA; Fri, 26 Jan 2024 18:49:15 +0000 (UTC) Received: from vps-vb.mhejs.net (vps-vb.mhejs.net [37.28.154.113]) (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 794D421371; Fri, 26 Jan 2024 18:49:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=37.28.154.113 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706294955; cv=none; b=CMgiMGZ4iiTLH2nqnNnz5ehqnSl5seZzskBmGa1s/DRXxF6/UIcU4EvA/rEuwFnazfijQF7LQR6s5yHaeQW1JU3WD3/luSmnMXE/9cdE6ol7Jwnh84T5XQpkRr7JzWDtQh/kccSqaYtVOmzBQIG8zSHu2Ss3CJxZrLkfhbEXgHk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706294955; c=relaxed/simple; bh=pStHePFSIKYPMYDhCKX9LHB74JCGqh+BFv00THOanSE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qGKNNrNR4C9NUOW0FQmhCvVz32C/JMRI3ngKZZDxfYG5N/IpPrnBUAxQwGm75nenOAvKUZBdbNUdf/c7hGRBwpta5/3avrM26u0nOc9bSb/Wv2OHjUvQ/cKzWAABP9koBCPGzM//6ZaBJpIyHsNJBroGYk4c8Z5zwS3cfB7bGYY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=maciej.szmigiero.name; spf=pass smtp.mailfrom=maciej.szmigiero.name; arc=none smtp.client-ip=37.28.154.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=maciej.szmigiero.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=maciej.szmigiero.name Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rTRG6-0007EI-DT; Fri, 26 Jan 2024 19:48:58 +0100 Message-ID: <592977b7-e4c9-43af-aa33-1ce3b6fa1275@maciej.szmigiero.name> Date: Fri, 26 Jan 2024 19:48:52 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] KVM: x86: Give a hint when Win2016 might fail to boot due to XSAVES erratum Content-Language: en-US, pl-PL To: Paolo Bonzini Cc: Sean Christopherson , Maxim Levitsky , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: From: "Maciej S. Szmigiero" Autocrypt: addr=mail@maciej.szmigiero.name; keydata= xsFNBFpGusUBEADXUMM2t7y9sHhI79+2QUnDdpauIBjZDukPZArwD+sDlx5P+jxaZ13XjUQc 6oJdk+jpvKiyzlbKqlDtw/Y2Ob24tg1g/zvkHn8AVUwX+ZWWewSZ0vcwp7u/LvA+w2nJbIL1 N0/QUUdmxfkWTHhNqgkNX5hEmYqhwUPozFR0zblfD/6+XFR7VM9yT0fZPLqYLNOmGfqAXlxY m8nWmi+lxkd/PYqQQwOq6GQwxjRFEvSc09m/YPYo9hxh7a6s8hAP88YOf2PD8oBB1r5E7KGb Fv10Qss4CU/3zaiyRTExWwOJnTQdzSbtnM3S8/ZO/sL0FY/b4VLtlZzERAraxHdnPn8GgxYk oPtAqoyf52RkCabL9dsXPWYQjkwG8WEUPScHDy8Uoo6imQujshG23A99iPuXcWc/5ld9mIo/ Ee7kN50MOXwS4vCJSv0cMkVhh77CmGUv5++E/rPcbXPLTPeRVy6SHgdDhIj7elmx2Lgo0cyh uyxyBKSuzPvb61nh5EKAGL7kPqflNw7LJkInzHqKHDNu57rVuCHEx4yxcKNB4pdE2SgyPxs9 9W7Cz0q2Hd7Yu8GOXvMfQfrBiEV4q4PzidUtV6sLqVq0RMK7LEi0RiZpthwxz0IUFwRw2KS/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8QFQL5 5ZSOo27q/Ox95rwuC/n+PoJxBfqU36XBi886VV4LxuGZ8kfy0qDpL5neYtkC9w== Disposition-Notification-To: "Maciej S. Szmigiero" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 26.01.2024 19:36, Paolo Bonzini wrote: > On Wed, Jan 24, 2024 at 9:18 PM Maciej S. Szmigiero > wrote: >> +static void kvm_hv_xsaves_xsavec_maybe_warn_unlocked(struct kvm_vcpu *vcpu) > > Calling this function "unlocked" is confusing (others would say > "locked" is confusing instead). The double-underscore convention is > more common. > >> +{ >> + struct kvm *kvm = vcpu->kvm; >> + struct kvm_hv *hv = to_kvm_hv(kvm); >> + >> + if (hv->xsaves_xsavec_warned) >> + return; >> + >> + if (!vcpu->arch.hyperv_enabled) >> + return; > > I think these two should be in kvm_hv_xsaves_xsavec_maybe_warn(), > though the former needs to be checked again under the lock. > >> + if ((hv->hv_guest_os_id & KVM_HV_WIN2016_GUEST_ID_MASK) != >> + KVM_HV_WIN2016_GUEST_ID) >> + return; > > At this point there is no need to return. You can set > xsaves_xsavec_warned and save the checks in the future. > >> + /* UP configurations aren't affected */ >> + if (atomic_read(&kvm->online_vcpus) < 2) >> + return; >> + >> + if (boot_cpu_has(X86_FEATURE_XSAVES) || >> + !guest_cpuid_has(vcpu, X86_FEATURE_XSAVEC)) >> + return; > > boot_cpu_has can also be done first to cull the whole check. > >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> index 27e23714e960..db0a2c40d749 100644 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -1782,6 +1782,10 @@ static int set_efer >> if ((efer ^ old_efer) & KVM_MMU_EFER_ROLE_BITS) >> kvm_mmu_reset_context(vcpu); >> >> + if (guest_cpuid_is_amd_or_hygon(vcpu) && >> + efer & EFER_SVME) >> + kvm_hv_xsaves_xsavec_maybe_warn(vcpu); >> + >> return 0; >> } > > Checking guest_cpuid_is_amd_or_hygon() is relatively expensive, it > should be done after "efer & EFER_SVME" but really the bug can happen > just as well on Intel as far as I understand? It's just less likely > due to the AMD erratum. Yes, I've checked this guest on an Intel host and it also fails to boot in !XSAVES && XSAVEC configuration. Only on Intel it's purely a theoretical problem as AFAIK there's no corresponding Intel errata that disables just XSAVES. > > I'll send a v2. > > Paolo > Thanks, Maciej