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

Re: [PATCH v3 2/2] x86/monitor: Add new monitor event to catch all vmexits


  • To: Tamas K Lengyel <tamas.lengyel@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 6 Apr 2022 17:14:34 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=Wy0BAGBUiBDqNGLlf+POg46fpf7VoNTa8vzHxtxKSDk=; b=nbKG2Nn9Aea166dR2Ohf1zTgkkDfGXaOw9NItW03xQ6zcV/pjM/tS3VLaQNsW1OcWFkQ2Nu4lIkf7lm2lkydCNjSvC8JtVprUIe9D+VuoMzeT3j2/QnXYZUz8uH9DBS3ROmNuNFYLGD5AjICai9lAUDXD45nYJAQlxCrATziiA/5XWUyq+84IUdpIl+81CrvEzNr7qsqnFoanxkhhK94pVnT156J93nCe8X0uVhHFgiygaKaIwEUU3SqdH0vBwg0odHmNgiAi5lN9giwU/7myEt7JFVXqaf2t8hwdvS4zk0Dz69cpeLTvDdGkJBLjyr1lcjfKzReUhgYYmcLwv29zA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lmGO6VR425V+v0xQPKLe1WodvsMeD4eBQSCc5M+9nFttesYupn6MxACA25UObhW/wTLIcqLGVOfCq+vlMKMdt4w/T5+5iR04MbnjGiWaLhNfZzCryieN++BbzOB4uPRlZbh1mgL/9eqHPuOlxxaEKsCajbih90Vy6cFjQf69h9grAWxORyGvY+y0N9J8Sibq0z/KT2GDFK4WfmM8//XORUbyb1y4oL9ycJYXHs+tC7zMPx+KKYBeuCW+pzDp9d6XfY34ihPkhLRHtadC1ohzqmY8k39NMaflDtAOdI/e/3tYpaLqLqjqYbY2Na/bc5VUnnzyNbz4hQyu9rPQ1cl73w==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Wei Liu <wl@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, 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>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 06 Apr 2022 15:14:57 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 06.04.2022 16:58, Tamas K Lengyel wrote:
> --- a/xen/arch/x86/hvm/monitor.c
> +++ b/xen/arch/x86/hvm/monitor.c
> @@ -328,6 +328,24 @@ bool hvm_monitor_check_p2m(unsigned long gla, gfn_t gfn, 
> uint32_t pfec,
>      return monitor_traps(curr, true, &req) >= 0;
>  }
>  
> +int hvm_monitor_vmexit(unsigned long exit_reason,
> +                       unsigned long exit_qualification)
> +{
> +    struct vcpu *curr = current;
> +    struct arch_domain *ad = &curr->domain->arch;
> +    vm_event_request_t req = {};
> +
> +    ASSERT(ad->monitor.vmexit_enabled);
> +
> +    req.reason = VM_EVENT_REASON_VMEXIT;
> +    req.u.vmexit.reason = exit_reason;
> +    req.u.vmexit.qualification = exit_qualification;
> +
> +    set_npt_base(curr, &req);
> +
> +    return monitor_traps(curr, !!ad->monitor.vmexit_sync, &req);

vmexit_sync is a single-bit bitfield; I don't see the need for using
!! here, even more so that the respective parameter of monitor_traps()
is "bool" anyway.

> --- a/xen/arch/x86/hvm/vmx/vmx.c
> +++ b/xen/arch/x86/hvm/vmx/vmx.c
> @@ -4008,6 +4008,18 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
>          }
>      }
>  
> +    if ( unlikely(currd->arch.monitor.vmexit_enabled) )
> +    {
> +        int rc;
> +        __vmread(EXIT_QUALIFICATION, &exit_qualification);
> +

Nit: Please swap blank and non-blank lines here.

> +        rc = hvm_monitor_vmexit(exit_reason, exit_qualification);
> +        if ( rc < 0 )
> +            goto exit_and_crash;
> +        else if ( rc )

Nit: No need for "else" here, just if() suffices after "goto".

> +            return;
> +    }
> +
>      /* XXX: This looks ugly, but we need a mechanism to ensure
>       * any pending vmresume has really happened
>       */

A few lines down from here failed VM entry is being handled? Wouldn't
you want to place your code after that? And wouldn't you want to avoid
invoking the monitor for e.g. EXIT_REASON_EXTERNAL_INTERRUPT,
EXIT_REASON_MCE_DURING_VMENTRY, and at least the NMI sub-case of
EXIT_REASON_EXCEPTION_NMI?

Jan




 


Rackspace

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