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

Re: [PATCH] x86/msi: prevent MSI entry re-writes of the same data


  • To: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 5 Mar 2025 11:30:51 +0100
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 05 Mar 2025 10:31:08 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 28.02.2025 12:32, Roger Pau Monne wrote:
> @@ -191,8 +193,6 @@ void msi_compose_msg(unsigned vector, const cpumask_t 
> *cpu_mask, struct msi_msg
>  
>  static int write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
>  {
> -    entry->msg = *msg;
> -
>      if ( iommu_intremap != iommu_intremap_off )
>      {
>          int rc;
> @@ -203,6 +203,20 @@ static int write_msi_msg(struct msi_desc *entry, struct 
> msi_msg *msg)
>              return rc;
>      }
>  
> +    /*
> +     * Avoid updating the MSI entry if the address and data fields haven't
> +     * changed.  When using interrupt remapping changing the MSI affinity
> +     * shouldn't change the interrupt remapping table index, and hence the 
> MSI
> +     * address and data fields should remain the same.
> +     */
> +    if ( entry->msg.address == msg->address && entry->msg.data == msg->data )
> +    {
> +        entry->msg.dest32 = msg->dest32;
> +        return 0;
> +    }
> +
> +    entry->msg = *msg;

It is perhaps pure luck that iommu_update_ire_from_msi() doesn't use entry's
"msg" field, and hence that this re-arrangement is okay. It's unclear to me
whether going forward this might not bite us.

> @@ -1407,7 +1415,9 @@ int pci_restore_msi_state(struct pci_dev *pdev)
>          }
>          type = entry->msi_attrib.type;
>  
> -        msg = entry->msg;
> +        msg.dest32 = entry->msg.dest32;
> +        msi_compose_msg(desc->arch.vector, NULL, &msg);
> +        entry->msg = (typeof(entry->msg)){};
>          write_msi_msg(entry, &msg);

Hmm, this isn't exactly a "restore" then anymore. That said, re-constructing
the message may even be more correct. Then, however, the question is whether
passing NULL as msi_compose_msg()'s middle argument is really appropriate. A
little bit of commentary may be desirable here in any event, also as to need
to clear entry->msg.

There's (at least) one place where behavior changes with the change of what
we store in struct msi_desc's msg field (previously untranslated, now
translated): dump_msi() wants to use the untranslated form. I fear it can't
even re-construct some of the data it means to log (without reading from
the IRTE).

> --- a/xen/drivers/passthrough/vtd/iommu.c
> +++ b/xen/drivers/passthrough/vtd/iommu.c
> @@ -1182,7 +1182,7 @@ static void cf_check dma_msi_end(struct irq_desc *desc, 
> u8 vector)
>  static void cf_check dma_msi_set_affinity(
>      struct irq_desc *desc, const cpumask_t *mask)
>  {
> -    struct msi_msg msg;
> +    struct msi_msg msg = {};
>      unsigned int dest;
>      unsigned long flags;
>      struct vtd_iommu *iommu = desc->action->dev_id;

Why not a similar transformation as you do in set_msi_affinity(), eliminating
the local "dest"?

A change like the one here is likely needed in __hpet_setup_msi_irq(), to
prevent accidental "uninitialized struct field" warnings.
hpet_msi_set_affinity() might then also want to use msi_compose_msg(), albeit
that may also be regarded as an independent change.

Jan



 


Rackspace

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