Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp215684yba; Mon, 20 May 2019 07:32:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8iVQl3PVM5Tgng51zR+EIHf0fFvl7u+xhUWphk9+h7lPwjp/GY5++p2FInJnGXfZEt2Q5 X-Received: by 2002:a17:902:f081:: with SMTP id go1mr28946517plb.211.1558362778711; Mon, 20 May 2019 07:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558362778; cv=none; d=google.com; s=arc-20160816; b=IVtyJFnd8R4W1opXCIKlxhAxvO2+xF05eoPEffbnzU85M7a90H2QZAqYsYKPBkG6bl vjQRxfCja8/9UCWky68pGWtpB/rxuQV36K74bBPZZapgn/PHglA1289m8ltPRi1nOjiK YHkbL2FGcBMeafKhs06DhnpodBQB+QqJViPWVHtQYeev+8nYzP6SAUSZ6g+vL9vYP+vi 2NgXdy5qgB08Zn2jdEevc9PI1m9eFLt2EWANLSwxLapcj8j4MMdkZGVtoHuGVo+2BpkW MZg5EcPqzdJzbNLOVC6TAae/zPRR9GZIuIY2DxtSM3V30TGP0pkS9qS1fNr3tj6X8uHN c7wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:cc:to:subject:from; bh=WcharAN6lDZ0QHHvnrPjFGK/6ZxhkbRR8vaxH125Gyk=; b=WS9oc/b4NCYWJdZmSVJN/icBDe4Z+NUV8Xdw63lQkPJLI81NqxeqxQJLD8sPvwVIzV MSqZ2NMxeGpkaYDzBVlH9ah5PcnK7VtscBfRyiApLHsG45QIDPUh9GchzryZXonQpsOV mxuxa6UdqqdWLtxgL0gSqqWSFSj6/qBIkSWBgvQHeHQd2TJ27GhiqWuubfPHm96w34Yp bcZ/AiiSXPvgztRjzaFascUGm5B7JaEeVz7aHk9UdJAMydz/3jk2ffFUAJICki8EHyya CN8aL8C8VclBD5ZG/xbX31r4KOYueP0VCU6PMiO2qmuQ1Q1nl3rSDNysaFqNu0vyvZjb qkxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q195si1414853pgq.119.2019.05.20.07.32.38; Mon, 20 May 2019 07:32:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732598AbfETLTF (ORCPT + 99 others); Mon, 20 May 2019 07:19:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:33964 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730640AbfETLTE (ORCPT ); Mon, 20 May 2019 07:19:04 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id CEF1EAEF1; Mon, 20 May 2019 11:19:02 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 7104DE0184; Mon, 20 May 2019 13:19:02 +0200 (CEST) From: Michal Kubecek Subject: [PATCH] mlx5: avoid 64-bit division To: Leon Romanovsky Cc: Doug Ledford , Jason Gunthorpe , Ariel Levkovich , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Message-Id: <20190520111902.7104DE0184@unicorn.suse.cz> Date: Mon, 20 May 2019 13:19:02 +0200 (CEST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 25c13324d03d ("IB/mlx5: Add steering SW ICM device memory type") breaks i386 build by introducing three 64-bit divisions. As the divisor is MLX5_SW_ICM_BLOCK_SIZE() which is always a power of 2, we can replace the division with bit operations. Fixes: 25c13324d03d ("IB/mlx5: Add steering SW ICM device memory type") Signed-off-by: Michal Kubecek --- drivers/infiniband/hw/mlx5/cmd.c | 9 +++++++-- drivers/infiniband/hw/mlx5/main.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/cmd.c b/drivers/infiniband/hw/mlx5/cmd.c index e3ec79b8f7f5..6c8645033102 100644 --- a/drivers/infiniband/hw/mlx5/cmd.c +++ b/drivers/infiniband/hw/mlx5/cmd.c @@ -190,12 +190,12 @@ int mlx5_cmd_alloc_sw_icm(struct mlx5_dm *dm, int type, u64 length, u16 uid, phys_addr_t *addr, u32 *obj_id) { struct mlx5_core_dev *dev = dm->dev; - u32 num_blocks = DIV_ROUND_UP(length, MLX5_SW_ICM_BLOCK_SIZE(dev)); u32 out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {}; u32 in[MLX5_ST_SZ_DW(create_sw_icm_in)] = {}; unsigned long *block_map; u64 icm_start_addr; u32 log_icm_size; + u32 num_blocks; u32 max_blocks; u64 block_idx; void *sw_icm; @@ -224,6 +224,8 @@ int mlx5_cmd_alloc_sw_icm(struct mlx5_dm *dm, int type, u64 length, return -EINVAL; } + num_blocks = (length + MLX5_SW_ICM_BLOCK_SIZE(dev) - 1) >> + MLX5_LOG_SW_ICM_BLOCK_SIZE(dev); max_blocks = BIT(log_icm_size - MLX5_LOG_SW_ICM_BLOCK_SIZE(dev)); spin_lock(&dm->lock); block_idx = bitmap_find_next_zero_area(block_map, @@ -266,13 +268,16 @@ int mlx5_cmd_dealloc_sw_icm(struct mlx5_dm *dm, int type, u64 length, u16 uid, phys_addr_t addr, u32 obj_id) { struct mlx5_core_dev *dev = dm->dev; - u32 num_blocks = DIV_ROUND_UP(length, MLX5_SW_ICM_BLOCK_SIZE(dev)); u32 out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {}; u32 in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {}; unsigned long *block_map; + u32 num_blocks; u64 start_idx; int err; + num_blocks = (length + MLX5_SW_ICM_BLOCK_SIZE(dev) - 1) >> + MLX5_LOG_SW_ICM_BLOCK_SIZE(dev); + switch (type) { case MLX5_IB_UAPI_DM_TYPE_STEERING_SW_ICM: start_idx = diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index abac70ad5c7c..340290b883fe 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -2344,7 +2344,7 @@ static int handle_alloc_dm_sw_icm(struct ib_ucontext *ctx, /* Allocation size must a multiple of the basic block size * and a power of 2. */ - act_size = roundup(attr->length, MLX5_SW_ICM_BLOCK_SIZE(dm_db->dev)); + act_size = round_up(attr->length, MLX5_SW_ICM_BLOCK_SIZE(dm_db->dev)); act_size = roundup_pow_of_two(act_size); dm->size = act_size; -- 2.21.0