[09/13] net/hns3: fix maximum frame size update after buffer alloc
Checks
Commit Message
From: Chengchang Tang <tangchengchang@huawei.com>
After MTU changed, the buffer used to store packets in HW should be
reallocated. And buffer size is allocated based on the maximum frame
size in the PF struct. However, the value of maximum frame size is
not updated in time when MTU is changed. This would lead to a packet
loss for not enough buffer.
This patch update the maximum frame size before reallocating the HW
buffer. And a rollback operation is added to avoid the side effects
of buffer reallocation failures.
Fixes: 1f5ca0b460cd ("net/hns3: support some device operations")
Fixes: d51867db65c1 ("net/hns3: add initialization")
Cc: stable@dpdk.org
Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
---
drivers/net/hns3/hns3_ethdev.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
Comments
On 2/24/2021 1:28 AM, Lijun Ou wrote:
> From: Chengchang Tang <tangchengchang@huawei.com>
>
> After MTU changed, the buffer used to store packets in HW should be
> reallocated. And buffer size is allocated based on the maximum frame
> size in the PF struct. However, the value of maximum frame size is
> not updated in time when MTU is changed. This would lead to a packet
> loss for not enough buffer.
>
> This patch update the maximum frame size before reallocating the HW
> buffer. And a rollback operation is added to avoid the side effects
> of buffer reallocation failures.
>
> Fixes: 1f5ca0b460cd ("net/hns3: support some device operations")
> Fixes: d51867db65c1 ("net/hns3: add initialization")
> Cc: stable@dpdk.org
>
> Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
> Signed-off-by: Lijun Ou <oulijun@huawei.com>
Isn't the patch title should say 'before', like:
net/hns3: fix maximum frame size update _before_ buffer alloc
Or perhaps I get the patch wrong...
在 2021/2/26 23:25, Ferruh Yigit 写道:
> On 2/24/2021 1:28 AM, Lijun Ou wrote:
>> From: Chengchang Tang <tangchengchang@huawei.com>
>>
>> After MTU changed, the buffer used to store packets in HW should be
>> reallocated. And buffer size is allocated based on the maximum frame
>> size in the PF struct. However, the value of maximum frame size is
>> not updated in time when MTU is changed. This would lead to a packet
>> loss for not enough buffer.
>>
>> This patch update the maximum frame size before reallocating the HW
>> buffer. And a rollback operation is added to avoid the side effects
>> of buffer reallocation failures.
>>
>> Fixes: 1f5ca0b460cd ("net/hns3: support some device operations")
>> Fixes: d51867db65c1 ("net/hns3: add initialization")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
>> Signed-off-by: Lijun Ou <oulijun@huawei.com>
>
> Isn't the patch title should say 'before', like:
> net/hns3: fix maximum frame size update _before_ buffer alloc
>
> Or perhaps I get the patch wrong...
> .
The expression here may vary from different perspectives. From a
hardware standpoint, the problem is that the maximum frame size update
buffer allocation. From a software standpoint, the the buffer size that
should be allocted depends on the maximum frame size kept in the driver,
and the problem is caused by the late value update in the driver.
>
On 2/24/2021 1:28 AM, Lijun Ou wrote:
> From: Chengchang Tang <tangchengchang@huawei.com>
>
> After MTU changed, the buffer used to store packets in HW should be
> reallocated. And buffer size is allocated based on the maximum frame
> size in the PF struct. However, the value of maximum frame size is
> not updated in time when MTU is changed. This would lead to a packet
> loss for not enough buffer.
>
> This patch update the maximum frame size before reallocating the HW
> buffer. And a rollback operation is added to avoid the side effects
> of buffer reallocation failures.
>
> Fixes: 1f5ca0b460cd ("net/hns3: support some device operations")
> Fixes: d51867db65c1 ("net/hns3: add initialization")
> Cc: stable@dpdk.org
>
> Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
> Signed-off-by: Lijun Ou <oulijun@huawei.com>
After the previous 'before/after' confusion, what do you think to update the
patch title as:
net/hns3: fix HW buffer size on MTU update
@@ -2460,17 +2460,33 @@ hns3_set_mac_mtu(struct hns3_hw *hw, uint16_t new_mps)
static int
hns3_config_mtu(struct hns3_hw *hw, uint16_t mps)
{
+ struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
+ uint16_t original_mps = hns->pf.mps;
+ int err;
int ret;
ret = hns3_set_mac_mtu(hw, mps);
if (ret) {
- hns3_err(hw, "Failed to set mtu, ret = %d", ret);
+ hns3_err(hw, "failed to set mtu, ret = %d", ret);
return ret;
}
+ hns->pf.mps = mps;
ret = hns3_buffer_alloc(hw);
- if (ret)
- hns3_err(hw, "Failed to allocate buffer, ret = %d", ret);
+ if (ret) {
+ hns3_err(hw, "failed to allocate buffer, ret = %d", ret);
+ goto rollback;
+ }
+
+ return 0;
+
+rollback:
+ err = hns3_set_mac_mtu(hw, original_mps);
+ if (err) {
+ hns3_err(hw, "fail to rollback MTU, err = %d", err);
+ return ret;
+ }
+ hns->pf.mps = original_mps;
return ret;
}
@@ -2505,7 +2521,7 @@ hns3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
dev->data->port_id, mtu, ret);
return ret;
}
- hns->pf.mps = (uint16_t)frame_size;
+
if (is_jumbo_frame)
dev->data->dev_conf.rxmode.offloads |=
DEV_RX_OFFLOAD_JUMBO_FRAME;