All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
@ 2021-10-28  9:50 Kumar Thangavel
  2021-11-03 15:11 ` Kumar Thangavel
  0 siblings, 1 reply; 16+ messages in thread
From: Kumar Thangavel @ 2021-10-28  9:50 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S. Miller, Jakub Kicinski
  Cc: linux-aspeed, 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.

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>

---
  v4:
   - Updated 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 | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
index ba9ae482141b..e44fe138c20f 100644
--- a/net/ncsi/ncsi-cmd.c
+++ b/net/ncsi/ncsi-cmd.c
@@ -213,12 +213,16 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb,
 {
 	struct ncsi_cmd_oem_pkt *cmd;
 	unsigned int len;
+	/* 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
+	 */
 
+	unsigned short 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, 26);
 
 	cmd = skb_put_zero(skb, len);
 	memcpy(&cmd->mfr_id, nca->data, nca->payload);
@@ -272,6 +276,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 +286,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, 26);
 
 	/* Allocate skb */
 	skb = alloc_skb(len, GFP_ATOMIC);
-- 
2.17.1


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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
  2021-10-28  9:50 [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets Kumar Thangavel
@ 2021-11-03 15:11 ` Kumar Thangavel
  2021-11-03 15:49   ` Jakub Kicinski
  0 siblings, 1 reply; 16+ messages in thread
From: Kumar Thangavel @ 2021-11-03 15:11 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S. Miller, Jakub Kicinski
  Cc: linux-aspeed, OpenBMC Maillist, Amithash Prasad, velumanit, patrickw3

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

Hi All,

    Could you please review the patch and provide your feedback?

Thanks,
Kumar.

On Thu, Oct 28, 2021 at 3:20 PM Kumar Thangavel <
kumarthangavel.hcl@gmail.com> 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.
>
> 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>
>
> ---
>   v4:
>    - Updated 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 | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
> index ba9ae482141b..e44fe138c20f 100644
> --- a/net/ncsi/ncsi-cmd.c
> +++ b/net/ncsi/ncsi-cmd.c
> @@ -213,12 +213,16 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb,
>  {
>         struct ncsi_cmd_oem_pkt *cmd;
>         unsigned int len;
> +       /* 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
> +        */
>
> +       unsigned short 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, 26);
>
>         cmd = skb_put_zero(skb, len);
>         memcpy(&cmd->mfr_id, nca->data, nca->payload);
> @@ -272,6 +276,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 +286,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, 26);
>
>         /* Allocate skb */
>         skb = alloc_skb(len, GFP_ATOMIC);
> --
> 2.17.1
>
>

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

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
  2021-11-03 15:11 ` Kumar Thangavel
@ 2021-11-03 15:49   ` Jakub Kicinski
  2021-11-03 16:13     ` Kumar Thangavel
  0 siblings, 1 reply; 16+ messages in thread
From: Jakub Kicinski @ 2021-11-03 15:49 UTC (permalink / raw)
  To: Kumar Thangavel
  Cc: linux-aspeed, OpenBMC Maillist, Amithash Prasad, patrickw3,
	Samuel Mendoza-Jonas, velumanit, David S. Miller

On Wed, 3 Nov 2021 20:41:56 +0530 Kumar Thangavel wrote:
>     Could you please review the patch and provide your feedback?

You missed CCing netdev@ again. You need to CC the mailing list 
to get the patch considered for merging.

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
  2021-11-03 15:49   ` Jakub Kicinski
@ 2021-11-03 16:13     ` Kumar Thangavel
  2021-11-03 16:16       ` Jakub Kicinski
  0 siblings, 1 reply; 16+ messages in thread
From: Kumar Thangavel @ 2021-11-03 16:13 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: linux-aspeed, OpenBMC Maillist, Amithash Prasad, patrickw3,
	Samuel Mendoza-Jonas, velumanit, David S. Miller

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

Hi Jakub,

Thanks for your response.

Somehow, My mails are not delivered to netdev@vger.kernel.org.

So, I removed it in my last 2 patchsets.

I will try again to CCing netdev@vger.kernel.org.

Thanks,
Kumar.



On Wed, Nov 3, 2021 at 9:19 PM Jakub Kicinski <kuba@kernel.org> wrote:

> On Wed, 3 Nov 2021 20:41:56 +0530 Kumar Thangavel wrote:
> >     Could you please review the patch and provide your feedback?
>
> You missed CCing netdev@ again. You need to CC the mailing list
> to get the patch considered for merging.
>

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

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
  2021-11-03 16:13     ` Kumar Thangavel
