From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@qumranet.com>, Chris Wright <chrisw@redhat.com>
Cc: kvm-devel <kvm@vger.kernel.org>, Len Brown <lenb@kernel.org>
Subject: [patch 4/4] KVM: allow direct access to PMTimer port
Date: Sat, 24 May 2008 20:43:46 -0300 [thread overview]
Message-ID: <20080525000036.710955693@localhost.localdomain> (raw)
In-Reply-To: 20080524234342.983197667@localhost.localdomain
[-- Attachment #1: kvm-open-pmtmr --]
[-- Type: text/plain, Size: 3581 bytes --]
There's not much point in exiting for pmtimer reads, since it runs at a
fixed clock rate and its start value is undefined.
The KVM-specific ioctl to read the counter from userspace is not nice
though. Ideas?
CC: Len Brown <lenb@kernel.org>
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index baf9607..f7e44d8 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -24,6 +24,7 @@
#include <linux/vmalloc.h>
#include <linux/highmem.h>
#include <linux/sched.h>
+#include <linux/acpi_pmtmr.h>
#include <asm/desc.h>
@@ -424,6 +425,10 @@ static __init int svm_hardware_setup(void)
iopm_va = page_address(iopm_pages);
memset(iopm_va, 0xff, PAGE_SIZE * (1 << IOPM_ALLOC_ORDER));
clear_bit(0x80, iopm_va); /* allow direct access to PC debug port */
+ if (pmtmr_ioport)
+ for (r = 0; r < 4; r++)
+ clear_bit(pmtmr_ioport+r, iopm_va);
+
iopm_base = page_to_pfn(iopm_pages) << PAGE_SHIFT;
if (boot_cpu_has(X86_FEATURE_NX))
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index aaa99ed..4f77fd7 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -26,6 +26,7 @@
#include <linux/highmem.h>
#include <linux/sched.h>
#include <linux/moduleparam.h>
+#include <linux/acpi_pmtmr.h>
#include <asm/io.h>
#include <asm/desc.h>
@@ -3261,6 +3262,10 @@ static int __init vmx_init(void)
va = kmap(vmx_io_bitmap_a);
memset(va, 0xff, PAGE_SIZE);
clear_bit(0x80, va);
+ if (pmtmr_ioport)
+ for (r = 0; r < 4; r++)
+ clear_bit(pmtmr_ioport+r, va);
+
kunmap(vmx_io_bitmap_a);
va = kmap(vmx_io_bitmap_b);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e537005..9769f52 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -27,6 +27,7 @@
#include <linux/module.h>
#include <linux/mman.h>
#include <linux/highmem.h>
+#include <linux/acpi_pmtmr.h>
#include <asm/uaccess.h>
#include <asm/msr.h>
@@ -790,6 +791,7 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_PIT:
case KVM_CAP_NOP_IO_DELAY:
case KVM_CAP_MP_STATE:
+ case KVM_CAP_GET_PMTIMER:
r = 1;
break;
case KVM_CAP_VAPIC:
@@ -1678,6 +1680,18 @@ long kvm_arch_vm_ioctl(struct file *filp,
r = 0;
break;
}
+ case KVM_GET_PMTIMER: {
+ struct kvm_pmtimer pmtmr;
+ r = -ENODEV;
+ if (!pmtmr_ioport)
+ goto out;
+ pmtmr.val = inl(pmtmr_ioport);
+ r = -EFAULT;
+ if (copy_to_user(argp, &pmtmr, sizeof pmtmr))
+ goto out;
+ r = 0;
+ break;
+ }
default:
;
}
diff --git a/drivers/clocksource/acpi_pm.c b/drivers/clocksource/acpi_pm.c
index 7b46faf..d3d4294 100644
--- a/drivers/clocksource/acpi_pm.c
+++ b/drivers/clocksource/acpi_pm.c
@@ -29,6 +29,7 @@
* in arch/i386/kernel/acpi/boot.c
*/
u32 pmtmr_ioport __read_mostly;
+EXPORT_SYMBOL(pmtmr_ioport);
static inline u32 read_pmtmr(void)
{
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index a281afe..3672890 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -247,6 +247,10 @@ struct kvm_mp_state {
__u32 mp_state;
};
+struct kvm_pmtimer {
+ __u32 val;
+};
+
struct kvm_s390_psw {
__u64 mask;
__u64 addr;
@@ -346,6 +350,7 @@ struct kvm_trace_rec {
#define KVM_CAP_NOP_IO_DELAY 12
#define KVM_CAP_PV_MMU 13
#define KVM_CAP_MP_STATE 14
+#define KVM_CAP_GET_PMTIMER 15
/*
* ioctls for VM fds
@@ -371,6 +376,7 @@ struct kvm_trace_rec {
#define KVM_CREATE_PIT _IO(KVMIO, 0x64)
#define KVM_GET_PIT _IOWR(KVMIO, 0x65, struct kvm_pit_state)
#define KVM_SET_PIT _IOR(KVMIO, 0x66, struct kvm_pit_state)
+#define KVM_GET_PMTIMER _IOR(KVMIO, 0x67, struct kvm_pmtimer)
/*
* ioctls for vcpu fds
--
next prev parent reply other threads:[~2008-05-25 0:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-24 23:43 [patch 0/4] C2 "emulation" Marcelo Tosatti
2008-05-24 23:43 ` [patch 1/4] QEMU/KVM: self-disabling C2 emulation Marcelo Tosatti
2008-05-24 23:43 ` [patch 2/4] libkvm: KVM_GET_PMTIMER ioctl support Marcelo Tosatti
2008-05-24 23:43 ` [patch 3/4] QEMU/KVM: non-virtualized ACPI PMTimer support Marcelo Tosatti
2008-05-25 10:18 ` Avi Kivity
2008-05-25 16:32 ` Marcelo Tosatti
2008-05-26 8:16 ` Avi Kivity
2008-05-29 17:56 ` Marcelo Tosatti
2008-05-31 7:52 ` Avi Kivity
2008-05-25 10:19 ` Avi Kivity
2008-05-25 17:39 ` Marcelo Tosatti
2008-05-26 8:23 ` Avi Kivity
2008-05-24 23:43 ` Marcelo Tosatti [this message]
2008-05-25 10:04 ` [patch 4/4] KVM: allow direct access to PMTimer port Avi Kivity
2008-05-25 16:09 ` Marcelo Tosatti
2008-05-25 12:31 ` Avi Kivity
2008-05-25 16:12 ` Marcelo Tosatti
2008-05-26 8:03 ` Avi Kivity
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=20080525000036.710955693@localhost.localdomain \
--to=mtosatti@redhat.com \
--cc=avi@qumranet.com \
--cc=chrisw@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=lenb@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