[Cluster-devel] [PATCHv2 dlm/next 14/17] fs: dlm: remove unaligned memory access handling

Alexander Aring aahringo at redhat.com
Tue Dec 1 15:09:54 UTC 2020


This patch removes unaligned memory access handling for receiving
midcomms messages. The allocated receive buffer is always memory aligned
as the code shows, but each dlm message length and their structure fields
are always aligned to 4 bytes addresses so it should be fine to remove
this special handling.

Signed-off-by: Alexander Aring <aahringo at redhat.com>
---
 fs/dlm/midcomms.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/fs/dlm/midcomms.c b/fs/dlm/midcomms.c
index e058e017c77d..76e7904c3021 100644
--- a/fs/dlm/midcomms.c
+++ b/fs/dlm/midcomms.c
@@ -22,8 +22,6 @@
  * into packets and sends them to the comms layer.
  */
 
-#include <asm/unaligned.h>
-
 #include "dlm_internal.h"
 #include "lowcomms.h"
 #include "config.h"
@@ -83,6 +81,8 @@ void dlm_midcomms_stop(void)
  * commands.
  */
 
+#define DLM_MSGLEN_IS_NOT_ALIGNED(len) ((len & 0x3) != 0)
+
 int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int len)
 {
 	const unsigned char *ptr = buf;
@@ -96,10 +96,12 @@ int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int len)
 		/* no message should be more than this otherwise we
 		 * cannot deliver this message to upper layers
 		 */
-		msglen = get_unaligned_le16(&hd->h_length);
-		if (msglen > DEFAULT_BUFFER_SIZE) {
-			log_print("received invalid length header: %u, will abort message parsing",
-				  msglen);
+		msglen = le16_to_cpu(hd->h_length);
+		if (msglen > DEFAULT_BUFFER_SIZE ||
+		    msglen < sizeof(struct dlm_header) ||
+		    DLM_MSGLEN_IS_NOT_ALIGNED(msglen)) {
+			log_print("received invalid length header: %u from node %d, will abort message parsing",
+				  msglen, nodeid);
 			return -EBADMSG;
 		}
 
@@ -132,14 +134,6 @@ int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int len)
 			goto skip;
 		}
 
-		/* for aligned memory access, we just copy current message
-		 * to begin of the buffer which contains already parsed buffer
-		 * data and should provide align access for upper layers
-		 * because the start address of the buffer has a aligned
-		 * address. This memmove can be removed when the upperlayer
-		 * is capable of unaligned memory access.
-		 */
-		memmove(buf, ptr, msglen);
 		dlm_receive_buffer((union dlm_packet *)buf, nodeid);
 
 skip:
-- 
2.26.2




More information about the Cluster-devel mailing list