From nobody Sun Feb 8 06:21:43 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 C13B9374EA for ; Fri, 5 Apr 2024 23:56:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361372; cv=none; b=VYiqCk0UvPTCrPYaL7GvEkqocyjhqsSJ2s70uv1AU3/eo41lTvH5FOzRMjos3xz27YysaBRK5Rem1Nsu2aBO0PXTnOAmV+wajnbRGpypi7nkUWPthto9WurxaXyBUq530Se0ewBqhL1661JlpJH3pj6doBX1U5JnDiLVT5/M1bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361372; c=relaxed/simple; bh=8lScNtViHEsyfm2JCHUZapYQ1CBggYo9daCone+eouU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SZ2h4Qeyi62dun/Sa+IyC3/9izrWKcZM2vkjZm9MWsK4Vw7VrsvlLC/fUis+iYtf2gK3zJkBNzXuoHG7zEuNonRCNSzzzzP2WA9GmSncJzf4YjpOQsGjkHq8ghswN1gqgb9/oUSyTmCFOKPEAc+VIsPHJTnWMNG7ZwnHTIEIuKM= 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=JMun0koC; arc=none smtp.client-ip=209.85.215.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JMun0koC" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-5e4df21f22dso1864213a12.0 for ; Fri, 05 Apr 2024 16:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712361370; x=1712966170; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=4r+RoLEjqU5HCVgTykkvgt8C73/zrEV4zkUK1D/uSqA=; b=JMun0koCqDkQPhTnkp6I1SPQCFzxwOWaNnzUwUmdLavH1PAr4gXP2TXExbRYZErwiM du/aPi6/wrBL5y7nIUQYFhdKXk9go3E1y+1/r0vh0P/HxRbw5ITCTF4Eb2909mNX0a/M jnkLMwYkZ5oT0aS7O+eEzkku/GZLVoA6zXln8L6P/jypNYj7LBt1huHyJj7s3ss2EgAh oaJ/dw4/EkB9F9wbxWx/S1yCHoOZVFDqucI9hTdXOlcifFq1aSdvZAhTWMBDX+k+LHr4 tL50lq1g9h8aGfzTJJG13nQOTB6yW/TqbuDNxJjhFd52B0/zKqcexxp/5fYymPhpUT45 ouuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712361370; x=1712966170; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4r+RoLEjqU5HCVgTykkvgt8C73/zrEV4zkUK1D/uSqA=; b=tN1/3JiJan1FLs/8ii1KJP50o4xA5MmdP8bCI+aow5r3e/ybHiFKOQTGTGXdDEtIdC bUSpUaghZZq7UO6FtsKB/ujPYwcVoEF9Rgg96sY7FTUgNf1GFk9WmWh0YT+ByyvIv0+V +BcDmNtg7SNwy7R7VOPmANZWMEb4IhbhEyAHm7KRcVIPR2uwjRIVMBCSiYBvJeEKMa0e Qd3SXFKOMoBCLnOisFfjT7VPZLtme8yLMJ3JalBmsq8OnqkrOohVGG5bHLy8YdT3HvT/ WTuIxMScF7wTC4LiIWkEvuOwqgw2+M0eSuD50zm4CZtB0evVJyzianlXQYd7lJpV6dl3 gZVA== X-Forwarded-Encrypted: i=1; AJvYcCWvmtcM7w7P+jA6dnqSmDwEzt9hSLd1Ec1RaebzdL+rKCC8jtIwJ1RrQiuIgBrc0RvVRGH1JpH2s6oV+NE1sPlc8MqahJ+gGx+ZvO7w X-Gm-Message-State: AOJu0Yy5BRy316C5VwEKGtlK3+wN5Ua6cvC4t1fxPyuzQr6Mmqkfzr8a kCi6hy2E1WtyOekbXDtOG+iO9uKIwLbXwXfH64ZpATrLg7cXGfuT6+VamWSC9FtmxHg56YLoj1s yRw== X-Google-Smtp-Source: AGHT+IFUv4Qi4W+CY+cd4Q+YVTMoq2UI1X46jcY5pyYF/waoENQ2hrc55fo9CuZwfUzQglgS5ZSBR3X37bg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:ce14:0:b0:5dc:9e39:dbc7 with SMTP id y20-20020a63ce14000000b005dc9e39dbc7mr12081pgf.6.1712361369977; Fri, 05 Apr 2024 16:56:09 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 5 Apr 2024 16:55:54 -0700 In-Reply-To: <20240405235603.1173076-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405235603.1173076-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405235603.1173076-2-seanjc@google.com> Subject: [PATCH 01/10] KVM: x86: Snapshot if a vCPU's vendor model is AMD vs. Intel compatible From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jim Mattson , Like Xu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add kvm_vcpu_arch.is_amd_compatible to cache if a vCPU's vendor model is compatible with AMD, i.e. if the vCPU vendor is AMD or Hygon, along with helpers to check if a vCPU is compatible AMD vs. Intel. To handle Intel vs. AMD behavior related to masking the LVTPC entry, KVM will need to check for vendor compatibility on every PMI injection, i.e. querying for AMD will soon be a moderately hot path. Note! This subtly (or maybe not-so-subtly) makes "Intel compatible" KVM's default behavior, both if userspace omits (or never sets) CPUID 0x0 and if userspace sets a completely unknown vendor. One could argue that KVM should treat such vCPUs as not being compatible with Intel *or* AMD, but that would add useless complexity to KVM. KVM needs to do *something* in the face of vendor specific behavior, and so unless KVM conjured up a magic third option, choosing to treat unknown vendors as neither Intel nor AMD means that checks on AMD compatibility would yield Intel behavior, and checks for Intel compatibility would yield AMD behavior. And that's far worse as it would effectively yield random behavior depending on whether KVM checked for AMD vs. Intel vs. !AMD vs. !Intel. And practically speaking, all x86 CPUs follow either Intel or AMD architecture, i.e. "supporting" an unknown third architecture adds no value. Deliberately don't convert any of the existing guest_cpuid_is_intel() checks, as the Intel side of things is messier due to some flows explicitly checking for exactly vendor=3D=3DIntel, versus some flows assuming anything that isn't "AMD compatible" gets Intel behavior. The Intel code will be cleaned up in the future. Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/cpuid.c | 1 + arch/x86/kvm/cpuid.h | 10 ++++++++++ arch/x86/kvm/mmu/mmu.c | 2 +- arch/x86/kvm/x86.c | 2 +- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 16e07a2eee19..6efd1497b026 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -855,6 +855,7 @@ struct kvm_vcpu_arch { int cpuid_nent; struct kvm_cpuid_entry2 *cpuid_entries; struct kvm_hypervisor_cpuid kvm_cpuid; + bool is_amd_compatible; =20 /* * FIXME: Drop this macro and use KVM_NR_GOVERNED_FEATURES directly diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index bfc0bfcb2bc6..77352a4abd87 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -376,6 +376,7 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *v= cpu) =20 kvm_update_pv_runtime(vcpu); =20 + vcpu->arch.is_amd_compatible =3D guest_cpuid_is_amd_or_hygon(vcpu); vcpu->arch.maxphyaddr =3D cpuid_query_maxphyaddr(vcpu); vcpu->arch.reserved_gpa_bits =3D kvm_vcpu_reserved_gpa_bits_raw(vcpu); =20 diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h index 856e3037e74f..23dbb9eb277c 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -120,6 +120,16 @@ static inline bool guest_cpuid_is_intel(struct kvm_vcp= u *vcpu) return best && is_guest_vendor_intel(best->ebx, best->ecx, best->edx); } =20 +static inline bool guest_cpuid_is_amd_compatible(struct kvm_vcpu *vcpu) +{ + return vcpu->arch.is_amd_compatible; +} + +static inline bool guest_cpuid_is_intel_compatible(struct kvm_vcpu *vcpu) +{ + return !guest_cpuid_is_amd_compatible(vcpu); +} + static inline int guest_cpuid_family(struct kvm_vcpu *vcpu) { struct kvm_cpuid_entry2 *best; diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 992e651540e8..bf4de6d7e39c 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4935,7 +4935,7 @@ static void reset_guest_rsvds_bits_mask(struct kvm_vc= pu *vcpu, context->cpu_role.base.level, is_efer_nx(context), guest_can_use(vcpu, X86_FEATURE_GBPAGES), is_cr4_pse(context), - guest_cpuid_is_amd_or_hygon(vcpu)); + guest_cpuid_is_amd_compatible(vcpu)); } =20 static void __reset_rsvds_bits_mask_ept(struct rsvd_bits_validate *rsvd_ch= eck, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 47d9f03b7778..ebcc12d1e1de 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3470,7 +3470,7 @@ static bool is_mci_status_msr(u32 msr) static bool can_set_mci_status(struct kvm_vcpu *vcpu) { /* McStatusWrEn enabled? */ - if (guest_cpuid_is_amd_or_hygon(vcpu)) + if (guest_cpuid_is_amd_compatible(vcpu)) return !!(vcpu->arch.msr_hwcr & BIT_ULL(18)); =20 return false; --=20 2.44.0.478.gd926399ef9-goog From nobody Sun Feb 8 06:21:43 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 D4DD33A8D0 for ; Fri, 5 Apr 2024 23:56:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361374; cv=none; b=HpIOybmLfecy+hJopgGG2GHHBDGgObnHU1OEo8jYDg7QpDWLBY55+u1hrg2OZyAkU637YXb0lASUqf+F51XwnQTz392b9TLzwVBVbxvQ5Cf+py1/9qhf7KhFFqh0vKPtUAYj2K91pP6eglMm+nd0LofOJuEKY0EVLA9aqv+L5x8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361374; c=relaxed/simple; bh=xbZiBhFR1GD8yrF6sLlU6H1LX9EPZovTo0hzoXLG8aU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Lf18f5UF0LvO680ex/DvUuR/ODK+O4mGfJ4yea/Qflu0CJSG0xof0SDwNUD6TxV0DeCPY5VQMoqxVemfmcX2K+8QXl36eogs5TSaxAOlB+mWmGzaFm9mS5l+ofb77GeVqI+5YIkLtEc7j7ClSZK8QVCN/f1y2kCfGrrRISLLNPs= 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=exk7qQwt; arc=none smtp.client-ip=209.85.128.201 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="exk7qQwt" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60cc00203faso46402017b3.2 for ; Fri, 05 Apr 2024 16:56:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712361372; x=1712966172; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=A9lrggeLpLCqzlw5rBZRk9JnCRZ4h79aA0odPmKt0/Y=; b=exk7qQwt2tFgGQFALCYzNz62cfq1uCdAj2elVfWgXOU5ISBdrUO9XBHUtHlG/s0D15 ysNo6oRJkJm2J1A6jj9OXv15OdetgJFvuHR9wnPurMsNVqv2ksLvyndqeZ7e7LUhKxlu Cz7gryjgRzcd8z7ONh11dR0ICAvgNaH1z7D+5kvIRikBh8fP+QKXPHtv+Wx31aosjZbO 9RwjostrYObLlaa+LSGKuSDtxbHK50JwNwPAUPIoKJO5gw8n7+/iB7Mi/t251t2sra8c Yf62OpIU5LkyTvvQL52MaVdU/DfbHTWutpgmSI9LTnWzlO2vdqCShEy6li0aEs1q5agf 085A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712361372; x=1712966172; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=A9lrggeLpLCqzlw5rBZRk9JnCRZ4h79aA0odPmKt0/Y=; b=Vp+UVB4Q8BtofA3X+qyUL+PuTh7pLbY6axDrp2O/wGHHZa7jZMATpkZnFWujbv8HfK 0CmXILsZe9ddycy7DMVoNjrYMptaHRGE7SNcGiCtjwTV+eo9uzX4L9ALiOMPe8k+3G3+ A40PG4B0CcRvQ/MP5wOy11tSRrxejLP3KShb9QUqS+fIBkgpoMatpA4yYs/NXAWXR3gr aOkfac+bHeAgukO7U7hrtVaOGSKR2qLa3NfutUXqMuiPWHb+lDoSZhPl9szlTbfl4q6c FbA00Qm3wfVgK4crK+xYHPd41HJGls8nSMqxIGsL7NO3bxMHbjuLXlz87wlitRcuW+2Z CftA== X-Forwarded-Encrypted: i=1; AJvYcCXMtGX9o+jLmRjvFQNM8gfu1GO7p4aDeDm+YkexFHVA5yo2B9O7tQhNACAx6MEHFOor8hB6o4bNaGBA8bbEEnW2N94DLa7rAK+a4HNk X-Gm-Message-State: AOJu0Yyn93DK7CO3J183XheydY6pcJK1PbfVMNXIDghI3y3a40SsV1Y+ oRQZ6+M5uzJJjY4OYGz4Sjl5NzY56kQsbLntm5lk9jeV2NiBktZCiOhtE6koTtFHW4EFQCdh0uq Tgg== X-Google-Smtp-Source: AGHT+IHxX7pBb2sUjx5QNvzOVxofCju8D1fTDdX9zEtiJP7uYXUfRHPoMknf9MR/69TMULXioiY7atftN3k= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a5b:944:0:b0:dcd:4286:4498 with SMTP id x4-20020a5b0944000000b00dcd42864498mr170623ybq.6.1712361371935; Fri, 05 Apr 2024 16:56:11 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 5 Apr 2024 16:55:55 -0700 In-Reply-To: <20240405235603.1173076-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405235603.1173076-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405235603.1173076-3-seanjc@google.com> Subject: [PATCH 02/10] KVM: x86/pmu: Do not mask LVTPC when handling a PMI on AMD platforms From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jim Mattson , Like Xu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Sandipan Das On AMD and Hygon platforms, the local APIC does not automatically set the mask bit of the LVTPC register when handling a PMI and there is no need to clear it in the kernel's PMI handler. For guests, the mask bit is currently set by kvm_apic_local_deliver() and unless it is cleared by the guest kernel's PMI handler, PMIs stop arriving and break use-cases like sampling with perf record. This does not affect non-PerfMonV2 guests because PMIs are handled in the guest kernel by x86_pmu_handle_irq() which always clears the LVTPC mask bit irrespective of the vendor. Before: $ perf record -e cycles:u true [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.001 MB perf.data (1 samples) ] After: $ perf record -e cycles:u true [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (19 samples) ] Fixes: a16eb25b09c0 ("KVM: x86: Mask LVTPC when handling a PMI") Cc: stable@vger.kernel.org Signed-off-by: Sandipan Das Reviewed-by: Jim Mattson [sean: use is_intel_compatible instead of !is_amd_or_hygon()] Signed-off-by: Sean Christopherson --- arch/x86/kvm/lapic.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index cf37586f0466..ebf41023be38 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2776,7 +2776,8 @@ int kvm_apic_local_deliver(struct kvm_lapic *apic, in= t lvt_type) trig_mode =3D reg & APIC_LVT_LEVEL_TRIGGER; =20 r =3D __apic_accept_irq(apic, mode, vector, 1, trig_mode, NULL); - if (r && lvt_type =3D=3D APIC_LVTPC) + if (r && lvt_type =3D=3D APIC_LVTPC && + guest_cpuid_is_intel_compatible(apic->vcpu)) kvm_lapic_set_reg(apic, APIC_LVTPC, reg | APIC_LVT_MASKED); return r; } --=20 2.44.0.478.gd926399ef9-goog From nobody Sun Feb 8 06:21:43 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 3EDBA45BE2 for ; Fri, 5 Apr 2024 23:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361375; cv=none; b=oGSDwZlNzgnUmJiZ4I5tnnSRvTjn7CCwOSzEMlrBmZ5lLC+ViZk4iKbh17lkTwgoUg1Mx/wSYrBPsMZhRKBSCF22J5iH253X6jZg8dNRv18dMgAK0kQxryHma5d3yeBaCDlRQAGiqbQ89wq2g2EHojvZTY1gZCs5GoQzxySreS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361375; c=relaxed/simple; bh=chnMm1zFatZ8q6GaXGi1GZwfE6vOSQp47VdBoBbf3AE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QdwxYeECyf6wdfdBTSp5Y9Mn0wt/i9/0w89741fk5WU4E66aZr4eN+4N+JP/25K46dK5V7H4iz8F0EStr6daKYvKDoz8JUWtn3a5m+GLvyfgDJhbiQE9mC8rG3qL5OXyvRUfcWFnh0lZ2RUSY621aqnxxth6XbUAfiWV+b1E8mM= 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=wBirsjR1; arc=none smtp.client-ip=209.85.216.74 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wBirsjR1" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2a48ed89c7eso580863a91.3 for ; Fri, 05 Apr 2024 16:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712361373; x=1712966173; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=FffwbB6LnatDKMg9SsqQhArJTyGAeiJWu5lvAsN6Mjk=; b=wBirsjR1NQA8cfl+0rDDEQQTvtCOhHgWFQOvuigI9slaJg3pojGmoWmYEFG+toUt2U ktmEjlG2SZVoKsvaFfv7kzjIyoiDLpzWDkEpJjYSCLrO1p1izH+LTZVzbPa+xreddn1r V6A8boPyQdpB4AsPHmaQFRDhBhM6iz/7wXLM8GxGV4fR3LtEhoubtGk7uvOlgim7PG+W ZgksZRd/M41UcpP56SCXRXXuMvcw2RSKuFWXO68p1CQk3l9K8WxOOfU4RSai4W/Rj0vx 0+zibG0725gigIv/EtMiaYqKCHsrqiVCYhnv6nGO/C4ZETH6nZBBTo/rbWolKCirLVmI DSLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712361373; x=1712966173; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FffwbB6LnatDKMg9SsqQhArJTyGAeiJWu5lvAsN6Mjk=; b=T1Rsz8vYTDu/1BOi2Crub2+9igXfMJYVRMVku/W2g+4MUps3OH7HrdyLvVazkCnydJ mLZvb4zYDmTSDmcywcCg10uu8RKDeZuCNLj5euh6msJGv7ZQ4z8FdXfFyBQlmnIhga8c MkcphFS4yCNMYhDVpogTpmQWtgREGHRvvoEVr5vbuRsu+TV9PCKDSNr8asaGel5dkmjs BsmJaDsQECSSwv1uqtuLSsUNPvYIz8LfJtx3C02TFCHHnsEIS13Ruv4n1anvffhmrvXl VoOv1t20caIWRfYVz4DWEDDdxzuGbNlVe0mFuXAsKkGDT7H8Tettb1w4J7HENvttry9x soyw== X-Forwarded-Encrypted: i=1; AJvYcCVan9NcVAIK06pDft/Dn9lIy9pwcFsqs1qBeqZUW5N4zXRNRnS+blgbQQD3baSGbVy8vLIEiLMs929y/n1IrwifzTB4D0VOcn/980vv X-Gm-Message-State: AOJu0Yxav5lHypJYUmmCLFNQ87FPZnqoyEFO1/xAYLBZPuUa0RqYWH4J QyYn/iqRVB9OEhaBkC/BzIEf3hobjVay5dwSc6yX1b9GldIrX+hq4eOORMCOjSEMkhobTc13kOw F8w== X-Google-Smtp-Source: AGHT+IH9aecytVAOtnV2yNzg2I3ctJJZWmYrY4cvrhScbFQqL+6+y5ypppJF5bqHYcJe2XUZwFiInnFZSBA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:d4c1:b0:1e3:d0fa:dedf with SMTP id o1-20020a170902d4c100b001e3d0fadedfmr49827plg.4.1712361373581; Fri, 05 Apr 2024 16:56:13 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 5 Apr 2024 16:55:56 -0700 In-Reply-To: <20240405235603.1173076-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405235603.1173076-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405235603.1173076-4-seanjc@google.com> Subject: [PATCH 03/10] KVM: x86/pmu: Squash period for checkpointed events based on host HLE/RTM From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jim Mattson , Like Xu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Zero out the sampling period for checkpointed events if the host supports HLE or RTM, i.e. supports transactions and thus checkpointed events, not based on whether the vCPU vendor model is Intel. Perf's refusal to allow a sample period for checkpointed events is based purely on whether or not the CPU supports HLE/RTM transactions, i.e. perf has no knowledge of the vCPU vendor model. Note, it is _extremely_ unlikely that the existing code is a problem in real world usage, as there are far, far bigger hurdles that would need to be cleared to support cross-vendor vPMUs. The motivation is mainly to eliminate the use of guest_cpuid_is_intel(), in order to get to a state where KVM pivots on AMD vs. Intel compatibility, i.e. doesn't check for exactly vendor=3D=3DIntel except in rare circumstances (i.e. for CPU quirks= ). Cc: Like Xu Signed-off-by: Sean Christopherson --- arch/x86/kvm/pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index c397b28e3d1b..8c3564917953 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -194,7 +194,7 @@ static int pmc_reprogram_counter(struct kvm_pmc *pmc, u= 32 type, u64 config, attr.sample_period =3D get_sample_period(pmc, pmc->counter); =20 if ((attr.config & HSW_IN_TX_CHECKPOINTED) && - guest_cpuid_is_intel(pmc->vcpu)) { + (boot_cpu_has(X86_FEATURE_RTM) || boot_cpu_has(X86_FEATURE_HLE))) { /* * HSW_IN_TX_CHECKPOINTED is not supported with nonzero * period. Just clear the sample period so at least --=20 2.44.0.478.gd926399ef9-goog From nobody Sun Feb 8 06:21:43 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 1D1264AEF7 for ; Fri, 5 Apr 2024 23:56:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361377; cv=none; b=oIsAsX3/3g0kLemJ4biaZInOLnhyVXSXApMW+fAFyHrTG1KWwWt1LQew1jvAKZzfUr3t/n5Fl/lFUMPJpP5aSjRCXecFXgJelkhc4WwfOva1n6qZF6TbwEFQsZMTlLW/DOSJjt/XUYHtmaQazdbnDZGAsyDxvgDwGDfH+Chk9+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361377; c=relaxed/simple; bh=torl8B7uqungrFtG8/K2MGtZpZ3nwc8GBWa8Ngm8w58=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ESvN+zYtKER276kVYph6vxOkW39M9uKfXqZ+XP+M+xk9bC071TQEtgkW778PQnD7C6I+4oYSi3xr6WTrkn3cBVi9RQXTLbCLZJLefzf1qIZSEx3cTxziVVwdtt1jeOXobouJFx3fm/KzeCw2nFnd7KY8hrQxSB/hf7u+HpA7ESQ= 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=YjM4qu6B; arc=none smtp.client-ip=209.85.215.201 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YjM4qu6B" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-5e4df21f22dso1864240a12.0 for ; Fri, 05 Apr 2024 16:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712361375; x=1712966175; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=33EqBa4idiXBlKLk1bB/GrgkrHxm1+OWlCnF+mCuARU=; b=YjM4qu6B/aBJINhFpoKfYsuPWqCMVqcrTH5fx8t4TMv9AdtFh+/Ypx0qNqXS+M5PtQ 5UGZxAmDheyelzx0x77277dHpSgHxQEIeVAkmuvRv2XRsSovDySxorN1UYqbcGhjruXx SNsyPz5GES0JqsBq7dThm+1PO+OS8Ud5Bw5Hjr8dEAtv1t5BdMO2Z4Anu4vymuwbMO3J GVZC2RqEdOuBbcH6yf0scaajChowARibphLngvTRO3es93MtS4KkL6Nm63hHoX7P94KC QwyHr3rY9hRrR+naFKU6FKaEtZ1uJEW2BaBsFnAdxFd9Z/2P0JvpVJN+4BGrUwH6H8rY FiTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712361375; x=1712966175; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=33EqBa4idiXBlKLk1bB/GrgkrHxm1+OWlCnF+mCuARU=; b=jvjRBRymKJ4WANVVilEXnQ/FfO/JHKxCgFd47qlMh+kBaFDKVqaMcFBv8pAPVLHP0I gzBWAijWKSyb5uIgwoQuSSRLc1D1Jimyej10nHYUyznP8Ld0WLd6TNs8uL9M8dMIdQ8Z tAd1+iuWe704ruiCvHPXZ9xrk2peB2FHOZOW4osfftUQHbNIzOGkb+fN74ec424BVOAM pwFhYfOIcTnePlnmhb98G9FwqA+UHrbjJKVDmYvJEqVxX5+256Ga5sMB79OrFe9aBBi5 HJkBp2l8UKLrFDYjseXXmSx7omurCb1GTQm63NFerTOn2METCRK0mrVyypEEKvDcX54M PHsg== X-Forwarded-Encrypted: i=1; AJvYcCWJ/Yrj7lc3xMGDx8fB3FdbcGwmiiwHqZT0Y4+ErLbaJJsB5n5gGOMN6P6FBTQKYPEzoHBMw+r5iPmZ4foyHeKcDvucMETuviWYxNf9 X-Gm-Message-State: AOJu0Yy3CmB59Yh7mpdkEVnaXEeO+/pUswGW7A50kGCSTqlNauBk4kEc Jio7GviXNsBd0QPgDJywww0KYt4XW+/zLLZZ5fB9hCSuZLWElNpP1JoZ9VX6/4iXhUbfUViHmv8 9Vw== X-Google-Smtp-Source: AGHT+IF/gFn9ejmWPWLzczLWx54pSx+kzM32Cqmgdh9HBzRcO6XJurThB4YInPhTEun/QvpjJo/Q33QHoJ8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a65:6a50:0:b0:5e4:2b26:960a with SMTP id o16-20020a656a50000000b005e42b26960amr12959pgu.4.1712361375228; Fri, 05 Apr 2024 16:56:15 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 5 Apr 2024 16:55:57 -0700 In-Reply-To: <20240405235603.1173076-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405235603.1173076-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405235603.1173076-5-seanjc@google.com> Subject: [PATCH 04/10] KVM: x86: Apply Intel's TSC_AUX reserved-bit behavior to Intel compat vCPUs From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jim Mattson , Like Xu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extend Intel's check on MSR_TSC_AUX[63:32] to all vCPU models that are Intel compatible, i.e. aren't AMD or Hygon in KVM's world, as the behavior is architectural, i.e. applies to any CPU that is compatible with Intel's architecture. Applying the behavior strictly to Intel wasn't intentional, KVM simply didn't have a concept of "Intel compatible" as of commit 61a05d444d2c ("KVM: x86: Tie Intel and AMD behavior for MSR_TSC_AUX to guest CPU model"). Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ebcc12d1e1de..d9719141502a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1883,11 +1883,11 @@ static int __kvm_set_msr(struct kvm_vcpu *vcpu, u32= index, u64 data, * incomplete and conflicting architectural behavior. Current * AMD CPUs completely ignore bits 63:32, i.e. they aren't * reserved and always read as zeros. Enforce Intel's reserved - * bits check if and only if the guest CPU is Intel, and clear - * the bits in all other cases. This ensures cross-vendor - * migration will provide consistent behavior for the guest. + * bits check if the guest CPU is Intel compatible, otherwise + * clear the bits. This ensures cross-vendor migration will + * provide consistent behavior for the guest. */ - if (guest_cpuid_is_intel(vcpu) && (data >> 32) !=3D 0) + if (guest_cpuid_is_intel_compatible(vcpu) && (data >> 32) !=3D 0) return 1; =20 data =3D (u32)data; --=20 2.44.0.478.gd926399ef9-goog From nobody Sun Feb 8 06:21:43 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 B25FC4F201 for ; Fri, 5 Apr 2024 23:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361379; cv=none; b=SO60B5I4akR3L7OhmDjyQKfEO6wDZwR2cS7wJn67St/bWf/iA792hKxkJKoE6c85lsE90ZHWps33PQ3pAufHFZBujOVOrRg0S2mDgEw/PGRxTVGPiHx1C9H6CJMqvT83UHy8/UYe/5itcrxXhYO3s8y3T+gkvD8511OVEUAAJ2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361379; c=relaxed/simple; bh=AljPKUJ52FByOX5/k02Ea5UG3D0X4h61RvjHmr0q7D4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=A3ueTU2991TDZAhyZv52/Nq9Sbhd88d5epMD7g3yXj5WL29hAOjwO9XpMBbDULedbr6EpR10jL5gOVVqi8GgsYRpe5oxfvkmSCBfWNwKRqlQF0yF2GTJedKw6BlhYSNbrsxK06dCF1QaeXQ1nuyQymdcjf9LzBFCJCslCk8sjUw= 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=UI6QV7zx; arc=none smtp.client-ip=209.85.216.74 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UI6QV7zx" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2a2fe3c35a1so1349098a91.0 for ; Fri, 05 Apr 2024 16:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712361377; x=1712966177; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=S44Se3gmnxsaX6emvGqSIzjFMncY1DPTABLM/XCmeAQ=; b=UI6QV7zxLU3TN6Zq2Zx1ain9zYLouuatuJmohYX4Bgu8bdkE3Nhw8AQ647N2pI2Yfs 2KR5hUk+6vQ0Co2MAbQrHteIvQYcuYHr/D0R2zR2K+WE/fU/NYQf0D9dPzk5Wtb23ovv ox2StBaelZQCOXWG1UR4LqJ2dP3p/v5bUF3epVV8XQ7prQcueXBLu9aNoq3rAQyAGJbW bDnJ089S5fkT7g02XLLJthPqiMCJ+wWL42XHViAn7YDWXKYLG9Wy0RnhYUNIrv8XbPFJ oU5WyMEoH4A0PAU0+UBrpbdMU03MS5K25zO0p/UIs7BIazAJqBvrRHWWNFk8qyGlgczT hdVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712361377; x=1712966177; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=S44Se3gmnxsaX6emvGqSIzjFMncY1DPTABLM/XCmeAQ=; b=alWja3PFDzwvdyMj7NguqE57ihGTKxY++2ASQKLCiCa/B4Qc/x4aEcEx0yUKOp4gxk Q7UUBIZsuBEZHoO3fkyes4SKF2Oplv05fUGBwwWO15/rstNYMRAUuqNnLJFJAKzLYtPQ L4zKN855QaiLAyXcoqnQ6JrmKVPWhwIF62sSkXBgdcpDOR54tXoHptJAkofCUNVJzPUv wC7QPj2q88mpbEC2FPYiWzenkk2yJvvVrBjNtYZdZm/MT+6/V2PK40COXb2bqlbWrbDX yHkpXcw2NJ4RGiWXNJKTC0Uku1wMwOzcxXxP/u/5/5KSaFG65EydQ3sBqKYhajwcmVTx eiNg== X-Forwarded-Encrypted: i=1; AJvYcCUkknEPEnsADwnLNadFjIj41dmAI5cXSWMdKAIvygZP0WL8D+ZNFb6CXuVeLDuPA0MIjEKSwH++BPJhcvpxainXwJwjllzKkK9L4TJv X-Gm-Message-State: AOJu0YzHW048y/zO+AOtKPRwVvtmeDSaM8u6RYT2FsEF1tN2ZxKTD393 KJitGy43dapuwtHoyK9pcSyYElnPuhz/DVufp/l9bbpN8MxIZ+zgHcAK5FW8PN276NCrgOR6fpN glw== X-Google-Smtp-Source: AGHT+IFSoeSfmhaaetrSt3kO581BOnUyFdA9ebGWFCQtIhz7u3HLEM4R1TrX5WUOnjWB2WCASTfw9K7dxFg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:214:b0:2a0:40df:2f57 with SMTP id fy20-20020a17090b021400b002a040df2f57mr8680pjb.6.1712361376966; Fri, 05 Apr 2024 16:56:16 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 5 Apr 2024 16:55:58 -0700 In-Reply-To: <20240405235603.1173076-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405235603.1173076-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405235603.1173076-6-seanjc@google.com> Subject: [PATCH 05/10] KVM: x86: Inhibit code #DBs in MOV-SS shadow for all Intel compat vCPUs From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jim Mattson , Like Xu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Treat code #DBs as inhibited in MOV/POP-SS shadows for vCPU models that are Intel compatible, not just strictly vCPUs with vendor=3D=3DIntel. The behavior is explicitly called out in the SDM, and thus architectural, i.e. applies to all CPUs that implement Intel's architecture, and isn't a quirk that is unique to CPUs manufactured by Intel: However, if an instruction breakpoint is placed on an instruction located immediately after a POP SS/MOV SS instruction, the breakpoint will be suppressed as if EFLAGS.RF were 1. Applying the behavior strictly to Intel wasn't intentional, KVM simply didn't have a concept of "Intel compatible" as of commit baf67ca8e545 ("KVM: x86: Suppress code #DBs on Intel if MOV/POP SS blocking is active"). Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d9719141502a..8ea6f4fc910f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8984,19 +8984,17 @@ EXPORT_SYMBOL_GPL(kvm_skip_emulated_instruction); =20 static bool kvm_is_code_breakpoint_inhibited(struct kvm_vcpu *vcpu) { - u32 shadow; - if (kvm_get_rflags(vcpu) & X86_EFLAGS_RF) return true; =20 /* - * Intel CPUs inhibit code #DBs when MOV/POP SS blocking is active, - * but AMD CPUs do not. MOV/POP SS blocking is rare, check that first - * to avoid the relatively expensive CPUID lookup. + * Intel compatible CPUs inhibit code #DBs when MOV/POP SS blocking is + * active, but AMD compatible CPUs do not. */ - shadow =3D static_call(kvm_x86_get_interrupt_shadow)(vcpu); - return (shadow & KVM_X86_SHADOW_INT_MOV_SS) && - guest_cpuid_is_intel(vcpu); + if (!guest_cpuid_is_intel_compatible(vcpu)) + return false; + + return static_call(kvm_x86_get_interrupt_shadow)(vcpu) & KVM_X86_SHADOW_I= NT_MOV_SS; } =20 static bool kvm_vcpu_check_code_breakpoint(struct kvm_vcpu *vcpu, --=20 2.44.0.478.gd926399ef9-goog From nobody Sun Feb 8 06:21:43 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 F3DAF55E6B for ; Fri, 5 Apr 2024 23:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361382; cv=none; b=WUwhTUfYeO67QkoSHDOyhOC7ncObJAx5jchxTj0RGhP1H7ryxbYa4Or+7o8eZzBLaenBVDDabyACt1X0P9Q8AZhZtykbmhY/XF+w4nQ6YqclyCAtYxj2LmMNFUV+Cug9igbwQucD8zIFdnlvAq9JbeAHkBA4Mp3Av/GlLiw2bXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361382; c=relaxed/simple; bh=SjL/u1m2Yv/QRFJSraA0c31ZdkVwSK2OEnA/q8Dl4T4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VCqTJP35fZQTXklbuFIaB3pwec7NldHhZJ7GE1zFodeNwaq/Con3sVTSE6EZXE6xvdqRz+tUT0CmQ286kGK7LMPhCEGj5Ivh8gRx6yBanDTiickYrl+4S7dFCDGP+0bFQRBP3JbDBAIeGy9kNMlyASk4jAk2pX7uXtvkCkNugUA= 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=p3kzgsFL; arc=none smtp.client-ip=209.85.210.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="p3kzgsFL" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-6ed0fd8a612so129312b3a.1 for ; Fri, 05 Apr 2024 16:56:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712361379; x=1712966179; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=dc7nqkLts1TDH13FpbqcVsZjCzE8xryBRB3cO5xkb48=; b=p3kzgsFLGmqGYFnyqpmXELrBWRsKSbHyiNDaoqtneGEwuUWA9jZBFop+TJZ1wjhWwI b7OcfZZ/ljjB+WqWG8XTblOQwVOc4TmK+0Nl+CeMbLLZvg2XPvInJQSA8E0kJx3DyppL cLhiKiG/X7oQ0TN/RV2QWYUDw09WFG3VMT8Pa6RpvCly3j2E2i+WyLyawuXAXgOLuOib KPd233oXdjw6xKBPgFnIuKSfThiYFb6YsWDE85MYhM3HCf6p4iIoDFnW8sienWIzlGnx 5Ktx9z5f8wQST1+6S8PHe0tDqql89yC28Xw98wzM2L1mm6ytLLFRrLYmQUaWuPz+wl+l iClA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712361379; x=1712966179; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dc7nqkLts1TDH13FpbqcVsZjCzE8xryBRB3cO5xkb48=; b=KOJdOEtXQBWyxdbdraHPuJrDy+lPvd78hV4UI0PPqunUvr1+S8zS1x4u6RjzG+BuEb 6gZikHHEL6J6CTIQdaeZuuuog5+qa9spajQdvowXIGAJGuyBVgIS/ge2726q2zhCwOlj vn8cH1kL/aREQzcJ1yHvOSIXUXXPhCtKxzqGRCJi4W7WtBmOF6C0JFs+KAttczVSQ3YI Iz5HsYBWQmUoUBxAN78mSbEW2KpcE5Mn/G22F5mob8lJVnSox3qctycJlNjA1BSUDMI/ 0KQAk0GNmTQAwRdxFMOLvj1FZ8YpR8R6FqtB//GyT7oXdOsDJ9AtoSry993tOZ22Wexe EUlw== X-Forwarded-Encrypted: i=1; AJvYcCVHg4J92ZPfLQ7S/Q1ocIWkv8FV7P+fmoZ5djHcHRZ5rwOXSuSmREKZQw0dtBr9396NuBtc4tf+kSmr54oC97y9VOszfjW8jPK1TH0M X-Gm-Message-State: AOJu0Yysqn2tTf37LPHsWs2jnv1CwLuCOe1qog4UVTOWayAp2cfLoe1M C10wvPD97AAsGJ1YWwSe2qHysn19+mWbWuI6mZnmu4vcnb7tQiDrN5yGUUDxBaCJo0OZOjP+tAg 3pg== X-Google-Smtp-Source: AGHT+IHgLgfMouF5Fr9j95xTXSHpDYGHdGZywxLUroJfpTjaxfmeAcot/L0Rnzk/8SgWunlRcEKDGyS7IR8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:92a6:b0:6ea:d61b:ec8d with SMTP id jw38-20020a056a0092a600b006ead61bec8dmr235502pfb.5.1712361379288; Fri, 05 Apr 2024 16:56:19 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 5 Apr 2024 16:55:59 -0700 In-Reply-To: <20240405235603.1173076-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405235603.1173076-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405235603.1173076-7-seanjc@google.com> Subject: [PATCH 06/10] KVM: x86: Use "is Intel compatible" helper to emulate SYSCALL in !64-bit From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jim Mattson , Like Xu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use guest_cpuid_is_intel_compatible() to determine whether SYSCALL in 32-bit Protected Mode (including Compatibility Mode) should #UD or succeed. The existing code already does the exact equivalent of guest_cpuid_is_intel_compatible(), just in a rather roundabout way. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/emulate.c | 45 ++++++++------------------------------ arch/x86/kvm/kvm_emulate.h | 1 + arch/x86/kvm/x86.c | 6 +++++ 3 files changed, 16 insertions(+), 36 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 5d4c86133453..1fb73d96bdf0 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2363,41 +2363,6 @@ static bool vendor_intel(struct x86_emulate_ctxt *ct= xt) return is_guest_vendor_intel(ebx, ecx, edx); } =20 -static bool em_syscall_is_enabled(struct x86_emulate_ctxt *ctxt) -{ - const struct x86_emulate_ops *ops =3D ctxt->ops; - u32 eax, ebx, ecx, edx; - - /* - * syscall should always be enabled in longmode - so only become - * vendor specific (cpuid) if other modes are active... - */ - if (ctxt->mode =3D=3D X86EMUL_MODE_PROT64) - return true; - - eax =3D 0x00000000; - ecx =3D 0x00000000; - ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx, true); - /* - * remark: Intel CPUs only support "syscall" in 64bit longmode. Also a - * 64bit guest with a 32bit compat-app running will #UD !! While this - * behaviour can be fixed (by emulating) into AMD response - CPUs of - * AMD can't behave like Intel. - */ - if (is_guest_vendor_intel(ebx, ecx, edx)) - return false; - - if (is_guest_vendor_amd(ebx, ecx, edx) || - is_guest_vendor_hygon(ebx, ecx, edx)) - return true; - - /* - * default: (not Intel, not AMD, not Hygon), apply Intel's - * stricter rules... - */ - return false; -} - static int em_syscall(struct x86_emulate_ctxt *ctxt) { const struct x86_emulate_ops *ops =3D ctxt->ops; @@ -2411,7 +2376,15 @@ static int em_syscall(struct x86_emulate_ctxt *ctxt) ctxt->mode =3D=3D X86EMUL_MODE_VM86) return emulate_ud(ctxt); =20 - if (!(em_syscall_is_enabled(ctxt))) + /* + * Intel compatible CPUs only support SYSCALL in 64-bit mode, whereas + * AMD allows SYSCALL in any flavor of protected mode. Note, it's + * infeasible to emulate Intel behavior when running on AMD hardware, + * as SYSCALL won't fault in the "wrong" mode, i.e. there is no #UD + * for KVM to trap-and-emulate, unlike emulating AMD on Intel. + */ + if (ctxt->mode !=3D X86EMUL_MODE_PROT64 && + ctxt->ops->guest_cpuid_is_intel_compatible(ctxt)) return emulate_ud(ctxt); =20 ops->get_msr(ctxt, MSR_EFER, &efer); diff --git a/arch/x86/kvm/kvm_emulate.h b/arch/x86/kvm/kvm_emulate.h index 5382646162a3..0f71d4699b78 100644 --- a/arch/x86/kvm/kvm_emulate.h +++ b/arch/x86/kvm/kvm_emulate.h @@ -222,6 +222,7 @@ struct x86_emulate_ops { bool (*guest_has_movbe)(struct x86_emulate_ctxt *ctxt); bool (*guest_has_fxsr)(struct x86_emulate_ctxt *ctxt); bool (*guest_has_rdpid)(struct x86_emulate_ctxt *ctxt); + bool (*guest_cpuid_is_intel_compatible)(struct x86_emulate_ctxt *ctxt); =20 void (*set_nmi_mask)(struct x86_emulate_ctxt *ctxt, bool masked); =20 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8ea6f4fc910f..ac607b41890e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8505,6 +8505,11 @@ static bool emulator_guest_has_rdpid(struct x86_emul= ate_ctxt *ctxt) return guest_cpuid_has(emul_to_vcpu(ctxt), X86_FEATURE_RDPID); } =20 +static bool emulator_guest_cpuid_is_intel_compatible(struct x86_emulate_ct= xt *ctxt) +{ + return guest_cpuid_is_intel_compatible(emul_to_vcpu(ctxt)); +} + static ulong emulator_read_gpr(struct x86_emulate_ctxt *ctxt, unsigned reg) { return kvm_register_read_raw(emul_to_vcpu(ctxt), reg); @@ -8603,6 +8608,7 @@ static const struct x86_emulate_ops emulate_ops =3D { .guest_has_movbe =3D emulator_guest_has_movbe, .guest_has_fxsr =3D emulator_guest_has_fxsr, .guest_has_rdpid =3D emulator_guest_has_rdpid, + .guest_cpuid_is_intel_compatible =3D emulator_guest_cpuid_is_intel_compat= ible, .set_nmi_mask =3D emulator_set_nmi_mask, .is_smm =3D emulator_is_smm, .is_guest_mode =3D emulator_is_guest_mode, --=20 2.44.0.478.gd926399ef9-goog From nobody Sun Feb 8 06:21:43 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 C05A458AD2 for ; Fri, 5 Apr 2024 23:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361383; cv=none; b=UV3qBQ5zgHnOkDcJ77vZ+8CPLi8k4nb7Z2tB6mQD1pNNErjdNJCEurRwF3WuQZS6bHKYVFygCjVXhMKAZDZkj1Sreiht2cRpXB9sczzKROhhba9hctodeaf+eT571PK2sLNOnTH6DhsVRdKz9jT5HGvTbY+K+6eal/X8qV6/Jzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361383; c=relaxed/simple; bh=uTEAcElbjgc42YO5RZICLCtvkeeQwfPNpAbVw/4NQqI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=o2eYvyVnN373pUBidf1TwymvTROH3ozr7/7PVSNsrrA3fBbuMdv1ZXKszi8dynhTuuu/Way0HW83vcLhnelpxbTMgAGKeLEPtiXKQElqt3Cb7+RrsRgBGtjOZU7lwP/4pmabxDQu3uGPEb5SJdsvTyxJbOWxN7vVn156K8lfaK0= 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=nEsuPX5+; arc=none smtp.client-ip=209.85.216.73 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nEsuPX5+" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-29bf071cc04so2319254a91.0 for ; Fri, 05 Apr 2024 16:56:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712361381; x=1712966181; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=c9C5YQrHXZZ5HmBmRXt2H633vB/NFcbA0Pv9V/zyx9M=; b=nEsuPX5+3VN30T4oSk9YLixErBMogdK6GRAeSO8mgis2VkZ/+FJQFC1OcbtBAf3txp NMgc8jv6/NQX0b+plw8q95JHGpr5gdKx7yv/y3bQTyp+xfDKgkSwpBiDw0q3XqXGwlk/ QVNc4MBTC8hfhj7AN+V6K6s151xLEUTveYqi3SXVi6pZdwQwwG88liUOANFDEHVmBd4N OCAPNoT3W6natg255YndqwXx3jCZtOChhus54Ocanz3f9WZErfGnu+SqvJ1J8o4BhLly 4oRVRgZG9NQ0ie6021pzGYbxju8Iaa07L5KQGmzvn6FSl9Ziiu9FpsHegQBCFdFfAu6N sCbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712361381; x=1712966181; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=c9C5YQrHXZZ5HmBmRXt2H633vB/NFcbA0Pv9V/zyx9M=; b=jN5CSJsQTo5GpD+rtEhg5tWrW3l/mlIzG3u5UUL4WN13itqzmNzo9iV1FgaIUod+in rJ7k8u5ck8vBFaFDH2dlZQeKekSb3ZAAIZmk16JRzPpIKTKsepV2MiXNy82oHxkCiVGr d+n7S/+OrR43bBTgPxkwuZfaZShYKt5kNCBhpQSPa9FqRfX5zdgqkU4QzlL8m6GyMzt3 cDBv5ZzD2ShB96dBai/i+yKPIPRLUomSEVOtW0miolcFml+0Zduo+im6ggkCjBFG9rQN B1E7e8U9lmJUbj8SKt2Qz5Jo27i9s9gIyqx+EG78UOBh92gn+1km8mtfiRpbdoc5qjFY BKtg== X-Forwarded-Encrypted: i=1; AJvYcCXiJnXel7iHHC+z5HQmADtjMpwdQTqmwAkEck8pH/luD9CAS3B026cRaBMvzelwWwYwY0zOc9xQviZPnyRD3q7NhyxWvyOctE0Qhdh+ X-Gm-Message-State: AOJu0YzeiECVPgbcEx39ky1pqFAqFDlEMb2K3lVmzANSBl22I2eccoHO XbQLJ45hKG+Bgk3ev4hnGo7JknXg0QHbwnn1Vbw8z1qhB1feBaXw1/9lX1GA3AeGfj9CjcQBaT3 I1Q== X-Google-Smtp-Source: AGHT+IHs9jTGhTQuC9VHaf7pS6UP8HTmTzMNz8fgepBti3jcRSzoDy5YtVrLJpQTYgtMnhp00dCWO2H9Ryg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:ea01:b0:1e2:b75e:37b5 with SMTP id s1-20020a170902ea0100b001e2b75e37b5mr47992plg.2.1712361381133; Fri, 05 Apr 2024 16:56:21 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 5 Apr 2024 16:56:00 -0700 In-Reply-To: <20240405235603.1173076-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405235603.1173076-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405235603.1173076-8-seanjc@google.com> Subject: [PATCH 07/10] KVM: SVM: Emulate SYSENTER RIP/RSP behavior for all Intel compat vCPUs From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jim Mattson , Like Xu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Emulate bits 63:32 of the SYSENTER_R{I,S}P MSRs for all vCPUs that are compatible with Intel's architecture, not just strictly vCPUs that have vendor=3D=3DIntel. The behavior of bits 63:32 is architecturally defined in the SDM, i.e. not some uarch specific quirk of Intel CPUs. Signed-off-by: Sean Christopherson --- arch/x86/kvm/cpuid.h | 8 -------- arch/x86/kvm/svm/svm.c | 14 +++++++------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h index 23dbb9eb277c..03d015e9ce33 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -112,14 +112,6 @@ static inline bool guest_cpuid_is_amd_or_hygon(struct = kvm_vcpu *vcpu) is_guest_vendor_hygon(best->ebx, best->ecx, best->edx)); } =20 -static inline bool guest_cpuid_is_intel(struct kvm_vcpu *vcpu) -{ - struct kvm_cpuid_entry2 *best; - - best =3D kvm_find_cpuid_entry(vcpu, 0); - return best && is_guest_vendor_intel(best->ebx, best->ecx, best->edx); -} - static inline bool guest_cpuid_is_amd_compatible(struct kvm_vcpu *vcpu) { return vcpu->arch.is_amd_compatible; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index d1a9f9951635..e1266b023203 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1196,7 +1196,7 @@ static inline void init_vmcb_after_set_cpuid(struct k= vm_vcpu *vcpu) { struct vcpu_svm *svm =3D to_svm(vcpu); =20 - if (guest_cpuid_is_intel(vcpu)) { + if (guest_cpuid_is_intel_compatible(vcpu)) { /* * We must intercept SYSENTER_EIP and SYSENTER_ESP * accesses because the processor only stores 32 bits. @@ -2853,12 +2853,12 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struc= t msr_data *msr_info) break; case MSR_IA32_SYSENTER_EIP: msr_info->data =3D (u32)svm->vmcb01.ptr->save.sysenter_eip; - if (guest_cpuid_is_intel(vcpu)) + if (guest_cpuid_is_intel_compatible(vcpu)) msr_info->data |=3D (u64)svm->sysenter_eip_hi << 32; break; case MSR_IA32_SYSENTER_ESP: msr_info->data =3D svm->vmcb01.ptr->save.sysenter_esp; - if (guest_cpuid_is_intel(vcpu)) + if (guest_cpuid_is_intel_compatible(vcpu)) msr_info->data |=3D (u64)svm->sysenter_esp_hi << 32; break; case MSR_TSC_AUX: @@ -3081,11 +3081,11 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struc= t msr_data *msr) * 32 bit part of these msrs to support Intel's * implementation of SYSENTER/SYSEXIT. */ - svm->sysenter_eip_hi =3D guest_cpuid_is_intel(vcpu) ? (data >> 32) : 0; + svm->sysenter_eip_hi =3D guest_cpuid_is_intel_compatible(vcpu) ? (data >= > 32) : 0; break; case MSR_IA32_SYSENTER_ESP: svm->vmcb01.ptr->save.sysenter_esp =3D (u32)data; - svm->sysenter_esp_hi =3D guest_cpuid_is_intel(vcpu) ? (data >> 32) : 0; + svm->sysenter_esp_hi =3D guest_cpuid_is_intel_compatible(vcpu) ? (data >= > 32) : 0; break; case MSR_TSC_AUX: /* @@ -4328,11 +4328,11 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcp= u *vcpu) kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_LBRV); =20 /* - * Intercept VMLOAD if the vCPU mode is Intel in order to emulate that + * Intercept VMLOAD if the vCPU model is Intel in order to emulate that * VMLOAD drops bits 63:32 of SYSENTER (ignoring the fact that exposing * SVM on Intel is bonkers and extremely unlikely to work). */ - if (!guest_cpuid_is_intel(vcpu)) + if (!guest_cpuid_is_intel_compatible(vcpu)) kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_V_VMSAVE_VMLOAD); =20 kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_PAUSEFILTER); --=20 2.44.0.478.gd926399ef9-goog From nobody Sun Feb 8 06:21:43 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 5B3875D73B for ; Fri, 5 Apr 2024 23:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361384; cv=none; b=VZCXkHWn26Uw+G3qCTmlMSKZ7p3galQszI/Yv+86vXEp9A8Uv/ZnTTIinvK9iCNatnXpYsYBZG/LSro08dZwQwFGUDX73FP7KXw7jgiiV7pD2oPL+mTowDIZuV2TIBlbCjzZwFdf1fww7PbpNlbi3yktk0Bllyy3Ex+esV1kF3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361384; c=relaxed/simple; bh=H6nYKSnkJ9WM2desm7KNbB1Q8JvyoSy87GOitFOzshw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GJV+Wn5yUULlI043Yi2J3jac6lpp9rJsWxDQ1DRlz0CZeHnaP6jCbFUAu4vavQCJPzuDtTZ1Ju3KCIZUX+vt18S22wHLzCdoMXkaxbvej4AQ/ohCGcyr1baoy8WJd15+oIB6TPiw3AtMyN1MdOcSwoR9KlLlPAcxWwe4VVCuuZw= 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=bdAtFD/3; arc=none smtp.client-ip=209.85.210.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bdAtFD/3" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-6ed007e950dso904546b3a.1 for ; Fri, 05 Apr 2024 16:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712361383; x=1712966183; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=aBGD+1+NYJryR8MdWegT7yXPgS8gyTtoFLOwao+cTXc=; b=bdAtFD/3/yyQx5ZqMKWdJDnywaIKTtT6hHt7IeNwTfPDyIeVnTZtQpci2gwYs6GZ1E Etk0puekVsr8Zf+MJCoJgapmXF67idq6bRXOvfSvRsiHiUibjk62f/vcKb9+2doLsOWT KDYPJI4vmr6hf0fhJtMxAs8TfYDbeQYd8AkRMaFCS/7mp+DPrBgV9tjQeTxC+WkJTwFj 8MLtWOuf2K3PXROfCvxEN54PhlBGxxsV9FmT2iNEqw4BVAX/QMYT+xuSFwHxdik1PHfs Oo0kaBt05+Jkb3omymypyz/Tyau/jB1/eELq4XeYlLWya75Orf8zM/9YO+gGXNBlZTXK WuJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712361383; x=1712966183; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aBGD+1+NYJryR8MdWegT7yXPgS8gyTtoFLOwao+cTXc=; b=VNmFeuyRFciGULOZe8KTf6KdcOLZc11xPPYwlQQdxsCC1XcMI2LVchm8lNrrfuXTLM yeGKHwvB7rN9ah4R6VL3w6jW1yMysAVFql77ptGMB6k1kMqj0KELK1BVIG4qVD8odLbU HUnXGnUD7O2tJBC3mkmFwg26ZfR6Zwjo3J/v5VinpDn8It2Ks99wgXwFhwvQEVd3Y6hE vcbfritlUOts6ceUriKefm1XYbKaUUelpLFvzVjf/mZSF88hYlPbX9103JyftLey3ctR HrFUqV1w619w9sjjd86alUAmyGK9k1CNwGaJb+hAcoxxUMgJcLjMnvFZ4YZ270uHOLhM j3Gg== X-Forwarded-Encrypted: i=1; AJvYcCXtlce2DiFloSYkBRYZS8JZa17ocd6Tk2fhzizn73XySNuMEIUnlF22pB2hG3zhzwiENZYusmqKDHNaOjqlhUTpc+dM+3SVUKFfcqR2 X-Gm-Message-State: AOJu0YxvGaXNOHT2WND25OncSKyERnVyOK47gVBa4kGRrd2S/pWjTIj+ /z4KEEonYvPy9SX8FzU6V61iLi9DeGaRC2dphGowFtN47Ra7HRJcA+NbraJWRBeuUC+UAJmI3Se NGQ== X-Google-Smtp-Source: AGHT+IF3TVd3OdDVtN3oDGrVy2/CgLa3AqQHgD0Q9oZH7Lgt1wEtK2sbv80Wz4fL6xGg/zn6ticXi0zpknM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:17a2:b0:6ea:f425:dba2 with SMTP id s34-20020a056a0017a200b006eaf425dba2mr228426pfg.0.1712361382841; Fri, 05 Apr 2024 16:56:22 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 5 Apr 2024 16:56:01 -0700 In-Reply-To: <20240405235603.1173076-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405235603.1173076-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405235603.1173076-9-seanjc@google.com> Subject: [PATCH 08/10] KVM: x86: Allow SYSENTER in Compatibility Mode for all Intel compat vCPUs From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jim Mattson , Like Xu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Emulate SYSENTER in Compatibility Mode for all vCPUs models that are compatible with Intel's architecture, as the behavior if SYSENTER is architecturally defined in Intel's SDM, i.e. should be followed by any CPU that implements Intel's architecture. Signed-off-by: Sean Christopherson --- arch/x86/kvm/emulate.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 1fb73d96bdf0..26e8c197a1d1 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2354,6 +2354,7 @@ setup_syscalls_segments(struct desc_struct *cs, struc= t desc_struct *ss) ss->avl =3D 0; } =20 +#ifdef CONFIG_X86_64 static bool vendor_intel(struct x86_emulate_ctxt *ctxt) { u32 eax, ebx, ecx, edx; @@ -2362,6 +2363,7 @@ static bool vendor_intel(struct x86_emulate_ctxt *ctx= t) ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx, true); return is_guest_vendor_intel(ebx, ecx, edx); } +#endif =20 static int em_syscall(struct x86_emulate_ctxt *ctxt) { @@ -2444,11 +2446,11 @@ static int em_sysenter(struct x86_emulate_ctxt *ctx= t) return emulate_gp(ctxt, 0); =20 /* - * Not recognized on AMD in compat mode (but is recognized in legacy - * mode). + * Intel's architecture allows SYSENTER in compatibility mode, but AMD + * does not. Note, AMD does allow SYSENTER in legacy protected mode. */ - if ((ctxt->mode !=3D X86EMUL_MODE_PROT64) && (efer & EFER_LMA) - && !vendor_intel(ctxt)) + if ((ctxt->mode !=3D X86EMUL_MODE_PROT64) && (efer & EFER_LMA) && + !ctxt->ops->guest_cpuid_is_intel_compatible(ctxt)) return emulate_ud(ctxt); =20 /* sysenter/sysexit have not been tested in 64bit mode. */ --=20 2.44.0.478.gd926399ef9-goog From nobody Sun Feb 8 06:21:43 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 BE88B70CC8 for ; Fri, 5 Apr 2024 23:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361387; cv=none; b=P1AZPJE8N+0lkkSaphC0djB2nif0VGn4bwnDnXY0isgcW+3Qur6eoDzq9wmk032Cu3WDCehDy97berdMPvrl4ZdI5V+TmH66x5Z5hovDPxYVqMKdGMBdimlgbrR9MaRsIrPCRx1RdXGPVSLPwJ7MwRtUAxC2mORf9qdYde/fZgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361387; c=relaxed/simple; bh=b/B5Yxc1o5uGiHJ7jeAtZBsI3i+lBvUWpy7nGRTLMZ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=doHf4X4/gMj5IDgdf0H09bY6aeS32TUE9lNpBpkK07RelDufPI65OsmSqrVMHu0s5n94pqehGkp5zrMb7A8CGYPpT7xMd60Z+KDJzieurIzhgm7m2xrvkbjj7HI8GKXoA1TT7etU7LaPJVJ7/mgB48SpXchV1k1GkffgzYV0Yms= 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=nQS684c4; arc=none smtp.client-ip=209.85.128.201 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nQS684c4" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6152135cd23so39789637b3.0 for ; Fri, 05 Apr 2024 16:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712361385; x=1712966185; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=Z2SJx+1wJFr0pWJuRZAhG+dHu/wPMI/D+PKH1v3GyCs=; b=nQS684c4a9A+0qoXhwtNKGH/328FgAm+mK/aUdb5JEBu6YSUSstc1ba8zBH5XT4fJx RyGRKnkCYWI4PsS424HbZE2lowr1+qvVI9v5aJaFbuDhJFCiqjJXvXpWf1MuAHVRe2Ww B3C9mWKHEqQ/akKPqJkMY2eyKLAIV4xVjQdBqE/K1q2E/+l9nMSjB1eorYvv8BahuNaX dYcqck083YKCYCt22vQIzCivsYHIkZASNUSXz/FOL8A3Oa7FFOCSVPZsk0VkxyuZu9eX Jn2a+MLxj2HCPcwOIInZNQPTkjXD0HhTIootK/STwqg5kYi66l9KIlrhZCyNyfNiqzT3 iisA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712361385; x=1712966185; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z2SJx+1wJFr0pWJuRZAhG+dHu/wPMI/D+PKH1v3GyCs=; b=jLozQRCSfJXlSgWNory6Ln3NwOcPMvjc8tGD+PbxifVzzLEehq/83rErkLjnpUrwul Q8setqdRFDR2QpAWtTb85KMyq8pSr9e4Zgon1jkfS5aZ5oG2FIrEJ4FOwjecNcRYujqn /7+JfuxCIHf/F9wGCYNB/qfQ2mohKKviThhY1OzumylS2d8iaAk4t6hyaPyYdYXKnmEU JgrmSrpkt/rmFln5HUWg5rF2DBfOp66XxvsxfQmi0dhjQBmCqrZ8rKu1Em8jzvtzZxQl V4uRQWv0/6IFN2G0ZlyaZ/yqQoW4YtQc8ZUaPZwvUZFlkaiQ0q4M94Qu9zBovMTVpdv2 oaGg== X-Forwarded-Encrypted: i=1; AJvYcCXaHuOALMBFF12H9VomPNzomPvw8OCW9BRnrH+pULlDIV9XkRWBumihVZaTb+JQwaVYZgfCCeGRWA2EChotwDt8eKtAk3guR6Y8hCIu X-Gm-Message-State: AOJu0YxJauqWunNUvTNnJayaI7Tm0z1UPn+q9r2aCBEt1wvwsvKB20KS 1FkeRVDAiJAVongiShbGH0Wi5AJEeMpulVwqi3k+J4meUc2s1kGnvLMf/PmGwG5QO2QuIPMYz34 1lQ== X-Google-Smtp-Source: AGHT+IEAQcVWaY2kxMZHD+fyUuyDnGFHrg0CbB+w3iHQiSVLJqyqN5x6yG2JtfvWF0cd2xOm/IS3a+FB7Bg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:8341:0:b0:615:3072:1934 with SMTP id t62-20020a818341000000b0061530721934mr659372ywf.10.1712361384736; Fri, 05 Apr 2024 16:56:24 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 5 Apr 2024 16:56:02 -0700 In-Reply-To: <20240405235603.1173076-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405235603.1173076-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405235603.1173076-10-seanjc@google.com> Subject: [PATCH 09/10] KVM: x86: Open code vendor_intel() in string_registers_quirk() From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jim Mattson , Like Xu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Open code the is_guest_vendor_intel() check in string_registers_quirk() to discourage makiking exact vendor=3D=3DIntel checks in the emulator, and to remove the rather awful #ifdeffery. The string quirk is literally the only Intel specific, *non-architectural* behavior that KVM emulates. All Intel specific behavior that is architecturally defined applies to all vendors that are compatible with Intel's architecture, i.e. should use guest_cpuid_is_intel_compatible(). Signed-off-by: Sean Christopherson --- arch/x86/kvm/emulate.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 26e8c197a1d1..1acd97c6fa53 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2354,17 +2354,6 @@ setup_syscalls_segments(struct desc_struct *cs, stru= ct desc_struct *ss) ss->avl =3D 0; } =20 -#ifdef CONFIG_X86_64 -static bool vendor_intel(struct x86_emulate_ctxt *ctxt) -{ - u32 eax, ebx, ecx, edx; - - eax =3D ecx =3D 0; - ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx, true); - return is_guest_vendor_intel(ebx, ecx, edx); -} -#endif - static int em_syscall(struct x86_emulate_ctxt *ctxt) { const struct x86_emulate_ops *ops =3D ctxt->ops; @@ -2622,7 +2611,14 @@ static void string_registers_quirk(struct x86_emulat= e_ctxt *ctxt) * manner when ECX is zero due to REP-string optimizations. */ #ifdef CONFIG_X86_64 - if (ctxt->ad_bytes !=3D 4 || !vendor_intel(ctxt)) + u32 eax, ebx, ecx, edx; + + if (ctxt->ad_bytes !=3D 4) + return; + + eax =3D ecx =3D 0; + ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx, true); + if (!is_guest_vendor_intel(ebx, ecx, edx)) return; =20 *reg_write(ctxt, VCPU_REGS_RCX) =3D 0; --=20 2.44.0.478.gd926399ef9-goog From nobody Sun Feb 8 06:21:43 2026 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 A14A574BF5 for ; Fri, 5 Apr 2024 23:56:27 +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=1712361389; cv=none; b=hyTUk28zoKO6cXGyPPFB6HEK6nA4hltdg9TU418VigXt6kj4biSflx+KKQGmRP0YA8FmJu4+Mpz1iguctgQDS1VHczVYr/gK0DRSStdnyiXIwCbaLUe+R+Q2umIIZ9rsD0ZhLJ4LZqLn9j6WfyZ9GaCzuPKpaWticnS96ORkJ1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361389; c=relaxed/simple; bh=5RDlYnCWS4ayQasdUGV2EFJf2g/5sa2I9izwXCuUezI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dBAEDnGjAOTY0AMcHldM3r8bz4PbYF1yIOZj4XTanDdgDEoaUwTf2K6aWhYgta/PPJtNX5rrp8wlRdoqBSKX5FwB6THDnXIew+8NfJ8I8wBI+TmeqyDE13wCggTI+aDt7c7xl6ctwG4dGxig9HvNQ5osluaLa4VIyBdGv7ypbyM= 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=T3s+Y8Sq; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="T3s+Y8Sq" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-615110c3472so48681627b3.3 for ; Fri, 05 Apr 2024 16:56:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712361386; x=1712966186; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=GbwikEYWbQPXHEM5/lws4KQQn5EqaCgsUvoAMFf6UNk=; b=T3s+Y8SqupuAdHuqAourmoM0WiRcDm/9RvAI+UhLOgJaCvTEX38tD20PUzelLg9CCM Evf9MLKH+Ccd3gqgomBYmBjuGNzvV+Q3p3CzNNG31V8eR4lLo9QC1KaNdA8qf5Iu6ZG5 VGRuxMiNrr/+CBYYCeCjL86cVLdu8T+a6YH7I0HGlfXFOAuiN3l+SpjsdEUsUm8jICqP OHGNDG1M9bVqmTJXA++UM2afd3wAF3ayrmHVmiANJh5DLCGsLKROencvAGLd56Tugp+q +2s/ROuQNzHkmqVeiPHGIEYX3MKQsR+6yCOPSi37czkRMXvmKbcFdE0HL+tGWM6vFmdt djWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712361386; x=1712966186; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GbwikEYWbQPXHEM5/lws4KQQn5EqaCgsUvoAMFf6UNk=; b=h6i+gMPwcTyWMk34Lyi5uguc9pEcCBT3OlUobOTwDv9yJ/gqrPgkblqI3PQjhrbHjH A8H1nBn1omMfmyuPo/WrbXf8wkcnujAN5yJZVofLTs8CE4vckIi9jRyL3ZpLtQuvTNOZ yJNBGM+2aedPIKemFW7Pba3VvAXLiezuvNVlTp+wkS9+JINJHxLp/2ahjVArU1qR9uQt TOElCVVjjdg/qoW2wCh/adNNinA3EuHH2DxzskL0xkUyY03dW1xK2n7RJdRzC8QZEoeE lbfuuTQztXaBKEfRG69kM2gRPS353bolbAir125ZkoVs9nRN9JVauvzv/nhs3BOfvHFG b/QQ== X-Forwarded-Encrypted: i=1; AJvYcCWMhsdrt9LFe6YcG3TFjQx51GQ+/6di/qauaeaFnIzmiWHSHSNnGEWBPy3eFfKf7iH03Sx2mQvfp3zfuqptgt/BpiQsV4U6J1+SzKRG X-Gm-Message-State: AOJu0YzlcIYgcCWtrvnXkk9Iq4iZpR+Phx79MOpGIAq6iupZr2Vcaoal 3y5yM2IN8mCGSsMO/7l3ueA6bJJVoDR+bQ6qPQyZMbahUzk3JnfKdTdncr91RMKG/3puw0yEqol OPQ== X-Google-Smtp-Source: AGHT+IE8jGFCNdnvcQoFiWg4slvFmL6J7M5uI9g+aVjoREsOBmGh3S15qyummmRu81lWYixJYoV7vfpkwtw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:d0c:b0:617:cbcf:8233 with SMTP id cn12-20020a05690c0d0c00b00617cbcf8233mr712182ywb.2.1712361386753; Fri, 05 Apr 2024 16:56:26 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 5 Apr 2024 16:56:03 -0700 In-Reply-To: <20240405235603.1173076-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405235603.1173076-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405235603.1173076-11-seanjc@google.com> Subject: [PATCH 10/10] KVM: x86: Bury guest_cpuid_is_amd_or_hygon() in cpuid.c From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jim Mattson , Like Xu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move guest_cpuid_is_amd_or_hygon() into cpuid.c now that, except for one Intel quirk in the emulator, KVM checks for AMD vs. Intel *compatible* vCPUs, not exact vendors, i.e. now that there should not be any reason for KVM at-large to care about the exact vendor. Opportunistically refactor the guts of the helper to use "entry" instead of "best", and short circuit the !entry path to make the common case more readable. Signed-off-by: Sean Christopherson --- arch/x86/kvm/cpuid.c | 12 ++++++++++++ arch/x86/kvm/cpuid.h | 10 ---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 77352a4abd87..c5fb39930213 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -335,6 +335,18 @@ static bool kvm_cpuid_has_hyperv(struct kvm_cpuid_entr= y2 *entries, int nent) #endif } =20 +static bool guest_cpuid_is_amd_or_hygon(struct kvm_vcpu *vcpu) +{ + struct kvm_cpuid_entry2 *entry; + + entry =3D kvm_find_cpuid_entry(vcpu, 0); + if (!entry) + return false; + + return is_guest_vendor_amd(entry->ebx, entry->ecx, entry->edx) || + is_guest_vendor_hygon(entry->ebx, entry->ecx, entry->edx); +} + static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) { struct kvm_lapic *apic =3D vcpu->arch.apic; diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h index 03d015e9ce33..41697cca354e 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -102,16 +102,6 @@ static __always_inline void guest_cpuid_clear(struct k= vm_vcpu *vcpu, *reg &=3D ~__feature_bit(x86_feature); } =20 -static inline bool guest_cpuid_is_amd_or_hygon(struct kvm_vcpu *vcpu) -{ - struct kvm_cpuid_entry2 *best; - - best =3D kvm_find_cpuid_entry(vcpu, 0); - return best && - (is_guest_vendor_amd(best->ebx, best->ecx, best->edx) || - is_guest_vendor_hygon(best->ebx, best->ecx, best->edx)); -} - static inline bool guest_cpuid_is_amd_compatible(struct kvm_vcpu *vcpu) { return vcpu->arch.is_amd_compatible; --=20 2.44.0.478.gd926399ef9-goog