From cf88f570e2e67409fa1fa3d7b50dd48cabab7e82 Mon Sep 17 00:00:00 2001 From: Jack Morgenstein Date: Mon, 18 Feb 2013 12:34:59 +0200 Subject: [PATCH] mlx4_core: change resource quotas to enable supporting upstream-kernel guests The resource-quota code passed non-power-of-2 quotas to guests. In the upstream kernel (bugs), resource quotas for MPTs and QPs are assumed to be powers-of-2. In MPT case, mlx4_init_mr_table checks for num_mpts being a power-of-2 before checking if it is running as a slave. In the QP case, procedure mlx4_qp_alloc() assumes that (num_qps - 1) is a power-of-2 when calling radix_tree_insert() and radix_tree_delete(). In the MPT case, mlx4_init_mr_table() failed on the guest, causing abort of the guest driver bringup. In the QP case, although create-qp succeeded on the hypervisor, the radix_tree_insert() call failed, resulting in failure to create QPs with certain qp numbers. The fix, for both cases, is to round-up the quota to the next power-of-2 for guests for MPTs and QPs. This does no harm, as these two resources were not really meant to be limited by an upper quota. The guaranteed resources for QPs and MPTs per VF/PF are not affected by this change. The only effect is that no guest will ever be able to actually reach its max-quota for QPs and MPTs. Signed-off-by: Jack Morgenstein (Ported from Mellanox OFED 2.4) Signed-off-by: Mukesh Kacker --- drivers/net/ethernet/mellanox/mlx4/resource_tracker.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c index bafe2180cf0c..ec431c928228 100644 --- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c +++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c @@ -417,6 +417,11 @@ static inline void initialize_res_quotas(struct mlx4_dev *dev, res_alloc->guaranteed[vf] = num_instances / (2 * (dev->persist->num_vfs + 1)); res_alloc->quota[vf] = (num_instances / 2) + res_alloc->guaranteed[vf]; + + /* upstream kernel code required that num_mpts and num_qps be power-of-2 */ + if (res_type == RES_MPT || res_type == RES_QP) + res_alloc->quota[vf] = roundup_pow_of_two(res_alloc->quota[vf]); + if (vf == mlx4_master_func_num(dev)) { res_alloc->res_free = num_instances; if (res_type == RES_MTT) { -- 2.50.1