mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Huang, Kai" <kai.huang@intel.com>
To: "robert.hoo.linux@gmail.com" <robert.hoo.linux@gmail.com>,
	"Christopherson,, Sean" <seanjc@google.com>
Cc: "zhuangel570@gmail.com" <zhuangel570@gmail.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Li, Rongqing" <lirongqing@baidu.com>
Subject: Re: [PATCH] KVM: x86/mmu: Add "never" option to allow sticky disabling of nx_huge_pages
Date: Tue, 6 Jun 2023 09:47:50 +0000	[thread overview]
Message-ID: <18de02cd277646675ff4ee62f7af0f52c13534aa.camel@intel.com> (raw)
In-Reply-To: <ZHoGEwFqx3kJrmJe@google.com>

On Fri, 2023-06-02 at 08:09 -0700, 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;
> > > +		}
> > > +		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.

Also IIUC once set to "never" userspace will not be able to switch to other
modes, unless userspace reloads KVM.  Worth to call out this too?

Acked-by: Kai Huang <kai.huang@intel.com>


  parent reply	other threads:[~2023-06-06  9:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-02  0:58 Sean Christopherson
2023-06-02  6:06 ` Robert Hoo
2023-06-02 15:09   ` Sean Christopherson
2023-06-03  0:54     ` Robert Hoo
2023-06-06  9:47     ` Huang, Kai [this message]
2023-06-05  4:26 ` Li,Rongqing
2023-06-06 20:26 ` Luiz Capitulino
2023-06-06 22:03   ` Sean Christopherson
2023-06-07  2:08     ` Luiz Capitulino
2023-06-13 23:21 ` Sean Christopherson
2023-06-14 13:20   ` Luiz Capitulino
2023-06-14 19:07     ` Sean Christopherson
2023-07-11 16:12       ` Like Xu
2023-07-12 23:47         ` Sean Christopherson

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=18de02cd277646675ff4ee62f7af0f52c13534aa.camel@intel.com \
    --to=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=pbonzini@redhat.com \
    --cc=robert.hoo.linux@gmail.com \
    --cc=seanjc@google.com \
    --cc=zhuangel570@gmail.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

Powered by JetHome