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

Re: [XEN PATCH v2] x86/monitor: Add new monitor event to catch I/O instructions


  • To: Dmitry Isaykin <isaikin-dmitry@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 17 Mar 2023 11:13:31 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CTwySt9G0DcNtvaMF07swXXGspE6IBr0o096KhDaBVA=; b=kl4fL+aEThKPzCLGx2NutPuw9XgsM9okTqzS9oozttKcLzBWdzN8Io7YRZe/sHGwQOPjNujCn0RcfDV9TZCXZdOHkI2LLcGsus/Anp2i6PwBhjdqbCbS+zUmcgkEcaLLwMrU5Z6h7MOlt1V22twFFfXzvouWbe63nr/sUnPjzcEUj+IUpRr/v3toXBaOYO7elCsM5RtHGr8C6IKP3wBj5FzdFmtWjpHdR0xVd7LmtJuY6P2XSgGgAj9VcHXye/0USrv+hL8n5TUS5iYeVZ10Mj0hEDFeoS6Gn5koZF1wSqojZu7nFXziCCCA3hNoqY/aq7F3widEbBtBnalMn2aj1g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CEcVpCflD6qFE5vIEPBnkDCeMXffll1zk4ZnoBQxbPglyRfddoRiyFpYrGiMfrqywpNdDgXrGhHGLkRUakW6v4R7wgyH7zgtxTLJw2gMzpdGnAEREAELOdW7wL96ZIRUy3vJDv4N5jF1J5tkG4jyX5LdP+vLwn1tjwc2oP3eRr+kyJFpZRchwBT+SfG2XdtgoJPtnAhCdGPBmTgNkVrzKA7OGrg/zLSKqkHRMBunRcnAqgKz8k5YjmtZSyimZSHd8z8qr/UQQkzBXgzi3v4IBV2tS8B2d9X2hm/cufRIZOjmRjoO35vCUlcMJ0gfXhneLjsC5Q6pvYZytr89IU6bbA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Wei Liu <wl@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Tamas K Lengyel <tamas@xxxxxxxxxxxxx>, Alexandru Isaila <aisaila@xxxxxxxxxxxxxxx>, Petre Pircalabu <ppircalabu@xxxxxxxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Jun Nakajima <jun.nakajima@xxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>, Anton Belousov <abelousov@xxxxxxxxxxxxxx>
  • Delivery-date: Fri, 17 Mar 2023 11:14:11 +0000
  • Ironport-data: A9a23:oK594KDkUkFpAhVW/yHjw5YqxClBgxIJ4kV8jS/XYbTApDlwhjZWz TAbWmqGPfvcMGWjKot3Oomy90ICucLXnd5mQQY4rX1jcSlH+JHPbTi7wuUcHAvJd5GeExg3h yk6QoOdRCzhZiaE/n9BCpC48T8nk/nOHuGmYAL9EngZbRd+Tys8gg5Ulec8g4p56fC0GArIs t7pyyHlEAbNNwVcbyRFu8pvlDs15K6p4GhB4QRnDRx2lAS2e0c9Xcp3yZ6ZdxMUcqEMdsamS uDKyq2O/2+x13/B3fv8z94X2mVTKlLjFVDmZkh+AsBOsTAbzsAG6Y4pNeJ0VKtio27hc+ada jl6ncfYpQ8BZsUgkQmGOvVSO3kW0aZuoNcrLZUj2CA6IoK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<xen-devel.lists.xenproject.org>

On 15/03/2023 6:54 pm, Dmitry Isaykin wrote:
> diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
> index a43bcf2e92..49225f48a7 100644
> --- a/xen/arch/x86/hvm/svm/svm.c
> +++ b/xen/arch/x86/hvm/svm/svm.c
> @@ -2939,17 +2939,26 @@ void svm_vmexit_handler(void)
>          break;
>  
>      case VMEXIT_IOIO:
> -        if ( (vmcb->exitinfo1 & (1u<<2)) == 0 )
> +     {
> +        uint16_t port = (vmcb->exitinfo1 >> 16) & 0xFFFF;
> +        int bytes = ((vmcb->exitinfo1 >> 4) & 0x07);
> +        int dir = (vmcb->exitinfo1 & 1) ? IOREQ_READ : IOREQ_WRITE;
> +        bool string_ins = (vmcb->exitinfo1 & (1u<<2));
> +        int rc = hvm_monitor_io(port, bytes, dir, string_ins);
> +        if ( rc < 0 )
> +            goto unexpected_exit_type;
> +        if ( !rc )
>          {
> -            uint16_t port = (vmcb->exitinfo1 >> 16) & 0xFFFF;
> -            int bytes = ((vmcb->exitinfo1 >> 4) & 0x07);
> -            int dir = (vmcb->exitinfo1 & 1) ? IOREQ_READ : IOREQ_WRITE;
> -            if ( handle_pio(port, bytes, dir) )
> -                __update_guest_eip(regs, vmcb->exitinfo2 - vmcb->rip);
> +            if ( !string_ins )
> +            {
> +                if ( handle_pio(port, bytes, dir) )
> +                    __update_guest_eip(regs, vmcb->exitinfo2 - vmcb->rip);
> +            }
> +            else if ( !hvm_emulate_one_insn(x86_insn_is_portio, "port I/O") )
> +                hvm_inject_hw_exception(TRAP_gp_fault, 0);
>          }
> -        else if ( !hvm_emulate_one_insn(x86_insn_is_portio, "port I/O") )
> -            hvm_inject_hw_exception(TRAP_gp_fault, 0);
>          break;
> +    }

There are a few style issues, but it's also a mess because of the manual
exitinfo decoding, so I went ahead and did

https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=df9369154aa010b2322e3f3e0727a242784cfd4f

to clean it up.  The rebased version of this hunk is now:

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index bfe03316def6..17ac99f6cd56 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -2939,6 +2939,15 @@ void svm_vmexit_handler(void)
         break;
 
     case VMEXIT_IOIO:
+        rc = hvm_monitor_io(vmcb->ei.io.port,
+                            vmcb->ei.io.bytes,
+                            vmcb->ei.io.in ? IOREQ_READ : IOREQ_WRITE,
+                            vmcb->ei.io.str);
+        if ( rc < 0 )
+            goto unexpected_exit_type;
+        if ( rc )
+            break;
+
         if ( !vmcb->ei.io.str )
         {
             if ( handle_pio(vmcb->ei.io.port,

which I hope you'll agree is much more simple to follow.

I'm also trying to sort out a similar cleanup on the Intel side, but
haven't managed to post that yet.

~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.