Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Xiaoyao Li" <xiaoyao.li@intel.com>,
	"Chenyi Qiang" <chenyi.qiang@intel.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Sean Christopherson" <sean.j.christopherson@intel.com>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>,
	"Jim Mattson" <jmattson@google.com>,
	"Joerg Roedel" <joro@8bytes.org>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] KVM: X86: Dynamically allocating MSR number lists(msrs_to_save[], emulated_msrs[], msr_based_features[])
Date: Tue, 5 Nov 2019 14:03:24 +0100	[thread overview]
Message-ID: <cd930947-2621-550c-8a41-e1a396650928@redhat.com> (raw)
In-Reply-To: <477da390-4bdb-c25d-24b1-5b57c3bf78bb@intel.com>

On 05/11/19 13:51, Xiaoyao Li wrote:
> On 11/5/2019 7:30 PM, Paolo Bonzini wrote:
>> On 05/11/19 10:20, Chenyi Qiang wrote:
>>> The three msr number lists(msrs_to_save[], emulated_msrs[] and
>>> msr_based_features[]) are global arrays of kvm.ko, which are
>>> initialized/adjusted (copy supported MSRs forward to override the
>>> unsupported MSRs) when installing kvm-{intel,amd}.ko, but it doesn't
>>> reset these three arrays to their initial value when uninstalling
>>> kvm-{intel,amd}.ko. Thus, at the next installation, kvm-{intel,amd}.ko
>>> will initialize the modified arrays with some MSRs lost and some MSRs
>>> duplicated.
>>>
>>> So allocate and initialize these three MSR number lists dynamically when
>>> installing kvm-{intel,amd}.ko and free them when uninstalling.
>>>
>>> Cc: stable@vger.kernel.org
>>> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
>>> Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com>
>>> ---
>>>   arch/x86/kvm/x86.c | 86 ++++++++++++++++++++++++++++++----------------
>>>   1 file changed, 57 insertions(+), 29 deletions(-)
>>>
>>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>>> index ff395f812719..08efcf6351cc 100644
>>> --- a/arch/x86/kvm/x86.c
>>> +++ b/arch/x86/kvm/x86.c
>>> @@ -1132,13 +1132,15 @@ EXPORT_SYMBOL_GPL(kvm_rdpmc);
>>>    * List of msr numbers which we expose to userspace through
>>> KVM_GET_MSRS
>>>    * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.
>>>    *
>>> - * This list is modified at module load time to reflect the
>>> + * The three msr number lists(msrs_to_save, emulated_msrs,
>>> msr_based_features)
>>> + * are allocated and initialized at module load time and freed at
>>> unload time.
>>> + * msrs_to_save is selected from the msrs_to_save_all to reflect the
>>>    * capabilities of the host cpu. This capabilities test skips MSRs
>>> that are
>>> - * kvm-specific. Those are put in emulated_msrs; filtering of
>>> emulated_msrs
>>> + * kvm-specific. Those are put in emulated_msrs_all; filtering of
>>> emulated_msrs
>>>    * may depend on host virtualization features rather than host cpu
>>> features.
>>>    */
>>>   -static u32 msrs_to_save[] = {
>>> +const u32 msrs_to_save_all[] = {
>>
>> This can remain static.
> 
> How about static const u32 msrs_to_save_all[] ?
> 
> Or you think static is enough?

"static const" is best indeed (that's what I meant, but I wasn't very
clear).

Paolo

>>>       MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP,
>>> MSR_IA32_SYSENTER_EIP,
>>>       MSR_STAR,
>>>   #ifdef CONFIG_X86_64
>>> @@ -1179,9 +1181,10 @@ static u32 msrs_to_save[] = {
>>>       MSR_ARCH_PERFMON_EVENTSEL0 + 16, MSR_ARCH_PERFMON_EVENTSEL0 + 17,
>>>   };
>>>   +static u32 *msrs_to_save;
>>
>> You can use ARRAY_SIZE to allocate the destination arrays statically.
> 
> It's much better, then we don't need to allocation and free.
> 
>> Paolo
>>


  reply	other threads:[~2019-11-05 13:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-05  9:20 [PATCH] KVM: X86: Dynamically allocating MSR number lists(msrs_to_save[], emulated_msrs[], msr_based_features[]) Chenyi Qiang
2019-11-05 10:41 ` Paolo Bonzini
2019-11-05 11:11   ` Xiaoyao Li
2019-11-05 11:20     ` Paolo Bonzini
2019-11-05 11:30 ` Paolo Bonzini
2019-11-05 12:51   ` Xiaoyao Li
2019-11-05 13:03     ` Paolo Bonzini [this message]
2019-11-06  1:01       ` cqiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cd930947-2621-550c-8a41-e1a396650928@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=chenyi.qiang@intel.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rkrcmar@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=vkuznets@redhat.com \
    --cc=xiaoyao.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox