From patchwork Tue Nov 5 12:08:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junxian Huang X-Patchwork-Id: 13862875 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84F2E1CEAD3; Tue, 5 Nov 2024 12:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730808911; cv=none; b=VsdNnL5wfEFdY5zOnFobNIOD3j/ihOh8WeC/RQoYYivG37qpmUl5CTYNGFGesa9alLmcgh2r6zp/O8txjTRBf9HaDNyBG9pLBPyTX16/2LIbglltLTamTVXsF+mAG8STVkm7MqzwEEPGmpqnUff37cBEFKmWNt+DUaD7qDObJ4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730808911; c=relaxed/simple; bh=g8W2mxWXStiowo6LQz1Q8e/wZEmAKNtw5//26LeEZuA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OqBfr8V5BSIvorMtcAD2hzRI6H+mrbGM2d2AN0FHWcWnFc2HZU8LYyQesVdZGjht0CTF3HWTOIoZc/CViWB+YILVt0ZFVuLXUmccMdWWme7DTYPSbXNPoFawBCRBjCGzjXZwE8hSDVIV5PScmFAyIVtH2yqKSZieOY7hi/RH28Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hisilicon.com; spf=pass smtp.mailfrom=hisilicon.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hisilicon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hisilicon.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XjS0Q0JJ9zpY1W; Tue, 5 Nov 2024 20:13:10 +0800 (CST) Received: from kwepemf100018.china.huawei.com (unknown [7.202.181.17]) by mail.maildlp.com (Postfix) with ESMTPS id 5D53518009B; Tue, 5 Nov 2024 20:15:04 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemf100018.china.huawei.com (7.202.181.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 5 Nov 2024 20:15:03 +0800 From: Junxian Huang To: , , CC: , , , , Subject: [PATCH for-next 1/2] RDMA/core: Add dummy sg_offset pointer for ib_map_mr_sg() and ib_map_mr_sg_pi() Date: Tue, 5 Nov 2024 20:08:40 +0800 Message-ID: <20241105120841.860068-2-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241105120841.860068-1-huangjunxian6@hisilicon.com> References: <20241105120841.860068-1-huangjunxian6@hisilicon.com> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf100018.china.huawei.com (7.202.181.17) ib_map_mr_sg() and ib_map_mr_sg_pi() allow ULPs to specify NULL as the sg_offset/data_sg_offset/meta_sg_offset arguments. In these cases, pass a dummy pointer to drivers so they don't have to add NULL pointer checks. Signed-off-by: Junxian Huang --- drivers/infiniband/core/verbs.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index 473ee0831307..27060554dde2 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -2670,6 +2670,9 @@ int ib_map_mr_sg_pi(struct ib_mr *mr, struct scatterlist *data_sg, struct scatterlist *meta_sg, int meta_sg_nents, unsigned int *meta_sg_offset, unsigned int page_size) { + unsigned int data_dummy = 0; + unsigned int meta_dummy = 0; + if (unlikely(!mr->device->ops.map_mr_sg_pi || WARN_ON_ONCE(mr->type != IB_MR_TYPE_INTEGRITY))) return -EOPNOTSUPP; @@ -2677,8 +2680,9 @@ int ib_map_mr_sg_pi(struct ib_mr *mr, struct scatterlist *data_sg, mr->page_size = page_size; return mr->device->ops.map_mr_sg_pi(mr, data_sg, data_sg_nents, - data_sg_offset, meta_sg, - meta_sg_nents, meta_sg_offset); + data_sg_offset ? : &data_dummy, + meta_sg, meta_sg_nents, + meta_sg_offset ? : &meta_dummy); } EXPORT_SYMBOL(ib_map_mr_sg_pi); @@ -2711,12 +2715,14 @@ EXPORT_SYMBOL(ib_map_mr_sg_pi); int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents, unsigned int *sg_offset, unsigned int page_size) { + unsigned int dummy = 0; + if (unlikely(!mr->device->ops.map_mr_sg)) return -EOPNOTSUPP; mr->page_size = page_size; - return mr->device->ops.map_mr_sg(mr, sg, sg_nents, sg_offset); + return mr->device->ops.map_mr_sg(mr, sg, sg_nents, sg_offset ? : &dummy); } EXPORT_SYMBOL(ib_map_mr_sg); From patchwork Tue Nov 5 12:08:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junxian Huang X-Patchwork-Id: 13862873 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89CFE1D460E; Tue, 5 Nov 2024 12:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730808910; cv=none; b=e1Ahec9oJjySTizeW0HEl9tFzoymdSQ+eLSaNUBOsmno+4196go5XxiTJtpx4ZVVv1TSgCbvIHF10fQnTMpp7WOuqNuDE9hXfiten6oQziVxPsz6lH6rOdWykFs62XDrtwtRVAuOYT4OnMP34rdTAFHF3M5/5WD69ABJGakZSdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730808910; c=relaxed/simple; bh=iXEKC62juvToWzOz9505gScfU3Uf65xMr1hlof+jCq0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Flb8//efWa8NTeJ4uUZB4GUI76TVQbAivFkce4hzO6LECUCYdouqVr7XHPuBDZ2pCk7KO7jV9OBd+wXosCS2+MTaA7rf7kLckJGEQ+iq3fQPGZONmpdTHdmJzZl7sOsjCkFeHT7k9/NYVj/OUYvNkpXg68kSREcd8J0lngjcatA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hisilicon.com; spf=pass smtp.mailfrom=hisilicon.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hisilicon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hisilicon.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4XjS0h6FMpz2Fbqc; Tue, 5 Nov 2024 20:13:24 +0800 (CST) Received: from kwepemf100018.china.huawei.com (unknown [7.202.181.17]) by mail.maildlp.com (Postfix) with ESMTPS id B68511402E2; Tue, 5 Nov 2024 20:15:04 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemf100018.china.huawei.com (7.202.181.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 5 Nov 2024 20:15:04 +0800 From: Junxian Huang To: , , CC: , , , , Subject: [PATCH for-next 2/2] RDMA: Delete NULL pointer checks for sg_offset in .map_mr_sg ops Date: Tue, 5 Nov 2024 20:08:41 +0800 Message-ID: <20241105120841.860068-3-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241105120841.860068-1-huangjunxian6@hisilicon.com> References: <20241105120841.860068-1-huangjunxian6@hisilicon.com> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf100018.china.huawei.com (7.202.181.17) Since we can now ensure that the sg_offset/data_sg_offset/meta_sg_offset arguments are valid pointer, NULL pointer checks in drivers are no longer needed. Signed-off-by: Junxian Huang --- drivers/infiniband/hw/mlx5/mr.c | 18 ++++++------------ drivers/infiniband/sw/rdmavt/trace_mr.h | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c index 45d9dc9c6c8f..f119078ca671 100644 --- a/drivers/infiniband/hw/mlx5/mr.c +++ b/drivers/infiniband/hw/mlx5/mr.c @@ -2545,17 +2545,13 @@ mlx5_ib_map_pa_mr_sg_pi(struct ib_mr *ibmr, struct scatterlist *data_sg, if (data_sg_nents == 1) { n++; mr->mmkey.ndescs = 1; - if (data_sg_offset) - sg_offset = *data_sg_offset; + sg_offset = *data_sg_offset; mr->data_length = sg_dma_len(data_sg) - sg_offset; mr->data_iova = sg_dma_address(data_sg) + sg_offset; if (meta_sg_nents == 1) { n++; mr->meta_ndescs = 1; - if (meta_sg_offset) - sg_offset = *meta_sg_offset; - else - sg_offset = 0; + sg_offset = *meta_sg_offset; mr->meta_length = sg_dma_len(meta_sg) - sg_offset; mr->pi_iova = sg_dma_address(meta_sg) + sg_offset; } @@ -2576,7 +2572,7 @@ mlx5_ib_sg_to_klms(struct mlx5_ib_mr *mr, { struct scatterlist *sg = sgl; struct mlx5_klm *klms = mr->descs; - unsigned int sg_offset = sg_offset_p ? *sg_offset_p : 0; + unsigned int sg_offset = *sg_offset_p; u32 lkey = mr->ibmr.pd->local_dma_lkey; int i, j = 0; @@ -2594,15 +2590,14 @@ mlx5_ib_sg_to_klms(struct mlx5_ib_mr *mr, sg_offset = 0; } - if (sg_offset_p) - *sg_offset_p = sg_offset; + *sg_offset_p = sg_offset; mr->mmkey.ndescs = i; mr->data_length = mr->ibmr.length; if (meta_sg_nents) { sg = meta_sgl; - sg_offset = meta_sg_offset_p ? *meta_sg_offset_p : 0; + sg_offset = *meta_sg_offset_p; for_each_sg(meta_sgl, sg, meta_sg_nents, j) { if (unlikely(i + j >= mr->max_descs)) break; @@ -2615,8 +2610,7 @@ mlx5_ib_sg_to_klms(struct mlx5_ib_mr *mr, sg_offset = 0; } - if (meta_sg_offset_p) - *meta_sg_offset_p = sg_offset; + *meta_sg_offset_p = sg_offset; mr->meta_ndescs = j; mr->meta_length = mr->ibmr.length - mr->data_length; diff --git a/drivers/infiniband/sw/rdmavt/trace_mr.h b/drivers/infiniband/sw/rdmavt/trace_mr.h index 0cb8e0a0565e..6f4c70480d34 100644 --- a/drivers/infiniband/sw/rdmavt/trace_mr.h +++ b/drivers/infiniband/sw/rdmavt/trace_mr.h @@ -159,7 +159,7 @@ TRACE_EVENT( __entry->user_base = to_imr(ibmr)->mr.user_base; __entry->ibmr_length = to_imr(ibmr)->mr.length; __entry->sg_nents = sg_nents; - __entry->sg_offset = sg_offset ? *sg_offset : 0; + __entry->sg_offset = *sg_offset; ), TP_printk( "[%s] ibmr_iova %llx iova %llx user_base %llx length %llx sg_nents %d sg_offset %u",