KVM Archive mirror
 help / color / mirror / Atom feed
* [PATCH kvmtool] x86: Fix PIT2 init
@ 2024-04-15 15:42 Brendan Jackman
  2024-04-19 13:39 ` Will Deacon
  0 siblings, 1 reply; 3+ messages in thread
From: Brendan Jackman @ 2024-04-15 15:42 UTC (permalink / raw
  To: kvm, Will Deacon, Julien Thierry; +Cc: Brendan Jackman

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(-)

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)
-- 
2.44.0.683.g7961c838ac-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH kvmtool] x86: Fix PIT2 init
  2024-04-15 15:42 [PATCH kvmtool] x86: Fix PIT2 init Brendan Jackman
@ 2024-04-19 13:39 ` Will Deacon
  2024-04-19 14:23   ` Brendan Jackman
  0 siblings, 1 reply; 3+ messages in thread
From: Will Deacon @ 2024-04-19 13:39 UTC (permalink / raw
  To: Brendan Jackman; +Cc: kvm, Julien Thierry

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH kvmtool] x86: Fix PIT2 init
  2024-04-19 13:39 ` Will Deacon
@ 2024-04-19 14:23   ` Brendan Jackman
  0 siblings, 0 replies; 3+ messages in thread
From: Brendan Jackman @ 2024-04-19 14:23 UTC (permalink / raw
  To: Will Deacon; +Cc: kvm, Julien Thierry

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-19 14:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-15 15:42 [PATCH kvmtool] x86: Fix PIT2 init Brendan Jackman
2024-04-19 13:39 ` Will Deacon
2024-04-19 14:23   ` Brendan Jackman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).