From patchwork Wed Oct 9 18:17:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13829047 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 8499C1E04BF for ; Wed, 9 Oct 2024 18:17:46 +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=1728497868; cv=none; b=silKG/hP4mEes4V9c8MF3EzZLNw2wjmC1WM6GsGhttdPNFQ6VKTR1oB1xb7YElRV7gXE0K32kJ1pzAvVdIGHQMR4AEIsTfomOovFnyF+kXuVFDj78KW06JgSFQ9j/JnvejlkjBfnX4Q4P0aqTEDXhpV9HJPxy1kitP+jz3KikOs= 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.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="bRjp8Pvg" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-70ac9630e3aso106330a12.1 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=Sjy395JQy27JyEiLOqyYn9Uj86CDqopXKan4IH9kKxc5TezOwd+DfN85LCJDJgApmk 6nDHjxa8w8PBRcABXM7jxNaOKmrYK62UA2Pspgoqcd32/4Zf+i4ijAqGfimedraHpQvK uZi4F2VtbFLf+UAksr6p+oJSylX1pEK4dD/F9A8bT+2w/TybPmakx7wJ4K9FHqXPoS4r l4zd+HvCWbz2fOgo8U83/kWcPc9gy8Vu3Y0Oar739IUhz2N79wyvpSajNK9HXhOEUhwD 2zjv638wj9pyQWgjxQcLh4/3rmWWq65VjbN3F8QU06HcJcfwP3jKxyjqQIjQtZ3DjsW9 c4Lw== X-Gm-Message-State: AOJu0YwTI+GRCOZNs054rPTKAKtQRm0Efzai/rLzczL6Cu0U+9ESySTP dAScijP9P9n5D/8+3oQs7+q/KtyONHM/vi3ocspI4kQ3DgTkyleiACg33EurgFXGDeUf0mLj6e5 ISQ== 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: kvm@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 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 --- 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 value) u64 old_value = vcpu->arch.apic_base; struct kvm_lapic *apic = vcpu->arch.apic; + if (old_value == value) + return; + vcpu->arch.apic_base = value; if ((old_value ^ value) & MSR_IA32_APICBASE_ENABLE) From patchwork Wed Oct 9 18:17:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13829048 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 730F11E0E05 for ; Wed, 9 Oct 2024 18:17:48 +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=1728497869; cv=none; b=BOyxbW6lg7ChYiDyI3+kxwZ+58oLSEBkogfyTZiKM4DLW+LnHEdrwPnNq+wxw6IOC1rvm92xLPXfkwEyGwCWJUYju9pXOTIs0cA9v9JUqyoB47lFyBm+Dv2x2xF01mABWY5q0Koe/J8bO8S1dckogBAMnNKWybFlYR4lMUr5144= 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.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="ayEExf5E" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-71e026caf8bso118676b3a.2 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=HP7ruPYtkKKgCVk1eXkWNbsyRLyDeR2PY29MwcIo9NnpMWlirEzAI4+OekcM7TnzjE mya8ygT7bwJJVtWxrj9DHed4tIbGZLBemzpSWKSi9OpBtOPSxaM2zdm/Ew6ia+yzqVqd jV7KFOPHXoRMWqL66oUnnuBYVr7q5pdFE9+P7FBnCLfBMMLya92g0wfVVITF+rTs8u9f yZWmfRpeKBFBqDKAToyhJ4eLxa6l7j4Ra0pbxBfYMH8egfinxOteAY63yUs0h9Ad/UYv E9WnueVYl2XJef5i7N1SRLNXLhjf2qzZsh4VyPCyD/k5DzsHUoTQVoJTfdKhcjE6U3NM +dGA== X-Gm-Message-State: AOJu0YyJCvj/AV4khDd4/aPmpbeuncUnva8LTkIldcmRJsHDIp7RwXhp vtxnzSNsT+e7x3xlGrdGvxdbBevncHTaHpJz0mzfCrxFHKMhs+rUfoOI3YiV5Wv8Ol3luh7pFTB GAA== 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: kvm@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 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 = 0xfee00000 | MSR_IA32_APICBASE_ENABLE; but it also called kvm_create_lapic() when irqchip_in_kernel() is true. Signed-off-by: Sean Christopherson --- 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) kvm_x86_call(apicv_pre_state_restore)(vcpu); - 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))); From patchwork Wed Oct 9 18:17:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13829049 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 871CA1E1A3F for ; Wed, 9 Oct 2024 18:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497872; cv=none; b=a7P+eRdrwAEEnYxqlTLTtJ68n99prdkEOZ8blO/UV9BG4b+21nJvNIvYxO86/71SR4fe1TA/PQfjfTl+2A7rH9pnpHPFFEfGZ9qKWi3bzv2d6uXrCY2x8amUj+qeBgZX0BuSItZou4mCgf5j3bWDwbRRyxEI/qyUzMRqyDN69sU= 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.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="k6Rg2T90" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-207510f3242so606165ad.0 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=uX0FG4G2ORYOwLx7mYnSwdvox+Z5JnbkJt37yhrSOByIT3/mjSr1J5QELSKWYUokuj bvzoPsnHc3skTKEEKJP780iqyza9BykVHQtgV6I/fA8o3ZX72VJBKux3CJSn0CDc/1sr xmScktwpCu1hFtY8eUHNmAICOkXFrZgZfbiB9okM4aLcXXKQCObSTn7ORRvnq1iCAzjP Cj/U1w7CV4RRuX7CtG/btmoNvpZ78Qa0HOVYem9yqsgb/60WNm6N/zE7EM+mgs9kdpXj 6gjR6GJP2e+TZESex3GxucHwe5iQh1rfz33MwyfqKq/1P37lPa0Xwwxp7fMa9aVmw7tB 8pWQ== X-Gm-Message-State: AOJu0Yy6ShXV9XxDzMn+b8F/g9+zFzG32HWjKybPao5vWpGjqlA5b6/r JC3YOuDV2Al/DhAQNnVia/B81rjXAL29E147okOPvYhh0B3a0iUKYPYBQcovOapM5PH2VYRkK+i j9g== 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: kvm@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 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 --- 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, struct 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); -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); } -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); @@ -4314,7 +4309,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) msr_info->data = 1 << 24; break; case MSR_IA32_APICBASE: - msr_info->data = kvm_get_apic_base(vcpu); + msr_info->data = 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) kvm_run->if_flag = kvm_x86_call(get_if_flag)(vcpu); kvm_run->cr8 = kvm_get_cr8(vcpu); - kvm_run->apic_base = kvm_get_apic_base(vcpu); + kvm_run->apic_base = vcpu->arch.apic_base; kvm_run->ready_for_interrupt_injection = pic_in_kernel(vcpu->kvm) || @@ -11711,7 +11706,7 @@ static void __get_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) sregs->cr4 = kvm_read_cr4(vcpu); sregs->cr8 = kvm_get_cr8(vcpu); sregs->efer = vcpu->arch.efer; - sregs->apic_base = kvm_get_apic_base(vcpu); + sregs->apic_base = vcpu->arch.apic_base; } static void __get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) From patchwork Wed Oct 9 18:17:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13829050 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 36D3B1E22E2 for ; Wed, 9 Oct 2024 18:17:52 +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=1728497873; cv=none; b=oqvACkOd+CgyZ6HXCt40jHGhXQ7HcZRUPrIslTWi1mODU3dJDkmgPQfimZDO6zarkIdMBwdv1nu9TRfY1uOhkBVuS7UjW02hLCdtSK8UaO8t9EhX3NSkaYwT6UeY7IDGM+cwEIvEpVCqexZNHX0MSVstpvzbIhSv6IACvoPKLJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497873; c=relaxed/simple; bh=dr1ocippoTiMHINFoEKeoOJdkH3TJbfSreMvnI8POao=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IilrEsufyzO2mVzhssHTBQNODPRIiUJ+/vJwM1E6KzSY4Z/2nRQo6HQ0srWBpQqI5in24ncS7D0KOWmhNYqPTfEuMCydYaPuavwwRaEaG7c4fOAwy+Y26bk88k0iE64fkNfTIz8sd48BCJI0gefGyDcLxzXesyoztnmIpt3/TvM= 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.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="imfZ9yF3" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-206b912491eso12480045ad.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=knRdos+shgXa1k8g4IbIm926yQlkmc73nqLSOFNsk3vhlnwbQ1D0LeT/6mmom3ht9g geKSLtbiwWEP//1aH6WWuqIxfAPQ4PqYMuh218hBH6F+Ua29QZzoFOk+SYgo6BgQe1Hk REDLPcE4Ab0jLx55NDXlj2HztvNIPJjNZKl+25tEfWlOBRQlI5VBCIMa5i7JHUUsjAb6 ZzQkxWKl/WbJCPajHHgWfs56Q1nCzdSFukNnNhgqnQhP+Eq7ii/V0x1W6lF559vF7Tli eyLwNX61lkLVCWtyi6RuC/MJY8xGy3cn5cuEW+gA+2C3XFoTxxVkku6CLm+R/RxEHLNr kuTg== X-Gm-Message-State: AOJu0YyonuBrvRBjLONM5GFLZylhDWMXD5h6MQxYt5qSqzoJWq76BeL7 vgFIaTQqVQhG3KJLOtc5ojY96uIRy7YZJWA6RcIWaXxCzsnzuLikV4WT+VIIzrQHOUecOlHc/Je DCA== 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: kvm@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 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 --- 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); u64 kvm_get_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu); @@ -270,6 +269,11 @@ static inline enum lapic_mode kvm_apic_mode(u64 apic_base) return apic_base & (MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE); } +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); } -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 = kvm_get_apic_mode(vcpu); From patchwork Wed Oct 9 18:17:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13829051 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 8CA571E2604 for ; Wed, 9 Oct 2024 18:17:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497876; cv=none; b=LSgefF3OD+XnSW6ewjFsLoh5XIQQQTHV4oYq7XUy4nDpcyqELxejrtOZ7HeCKLLqNRb2eZIFAw9jnWsXs9un1Y59RHPjtNBayJmma09IdT9tIRDj6l93dT7UEpFayM7/bOzWGlMUe5lNbYu9JShfHeR0JAjKMVi/4vuFDaKmxc4= 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.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="o8b4Ykvc" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e28edea9af6so40234276.3 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=c/ShJ7yoRjy8S0c8PYPaWczWYz3FWov0DfIAtCOPGyCMYblExkn8msHEUjitWqU/aD RWfuopw9BsjyJqeYaK4BM2QpKnRBkLUMIcMHyMG18rTGJJziIIa6bvd9XoU8u4w2pKEK +zhcxxwC2z4kIS59ep7D2IpTXMHlQPGCLcy6B5PiSloykC4FjrHp16HHVGmBu/49/72E W77W7eaKXBzrhkEke++MyZ2E8kWgk3IQ/OAHufBbaLOqQ1ldV6jzzPwl0mHmRMo/xb8B c+Siq/SkQ4L9CS+fqgVIzMdWjDMwkRODs0WxC+WEb08ddrdWtOdP0B3lQGW+LdHiNlh6 UjAw== X-Gm-Message-State: AOJu0YzGIyQGlSME/I5Wo0H74G2t3JQztNtnwlPBcvpaCLq72v01mxQT NcmwxOhjTo/TPIfW17+9S9BqC0rvAkC0m3FN2LjcCzOJ3j3zQLcp+xx8or8kRhSlGqDBOy5C5V1 EJQ== 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: kvm@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 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 --- 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 value) } } +int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info) +{ + enum lapic_mode old_mode = kvm_get_apic_mode(vcpu); + enum lapic_mode new_mode = kvm_apic_mode(msr_info->data); + u64 reserved_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu) | 0x2ff | + (guest_cpuid_has(vcpu, X86_FEATURE_X2APIC) ? 0 : X2APIC_ENABLE); + + if ((msr_info->data & reserved_bits) != 0 || new_mode == LAPIC_MODE_INVALID) + return 1; + if (!msr_info->host_initiated) { + if (old_mode == LAPIC_MODE_X2APIC && new_mode == LAPIC_MODE_XAPIC) + return 1; + if (old_mode == LAPIC_MODE_DISABLED && new_mode == LAPIC_MODE_X2APIC) + 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 = 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); } -int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info) -{ - enum lapic_mode old_mode = kvm_get_apic_mode(vcpu); - enum lapic_mode new_mode = kvm_apic_mode(msr_info->data); - u64 reserved_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu) | 0x2ff | - (guest_cpuid_has(vcpu, X86_FEATURE_X2APIC) ? 0 : X2APIC_ENABLE); - - if ((msr_info->data & reserved_bits) != 0 || new_mode == LAPIC_MODE_INVALID) - return 1; - if (!msr_info->host_initiated) { - if (old_mode == LAPIC_MODE_X2APIC && new_mode == LAPIC_MODE_XAPIC) - return 1; - if (old_mode == LAPIC_MODE_DISABLED && new_mode == LAPIC_MODE_X2APIC) - 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. * From patchwork Wed Oct 9 18:17:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13829052 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 6BE0A1E283F for ; Wed, 9 Oct 2024 18:17:56 +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=1728497878; cv=none; b=oSthG0+v1APiFezN1w1bVmgk/2ZT0vC3/DTjQyfa/mERNvObg1is6ZCOH2Hg3UHQYcx1W6hLhjxcLZAROifnHshWt54ZPvsMkC+PxPju5dk9E5IrI3Axhmx7aVo8GvD10fccp2OnD8Zx4x9nH/AmjWkeD4aSVdkozgfa5hu4iIg= 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.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="IwBjmCun" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e26ba37314so5833737b3.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=SD4ApxTChB21g6H5Lb/r8WHmdF4dnxU0tmEzu0R0SVgrBseV3B7YKKB7O/dl0Wde8Y 7Zf0uZu/C4+CB+Peg1hOf0FAOVXFIoMN79gswlHJxR1kXhJQlkjdNlHwDktRfdRunUu3 o9v4u6wSpYxASsoawAflF26jwc9YOMbqWoSmRTO+h4zPc5zB+h7mMU5iWGiPLl5/9RU3 OpRYxaHSSeHuPWi1GgEix/9xp4NiXYsHEOmCw8CkvenJWcFBsMEkFF/BI6pZSexifcDC OUwt/xjqWw00/qtrrEBSUIqqMsVlTf32zv8tEF5OA2tk0yuccA9BNIef/COZDS1zqUKS izgQ== X-Gm-Message-State: AOJu0YyeMChXHGPhZUr5ZJ8EChmoWqh0lZwpObICNz8SJ8ZC+hkU2ziZ XnCrC7AVk+fgaolYcG3s1YM8vpRbOkXRHlBCUCqZQBV4YVy008Y4mEv6G4uFeRVSVCmEGs8gNK9 GXQ== 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: kvm@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 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: 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; } -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 = vcpu->arch.apic_base; struct kvm_lapic *apic = vcpu->arch.apic; @@ -2628,7 +2628,7 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value) } } -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 = kvm_get_apic_mode(vcpu); enum lapic_mode new_mode = kvm_apic_mode(msr_info->data); @@ -2644,7 +2644,7 @@ int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info) return 1; } - 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 = APIC_DEFAULT_PHYS_BASE | MSR_IA32_APICBASE_ENABLE; if (kvm_vcpu_is_reset_bsp(vcpu)) msr_val |= MSR_IA32_APICBASE_BSP; - kvm_lapic_set_base(vcpu, msr_val); + __kvm_apic_set_base(vcpu, msr_val); } 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_event); 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, struct 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); -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, apic_base_msr.data = sregs->apic_base; apic_base_msr.host_initiated = true; - if (kvm_set_apic_base(vcpu, &apic_base_msr)) + if (kvm_apic_set_base(vcpu, &apic_base_msr)) return -EINVAL; if (vcpu->arch.guest_state_protected) From patchwork Wed Oct 9 18:17:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13829053 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 DFF051E2604 for ; Wed, 9 Oct 2024 18:17:57 +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=1728497879; cv=none; b=AwPEeSMpsV0sGg3nRQkt2YOUma6TFvzo9MY1pQInVG39XouSUOq3wIiI6OVQepCLa8ylj9DuaAHxHxMtYN9UugYp8uxgibwKHvuHXlwAl8dbu7/a2UmK7SocR7t16Bql3J7g4Mor5qjOVDpKhckosCHwoATYF1Qr6Qt1NgqVNes= 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.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="gcIw2BMi" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2e1346983c8so173216a91.0 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=u6FLNi8nGbfaXWN1YEkKcCZyBJJCJ04I5/MLOZ15qnrTdvCnJWkAl//AiRYu8gFCxt qBqlMMEyn9k2i7acECEcIrK+cxUB/epjrSq+aevamnRrQ3Mky/zUnWqwH5jDNWAI+lfR NOokVh57ovivOSulfBgBTFDHgXtvX6sen8X6SYCMUwjjCClu2KXki+AFYxV/fFI2w1t7 mmpArWrAIg8GCTwtoy1C16yEaQhBP2BjevQxCPnsmUM1/h5EOyM8iIVNQSDk7SNjbcRf MpUZoSCqMX83VJU7Oax5nfgGu1jYjX4fXIAhVDWuefPdErt4Vr3ujHyVOR/jhLcpc3Mb LElg== X-Gm-Message-State: AOJu0YyjC+cjWHri0l7oNhRz3uD9MKJW93TvviBFSM+A+0Cszdau6dyv eGqEzag4uoqL/dAqbt+uGAoVq3057tjqnYgi3gOxJAvBEeDipWQbnTjJ7Z7za28vc7tWrtthyoi GqA== 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: kvm@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 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 --- 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 }; -void kvm_recalculate_apic_map(struct kvm *kvm) +static void kvm_recalculate_apic_map(struct kvm *kvm) { struct kvm_apic_map *new, *old = 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_event); 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,