Skip to contentSkip to conversation

dlm: align midcomms message buffer

PATCH In review David Teigland 3 participants 4 messages Jan 24, 2008 – Jan 29, 2008 Distributed lock manager (DLM)

lore
Share & tools
lore

David Teigland

author maintainer
#0 lore raw

PATCH 6/19 dlm: align midcomms message buffer

From: Fabio M. Di Nitto <[email protected]>

gcc does not guarantee that a static buffer is 64bit aligned. This change allows sparc64 to work.

---
 fs/dlm/midcomms.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/dlm/midcomms.c +1 -1
index f8c69dd..da653b5 100644
@@ -58,7 +58,7 @@ static void copy_from_cb(void *dst, const void *base, unsigned offset,
 int dlm_process_incoming_buffer(int nodeid, const void *base,
 				unsigned offset, unsigned len, unsigned limit)
 {
-	unsigned char __tmp[DLM_INBUF_LEN];
+	unsigned char __tmp[DLM_INBUF_LEN] __attribute__((aligned(64)));
 	struct dlm_header *msg = (struct dlm_header *) __tmp;
 	int ret = 0;
 	int err = 0;
Signature · 1 line
1.5.3.3
#1 lore raw
Quoted 6 lines · On Thu, 24 Jan 2008 10:50:29 -0600 David Teigland <[email protected]> wrote:

From: Fabio M. Di Nitto <[email protected]>

gcc does not guarantee that a static buffer is 64bit aligned. This change allows sparc64 to work.

This buffer is not static: changelog needs fixing: s/static/auto/

Quoted 9 lines
---
 fs/dlm/midcomms.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/dlm/midcomms.c +0 -0
index f8c69dd..da653b5 100644

fs/dlm/midcomms.c static void copy_from_cb(void *dst, const void *base, unsigned offset, · line 64

Quoted 8 lines
fs/dlm/midcomms.c +1 -1
@@ -58,7 +58,7 @@ static void copy_from_cb(void *dst, const void *base, unsigned offset,
 int dlm_process_incoming_buffer(int nodeid, const void *base,
 				unsigned offset, unsigned len, unsigned limit)
 {
-	unsigned char __tmp[DLM_INBUF_LEN];
+	unsigned char __tmp[DLM_INBUF_LEN] __attribute__((aligned(64)));
 	struct dlm_header *msg = (struct dlm_header *) __tmp;
 	int ret = 0;
 	int err = 0;

Why does DLM require that this thing be 64-bit aligned?

It all looks rather ugly. Can't this stuff be implemeted within the C type system somehow?

#2 lore raw
Quoted 8 lines · Andrew Morton
Quoted 6 lines · On Thu, 24 Jan 2008 10:50:29 -0600 David Teigland <[email protected]> wrote:

From: Fabio M. Di Nitto <[email protected]>

gcc does not guarantee that a static buffer is 64bit aligned. This change allows sparc64 to work.

This buffer is not static: changelog needs fixing: s/static/auto/

thanks

Quoted 5 lines
Quoted 5 lines
---
 fs/dlm/midcomms.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 15 lines

fs/dlm/midcomms.c static void copy_from_cb(void *dst, const void *base, unsigned offset, · line 64

Quoted 13 lines
fs/dlm/midcomms.c +1 -1
index f8c69dd..da653b5 100644
@@ -58,7 +58,7 @@ static void copy_from_cb(void *dst, const void *base, unsigned offset,
 int dlm_process_incoming_buffer(int nodeid, const void *base,
 				unsigned offset, unsigned len, unsigned limit)
 {
-	unsigned char __tmp[DLM_INBUF_LEN];
+	unsigned char __tmp[DLM_INBUF_LEN] __attribute__((aligned(64)));
 	struct dlm_header *msg = (struct dlm_header *) __tmp;
 	int ret = 0;
 	int err = 0;

Why does DLM require that this thing be 64-bit aligned?

i spotted this running on sparc64 and the kernel was both complaning about TSP not being aligned and the data on the other side of the wire were wrong.

Quoted 2 lines

It all looks rather ugly. Can't this stuff be implemeted within the C type system somehow?

Yes, i will rework it.

Thanks for the feedback.

Fabio

--
I'm going to make him an offer he can't refuse.

#3 lore raw
In reply to Andrew Morton
Quoted 29 lines · Andrew Morton
Quoted 6 lines · On Thu, 24 Jan 2008 10:50:29 -0600 David Teigland <[email protected]> wrote:

From: Fabio M. Di Nitto <[email protected]>

gcc does not guarantee that a static buffer is 64bit aligned. This change allows sparc64 to work.

This buffer is not static: changelog needs fixing: s/static/auto/

Quoted 9 lines
---
 fs/dlm/midcomms.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/dlm/midcomms.c +0 -0
index f8c69dd..da653b5 100644

fs/dlm/midcomms.c static void copy_from_cb(void *dst, const void *base, unsigned offset, · line 64

Quoted 8 lines
fs/dlm/midcomms.c +1 -1
@@ -58,7 +58,7 @@ static void copy_from_cb(void *dst, const void *base, unsigned offset,
 int dlm_process_incoming_buffer(int nodeid, const void *base,
 				unsigned offset, unsigned len, unsigned limit)
 {
-	unsigned char __tmp[DLM_INBUF_LEN];
+	unsigned char __tmp[DLM_INBUF_LEN] __attribute__((aligned(64)));
 	struct dlm_header *msg = (struct dlm_header *) __tmp;
 	int ret = 0;
 	int err = 0;

Why does DLM require that this thing be 64-bit aligned?

Quoted 3 lines

It all looks rather ugly. Can't this stuff be implemeted within the C type system somehow?

how about this one:

Quoted 1 line

From adfe3b0654583d34b0840d20a69e4306d5b98caf Mon Sep 17 00:00:00 2001

Message-Id: <adfe3b0654583d34b0840d20a69e4306d5b98caf.1201584946.git.fabbione@ubuntu.com>
From: Fabio M. Di Nitto <[email protected]>
Date: Tue, 29 Jan 2008 06:35:20 +0100
Subject: [PATCH 1/1] dlm: align midcomms message buffer

gcc does not guarantee that an auto buffer is 64bit aligned. This change allows sparc64 to work.

---
:100644 100644 f8c69dd... 53b7af2... M fs/dlm/midcomms.c

 fs/dlm/midcomms.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
fs/dlm/midcomms.c +8 -5
index f8c69dd..53b7af2 100644
@@ -58,8 +58,11 @@ static void copy_from_cb(void *dst, const void *base, unsigned offset,
 int dlm_process_incoming_buffer(int nodeid, const void *base,
 				unsigned offset, unsigned len, unsigned limit)
 {
-	unsigned char __tmp[DLM_INBUF_LEN];
-	struct dlm_header *msg = (struct dlm_header *) __tmp;
+	union {
+		unsigned char __buf[DLM_INBUF_LEN];
+		struct dlm_header dlm;
+	} __tmp;
+	struct dlm_header *msg = &__tmp.dlm;
 	int ret = 0;
 	int err = 0;
 	uint16_t msglen;
@@ -100,8 +103,8 @@ int dlm_process_incoming_buffer(int nodeid, const void *base,
 		   in the buffer on the stack (which should work for most
 		   ordinary messages). */
 
-		if (msglen > sizeof(__tmp) &&
-		    msg == (struct dlm_header *) __tmp) {
+		if (msglen > DLM_INBUF_LEN &&
+		    msg == &__tmp.dlm) {
 			msg = kmalloc(dlm_config.ci_buffer_size, GFP_KERNEL);
 			if (msg == NULL)
 				return ret;
@@ -119,7 +122,7 @@ int dlm_process_incoming_buffer(int nodeid, const void *base,
 		dlm_receive_buffer(msg, nodeid);
 	}
 
-	if (msg != (struct dlm_header *) __tmp)
+	if (msg != &__tmp.dlm)
 		kfree(msg);
 
 	return err ? err : ret;
Signature · 5 lines
1.5.3.8


--
I'm going to make him an offer he can't refuse.