All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergei Trofimovich <slyfox@gentoo.org>
To: "Elliott, Robert (Servers)" <elliott@hpe.com>
Cc: Arnd Bergmann <arnd@kernel.org>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
	Don Brace - C33706 <don.brace@microchip.com>,
	"linux-ia64@vger.kernel.org" <linux-ia64@vger.kernel.org>,
	"storagedev@microchip.com" <storagedev@microchip.com>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	"jszczype@redhat.com" <jszczype@redhat.com>,
	Scott Benesh <scott.benesh@microchip.com>,
	Scott Teel <scott.teel@microchip.com>,
	"thenzl@redhat.com" <thenzl@redhat.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 3/3] hpsa: add an assert to prevent from __packed reintroduction
Date: Sat, 03 Apr 2021 14:51:48 +0000	[thread overview]
Message-ID: <20210403155148.0f5c94ff@sf> (raw)
In-Reply-To: <TU4PR8401MB1055C76F16F4D8A2DCF541F8AB7A9@TU4PR8401MB1055.NAMPRD84.PROD.OUTLOOK.COM>

On Fri, 2 Apr 2021 14:40:39 +0000
"Elliott, Robert (Servers)" <elliott@hpe.com> wrote:

> It looks like ia64 implements atomic_t as a 64-bit value and expects atomic_t
> to be 64-bit aligned, but does nothing to ensure that.
> 
> For x86, atomic_t is a 32-bit value and atomic64_t is a 64-bit value, and
> the definition of atomic64_t is overridden in a way that ensures
> 64-bit (8 byte) alignment:
> 
> Generic definitions are in include/linux/types.h:
>     typedef struct {
>             int counter;
>     } atomic_t;
> 
>     #define ATOMIC_INIT(i) { (i) }
> 
>     #ifdef CONFIG_64BIT
>     typedef struct {
>             s64 counter;
>     } atomic64_t;
>     #endif
> 
> Override in arch/x86/include/asm/atomic64_32.h:
>     typedef struct {
>             s64 __aligned(8) counter;
>     } atomic64_t;
> 
> Perhaps ia64 needs to take over the definition of both atomic_t and atomic64_t
> and do the same?

I don't think it's needed. ia64 is a 64-bit arch with expected
natural alignment for s64: alignof(s64)=8.

Also if my understanding is correct adding __aligned(8) would not fix
use case of embedding locks into packed structs even on x86_64 (or i386):

    $ cat a.c
    #include <stdio.h>
    #include <stddef.h>

    typedef struct { unsigned long long __attribute__((aligned(8))) l; } lock_t;
    struct s { char c; lock_t lock; } __attribute__((packed));
    int main() { printf ("offsetof(struct s, lock) = %lu\nsizeof(struct s) = %lu\n", offsetof(struct s, lock), sizeof(struct s)); }

    $ x86_64-pc-linux-gnu-gcc a.c -o a && ./a
    offsetof(struct s, lock) = 1
    sizeof(struct s) = 9

    $ x86_64-pc-linux-gnu-gcc a.c -o a -m32 && ./a
    offsetof(struct s, lock) = 1
    sizeof(struct s) = 9

Note how alignment of 'lock' stays 1 byte in both cases.

8-byte alignment added for i386 in
    https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id»f2a330d92c5afccfd17592ba9ccd50f41cf748
is only as a performance optimization (not a correctness fix).

Larger alignment on i386 is preferred because alignof(s64)=4 on
that target which might make atomic op span cache lines that
leads to performance degradation.

-- 

  Sergei

WARNING: multiple messages have this Message-ID (diff)
From: Sergei Trofimovich <slyfox@gentoo.org>
To: "Elliott, Robert (Servers)" <elliott@hpe.com>
Cc: Arnd Bergmann <arnd@kernel.org>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	"John Paul Adrian Glaubitz" <glaubitz@physik.fu-berlin.de>,
	Don Brace - C33706 <don.brace@microchip.com>,
	"linux-ia64@vger.kernel.org" <linux-ia64@vger.kernel.org>,
	"storagedev@microchip.com" <storagedev@microchip.com>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	"jszczype@redhat.com" <jszczype@redhat.com>,
	Scott Benesh <scott.benesh@microchip.com>,
	Scott Teel <scott.teel@microchip.com>,
	"thenzl@redhat.com" <thenzl@redhat.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 3/3] hpsa: add an assert to prevent from __packed reintroduction
Date: Sat, 3 Apr 2021 15:51:48 +0100	[thread overview]
Message-ID: <20210403155148.0f5c94ff@sf> (raw)
In-Reply-To: <TU4PR8401MB1055C76F16F4D8A2DCF541F8AB7A9@TU4PR8401MB1055.NAMPRD84.PROD.OUTLOOK.COM>

On Fri, 2 Apr 2021 14:40:39 +0000
"Elliott, Robert (Servers)" <elliott@hpe.com> wrote:

