Received: by 2002:ab2:26cd:0:b0:1ed:3240:60d6 with SMTP id c13csp501334lqf; Mon, 4 Mar 2024 12:50:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWLn54uWAxLuhiK2IMPvNWZQNGXau6mh7Qi5Jf9ejKZQJqIopQAzisomgGW29s5RRYfqzXHeL63yJ4gB+xEk6u/n1EtjqnXUK06DySOTQ== X-Google-Smtp-Source: AGHT+IFleh5O7cPB7AZSSZF5HabeUgkT7mreajJo6Se0dFzEpMHnhloVA1TaldgiTQasvypqVP2o X-Received: by 2002:a17:906:7185:b0:a45:2091:8193 with SMTP id h5-20020a170906718500b00a4520918193mr3450690ejk.68.1709585405588; Mon, 04 Mar 2024 12:50:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709585405; cv=pass; d=google.com; s=arc-20160816; b=tGZOsKltEEn4/1fxNv1Gg1ZuZZItxQozFNQod3WpywT3rS9a/Gu3z6o4uihUEO234f WRZyzkrosyk892KHO5RJloq1DzhUWHEMYloqQjIjDVpCteOs5TU0EZtkvKLJlBh0TDrx siJBd32ron41dPPiADwRaSbiNaFXS480AzKvytEJ3kn4n8D5Sdw1Lj/TwoX4uljPZfor 8PXx4VvoWa3/p73zd4sL9r94+3oq5rm3r4VLyM7wqpyMgn55SP4VDe1idTfAsf/0Xm83 Ppn4XTPMOdUrFs1aX4edO2Rpg+cpg/bEABVZBAbl2CSqDaMGA+mpMS/qc7oxFcf2VuoJ Qpzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:date:dkim-signature; bh=Wvrqw1J4AWCkZRLQPrePGKOZL8AsSzVG85lzhBNbxRo=; fh=JOicaIda9gfT7o9ORc55SsAMDN49VCO95FpbwLrpmKI=; b=1ESyckEIFXRuJTkXiz8U2rr+SfkymcfWvcB+uv/Ss2hH2VGc8TmYtRQEqK31a4U5bN 6OrybN/rzL9bA8ScE4rJMXgts/LXRhL1rY2Zj8ERfec0ds2RsOdMJ3+fY17T5IdSiYU2 4Hg9mzIa6sY+hbd7UTwnMuApJ/R2t/ma8Ti3LeeQi+zTO0S6R471S0DYh0CHilMBteft 3psFBPoAi8/WY3WznicWTJqgl895X+wjLEwkOXH9wg6bjLlDDyTnVmaexCa7lGLAKumO Upp0B5LvNHa3cIg/4C/84eR4pWNbjZVWCuzafuMnjCM3E6t0BbdlCXjP5/40t31rik9v LVbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Z+EizRfY; 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-91254-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91254-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bn7-20020a170907268700b00a3e68c15801si4475482ejc.776.2024.03.04.12.50.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 12:50:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91254-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Z+EizRfY; 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-91254-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91254-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2DE9B1F23169 for ; Mon, 4 Mar 2024 20:50:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FDC9101C1; Mon, 4 Mar 2024 20:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Z+EizRfY" 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 D498DDF67 for ; Mon, 4 Mar 2024 20:49:53 +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=1709585395; cv=none; b=C6Psx7SOZ4ld/V0NK3xNlYpcAeN3CrI3qMgPQO0SWdAHOz0IqvA7EYjfyxj+xkQQDjycCRCi+n92gC1ngYKusKfCOMwnrihVnnnKPhCBhhZXg/mOmnR3U/mAWQbpAaTfylzXQzb7N3uE+YVVOaPoUN8/BHmTCoMGka7eWx+iB+8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585395; c=relaxed/simple; bh=A+CXBTKX4i/CDGbxfMAyWrBuJdNoNwdpxzflMVoCsm4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mia1Dw0F+MxyOyidKCstIS9k2rHUJBZ32IOR4QvHR9CTxES5fuoECNSPp3vCfx7TxddP3fvn8bDME+5d0SonTu2NzeKlPFrTiC5D3o4gGWO5LszpA5LDrB3QH5YUgig0YUw+D2L0lCg2bCPS1Z+ay/lwksgYDoWVdZTcu689ZKA= 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=Z+EizRfY; 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 Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6092bf785d7so91451217b3.0 for ; Mon, 04 Mar 2024 12:49:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709585393; x=1710190193; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=Wvrqw1J4AWCkZRLQPrePGKOZL8AsSzVG85lzhBNbxRo=; b=Z+EizRfYzytRxcDccGpWaCRqTz52e+cvrhSjDaPmvJ7y+1nbOboCu0Lsqb9kYU82r5 OiK8LZ9DOCPq7vUNcaYJXhuvlaUbqwPRxJ+eEFj0xZz9bzq632kAoXHsuDEWFzL/iLwR r/6yuAU+Q2OZ6bZCbRsYBogaFwVsORrq0mIao4wVPol5d8GY59fbRiMT16dGOj/+wpix 7JU5VrkTPI2xwz8VPT+BLRdlLdBEdG/fZppsyU/NbisXhykecJL/3F4Ukr8Ar2JnjAZL TdFvldoj7e/Ighdc/vDHMjmB+SETSaaVW6ry2V0NucgbeRZdEShzaNx21bx+3rEspP52 4vbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709585393; x=1710190193; h=content-transfer-encoding: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=Wvrqw1J4AWCkZRLQPrePGKOZL8AsSzVG85lzhBNbxRo=; b=QIxytfO7PzoMo5qc+jgDyrC6pAK3C+CdQ6nwTY7kgYFAEcP7w6LtlRNOTx3pVXRQOx SemFMkuSF/dMOS3wkD+Z9KsAn9scFpennlIgjLtOSCns4NuNw8SfM/u/L44kXOYuiIfS xblo96uL12JO/NfSO3HtvW+vc4MqFOyjPbJ/m/k6WsjR4RPHLFihDkSzeQDAG2JCMzQK vSmCdtcEDr6K5g4bxLR82IxLkD1ysJY5rrHNNwrKVHqMkmkf2ldyrBFEu8Tx1etTeqaN SLR2vj/Ae2BIQZeRl5zCtpzK8s5ViQ2Hc00mUwzsPuBKMkf66u6e1sW0GVPuyHR5QJ5R eyrQ== X-Forwarded-Encrypted: i=1; AJvYcCUK0yRQIqQ8xK/Wg/PoS+ZjGktmSjD5vkkG4v2ysIvK1vjpohhw3MG4xY99AMcrjMxXv7EeM9EXOTZBeVviHbqXA1ybAC8DjV0jXfF0 X-Gm-Message-State: AOJu0YyMoCA4AHbLn1fFMxea9+tLuy17SB0JcNOUhrxwnZhTzE7OplJi N6ttQW3IuW+GXGCz5NYweG+NQzFE9NHPZ2P5H36i5G7Iy0B7M2iOwhrNSGFYiQSX1pB2SAGV1a1 kdg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1004:b0:dc7:42:ecd with SMTP id w4-20020a056902100400b00dc700420ecdmr2589331ybt.6.1709585392894; Mon, 04 Mar 2024 12:49:52 -0800 (PST) Date: Mon, 4 Mar 2024 12:49:51 -0800 In-Reply-To: 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> Message-ID: Subject: Re: [PATCH] KVM: x86: Do not mask LVTPC when handling a PMI on AMD platforms From: Sean Christopherson To: Jim Mattson Cc: Sandipan Das , 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="utf-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 01, 2024, Jim Mattson wrote: > On Thu, Feb 29, 2024 at 11:44=E2=80=AFPM Sandipan Das wrote: > > > > 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. >=20 > I don't know why it didn't occur to me that different x86 vendors > wouldn't agree on this specification. :) Because you're sane? :-D > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > > index 3242f3da2457..0959a887c306 100644 > > --- a/arch/x86/kvm/lapic.c > > +++ b/arch/x86/kvm/lapic.c > > @@ -2768,7 +2768,7 @@ int kvm_apic_local_deliver(struct kvm_lapic *apic= , int lvt_type) > > trig_mode =3D reg & APIC_LVT_LEVEL_TRIGGER; > > > > r =3D __apic_accept_irq(apic, mode, vector, 1, trig_mod= e, NULL); > > - if (r && lvt_type =3D=3D APIC_LVTPC) > > + if (r && lvt_type =3D=3D APIC_LVTPC && !guest_cpuid_is_= amd_or_hygon(apic->vcpu)) >=20 > Perhaps we could use a positive predicate instead: > guest_cpuid_is_intel(apic->vcpu)? AFAICT, Zhaoxin follows intel behavior, so we'd theoretically have to allow= for that too. The many checks of guest_cpuid_is_intel() in KVM suggest that no= one actually cares about about correctly virtualizing Zhaoxin CPUs, but it's an= easy enough problem to solve. I'm also very tempted to say KVM should cache the Intel vs. AMD vCPU model.= E.g. if userspace does something weird with guest CPUID and puts CPUID.0x0 somew= here other than the zeroth entry, KVM's linear walk to find a CPUID entry will m= ake this a pretty slow lookup. Then we could also encapsulate the gory details for Intel vs. Zhaoxin vs. C= entaur, and AMD vs. Hygon, e.g. if (r && lvt_type =3D=3D APIC_LVTPC && apic->vcpu->arch.is_model_intel_compatible)