All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brendan Jackman <jackmanb@google.com>
To: kvm@vger.kernel.org, Will Deacon <will@kernel.org>,
	 Julien Thierry <julien.thierry.kdev@gmail.com>
Cc: Brendan Jackman <jackmanb@google.com>
Subject: [PATCH kvmtool] x86: Fix PIT2 init
Date: Mon, 15 Apr 2024 15:42:44 +0000	[thread overview]
Message-ID: <20240415154244.2840081-1-jackmanb@google.com> (raw)

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


             reply	other threads:[~2024-04-15 15:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-15 15:42 Brendan Jackman [this message]
2024-04-19 13:39 ` [PATCH kvmtool] x86: Fix PIT2 init Will Deacon
2024-04-19 14:23   ` Brendan Jackman

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=20240415154244.2840081-1-jackmanb@google.com \
    --to=jackmanb@google.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=will@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.