mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: moehanabi <moehanabichan@gmail.com>
To: seanjc@google.com
Cc: bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	mingo@redhat.com, moehanabichan@gmail.com, pbonzini@redhat.com,
	tglx@linutronix.de, x86@kernel.org
Subject: Re: Re: [PATCH] KVM: x86: Check irqchip mode before create PIT
Date: Thu, 25 Jan 2024 01:02:43 +0800	[thread overview]
Message-ID: <20240124170243.93-1-moehanabichan@outlook.com> (raw)
In-Reply-To: <ZbE7kd9W8csPRjvU@google.com>

> On Thu, Jan 25, 2024, Brilliant Hanabi wrote:
> > As the kvm api(https://docs.kernel.org/virt/kvm/api.html) reads,
> > KVM_CREATE_PIT2 call is only valid after enabling in-kernel irqchip
> > support via KVM_CREATE_IRQCHIP.
> > 
> > Without this check, I can create PIT first and enable irqchip-split
> > then, which may cause the PIT invalid because of lacking of in-kernel
> > PIC to inject the interrupt.
> 
> Does this cause actual problems beyond the PIT not working for the guest?  E.g.
> does it put the host kernel at risk?  If the only problem is that the PIT doesn't
> work as expected, I'm tempted to tweak the docs to say that KVM's PIT emulation
> won't work without an in-kernel I/O APIC.  Rejecting the ioctl could theoertically
> break misconfigured setups that happen to work, e.g. because the guest never uses
> the PIT.

I don't think it will put the host kernel at risk. But that's exactly what
kvmtool does: it creates in-kernel PIT first and set KVM_CREATE_IRQCHIP then.
I found this problem because I was working on implementing a userspace PIC
and PIT in kvmtool. As I planned, I'm going to commit a related patch to 
kvmtool if this patch will be applied.

> > Signed-off-by: Brilliant Hanabi <moehanabichan@gmail.com>
> > ---
> >  arch/x86/kvm/x86.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 27e23714e960..3edc8478310f 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -7016,6 +7016,8 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
> >  		r = -EEXIST;
> >  		if (kvm->arch.vpit)
> >  			goto create_pit_unlock;
> > +		if (!pic_in_kernel(kvm))
> > +			goto create_pit_unlock;
> 
> -EEXIST is not an appropriate errno.

Which errno do you think is better?

> >  		r = -ENOMEM;
> >  		kvm->arch.vpit = kvm_create_pit(kvm, u.pit_config.flags);
> >  		if (kvm->arch.vpit)
> > -- 
> > 2.39.3
> > 

  reply	other threads:[~2024-01-24 17:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-24 16:02 Brilliant Hanabi
2024-01-24 16:32 ` Sean Christopherson
2024-01-24 17:02   ` moehanabi [this message]
2024-01-24 17:43     ` Sean Christopherson
2024-01-24 19:01       ` Brilliant Hanabi
2024-01-24 23:59         ` Sean Christopherson
2024-01-25  5:08           ` [PATCH v2] " Tengfei Yu
2024-01-26 18:12             ` Paolo Bonzini
2024-01-26 18:11           ` Re: Re: [PATCH] " Paolo Bonzini

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=20240124170243.93-1-moehanabichan@outlook.com \
    --to=moehanabichan@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®