@ 2021-11-03 16:16       ` Jakub Kicinski
  2021-11-03 16:37         ` Kumar Thangavel
  0 siblings, 1 reply; 16+ messages in thread
From: Jakub Kicinski @ 2021-11-03 16:16 UTC (permalink / raw)
  To: Kumar Thangavel
  Cc: linux-aspeed, OpenBMC Maillist, Amithash Prasad, patrickw3,
	Samuel Mendoza-Jonas, velumanit, David S. Miller

On Wed, 3 Nov 2021 21:43:03 +0530 Kumar Thangavel wrote:
> Hi Jakub,
> 
> Thanks for your response.
> 
> Somehow, My mails are not delivered to netdev@vger.kernel.org.
> 
> So, I removed it in my last 2 patchsets.
> 
> I will try again to CCing netdev@vger.kernel.org.

For normal replies you need to use plain text, not HTML. The mailing
list rejects HTML emails. But the patch should go thru, we'll see.

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
  2021-11-03 16:16       ` Jakub Kicinski
@ 2021-11-03 16:37         ` Kumar Thangavel
  0 siblings, 0 replies; 16+ messages in thread
From: Kumar Thangavel @ 2021-11-03 16:37 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: linux-aspeed, OpenBMC Maillist, Amithash Prasad, patrickw3,
	Samuel Mendoza-Jonas, velumanit, David S. Miller

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

Ok Sure Jakub.

Thanks,
Kumar.

On Wed, Nov 3, 2021 at 9:46 PM Jakub Kicinski <kuba@kernel.org> wrote:

> On Wed, 3 Nov 2021 21:43:03 +0530 Kumar Thangavel wrote:
> > Hi Jakub,
> >
> > Thanks for your response.
> >
> > Somehow, My mails are not delivered to netdev@vger.kernel.org.
> >
> > So, I removed it in my last 2 patchsets.
> >
> > I will try again to CCing netdev@vger.kernel.org.
>
> For normal replies you need to use plain text, not HTML. The mailing
> list rejects HTML emails. But the patch should go thru, we'll see.
>

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

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
  2021-11-10  9:54 ` Kumar Thangavel
  (?)
@ 2021-11-15  5:28   ` kernel test robot
  -1 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2021-11-15  5:28 UTC (permalink / raw)
  To: Kumar Thangavel, Samuel Mendoza-Jonas, David S. Miller, Jakub Kicinski
  Cc: llvm, kbuild-all, netdev, openbmc, linux-aspeed, patrickw3,
	Amithash Prasad, velumanit, sdasari

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

