From nobody Wed Nov 27 14:21:42 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 BB8291CEAC7 for ; Fri, 1 Nov 2024 18:36:07 +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=1730486169; cv=none; b=rZ9ih1Qv5Ivxj7ROT3mDPBqeCAvJ7zTYtnK9HbvcI0yuZ7eri2TmFMfQIAplCZWnKlri/HlW3c/uaw56Mc7QYEoPkSXIxnLrYPNQS9u9HPcBGhBh7pWCo/SCfHoFktBUQX5WSZGsalW4ZWDMD7xyrxEYMrwvwAP63TwE2c6zWvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730486169; c=relaxed/simple; bh=Zq395NiiKporolLjoST+6+2+QTwzJOuMC+X29AbEL8U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Voc+/OAxC0MKYwoUIKvrm7sKZYR0afg34ZSN8HIsy+9zd+Bpl7Xu6WaxsKn5iXwCHG6UnfmZqzT6atvbrg32+OINDQu1fIY09ZzruK8wawVeGnZof/FXPAhnSt4VnURJ/RxnoESeTKm7RVixghU2ttddDlSYto0Iu5akUZ5FcaM= 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=h+0/seQw; 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="h+0/seQw" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-20d417fc584so26079895ad.1 for ; Fri, 01 Nov 2024 11:36:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730486167; x=1731090967; 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=6jSxIG8GHxBvV25BqBO2yI1fCAIS8ozpFMSRDXOmwqc=; b=h+0/seQwYnhYGdnQNS7FT1h53uIlhgyljfiZluwq9hSH4/GWPJCTQo6LlM2YS5gnUJ BO1aphj1nfZjNRaF74cS3iaYRN7rmbbol1M2yzzMjKePaW7LWv5dzx+mgOuueMLQbTYY bxu3e6zNhymaSULDHYzAtV2Xy4MfR6gOzT6itK+xtuQLPFYe98BpzyqlbKKJRHICCLLD ZE2bzX6KTTXI9uQJF/0AvwnPVveFoX++ybYWZvdbZc59DA7H4GVb232E623w5+LAnFJx uPcMC0LWpv/pR/2mYr40YOPFcbRrS3+qAFI6OJ4YegyMUEkTbwvGjTBK5NvJFXlS0MWa ye2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730486167; x=1731090967; 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=6jSxIG8GHxBvV25BqBO2yI1fCAIS8ozpFMSRDXOmwqc=; b=L6xukibms4TnLJfaFXveWyERWzFf7zGI0cXx4ckAxIovXXV19yqo15uoIyoHXmTrFK DgsQx9BbChQf1JeLLEaZC+Q1Kh1wYB7pB06qK+jDpCjq/AJbw8gyMQH4BzY/rm/PwLtC UYDFf4Dn13pARZWu3+6EMKwk502WCRLdNVwGMh2JUFMNqcfFd/SHfs/GwJCMB1ZuEy3B JecUTWRmp1xcwwOfEeeDgkcvR8/a/1bwSF/Y+GRNk2Jx+QkkOZbR9M/UewYO1xjbXFNl 8i2ntgSUj37D8uikVgombipyNR5ONPmjG3ZqXgyASdIcHkktDw5hwz3lX+Z/IVpxSok/ oLoQ== X-Forwarded-Encrypted: i=1; AJvYcCUDytBBIEMyy15VMx/OMT2ACx+ZoL9U5PlKrIMlgYHpmfxYbD3VRXQ59s71Mv6wHmE224YRwcdQMRsRCIo=@vger.kernel.org X-Gm-Message-State: AOJu0Yzqtygf6gDsqZOrmda2yLPQi37jM00CMEINjiVCcLiuXeTutOA2 ocgPsLkPqfItE7aX9Qywuy4seqEA5iv+QKlGnBla9mioAyTIC+T+GXd4U7APp5/5AG5Z319GXlL WDw== X-Google-Smtp-Source: AGHT+IFrzmaPgq4f61T2d+s5PZaLEK0ub9APvURzd9YoOZMotBWAM23YHpiHaxsWiIK/KyaT/0sYL80OMUA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a17:902:864b:b0:20c:90b9:3cf1 with SMTP id d9443c01a7336-21103cf3ef7mr80685ad.7.1730486167022; Fri, 01 Nov 2024 11:36:07 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 1 Nov 2024 11:35:51 -0700 In-Reply-To: <20241101183555.1794700-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: <20241101183555.1794700-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241101183555.1794700-6-seanjc@google.com> Subject: [PATCH v2 5/9] 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, Kai Huang 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. Reviewed-by: Kai Huang Reviewed-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241009181742.1128779-6-seanjc@google.com 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 9f88a49654b0..b4cc5b0e8796 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 95af45542355..57dca2bdd40d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -668,27 +668,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.163.g1226f6d8fa-goog