Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp72400lqc; Thu, 7 Mar 2024 10:36:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWTNMjooIiH1Xj3dz1AC7yfTZo2H+SbzvLNSzVMjOQWy6RRuU45xC9uNJoa0H/n4t0yZsbzvBtbveg4i3sQgAFjZ9rH70lVDy9lLlRJbQ== X-Google-Smtp-Source: AGHT+IF4rmuv/Sm4aaaEp/W1XtXIxiDhtR76+nEYqcptFrkgfKiytBv3fx6ure0HcZJ84c2Nkpdh X-Received: by 2002:a17:903:2305:b0:1dc:6fec:15d8 with SMTP id d5-20020a170903230500b001dc6fec15d8mr10712476plh.47.1709836569137; Thu, 07 Mar 2024 10:36:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709836569; cv=pass; d=google.com; s=arc-20160816; b=gRjnyqTRx6g55oGhFQ1MOxax6lKNRn1Zb5iKbrFPuyLSs4dtFXhSnYyNbc6wQD+tjR KJxzrknW5ZXC7RRGniiiYuGNLemhMRU7f2o+IUtvm5VJm01On7GfID1rFKck9w/QvFdn Q/1jSAfPW1FCVzHQx+vaZC8fOccGlw1BqX6dYhywSFSYbWO1RWgm+/e0mhpHBfAfWapW aXN+RgktlNztQOw5yDZUTv7Luy1v7RoSN6qrzrJHL+9E9b8EdqVCFRVq+Xek02MMXZWf 6i4QLOe4zdGYiYUn2jhIMi91c8i9TKT7otp1jtAhBTKUJIy8sqz93zpuX225YPr1L/Nb 7LtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=6gcB7rs/ZShkZQFSJOEoG/IHLW4vs94Ivr+W9yFak8E=; fh=U6xmODt7gjrQZWyPdcMTBeUyLAw+MpAAjqOJD9dGaD4=; b=Blaq7nXs9rlmrsGOAJWV+NoZ78JuaShrkSNFVNPNaf4qF8R0AIMLlcwezve05nm1K/ vcvVYKdUUlWratXKN05ZmDc90BoqlfIF7t8NSiiJWYmGrqIw1QJRwokj53T0Y5Z4WggV LFzpeKrOOQx7vPfICG5D3dEavtcjM46/H8G9N3GWq4qJsU0VVqys5jaY4AdB9xAuoZ/M wk4gKQse6aUfhi69HQJzfneUG3r3oNeHzRWiBP7Q/5azfaE/1lkYAEIcaFCoud6lPWyc Cf+9qUOg0ao+3I+f7SqHRZtkm5gl0uPbxZ/V9TSsGVhqE16LUZwKCcYDWdRghAQcy7v6 J29A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jo3kuQ5w; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-96020-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96020-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u4-20020a170902e5c400b001dcf90d6315si10732963plf.107.2024.03.07.10.36.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 10:36:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96020-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jo3kuQ5w; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-96020-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96020-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 C4285288451 for ; Thu, 7 Mar 2024 18:36:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1EB213340F; Thu, 7 Mar 2024 18:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jo3kuQ5w" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7725912F5A5 for ; Thu, 7 Mar 2024 18:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709836559; cv=none; b=hCGh2rZY1JdfIJ+Zf1A7tSsOv9d6rYmdjCYWCP4gIGhd0ZyH5JjrYbfkFTXQJffdecnA0UVvrnOc84bHrVILDqBbrWFQPaMRh5wEIfyGbQ3VpM0LjCinwwRdYb7QrZSOqUc1B4PHY/JIe78QoR4vo24RMEOXLBj1MpaJkHIGKZg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709836559; c=relaxed/simple; bh=iEEp31JydCDbDDWUypoDZzp7A7ngZJq4AsyQqSmOJcQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TovNFvWBR2Ug8KrmXKT4ck+I2fc7Uc7oQrz8SF64XFzm/ke5qzxNpTxP1k0iY4IJDlyTpH1f2uMtO2Xc6B1kcKJe7LxJ75p9dDIvOZkrfjwD9erMVFKlx46tOTKc6oWnsJrILpT/dLskaLYUz7fuBBE9+CACAC2iaNt6QVmVcHY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jo3kuQ5w; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5f38d676cecso29277597b3.0 for ; Thu, 07 Mar 2024 10:35:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709836556; x=1710441356; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6gcB7rs/ZShkZQFSJOEoG/IHLW4vs94Ivr+W9yFak8E=; b=jo3kuQ5wbdX/qCJSNc2SUfUcCL8no5pI9za0iS5c5rznTyUPsWskbhr5hWtZ1Cg5h1 yGDB/dPRvw3ECkaDmPO+P1twDgLMSnk35kj0VR8TKYRIvcC1h8gyv3/vOxyPxXEHaMcl 6aKvofj9YvbY0ER8y8XzYFvdbHnr4yYEDK0Wvdme9mAjHoVrYxEvcjyMYFejVC9gRuY7 6AbOYloTfqq2PavZ+j2o2XigebgUZ0TvlFKO5rbaSvoIG0gm4R19BxTmkZ1OzpucFl41 FOl3xdxq7xyHes2BfBGVEdXN6D8RWVrnvq0Bhl8qKyLr8I1UFsl8e0uBlA0hTxr3Hxt4 2o+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709836556; x=1710441356; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6gcB7rs/ZShkZQFSJOEoG/IHLW4vs94Ivr+W9yFak8E=; b=fFohtISNSolT5gxus+N6atX6/XvHf0fIm7jbtLL0nV4nvpoNd4g9dBVeibHzmIVCUH vnOITJX7EpZ6boyzH0JY5tzy+KaxQerIiBEOMqjyAw8Jfuneviv9mRKh3XuFc78yXtC8 mzF3Ew64YRVn7HwkcjOnDyTZRnVPMerv69YypYkYMaXEKmPJKJgzCIM/HrgeEZZMwiI+ cZuHdwP8TGXUUafZ/2EYBLkotgvmzWp4HCbTR03AbS/aGnpu6NPHaz2ARI/vQh/M6cP8 n4a618XolIDKKLm+lBJhWlL4zY5c4QYmcm2uBMuIVaIIpHwi4eXowMuSWK0YV3syetVy +KNA== X-Forwarded-Encrypted: i=1; AJvYcCUu09DyWw2vHOYHNcVeO8wqQC2KDJ4PGc1+w/YLjgeje6VwqV4rs8Y67FMYV//P+gEt55Y3Zp20AJRA+uYvR8+JTSX2AtdD7BKkNXOS X-Gm-Message-State: AOJu0YwfzFCSncIFIt6J6f8nLB0+eIzvFBgsrNXX/nHbKkh6bARjsc+L 5U2vHvjHDvjvkER6Dt6afETBRNZAHbQGRoOuy8aOSnxYK/txJSczOaZNhwCGD1Y47XVzoqdqmYU zmA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:3a03:0:b0:dc7:463a:46d2 with SMTP id h3-20020a253a03000000b00dc7463a46d2mr49728yba.0.1709836556326; Thu, 07 Mar 2024 10:35:56 -0800 (PST) Date: Thu, 7 Mar 2024 10:35:54 -0800 In-Reply-To: <23a1af5f-e08d-4cf6-b4bd-8cfb6266f441@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240301074423.643779-1-sandipan.das@amd.com> <23a1af5f-e08d-4cf6-b4bd-8cfb6266f441@amd.com> Message-ID: Subject: Re: [PATCH] KVM: x86: Do not mask LVTPC when handling a PMI on AMD platforms From: Sean Christopherson To: Sandipan Das Cc: Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, mlevitsk@redhat.com, vkuznets@redhat.com, mizhang@google.com, tao1.su@linux.intel.com, andriy.shevchenko@linux.intel.com, ravi.bangoria@amd.com, ananth.narayan@amd.com, nikunj.dadhania@amd.com, santosh.shukla@amd.com, manali.shukla@amd.com Content-Type: text/plain; charset="us-ascii" On Thu, Mar 07, 2024, Sandipan Das wrote: > On 3/5/2024 2:19 AM, Sean Christopherson wrote: > The following are excerpts from some changes that I have been working on. Instead > of a boolean flag, this saves the compatible vendor in kvm_vcpu_arch and tries > to match it against X86_VENDOR_* values. The goal is to replace > guest_cpuid_is_{intel,amd_or_hygon}() with > guest_vendor_is_compatible(vcpu, X86_VENDOR_{INTEL,AMD}). Is this viable? > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index d271ba20a0b2..c4ada5b12fc3 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1042,6 +1042,7 @@ struct kvm_vcpu_arch { > #if IS_ENABLED(CONFIG_HYPERV) > hpa_t hv_root_tdp; > #endif > + u8 compat_vendor; Ooh, clever, much better than my idea of using multiple booleans. One potential flaw though: the vCPU structure is zero-allocated, and so this will get a false positive on X86_VENDOR_INTEL if userspace never sets guest CPUID. That might actually be desirable though? E.g. it's closer to KVM's current behavior. Maybe. I dunno :-) Anyways, KVM *does* need to be consistent, i.e. the default needs to yield the same behavior as guest CPUID without entry 0x0 so that setting *other* CPUID entries doesn't change from INTEL=>UNKNOWN. More below. > }; > > struct kvm_lpage_info { > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index adba49afb5fe..00170762e72a 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -376,6 +376,13 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) > kvm_hv_set_cpuid(vcpu, kvm_cpuid_has_hyperv(vcpu->arch.cpuid_entries, > vcpu->arch.cpuid_nent)); > > + if (guest_cpuid_is_intel_compatible(vcpu)) > + vcpu->arch.compat_vendor = X86_VENDOR_INTEL; > + else if (guest_cpuid_is_amd_or_hygon(vcpu)) > + vcpu->arch.compat_vendor = X86_VENDOR_AMD; > + else > + vcpu->arch.compat_vendor = X86_VENDOR_UNKNOWN; I would prefer to provide a helper for just getting the compat vendor. E.g. static u8 kvm_vcpu_get_compat_vendor(struct kvm_vcpu *vcpu) { struct kvm_cpuid_entry2 *best; best = kvm_find_cpuid_entry(vcpu, 0); if (!best) return ???; if (is_guest_vendor_intel(best->ebx, best->ecx, best->edx) || is_guest_vendor_centaur(best->ebx, best->ecx, best->edx) || is_guest_vendor_zhaoxin(best->ebx, best->ecx, best->edx)) return X86_VENDOR_INTEL; if (is_guest_vendor_amd(best->ebx, best->ecx, best->edx) || is_guest_vendor_hygon(best->ebx, best->ecx, best->edx)) return X86_VENDOR_AMD; return X86_VENDOR_UNKNOWN; } and then a follow-up patch can remove guest_cpuid_is_amd_or_hygon() once all users are converted to guest_vendor_is_compatible().