All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qian Cai <cai@lca.pw>
To: David Laight <David.Laight@ACULAB.COM>,
	"vyasevich@gmail.com" <vyasevich@gmail.com>,
	"nhorman@tuxdriver.com" <nhorman@tuxdriver.com>,
	"marcelo.leitner@gmail.com" <marcelo.leitner@gmail.com>
Cc: "linux-sctp@vger.kernel.org" <linux-sctp@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net/sctp: fix GCC8+ -Wpacked-not-aligned warnings
Date: Mon, 29 Jul 2019 15:16:42 +0000	[thread overview]
Message-ID: <1564413402.11067.26.camel@lca.pw> (raw)
In-Reply-To: <158b26b6f3b24164aceacd2428095315@AcuMS.aculab.com>

On Mon, 2019-07-29 at 10:39 +0000, David Laight wrote:
> From: Qian Cai
> > Sent: 26 July 2019 21:58
> > 
> > There are a lot of those warnings with GCC8+ 64bit,
> > 
> 
> ...
> > Fix them by aligning the structures and fields to 8 bytes instead.
> 
> ...
> >  struct sctp_setpeerprim {
> >  	sctp_assoc_t            sspp_assoc_id;
> > -	struct sockaddr_storage sspp_addr;
> > -} __attribute__((packed, aligned(4)));
> > +	struct sockaddr_storage sspp_addr __attribute__((aligned(8)));
> > +} __attribute__((packed, aligned(8)));
> 
> What happens to this one if you change both to aligned(4) ?
> Much the same way as:
> 	struct {
> 		int a;
> 		long b __attribute__((aligned(4));
> 	};
> is only 12 bytes on (most) 64bit systems.

No, that won't work. It because that,

#define sockaddr_storage __kernel_sockaddr_storage

struct __kernel_sockaddr_storage {
...
} __attribute__ ((aligned(_K_SS_ALIGNSIZE)))

#define _K_SS_ALIGNSIZE	(__alignof__ (struct sockaddr *))

A pointer is 8-byte on 64-bit systems. If changed "struct
__kernel_sockaddr_storage" to use,

__attribute__ ((aligned((4)))

it then silence the warnings.

WARNING: multiple messages have this Message-ID (diff)
From: Qian Cai <cai@lca.pw>
To: David Laight <David.Laight@ACULAB.COM>,
	"vyasevich@gmail.com" <vyasevich@gmail.com>,
	"nhorman@tuxdriver.com" <nhorman@tuxdriver.com>,
	"marcelo.leitner@gmail.com" <marcelo.leitner@gmail.com>
Cc: "linux-sctp@vger.kernel.org" <linux-sctp@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net/sctp: fix GCC8+ -Wpacked-not-aligned warnings
Date: Mon, 29 Jul 2019 11:16:42 -0400	[thread overview]
Message-ID: <1564413402.11067.26.camel@lca.pw> (raw)
In-Reply-To: <158b26b6f3b24164aceacd2428095315@AcuMS.aculab.com>

On Mon, 2019-07-29 at 10:39 +0000, David Laight wrote:
> From: Qian Cai
> > Sent: 26 July 2019 21:58
> > 
> > There are a lot of those warnings with GCC8+ 64bit,
> > 
> 
> ...
> > Fix them by aligning the structures and fields to 8 bytes instead.
> 
> ...
> >  struct sctp_setpeerprim {
> >  	sctp_assoc_t            sspp_assoc_id;
> > -	struct sockaddr_storage sspp_addr;
> > -} __attribute__((packed, aligned(4)));
> > +	struct sockaddr_storage sspp_addr __attribute__((aligned(8)));
> > +} __attribute__((packed, aligned(8)));
> 
> What happens to this one if you change both to aligned(4) ?
> Much the same way as:
> 	struct {
> 		int a;
> 		long b __attribute__((aligned(4));
> 	};
> is only 12 bytes on (most) 64bit systems.

No, that won't work. It because that,

#define sockaddr_storage __kernel_sockaddr_storage

struct __kernel_sockaddr_storage {
...
} __attribute__ ((aligned(_K_SS_ALIGNSIZE)))

#define _K_SS_ALIGNSIZE	(__alignof__ (struct sockaddr *))

A pointer is 8-byte on 64-bit systems. If changed "struct
__kernel_sockaddr_storage" to use,

__attribute__ ((aligned((4)))

it then silence the warnings.

  reply	other threads:[~2019-07-29 15:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-26 20:57 [PATCH] net/sctp: fix GCC8+ -Wpacked-not-aligned warnings Qian Cai
2019-07-26 20:57 ` Qian Cai
2019-07-26 21:30 ` Marcelo Ricardo Leitner
2019-07-26 21:30   ` Marcelo Ricardo Leitner
2019-07-28 17:05   ` Qian Cai
2019-07-28 17:05     ` Qian Cai
2019-07-28 19:41     ` Marcelo Ricardo Leitner
2019-07-28 19:41       ` Marcelo Ricardo Leitner
2019-07-29 10:39 ` David Laight
2019-07-29 15:16   ` Qian Cai [this message]
2019-07-29 15:16     ` Qian Cai

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=1564413402.11067.26.camel@lca.pw \
    --to=cai@lca.pw \
    --cc=David.Laight@ACULAB.COM \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sctp@vger.kernel.org \
    --cc=marcelo.leitner@gmail.com \
    --cc=nhorman@tuxdriver.com \
    --cc=vyasevich@gmail.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.