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

Re: [PATCH v2 4/5] x86/iommu: pass full IO-APIC RTE for remapping table update


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Wed, 26 Jul 2023 12:08:15 +0200
  • 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=wC6chUNrgyfNv0/hreGukj96USzDpkoCgiDxE/KSRWc=; b=c7biTNsXACiFRnPRsw+LVehAURhn9JZUXrxP7BDD5H3NmJ44JZLMJQHGII/9wWupDUcLr2LyxmWoZpDZTqp1A0EvVIwqhDcKon/MzIXuoSPjlN5KEgZv9JQNqufV+ovyfuuKFp3JWoTZnf1wjedRvhXq6HVAwGIja+JzBZKa5w1qCDXR5UPB+XzsQY5pL0l53ufa7q9s+rxycfx6z3V9pRgDVfhs1SrW0+lopblbftqHZ/4zyXcU4L9O4NZ3hyF61PB4En3pEg2pmYItHxQ8kmoXRYJtjGQgNz7VCIM7dWRykfJBWvy60iRh74zFV/A22V/XKNCRdqj/MDZoZ0yxCg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D5PBKeqUQTQC/EhWfyuXqm780wNp3wClTTIlXlBVEMDTeS+XdG7IKwYO4cew5C0dhu9YLd3Zca99jHox7jTIiohjxNFAsdMy9hjDRDMsmrvvB0laWfYoEL5/Lh9ej65tAzwBWt37VPLfq2JFRYP20kLx3ithMmDesr54ykqW9tAo21loem6SVb2ANAHVHGne5ucaWf85OgkUsiPuAf5FAM6wGOYXewh+EEMucxGjgeEnt/gBN0WGmOan0RFYHT/kNA6rgaDK7v+s2aWq0SflrDVntqxftIYSkT8x25t7Cqqi1jaPLc5ZscjnQuG+34m0j3DPsG4t5oC882ivzXEahg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 26 Jul 2023 10:08:36 +0000
  • Ironport-data: A9a23:42Xp8q72SbZoe1CRdmeXZQxRtPvGchMFZxGqfqrLsTDasY5as4F+v jMbDGqBO/jYMDD2ftp2Odu/9koA7JfTydQwSQpp+S8wHi5G8cbLO4+Ufxz6V8+wwm8vb2o8t plDNYOQRCwQZiWBzvt4GuG59RGQ7YnRGvynTraCYnsrLeNdYH9JoQp5nOIkiZJfj9G8Agec0 fv/uMSaM1K+s9JOGjt8B5mr9lU35ZwehBtC5gZlPa8R4QeE/5UoJMl3yZ+ZfiOQrrZ8RoZWd 86bpJml82XQ+QsaC9/Nut4XpWVTH9Y+lSDX4pZnc/DKbipq/0Te4Y5iXBYoUm9Fii3hojxE4 I4lWapc6+seFvakdOw1C3G0GszlVEFM0OevzXOX6aR/w6BaGpdFLjoH4EweZOUlFuhL7W5m7 txBdRkRNEG/u/u1+L2GTe91ifgzBZy+VG8fkikIITDxK98DGcyGb4CUoNhS0XE3m9xEGuvYa 4wBcz1zYR/cYhpJfFAKFJY5m+TujX76G9FagAvN+exrvC6Ml0otiNABM/KMEjCObd9SkUuC4 HrP4kzyAw0ANczZwj2Amp6prraWwnilA9hNStVU8NZRsVqOnl4sKycGfmv88OuXjUike/Fmf hl8Fi0G6PJaGFaQZtv3UgC8oXWElgUBQNcWGOo/gCmSzoLE7gDfAXILJhZCZcInsokqRDUs/ l6Pg97tQzdotdW9UXuA8p+EoDX0PjIaRUcSaClBQQYb7t3LpIAokgmJXttlCLSyjND+BXf32 T/ikcQlr7AajMpO26Dl+1nC226ovsKRElZz4RjLVGW46A8/fJSie4Gj9Vnc67BHMZqdSV6C+ nMDnqBy8dwzMH1ErwTVKM1lIV1jz6/t3OH06bK3I6Qcyg==
  • Ironport-hdrordr: A9a23:Ty+vp6qiloiJ7A/KrzoChqoaV5oveYIsimQD101hICG9JPbo8/ xG/c566faasl0ssR0b8+xoW5PgfZq/z/FICNIqTNKftWDd0QOVxedZgLcKqAePJ8SRzIJgPQ gLSdkYNDVdZ2IK7voTQWODYrQd/OU=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Wed, Jul 19, 2023 at 12:37:47PM +0200, Jan Beulich wrote:
