From nobody Wed Nov 27 13:45:48 2024 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 85F6B1E0B9A for ; Wed, 9 Oct 2024 18:17:46 +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=1728497868; cv=none; b=HjvrN62+wOJKN5J+ctDDSJREcghU0W0l7jU7st6F2Maslg0oSZlVnbfyR6ZkmAUFe7Mj8c6CSuNkY4j0twBma7M0dAbwMRurXw5KIBDSTijf75r3vB3lLRn4xMKIumLPZJpSTxhwpxAF+btBOdBS0OBrqRq11rE9N22HICMiJiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497868; c=relaxed/simple; bh=0zM527JK/paLZTNDe5QFY0koUa6j7yB2QFiZGlD4Z4g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qvzshdHWSToZQAb9SGa9XGa5p2BAAXfU+BXXX/wFxhZ/MayMYItvXnEDf4NIAjMN8QxRmvLhjtNv8zJ4wFn99Umak7N666Y0c6SLsdB7HVvqzbJywgOErqkXVdkihAHox4otH3LNnOzcBlwM++gINKyC90s9EdtT0L40IDq0l20= 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=bRjp8Pvg; 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="bRjp8Pvg" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7e6c40a5795so74188a12.3 for ; Wed, 09 Oct 2024 11:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728497866; x=1729102666; 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=be89kprlJKC4G7WLZof2cKHiOhtzCos3l78DyaXkfv4=; b=bRjp8PvgU5Jvw764HVrDE2TtO2Rp3hWQ2w3nm23XPKqLkGlC33NhSP2dporg4Jd1Ct Pd9gyEQOfoXip1zs2sulKzyE1U0kTnXx7tR5LV++5c/3Cr9RFafKrIGV/dmlWt4MgL6r Wumsvodcurys29Cb3Y+FnY1BOyD9idx4bxaLOfUDFwXEs1G9JjS/jitPPOKOQuJmEpSH 5y6bIyPAwZkVmKKwiA+ulID7L/EmZVOw3HXomNdm+8bhDm5mLqyHs3CGgKvPsdpT+IR4 galN9O1y7pYiArwdwGpuhQAsf9RenL1t0wo3ffUuQpzP6KUjgOU/NrpRVp2xO2h/mhfK 9fFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728497866; x=1729102666; 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=be89kprlJKC4G7WLZof2cKHiOhtzCos3l78DyaXkfv4=; b=FihTVAHBoBPVLBXCi1u7ZNOXCxwMLnvT7Qw8kZtXdxTdY+S3YAYGifxjWURiEIyToL 9nGpWnxLiLvldewsH5UimWlusiMVwWS9qKGE43X/73Bo6qWPYuLWAuBoy/8Kk5ZawjLp csDqaVHwOQUIreFQmMaPxsEOhJF5FkYGSvncDhEHx1GQCB85g38Z6fZ8F30j3j2ahheN j7eDh3+AtjKudoVMz/ljicxBuXaWeMMkbzGYtq++lRnKBUVIpX0hKFgdyl8hpYP6+fjG BEBR12y/y7TTKF2gFGpOIuKSgl9bXTztDZZaDAGFN8cQ4ddVuw3bPTKs58T+6PrlnzPU vq6A== X-Forwarded-Encrypted: i=1; AJvYcCXmzkx5mXAotiZa+JOlk/WbHGhx2alb2cdEhrekTJ0L7yPn/F99hRoYMRmwqwr7YLOPtLgjV9eqRH1dzcg=@vger.kernel.org X-Gm-Message-State: AOJu0YzUqxfR+EjjWg4RmwCaDsSLxZPvXYobnzThi9l+UNc9Mh269chE b2XE8Kl7YGmihxys7fioFqttL4zKl51S+JKI9B4Qgt4HfGvjNEG7TKnUaccERcnxpo6K/04Hx1G Meg== X-Google-Smtp-Source: AGHT+IH++ydkI6iIiLg5mDcR+PNffx9cTT1AyjXQiz1ktdHe1ZEbIL4uc7d0r3nPPztS+TWADPeejHpXgr0= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a63:5a46:0:b0:7db:539:893c with SMTP id 41be03b00d2f7-7ea320ea266mr3285a12.9.1728497865541; Wed, 09 Oct 2024 11:17:45 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 11:17:35 -0700 In-Reply-To: <20241009181742.1128779-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: <20241009181742.1128779-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009181742.1128779-2-seanjc@google.com> Subject: [PATCH 1/7] KVM: x86: Short-circuit all kvm_lapic_set_base() if MSR value isn't changing From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Do nothing in kvm_lapic_set_base() if the APIC base MSR value is the same as the current value. All flows except the handling of the base address explicitly take effect if and only if relevant bits are changing. For the base address, invoking kvm_lapic_set_base() before KVM initializes the base to APIC_DEFAULT_PHYS_BASE during vCPU RESET would be a KVM bug, i.e. KVM _must_ initialize apic->base_address before exposing the vCPU (to userspace or KVM at-large). Note, the inhibit is intended to be set if the base address is _changed_ from the default, i.e. is also covered by the RESET behavior. Signed-off-by: Sean Christopherson Reviewed-by: Kai Huang --- arch/x86/kvm/lapic.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 2098dc689088..ffccd6e7e5c1 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2582,6 +2582,9 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 va= lue) u64 old_value =3D vcpu->arch.apic_base; struct kvm_lapic *apic =3D vcpu->arch.apic; =20 + if (old_value =3D=3D value) + return; + vcpu->arch.apic_base =3D value; =20 if ((old_value ^ value) & MSR_IA32_APICBASE_ENABLE) --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:45:48 2024 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 5D5BE1E0DFC for ; Wed, 9 Oct 2024 18:17:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497869; cv=none; b=TXOk4wYkjduEVzbig/IwlSuc3cpLV5XK8AYuNc84u8/deowXZMUvYuyhD9xLM9MkI41OpFHjY+r0hNdiNtURyHMd9/gY+xDaoZR0kecnCQQdknajV+pmyowMhieU3Om56gTKmRck3wiypvmUuISr8kmiELZeLe7x0cXsglaX0dM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497869; c=relaxed/simple; bh=DDLfj0TQYGwpLkFazEuQUvzdkQZmzTYxm2iRMOY43rw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Wo/uQBV7WHqnNco+axSUmX1iNfIDmlbEmstfW2sPfYOk4HUUrXqnLXNvBdqAxTTiSBHj9n+UkmiHiT1hvWMRmLIi9FR5PrjxZDyH3ZbBnDMTKNFzZNe8Ts9FdCcoDus0lmi7AAYt82N4MUKQ2E3NGGYu5yPG6IQ/SKUaMVfUZd4= 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=ayEExf5E; arc=none smtp.client-ip=209.85.210.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="ayEExf5E" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-71e1e989aa2so130859b3a.3 for ; Wed, 09 Oct 2024 11:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728497868; x=1729102668; 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=2G7TjtKE6sDpC5bp0OSd5cuEOohLepXkfXg2tU0SKoY=; b=ayEExf5E+PPxYZ2EqowrESiE9/vonl9bHhKnQBoxjec3o0VyRLXyaOOsFUwPAZsHYJ b/2jPIX6BYT333jrnU6VkXvgnjd4+SJgNE0RYNhZ7HQ4qnL7O/xk2nsXgBq68Qf6Gkg8 WteyoVnOAMvHMUeWQkjvQTngcMwvW641zrHEEokZ9lpGxnlLnS1Kg7AxetmT2LtaqH8a sttL1cx3wu8ECYcv1O+E1f4zF1Qz14+yVv5drGd0BpdFCd4bSiZq/Dkoc/VrC1SJWIMJ 2uyHfcpT2msm5FzM+8AxvBPc+SbU+MZ8dRgC1hlidiI9NX/2SqZAweIKdJZxz5vXq7bL 9B8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728497868; x=1729102668; 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=2G7TjtKE6sDpC5bp0OSd5cuEOohLepXkfXg2tU0SKoY=; b=Q2x0IwW77hANvuoxMNuIHN2RYHmJbQvs5kWtUXhhL3GAfQOkMBQPF77Tym4ZCSIXQs K43T5jJlAlvywjiDLscDcf/yzSTM0kcZNGwklnBbyPC7MQppywRby34HNrAzALmK6gPQ lbFVRQk7E58f6+qVIrlon7KcKU9cTjP6CoCyLiPeSvYFNVDP17a1a2diS/ouvwqkwUJU ti8fMYbBx302ZOpRjt6cXt2PwcuUMXAPdBnb14/9hAwrWXmOr5LqTgKFpKdjvqYFvmm5 SDu8zG5fR+MlRCqPCcU4Ajlv9lli9ZknXSVL4RQ2BWlvkAQhyDaBfFV2LJeBC3meRRI9 kQaQ== X-Forwarded-Encrypted: i=1; AJvYcCV7C0w9P/EU6oJGGsxHp3Nu8lATjQP62eXaMuEySGOLe8CIWqZmMeUWK78gi5sfxqt+wVep/x0UA/3I1Oo=@vger.kernel.org X-Gm-Message-State: AOJu0YyWp0jevWRJi23W/emiakL63syV/hRdZ/R6HyIpa/Yv4njqsuWx iLofq1M5kN+vnYBRxfFZ1ejMgVoSIBWd+Bi8Mq+QVmWnMgO9DGn77gOb4PDyjRvxLwAumE8v6CO uDA== X-Google-Smtp-Source: AGHT+IEDBDcN5R3goI4UO9P1OG6J750Ofxm36RRfmx857Ihy1BrsZNT8kpRnKzVh5TGPa8Wq9gICpJyQfxA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:6a00:3e0c:b0:71e:aa:eac9 with SMTP id d2e1a72fcca58-71e1db7352cmr6743b3a.2.1728497867481; Wed, 09 Oct 2024 11:17:47 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 11:17:36 -0700 In-Reply-To: <20241009181742.1128779-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: <20241009181742.1128779-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009181742.1128779-3-seanjc@google.com> Subject: [PATCH 2/7] KVM: x86: Drop superfluous kvm_lapic_set_base() call when setting APIC state From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that kvm_lapic_set_base() does nothing if the "new" APIC base MSR is the same as the current value, drop the kvm_lapic_set_base() call in the KVM_SET_LAPIC flow that passes in the current value, as it too does nothing. Note, the purpose of invoking kvm_lapic_set_base() was purely to set apic->base_address (see commit 5dbc8f3fed0b ("KVM: use kvm_lapic_set_base() to change apic_base")). And there is no evidence that explicitly setting apic->base_address in KVM_SET_LAPIC ever had any functional impact; even in the original commit 96ad2cc61324 ("KVM: in-kernel LAPIC save and restore support"), all flows that set apic_base also set apic->base_address to the same address. E.g. svm_create_vcpu() did open code a write to apic_base, svm->vcpu.apic_base =3D 0xfee00000 | MSR_IA32_APICBASE_ENABLE; but it also called kvm_create_lapic() when irqchip_in_kernel() is true. Signed-off-by: Sean Christopherson Reviewed-by: Kai Huang --- arch/x86/kvm/lapic.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index ffccd6e7e5c1..fe30f465611f 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -3072,7 +3072,6 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct = kvm_lapic_state *s) =20 kvm_x86_call(apicv_pre_state_restore)(vcpu); =20 - kvm_lapic_set_base(vcpu, vcpu->arch.apic_base); /* set SPIV separately to get count of SW disabled APICs right */ apic_set_spiv(apic, *((u32 *)(s->regs + APIC_SPIV))); =20 --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:45:48 2024 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 8560F1E1A3D for ; Wed, 9 Oct 2024 18:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497872; cv=none; b=Fqd+l9OIYWnvjXhzNxaoYg5Fc8pklt4vU+6hWG9Xrg/eGqJjD9Gt/NT0AWXQSQcSgx5/eZ+o611f6Ld8b7Xisxad3vUUcb2TaCAMOQ9oQVFEVZH3ttvAkkY9Pz47oPJMamBmalUN+8prawaOd3rHRkbQ0P1Q2iDEP9p4HbCGHVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497872; c=relaxed/simple; bh=aQegb2jJTwclP7J/2+nvzeBKDFmobcteHsPnTE7cqaE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=k/yTz//HotFUANFvcEUTrBcEl/esh6585VK9Yx/ttgQj2u33TocXG75a5DtZSnE8UxLusd9+k0wyAgJhUD7HtXg2gisz5+yC8I49YpDC1lBcl6RbISRMQxfpjGhCacXgo7Ex+kyFz1cfMpITwhKkH0sOrbR1s3Vsu4gydgUnfzU= 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=k6Rg2T90; arc=none smtp.client-ip=209.85.214.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="k6Rg2T90" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-20c56938075so396925ad.2 for ; Wed, 09 Oct 2024 11:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728497870; x=1729102670; 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=0EI8KqLxjBp63sDvxFB6h3mtXjGqieRpikapG45fsO0=; b=k6Rg2T90/OWcptAxi5HK3BXksYPC5YqquC88l0hMmBKDjjiICD0cIGmtiyEkAGnQaz eB5j2jdyRuGZYaVg90/HrOix4oV4vHUuugp4olL5K1BtEyO0KZHmZh+kw27TR9Q0fCOs yICmv8VFITNCOVScVBmNAHsIZburP3FVoHM6UkdhRcF7uLugFnsh4FmQUqzC5712rm7+ KtHXe+JMxXGrONO6EIYvJjLkyMPSli0YAA/6uTiqc20aizsiodo4iyVXePo/jpV12nZH kl5fK7leY9NPmQ/soO58I1/PSuLQxIGDXHSjgwQ4rZI3H9vDGg67J0AB74akS72w8GVG s37w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728497870; x=1729102670; 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=0EI8KqLxjBp63sDvxFB6h3mtXjGqieRpikapG45fsO0=; b=FDieb09KJaY6jhr15h/or/Cr0opc1EcKSDIkbL126gJXEoEZxatNU79siy6t4PGwh1 5RI6Wu/Meqe2MwfffJqB3ygl3weh/XZQDPLEW0z49CjqIG5Yqz2N+1mYmGTHGKECTEKI wkxtbGOx3AcmZZSJ1rhMe53HQMlXM14SPJv8hcsVKEY62cCyQXL1hOnj6P3MqWK0Y29/ roxT+44+AuNX1R+I7FkA1iGYjUTI2/dVcUbR+c6hqAXm4wpmoYOk/gBeX9EpMbqlKLBc pfGyUHGXFPbCJl+8GNYlrMx1miypulIv1ji3pXNLz2wX42CkqKhKCts+pfDM8tcgd6Hy rBGQ== X-Forwarded-Encrypted: i=1; AJvYcCUf1Hkg9zn+OyQFZnyU5mSCj7AZFpgLD05hYca5lTa9AqbaRX9OOnqQBgzBCLnT+HQzwDYiBflVlH1qkeg=@vger.kernel.org X-Gm-Message-State: AOJu0YwEN2WqVHmJxqb1x75siG4pg7cg3wkYNA2XzGLe/Hv/AdC0A70b D9wSz2JZuTJXxo6S5RMPBafC3G551F59+ANVcOylVsVOhamfhYL+M61lWTxexKltc20GB2uUNbY WpQ== X-Google-Smtp-Source: AGHT+IGCHE/pJCSD+8XIOOuGuBub6Cuxazc+vzvdE8v2/ieW0mgwvDRyxLPmlm5mrBxuObiPc5iUxZ7oNo4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a17:902:d502:b0:20b:7ece:3225 with SMTP id d9443c01a7336-20c6358fdd3mr824545ad.0.1728497869626; Wed, 09 Oct 2024 11:17:49 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 11:17:37 -0700 In-Reply-To: <20241009181742.1128779-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: <20241009181742.1128779-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009181742.1128779-4-seanjc@google.com> Subject: [PATCH 3/7] KVM: x86: Get vcpu->arch.apic_base directly and drop kvm_get_apic_base() From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Access KVM's emulated APIC base MSR value directly instead of bouncing through a helper, as there is no reason to add a layer of indirection, and there are other MSRs with a "set" but no "get", e.g. EFER. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Kai Huang --- arch/x86/kvm/lapic.h | 1 - arch/x86/kvm/x86.c | 13 ++++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index 1b8ef9856422..441abc4f4afd 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -117,7 +117,6 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, str= uct kvm_lapic *src, struct kvm_lapic_irq *irq, int *r, struct dest_map *dest_map); void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high); =20 -u64 kvm_get_apic_base(struct kvm_vcpu *vcpu); int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info); int kvm_apic_get_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s); int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 83fe0a78146f..046cb7513436 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -667,14 +667,9 @@ static void drop_user_return_notifiers(void) kvm_on_user_return(&msrs->urn); } =20 -u64 kvm_get_apic_base(struct kvm_vcpu *vcpu) -{ - return vcpu->arch.apic_base; -} - enum lapic_mode kvm_get_apic_mode(struct kvm_vcpu *vcpu) { - return kvm_apic_mode(kvm_get_apic_base(vcpu)); + return kvm_apic_mode(vcpu->arch.apic_base); } EXPORT_SYMBOL_GPL(kvm_get_apic_mode); =20 @@ -4314,7 +4309,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct = msr_data *msr_info) msr_info->data =3D 1 << 24; break; case MSR_IA32_APICBASE: - msr_info->data =3D kvm_get_apic_base(vcpu); + msr_info->data =3D vcpu->arch.apic_base; break; case APIC_BASE_MSR ... APIC_BASE_MSR + 0xff: return kvm_x2apic_msr_read(vcpu, msr_info->index, &msr_info->data); @@ -10159,7 +10154,7 @@ static void post_kvm_run_save(struct kvm_vcpu *vcpu) =20 kvm_run->if_flag =3D kvm_x86_call(get_if_flag)(vcpu); kvm_run->cr8 =3D kvm_get_cr8(vcpu); - kvm_run->apic_base =3D kvm_get_apic_base(vcpu); + kvm_run->apic_base =3D vcpu->arch.apic_base; =20 kvm_run->ready_for_interrupt_injection =3D pic_in_kernel(vcpu->kvm) || @@ -11711,7 +11706,7 @@ static void __get_sregs_common(struct kvm_vcpu *vcp= u, struct kvm_sregs *sregs) sregs->cr4 =3D kvm_read_cr4(vcpu); sregs->cr8 =3D kvm_get_cr8(vcpu); sregs->efer =3D vcpu->arch.efer; - sregs->apic_base =3D kvm_get_apic_base(vcpu); + sregs->apic_base =3D vcpu->arch.apic_base; } =20 static void __get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:45:48 2024 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 A0B341E22FA for ; Wed, 9 Oct 2024 18:17:52 +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=1728497874; cv=none; b=RGlZFQyOmMPKfxuDPyATxS2Ajg5C6iNcPE/MZOIJq/C2vTLOyiDtExwNva2rbK7pelpElldEwO7eIezTGYgHs2cOIdb1fv/2QuZ7wsbN8zEbqNVwOrTdS7WjkJzinAb4I/bgMnDN7Wo4S0D8jSO0+3zmMrphZGOZ1DhZdQ9Z/uM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497874; c=relaxed/simple; bh=dr1ocippoTiMHINFoEKeoOJdkH3TJbfSreMvnI8POao=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NBWaldUhvwJYI3kB8S7YKz/MSfjd0csp56eH6czHqK8+RkXd+GfnAnZyeVYopeOnH8w+jdN8TePsy1gkczYZdmUNcDHWsfAIqj4OGRPo4lld6vY15r2tFlDojJhA6m1bHxw1uoE4Cc27kR827ftMCM4nLvdQ/u4DWgaqBakaF5A= 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=imfZ9yF3; 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="imfZ9yF3" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2e1346983c8so173154a91.0 for ; Wed, 09 Oct 2024 11:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728497872; x=1729102672; 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=uFbHUh5HFyC0uY+uQnqYlSoSZ23sTgNwEXGQiV0ebm0=; b=imfZ9yF3F+EdM9ILJdDLnqX6xTls+cXhKaJb210JUWqIx6YrclGDxuyVRWGjuraXpU pUCz23QO17XNGOT9FPLBf+Hlg3mmvx1bRjlMIkMdBXdq0QZWbGquIeZgZJo2OMwBbaGS CVQC+VXdKm0TpE1hOGAwR7Cwcak2Wc6v7ouNXDt6lYdzis8S5SN221as6zYGTcOjJApM W8DMlWHNkwpASSelXror3xobdXWVz/OvqiXBvO2zSCH/HaahMnfACPN3VdCamhW5z/Fo RBIZYwWIWaufqsU7ELvS8YzDJJCxYYXAGXTddiOngyrq9z1GExhVGZinKHwWv8HET4k3 BLCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728497872; x=1729102672; 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=uFbHUh5HFyC0uY+uQnqYlSoSZ23sTgNwEXGQiV0ebm0=; b=vgKhCU8rDDFu79QK0MeMEOBxdl50XurMZ+v3u+UP/ScXBNJwD6Rv+9F3TdMe2/y2XH 2m8PF0q5bEWjL587NrrrKgd9ywmV5lEnTT8g9yQTbFlprWrwp18jQAKshohBIy30Paa0 kVOQ5d1kok/8uFEmfy3PafblHitrP+e0GmMeKtltdLS/gBfMKYevCN9ob2ZCFoTotC/c T1DKl/xRv/xEO/wN3gLzqmwHToY7Fa4WW0Qmk2OSVkLZ4bl419AHlKuGjQax7vpQp4e0 3zZc9VvaZ+yqf0yksZoKX/hqAT0f2H1PpxKjqh8PTlXoqov2spELzsK4cHsWBNfVOoXm okWA== X-Forwarded-Encrypted: i=1; AJvYcCUxBIMecOq43Z/RGjLmYTWK/pCXP2cTK//IR8HbNHr3BGPo/ITrhZg627U+GOUO5uZCFrBIga6k40O8OFs=@vger.kernel.org X-Gm-Message-State: AOJu0YyK+oV8jRslcLxKGfBYRswjbtZrZ3sVBHkZqg6XssdaYboSyGC+ kV6G0SkAZRfC3S0E9kMZJU/yTrIb2sNXsbz1Vu8jbiqPU7+4jRWXY3s12B4eLAk3i7IH+DQg6XE JVA== X-Google-Smtp-Source: AGHT+IFxgGjwSMcuXgjNkJ5HhITFq3whkXYGmzmgq9KCSPfSEZArwXJp8THUlfo6pQ76SR1lEIlfpReep/U= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a17:90a:cf07:b0:2d8:8c74:7088 with SMTP id 98e67ed59e1d1-2e2c7f4f80bmr1263a91.0.1728497871555; Wed, 09 Oct 2024 11:17:51 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 11:17:38 -0700 In-Reply-To: <20241009181742.1128779-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: <20241009181742.1128779-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009181742.1128779-5-seanjc@google.com> Subject: [PATCH 4/7] KVM: x86: Inline kvm_get_apic_mode() in lapic.h From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Inline kvm_get_apic_mode() in lapic.h to avoid a CALL+RET as well as an export. The underlying kvm_apic_mode() helper is public information, i.e. there is no state/information that needs to be hidden from vendor modules. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Kai Huang --- arch/x86/kvm/lapic.h | 6 +++++- arch/x86/kvm/x86.c | 6 ------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index 441abc4f4afd..fc4bd36d44cf 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -120,7 +120,6 @@ void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_= low, u32 icr_high); int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info); int kvm_apic_get_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s); int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s); -enum lapic_mode kvm_get_apic_mode(struct kvm_vcpu *vcpu); int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu); =20 u64 kvm_get_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu); @@ -270,6 +269,11 @@ static inline enum lapic_mode kvm_apic_mode(u64 apic_b= ase) return apic_base & (MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE); } =20 +static inline enum lapic_mode kvm_get_apic_mode(struct kvm_vcpu *vcpu) +{ + return kvm_apic_mode(vcpu->arch.apic_base); +} + static inline u8 kvm_xapic_id(struct kvm_lapic *apic) { return kvm_lapic_get_reg(apic, APIC_ID) >> 24; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 046cb7513436..c70ee3b33b93 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -667,12 +667,6 @@ static void drop_user_return_notifiers(void) kvm_on_user_return(&msrs->urn); } =20 -enum lapic_mode kvm_get_apic_mode(struct kvm_vcpu *vcpu) -{ - return kvm_apic_mode(vcpu->arch.apic_base); -} -EXPORT_SYMBOL_GPL(kvm_get_apic_mode); - int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info) { enum lapic_mode old_mode =3D kvm_get_apic_mode(vcpu); --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:45:48 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 789DC1C2DB8 for ; Wed, 9 Oct 2024 18:17:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497876; cv=none; b=lO9sI2oxeFUD30D9AtA824oZPMylzKqqc6HqKMjQW7eOtALHEz8xGMlPtzerOdyMK8J9HWj7MlAHkB/G9Ah+PxPKMe6fjqsCAa+ghU527iezdfulvi594Uwn90kxdYuZjFiE+tWr4xHSORPchJEi51AfHE/U8HoprQDvXbgM1VI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497876; c=relaxed/simple; bh=GnpcuwMdkFaGr6O5Lmms01caFImUqZlbd0zCVFngLZM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Av+o/eM2TjSKHIzWlZZPCBwKI1SKuGzWGn1iBBr4hdxaXO65h+9oQTNFEVp9AQGIHutU9B2VphGLTOqXzTGyZhBmdvb8n4PT6DCRydufVjf/u0U+FXraJUcY0PksY9p5J3NkGDHznbRTjMasVU91WW5ula069kAzUI7m8si1JoA= 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=o8b4Ykvc; arc=none smtp.client-ip=209.85.219.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="o8b4Ykvc" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e02b5792baaso44285276.2 for ; Wed, 09 Oct 2024 11:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728497873; x=1729102673; 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=rMwbZf1LmTNfEGZdnzInWLtMby5O9zhLRFRQddIF11U=; b=o8b4Ykvcjx+cVqgOjQ8unNtBY3JAXK9ySaWkuGvWmf2+TKp4Z/0EctnUX+4zyrI8eS ixTc8ALs0AsA7wKm8Gphuza9NRZoWX5d01kvlFm/EZErXsjfw+FQLlhmyZ4Fmh9CarOV vAk5LyKLsYvS9CMEhd1b9DPwDO4LJBkUqljrtM/zrn8oG7H0OATO+hDpsBfP4wBnjW9F UXi0rU71qz5HZDDyc5+R3DGsQJZKv8k/WQuIYOvCw5k0QLz5/bhWccaAiHFLPZ/WOc0V +6ZuOuCuFBHkRXQcZUlzGEMshW5hP9/W8nj7RUXHh8GNNMRlkgmrftREFFHKEfeuU4Rt qIWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728497873; x=1729102673; 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=rMwbZf1LmTNfEGZdnzInWLtMby5O9zhLRFRQddIF11U=; b=DekKlhraUSpHcbtkg956aH4hLyg+RvmRZPMhmxrUIH6cDpdofA33O3TPB+5lcJ5tGI EmaRnrb3bfr5zFgLzX0lNj6yb9kk0TbTkGLB8bIRSBGZv7v3aZrSmOPk4wbFKnJIcSHU ThxjL7nMmqomPnz5CFqoTRFQd+En0qmgvaOlLqRTNjp8Bwo2FOoNO3BUwOSU8vNw7ujl pQkiddRG5r2Pe4krjKUI8ydMT6lO6hrRlPfQlDMOcEh8pwkI7pKN2KnrMixkxrzgVnvW av466RqYPuc5eRU62KL78Wme9mbutaFm0BHms7OlLr5gIxie0qn+OX3vOnLSJmoxsmSE 37Mg== X-Forwarded-Encrypted: i=1; AJvYcCVShMJUxQeXPSUquonT2/VDthtBNN3Shfb96bKU+5979ZSu9gmZrUVMnedB6RPS0B2g6y7L3A5N8fDRvJo=@vger.kernel.org X-Gm-Message-State: AOJu0YzKXoehWBdmyMJyFun2dF3fK9R4Q0Cyu4mGVFYd8343BCEZmnzt BnHmGOxJK23u2Lf0ltRVqBaoyw3IzewFXTHNg7Wfqj5Ys/w8KFLKyBUpRCiEZj8NUA5TAX6n6Ju r6A== X-Google-Smtp-Source: AGHT+IEvsS4c3s6n9g7x2z5D5H012XZQOsx3RuO4m9O7OjJK48IPzr0OmRE9xbrojGbugDgpO+45yxUumnA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a25:d84c:0:b0:e28:e9ea:8cca with SMTP id 3f1490d57ef6-e28fe3fc233mr56043276.8.1728497873567; Wed, 09 Oct 2024 11:17:53 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 11:17:39 -0700 In-Reply-To: <20241009181742.1128779-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: <20241009181742.1128779-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009181742.1128779-6-seanjc@google.com> Subject: [PATCH 5/7] KVM: x86: Move kvm_set_apic_base() implementation to lapic.c (from x86.c) From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move kvm_set_apic_base() to lapic.c so that the bulk of KVM's local APIC code resides in lapic.c, regardless of whether or not KVM is emulating the local APIC in-kernel. This will also allow making various helpers visible only to lapic.c. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Kai Huang --- arch/x86/kvm/lapic.c | 21 +++++++++++++++++++++ arch/x86/kvm/x86.c | 21 --------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index fe30f465611f..6239cfd89aad 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2628,6 +2628,27 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 v= alue) } } =20 +int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info) +{ + enum lapic_mode old_mode =3D kvm_get_apic_mode(vcpu); + enum lapic_mode new_mode =3D kvm_apic_mode(msr_info->data); + u64 reserved_bits =3D kvm_vcpu_reserved_gpa_bits_raw(vcpu) | 0x2ff | + (guest_cpuid_has(vcpu, X86_FEATURE_X2APIC) ? 0 : X2APIC_ENABLE); + + if ((msr_info->data & reserved_bits) !=3D 0 || new_mode =3D=3D LAPIC_MODE= _INVALID) + return 1; + if (!msr_info->host_initiated) { + if (old_mode =3D=3D LAPIC_MODE_X2APIC && new_mode =3D=3D LAPIC_MODE_XAPI= C) + return 1; + if (old_mode =3D=3D LAPIC_MODE_DISABLED && new_mode =3D=3D LAPIC_MODE_X2= APIC) + return 1; + } + + kvm_lapic_set_base(vcpu, msr_info->data); + kvm_recalculate_apic_map(vcpu->kvm); + return 0; +} + void kvm_apic_update_apicv(struct kvm_vcpu *vcpu) { struct kvm_lapic *apic =3D vcpu->arch.apic; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c70ee3b33b93..a2a2a6126e67 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -667,27 +667,6 @@ static void drop_user_return_notifiers(void) kvm_on_user_return(&msrs->urn); } =20 -int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info) -{ - enum lapic_mode old_mode =3D kvm_get_apic_mode(vcpu); - enum lapic_mode new_mode =3D kvm_apic_mode(msr_info->data); - u64 reserved_bits =3D kvm_vcpu_reserved_gpa_bits_raw(vcpu) | 0x2ff | - (guest_cpuid_has(vcpu, X86_FEATURE_X2APIC) ? 0 : X2APIC_ENABLE); - - if ((msr_info->data & reserved_bits) !=3D 0 || new_mode =3D=3D LAPIC_MODE= _INVALID) - return 1; - if (!msr_info->host_initiated) { - if (old_mode =3D=3D LAPIC_MODE_X2APIC && new_mode =3D=3D LAPIC_MODE_XAPI= C) - return 1; - if (old_mode =3D=3D LAPIC_MODE_DISABLED && new_mode =3D=3D LAPIC_MODE_X2= APIC) - return 1; - } - - kvm_lapic_set_base(vcpu, msr_info->data); - kvm_recalculate_apic_map(vcpu->kvm); - return 0; -} - /* * Handle a fault on a hardware virtualization (VMX or SVM) instruction. * --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:45:48 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 63CB71DF734 for ; Wed, 9 Oct 2024 18:17:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497878; cv=none; b=ZtNl3X0m2y1g5O30mQonFcPhtZcEeGdd1dGG41iaDi8zfvHc7dEpHEyt1/99dCVp8224jnkI5Dlr5eCihL4yyG7OX8eLo04HP1sukeQtbI77eDj50xTEqCpltFzNewpgzEtwy/LNYr1AsEw5fHfCa/dXrFqDmEzTueHtar3RaA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497878; c=relaxed/simple; bh=lT1ZYT62nfExH90IUevqSKyYCT9nh/Q35XBGNwwaFTA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aDdNoMrYyf09FgppivnWGJvGgHrXsbZZ5IL4QPONIYWfcRrqAqe/q1Rvv7IJoQwZfMjeCufLO5IZpZVMuAhYX7PVuJZT8T8jKct+Fghrz4ZVah5IqmjIl6xRwmnSlK+NGqAqbI+t06MPh0dql7n2f+Ps4OrNAss0WZGdhHLS4wY= 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=IwBjmCun; arc=none smtp.client-ip=209.85.219.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="IwBjmCun" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e02fff66a83so90001276.0 for ; Wed, 09 Oct 2024 11:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728497875; x=1729102675; 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=Kt7FHOB1935LxbC6vNqAogsIeVnq7546lEYAivm6tgg=; b=IwBjmCunJKcjnpHjPu3yLpGnAYlIglcmQtpe5d5tZReInudwhtCzZSrUX/i/zXaq44 Bgi0CG9LiUR3NwKYcyx9ZWXY3crwgMSONiEfemSS8j7AHQ483g8iOmxWF3bynlaQUlmJ QR7bD0dKTRXl7pNYGiKQR1qYcG5gmzxjfsW8ZGzc8czwNiwnSvYcmwWDAxbBjMZFekas 5wihCJjsCMtqqGxktX1RGaITxnl/xh+MAAbsD6YE5sgYiJEhxp/S8lLWXZm7RO6Fn9iz aSh767f6xIGpwSnZ/2KOjWDRxCGnIqEQrN2W3/dIi0kS3Uxo/b2GxaMI7D+hgEvxJH82 WMLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728497875; x=1729102675; 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=Kt7FHOB1935LxbC6vNqAogsIeVnq7546lEYAivm6tgg=; b=B4x74rptv9Vs5EtJopMUoYIuJAKuErfjEKICltUYM8874bB6yPFQppbb6qHtpm/dIV bhXvGpaXVPlfRn/f0dnXhrXA07zlKdRpOHUo4mopdB6hZfBZoxvYeShAiF/OOCM9aDCx 5wrQPFH3oDqBkcnzApcalpiBVJSjx89U+MVBoasVFNlAuRVHCdY0w1PLoSX025F0k0dw sLZJNLe8q3j8FSOwzMXOv9uZm13NpvMX5vFvHcSmJBl6F1Xra/t5IDAIVggYA3FnU1MZ j2g7AQzp7N0SKqM6eB/prFGVWTrDzWQDZQFtvAWznEVQDbNLtjtxx2JNRqlCsADBdsdG bibg== X-Forwarded-Encrypted: i=1; AJvYcCUun0MVCOnVqYUeYyia1NjyypWORc79cMr0A7Qnim5EqmDyG7ZEF5YVmrx1LDz7Rzqn06vhlekea7zUO1Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzzvXE9WgsptVafoiJ1Q7Kkuvj/L/OJMFTbXSfHJvcrIJE5/sWH zJ9XhBbwt8TviPJ6q3b4E0C49wAGqjW3Bfi4FzeACWu+LGg2rbisPEcv8U16PTS+2bHHbKVQ9KU gGg== X-Google-Smtp-Source: AGHT+IGocRXOmVCQlqmoBkHUcGAAivPICXDUGWlVk79DtpyGqwVyyI7/c8wZnPktuAFL8/nvHRwhlb2HbiE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a25:d806:0:b0:e22:5fcb:5e22 with SMTP id 3f1490d57ef6-e28fe33b922mr2742276.3.1728497875306; Wed, 09 Oct 2024 11:17:55 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 11:17:40 -0700 In-Reply-To: <20241009181742.1128779-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: <20241009181742.1128779-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009181742.1128779-7-seanjc@google.com> Subject: [PATCH 6/7] KVM: x86: Rename APIC base setters to better capture their relationship From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename kvm_set_apic_base() and kvm_lapic_set_base() to kvm_apic_set_base() and __kvm_apic_set_base() respectively to capture that the underscores version is a "special" variant (it exists purely to avoid recalculating the optimized map multiple times when stuffing the RESET value). No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Kai Huang Reviewed-by: Paolo Bonzini --- arch/x86/kvm/lapic.c | 8 ++++---- arch/x86/kvm/lapic.h | 3 +-- arch/x86/kvm/x86.c | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 6239cfd89aad..0a73d9a09fe0 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2577,7 +2577,7 @@ u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu) return (tpr & 0xf0) >> 4; } =20 -void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value) +static void __kvm_apic_set_base(struct kvm_vcpu *vcpu, u64 value) { u64 old_value =3D vcpu->arch.apic_base; struct kvm_lapic *apic =3D vcpu->arch.apic; @@ -2628,7 +2628,7 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 va= lue) } } =20 -int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info) +int kvm_apic_set_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info) { enum lapic_mode old_mode =3D kvm_get_apic_mode(vcpu); enum lapic_mode new_mode =3D kvm_apic_mode(msr_info->data); @@ -2644,7 +2644,7 @@ int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct m= sr_data *msr_info) return 1; } =20 - kvm_lapic_set_base(vcpu, msr_info->data); + __kvm_apic_set_base(vcpu, msr_info->data); kvm_recalculate_apic_map(vcpu->kvm); return 0; } @@ -2752,7 +2752,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init= _event) msr_val =3D APIC_DEFAULT_PHYS_BASE | MSR_IA32_APICBASE_ENABLE; if (kvm_vcpu_is_reset_bsp(vcpu)) msr_val |=3D MSR_IA32_APICBASE_BSP; - kvm_lapic_set_base(vcpu, msr_val); + __kvm_apic_set_base(vcpu, msr_val); } =20 if (!apic) diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index fc4bd36d44cf..0dd5055852ad 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -95,7 +95,6 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_eve= nt); u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu); void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu, unsigned long cr8); void kvm_lapic_set_eoi(struct kvm_vcpu *vcpu); -void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value); void kvm_recalculate_apic_map(struct kvm *kvm); void kvm_apic_set_version(struct kvm_vcpu *vcpu); void kvm_apic_after_set_mcg_cap(struct kvm_vcpu *vcpu); @@ -117,7 +116,7 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, str= uct kvm_lapic *src, struct kvm_lapic_irq *irq, int *r, struct dest_map *dest_map); void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high); =20 -int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info); +int kvm_apic_set_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info); int kvm_apic_get_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s); int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s); int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a2a2a6126e67..803db3e9ab8a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3858,7 +3858,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct = msr_data *msr_info) case MSR_MTRRdefType: return kvm_mtrr_set_msr(vcpu, msr, data); case MSR_IA32_APICBASE: - return kvm_set_apic_base(vcpu, msr_info); + return kvm_apic_set_base(vcpu, msr_info); case APIC_BASE_MSR ... APIC_BASE_MSR + 0xff: return kvm_x2apic_msr_write(vcpu, msr, data); case MSR_IA32_TSC_DEADLINE: @@ -11865,7 +11865,7 @@ static int __set_sregs_common(struct kvm_vcpu *vcpu= , struct kvm_sregs *sregs, =20 apic_base_msr.data =3D sregs->apic_base; apic_base_msr.host_initiated =3D true; - if (kvm_set_apic_base(vcpu, &apic_base_msr)) + if (kvm_apic_set_base(vcpu, &apic_base_msr)) return -EINVAL; =20 if (vcpu->arch.guest_state_protected) --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:45:48 2024 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 E12AD1E32A1 for ; Wed, 9 Oct 2024 18:17:57 +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=1728497879; cv=none; b=EN2v4ay0kIUP/Sk1BfMZmV8fr/tlL7CaamWfkTPIyAkGPxeOwNTHSuoaGKG1H9359YsNB0GAwcZSddVcXnGzeKQHH0n1XXmnIBY0pQjIAmkYlny0UTwh9hpRZZrG5cthaeci1CmJsiSl78vugy6fGbhxQrAkmEbowOrTNafSLlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497879; c=relaxed/simple; bh=ExK2B45+IldPIhcp+mgV/yZse0LGT5sPNb9IYvCVpXQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kGA95wHswqg5Yly0zkyxNYoHWhgF/riTzsZTdv+HkzEjVL/FYMnSKizFPRtrv37n2Db3CCVRIh1saNwi0tcRxkMlfeCWEdyra9X3NhrQQOYu+VJ5D/0L48a4RocRF2xZQ1FmxKvEVbbqGV3/bOp+5PAZP9ibaDRIYm40xTb4V+k= 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=gcIw2BMi; 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="gcIw2BMi" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7e6cc094c2fso1011802a12.1 for ; Wed, 09 Oct 2024 11:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728497877; x=1729102677; 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=MaWbmPdh1mO0Nq8ZJC6BrpKNBUmVzBfz3tM+bJ0ag3A=; b=gcIw2BMi/bfSPdDa4tBo7uKhSBh3/pnSwyGnAkUxFr0gR9ECcOUUSqHugiRYlba5XF IKXq7BPM+Pr3C7mlIu3E39myJEVsPwOw62HecrAvXJgHiBYblUqGIBY87TKc8N5w4Oks 1nVcA8+Mx4doXEjL6R6zWweUo3Hl16rfnk/xYUc8WxJ8hcvLEH6mrNv51VwAlK4/TMoz DU7HkI7EshmXbilQlp7+e8NY0ePgVfZXAct3Tscg+4WNzOGPtIgGHVdpnTVX6rXZz1yw A3CNvy6tPe5/j8oz5A7ZjOu85YiYHe4gsNcZVFpax9SXQ7gVC3Cwkm4Yy6CpjWPKVVoe PXJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728497877; x=1729102677; 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=MaWbmPdh1mO0Nq8ZJC6BrpKNBUmVzBfz3tM+bJ0ag3A=; b=hOy2OlTKanjHgzePfcrWKUzAKKf7TWngICXEdhZrhuEQPIek/Oub5xCCa9sUI1L4Nb S45NOAgeliasAWiDIMKHRcfM0AtKWfnA6Vs0rUtSMtvqMwDahLDTCZIcei7kZXEu9bBW +Yjzr/Mo+y/vvVhhHgi9KJqq0+1UWCXuC71ySmDeG90Gd3AwRyaxLzzOyTryFHiZU5mZ 6UCh8vt3H6brmuqaIt8GTeRbhxoMo6O8jNyd4/Ak62mE48eU8hWVz0xXu7FS+9WHFWeQ So4ck5VhSz7EiQQd4/PEgaIie/xX+7kmi8f6uUHYnPDHSEMrXyb1JcdjR+piAnuL3Qq+ 02yQ== X-Forwarded-Encrypted: i=1; AJvYcCURncCYg9vrpOdYAaUgUI+pIXAs9MYvKNDrCMsqksRx10pxbVYCQ2ZunUmJDTCM/DatfFjNi0hezV53GK8=@vger.kernel.org X-Gm-Message-State: AOJu0YwSab4ueD5KoWs64kAoBoyuNbSTn3fcioryI1QY3LBgSnbR93s9 si9gDb924mQ9/JJCmhq24uBQwxfhpnmm9TRhR1qHV/prqDZMb+UIduO4GT4CnyLPqZX+L4Y9w1/ xJw== X-Google-Smtp-Source: AGHT+IGNIE/edZnSUhMLEyYIvFpZ/Bc88mfOHpXxJTPoPiSpDG28tToOr/MFA+a/5VyqkU8h8H9o9tS/A/o= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a17:90b:815:b0:2e2:bf47:956e with SMTP id 98e67ed59e1d1-2e2c7ff9325mr656a91.1.1728497877077; Wed, 09 Oct 2024 11:17:57 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 11:17:41 -0700 In-Reply-To: <20241009181742.1128779-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: <20241009181742.1128779-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009181742.1128779-8-seanjc@google.com> Subject: [PATCH 7/7] KVM: x86: Make kvm_recalculate_apic_map() local to lapic.c From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make kvm_recalculate_apic_map() local to lapic.c now that all external callers are gone. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Kai Huang --- arch/x86/kvm/lapic.c | 2 +- arch/x86/kvm/lapic.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 0a73d9a09fe0..21fe50aad603 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -382,7 +382,7 @@ enum { DIRTY }; =20 -void kvm_recalculate_apic_map(struct kvm *kvm) +static void kvm_recalculate_apic_map(struct kvm *kvm) { struct kvm_apic_map *new, *old =3D NULL; struct kvm_vcpu *vcpu; diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index 0dd5055852ad..fdd6cf29a0be 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -95,7 +95,6 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_eve= nt); u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu); void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu, unsigned long cr8); void kvm_lapic_set_eoi(struct kvm_vcpu *vcpu); -void kvm_recalculate_apic_map(struct kvm *kvm); void kvm_apic_set_version(struct kvm_vcpu *vcpu); void kvm_apic_after_set_mcg_cap(struct kvm_vcpu *vcpu); bool kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, --=20 2.47.0.rc1.288.g06298d1525-goog