From patchwork Wed May 12 03:27:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 12252617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09868C433ED for ; Wed, 12 May 2021 03:28:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD286613C8 for ; Wed, 12 May 2021 03:28:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229952AbhELD3J (ORCPT ); Tue, 11 May 2021 23:29:09 -0400 Received: from mail-pg1-f178.google.com ([209.85.215.178]:47089 "EHLO mail-pg1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbhELD3J (ORCPT ); Tue, 11 May 2021 23:29:09 -0400 Received: by mail-pg1-f178.google.com with SMTP id m124so17167910pgm.13 for ; Tue, 11 May 2021 20:28:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PpfFDOKdUbD020JfVQyuA+Evu+NBA9JdyPd4651AemA=; b=bccem2BgcaVMkmiJaVHbQv61olmIJXZSr/fiBLnLg0hBcd8/AAB+Oj9zXjJ4szfLwd iXxi9oXcrV+iBRkeWNp7EKdgOzkbK9HagLuSIozuTNz5GACPqzf1xhE297YH0q4rqtj9 zKrcqxdhfSlxg/6mgA0mN8UNo50vi+qBczE6Nw834Vb8LBoDKT+8u+2N+h/qK8ZPWsa4 pnTjNqMfLhv83vx418YDFAV+n4Gxg0QcgZYZAjn0LzKT6SAikKkiRlkjws1H5oYto/Rx kXPm3sF2YX98PqKs8IAUAvBFVqj34ewal+ZAM2HRTmb1CCQ+pIUGIYY1XQ8+nZhvoIaS 44vw== X-Gm-Message-State: AOAM531AG2JFr+2KZp8lPE23N/MK8vdihbFB/4nNYVadxvGur/+ptdGN 2WwCeCvRhKQtwZFRTUgmC7s= X-Google-Smtp-Source: ABdhPJw1FpFjUBzhLdiVoYSRbb3FiXaD5zBPNUjYWD86RH/rH9Tzn3CJh8IDF90WeDgqNS3uh4CO8g== X-Received: by 2002:a05:6a00:b8c:b029:28e:eb6c:ea52 with SMTP id g12-20020a056a000b8cb029028eeb6cea52mr34460465pfj.21.1620790080579; Tue, 11 May 2021 20:28:00 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:76b9:3c77:17e3:3073]) by smtp.gmail.com with ESMTPSA id q194sm15008703pfc.62.2021.05.11.20.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 20:28:00 -0700 (PDT) From: Bart Van Assche To: Jason Gunthorpe Cc: Leon Romanovsky , Doug Ledford , linux-rdma@vger.kernel.org, Bart Van Assche , Don Hiatt , Dennis Dalessandro Subject: [PATCH 1/5] RDMA/ib_hdrs.h: Remove a superfluous cast Date: Tue, 11 May 2021 20:27:48 -0700 Message-Id: <20210512032752.16611-2-bvanassche@acm.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512032752.16611-1-bvanassche@acm.org> References: <20210512032752.16611-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org be16_to_cpu() returns a u16 value. Remove the superfluous u16 cast. That cast was introduced by commit 7dafbab3753f ("IB/hfi1: Add functions to parse BTH/IB headers"). Cc: Don Hiatt Cc: Dennis Dalessandro Signed-off-by: Bart Van Assche Reviewed-by: Leon Romanovsky --- include/rdma/ib_hdrs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rdma/ib_hdrs.h b/include/rdma/ib_hdrs.h index 57c1ac881d08..82483120539f 100644 --- a/include/rdma/ib_hdrs.h +++ b/include/rdma/ib_hdrs.h @@ -208,7 +208,7 @@ static inline u8 ib_get_lver(struct ib_header *hdr) static inline u16 ib_get_len(struct ib_header *hdr) { - return (u16)(be16_to_cpu(hdr->lrh[2])); + return be16_to_cpu(hdr->lrh[2]); } static inline u32 ib_get_qkey(struct ib_other_headers *ohdr) From patchwork Wed May 12 03:27:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 12252619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4B88C433B4 for ; Wed, 12 May 2021 03:28:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B47F5613C8 for ; Wed, 12 May 2021 03:28:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229968AbhELD3K (ORCPT ); Tue, 11 May 2021 23:29:10 -0400 Received: from mail-pf1-f172.google.com ([209.85.210.172]:43789 "EHLO mail-pf1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbhELD3J (ORCPT ); Tue, 11 May 2021 23:29:09 -0400 Received: by mail-pf1-f172.google.com with SMTP id b21so10442040pft.10 for ; Tue, 11 May 2021 20:28:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WoyNMArjDVR/sKZi2hfi9ZppuBc1G5/TZn1XgWLSKwg=; b=Px2ase8QE3d9ft5eRkcRmxxb9eFQ+bW5mn8d/eCKi6kJAtB81sSkfAJ21vD8Pias0v m9e7TC0wrlLmXMhz0/VHJbDHtQeBRpq5AlOleJzIysWO9uy6vrpsPo4qZPY6gorOHRFU 552eSbL5eOBw1Z8huOYb2Aspa+5mbmC9X9zWDx1BtQiEclydY3w/Ju2ZCqS1X2nJGe+N 86qZGeejgqvAoSM5cDZD1wurjBla2cTnmQzSd8BFPegJh+dir822x7JT5QeXff2TAOTi vmNao4h+Wjt/HaxpbqRWf41/dGkohCy/Hrv9z1Vgu5810yRPj/RCc9Olh/3xw+MFO16W fh0Q== X-Gm-Message-State: AOAM532KV0euY8qADvi5EDQZ7wd9/OJb7UOJ9+vZ0TWcVZkwHuJ7yDwY Pqc4lRKPPtRP46w5aLyNau0= X-Google-Smtp-Source: ABdhPJyVL1f6FNOPDk+4QyWw83TF6nB0XNkHMo2BcPYHy/EBWwJ8KZCupSc1GnyLezcwakN+VD4GaA== X-Received: by 2002:a63:2686:: with SMTP id m128mr34316431pgm.406.1620790081965; Tue, 11 May 2021 20:28:01 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:76b9:3c77:17e3:3073]) by smtp.gmail.com with ESMTPSA id q194sm15008703pfc.62.2021.05.11.20.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 20:28:01 -0700 (PDT) From: Bart Van Assche To: Jason Gunthorpe Cc: Leon Romanovsky , Doug Ledford , linux-rdma@vger.kernel.org, Bart Van Assche , Nicolas Morey-Chaisemartin Subject: [PATCH 2/5] RDMA/srp: Add more structure size checks Date: Tue, 11 May 2021 20:27:49 -0700 Message-Id: <20210512032752.16611-3-bvanassche@acm.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512032752.16611-1-bvanassche@acm.org> References: <20210512032752.16611-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Before modifying how the __packed attribute is used, add compile time size checks for the structures that will be modified. Cc: Nicolas Morey-Chaisemartin Signed-off-by: Bart Van Assche Reviewed-by: Leon Romanovsky --- drivers/infiniband/ulp/srp/ib_srp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 31f8aa2c40ed..0f66bf015db6 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -4078,10 +4078,13 @@ static int __init srp_init_module(void) { int ret; + BUILD_BUG_ON(sizeof(struct srp_aer_req) != 36); + BUILD_BUG_ON(sizeof(struct srp_cmd) != 48); BUILD_BUG_ON(sizeof(struct srp_imm_buf) != 4); + BUILD_BUG_ON(sizeof(struct srp_indirect_buf) != 20); BUILD_BUG_ON(sizeof(struct srp_login_req) != 64); BUILD_BUG_ON(sizeof(struct srp_login_req_rdma) != 56); - BUILD_BUG_ON(sizeof(struct srp_cmd) != 48); + BUILD_BUG_ON(sizeof(struct srp_rsp) != 36); if (srp_sg_tablesize) { pr_warn("srp_sg_tablesize is deprecated, please use cmd_sg_entries\n"); From patchwork Wed May 12 03:27:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 12252621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD9A7C43461 for ; Wed, 12 May 2021 03:28:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E8A4613C8 for ; Wed, 12 May 2021 03:28:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229994AbhELD3L (ORCPT ); Tue, 11 May 2021 23:29:11 -0400 Received: from mail-pg1-f180.google.com ([209.85.215.180]:45766 "EHLO mail-pg1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbhELD3K (ORCPT ); Tue, 11 May 2021 23:29:10 -0400 Received: by mail-pg1-f180.google.com with SMTP id q15so12962635pgg.12 for ; Tue, 11 May 2021 20:28:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3L77qsW4ZKuP/IDKiGViaG6824W9YPVT7keFJzoQ2EA=; b=fRJ7IlqulkSDR8id3f/uoVH6oOPb1GB3NDf5kx7+LxA4HieySrqNNkF5GwbV5ryoQ6 pZgmBJFGnjy2hU2agYyn8Q6VMyGUp8uNvyMBb+I2EBakwg5gwHNvHezRgdaEXCqQOFmw IFSDxLmrnoZbTG0YZuFR0QyO347qLerFqHbaOV7mdgwSrdgNhgQkVDRV+i8DKGKXEtum YJw2dX7Xy/5iuU+LiaUNOKpyMFanS1IBeQJANkU1IqsYfyURe9hua1fSg4apy03a4wow 3YFQEdeBGA5Gge1K7gYLMPTUlxYjKKGhQpQQlS4gznGzVXgjShMRrdOF27zjHmUvGBQx ITRA== X-Gm-Message-State: AOAM532equ2JKRvjStIFvel5mj16HcKwckyYFE1TfF7dMnaaINXqPvGy eTOgPugJgt8dGpBwIMSqyWA= X-Google-Smtp-Source: ABdhPJyWA3aycje66h4lVwecH2DlTGYHvwggvm+jASIWKM+oxRICMYJR9HQ3dY98cWKbRJHxWTC7eQ== X-Received: by 2002:a63:d14b:: with SMTP id c11mr9184512pgj.162.1620790083379; Tue, 11 May 2021 20:28:03 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:76b9:3c77:17e3:3073]) by smtp.gmail.com with ESMTPSA id q194sm15008703pfc.62.2021.05.11.20.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 20:28:02 -0700 (PDT) From: Bart Van Assche To: Jason Gunthorpe Cc: Leon Romanovsky , Doug Ledford , linux-rdma@vger.kernel.org, Bart Van Assche , Nicolas Morey-Chaisemartin Subject: [PATCH 3/5] RDMA/srp: Apply the __packed attribute to members instead of structures Date: Tue, 11 May 2021 20:27:50 -0700 Message-Id: <20210512032752.16611-4-bvanassche@acm.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512032752.16611-1-bvanassche@acm.org> References: <20210512032752.16611-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Applying the __packed attribute to an entire data structure results in suboptimal code on architectures that do not support unaligned accesses. Hence apply the __packed attribute only to those data members that are not naturally aligned. Cc: Nicolas Morey-Chaisemartin Signed-off-by: Bart Van Assche --- include/scsi/srp.h | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/include/scsi/srp.h b/include/scsi/srp.h index 177d8026e96f..84d2b5fc1409 100644 --- a/include/scsi/srp.h +++ b/include/scsi/srp.h @@ -107,10 +107,10 @@ struct srp_direct_buf { * having the 20-byte structure padded to 24 bytes on 64-bit architectures. */ struct srp_indirect_buf { - struct srp_direct_buf table_desc; + struct srp_direct_buf table_desc __packed; __be32 len; - struct srp_direct_buf desc_list[]; -} __attribute__((packed)); + struct srp_direct_buf desc_list[] __packed; +}; /* Immediate data buffer descriptor as defined in SRP2. */ struct srp_imm_buf { @@ -175,13 +175,13 @@ struct srp_login_rsp { u8 opcode; u8 reserved1[3]; __be32 req_lim_delta; - u64 tag; + u64 tag __packed; __be32 max_it_iu_len; __be32 max_ti_iu_len; __be16 buf_fmt; u8 rsp_flags; u8 reserved2[25]; -} __attribute__((packed)); +}; struct srp_login_rej { u8 opcode; @@ -207,10 +207,6 @@ struct srp_t_logout { u64 tag; }; -/* - * We need the packed attribute because the SRP spec only aligns the - * 8-byte LUN field to 4 bytes. - */ struct srp_tsk_mgmt { u8 opcode; u8 sol_not; @@ -225,10 +221,6 @@ struct srp_tsk_mgmt { u8 reserved5[8]; }; -/* - * We need the packed attribute because the SRP spec only aligns the - * 8-byte LUN field to 4 bytes. - */ struct srp_cmd { u8 opcode; u8 sol_not; @@ -266,7 +258,7 @@ struct srp_rsp { u8 sol_not; u8 reserved1[2]; __be32 req_lim_delta; - u64 tag; + u64 tag __packed; u8 reserved2[2]; u8 flags; u8 status; @@ -275,7 +267,7 @@ struct srp_rsp { __be32 sense_data_len; __be32 resp_data_len; u8 data[]; -} __attribute__((packed)); +}; struct srp_cred_req { u8 opcode; @@ -301,13 +293,13 @@ struct srp_aer_req { u8 sol_not; u8 reserved[2]; __be32 req_lim_delta; - u64 tag; + u64 tag __packed; u32 reserved2; struct scsi_lun lun; __be32 sense_data_len; u32 reserved3; u8 sense_data[]; -} __attribute__((packed)); +}; struct srp_aer_rsp { u8 opcode; From patchwork Wed May 12 03:27:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 12252623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5BD1C433B4 for ; Wed, 12 May 2021 03:28:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70603613C8 for ; Wed, 12 May 2021 03:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230011AbhELD3M (ORCPT ); Tue, 11 May 2021 23:29:12 -0400 Received: from mail-pf1-f172.google.com ([209.85.210.172]:39727 "EHLO mail-pf1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbhELD3M (ORCPT ); Tue, 11 May 2021 23:29:12 -0400 Received: by mail-pf1-f172.google.com with SMTP id c17so17557427pfn.6 for ; Tue, 11 May 2021 20:28:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NeoVKuu1izPRDjzl6yrfqlvFWiO09o+X/S+BeQbM/x0=; b=LTplK823Hh1mAgDTcBkumq7uTtdpkWOIyVWfhUrCsO40QjFlB9HiTFLYMHHR8aekFM aTFQRumu69j8xcPArbFgobC+9ZqstTXLvYM8+IGHqVoViPXtxBCPKcr5lJwHl/k/EBh0 917S1gf3qziEfGhvI5Yrpe/ZonXwLm+P9uqG02ImfVcHC70jnMFtufy5iwafN4XGPmcc 5sHFC5ecwk7RUvvWKFO4F1O/OaGlRlCYye5Rq7XEZ2AEG5+/RNiP3ZcUhqvHlEnspKqg 8/fHuwp3a+r/kFDZDpP7hTZ4CwyVBl18HvXvnkrnQip9alrMt4AliThqz9ZeLy6TvsS6 h35Q== X-Gm-Message-State: AOAM531JQtOMSIdEpEpcM2ppoMJmKwKKLvSnRt8I+7FaK8i32flQYzW/ eenl4ShzJrxfEsQNN0GFBGE= X-Google-Smtp-Source: ABdhPJylkitJz9sPpl+f/UAmSGNhi1GEyUudwxNw6TfSmXpt+xSGvpV6QGiZZ/6gBtkKkP9uGa21cg== X-Received: by 2002:a62:4e10:0:b029:2cb:cf3b:d195 with SMTP id c16-20020a624e100000b02902cbcf3bd195mr4465125pfb.74.1620790084797; Tue, 11 May 2021 20:28:04 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:76b9:3c77:17e3:3073]) by smtp.gmail.com with ESMTPSA id q194sm15008703pfc.62.2021.05.11.20.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 20:28:04 -0700 (PDT) From: Bart Van Assche To: Jason Gunthorpe Cc: Leon Romanovsky , Doug Ledford , linux-rdma@vger.kernel.org, Bart Van Assche , Max Gurtovoy , Nicolas Morey-Chaisemartin Subject: [PATCH 4/5] RDMA/srp: Fix a recently introduced memory leak Date: Tue, 11 May 2021 20:27:51 -0700 Message-Id: <20210512032752.16611-5-bvanassche@acm.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512032752.16611-1-bvanassche@acm.org> References: <20210512032752.16611-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Only allocate an mr_list if it will be used and if it will be freed. Cc: Max Gurtovoy Cc: Nicolas Morey-Chaisemartin Fixes: f273ad4f8d90 ("RDMA/srp: Remove support for FMR memory registration") Signed-off-by: Bart Van Assche Reviewed-by: Max Gurtovoy --- drivers/infiniband/ulp/srp/ib_srp.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 0f66bf015db6..52db42af421b 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -1009,12 +1009,13 @@ static int srp_alloc_req_data(struct srp_rdma_ch *ch) for (i = 0; i < target->req_ring_size; ++i) { req = &ch->req_ring[i]; - mr_list = kmalloc_array(target->mr_per_cmd, sizeof(void *), - GFP_KERNEL); - if (!mr_list) - goto out; - if (srp_dev->use_fast_reg) + if (srp_dev->use_fast_reg) { + mr_list = kmalloc_array(target->mr_per_cmd, + sizeof(void *), GFP_KERNEL); + if (!mr_list) + goto out; req->fr_list = mr_list; + } req->indirect_desc = kmalloc(target->indirect_size, GFP_KERNEL); if (!req->indirect_desc) goto out; From patchwork Wed May 12 03:27:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 12252625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEE18C43460 for ; Wed, 12 May 2021 03:28:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E52C613B5 for ; Wed, 12 May 2021 03:28:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229964AbhELD3O (ORCPT ); Tue, 11 May 2021 23:29:14 -0400 Received: from mail-pf1-f179.google.com ([209.85.210.179]:44647 "EHLO mail-pf1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbhELD3N (ORCPT ); Tue, 11 May 2021 23:29:13 -0400 Received: by mail-pf1-f179.google.com with SMTP id a5so10498208pfa.11 for ; Tue, 11 May 2021 20:28:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x+K6AnurGTbqDz2I+bQ4vK3yVqFAky7xD8T230Jt6d8=; b=mcBSfiTvDwQTJJt1VKbVA+eShSZhmJVeBmMlzAwvZeeZrGukfJUwjzYrR4ouAGsN/D mdv+ktLWOOyDy890fXJy6Omt8UQnWR/Y6zKkc/9+iGppUQuUFisgrLUH0XHZL3I5HxOf s0pJbW3zi+s9sktXgJkEgAk52Spha99S0OECLtFuAVhVBHgnguFlfzFzVd/rrRWxEdbk D35JSr1/I42WCcyZDibhvbCHKnQc+CEdZKg3ZK2nu7xas3P80uCghUTkt3YcRGSH/082 JIQDG3lR/PWMo6N1Rhh+hLmYjHZCTmeXwxqxJeX57w98HydjiVCGTFJlgfn4Q48A2kua m66g== X-Gm-Message-State: AOAM532whd4qp/bgCHcd2l9WBwWEejUlSDM3ywd096h56yLSxxTWJ01N K7x5lVNZL5otZ0V2FXmEFTU= X-Google-Smtp-Source: ABdhPJyFZG/PLW0il4ab+P7FY17g8cOFN3NLXNdJsDmvk0/5Reo44v8rEWX7pfzy6n6mJZGNrpa1Pw== X-Received: by 2002:a63:2bd0:: with SMTP id r199mr34213548pgr.395.1620790086237; Tue, 11 May 2021 20:28:06 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:76b9:3c77:17e3:3073]) by smtp.gmail.com with ESMTPSA id q194sm15008703pfc.62.2021.05.11.20.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 20:28:05 -0700 (PDT) From: Bart Van Assche To: Jason Gunthorpe Cc: Leon Romanovsky , Doug Ledford , linux-rdma@vger.kernel.org, Bart Van Assche , Nicolas Morey-Chaisemartin Subject: [PATCH 5/5] RDMA/srp: Make struct scsi_cmnd and struct srp_request adjacent Date: Tue, 11 May 2021 20:27:52 -0700 Message-Id: <20210512032752.16611-6-bvanassche@acm.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512032752.16611-1-bvanassche@acm.org> References: <20210512032752.16611-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Define .init_cmd_priv and .exit_cmd_priv callback functions in struct scsi_host_template. Set .cmd_size such that the SCSI core allocates per-command private data. Use scsi_cmd_priv() to access that private data. Remove the req_ring pointer from struct srp_rdma_ch since it is no longer necessary. Convert srp_alloc_req_data() and srp_free_req_data() into functions that initialize one instance of the SRP-private command data. This is a micro-optimization since this patch removes several pointer dereferences from the hot path. Note: due to commit e73a5e8e8003 ("scsi: core: Only return started requests from scsi_host_find_tag()"), it is no longer necessary to protect the completion path against duplicate responses. Cc: Nicolas Morey-Chaisemartin Signed-off-by: Bart Van Assche --- drivers/infiniband/ulp/srp/ib_srp.c | 156 ++++++++++++---------------- drivers/infiniband/ulp/srp/ib_srp.h | 2 - 2 files changed, 65 insertions(+), 93 deletions(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 52db42af421b..773ac5929082 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -965,69 +965,55 @@ static void srp_disconnect_target(struct srp_target_port *target) } } -static void srp_free_req_data(struct srp_target_port *target, - struct srp_rdma_ch *ch) +static int srp_exit_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd) { + struct srp_target_port *target = host_to_target(shost); struct srp_device *dev = target->srp_host->srp_dev; struct ib_device *ibdev = dev->dev; - struct srp_request *req; - int i; + struct srp_request *req = scsi_cmd_priv(cmd); - if (!ch->req_ring) - return; - - for (i = 0; i < target->req_ring_size; ++i) { - req = &ch->req_ring[i]; - if (dev->use_fast_reg) - kfree(req->fr_list); - if (req->indirect_dma_addr) { - ib_dma_unmap_single(ibdev, req->indirect_dma_addr, - target->indirect_size, - DMA_TO_DEVICE); - } - kfree(req->indirect_desc); + if (dev->use_fast_reg) + kfree(req->fr_list); + if (req->indirect_dma_addr) { + ib_dma_unmap_single(ibdev, req->indirect_dma_addr, + target->indirect_size, + DMA_TO_DEVICE); } + kfree(req->indirect_desc); - kfree(ch->req_ring); - ch->req_ring = NULL; + return 0; } -static int srp_alloc_req_data(struct srp_rdma_ch *ch) +static int srp_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd) { - struct srp_target_port *target = ch->target; + struct srp_target_port *target = host_to_target(shost); struct srp_device *srp_dev = target->srp_host->srp_dev; struct ib_device *ibdev = srp_dev->dev; - struct srp_request *req; + struct srp_request *req = scsi_cmd_priv(cmd); void *mr_list; dma_addr_t dma_addr; - int i, ret = -ENOMEM; - - ch->req_ring = kcalloc(target->req_ring_size, sizeof(*ch->req_ring), - GFP_KERNEL); - if (!ch->req_ring) - goto out; + int ret = -ENOMEM; - for (i = 0; i < target->req_ring_size; ++i) { - req = &ch->req_ring[i]; - if (srp_dev->use_fast_reg) { - mr_list = kmalloc_array(target->mr_per_cmd, - sizeof(void *), GFP_KERNEL); - if (!mr_list) - goto out; - req->fr_list = mr_list; - } - req->indirect_desc = kmalloc(target->indirect_size, GFP_KERNEL); - if (!req->indirect_desc) - goto out; - - dma_addr = ib_dma_map_single(ibdev, req->indirect_desc, - target->indirect_size, - DMA_TO_DEVICE); - if (ib_dma_mapping_error(ibdev, dma_addr)) + if (srp_dev->use_fast_reg) { + mr_list = kmalloc_array(target->mr_per_cmd, sizeof(void *), + GFP_KERNEL); + if (!mr_list) goto out; + req->fr_list = mr_list; + } + req->indirect_desc = kmalloc(target->indirect_size, GFP_KERNEL); + if (!req->indirect_desc) + goto out; - req->indirect_dma_addr = dma_addr; + dma_addr = ib_dma_map_single(ibdev, req->indirect_desc, + target->indirect_size, + DMA_TO_DEVICE); + if (ib_dma_mapping_error(ibdev, dma_addr)) { + srp_exit_cmd_priv(shost, cmd); + goto out; } + + req->indirect_dma_addr = dma_addr; ret = 0; out: @@ -1069,10 +1055,6 @@ static void srp_remove_target(struct srp_target_port *target) } cancel_work_sync(&target->tl_err_work); srp_rport_put(target->rport); - for (i = 0; i < target->ch_count; i++) { - ch = &target->ch[i]; - srp_free_req_data(target, ch); - } kfree(target->ch); target->ch = NULL; @@ -1291,22 +1273,32 @@ static void srp_finish_req(struct srp_rdma_ch *ch, struct srp_request *req, } } -static void srp_terminate_io(struct srp_rport *rport) +struct srp_terminate_context { + struct srp_target_port *srp_target; + int scsi_result; +}; + +static bool srp_terminate_cmd(struct scsi_cmnd *scmnd, void *context_ptr, + bool reserved) { - struct srp_target_port *target = rport->lld_data; - struct srp_rdma_ch *ch; - int i, j; + struct srp_terminate_context *context = context_ptr; + struct srp_target_port *target = context->srp_target; + u32 tag = blk_mq_unique_tag(scmnd->request); + struct srp_rdma_ch *ch = &target->ch[blk_mq_unique_tag_to_hwq(tag)]; + struct srp_request *req = scsi_cmd_priv(scmnd); - for (i = 0; i < target->ch_count; i++) { - ch = &target->ch[i]; + srp_finish_req(ch, req, NULL, context->scsi_result); - for (j = 0; j < target->req_ring_size; ++j) { - struct srp_request *req = &ch->req_ring[j]; + return true; +} - srp_finish_req(ch, req, NULL, - DID_TRANSPORT_FAILFAST << 16); - } - } +static void srp_terminate_io(struct srp_rport *rport) +{ + struct srp_target_port *target = rport->lld_data; + struct srp_terminate_context context = { .srp_target = target, + .scsi_result = DID_TRANSPORT_FAILFAST << 16 }; + + scsi_host_busy_iter(target->scsi_host, srp_terminate_cmd, &context); } /* Calculate maximum initiator to target information unit length. */ @@ -1362,13 +1354,12 @@ static int srp_rport_reconnect(struct srp_rport *rport) ch = &target->ch[i]; ret += srp_new_cm_id(ch); } - for (i = 0; i < target->ch_count; i++) { - ch = &target->ch[i]; - for (j = 0; j < target->req_ring_size; ++j) { - struct srp_request *req = &ch->req_ring[j]; + { + struct srp_terminate_context context = { + .srp_target = target, .scsi_result = DID_RESET << 16}; - srp_finish_req(ch, req, NULL, DID_RESET << 16); - } + scsi_host_busy_iter(target->scsi_host, srp_terminate_cmd, + &context); } for (i = 0; i < target->ch_count; i++) { ch = &target->ch[i]; @@ -1964,13 +1955,10 @@ static void srp_process_rsp(struct srp_rdma_ch *ch, struct srp_rsp *rsp) spin_unlock_irqrestore(&ch->lock, flags); } else { scmnd = scsi_host_find_tag(target->scsi_host, rsp->tag); - if (scmnd && scmnd->host_scribble) { - req = (void *)scmnd->host_scribble; + if (scmnd) { + req = scsi_cmd_priv(scmnd); scmnd = srp_claim_req(ch, req, NULL, scmnd); } else { - scmnd = NULL; - } - if (!scmnd) { shost_printk(KERN_ERR, target->scsi_host, "Null scmnd for RSP w/tag %#016llx received on ch %td / QP %#x\n", rsp->tag, ch - target->ch, ch->qp->qp_num); @@ -2002,7 +1990,6 @@ static void srp_process_rsp(struct srp_rdma_ch *ch, struct srp_rsp *rsp) srp_free_req(ch, req, scmnd, be32_to_cpu(rsp->req_lim_delta)); - scmnd->host_scribble = NULL; scmnd->scsi_done(scmnd); } } @@ -2170,13 +2157,12 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd) { struct srp_target_port *target = host_to_target(shost); struct srp_rdma_ch *ch; - struct srp_request *req; + struct srp_request *req = scsi_cmd_priv(scmnd); struct srp_iu *iu; struct srp_cmd *cmd; struct ib_device *dev; unsigned long flags; u32 tag; - u16 idx; int len, ret; scmnd->result = srp_chkready(target->rport); @@ -2186,10 +2172,6 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd) WARN_ON_ONCE(scmnd->request->tag < 0); tag = blk_mq_unique_tag(scmnd->request); ch = &target->ch[blk_mq_unique_tag_to_hwq(tag)]; - idx = blk_mq_unique_tag_to_tag(tag); - WARN_ONCE(idx >= target->req_ring_size, "%s: tag %#x: idx %d >= %d\n", - dev_name(&shost->shost_gendev), tag, idx, - target->req_ring_size); spin_lock_irqsave(&ch->lock, flags); iu = __srp_get_tx_iu(ch, SRP_IU_CMD); @@ -2198,13 +2180,10 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd) if (!iu) goto err; - req = &ch->req_ring[idx]; dev = target->srp_host->srp_dev->dev; ib_dma_sync_single_for_cpu(dev, iu->dma, ch->max_it_iu_len, DMA_TO_DEVICE); - scmnd->host_scribble = (void *) req; - cmd = iu->buf; memset(cmd, 0, sizeof *cmd); @@ -3085,6 +3064,8 @@ static struct scsi_host_template srp_template = { .target_alloc = srp_target_alloc, .slave_configure = srp_slave_configure, .info = srp_target_info, + .init_cmd_priv = srp_init_cmd_priv, + .exit_cmd_priv = srp_exit_cmd_priv, .queuecommand = srp_queuecommand, .change_queue_depth = srp_change_queue_depth, .eh_timed_out = srp_timed_out, @@ -3098,6 +3079,7 @@ static struct scsi_host_template srp_template = { .cmd_per_lun = SRP_DEFAULT_CMD_SQ_SIZE, .shost_attrs = srp_host_attrs, .track_queue_depth = 1, + .cmd_size = sizeof(struct srp_request), }; static int srp_sdev_count(struct Scsi_Host *host) @@ -3677,8 +3659,6 @@ static ssize_t srp_create_target(struct device *dev, if (ret) goto out; - target->req_ring_size = target->queue_size - SRP_TSK_MGMT_SQ_SIZE; - if (!srp_conn_unique(target->srp_host, target)) { if (target->using_rdma_cm) { shost_printk(KERN_INFO, target->scsi_host, @@ -3781,10 +3761,6 @@ static ssize_t srp_create_target(struct device *dev, if (ret) goto err_disconnect; - ret = srp_alloc_req_data(ch); - if (ret) - goto err_disconnect; - ret = srp_connect_ch(ch, max_iu_len, multich); if (ret) { char dst[64]; @@ -3803,7 +3779,6 @@ static ssize_t srp_create_target(struct device *dev, goto free_ch; } else { srp_free_ch_ib(target, ch); - srp_free_req_data(target, ch); target->ch_count = ch - target->ch; goto connected; } @@ -3864,7 +3839,6 @@ static ssize_t srp_create_target(struct device *dev, for (i = 0; i < target->ch_count; i++) { ch = &target->ch[i]; srp_free_ch_ib(target, ch); - srp_free_req_data(target, ch); } kfree(target->ch); diff --git a/drivers/infiniband/ulp/srp/ib_srp.h b/drivers/infiniband/ulp/srp/ib_srp.h index 6818cac0a3b7..abccddeea1e3 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.h +++ b/drivers/infiniband/ulp/srp/ib_srp.h @@ -174,7 +174,6 @@ struct srp_rdma_ch { struct srp_iu **tx_ring; struct srp_iu **rx_ring; - struct srp_request *req_ring; int comp_vector; u64 tsk_mgmt_tag; @@ -220,7 +219,6 @@ struct srp_target_port { int mr_pool_size; int mr_per_cmd; int queue_size; - int req_ring_size; int comp_vector; int tl_retry_count;