From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DD01C433F5 for ; Wed, 17 Nov 2021 07:56:09 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AA9C161BD2 for ; Wed, 17 Nov 2021 07:56:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AA9C161BD2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HvFc70BXwz2yP5 for ; Wed, 17 Nov 2021 18:56:07 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Dtqz9Zpl; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1029; helo=mail-pj1-x1029.google.com; envelope-from=kumarthangavel.hcl@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Dtqz9Zpl; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4HvFbL0vd2z2yNW; Wed, 17 Nov 2021 18:55:23 +1100 (AEDT) Received: by mail-pj1-x1029.google.com with SMTP id fv9-20020a17090b0e8900b001a6a5ab1392so1873391pjb.1; Tue, 16 Nov 2021 23:55:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=sMn+kSB0SMtbbATrssAZXo2j9mtwfINp7shAhK0Hg3Q=; b=Dtqz9Zpll3J6Dmv7AZRqvZ1dam1bRud/Q/5TkSCwzoe2rImvngB+rdOX59L8zxUKue kBqSdWdc6ZV/ycLotIthDYezPOMReEBTfSTUtlPfHTyMN433WYBggGnPIUU6ao4dNA9u TyM9GFBvuaaO5/9bZ+N7E/XlgoZh8WY6yGJ7f1lmYpvgUPcIhhJTGhcY9l6slzZj52uA uWRx3tKebh6HnW8EM7U4oC/eO9UDefOlQuSZ6F4pmNZxFNBYnIP/B+bSHUbgDGT0M1eu xBnfQ5MvbzWzhJhsc1ZAiRhP/ZZa9yeP1f4ek39DV6AVUQQ02DBUqhI4FHSGAWmd1PeU JHtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=sMn+kSB0SMtbbATrssAZXo2j9mtwfINp7shAhK0Hg3Q=; b=fiEmnGQMuhVSlLaO64Cuf2oCJ+9njIPRU+0ZoUJdpOGf1Eojo2yr8gKPxqlPiLHdPt R05eWBgYe/RXN9KdcsoF1g9tWFOgnPpMBCmuC2Trzccjp1UlK7Vuy6qicJhJukqsEQOZ OLGv/bk/v87hLUYYseqBEMEaGKgbfmxgBhc2+FRTzRnrtm698Px29Hz3amcjvUm14Mn5 E9cBi+HTudA3ingBYQX6GOUyNS/f1ADQo57lIQL/3bASbyjldMo5CD7yuHnhY7AT/vWQ SkPA0AVE/oPHn7Tiu5VjZCiMcA/CtKkYNBc22pGRQKKbuPKi4/i/ZiGoeyM+SRm8Awik 3g+A== X-Gm-Message-State: AOAM532emcoxajhwl9Ci29O1GXJQk1L541LnafMz9FOjHLsnPUWShbQo kMqWZdLiKIptRHiXPg0OX7I= X-Google-Smtp-Source: ABdhPJyApPE4b+5l7e4PSnCiyjleMBXoErF+yJ9jBacOCYdXaAkKP6/njIkHGl/3u7f5L7TdRqWQQg== X-Received: by 2002:a17:90b:3ec6:: with SMTP id rm6mr7136137pjb.41.1637135720945; Tue, 16 Nov 2021 23:55:20 -0800 (PST) Received: from gmail.com ([117.217.177.105]) by smtp.gmail.com with ESMTPSA id ls14sm4862214pjb.49.2021.11.16.23.55.16 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Nov 2021 23:55:20 -0800 (PST) From: Kumar Thangavel X-Google-Original-From: Kumar Thangavel Date: Wed, 17 Nov 2021 13:25:13 +0530 To: Samuel Mendoza-Jonas , "David S. Miller" , Jakub Kicinski Subject: [PATCH v6] Add payload to be 32-bit aligned to fix dropped packets Message-ID: <20211117075513.GA12199@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-aspeed@lists.ozlabs.org, netdev@vger.kernel.org, openbmc@lists.ozlabs.org, Amithash Prasad , velumanit@hcl.com, patrickw3@fb.com Errors-To: openbmc-bounces+openbmc=archiver.kernel.org@lists.ozlabs.org Sender: "openbmc" 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 Acked-by: Samuel Mendoza-Jonas Reviewed-by: Paul Menzel --- v6: - Updated type of padding_bytes variable - Updated type of payload variable - 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..78376d88e788 100644 --- a/net/ncsi/ncsi-cmd.c +++ b/net/ncsi/ncsi-cmd.c @@ -18,6 +18,8 @@ #include "internal.h" #include "ncsi-pkt.h" +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