xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Feng Wu <feng.wu@intel.com>
Cc: george.dunlap@eu.citrix.com, andrew.cooper3@citrix.com,
	dario.faggioli@citrix.com, kevin.tian@intel.com,
	xen-devel@lists.xen.org
Subject: Re: [PATCH v4 4/6] VMX: Make sure PI is in proper state before install the hooks
Date: Mon, 26 Sep 2016 06:45:58 -0600	[thread overview]
Message-ID: <57E934A60200007800112701@prv-mh.provo.novell.com> (raw)
In-Reply-To: <1474425470-3629-5-git-send-email-feng.wu@intel.com>

>>> On 21.09.16 at 04:37, <feng.wu@intel.com> wrote:
> We may hit the ASSERT() in vmx_vcpu_block in the current code,

There are three of them - please be explicit which one is what gets
dealt with here.

> --- a/xen/arch/x86/hvm/vmx/vmcs.c
> +++ b/xen/arch/x86/hvm/vmx/vmcs.c
> @@ -956,16 +956,13 @@ void virtual_vmcs_vmwrite(const struct vcpu *v, u32 vmcs_encoding, u64 val)
>   */
>  static void pi_desc_init(struct vcpu *v)
>  {
> -    uint32_t dest;
> -
>      v->arch.hvm_vmx.pi_desc.nv = posted_intr_vector;
>  
> -    dest = cpu_physical_id(v->processor);
> -
> -    if ( x2apic_enabled )
> -        v->arch.hvm_vmx.pi_desc.ndst = dest;
> -    else
> -        v->arch.hvm_vmx.pi_desc.ndst = MASK_INSR(dest, PI_xAPIC_NDST_MASK);
> +    /*
> +     * Mark NDST as invalid, then we can use this invalid value as a
> +     * marker to whether update NDST or not in vmx_pi_hooks_assign().
> +     */
> +    v->arch.hvm_vmx.pi_desc.ndst = 0xff;

Is this a proper "invalid" indicator in the x2APIC case? I would have
assumed you want 0xffffffff in that case.

> --- a/xen/arch/x86/hvm/vmx/vmx.c
> +++ b/xen/arch/x86/hvm/vmx/vmx.c
> @@ -211,14 +211,39 @@ static void vmx_pi_list_cleanup(struct vcpu *v)
>  /* This function is called when pcidevs_lock is held */
>  void vmx_pi_hooks_assign(struct domain *d)
>  {
> +    struct vcpu *v;
> +
>      if ( !iommu_intpost || !has_hvm_container_domain(d) )
>          return;
>  
>      ASSERT(!d->arch.hvm_domain.vmx.vcpu_block);
>  
> -    d->arch.hvm_domain.vmx.vcpu_block = vmx_vcpu_block;
> +    /*
> +     * We carefully handle the timing here:
> +     * - Install the context switch first
> +     * - Then set the NDST field
> +     * - Install the block and resume hooks in the end
> +     *
> +     * This can make sure the PI (especially the NDST feild) is
> +     * in proper state when we call vmx_vcpu_block().
> +     */
>      d->arch.hvm_domain.vmx.pi_switch_from = vmx_pi_switch_from;
>      d->arch.hvm_domain.vmx.pi_switch_to = vmx_pi_switch_to;
> +
> +    for_each_vcpu ( d, v )
> +    {
> +        unsigned int dest = cpu_physical_id(v->processor);
> +        struct pi_desc *pi_desc = &v->arch.hvm_vmx.pi_desc;
> +
> +	/*
> +	 * We don't need to update NDST if 'arch.hvm_domain.vmx.pi_switch_to'
> +	 * already gets called
> +	 */

Stray tabs.

> +        (void)cmpxchg(&pi_desc->ndst, 0xff,
> +                x2apic_enabled ? dest : MASK_INSR(dest, PI_xAPIC_NDST_MASK));

Here even more than above I think you want to derive the xAPIC
value from the wider x2APIC one not just for the value to write, but
also for the value to compare against. If you did so in pi_desc_init()
as well as here, I don't see a strict need for introducing a suitable
#define. If you don't, however, you definitely want a pair of
#define-s to one can associate both places with one another.

But overall I think this is much better than the previous version, so
thanks for doing (and testing) this.

Jan


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

  reply	other threads:[~2016-09-26 12:45 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-21  2:37 [PATCH v4 0/6] VMX: Properly handle pi descriptor and per-cpu blocking list Feng Wu
2016-09-21  2:37 ` [PATCH v4 1/6] VMX: Statically assign two PI hooks Feng Wu
2016-09-26 11:37   ` Jan Beulich
2016-09-26 12:09     ` Jan Beulich
2016-09-28  6:48       ` Wu, Feng
2016-09-28  9:38         ` Jan Beulich
2016-10-09  8:30           ` Wu, Feng
2016-10-10  7:26             ` Jan Beulich
2016-09-21  2:37 ` [PATCH v4 2/6] VMX: Properly handle pi when all the assigned devices are removed Feng Wu
2016-09-26 11:46   ` Jan Beulich
2016-09-28  6:50     ` Wu, Feng
2016-09-28  9:52       ` Jan Beulich
2016-09-29  3:08         ` Wu, Feng
2016-09-21  2:37 ` [PATCH v4 3/6] VMX: Cleanup PI per-cpu blocking list when vcpu is destroyed Feng Wu
2016-09-21  2:37 ` [PATCH v4 4/6] VMX: Make sure PI is in proper state before install the hooks Feng Wu
2016-09-26 12:45   ` Jan Beulich [this message]
2016-09-28  6:50     ` Wu, Feng
2016-09-21  2:37 ` [PATCH v4 5/6] VT-d: No need to set irq affinity for posted format IRTE Feng Wu
2016-09-26 12:58   ` Jan Beulich
2016-09-28  6:51     ` Wu, Feng
2016-09-28  9:58       ` Jan Beulich
2016-10-09  5:35         ` Wu, Feng
2016-10-10  7:02           ` Jan Beulich
2016-10-10 22:55             ` Wu, Feng
2016-09-21  2:37 ` [PATCH v4 6/6] VMX: Fixup PI descritpor when cpu is offline Feng Wu
2016-09-26 13:03   ` Jan Beulich
2016-09-28  6:53     ` Wu, Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57E934A60200007800112701@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dario.faggioli@citrix.com \
    --cc=feng.wu@intel.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=kevin.tian@intel.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).