[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7fc38a4a124caef6cb96a00000043a3288f4f004.camel@suse.com>
Date: Thu, 11 May 2023 17:59:26 +0200
From: Martin Wilck <mwilck@...e.com>
To: Juergen Gross <jgross@...e.com>, linux-kernel@...r.kernel.org,
linux-scsi@...r.kernel.org
Cc: "James E.J. Bottomley" <jejb@...ux.ibm.com>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
stable@...r.kernel.org
Subject: Re: [PATCH] scsi: Let scsi_execute_cmd() mark args->sshdr as invalid
On Thu, 2023-05-11 at 15:32 +0200, Juergen Gross wrote:
> On 11.05.23 15:23, Martin Wilck wrote:
> > On Thu, 2023-05-11 at 15:17 +0200, Juergen Gross wrote:
> > > >
> > > > We know for certain that sizeof(*sshdr) is 8 bytes, and will
> > > > most
> > > > probably remain so. Thus
> > > >
> > > > memset(sshdr, 0, sizeof(*sshdr))
> > > >
> > > > would result in more efficient code.
> > >
> > > I fail to see why zeroing a single byte would be less efficient
> > > than
> > > zeroing
> > > a possibly unaligned 8-byte area.
> >
> > I don't think it can be unaligned. gcc seems to think the same. It
> > compiles the memset(sshdr, ...) in scsi_normalize_sense() into a
> > single
> > instruction on x86_64.
> >
> > 0xffffffff8177e9d0 <scsi_normalize_sense>: nopl
> > 0x0(%rax,%rax,1) [FTRACE NOP]
> > 0xffffffff8177e9d5 <scsi_normalize_sense+5>: test %rdi,%rdi
> > 0xffffffff8177e9d8 <scsi_normalize_sense+8>: movq $0x0,(%rdx)
>
> A struct with 8 "u8" fields can be unaligned.
Right. I wrongly assumed this would be aligned like an u64. "The
alignment of any given struct or union type is required by the ISO C
standard to be at least a perfect multiple of the lowest common
multiple of the alignments of all of the members of the struct".
I wonder if this (non-)alignment of struct scsi_sense_hdr is
intentional, but that's a different discussion.
Thanks,
Martin
Powered by blists - more mailing lists