From nobody Wed Feb 11 05:35:55 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F445269AE3 for ; Thu, 29 May 2025 23:40: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=1748562058; cv=none; b=hKXec3EAgLLe6DqbEDaK5+NkHidWyb7yBM3K2c/CkWAkef5EvUOSUz+mhVVv6gFTdYk2FmbWgygTf3bGjCdUapJDp5RE5cEOmQ6+46NNIS6Tj3Np/gAoOWAv/Ylzs9d5UL0IhGLYcmiw3tbFmGc90wzx48mBU44R4hkEotxO0/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748562058; c=relaxed/simple; bh=wiSfnvg+3ob6BZ0Eu3gekeRK967P9Nv3tIdvcIcKxQ0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FOF7c1HWPPddH63RirNAM11+BboLGwcsOvhuOL1h+y3SLe8IkagMhv4e/NUbXPrHrN9Fdhu/8B7f/8Uw+1uK5xssh4xGg7SjBhk08QApT2O9az1wWUMSJ5ghR9OpvmSGjio9bg2oDLLF5PEml/nuXlx6DD5gQfBzNXZPCyfnMKM= 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=DkEmLBI/; 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="DkEmLBI/" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-310efe825ccso1375117a91.3 for ; Thu, 29 May 2025 16:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1748562056; x=1749166856; 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=+CgyWByAaHVV85PeVC13Q9ehun1/Wd3oFQ4GzRhsXCQ=; b=DkEmLBI/LEgYd2QJSbA27/HwX3AD0dc6dmG+tJ6rveX4K/IKKAfIlDZ1erOfPsICPv 6vqm41i1/74DNCm/p8vtbWRb1Jci6r0UokkM/zYM6+/Pmn+cnlSCEyhSiBxuzGfrOfBm 4rnQA1VxotQ58nk03g6Q6WY8h6AeIAdw+XOCQjvw1IP4vlCc05pdUN/d+uQEaXiesOHt esXM0ioW9sAOWt5y4CO2WfactTjOXtW+5rXsECHRlq/4caGcd2+ClKZQXvFIoyy6V58z /T3HCnISGnJy1/6yrnth5mxutGF8rEvTa09VwD2cJN2ms5WrhVFpH/ruD5n2SmEb7+xu x/RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748562056; x=1749166856; 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=+CgyWByAaHVV85PeVC13Q9ehun1/Wd3oFQ4GzRhsXCQ=; b=HWMwmAZjr8hHD4LlB3pPtYJ0ozDBoxRsArqrfWQWSqwATwGweLYAB2mfQoQFGYhJKR 9eZhchLtcHpPA350o0XKVv9kx5KUIePcsQmiIz3c7i7qUr9j3JAPS0TsQFrehmBL+/Gi rwL6EC5p0VFaBjB0ETsYT0X6+OMQVVAn3NfoI/2qmyzXFt13SLaLOg+3eW48Avov6Ub7 3NTe8DEmXyvDCXgHTW3c8sXDL9oVSqx/Up172Y/jF5wqmoONfHu9VWZ6Qg04+qkIu4GJ MU5Je9xexkXc8Ha/QkVFbyEQ4ArDY8upts9qpFoq1WxrLQH5lx87LcCksjQ1LdYX1hk5 aP+Q== X-Forwarded-Encrypted: i=1; AJvYcCWIjOsivd55Qtx5G/x5QY3pnZe76uPXBa4/tJuDTFCJcqwwSDe8GraWE2dmSbzzbM4lgUva3OVgPkhN/yY=@vger.kernel.org X-Gm-Message-State: AOJu0YyVNAo0FwLeSrgjMHeDaSr6aYi2nJ4bwtx0D/YJssFBsw5kbgnZ +E6EcVCLLMBQyoCz+lWVOIOCMD6J3IenbCUY3EwxtCrky2fUyC5XKVhZTL5D56cfgwV+lTjD+SW c7MNILg== X-Google-Smtp-Source: AGHT+IGo71TMXPlGjlEtx+9KCFpk1shtfB/J83ECXF+TfIzjn3vXYzFl65S88oW17CFw5334ijpYDq8c4lw= X-Received: from pjp3.prod.google.com ([2002:a17:90b:55c3:b0:312:a03:ef54]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4f4b:b0:311:c939:c851 with SMTP id 98e67ed59e1d1-312413f92e6mr2030455a91.4.1748562056573; Thu, 29 May 2025 16:40:56 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 29 May 2025 16:40:08 -0700 In-Reply-To: <20250529234013.3826933-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: <20250529234013.3826933-1-seanjc@google.com> X-Mailer: git-send-email 2.49.0.1204.g71687c7c1d-goog Message-ID: <20250529234013.3826933-24-seanjc@google.com> Subject: [PATCH 23/28] KVM: SVM: Move svm_msrpm_offset() to nested.c From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , Xin Li , Chao Gao , Dapeng Mi Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move svm_msrpm_offset() from svm.c to nested.c now that all usage of the u32-index offsets is nested virtualization specific. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/nested.c | 27 +++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 27 --------------------------- arch/x86/kvm/svm/svm.h | 1 - 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 0026d2adb809..5d6525627681 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -187,6 +187,33 @@ void recalc_intercepts(struct vcpu_svm *svm) static int nested_svm_msrpm_merge_offsets[6] __ro_after_init; static int nested_svm_nr_msrpm_merge_offsets __ro_after_init; =20 +static const u32 msrpm_ranges[] =3D { + SVM_MSRPM_RANGE_0_BASE_MSR, + SVM_MSRPM_RANGE_1_BASE_MSR, + SVM_MSRPM_RANGE_2_BASE_MSR +}; + +static u32 svm_msrpm_offset(u32 msr) +{ + u32 offset; + int i; + + for (i =3D 0; i < ARRAY_SIZE(msrpm_ranges); i++) { + if (msr < msrpm_ranges[i] || + msr >=3D msrpm_ranges[i] + SVM_MSRS_PER_RANGE) + continue; + + offset =3D (msr - msrpm_ranges[i]) / SVM_MSRS_PER_BYTE; + offset +=3D (i * SVM_MSRPM_BYTES_PER_RANGE); /* add range offset */ + + /* Now we have the u8 offset - but need the u32 offset */ + return offset / 4; + } + + /* MSR not in any range */ + return MSR_INVALID; +} + int __init nested_svm_init_msrpm_merge_offsets(void) { const u32 merge_msrs[] =3D { diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 9d01776d82d4..fa2df1c869db 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -195,33 +195,6 @@ static DEFINE_MUTEX(vmcb_dump_mutex); */ static int tsc_aux_uret_slot __read_mostly =3D -1; =20 -static const u32 msrpm_ranges[] =3D { - SVM_MSRPM_RANGE_0_BASE_MSR, - SVM_MSRPM_RANGE_1_BASE_MSR, - SVM_MSRPM_RANGE_2_BASE_MSR -}; - -u32 svm_msrpm_offset(u32 msr) -{ - u32 offset; - int i; - - for (i =3D 0; i < ARRAY_SIZE(msrpm_ranges); i++) { - if (msr < msrpm_ranges[i] || - msr >=3D msrpm_ranges[i] + SVM_MSRS_PER_RANGE) - continue; - - offset =3D (msr - msrpm_ranges[i]) / SVM_MSRS_PER_BYTE; - offset +=3D (i * SVM_MSRPM_BYTES_PER_RANGE); /* add range offset */ - - /* Now we have the u8 offset - but need the u32 offset */ - return offset / 4; - } - - /* MSR not in any range */ - return MSR_INVALID; -} - static int get_npt_level(void) { #ifdef CONFIG_X86_64 diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 23e1e3ae30b0..d146c35b9bd2 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -673,7 +673,6 @@ BUILD_SVM_MSR_BITMAP_HELPERS(void, set, __set) /* svm.c */ extern bool dump_invalid_vmcb; =20 -u32 svm_msrpm_offset(u32 msr); u32 *svm_vcpu_alloc_msrpm(void); void svm_vcpu_free_msrpm(u32 *msrpm); void svm_copy_lbrs(struct vmcb *to_vmcb, struct vmcb *from_vmcb); --=20 2.49.0.1204.g71687c7c1d-goog