diff mbox series

[kvmtool] x86: Fix PIT2 init

Message ID 20240415154244.2840081-1-jackmanb@google.com (mailing list archive)
State New, archived
Headers show
Series [kvmtool] x86: Fix PIT2 init | expand

Commit Message

Brendan Jackman April 15, 2024, 3:42 p.m. UTC
KVM docs[1] for KVM_CREATE_PIT2 say:

	This call is only valid after enabling in-kernel irqchip support
	via KVM_CREATE_IRQCHIP.

This was not enforced technically, until kernel commit 9e05d9b06757
("KVM: x86: Check irqchip mode before create PIT"). Now I get -ENOENT.

To fix it I've just reordered the ioctls. Doing this fixes the -ENOENT
when running a nested VM on VMX.

[1] https://www.kernel.org/doc/Documentation/virtual/kvm/api.txt

Signed-off-by: Brendan Jackman <jackmanb@google.com>
To: Will Deacon <will@kernel.org>
To: Julien Thierry <julien.thierry.kdev@gmail.com>
To: kvm@vger.kernel.org
---
 x86/kvm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Will Deacon April 19, 2024, 1:39 p.m. UTC | #1
Hi Brendan,

On Mon, Apr 15, 2024 at 03:42:44PM +0000, Brendan Jackman wrote:
> KVM docs[1] for KVM_CREATE_PIT2 say:
> 
> 	This call is only valid after enabling in-kernel irqchip support
> 	via KVM_CREATE_IRQCHIP.
> 
> This was not enforced technically, until kernel commit 9e05d9b06757
> ("KVM: x86: Check irqchip mode before create PIT"). Now I get -ENOENT.
> 
> To fix it I've just reordered the ioctls. Doing this fixes the -ENOENT
> when running a nested VM on VMX.
> 
> [1] https://www.kernel.org/doc/Documentation/virtual/kvm/api.txt
> 
> Signed-off-by: Brendan Jackman <jackmanb@google.com>
> To: Will Deacon <will@kernel.org>
> To: Julien Thierry <julien.thierry.kdev@gmail.com>
> To: kvm@vger.kernel.org
> ---
>  x86/kvm.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Thanks for the patch, but I think we already fixed this in e73a6b29f1eb
("x86: Enable in-kernel irqchip before creating PIT"). Please can you
check the latest kvmtool works for you?

Cheers,

Will
Brendan Jackman April 19, 2024, 2:23 p.m. UTC | #2
On Fri, 19 Apr 2024 at 15:40, Will Deacon <will@kernel.org> wrote:
> Thanks for the patch, but I think we already fixed this in e73a6b29f1eb
> ("x86: Enable in-kernel irqchip before creating PIT"). Please can you
> check the latest kvmtool works for you?

Oh right, I had pulled from a bogus remote so my repo was stale.
Second time I've made this mistake this year...

Anyway yep, this looks good to me. Sorry for the noise!

Brendan
diff mbox series

Patch

diff --git a/x86/kvm.c b/x86/kvm.c
index 328fa75..09127c2 100644
--- a/x86/kvm.c
+++ b/x86/kvm.c
@@ -150,6 +150,10 @@  void kvm__arch_init(struct kvm *kvm)
 	if (ret < 0)
 		die_perror("KVM_SET_TSS_ADDR ioctl");
 
+	ret = ioctl(kvm->vm_fd, KVM_CREATE_IRQCHIP);
+	if (ret < 0)
+		die_perror("KVM_CREATE_IRQCHIP ioctl");
+
 	ret = ioctl(kvm->vm_fd, KVM_CREATE_PIT2, &pit_config);
 	if (ret < 0)
 		die_perror("KVM_CREATE_PIT2 ioctl");
@@ -171,10 +175,6 @@  void kvm__arch_init(struct kvm *kvm)
 		die("out of memory");
 
 	madvise(kvm->ram_start, kvm->ram_size, MADV_MERGEABLE);
-
-	ret = ioctl(kvm->vm_fd, KVM_CREATE_IRQCHIP);
-	if (ret < 0)
-		die_perror("KVM_CREATE_IRQCHIP ioctl");
 }
 
 void kvm__arch_delete_ram(struct kvm *kvm)