diff mbox series

[for-next,7/9] RDMA/hns: Prevent the gid overflow

Message ID 1550809268-125729-8-git-send-email-oulijun@huawei.com (mailing list archive)
State Superseded
Delegated to: Jason Gunthorpe
Headers show
Series Hns updates | expand

Commit Message

Lijun Ou Feb. 22, 2019, 4:21 a.m. UTC
Because hip08 supports up to 256 gids and hip06 supports up to 2 gids, it
adds judgement for preventing the gid overflow.

Signed-off-by: Lijun Ou <oulijun@huawei.com>
---
 drivers/infiniband/hw/hns/hns_roce_main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Jason Gunthorpe Feb. 22, 2019, 4:24 p.m. UTC | #1
On Fri, Feb 22, 2019 at 12:21:06PM +0800, Lijun Ou wrote:
> Because hip08 supports up to 256 gids and hip06 supports up to 2 gids, it
> adds judgement for preventing the gid overflow.
> 
> Signed-off-by: Lijun Ou <oulijun@huawei.com>
>  drivers/infiniband/hw/hns/hns_roce_main.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c
> index 29fb4fb..e3f79d1 100644
> +++ b/drivers/infiniband/hw/hns/hns_roce_main.c
> @@ -81,8 +81,12 @@ static int hns_roce_add_gid(const struct ib_gid_attr *attr, void **context)
>  	unsigned long flags;
>  	int ret;
>  
> -	if (port >= hr_dev->caps.num_ports)
> +	if (port >= hr_dev->caps.num_ports ||
> +	    attr->index > hr_dev->caps.gid_table_len[port]) {
> +		dev_err(hr_dev->dev, "add gid failed. port - %d, index - %d\n",
> +			port, attr->index);
>  		return -EINVAL;
> +	}

The core code already checks these values, drivers should not
duplicate core checks. 

Drop these tests and make sure that
ib_dev->port_data[rdma_port].immutable.gid_tbl_len is right.

Jason
Lijun Ou Feb. 23, 2019, 11:07 a.m. UTC | #2
在 2019/2/23 0:24, Jason Gunthorpe 写道:
> On Fri, Feb 22, 2019 at 12:21:06PM +0800, Lijun Ou wrote:
>> Because hip08 supports up to 256 gids and hip06 supports up to 2 gids, it
>> adds judgement for preventing the gid overflow.
>>
>> Signed-off-by: Lijun Ou <oulijun@huawei.com>
>>  drivers/infiniband/hw/hns/hns_roce_main.c | 6 +++++-
>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c
>> index 29fb4fb..e3f79d1 100644
>> +++ b/drivers/infiniband/hw/hns/hns_roce_main.c
>> @@ -81,8 +81,12 @@ static int hns_roce_add_gid(const struct ib_gid_attr *attr, void **context)
>>  	unsigned long flags;
>>  	int ret;
>>  
>> -	if (port >= hr_dev->caps.num_ports)
>> +	if (port >= hr_dev->caps.num_ports ||
>> +	    attr->index > hr_dev->caps.gid_table_len[port]) {
>> +		dev_err(hr_dev->dev, "add gid failed. port - %d, index - %d\n",
>> +			port, attr->index);
>>  		return -EINVAL;
>> +	}
> The core code already checks these values, drivers should not
> duplicate core checks. 
>
> Drop these tests and make sure that
> ib_dev->port_data[rdma_port].immutable.gid_tbl_len is right.
>
> Jason
>
Yes, the gid_tbl_len is fixed in hns_roce_query_device. This fixes is required by our test team and I was reserved at the time. I will drop it
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c
index 29fb4fb..e3f79d1 100644
--- a/drivers/infiniband/hw/hns/hns_roce_main.c
+++ b/drivers/infiniband/hw/hns/hns_roce_main.c
@@ -81,8 +81,12 @@  static int hns_roce_add_gid(const struct ib_gid_attr *attr, void **context)
 	unsigned long flags;
 	int ret;
 
-	if (port >= hr_dev->caps.num_ports)
+	if (port >= hr_dev->caps.num_ports ||
+	    attr->index > hr_dev->caps.gid_table_len[port]) {
+		dev_err(hr_dev->dev, "add gid failed. port - %d, index - %d\n",
+			port, attr->index);
 		return -EINVAL;
+	}
 
 	spin_lock_irqsave(&hr_dev->iboe.lock, flags);