From: Samuel Holland <samuel@sholland.org>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Adam Radford <aradford@gmail.com>,
"James E.J. Bottomley" <jejb@linux.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
linux-scsi <linux-scsi@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] scsi: 3w-9xxx: Fix endianness issues found by sparse
Date: Sat, 8 Aug 2020 19:16:37 -0500 [thread overview]
Message-ID: <3493a479-3468-02e4-6eed-3645875b7841@sholland.org> (raw)
In-Reply-To: <CAK8P3a3bPb+-i2YbHmn84MEuCe4xG_BKP15vNO1B1kTkYZ+=pg@mail.gmail.com>
On 8/5/20 2:17 AM, Arnd Bergmann wrote:
> On Wed, Aug 5, 2020 at 3:44 AM Samuel Holland <samuel@sholland.org> wrote:
>> On 8/3/20 9:02 AM, Arnd Bergmann wrote:
>>> On Mon, Aug 3, 2020 at 5:42 AM Samuel Holland <samuel@sholland.org> wrote:
>>>> All of the command structures are packed, due to the "#pragma pack(1)" earlier
>>>> in the file. So alignment is not an issue. This dma_addr_t member _is_ the
>>>> explicit padding to make sizeof(TW_Command) -
>>>> sizeof(TW_Command.byte8_offset.{io,param}.sgl) equal TW_COMMAND_SIZE * 4. And
>>>> indeed the structure is expected to be a different size depending on
>>>> sizeof(dma_addr_t).
>>>
>>> Ah, so only the first few members are accessed by hardware and the
>>> last union is only accessed by the OS then? In that case I suppose it is
>>> all fine, but I would also suggest removing the "#pragma packed"
>>> to get somewhat more efficient access on systems that have problems
>>> with misaligned accesses.
>>
>> I don't know what part the hardware accesses; everything I know about the
>> hardware comes from reading the driver.
>
> I see now from your explanation below that this is a hardware-defined
> structure. I was confused by how it can be either 32 or 64 bits wide but
> found the
>
> tw_initconnect->features |= sizeof(dma_addr_t) > 4 ? 1 : 0;
>
> line now that tells the hardware about which format is used.
>
>> The problem with removing the "#pragma pack(1)" is that the structure is
>> inherently misaligned: byte8_offset.io.sgl starts at offset 12, but it may begin
>> with a __le64.
>
> I think a fairly clean way to handle this would be to remove the pragma
> and instead define a local type like
>
> #if IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT)
> typedef __le64 twa_address_t __packed;
> #else
> typedef __le32 twa_addr_t;
> #endif
I would be happy to implement this... but __packed only works on enums, structs,
and unions[1]:
In file included from drivers/scsi/3w-9xxx.c:100:
drivers/scsi/3w-9xxx.h:474:1: warning: 'packed' attribute ignored [-Wattributes]
474 | typedef __le64 twa_addr_t __packed;
| ^~~~~~~
[1]:
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-packed-type-attribute
> The problem with marking the entire structure as packed, rather than
> just individual members is that you end up with very inefficient bytewise
> access on some architectures (especially those without cache-coherent
> DMA or hardware unaligned access in the CPU), so I would recommend
> avoiding that in portable driver code.
I agree, but I think this is a separate issue from what this patch is fixing. I
would prefer to save this change for a separate patch.
Regards,
Samuel
prev parent reply other threads:[~2020-08-09 0:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-30 22:07 [PATCH v2] scsi: 3w-9xxx: Fix endianness issues found by sparse Samuel Holland
2020-07-31 7:29 ` Arnd Bergmann
2020-08-03 3:43 ` Samuel Holland
2020-08-03 14:02 ` Arnd Bergmann
2020-08-05 1:45 ` Samuel Holland
2020-08-05 7:17 ` Arnd Bergmann
2020-08-09 0:16 ` Samuel Holland [this message]
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=3493a479-3468-02e4-6eed-3645875b7841@sholland.org \
--to=samuel@sholland.org \
--cc=aradford@gmail.com \
--cc=arnd@arndb.de \
--cc=jejb@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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).