diff mbox

KVM: x86: relax MSR_KVM_SYSTEM_TIME alignment check

Message ID 20130322191407.GA23681@amt.cnet (mailing list archive)
State New, archived
Headers show

Commit Message

Marcelo Tosatti March 22, 2013, 7:14 p.m. UTC
RHEL5 i386 guests register non 32-byte aligned addresses:

kvm-clock: cpu 1, msr 0:3018aa5, secondary cpu clock
kvm-clock: cpu 2, msr 0:301f8e9, secondary cpu clock
kvm-clock: cpu 3, msr 0:302672d, secondary cpu clock

Check for an address+len that would cross page boundary
instead.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

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

Comments

Gleb Natapov March 22, 2013, 7:21 p.m. UTC | #1
On Fri, Mar 22, 2013 at 04:14:07PM -0300, Marcelo Tosatti wrote:
> 
> RHEL5 i386 guests register non 32-byte aligned addresses:
> 
> kvm-clock: cpu 1, msr 0:3018aa5, secondary cpu clock
> kvm-clock: cpu 2, msr 0:301f8e9, secondary cpu clock
> kvm-clock: cpu 3, msr 0:302672d, secondary cpu clock
> 
> Check for an address+len that would cross page boundary
> instead.
> 
Ugh. Is there guaranty that it will not register a memory region that
crosses page boundary or it is pure luck that this does not happen?

> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index f19ac0a..ad36d386 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1952,8 +1952,9 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>  
>  		gpa_offset = data & ~(PAGE_MASK | 1);
>  
> -		/* Check that the address is 32-byte aligned. */
> -		if (gpa_offset & (sizeof(struct pvclock_vcpu_time_info) - 1))
> +		/* Check that address+len does not cross page boundary */
> +		if ((gpa_offset + sizeof(struct pvclock_vcpu_time_info) - 1)
> +		    & PAGE_MASK)
>  			break;
>  
>  		if (kvm_gfn_to_hva_cache_init(vcpu->kvm,

--
			Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marcelo Tosatti March 22, 2013, 7:47 p.m. UTC | #2
On Fri, Mar 22, 2013 at 09:21:00PM +0200, Gleb Natapov wrote:
> On Fri, Mar 22, 2013 at 04:14:07PM -0300, Marcelo Tosatti wrote:
> > 
> > RHEL5 i386 guests register non 32-byte aligned addresses:
> > 
> > kvm-clock: cpu 1, msr 0:3018aa5, secondary cpu clock
> > kvm-clock: cpu 2, msr 0:301f8e9, secondary cpu clock
> > kvm-clock: cpu 3, msr 0:302672d, secondary cpu clock
> > 
> > Check for an address+len that would cross page boundary
> > instead.
> > 
> Ugh. Is there guaranty that it will not register a memory region that
> crosses page boundary or it is pure luck that this does not happen?

Pure build time luck - there is no guarantee that percpu data will not
cross page boundary AFAIK.

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

Patch

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index f19ac0a..ad36d386 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1952,8 +1952,9 @@  int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 
 		gpa_offset = data & ~(PAGE_MASK | 1);
 
-		/* Check that the address is 32-byte aligned. */
-		if (gpa_offset & (sizeof(struct pvclock_vcpu_time_info) - 1))
+		/* Check that address+len does not cross page boundary */
+		if ((gpa_offset + sizeof(struct pvclock_vcpu_time_info) - 1)
+		    & PAGE_MASK)
 			break;
 
 		if (kvm_gfn_to_hva_cache_init(vcpu->kvm,