From nobody Thu Dec 18 12:31:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 610402248AF for ; Wed, 6 Aug 2025 20:37:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754512671; cv=none; b=cTd4r+RolNjDdk6zuRs2IwjW1MFbgBR+nepG/OfEU7egknRVBQnBHZvlJr2CDCouWNPyOeuzHjyTl+cZw6RlkC47StE0NUyXp5MCI4oel8Hu8JbZ/LFD7O4HeiHepbP86FmZOV4fJIsy3Wy69LdwLuTcZzK+QfD77QugAjbfGH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754512671; c=relaxed/simple; bh=ppNcHhXRisKv01c9cZ1qnAtYlgHVNCWEVHkzlLJLWGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TjJI5g9X+pHSaF3kcAeZWGQnyVe3Zd86Ol/w0s0zuPZuQNRyH/el26L4apPi2xAcxy4qCZV1v44vEVkgURMQmhoxjq/kIKk59mtAEYxqVB9EhE1voOR0mAhHlhB+rqeaqCfUxAPsg8bpj3E/6l/gdmmFpEijP0suHMsrTXGOveM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WVhK5kIV; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WVhK5kIV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754512668; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=emfO1GPlFwZIV8t+Z04vg+2LWJzChrqCHQ/rDncitC0=; b=WVhK5kIVmPfZBog3DEeKO/5RIeLt/vNbKaedS9RSb/X9kZB3RyCcSYDggk6scFs4wrgu0c g0qscQUslDveE3JVBKDKyoQTPYq864EOwYS+Rh0zDWf4pHrbhoisEtabaq3AKFPFUmwgPx 1A5e+6e/cApmKDjx9OqiqlDoe15wOcA= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-307-szfcuH63M1iJfTs8avUUlQ-1; Wed, 06 Aug 2025 16:37:43 -0400 X-MC-Unique: szfcuH63M1iJfTs8avUUlQ-1 X-Mimecast-MFC-AGG-ID: szfcuH63M1iJfTs8avUUlQ_1754512659 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D8FBC1956095; Wed, 6 Aug 2025 20:37:38 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.17]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9B7211800446; Wed, 6 Aug 2025 20:37:35 +0000 (UTC) From: David Howells To: Steve French Cc: David Howells , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Wang Zhaolong , Stefan Metzmacher , Mina Almasry , linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, netfs@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 05/31] cifs: Introduce an ALIGN8() macro Date: Wed, 6 Aug 2025 21:36:26 +0100 Message-ID: <20250806203705.2560493-6-dhowells@redhat.com> In-Reply-To: <20250806203705.2560493-1-dhowells@redhat.com> References: <20250806203705.2560493-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" The PDU generation seems to do ALIGN(x, 8) a lot, so make a macro for that. Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Shyam Prasad N cc: Tom Talpey cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/smb/client/cifsglob.h | 2 ++ fs/smb/client/reparse.c | 2 +- fs/smb/client/smb2file.c | 2 +- fs/smb/client/smb2misc.c | 2 +- fs/smb/client/smb2pdu.c | 28 ++++++++++++++-------------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 89160bc34d35..67c1a63a08ba 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -2375,4 +2375,6 @@ static inline bool cifs_netbios_name(const char *name= , size_t namelen) return ret; } =20 +#define ALIGN8(x) ALIGN((x), 8) + #endif /* _CIFS_GLOB_H */ diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index 5fa29a97ac15..2622f90ebc92 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -571,7 +571,7 @@ static struct smb2_create_ea_ctx *ea_create_context(u32= dlen, size_t *cc_len) { struct smb2_create_ea_ctx *cc; =20 - *cc_len =3D round_up(sizeof(*cc) + dlen, 8); + *cc_len =3D ALIGN8(sizeof(*cc) + dlen); cc =3D kzalloc(*cc_len, GFP_KERNEL); if (!cc) return ERR_PTR(-ENOMEM); diff --git a/fs/smb/client/smb2file.c b/fs/smb/client/smb2file.c index a7f629238830..1c8fc06cd46f 100644 --- a/fs/smb/client/smb2file.c +++ b/fs/smb/client/smb2file.c @@ -48,7 +48,7 @@ static struct smb2_symlink_err_rsp *symlink_data(const st= ruct kvec *iov) cifs_dbg(FYI, "%s: skipping unhandled error context: 0x%x\n", __func__, le32_to_cpu(p->ErrorId)); =20 - len =3D ALIGN(le32_to_cpu(p->ErrorDataLength), 8); + len =3D ALIGN8(le32_to_cpu(p->ErrorDataLength)); p =3D (struct smb2_error_context_rsp *)(p->ErrorContextData + len); } while (p < end); } else if (le32_to_cpu(err->ByteCount) >=3D sizeof(*sym) && diff --git a/fs/smb/client/smb2misc.c b/fs/smb/client/smb2misc.c index cddf273c14ae..93ce9fc7b4a4 100644 --- a/fs/smb/client/smb2misc.c +++ b/fs/smb/client/smb2misc.c @@ -252,7 +252,7 @@ smb2_check_message(char *buf, unsigned int len, struct = TCP_Server_Info *server) * Some windows servers (win2016) will pad also the final * PDU in a compound to 8 bytes. */ - if (ALIGN(calc_len, 8) =3D=3D len) + if (ALIGN8(calc_len) =3D=3D len) return 0; =20 /* diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 2df93a75e3b8..96df4aa7a7af 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -619,14 +619,14 @@ build_signing_ctxt(struct smb2_signing_capabilities *= pneg_ctxt) /* * Context Data length must be rounded to multiple of 8 for some servers */ - pneg_ctxt->DataLength =3D cpu_to_le16(ALIGN(sizeof(struct smb2_signing_ca= pabilities) - + pneg_ctxt->DataLength =3D cpu_to_le16(ALIGN8(sizeof(struct smb2_signing_c= apabilities) - sizeof(struct smb2_neg_context) + - (num_algs * sizeof(u16)), 8)); + (num_algs * sizeof(u16)))); pneg_ctxt->SigningAlgorithmCount =3D cpu_to_le16(num_algs); pneg_ctxt->SigningAlgorithms[0] =3D cpu_to_le16(SIGNING_ALG_AES_CMAC); =20 ctxt_len +=3D sizeof(__le16) * num_algs; - ctxt_len =3D ALIGN(ctxt_len, 8); + ctxt_len =3D ALIGN8(ctxt_len); return ctxt_len; /* TBD add SIGNING_ALG_AES_GMAC and/or SIGNING_ALG_HMAC_SHA256 */ } @@ -663,7 +663,7 @@ build_netname_ctxt(struct smb2_netname_neg_context *pne= g_ctxt, char *hostname) /* copy up to max of first 100 bytes of server name to NetName field */ pneg_ctxt->DataLength =3D cpu_to_le16(2 * cifs_strtoUTF16(pneg_ctxt->NetN= ame, hostname, 100, cp)); /* context size is DataLength + minimal smb2_neg_context */ - return ALIGN(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg_= context), 8); + return ALIGN8(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg= _context)); } =20 static void @@ -709,18 +709,18 @@ assemble_neg_contexts(struct smb2_negotiate_req *req, * round up total_len of fixed part of SMB3 negotiate request to 8 * byte boundary before adding negotiate contexts */ - *total_len =3D ALIGN(*total_len, 8); + *total_len =3D ALIGN8(*total_len); =20 pneg_ctxt =3D (*total_len) + (char *)req; req->NegotiateContextOffset =3D cpu_to_le32(*total_len); =20 build_preauth_ctxt((struct smb2_preauth_neg_context *)pneg_ctxt); - ctxt_len =3D ALIGN(sizeof(struct smb2_preauth_neg_context), 8); + ctxt_len =3D ALIGN8(sizeof(struct smb2_preauth_neg_context)); *total_len +=3D ctxt_len; pneg_ctxt +=3D ctxt_len; =20 build_encrypt_ctxt((struct smb2_encryption_neg_context *)pneg_ctxt); - ctxt_len =3D ALIGN(sizeof(struct smb2_encryption_neg_context), 8); + ctxt_len =3D ALIGN8(sizeof(struct smb2_encryption_neg_context)); *total_len +=3D ctxt_len; pneg_ctxt +=3D ctxt_len; =20 @@ -749,7 +749,7 @@ assemble_neg_contexts(struct smb2_negotiate_req *req, if (server->compression.requested) { build_compression_ctxt((struct smb2_compression_capabilities_context *) pneg_ctxt); - ctxt_len =3D ALIGN(sizeof(struct smb2_compression_capabilities_context),= 8); + ctxt_len =3D ALIGN8(sizeof(struct smb2_compression_capabilities_context)= ); *total_len +=3D ctxt_len; pneg_ctxt +=3D ctxt_len; neg_context_count++; @@ -940,7 +940,7 @@ static int smb311_decode_neg_context(struct smb2_negoti= ate_rsp *rsp, * aligned offset following the previous negotiate context. */ if (i + 1 !=3D ctxt_cnt) - clen =3D ALIGN(clen, 8); + clen =3D ALIGN8(clen); if (clen > len_of_ctxts) break; =20 @@ -2631,7 +2631,7 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned = int *len) unsigned int group_offset =3D 0; struct smb3_acl acl =3D {}; =20 - *len =3D round_up(sizeof(struct crt_sd_ctxt) + (sizeof(struct smb_ace) * = 4), 8); + *len =3D ALIGN8(sizeof(struct crt_sd_ctxt) + (sizeof(struct smb_ace) * 4)= ); =20 if (set_owner) { /* sizeof(struct owner_group_sids) is already multiple of 8 so no need t= o round */ @@ -2706,7 +2706,7 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned = int *len) memcpy(aclptr, &acl, sizeof(struct smb3_acl)); =20 buf->ccontext.DataLength =3D cpu_to_le32(ptr - (__u8 *)&buf->sd); - *len =3D round_up((unsigned int)(ptr - (__u8 *)buf), 8); + *len =3D ALIGN8((unsigned int)(ptr - (__u8 *)buf)); =20 return buf; } @@ -2799,7 +2799,7 @@ alloc_path_with_tree_prefix(__le16 **out_path, int *o= ut_size, int *out_len, * final path needs to be 8-byte aligned as specified in * MS-SMB2 2.2.13 SMB2 CREATE Request. */ - *out_size =3D round_up(*out_len * sizeof(__le16), 8); + *out_size =3D ALIGN8(*out_len * sizeof(__le16)); *out_path =3D kzalloc(*out_size + sizeof(__le16) /* null */, GFP_KERNEL); if (!*out_path) return -ENOMEM; @@ -3064,7 +3064,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Ser= ver_Info *server, uni_path_len =3D (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2; /* MUST set path len (NameLength) to 0 opening root of share */ req->NameLength =3D cpu_to_le16(uni_path_len - 2); - copy_size =3D round_up(uni_path_len, 8); + copy_size =3D ALIGN8(uni_path_len); copy_path =3D kzalloc(copy_size, GFP_KERNEL); if (!copy_path) return -ENOMEM; @@ -4490,7 +4490,7 @@ smb2_new_read_req(void **buf, unsigned int *total_len, if (request_type & CHAINED_REQUEST) { if (!(request_type & END_OF_CHAIN)) { /* next 8-byte aligned request */ - *total_len =3D ALIGN(*total_len, 8); + *total_len =3D ALIGN8(*total_len); shdr->NextCommand =3D cpu_to_le32(*total_len); } else /* END_OF_CHAIN */ shdr->NextCommand =3D 0;