From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH] nested VMX: fix I/O port exit emulation Date: Tue, 3 Dec 2013 13:55:28 +0000 Message-ID: <529DE2D0.8090305@citrix.com> References: <529DEE4E0200007800109691@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0556900717105741106==" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VnqRp-0003nK-Gw for xen-devel@lists.xenproject.org; Tue, 03 Dec 2013 13:55:33 +0000 In-Reply-To: <529DEE4E0200007800109691@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: xen-devel , Matthew Daley , Eddie Dong , Jun Nakajima List-Id: xen-devel@lists.xenproject.org --===============0556900717105741106== Content-Type: multipart/alternative; boundary="------------050908000107020008080005" --------------050908000107020008080005 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit On 03/12/13 13:44, Jan Beulich wrote: > For multi-byte operations all affected ports' bits in the bitmap need > to be checked, not just the first port's one. > > Reported-by: Matthew Daley > Signed-off-by: Jan Beulich > > --- a/xen/arch/x86/hvm/vmx/vvmx.c > +++ b/xen/arch/x86/hvm/vmx/vvmx.c > @@ -2134,7 +2134,6 @@ int nvmx_n2_vmexit_handler(struct cpu_us > struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v); > struct nestedvmx *nvmx = &vcpu_2_nvmx(v); > u32 ctrl; > - u8 *bitmap; > > nvcpu->nv_vmexit_pending = 0; > nvmx->intr.intr_info = 0; > @@ -2220,15 +2219,22 @@ int nvmx_n2_vmexit_handler(struct cpu_us > if ( ctrl & CPU_BASED_ACTIVATE_IO_BITMAP ) > { > unsigned long qual; > - u16 port; > + u16 port, size; > > __vmread(EXIT_QUALIFICATION, &qual); > - port = qual >> 16; > - bitmap = nvmx->iobitmap[port >> 15]; > - if ( bitmap[(port & 0x7fff) >> 3] & (1 << (port & 0x7)) ) > - nvcpu->nv_vmexit_pending = 1; > + for ( port = qual >> 16, size = (qual & 7) + 1; ; ) > + { > + const u8 *bitmap = nvmx->iobitmap[port >> 15]; > + > + if ( bitmap[(port & 0x7fff) >> 3] & (1 << (port & 7)) ) > + nvcpu->nv_vmexit_pending = 1; > + if ( !--size ) > + break; > + if ( !++port ) > + nvcpu->nv_vmexit_pending = 1; > + } while ( !nvcpu->nv_vmexit_pending ); You have a rather odd looking "for () { } while ()" loop, which appears to be a while loop with no body and a constant loop condition. Is this intended? ~Andrew > if ( !nvcpu->nv_vmexit_pending ) > - gdprintk(XENLOG_WARNING, "L0 PIO %x.\n", port); > + printk(XENLOG_G_WARNING "L0 PIO %04x\n", port); > } > else if ( ctrl & CPU_BASED_UNCOND_IO_EXITING ) > nvcpu->nv_vmexit_pending = 1; > > > > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-devel --------------050908000107020008080005 Content-Type: text/html; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit
On 03/12/13 13:44, Jan Beulich wrote:
For multi-byte operations all affected ports' bits in the bitmap need
to be checked, not just the first port's one.

Reported-by: Matthew Daley <mattd@bugfuzz.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/hvm/vmx/vvmx.c
+++ b/xen/arch/x86/hvm/vmx/vvmx.c
@@ -2134,7 +2134,6 @@ int nvmx_n2_vmexit_handler(struct cpu_us
     struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
     struct nestedvmx *nvmx = &vcpu_2_nvmx(v);
     u32 ctrl;
-    u8 *bitmap;
 
     nvcpu->nv_vmexit_pending = 0;
     nvmx->intr.intr_info = 0;
@@ -2220,15 +2219,22 @@ int nvmx_n2_vmexit_handler(struct cpu_us
         if ( ctrl & CPU_BASED_ACTIVATE_IO_BITMAP )
         {
             unsigned long qual;
-            u16 port;
+            u16 port, size;
 
             __vmread(EXIT_QUALIFICATION, &qual);
-            port = qual >> 16;
-            bitmap = nvmx->iobitmap[port >> 15];
-            if ( bitmap[(port & 0x7fff) >> 3] & (1 << (port & 0x7)) )
-                nvcpu->nv_vmexit_pending = 1;
+            for ( port = qual >> 16, size = (qual & 7) + 1; ; )
+            {
+                const u8 *bitmap = nvmx->iobitmap[port >> 15];
+
+                if ( bitmap[(port & 0x7fff) >> 3] & (1 << (port & 7)) )
+                    nvcpu->nv_vmexit_pending = 1;
+                if ( !--size )
+                    break;
+                if ( !++port )
+                    nvcpu->nv_vmexit_pending = 1;
+            } while ( !nvcpu->nv_vmexit_pending );

You have a rather odd looking "for () { } while ()" loop, which appears to be a while loop with no body and a constant loop condition.  Is this intended?

~Andrew

             if ( !nvcpu->nv_vmexit_pending )
-               gdprintk(XENLOG_WARNING, "L0 PIO %x.\n", port);
+                printk(XENLOG_G_WARNING "L0 PIO %04x\n", port);
         }
         else if ( ctrl & CPU_BASED_UNCOND_IO_EXITING )
             nvcpu->nv_vmexit_pending = 1;





_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

--------------050908000107020008080005-- --===============0556900717105741106== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --===============0556900717105741106==--