Re: KVM: x86: verify MTRR/PAT validity

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/16/2009 03:05 PM, Marcelo Tosatti wrote:
Do not allow invalid MTRR/PAT values in set_msr_mtrr.

Please review carefully.

Signed-off-by: Marcelo Tosatti<mtosatti@xxxxxxxxxx>


+static unsigned mtrr_types[] = {0, 1, 4, 5, 6};
+static unsigned pat_types[] = {0, 1, 4, 5, 6, 7};
+
+static bool valid_mt(unsigned type, int len, unsigned array[len])
+{
+	int i;
+
+	for (i = 0; i<  len; i++)
+		if (type == array[i])
+			return true;
+
+	return false;
+}
+
+#define valid_pat_type(a) valid_mt(a, ARRAY_SIZE(pat_types), pat_types)
+#define valid_mtrr_type(a) valid_mt(a, ARRAY_SIZE(mtrr_types), mtrr_types)
+

A little pointless since this is so performance-insensitive, but still:

valid_pat_type(t)
{
    return t < 8 && (1 << t) & 0xf3; /* 0, 1, 4, 5, 6, 7 */
}

valid_mtrr_type(t)
{
    return t < 8 && (1 << t) & 0x73; /* 0, 1, 4, 5, 6 */
}

--
error compiling committee.c: too many arguments to function

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux