[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <79f3ab2e-ffff-0733-00bb-bab79a51b1e7@gmail.com>
Date: Sat, 3 Jun 2023 08:54:58 +0800
From: Robert Hoo <robert.hoo.linux@...il.com>
To: Sean Christopherson <seanjc@...gle.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, Li RongQing <lirongqing@...du.com>,
Yong He <zhuangel570@...il.com>,
Kai Huang <kai.huang@...el.com>
Subject: Re: [PATCH] KVM: x86/mmu: Add "never" option to allow sticky
disabling of nx_huge_pages
On 6/2/2023 11:09 PM, Sean Christopherson wrote:
> On Fri, Jun 02, 2023, Robert Hoo wrote:
>> On 6/2/2023 8:58 AM, Sean Christopherson wrote:
>>> @@ -6860,15 +6871,29 @@ static int set_nx_huge_pages(const char *val, const struct kernel_param *kp)
>>> bool old_val = nx_huge_pages;
>>> bool new_val;
>>> + if (nx_hugepage_mitigation_hard_disabled)
>>> + return -EPERM;
>>> +
>>> /* In "auto" mode deploy workaround only if CPU has the bug. */
>>> - if (sysfs_streq(val, "off"))
>>> + if (sysfs_streq(val, "off")) {
>>> new_val = 0;
>>> - else if (sysfs_streq(val, "force"))
>>> + } else if (sysfs_streq(val, "force")) {
>>> new_val = 1;
>>> - else if (sysfs_streq(val, "auto"))
>>> + } else if (sysfs_streq(val, "auto")) {
>>> new_val = get_nx_auto_mode();
>>> - else if (kstrtobool(val, &new_val) < 0)
>>> + } else if (sysfs_streq(val, "never")) {
>>> + new_val = 0;
>>> +
>>> + mutex_lock(&kvm_lock);
>>> + if (!list_empty(&vm_list)) {
>>> + mutex_unlock(&kvm_lock);
>>> + return -EBUSY;
Ah, right, thanks for explanation.
Reviewed-by: Robert Hoo <robert.hoo.linux@...il.com>
>>> + }
>>> + nx_hugepage_mitigation_hard_disabled = true;
>>> + mutex_unlock(&kvm_lock);
>>> + } else if (kstrtobool(val, &new_val) < 0) {
>>> return -EINVAL;
>>> + }
>>>
>>
>> IIUC, (Initially) "auto_off"/"off" --> create some VM --> turn to "never",
>> the created VMs still have those kthreads, but can never be used, until
>> destroyed with VM.
>
> Shouldn't be able to happen. The above rejects "never" if vm_list isn't empty,
> i.e. if there are any VMs, and sets nx_hugepage_mitigation_hard_disabled under
> kvm_lock to ensure it can't race with KVM_CREATE_VM. I forgot to call this out
> in the changelog though
Powered by blists - more mailing lists