Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7726913rwl; Tue, 10 Jan 2023 04:47:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXtRo3SpLT7/qO3DXS3+5uon2Mz/gOWuH6NwNJnaGRN1zqZnW3w5DQMl9EYpUdXGfMJL7xdy X-Received: by 2002:a05:6402:1149:b0:482:d62c:cde with SMTP id g9-20020a056402114900b00482d62c0cdemr53814204edw.13.1673354858409; Tue, 10 Jan 2023 04:47:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673354858; cv=none; d=google.com; s=arc-20160816; b=NjAWRSh53mYj5MOuhrppt64c93gBmryYUIAEIVC6xGfmeBX825W9+3gB9a6V1/F+Qe QVPWFpfYuE9JWT25CRq31Zdex5zT6kDKpUbSmjei+08I4DSi3Y5VZjLC4dFUsCFdXREw h+Ix5npvf8jSctiJEB36Z72lldAtoRdcyoOigm/pMt3KSJOjYiBdI9C39LaETNO9n8PQ DPOPdN0T3S3KpH8mhoBSWKbYPjHP2hxyNoqy7iEZG2aD7aPnHWP993W4y7iVnUJocmps IjTDsDFTdCd8kDfIRDWcYxLMK8PeyvZvHKVGVS+796QDbg3H3touma3e2a9dccDhlytj LNKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=KowriyyG1FIF2mYG3uhoZ5l9Kh0QAczNhRuEEsZNDy4=; b=W/etdOCP4HNIuGk3t9A8n8vjUHKCbZyioyTcvxeg1oHMn/hzYRoFaPLEA5dlEhXOvz g1OKQFLNPCejRtxaxnAutNbCVzqfI3KIzw0vjW0h592yzceNft1He9AJBiJlAPW7tEDq I7EdUA2TVEqljE9NQaKnMgKlDlZZe59GvabNj73VfU4uk+LKFDM0QNv/Tib7aoGETIig CRFW1x/sTmF/kd+D7tMbglFRic2KKoPivz2F7cud4ySarbjWm7Voie7eySTT356LPXJ0 CtQcxB0LTcgZOR9Wwbg2+Z0iygIulZWBL7hs7+wOnQBcAuAVF+Vzs8yowJbOSOyc0chP vjdw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a056402278c00b004615937b174si13339222ede.480.2023.01.10.04.47.21; Tue, 10 Jan 2023 04:47:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238384AbjAJMek convert rfc822-to-8bit (ORCPT + 65 others); Tue, 10 Jan 2023 07:34:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232931AbjAJMei (ORCPT ); Tue, 10 Jan 2023 07:34:38 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D55E51743C for ; Tue, 10 Jan 2023 04:34:35 -0800 (PST) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-319-CqCJCDyUO0CLmH1_J02gWQ-1; Tue, 10 Jan 2023 12:34:32 +0000 X-MC-Unique: CqCJCDyUO0CLmH1_J02gWQ-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Tue, 10 Jan 2023 12:34:31 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.044; Tue, 10 Jan 2023 12:34:31 +0000 From: David Laight To: 'Kalle Valo' CC: 'Martin Blumenstingl' , Ping-Ke Shih , "linux-wireless@vger.kernel.org" , "tehuang@realtek.com" , "s.hauer@pengutronix.de" , "tony0620emma@gmail.com" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH 1/4] rtw88: Add packed attribute to the eFuse structs Thread-Topic: [PATCH 1/4] rtw88: Add packed attribute to the eFuse structs Thread-Index: AQHZJOt8b7TA8qgUUEi14rUuSBslva6Xj6GQ Date: Tue, 10 Jan 2023 12:34:31 +0000 Message-ID: <7f75a99604394c47bd646c6a024cb27a@AcuMS.aculab.com> References: <20221228133547.633797-1-martin.blumenstingl@googlemail.com> <20221228133547.633797-2-martin.blumenstingl@googlemail.com> <92eb7dfa8b7d447e966a2751e174b642@realtek.com> <87da8c82dec749dc826b5a1b4c4238aa@AcuMS.aculab.com> <5c0c77240e7ddfdffbd771ee7e50d36ef3af9c84.camel@realtek.com> <87r0w2fvgz.fsf@kernel.org> In-Reply-To: <87r0w2fvgz.fsf@kernel.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Kalle Valo > Sent: 10 January 2023 12:03 ... > > Most hardware definitions align everything. > > > > What you may want to do is add compile-time asserts for the > > sizes of the structures. > > > > Remember that if you have 16/32 bit fields in packed structures > > on some architectures the compile has to generate code that does > > byte loads and shifts. > > > > The 'misaligned' property is lost when you take the address - so > > you can easily generate a fault. > > > > Adding __packed to a struct is a sledgehammer you really shouldn't need. > > Avoiding use of __packed is news to me, but is this really a safe rule? > Most of the wireless engineers are no compiler experts (myself included) > so I'm worried. For example, in ath10k and ath11k I try to use __packed > for all structs which are accessing hardware or firmware just to make > sure that the compiler is not changing anything. What may wish to do is get the compiler to generate an error if it would add any padding - but that isn't what __packed is for or what it does. The compiler will only ever add padding to ensure that fields are correctly aligned (usually a multiple of their size). There can also be padding at the end of a structure so that arrays are aligned. There are some unusual ABI that align all structures on 4 byte boundaries - but i don't think Linux has any of them. In any case this rarely matters. All structures that hardware/firmware access are very likely to have everything on its natural alignment unless you have a very old structure hat might have a 16bit aligned 32bit value that was assumed to be two words. Now if you have: struct { char a[4]; int b; } __packed foo; whenever you access foo.b the compiler might have to generate 4 separate byte memory accesses and a load of shift/and/or instructions in order to avoid a misaligned address trap. So you don't want to use __packed unless the field is actually expected to be misaligned. For most hardware/firmware structures this isn't true. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)