From patchwork Thu Feb 2 20:23:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 52161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp461763wrn; Thu, 2 Feb 2023 12:40:03 -0800 (PST) X-Google-Smtp-Source: AK7set8cjTibsOdP6uwlXATagGdVKZ3cnlGU0xUuD2AQ0H9ozZaW3R+zDPpu27bzt+EnyrYhiZVt X-Received: by 2002:a17:906:694c:b0:878:4cb8:3b2e with SMTP id c12-20020a170906694c00b008784cb83b2emr7614470ejs.16.1675370403053; Thu, 02 Feb 2023 12:40:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675370403; cv=none; d=google.com; s=arc-20160816; b=iP96Z35W3GsNiX8RV0pOTwHuQThKrDvLE6+xj05nST8St+jxgJj/hk1urn8bY+i0+s yAuf1teqPaCgz3Wx3pP6LPrtHin2Isa2yr6udlkowJLsaf8gBUN1ZKyCXHGUvkeZDKI7 j/P1/SH23XvlfOC6/a17Z74MmaazrLQWqkdT+avoEX8pXkLAFM/P549DavoXzIMKKIi4 xBy41eEbqakUgb5pHMbtL0EXsGLCFtKs1CHU6QKpDKPqGVYZZ0SJRm9evxhv5OY+9+r5 NJvTrDvaEsrJ/vRNu2omsFaVAkGDkOAPUeKcg2BLrTSzJWMZts9uVT7JbXj4HhKvHt72 2U5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=AqT2I7zNHEL1VtPxki6H+IJG9woM+cBYeWDvAxR4xAM=; b=Mc25QmWlyUHYzYYt12gGNuKDpi5GpGO0NQOrmuPPy5+xYcspf06bPQABbl9N/94KpO 78w7qmZR7oFo9GSmimHQ2Er3uUp5TlakfVah2OL5oC0zo3vJ3oOHdjEvLSvz53r0WS70 ynekP305uZ2+3niU7GPgQFqGiA5VAz2M1a5kKW/R68HSIYRDSCBGvTf6sDheDigBLoGx URitdyq6gNZUrwZHbrqAmML7w9tR+eb1xKhDsMC0V7klTuDFu/CjcqWE1uStN+N+Mh3x dojflIVLgblGDNti2RDDkGQ/9QZhBmqHBNSEgGuGhnoZe+YKywL+FtuRpvCjJt+LfUIx 3NcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a170907915300b0087c772e91b1si487396ejs.473.2023.02.02.12.39.38; Thu, 02 Feb 2023 12:40:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232852AbjBBUXm (ORCPT + 99 others); Thu, 2 Feb 2023 15:23:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbjBBUXj (ORCPT ); Thu, 2 Feb 2023 15:23:39 -0500 Received: from smtp.smtpout.orange.fr (smtp-14.smtpout.orange.fr [80.12.242.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9362B6DFFD for ; Thu, 2 Feb 2023 12:23:35 -0800 (PST) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id Ng7FpzaaXkc0dNg7FpPXWm; Thu, 02 Feb 2023 21:23:32 +0100 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Thu, 02 Feb 2023 21:23:32 +0100 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Mustafa Ismail , Shiraz Saleem , Jason Gunthorpe , Leon Romanovsky Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-rdma@vger.kernel.org Subject: [PATCH] RDMA/irdma: Slightly optimize irdma_form_ah_cm_frame() Date: Thu, 2 Feb 2023 21:23:24 +0100 Message-Id: <098e3c397be0436f1867899245ecfe656c472110.1675369386.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756753195520194326?= X-GMAIL-MSGID: =?utf-8?q?1756753195520194326?= There is no need to zero 'pktsize' bytes of 'buf', only the header needs to be cleared, to be safe. All the other bytes are already written with some memcpy() at the end of the function. Doing so also gives the opportunity to the compiler to avoid the memset() call. It can be inlined now that the length is known as compile time. Signed-off-by: Christophe JAILLET Reviewed-by: Shiraz Saleem --- Just in case, here is the diff of what is generated by gcc 11.3.0 before and after the patch. .L736: -# drivers/infiniband/hw/irdma/cm.c:340: memset(buf, 0, pktsize); +# drivers/infiniband/hw/irdma/cm.c:340: memset(buf, 0, sizeof(*tcph)); call __sanitizer_cov_trace_pc # - xorl %esi, %esi # - movzwl %r13w, %edx # _194, __fortify_size - movq %rbp, %rdi # buf, - call memset # - leaq 104(%r12), %rax #, _259 + movl $0, 16(%rbp) #, MEM [(void *)buf_114] + leaq 104(%r12), %rax #, _295 +# drivers/infiniband/hw/irdma/cm.c:342: sqbuf->totallen = pktsize; + movzwl %r13w, %r13d # _192, _192 +# drivers/infiniband/hw/irdma/cm.c:340: memset(buf, 0, sizeof(*tcph)); + movq $0, 0(%rbp) #, MEM [(void *)buf_114] +# drivers/infiniband/hw/irdma/cm.c:342: sqbuf->totallen = pktsize; + movq %rax, %rdi # _295, +# drivers/infiniband/hw/irdma/cm.c:340: memset(buf, 0, sizeof(*tcph)); + movq $0, 8(%rbp) #, MEM [(void *)buf_114] + movq %rax, 64(%rsp) # _295, %sfp # drivers/infiniband/hw/irdma/cm.c:342: sqbuf->totallen = pktsize; --- drivers/infiniband/hw/irdma/cm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/irdma/cm.c b/drivers/infiniband/hw/irdma/cm.c index 195aa9ea18b6..48c2a303e9ec 100644 --- a/drivers/infiniband/hw/irdma/cm.c +++ b/drivers/infiniband/hw/irdma/cm.c @@ -337,7 +337,7 @@ static struct irdma_puda_buf *irdma_form_ah_cm_frame(struct irdma_cm_node *cm_no pktsize = sizeof(*tcph) + opts_len + hdr_len + pd_len; - memset(buf, 0, pktsize); + memset(buf, 0, sizeof(*tcph)); sqbuf->totallen = pktsize; sqbuf->tcphlen = sizeof(*tcph) + opts_len;