Hi Kumar,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.16-rc1 next-20211115]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git cb690f5238d71f543f4ce874aa59237cf53a877c
config: riscv-buildonly-randconfig-r006-20211115 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project fbe72e41b99dc7994daac300d208a955be3e4a0a)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install riscv cross compiling tool for clang build
        # apt-get install binutils-riscv64-linux-gnu
        # https://github.com/0day-ci/linux/commit/263eaf647698f405f4f9905c947bf73b87c55b79
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
        git checkout 263eaf647698f405f4f9905c947bf73b87c55b79
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=riscv 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> net/ncsi/ncsi-cmd.c:225:9: warning: comparison of distinct pointer types ('typeof (payload) *' (aka 'unsigned short *') and 'typeof (26) *' (aka 'int *')) [-Wcompare-distinct-pointer-types]
           len += max(payload, 26);
                  ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:52:19: note: expanded from macro 'max'
   #define max(x, y)       __careful_cmp(x, y, >)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
           __builtin_choose_expr(__safe_cmp(x, y), \
                                 ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
                   (__typecheck(x, y) && __no_side_effects(x, y))
                    ^~~~~~~~~~~~~~~~~
   include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
           (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                      ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
   1 warning generated.


vim +225 net/ncsi/ncsi-cmd.c

   210	
   211	static int ncsi_cmd_handler_oem(struct sk_buff *skb,
   212					struct ncsi_cmd_arg *nca)
   213	{
   214		struct ncsi_cmd_oem_pkt *cmd;
   215		unsigned int len;
   216		/* NC-SI spec DSP_0222_1.2.0, section 8.2.2.2
   217		 * requires payload to be padded with 0 to
   218		 * 32-bit boundary before the checksum field.
   219		 * Ensure the padding bytes are accounted for in
   220		 * skb allocation
   221		 */
   222	
   223		unsigned short payload = ALIGN(nca->payload, 4);
   224		len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
 > 225		len += max(payload, 26);
   226	
   227		cmd = skb_put_zero(skb, len);
   228		memcpy(&cmd->mfr_id, nca->data, nca->payload);
   229		ncsi_cmd_build_header(&cmd->cmd.common, nca);
   230	
   231		return 0;
   232	}
   233	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32159 bytes --]

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
@ 2021-11-15  5:28   ` kernel test robot
  0 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2021-11-15  5:28 UTC (permalink / raw)
  To: Kumar Thangavel, Samuel Mendoza-Jonas, David S. Miller, Jakub Kicinski
  Cc: kbuild-all, linux-aspeed, netdev, openbmc, llvm, Amithash Prasad,
	velumanit, patrickw3

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

Hi Kumar,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.16-rc1 next-20211115]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git cb690f5238d71f543f4ce874aa59237cf53a877c
config: riscv-buildonly-randconfig-r006-20211115 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project fbe72e41b99dc7994daac300d208a955be3e4a0a)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install riscv cross compiling tool for clang build
        # apt-get install binutils-riscv64-linux-gnu
        # https://github.com/0day-ci/linux/commit/263eaf647698f405f4f9905c947bf73b87c55b79
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
        git checkout 263eaf647698f405f4f9905c947bf73b87c55b79
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=riscv 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> net/ncsi/ncsi-cmd.c:225:9: warning: comparison of distinct pointer types ('typeof (payload) *' (aka 'unsigned short *') and 'typeof (26) *' (aka 'int *')) [-Wcompare-distinct-pointer-types]
           len += max(payload, 26);
                  ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:52:19: note: expanded from macro 'max'
   #define max(x, y)       __careful_cmp(x, y, >)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
           __builtin_choose_expr(__safe_cmp(x, y), \
                                 ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
                   (__typecheck(x, y) && __no_side_effects(x, y))
                    ^~~~~~~~~~~~~~~~~
   include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
           (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                      ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
   1 warning generated.


vim +225 net/ncsi/ncsi-cmd.c

   210	
   211	static int ncsi_cmd_handler_oem(struct sk_buff *skb,
   212					struct ncsi_cmd_arg *nca)
   213	{
   214		struct ncsi_cmd_oem_pkt *cmd;
   215		unsigned int len;
   216		/* NC-SI spec DSP_0222_1.2.0, section 8.2.2.2
   217		 * requires payload to be padded with 0 to
   218		 * 32-bit boundary before the checksum field.
   219		 * Ensure the padding bytes are accounted for in
   220		 * skb allocation
   221		 */
   222	
   223		unsigned short payload = ALIGN(nca->payload, 4);
   224		len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
 > 225		len += max(payload, 26);
   226	
   227		cmd = skb_put_zero(skb, len);
   228		memcpy(&cmd->mfr_id, nca->data, nca->payload);
   229		ncsi_cmd_build_header(&cmd->cmd.common, nca);
   230	
   231		return 0;
   232	}
   233	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32159 bytes --]

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
@ 2021-11-15  5:28   ` kernel test robot
  0 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2021-11-15  5:28 UTC (permalink / raw)
  To: kbuild-all

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

Hi Kumar,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.16-rc1 next-20211115]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git cb690f5238d71f543f4ce874aa59237cf53a877c
config: riscv-buildonly-randconfig-r006-20211115 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project fbe72e41b99dc7994daac300d208a955be3e4a0a)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install riscv cross compiling tool for clang build
        # apt-get install binutils-riscv64-linux-gnu
        # https://github.com/0day-ci/linux/commit/263eaf647698f405f4f9905c947bf73b87c55b79
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
        git checkout 263eaf647698f405f4f9905c947bf73b87c55b79
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=riscv 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> net/ncsi/ncsi-cmd.c:225:9: warning: comparison of distinct pointer types ('typeof (payload) *' (aka 'unsigned short *') and 'typeof (26) *' (aka 'int *')) [-Wcompare-distinct-pointer-types]
           len += max(payload, 26);
                  ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:52:19: note: expanded from macro 'max'
   #define max(x, y)       __careful_cmp(x, y, >)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
           __builtin_choose_expr(__safe_cmp(x, y), \
                                 ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
                   (__typecheck(x, y) && __no_side_effects(x, y))
                    ^~~~~~~~~~~~~~~~~
   include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
           (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                      ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
   1 warning generated.


vim +225 net/ncsi/ncsi-cmd.c

   210	
   211	static int ncsi_cmd_handler_oem(struct sk_buff *skb,
   212					struct ncsi_cmd_arg *nca)
   213	{
   214		struct ncsi_cmd_oem_pkt *cmd;
   215		unsigned int len;
   216		/* NC-SI spec DSP_0222_1.2.0, section 8.2.2.2
   217		 * requires payload to be padded with 0 to
   218		 * 32-bit boundary before the checksum field.
   219		 * Ensure the padding bytes are accounted for in
   220		 * skb allocation
   221		 */
   222	
   223		unsigned short payload = ALIGN(nca->payload, 4);
   224		len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
 > 225		len += max(payload, 26);
   226	
   227		cmd = skb_put_zero(skb, len);
   228		memcpy(&cmd->mfr_id, nca->data, nca->payload);
   229		ncsi_cmd_build_header(&cmd->cmd.common, nca);
   230	
   231		return 0;
   232	}
   233	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 32159 bytes --]

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
  2021-11-10  9:54 ` Kumar Thangavel
  (?)
@ 2021-11-12  3:32   ` kernel test robot
  -1 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2021-11-12  3:32 UTC (permalink / raw)
  To: Kumar Thangavel, Samuel Mendoza-Jonas, David S. Miller, Jakub Kicinski
  Cc: llvm, kbuild-all, netdev, openbmc, linux-aspeed, patrickw3,
	Amithash Prasad, velumanit, sdasari

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

Hi Kumar,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.15 next-20211111]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git cb690f5238d71f543f4ce874aa59237cf53a877c
config: hexagon-buildonly-randconfig-r006-20211112 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 63ef0e17e28827eae53133b3467bdac7d9729318)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/263eaf647698f405f4f9905c947bf73b87c55b79
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
        git checkout 263eaf647698f405f4f9905c947bf73b87c55b79
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=hexagon 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> net/ncsi/ncsi-cmd.c:225:9: error: comparison of distinct pointer types ('typeof (payload) *' (aka 'unsigned short *') and 'typeof (26) *' (aka 'int *')) [-Werror,-Wcompare-distinct-pointer-types]
           len += max(payload, 26);
                  ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:52:19: note: expanded from macro 'max'
   #define max(x, y)       __careful_cmp(x, y, >)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
           __builtin_choose_expr(__safe_cmp(x, y), \
                                 ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
                   (__typecheck(x, y) && __no_side_effects(x, y))
                    ^~~~~~~~~~~~~~~~~
   include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
           (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                      ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
   1 error generated.


vim +225 net/ncsi/ncsi-cmd.c

   210	
   211	static int ncsi_cmd_handler_oem(struct sk_buff *skb,
   212					struct ncsi_cmd_arg *nca)
   213	{
   214		struct ncsi_cmd_oem_pkt *cmd;
   215		unsigned int len;
   216		/* NC-SI spec DSP_0222_1.2.0, section 8.2.2.2
   217		 * requires payload to be padded with 0 to
   218		 * 32-bit boundary before the checksum field.
   219		 * Ensure the padding bytes are accounted for in
   220		 * skb allocation
   221		 */
   222	
   223		unsigned short payload = ALIGN(nca->payload, 4);
   224		len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
 > 225		len += max(payload, 26);
   226	
   227		cmd = skb_put_zero(skb, len);
   228		memcpy(&cmd->mfr_id, nca->data, nca->payload);
   229		ncsi_cmd_build_header(&cmd->cmd.common, nca);
   230	
   231		return 0;
   232	}
   233	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33648 bytes --]

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
@ 2021-11-12  3:32   ` kernel test robot
  0 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2021-11-12  3:32 UTC (permalink / raw)
  To: Kumar Thangavel, Samuel Mendoza-Jonas, David S. Miller, Jakub Kicinski
  Cc: kbuild-all, linux-aspeed, netdev, openbmc, llvm, Amithash Prasad,
	velumanit, patrickw3

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

Hi Kumar,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.15 next-20211111]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git cb690f5238d71f543f4ce874aa59237cf53a877c
config: hexagon-buildonly-randconfig-r006-20211112 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 63ef0e17e28827eae53133b3467bdac7d9729318)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/263eaf647698f405f4f9905c947bf73b87c55b79
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
        git checkout 263eaf647698f405f4f9905c947bf73b87c55b79
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=hexagon 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> net/ncsi/ncsi-cmd.c:225:9: error: comparison of distinct pointer types ('typeof (payload) *' (aka 'unsigned short *') and 'typeof (26) *' (aka 'int *')) [-Werror,-Wcompare-distinct-pointer-types]
           len += max(payload, 26);
                  ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:52:19: note: expanded from macro 'max'
   #define max(x, y)       __careful_cmp(x, y, >)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
           __builtin_choose_expr(__safe_cmp(x, y), \
                                 ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
                   (__typecheck(x, y) && __no_side_effects(x, y))
                    ^~~~~~~~~~~~~~~~~
   include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
           (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                      ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
   1 error generated.


vim +225 net/ncsi/ncsi-cmd.c

   210	
   211	static int ncsi_cmd_handler_oem(struct sk_buff *skb,
   212					struct ncsi_cmd_arg *nca)
   213	{
   214		struct ncsi_cmd_oem_pkt *cmd;
   215		unsigned int len;
   216		/* NC-SI spec DSP_0222_1.2.0, section 8.2.2.2
   217		 * requires payload to be padded with 0 to
   218		 * 32-bit boundary before the checksum field.
   219		 * Ensure the padding bytes are accounted for in
   220		 * skb allocation
   221		 */
   222	
   223		unsigned short payload = ALIGN(nca->payload, 4);
   224		len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
 > 225		len += max(payload, 26);
   226	
   227		cmd = skb_put_zero(skb, len);
   228		memcpy(&cmd->mfr_id, nca->data, nca->payload);
   229		ncsi_cmd_build_header(&cmd->cmd.common, nca);
   230	
   231		return 0;
   232	}
   233	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33648 bytes --]

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
@ 2021-11-12  3:32   ` kernel test robot
  0 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2021-11-12  3:32 UTC (permalink / raw)
  To: kbuild-all

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

Hi Kumar,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.15 next-20211111]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git cb690f5238d71f543f4ce874aa59237cf53a877c
config: hexagon-buildonly-randconfig-r006-20211112 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 63ef0e17e28827eae53133b3467bdac7d9729318)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/263eaf647698f405f4f9905c947bf73b87c55b79
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kumar-Thangavel/Add-payload-to-be-32-bit-aligned-to-fix-dropped-packets/20211110-175537
        git checkout 263eaf647698f405f4f9905c947bf73b87c55b79
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=hexagon 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> net/ncsi/ncsi-cmd.c:225:9: error: comparison of distinct pointer types ('typeof (payload) *' (aka 'unsigned short *') and 'typeof (26) *' (aka 'int *')) [-Werror,-Wcompare-distinct-pointer-types]
           len += max(payload, 26);
                  ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:52:19: note: expanded from macro 'max'
   #define max(x, y)       __careful_cmp(x, y, >)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
           __builtin_choose_expr(__safe_cmp(x, y), \
                                 ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
                   (__typecheck(x, y) && __no_side_effects(x, y))
                    ^~~~~~~~~~~~~~~~~
   include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
           (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                      ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
   1 error generated.


vim +225 net/ncsi/ncsi-cmd.c

   210	
   211	static int ncsi_cmd_handler_oem(struct sk_buff *skb,
   212					struct ncsi_cmd_arg *nca)
   213	{
   214		struct ncsi_cmd_oem_pkt *cmd;
   215		unsigned int len;
   216		/* NC-SI spec DSP_0222_1.2.0, section 8.2.2.2
   217		 * requires payload to be padded with 0 to
   218		 * 32-bit boundary before the checksum field.
   219		 * Ensure the padding bytes are accounted for in
   220		 * skb allocation
   221		 */
   222	
   223		unsigned short payload = ALIGN(nca->payload, 4);
   224		len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
 > 225		len += max(payload, 26);
   226	
   227		cmd = skb_put_zero(skb, len);
   228		memcpy(&cmd->mfr_id, nca->data, nca->payload);
   229		ncsi_cmd_build_header(&cmd->cmd.common, nca);
   230	
   231		return 0;
   232	}
   233	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 33648 bytes --]

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
  2021-11-10  9:54 ` Kumar Thangavel
@ 2021-11-10 13:58   ` Denis Kirjanov
  -1 siblings, 0 replies; 16+ messages in thread
From: Denis Kirjanov @ 2021-11-10 13:58 UTC (permalink / raw)
  To: Kumar Thangavel, Samuel Mendoza-Jonas, David S. Miller, Jakub Kicinski
  Cc: openbmc, linux-aspeed, patrickw3, Amithash Prasad, velumanit,
	sdasari, netdev



11/10/21 12:54 PM, Kumar Thangavel пишет:
> 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.

Please add Fixes tag
> 
> 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>
> 
> ---
>    v4:
>     - Updated 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 | 21 +++++++++++++--------
>   1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
> index ba9ae482141b..e44fe138c20f 100644
> --- a/net/ncsi/ncsi-cmd.c
> +++ b/net/ncsi/ncsi-cmd.c
> @@ -213,12 +213,16 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb,
>   {
>   	struct ncsi_cmd_oem_pkt *cmd;
>   	unsigned int len;
> +	/* 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
> +	 */
>   
> +	unsigned short payload = ALIGN(nca->payload, 4);
>   	len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
> -	if (nca->payload < 26)
> -		len += 26;
Would be nice to have a constant
> -	else
> -		len += nca->payload;
> +	len += max(payload, 26);
>   
>   	cmd = skb_put_zero(skb, len);
>   	memcpy(&cmd->mfr_id, nca->data, nca->payload);
> @@ -272,6 +276,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 +286,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, 26);
>   
>   	/* Allocate skb */
>   	skb = alloc_skb(len, GFP_ATOMIC);
> 

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

* Re: [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
@ 2021-11-10 13:58   ` Denis Kirjanov
  0 siblings, 0 replies; 16+ messages in thread
From: Denis Kirjanov @ 2021-11-10 13:58 UTC (permalink / raw)
  To: Kumar Thangavel, Samuel Mendoza-Jonas, David S. Miller, Jakub Kicinski
  Cc: linux-aspeed, netdev, openbmc, Amithash Prasad, velumanit, patrickw3



11/10/21 12:54 PM, Kumar Thangavel пишет:
> 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.

Please add Fixes tag
> 
> 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>
> 
> ---
>    v4:
>     - Updated 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 | 21 +++++++++++++--------
>   1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
> index ba9ae482141b..e44fe138c20f 100644
> --- a/net/ncsi/ncsi-cmd.c
> +++ b/net/ncsi/ncsi-cmd.c
> @@ -213,12 +213,16 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb,
>   {
>   	struct ncsi_cmd_oem_pkt *cmd;
>   	unsigned int len;
> +	/* 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
> +	 */
>   
> +	unsigned short payload = ALIGN(nca->payload, 4);
>   	len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
> -	if (nca->payload < 26)
> -		len += 26;
Would be nice to have a constant
> -	else
> -		len += nca->payload;
> +	len += max(payload, 26);
>   
>   	cmd = skb_put_zero(skb, len);
>   	memcpy(&cmd->mfr_id, nca->data, nca->payload);
> @@ -272,6 +276,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 +286,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, 26);
>   
>   	/* Allocate skb */
>   	skb = alloc_skb(len, GFP_ATOMIC);
> 

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

* [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
@ 2021-11-10  9:54 ` Kumar Thangavel
  0 siblings, 0 replies; 16+ messages in thread
From: Kumar Thangavel @ 2021-11-10  9:54 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S. Miller, Jakub Kicinski
  Cc: openbmc, linux-aspeed, patrickw3, Amithash Prasad, velumanit,
	sdasari, netdev

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.

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>

---
  v4:
   - Updated 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 | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
index ba9ae482141b..e44fe138c20f 100644
--- a/net/ncsi/ncsi-cmd.c
+++ b/net/ncsi/ncsi-cmd.c
@@ -213,12 +213,16 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb,
 {
 	struct ncsi_cmd_oem_pkt *cmd;
 	unsigned int len;
+	/* 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
+	 */
 
+	unsigned short 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, 26);
 
 	cmd = skb_put_zero(skb, len);
 	memcpy(&cmd->mfr_id, nca->data, nca->payload);
@@ -272,6 +276,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 +286,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, 26);
 
 	/* Allocate skb */
 	skb = alloc_skb(len, GFP_ATOMIC);
-- 
2.17.1


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

* [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets
@ 2021-11-10  9:54 ` Kumar Thangavel
  0 siblings, 0 replies; 16+ messages in thread
From: Kumar Thangavel @ 2021-11-10  9:54 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.

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>

---
  v4:
   - Updated 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 | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
index ba9ae482141b..e44fe138c20f 100644
--- a/net/ncsi/ncsi-cmd.c
+++ b/net/ncsi/ncsi-cmd.c
@@ -213,12 +213,16 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb,
 {
 	struct ncsi_cmd_oem_pkt *cmd;
 	unsigned int len;
+	/* 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
+	 */
 
+	unsigned short 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, 26);
 
 	cmd = skb_put_zero(skb, len);
 	memcpy(&cmd->mfr_id, nca->data, nca->payload);
@@ -272,6 +276,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 +286,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, 26);
 
 	/* Allocate skb */
 	skb = alloc_skb(len, GFP_ATOMIC);
-- 
2.17.1


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

end of thread, other threads:[~2021-11-15  5:33 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-28  9:50 [PATCH v4] Add payload to be 32-bit aligned to fix dropped packets Kumar Thangavel
2021-11-03 15:11 ` Kumar Thangavel
2021-11-03 15:49   ` Jakub Kicinski
2021-11-03 16:13     ` Kumar Thangavel
2021-11-03 16:16       ` Jakub Kicinski
2021-11-03 16:37         ` Kumar Thangavel
2021-11-10  9:54 Kumar Thangavel
2021-11-10  9:54 ` Kumar Thangavel
2021-11-10 13:58 ` Denis Kirjanov
2021-11-10 13:58   ` Denis Kirjanov
2021-11-12  3:32 ` kernel test robot
2021-11-12  3:32   ` kernel test robot
2021-11-12  3:32   ` kernel test robot
2021-11-15  5:28 ` kernel test robot
2021-11-15  5:28   ` kernel test robot
2021-11-15  5:28   ` kernel test robot

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.