> It looks like ia64 implements atomic_t as a 64-bit value and expects atomic_t
> to be 64-bit aligned, but does nothing to ensure that.
> 
> For x86, atomic_t is a 32-bit value and atomic64_t is a 64-bit value, and
> the definition of atomic64_t is overridden in a way that ensures
> 64-bit (8 byte) alignment:
> 
> Generic definitions are in include/linux/types.h:
>     typedef struct {
>             int counter;
>     } atomic_t;
> 
>     #define ATOMIC_INIT(i) { (i) }
> 
>     #ifdef CONFIG_64BIT
>     typedef struct {
>             s64 counter;
>     } atomic64_t;
>     #endif
> 
> Override in arch/x86/include/asm/atomic64_32.h:
>     typedef struct {
>             s64 __aligned(8) counter;
>     } atomic64_t;
> 
> Perhaps ia64 needs to take over the definition of both atomic_t and atomic64_t
> and do the same?

I don't think it's needed. ia64 is a 64-bit arch with expected
natural alignment for s64: alignof(s64)=8.

Also if my understanding is correct adding __aligned(8) would not fix
use case of embedding locks into packed structs even on x86_64 (or i386):

    $ cat a.c
    #include <stdio.h>
    #include <stddef.h>

    typedef struct { unsigned long long __attribute__((aligned(8))) l; } lock_t;
    struct s { char c; lock_t lock; } __attribute__((packed));
    int main() { printf ("offsetof(struct s, lock) = %lu\nsizeof(struct s) = %lu\n", offsetof(struct s, lock), sizeof(struct s)); }

    $ x86_64-pc-linux-gnu-gcc a.c -o a && ./a
    offsetof(struct s, lock) = 1
    sizeof(struct s) = 9

    $ x86_64-pc-linux-gnu-gcc a.c -o a -m32 && ./a
    offsetof(struct s, lock) = 1
    sizeof(struct s) = 9

Note how alignment of 'lock' stays 1 byte in both cases.

8-byte alignment added for i386 in
    https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=bbf2a330d92c5afccfd17592ba9ccd50f41cf748
is only as a performance optimization (not a correctness fix).

Larger alignment on i386 is preferred because alignof(s64)=4 on
that target which might make atomic op span cache lines that
leads to performance degradation.

