From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 2F64A2153E5 for ; Wed, 22 Jan 2025 17:44:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737567887; cv=none; b=qP+NhgTu2ym8/w80Bx7IMshLuoKe8mJ8ZWt+2/QDuGkF5IpQG8HKGQtXiUe0OE3xwm1MjDxWHvA7f95Iec6YG6gRaRoW5qArBWc6TYk3jBc7mh/lq49hv97lfqyNuMhnHm+qkGzWJJEYuc7cqlX2sPpLj7BACSWQE7iMdfQOOFM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737567887; c=relaxed/simple; bh=9+dYk6uLPNaSfPahFJwjv2TJWB45nPzIcxXEYA0CRvk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=YSUrHPOh8K96FRIoEb/zbQD9FsVGlL/d2nIOOf1snAdGncOajTmEg4DKFHlX94m0Je7+CvlJupgwgLI5lhy/EDq//wnyq2XfIVFXfRdA1wl7NWhd7Zf6wnFA2+3oF0BT2nlKcFzaXwcTZ8WDChXPqEll4mjTs3PQJoJyr7iNaIo= 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=Oi0eEiL7; arc=none smtp.client-ip=170.10.129.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="Oi0eEiL7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737567885; 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: in-reply-to:in-reply-to:references:references; bh=0mKiKkRzZUgeGTjqlBuywLicTrfkha+hCUcAXkj1MAM=; b=Oi0eEiL7XIMe4gZbO43hOqxFSvC9ASvzVfaEAeN5vlPP32F7z1E4bvTeDQkpKMh/2GWoC+ gKWaN32zwQ2HzqDsrMrZ+DJUmmfCSaFr3staXSC7DzdnkjWdHm6GLarBBgI/1JGj9AVxZP DqnhaF/fkBXbuTEn4eMMKM283PW6Qy8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637--DNkcxvmM4-clyWmG9_r6g-1; Wed, 22 Jan 2025 12:44:43 -0500 X-MC-Unique: -DNkcxvmM4-clyWmG9_r6g-1 X-Mimecast-MFC-AGG-ID: -DNkcxvmM4-clyWmG9_r6g Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4359eb032c9so54656315e9.2 for ; Wed, 22 Jan 2025 09:44:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737567882; x=1738172682; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0mKiKkRzZUgeGTjqlBuywLicTrfkha+hCUcAXkj1MAM=; b=SZNKG7Kpg3rOzeqtMpSzthUumOREuANidoVsYsDF6akPqaVdxUX/H8zokL5i2PL33I YMfCEQiYkPZacaXIKR7oH1/HTrrP2LJ/kg469DBDXdyv8bQwtsTEHcA6peKjf+6cKROo FhFR4SapY2ceMhXuzHDVAKE1mY04j7E1PzxZBgMLi9uW4CCGaT0Sh/ZIlBBSv9yO101U P1N/BI92MjY+2c3kiR9LSjrjzlWgtDDVzctSIPTl8CaDcbNSo8BRAceBoijIdHzyJ6xb +jcOHVwOBmJjmeijQjSzHZuVAAJbC2XQNbfM7NjlseSFawb9O9cXp2cTHVLnt1YqqolV YgJQ== X-Forwarded-Encrypted: i=1; AJvYcCXZdrc59/T1TccprApq9+2ge8g7JrBNcBIGgjTCz1zwwIhzFpeUe4wTNUBl0eCbsaE2sO6tf9JR9tvlSCE=@vger.kernel.org X-Gm-Message-State: AOJu0Yyb2OMYn3lMFSCCqgCwBFZIY2k7DSIVLycOHnZgN7jtFB6I8bkH zghZ30YQp0p4t67AmUgDRZqoZYQRW+cJ9TO8rCvhodkDdWDB+eVwvFdwaKF5N2aA9n33SzuMu+0 1YFkr7QX8c7BqpzPNoEu4IOIWeA8TpmqFgh1AAJ0+kceilNdnNUJPTvQW/xAJH7/NI+4uyd0xMX YJj32MoSbHcRHWBmH9BRU3gY7XKBPDKa9W6YPHbfTXMnBUgA== X-Gm-Gg: ASbGncurd3pYpj4qWWKSnoWLjzhTigffrtswmecZ6/R1AeOC28Gf6iw+l4AcixwOhKt kIQghQu2u8Ls9F8UMHLmkxvCfbxEcz8uSS+80220RdcuxsXkurnrLqxZ5JtOZBBdYT7BBonsr/W +7jFf4xvVBRvb4EF+9FqklnNl1VZeCy8OpqNtmgPnuyYwEJ5SgLTdpUAITBVEE4CfTlkx6AQRzl WysWDp6J1tT0QFEfQjS8rmVBGbZTIxh/tWXSBDtBu/J8NYiJsV8fd0qVOPphnR5 X-Received: by 2002:a05:6000:1a8c:b0:385:e5d8:2bea with SMTP id ffacd0b85a97d-38bf56639c9mr19598841f8f.20.1737567882600; Wed, 22 Jan 2025 09:44:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDOBXvsJXq7GbkbLYKEhW7E7CbQYXUCT5onjS2F9ksK1iDunvcE5QpwuEznxi/SuLc8Yw7WA== X-Received: by 2002:a05:6000:1a8c:b0:385:e5d8:2bea with SMTP id ffacd0b85a97d-38bf56639c9mr19598813f8f.20.1737567882216; Wed, 22 Jan 2025 09:44:42 -0800 (PST) Received: from fedora (g2.ign.cz. [91.219.240.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf3221a5csm17131075f8f.34.2025.01.22.09.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2025 09:44:41 -0800 (PST) From: Vitaly Kuznetsov To: paul@xen.org, Fred Griffoul , kvm@vger.kernel.org Cc: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , David Woodhouse , linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: x86: Update Xen-specific CPUID leaves during mangling In-Reply-To: References: <20250122161612.20981-1-fgriffo@amazon.co.uk> <87tt9q7orq.fsf@redhat.com> Date: Wed, 22 Jan 2025 18:44:40 +0100 Message-ID: <87r04u7ng7.fsf@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Paul Durrant writes: > On 22/01/2025 17:16, Vitaly Kuznetsov wrote: >> Fred Griffoul writes: >> >>> Previous commit ee3a5f9e3d9b ("KVM: x86: Do runtime CPUID update before >>> updating vcpu->arch.cpuid_entries") implemented CPUID data mangling in >>> KVM_SET_CPUID2 support before verifying that no changes occur on running >>> vCPUs. However, it overlooked the CPUID leaves that are modified by >>> KVM's Xen emulation. >>> >>> Fix this by calling a Xen update function when mangling CPUID data. >>> >>> Fixes: ee3a5f9e3d9b ("KVM: x86: Do runtime CPUID update before >>> updating vcpu->arch.cpuid_entries") >> >> Well, kvm_xen_update_tsc_info() was added with >> >> commit f422f853af0369be27d2a9f1b20079f2bc3d1ca2 >> Author: Paul Durrant >> Date: Fri Jan 6 10:36:00 2023 +0000 >> >> KVM: x86/xen: update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present >> >> and the commit you mention in 'Fixes' is older: >> >> commit ee3a5f9e3d9bf94159f3cc80da542fbe83502dd8 >> Author: Vitaly Kuznetsov >> Date: Mon Jan 17 16:05:39 2022 +0100 >> >> KVM: x86: Do runtime CPUID update before updating vcpu->arch.cpuid_entries >> >> so I guess we should be 'Fixing' f422f853af03 instead :-) >> >>> Signed-off-by: Fred Griffoul >>> --- >>> arch/x86/kvm/cpuid.c | 1 + >>> arch/x86/kvm/xen.c | 5 +++++ >>> arch/x86/kvm/xen.h | 5 +++++ >>> 3 files changed, 11 insertions(+) >>> >>> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c >>> index edef30359c19..432d8e9e1bab 100644 >>> --- a/arch/x86/kvm/cpuid.c >>> +++ b/arch/x86/kvm/cpuid.c >>> @@ -212,6 +212,7 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 >>> */ >>> kvm_update_cpuid_runtime(vcpu); >>> kvm_apply_cpuid_pv_features_quirk(vcpu); >>> + kvm_xen_update_cpuid_runtime(vcpu); >> >> This one is weird as we update it in runtime (kvm_guest_time_update()) >> and values may change when we e.g. migrate the guest. First, I do not >> understand how the guest is supposed to notice the change as CPUID data >> is normally considered static. Second, I do not see how the VMM is >> supposed to track it as if it tries to supply some different data for >> these Xen leaves, kvm_cpuid_check_equal() will still fail. >> >> Would it make more sense to just ignore these Xen CPUID leaves with TSC >> information when we do the comparison? >> > > What is the purpose of the comparison anyway? IIUC we want to ensure > that a VMM does not change its mind after KVM_RUN so should we not be > stashing what was set by the VMM and comparing against that *before* > mangling any values? > I guess it can be done this way but we will need to keep these 'original' unmangled values for the lifetime of the vCPU with very little gain (IMO): KVM_SET_CPUID{,2} either fails (if the data is different) or does (almost) nothing when the data is the same. -- Vitaly