Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13898C7618F for ; Fri, 19 Jul 2019 18:45:04 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D7A0C21849 for ; Fri, 19 Jul 2019 18:45:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D7A0C21849 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hoXsA-00076y-1c; Fri, 19 Jul 2019 18:44:50 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hoXs8-00076q-P4 for xen-devel@lists.xenproject.org; Fri, 19 Jul 2019 18:44:48 +0000 X-Inumbo-ID: 4683fbae-aa55-11e9-99ae-fffbec0617c6 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 4683fbae-aa55-11e9-99ae-fffbec0617c6; Fri, 19 Jul 2019 18:44:44 +0000 (UTC) Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 0B7LBCpRQtza0vxuPvPWqH0xpRtfYngz6OeAcB6SVwG7FbQykPY2YpfrAPvUtH+oljmSCsZAJW bnhqODUH4wb7Dq9u/XZwY5dnDcMOBrqJa4jwWlZx5LyHMTPrRQ3ESepFyxzwceujtXWqJOUvQl XfFXjfkjpLVZ7RMK7dH0nNZMe47Sw4KD2Jt9XbyKrE1N0585eNa4TO1Xq4E/pr9eiN34p0b+oL CqKX3upDb3EAPgAsCxD0fogcrrqccogghkonbPkG4zb/3D39rIOZc9+SiRtq1dLmEUz2whTe/X iUY= X-SBRS: 2.7 X-MesageID: 3275266 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,283,1559534400"; d="scan'208,223";a="3275266" To: Jan Beulich References: <6272c301-a905-38cf-dd1a-645f3d703241@suse.com> <7eb213ad-94f1-6092-c670-3296aedf3f0e@suse.com> From: Andrew Cooper Openpgp: preference=signencrypt Autocrypt: addr=andrew.cooper3@citrix.com; prefer-encrypt=mutual; keydata= mQINBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTIb+OlMSJUWV4opS7WVNnxHbFTPYZVQ3erv7NKc2iVizCRZ2Kxn srM1oPXWRic8BIAdYOKOloF2300SL/bIpeD+x7h3w9B/qez7nOin5NzkxgFoaUeIal12pXSR Q354FKFoy6Vh96gc4VRqte3jw8mPuJQpfws+Pb+swvSf/i1q1+1I4jsRQQh2m6OTADHIqg2E ofTYAEh7R5HfPx0EXoEDMdRjOeKn8+vvkAwhviWXTHlG3R1QkbE5M/oywnZ83udJmi+lxjJ5 YhQ5IzomvJ16H0Bq+TLyVLO/VRksp1VR9HxCzItLNCS8PdpYYz5TC204ViycobYU65WMpzWe LFAGn8jSS25XIpqv0Y9k87dLbctKKA14Ifw2kq5OIVu2FuX+3i446JOa2vpCI9GcjCzi3oHV e00bzYiHMIl0FICrNJU0Kjho8pdo0m2uxkn6SYEpogAy9pnatUlO+erL4LqFUO7GXSdBRbw5 gNt25XTLdSFuZtMxkY3tq8MFss5QnjhehCVPEpE6y9ZjI4XB8ad1G4oBHVGK5LMsvg22PfMJ ISWFSHoF/B5+lHkCKWkFxZ0gZn33ju5n6/FOdEx4B8cMJt+cWwARAQABtClBbmRyZXcgQ29v cGVyIDxhbmRyZXcuY29vcGVyM0BjaXRyaXguY29tP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OD2sY3GYq2nf3Bbzx81wZK14JdDDHUX2Rs 6+ahAA== Message-ID: <1fc9a3f1-07a6-6897-6203-86014a77d265@citrix.com> Date: Fri, 19 Jul 2019 19:44:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------C215AC821AFDA668C4A4AC50" Content-Language: en-GB X-ClientProxiedBy: AMSPEX02CAS02.citrite.net (10.69.22.113) To AMSPEX02CL02.citrite.net (10.69.22.126) Subject: Re: [Xen-devel] [PATCH v3 04/14] AMD/IOMMU: use bit field for IRTE X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: "xen-devel@lists.xenproject.org" , Brian Woods , Suravee Suthikulpanit Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" --------------C215AC821AFDA668C4A4AC50 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On 19/07/2019 17:16, Jan Beulich wrote: > On 19.07.2019 17:56, Andrew Cooper wrote: >> On 16/07/2019 17:36, Jan Beulich wrote: >>> At the same time restrict its scope to just the single source file >>> actually using it, and abstract accesses by introducing a union of >>> pointers. (A union of the actual table entries is not used to make it >>> impossible to [wrongly, once the 128-bit form gets added] perform >>> pointer arithmetic / array accesses on derived types.) >>> >>> Also move away from updating the entries piecemeal: Construct a full new >>> entry, and write it out. >>> >>> Signed-off-by: Jan Beulich >> I'm still not entirely convinced by extra union and containerof(), but >> the result looks correct. > And I'm still open to going the other way, if you're convinced that > in update_intremap_entry() this > > struct irte_basic basic = { > .flds = { > .remap_en = true, > .int_type = int_type, > .dm = dest_mode, > .dest = dest, > .vector = vector, > } > }; > > (and similarly then for the 128-bit form, and of course .flds > inserted at other use sites) is overall better than the current > variant. I've just experimented with the attached delta and it does compile in CentOS 6, which is the usual culprit for problems in this area. I do think the result is easier-to-read code, which I am definitely in favour of. My ack still stands in all affected patches, but ideally with this kind of change folded in appropriately. ~Andrew --------------C215AC821AFDA668C4A4AC50 Content-Type: text/x-patch; name="reduced.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="reduced.patch" From e028cb655e889ca392023925280f30729be29be7 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Fri, 19 Jul 2019 19:20:27 +0100 Subject: Experiment without containerof diff --git a/xen/drivers/passthrough/amd/iommu_intr.c b/xen/drivers/passthrough/amd/iommu_intr.c index d8d0f71d0d..dc781bb9f1 100644 --- a/xen/drivers/passthrough/amd/iommu_intr.c +++ b/xen/drivers/passthrough/amd/iommu_intr.c @@ -24,41 +24,37 @@ #include #include -struct irte_basic { - bool remap_en:1; - bool sup_io_pf:1; - unsigned int int_type:3; - bool rq_eoi:1; - bool dm:1; - bool guest_mode:1; /* MBZ */ - unsigned int dest:8; - unsigned int vector:8; - unsigned int :8; -}; - union irte32 { - uint32_t raw[1]; - struct irte_basic basic; -}; - -struct irte_full { - bool remap_en:1; - bool sup_io_pf:1; - unsigned int int_type:3; - bool rq_eoi:1; - bool dm:1; - bool guest_mode:1; /* MBZ */ - unsigned int dest_lo:24; - unsigned int :32; - unsigned int vector:8; - unsigned int :24; - unsigned int :24; - unsigned int dest_hi:8; + uint32_t raw; + struct { + bool remap_en:1; + bool sup_io_pf:1; + unsigned int int_type:3; + bool rq_eoi:1; + bool dm:1; + bool guest_mode:1; /* MBZ */ + unsigned int dest:8; + unsigned int vector:8; + unsigned int :8; + } flds; }; union irte128 { uint64_t raw[2]; - struct irte_full full; + struct { + bool remap_en:1; + bool sup_io_pf:1; + unsigned int int_type:3; + bool rq_eoi:1; + bool dm:1; + bool guest_mode:1; /* MBZ */ + unsigned int dest_lo:24; + unsigned int :32; + unsigned int vector:8; + unsigned int :24; + unsigned int :24; + unsigned int dest_hi:8; + } flds; }; union irte_ptr { @@ -187,7 +183,7 @@ static void free_intremap_entry(const struct amd_iommu *iommu, entry.ptr128->raw[1] = 0; } else - ACCESS_ONCE(entry.ptr32->raw[0]) = 0; + ACCESS_ONCE(entry.ptr32->raw) = 0; __clear_bit(index, get_ivrs_mappings(iommu->seg)[bdf].intremap_inuse); } @@ -199,35 +195,36 @@ static void update_intremap_entry(const struct amd_iommu *iommu, { if ( iommu->ctrl.ga_en ) { - struct irte_full full = { - .remap_en = true, - .int_type = int_type, - .dm = dest_mode, - .dest_lo = dest, - .dest_hi = dest >> 24, - .vector = vector, + union irte128 irte = { + .flds = { + .remap_en = true, + .int_type = int_type, + .dm = dest_mode, + .dest_lo = dest, + .dest_hi = dest >> 24, + .vector = vector, + }, }; - ASSERT(!entry.ptr128->full.remap_en); - entry.ptr128->raw[1] = - container_of(&full, union irte128, full)->raw[1]; + ASSERT(!entry.ptr128->flds.remap_en); + entry.ptr128->raw[1] = irte.raw[1]; /* High half needs to be set before low one (containing RemapEn). */ smp_wmb(); - ACCESS_ONCE(entry.ptr128->raw[0]) = - container_of(&full, union irte128, full)->raw[0]; + ACCESS_ONCE(entry.ptr128->raw[0]) = irte.raw[0]; } else { - struct irte_basic basic = { - .remap_en = true, - .int_type = int_type, - .dm = dest_mode, - .dest = dest, - .vector = vector, + union irte32 irte = { + .flds = { + .remap_en = true, + .int_type = int_type, + .dm = dest_mode, + .dest = dest, + .vector = vector, + }, }; - ACCESS_ONCE(entry.ptr32->raw[0]) = - container_of(&basic, union irte32, basic)->raw[0]; + ACCESS_ONCE(entry.ptr32->raw) = irte.raw; } } @@ -244,7 +241,7 @@ static inline void set_rte_index(struct IO_APIC_route_entry *rte, int offset) static inline unsigned int get_full_dest(const union irte128 *entry) { - return entry->full.dest_lo | ((unsigned int)entry->full.dest_hi << 24); + return entry->flds.dest_lo | ((unsigned int)entry->flds.dest_hi << 24); } static int update_intremap_entry_from_ioapic( @@ -289,9 +286,9 @@ static int update_intremap_entry_from_ioapic( entry = get_intremap_entry(iommu, req_id, offset); /* The RemapEn fields match for all formats. */ - while ( iommu->enabled && entry.ptr32->basic.remap_en ) + while ( iommu->enabled && entry.ptr32->flds.remap_en ) { - entry.ptr32->basic.remap_en = false; + entry.ptr32->flds.remap_en = false; spin_unlock(lock); spin_lock(&iommu->lock); @@ -311,11 +308,11 @@ static int update_intremap_entry_from_ioapic( */ ASSERT(get_rte_index(rte) == offset); if ( iommu->ctrl.ga_en ) - vector = entry.ptr128->full.vector; + vector = entry.ptr128->flds.vector; else - vector = entry.ptr32->basic.vector; + vector = entry.ptr32->flds.vector; /* The IntType fields match for both formats. */ - delivery_mode = entry.ptr32->basic.int_type; + delivery_mode = entry.ptr32->flds.int_type; } else if ( x2apic_enabled ) { @@ -558,11 +555,11 @@ unsigned int amd_iommu_read_ioapic_from_ire( ASSERT(offset == (val & (INTREMAP_ENTRIES - 1))); val &= ~(INTREMAP_ENTRIES - 1); /* The IntType fields match for both formats. */ - val |= MASK_INSR(entry.ptr32->basic.int_type, + val |= MASK_INSR(entry.ptr32->flds.int_type, IO_APIC_REDIR_DELIV_MODE_MASK); val |= MASK_INSR(iommu->ctrl.ga_en - ? entry.ptr128->full.vector - : entry.ptr32->basic.vector, + ? entry.ptr128->flds.vector + : entry.ptr32->flds.vector, IO_APIC_REDIR_VECTOR_MASK); } else if ( x2apic_enabled ) @@ -631,9 +628,9 @@ static int update_intremap_entry_from_msi_msg( entry = get_intremap_entry(iommu, req_id, offset); /* The RemapEn fields match for all formats. */ - while ( iommu->enabled && entry.ptr32->basic.remap_en ) + while ( iommu->enabled && entry.ptr32->flds.remap_en ) { - entry.ptr32->basic.remap_en = false; + entry.ptr32->flds.remap_en = false; spin_unlock(lock); spin_lock(&iommu->lock); @@ -767,19 +764,19 @@ void amd_iommu_read_msi_from_ire( msg->data &= ~(INTREMAP_ENTRIES - 1); /* The IntType fields match for both formats. */ - msg->data |= MASK_INSR(entry.ptr32->basic.int_type, + msg->data |= MASK_INSR(entry.ptr32->flds.int_type, MSI_DATA_DELIVERY_MODE_MASK); if ( iommu->ctrl.ga_en ) { - msg->data |= MASK_INSR(entry.ptr128->full.vector, + msg->data |= MASK_INSR(entry.ptr128->flds.vector, MSI_DATA_VECTOR_MASK); msg->dest32 = get_full_dest(entry.ptr128); } else { - msg->data |= MASK_INSR(entry.ptr32->basic.vector, + msg->data |= MASK_INSR(entry.ptr32->flds.vector, MSI_DATA_VECTOR_MASK); - msg->dest32 = entry.ptr32->basic.dest; + msg->dest32 = entry.ptr32->flds.dest; } } @@ -894,9 +891,9 @@ static void dump_intremap_table(const struct amd_iommu *iommu, } else { - if ( !tbl.ptr32[count].raw[0] ) + if ( !tbl.ptr32[count].raw ) continue; - printk(" IRTE[%03x] %08x\n", count, tbl.ptr32[count].raw[0]); + printk(" IRTE[%03x] %08x\n", count, tbl.ptr32[count].raw); } } } --------------C215AC821AFDA668C4A4AC50 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcKaHR0cHM6Ly9saXN0 cy54ZW5wcm9qZWN0Lm9yZy9tYWlsbWFuL2xpc3RpbmZvL3hlbi1kZXZlbA== --------------C215AC821AFDA668C4A4AC50--