-- 

  Sergei

  reply	other threads:[~2021-04-03 14:51 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210222230519.73f3e239@sf>
2021-02-22 23:34 ` 5.11 regression: "ia64: add support for TIF_NOTIFY_SIGNAL" breaks ia64 boot Jens Axboe
2021-02-22 23:34   ` Jens Axboe
2021-02-22 23:55   ` John Paul Adrian Glaubitz
2021-02-22 23:55     ` John Paul Adrian Glaubitz
     [not found]     ` <20210223083507.43b5a6dd@sf>
2021-02-23  9:13       ` John Paul Adrian Glaubitz
2021-02-23 12:36         ` John Paul Adrian Glaubitz
2021-02-23 12:36           ` John Paul Adrian Glaubitz
     [not found]           ` <20210223192743.0198d4a9@sf>
     [not found]             ` <20210302222630.5056f243@sf>
2021-03-02 22:31               ` John Paul Adrian Glaubitz
2021-03-02 22:31                 ` John Paul Adrian Glaubitz
2021-03-03  0:22                 ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" bre Sergei Trofimovich
2021-03-03  0:22                   ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" breaks hpsa P600 Sergei Trofimovich
2021-03-03  8:55                   ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" Sergei Trofimovich
2021-03-03  8:55                     ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" breaks hpsa P600 Sergei Trofimovich
2021-03-03 17:33                     ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" Don.Brace
2021-03-03 17:33                       ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" breaks hpsa P600 Don.Brace
     [not found]                       ` <20210303220401.501449e5@sf>
2021-03-04 17:00                         ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" Don.Brace
2021-03-04 17:00                           ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" breaks hpsa P600 Don.Brace
2021-03-05 13:26                           ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" Tomas Henzl
2021-03-05 13:26                             ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" breaks hpsa P600 Tomas Henzl
2021-03-12 22:27                             ` [PATCH] hpsa: fix boot on ia64 (atomic_t alignment) Sergei Trofimovich
2021-03-12 22:27                               ` Sergei Trofimovich
2021-03-16 16:30                               ` Don.Brace
2021-03-16 16:30                                 ` Don.Brace
2021-03-16 18:28                                 ` Arnd Bergmann
2021-03-16 18:28                                   ` Arnd Bergmann
2021-03-17  2:25                                   ` Martin K. Petersen
2021-03-17  2:25                                     ` Martin K. Petersen
2021-03-17 13:19                                     ` David Laight
2021-03-17 19:06                                       ` Don.Brace
2021-03-17 19:06                                         ` Don.Brace
2021-03-17 17:28                               ` John Paul Adrian Glaubitz
2021-03-17 17:28                                 ` John Paul Adrian Glaubitz
2021-03-27 10:24                                 ` Sergei Trofimovich
2021-03-24  7:08                               ` John Paul Adrian Glaubitz
2021-03-24  7:08                                 ` John Paul Adrian Glaubitz
2021-03-24 18:37                               ` Don.Brace
2021-03-24 18:37                                 ` Don.Brace
2021-03-29 11:25                                 ` John Paul Adrian Glaubitz
2021-03-29 11:25                                   ` John Paul Adrian Glaubitz
2021-03-29 14:22                                   ` Arnd Bergmann
2021-03-29 14:22                                     ` Arnd Bergmann
2021-03-30  3:02                                     ` Martin K. Petersen
2021-03-30  3:02                                       ` Martin K. Petersen
2021-03-30  7:19                                       ` [PATCH v2 1/3] hpsa: use __packed on individual structs, not header-wide Sergei Trofimovich
2021-03-30  7:19                                         ` Sergei Trofimovich
2021-03-30  7:19                                         ` [PATCH v2 2/3] hpsa: fix boot on ia64 (atomic_t alignment) Sergei Trofimovich
2021-03-30  7:19                                           ` Sergei Trofimovich
2021-03-30  7:19                                         ` [PATCH v2 3/3] hpsa: add an assert to prevent from __packed reintroduction Sergei Trofimovich
2021-03-30  7:19                                           ` Sergei Trofimovich
2021-03-30  7:34                                           ` Arnd Bergmann
2021-03-30  7:34                                             ` Arnd Bergmann
2021-04-02 14:40                                             ` Elliott, Robert (Servers)
2021-04-02 14:40                                               ` Elliott, Robert (Servers)
2021-04-03 14:51                                               ` Sergei Trofimovich [this message]
2021-04-03 14:51                                                 ` Sergei Trofimovich
2021-03-30  7:30                                         ` [PATCH v2 1/3] hpsa: use __packed on individual structs, not header-wide Arnd Bergmann
2021-03-30  7:30                                           ` Arnd Bergmann
2021-03-30  7:43                                           ` Arnd Bergmann
2021-03-30  7:43                                             ` Arnd Bergmann
2021-04-02  3:54                                         ` Martin K. Petersen
2021-04-02  3:54                                           ` Martin K. Petersen
2021-04-15 18:41                                           ` Don.Brace
2021-04-15 18:41                                             ` Don.Brace
2021-03-05  9:22                       ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" Geert Uytterhoeven
2021-03-05  9:22                         ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" breaks hpsa P600 Geert Uytterhoeven
2021-03-05 13:31                         ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" Arnd Bergmann
2021-03-05 13:31                           ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" breaks hpsa P600 Arnd Bergmann
2021-03-05 20:45                           ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" Don.Brace
2021-03-05 20:45                             ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" breaks hpsa P600 Don.Brace
2021-03-03 15:42                   ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" Don.Brace
2021-03-03 15:42                     ` [bisected] 5.12-rc1 hpsa regression: "scsi: hpsa: Correct dev cmds outstanding for retried cmds" breaks hpsa P600 Don.Brace
2021-03-17 17:42             ` 5.11 regression: "ia64: add support for TIF_NOTIFY_SIGNAL" breaks ia64 boot John Paul Adrian Glaubitz
2021-03-17 17:42               ` John Paul Adrian Glaubitz
2021-03-17 17:53               ` John Paul Adrian Glaubitz
2021-03-17 17:53                 ` John Paul Adrian Glaubitz
     [not found]   ` <20210222235359.75d1a912@sf>
2021-02-23  0:34     ` Jens Axboe
2021-02-23  0:34       ` Jens Axboe
2021-02-23  0:41       ` Jens Axboe
2021-02-23  0:41         ` Jens Axboe
2021-02-23  0:43         ` Jens Axboe
2021-02-23  0:43           ` Jens Axboe
     [not found]           ` <20210223080830.23bccdbf@sf>
2021-03-02 22:07             ` Sergei Trofimovich
2021-03-02 22:07               ` Sergei Trofimovich
2021-03-02 22:31               ` Jens Axboe
2021-03-02 22:31                 ` Jens Axboe
     [not found]                 ` <20210302232716.353ed49b@sf>
2021-03-03  0:34                   ` Jens Axboe
2021-03-03  0:34                     ` Jens Axboe
2021-03-03  3:51                     ` Jens Axboe
2021-03-03  3:51                       ` Jens Axboe

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=20210403155148.0f5c94ff@sf \
    --to=slyfox@gentoo.org \
    --cc=arnd@kernel.org \
    --cc=don.brace@microchip.com \
    --cc=elliott@hpe.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=jszczype@redhat.com \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=scott.benesh@microchip.com \
    --cc=scott.teel@microchip.com \
    --cc=storagedev@microchip.com \
    --cc=thenzl@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.