aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/kvm_main.c
diff options
context:
space:
mode:
authorMichael Riepe <michael@mr511.de>2006-12-22 04:05:36 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-22 11:55:46 -0500
commitbf591b24d07126143356058966d79423661f491f (patch)
tree1e075cd80f0bc6952d7b18411b05ee786900c3b9 /drivers/kvm/kvm_main.c
parent2c264957105b7c248a456ba6602df667ae986550 (diff)
[PATCH] KVM: Do not export unsupported msrs to userspace
Some msrs, such as MSR_STAR, are not available on all processors. Exporting them causes qemu to try to fetch them, which will fail. So, check all msrs for validity at module load time. Signed-off-by: Michael Riepe <michael@mr511.de> Signed-off-by: Avi Kivity <avi@qumranet.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r--drivers/kvm/kvm_main.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 4621b4ee6744..bc2e6c19f855 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1417,6 +1417,9 @@ static int kvm_dev_ioctl_set_sregs(struct kvm *kvm, struct kvm_sregs *sregs)
1417/* 1417/*
1418 * List of msr numbers which we expose to userspace through KVM_GET_MSRS 1418 * List of msr numbers which we expose to userspace through KVM_GET_MSRS
1419 * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. 1419 * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.
1420 *
1421 * This list is modified at module load time to reflect the
1422 * capabilities of the host cpu.
1420 */ 1423 */
1421static u32 msrs_to_save[] = { 1424static u32 msrs_to_save[] = {
1422 MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP, 1425 MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP,
@@ -1427,6 +1430,22 @@ static u32 msrs_to_save[] = {
1427 MSR_IA32_TIME_STAMP_COUNTER, 1430 MSR_IA32_TIME_STAMP_COUNTER,
1428}; 1431};
1429 1432
1433static unsigned num_msrs_to_save;
1434
1435static __init void kvm_init_msr_list(void)
1436{
1437 u32 dummy[2];
1438 unsigned i, j;
1439
1440 for (i = j = 0; i < ARRAY_SIZE(msrs_to_save); i++) {
1441 if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0)
1442 continue;
1443 if (j < i)
1444 msrs_to_save[j] = msrs_to_save[i];
1445 j++;
1446 }
1447 num_msrs_to_save = j;
1448}
1430 1449
1431/* 1450/*
1432 * Adapt set_msr() to msr_io()'s calling convention 1451 * Adapt set_msr() to msr_io()'s calling convention
@@ -1735,15 +1754,15 @@ static long kvm_dev_ioctl(struct file *filp,
1735 if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list)) 1754 if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list))
1736 goto out; 1755 goto out;
1737 n = msr_list.nmsrs; 1756 n = msr_list.nmsrs;
1738 msr_list.nmsrs = ARRAY_SIZE(msrs_to_save); 1757 msr_list.nmsrs = num_msrs_to_save;
1739 if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list)) 1758 if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list))
1740 goto out; 1759 goto out;
1741 r = -E2BIG; 1760 r = -E2BIG;
1742 if (n < ARRAY_SIZE(msrs_to_save)) 1761 if (n < num_msrs_to_save)
1743 goto out; 1762 goto out;
1744 r = -EFAULT; 1763 r = -EFAULT;
1745 if (copy_to_user(user_msr_list->indices, &msrs_to_save, 1764 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
1746 sizeof msrs_to_save)) 1765 num_msrs_to_save * sizeof(u32)))
1747 goto out; 1766 goto out;
1748 r = 0; 1767 r = 0;
1749 } 1768 }
@@ -1894,6 +1913,8 @@ static __init int kvm_init(void)
1894 1913
1895 kvm_init_debug(); 1914 kvm_init_debug();
1896 1915
1916 kvm_init_msr_list();
1917
1897 if ((bad_page = alloc_page(GFP_KERNEL)) == NULL) { 1918 if ((bad_page = alloc_page(GFP_KERNEL)) == NULL) {
1898 r = -ENOMEM; 1919 r = -ENOMEM;
1899 goto out; 1920 goto out;