openbmc.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8] net/ncsi : Add payload to be 32-bit aligned to fix dropped packets
@ 2021-11-22 16:38 Kumar Thangavel
  2021-11-24 12:00 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 3+ messages in thread
From: Kumar Thangavel @ 2021-11-22 16:38 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S. Miller, Jakub Kicinski
  Cc: linux-aspeed, netdev, openbmc, Amithash Prasad, velumanit, patrickw3

Update NC-SI command handler (both standard and OEM) to take into
account of payload paddings in allocating skb (in case of payload
size is not 32-bit aligned).

The checksum field follows payload field, without taking payload
padding into account can cause checksum being truncated, leading to
dropped packets.

Fixes: fb4ee67529ff ("net/ncsi: Add NCSI OEM command support")
Signed-off-by: Kumar Thangavel <thangavel.k@hcl.com>
Acked-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>

---
  v8:
   - Updated padding_bytes as static const int variable

  v7:
   - Updated padding_bytes as const static int variable

  v6:
   - Updated type of padding_bytes variable
   - Updated type of payload
   - Seperated variable declarations and code

  v5:
   - Added Fixes tag
   - Added const variable for padding_bytes

  v4:
   - Used existing macro for max function

  v3:
   - Added Macro for MAX
   - Fixed the missed semicolon

  v2:
   - Added NC-SI spec version and section
   - Removed blank line
   - corrected spellings

  v1:
   - Initial draft

---
---
 net/ncsi/ncsi-cmd.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
index ba9ae482141b..dda8b76b7798 100644
--- a/net/ncsi/ncsi-cmd.c
+++ b/net/ncsi/ncsi-cmd.c
@@ -18,6 +18,8 @@
 #include "internal.h"
 #include "ncsi-pkt.h"
 
+static const int padding_bytes = 26;
+
 u32 ncsi_calculate_checksum(unsigned char *data, int len)
 {
 	u32 checksum = 0;
@@ -213,12 +215,17 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb,
 {
 	struct ncsi_cmd_oem_pkt *cmd;
 	unsigned int len;
+	int payload;
+	/* NC-SI spec DSP_0222_1.2.0, section 8.2.2.2
+	 * requires payload to be padded with 0 to
+	 * 32-bit boundary before the checksum field.
+	 * Ensure the padding bytes are accounted for in
+	 * skb allocation
+	 */
 
+	payload = ALIGN(nca->payload, 4);
 	len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
-	if (nca->payload < 26)
-		len += 26;
-	else
-		len += nca->payload;
+	len += max(payload, padding_bytes);
 
 	cmd = skb_put_zero(skb, len);
 	memcpy(&cmd->mfr_id, nca->data, nca->payload);
@@ -272,6 +279,7 @@ static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca)
 	struct net_device *dev = nd->dev;
 	int hlen = LL_RESERVED_SPACE(dev);
 	int tlen = dev->needed_tailroom;
+	int payload;
 	int len = hlen + tlen;
 	struct sk_buff *skb;
 	struct ncsi_request *nr;
@@ -281,14 +289,14 @@ static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca)
 		return NULL;
 
 	/* NCSI command packet has 16-bytes header, payload, 4 bytes checksum.
+	 * Payload needs padding so that the checksum field following payload is
+	 * aligned to 32-bit boundary.
 	 * The packet needs padding if its payload is less than 26 bytes to
 	 * meet 64 bytes minimal ethernet frame length.
 	 */
 	len += sizeof(struct ncsi_cmd_pkt_hdr) + 4;
-	if (nca->payload < 26)
-		len += 26;
-	else
-		len += nca->payload;
+	payload = ALIGN(nca->payload, 4);
+	len += max(payload, padding_bytes);
 
 	/* Allocate skb */
 	skb = alloc_skb(len, GFP_ATOMIC);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v8] net/ncsi : Add payload to be 32-bit aligned to fix dropped packets
  2021-11-22 16:38 [PATCH v8] net/ncsi : Add payload to be 32-bit aligned to fix dropped packets Kumar Thangavel
@ 2021-11-24 12:00 ` patchwork-bot+netdevbpf
  2021-11-25  9:56   ` Kumar Thangavel
  0 siblings, 1 reply; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-11-24 12:00 UTC (permalink / raw)
  To: Kumar Thangavel
  Cc: linux-aspeed, netdev, openbmc, amithash, patrickw3, kuba, sam,
	velumanit, davem

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Mon, 22 Nov 2021 22:08:18 +0530 you wrote:
> Update NC-SI command handler (both standard and OEM) to take into
> account of payload paddings in allocating skb (in case of payload
> size is not 32-bit aligned).
> 
> The checksum field follows payload field, without taking payload
> padding into account can cause checksum being truncated, leading to
> dropped packets.
> 
> [...]

Here is the summary with links:
  - [v8] net/ncsi : Add payload to be 32-bit aligned to fix dropped packets
    https://git.kernel.org/netdev/net/c/ac132852147a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v8] net/ncsi : Add payload to be 32-bit aligned to fix dropped packets
  2021-11-24 12:00 ` patchwork-bot+netdevbpf
@ 2021-11-25  9:56   ` Kumar Thangavel
  0 siblings, 0 replies; 3+ messages in thread
From: Kumar Thangavel @ 2021-11-25  9:56 UTC (permalink / raw)
  To: patchwork-bot+netdevbpf
  Cc: linux-aspeed, Networking, OpenBMC Maillist, Amithash Prasad,
	patrickw3, Jakub Kicinski, Samuel Mendoza-Jonas, velumanit,
	David S. Miller

[-- Attachment #1: Type: text/plain, Size: 898 bytes --]

Awesome, thanks!

On Wed, Nov 24, 2021 at 5:30 PM <patchwork-bot+netdevbpf@kernel.org> wrote:

> Hello:
>
> This patch was applied to netdev/net.git (master)
> by David S. Miller <davem@davemloft.net>:
>
> On Mon, 22 Nov 2021 22:08:18 +0530 you wrote:
> > Update NC-SI command handler (both standard and OEM) to take into
> > account of payload paddings in allocating skb (in case of payload
> > size is not 32-bit aligned).
> >
> > The checksum field follows payload field, without taking payload
> > padding into account can cause checksum being truncated, leading to
> > dropped packets.
> >
> > [...]
>
> Here is the summary with links:
>   - [v8] net/ncsi : Add payload to be 32-bit aligned to fix dropped packets
>     https://git.kernel.org/netdev/net/c/ac132852147a
>
> You are awesome, thank you!
> --
> Deet-doot-dot, I am a bot.
> https://korg.docs.kernel.org/patchwork/pwbot.html
>
>
>

[-- Attachment #2: Type: text/html, Size: 1592 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-25  9:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 16:38 [PATCH v8] net/ncsi : Add payload to be 32-bit aligned to fix dropped packets Kumar Thangavel
2021-11-24 12:00 ` patchwork-bot+netdevbpf
2021-11-25  9:56   ` Kumar Thangavel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).