> On 18.07.2023 14:43, Roger Pau Monne wrote:
> > @@ -439,36 +427,47 @@ unsigned int cf_check io_apic_read_remap_rte(
> >  }
> >  
> >  void cf_check io_apic_write_remap_rte(
> > -    unsigned int apic, unsigned int reg, unsigned int value)
> > +    unsigned int apic, unsigned int pin, uint64_t raw)
> >  {
> > -    unsigned int pin = (reg - 0x10) / 2;
> > +    struct IO_xAPIC_route_entry rte = { .raw = raw };
> >      struct IO_xAPIC_route_entry old_rte = { };
> >      struct IO_APIC_route_remap_entry *remap_rte;
> > -    unsigned int rte_upper = (reg & 1) ? 1 : 0;
> >      struct vtd_iommu *iommu = ioapic_to_iommu(IO_APIC_ID(apic));
> > -    int saved_mask;
> > -
> > -    old_rte = __ioapic_read_entry(apic, pin, true);
> > +    bool masked = true;
> > +    int rc;
> >  
> >      remap_rte = (struct IO_APIC_route_remap_entry *) &old_rte;
> >  
> > -    /* mask the interrupt while we change the intremap table */
> > -    saved_mask = remap_rte->mask;
> > -    remap_rte->mask = 1;
> > -    __io_apic_write(apic, reg & ~1, *(u32 *)&old_rte);
> > -    remap_rte->mask = saved_mask;
> > -
> > -    if ( ioapic_rte_to_remap_entry(iommu, apic, pin,
> > -                                   &old_rte, rte_upper, value) )
> > +    if ( !cpu_has_cx16 )
> >      {
> > -        __io_apic_write(apic, reg, value);
> > +       /*
> > +        * Cannot atomically update the IRTE entry: mask the IO-APIC pin to
> > +        * avoid interrupts seeing an inconsistent IRTE entry.
> > +        */
> > +        old_rte = __ioapic_read_entry(apic, pin, true);
> > +        if ( !old_rte.mask )
> > +        {
> > +            masked = false;
> > +            old_rte.mask = 1;
> > +            __ioapic_write_entry(apic, pin, true, old_rte);
> > +        }
> > +    }
> >  
> > -        /* Recover the original value of 'mask' bit */
> > -        if ( rte_upper )
> > -            __io_apic_write(apic, reg & ~1, *(u32 *)&old_rte);
> > +    rc = ioapic_rte_to_remap_entry(iommu, apic, pin, &old_rte, rte);
> 
> I realize it has been like this before, but passing &old_rte here is
> odd. We already have its properly typed alias: remap_rte. All the
> called function does is do the same type cast again. Question is
> whether ...
> 
> > +    if ( rc )
> > +    {
> > +        if ( !masked )
> > +        {
> > +            /* Recover the original value of 'mask' bit */
> > +            old_rte.mask = 0;
> > +            __ioapic_write_entry(apic, pin, true, old_rte);
> > +        }
> > +        dprintk(XENLOG_ERR VTDPREFIX,
> > +                "failed to update IRTE for IO-APIC#%u pin %u: %d\n",
> > +                apic, pin, rc);
> > +        return;
> >      }
> > -    else
> > -        __ioapic_write_entry(apic, pin, true, old_rte);
> > +    __ioapic_write_entry(apic, pin, true, old_rte);
> 
> ... the further uses of old_rte then won't end up yet more confusing
> than they already are (first and foremost again because of "old" not
> being applicable here).

I've instead opted to remove remap_rte from io_apic_write_remap_rte(),
as it was unused.  I've also added a comment to clarify the usage of
old_rte when ioapic_rte_to_remap_entry() returns success.

Thanks, Roger.



 


Rackspace

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