mirror of https://gitee.com/openkylin/linux.git
net: hns3: Fix tqp array traversal condition for vf
There are two tqp_num variables "hdev->tqp_num" and "kinfo->tqp_num"
used in VF. "hdev->tqp_num" is the total tqp number allocated to the
VF, and "kinfo->tqp_num" indicates the tqp number being used by the
VF. Usually the two variables are equal. But for the case hdev->tqp_num
larger than rss_size_max, and num_tc is 1, "kinfo->tqp_num" will be
less than "hdev->tqp_num".
In original codes, "hdev->tqp_num" is always used to traverse the
tqp array of kinfo. It may cause null pointer error when "hdev->tqp_num"
is larger than "kinfo->tqp_num"
Fixes: e2cb1dec97
("net: hns3: Add HNS3 VF HCL(Hardware Compatibility Layer) Support")
Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
0c21812302
commit
b4f1d30327
|
@ -31,16 +31,15 @@ static inline struct hclgevf_dev *hclgevf_ae_get_hdev(
|
||||||
|
|
||||||
static int hclgevf_tqps_update_stats(struct hnae3_handle *handle)
|
static int hclgevf_tqps_update_stats(struct hnae3_handle *handle)
|
||||||
{
|
{
|
||||||
|
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
|
||||||
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
|
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
|
||||||
struct hnae3_queue *queue;
|
|
||||||
struct hclgevf_desc desc;
|
struct hclgevf_desc desc;
|
||||||
struct hclgevf_tqp *tqp;
|
struct hclgevf_tqp *tqp;
|
||||||
int status;
|
int status;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < hdev->num_tqps; i++) {
|
for (i = 0; i < kinfo->num_tqps; i++) {
|
||||||
queue = handle->kinfo.tqp[i];
|
tqp = container_of(kinfo->tqp[i], struct hclgevf_tqp, q);
|
||||||
tqp = container_of(queue, struct hclgevf_tqp, q);
|
|
||||||
hclgevf_cmd_setup_basic_desc(&desc,
|
hclgevf_cmd_setup_basic_desc(&desc,
|
||||||
HCLGEVF_OPC_QUERY_RX_STATUS,
|
HCLGEVF_OPC_QUERY_RX_STATUS,
|
||||||
true);
|
true);
|
||||||
|
@ -77,17 +76,16 @@ static int hclgevf_tqps_update_stats(struct hnae3_handle *handle)
|
||||||
static u64 *hclgevf_tqps_get_stats(struct hnae3_handle *handle, u64 *data)
|
static u64 *hclgevf_tqps_get_stats(struct hnae3_handle *handle, u64 *data)
|
||||||
{
|
{
|
||||||
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
|
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
|
||||||
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
|
|
||||||
struct hclgevf_tqp *tqp;
|
struct hclgevf_tqp *tqp;
|
||||||
u64 *buff = data;
|
u64 *buff = data;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < hdev->num_tqps; i++) {
|
for (i = 0; i < kinfo->num_tqps; i++) {
|
||||||
tqp = container_of(handle->kinfo.tqp[i], struct hclgevf_tqp, q);
|
tqp = container_of(kinfo->tqp[i], struct hclgevf_tqp, q);
|
||||||
*buff++ = tqp->tqp_stats.rcb_tx_ring_pktnum_rcd;
|
*buff++ = tqp->tqp_stats.rcb_tx_ring_pktnum_rcd;
|
||||||
}
|
}
|
||||||
for (i = 0; i < kinfo->num_tqps; i++) {
|
for (i = 0; i < kinfo->num_tqps; i++) {
|
||||||
tqp = container_of(handle->kinfo.tqp[i], struct hclgevf_tqp, q);
|
tqp = container_of(kinfo->tqp[i], struct hclgevf_tqp, q);
|
||||||
*buff++ = tqp->tqp_stats.rcb_rx_ring_pktnum_rcd;
|
*buff++ = tqp->tqp_stats.rcb_rx_ring_pktnum_rcd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,28 +94,28 @@ static u64 *hclgevf_tqps_get_stats(struct hnae3_handle *handle, u64 *data)
|
||||||
|
|
||||||
static int hclgevf_tqps_get_sset_count(struct hnae3_handle *handle, int strset)
|
static int hclgevf_tqps_get_sset_count(struct hnae3_handle *handle, int strset)
|
||||||
{
|
{
|
||||||
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
|
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
|
||||||
|
|
||||||
return hdev->num_tqps * 2;
|
return kinfo->num_tqps * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u8 *hclgevf_tqps_get_strings(struct hnae3_handle *handle, u8 *data)
|
static u8 *hclgevf_tqps_get_strings(struct hnae3_handle *handle, u8 *data)
|
||||||
{
|
{
|
||||||
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
|
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
|
||||||
u8 *buff = data;
|
u8 *buff = data;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (i = 0; i < hdev->num_tqps; i++) {
|
for (i = 0; i < kinfo->num_tqps; i++) {
|
||||||
struct hclgevf_tqp *tqp = container_of(handle->kinfo.tqp[i],
|
struct hclgevf_tqp *tqp = container_of(kinfo->tqp[i],
|
||||||
struct hclgevf_tqp, q);
|
struct hclgevf_tqp, q);
|
||||||
snprintf(buff, ETH_GSTRING_LEN, "txq%d_pktnum_rcd",
|
snprintf(buff, ETH_GSTRING_LEN, "txq%d_pktnum_rcd",
|
||||||
tqp->index);
|
tqp->index);
|
||||||
buff += ETH_GSTRING_LEN;
|
buff += ETH_GSTRING_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < hdev->num_tqps; i++) {
|
for (i = 0; i < kinfo->num_tqps; i++) {
|
||||||
struct hclgevf_tqp *tqp = container_of(handle->kinfo.tqp[i],
|
struct hclgevf_tqp *tqp = container_of(kinfo->tqp[i],
|
||||||
struct hclgevf_tqp, q);
|
struct hclgevf_tqp, q);
|
||||||
snprintf(buff, ETH_GSTRING_LEN, "rxq%d_pktnum_rcd",
|
snprintf(buff, ETH_GSTRING_LEN, "rxq%d_pktnum_rcd",
|
||||||
tqp->index);
|
tqp->index);
|
||||||
buff += ETH_GSTRING_LEN;
|
buff += ETH_GSTRING_LEN;
|
||||||
|
@ -738,14 +736,12 @@ static int hclgevf_get_queue_id(struct hnae3_queue *queue)
|
||||||
|
|
||||||
static void hclgevf_reset_tqp_stats(struct hnae3_handle *handle)
|
static void hclgevf_reset_tqp_stats(struct hnae3_handle *handle)
|
||||||
{
|
{
|
||||||
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
|
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
|
||||||
struct hnae3_queue *queue;
|
|
||||||
struct hclgevf_tqp *tqp;
|
struct hclgevf_tqp *tqp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < hdev->num_tqps; i++) {
|
for (i = 0; i < kinfo->num_tqps; i++) {
|
||||||
queue = handle->kinfo.tqp[i];
|
tqp = container_of(kinfo->tqp[i], struct hclgevf_tqp, q);
|
||||||
tqp = container_of(queue, struct hclgevf_tqp, q);
|
|
||||||
memset(&tqp->tqp_stats, 0, sizeof(tqp->tqp_stats));
|
memset(&tqp->tqp_stats, 0, sizeof(tqp->tqp_stats));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1420,12 +1416,13 @@ static int hclgevf_init_vlan_config(struct hclgevf_dev *hdev)
|
||||||
|
|
||||||
static int hclgevf_ae_start(struct hnae3_handle *handle)
|
static int hclgevf_ae_start(struct hnae3_handle *handle)
|
||||||
{
|
{
|
||||||
|
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
|
||||||
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
|
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
|
||||||
int i, queue_id;
|
int i, queue_id;
|
||||||
|
|
||||||
for (i = 0; i < handle->kinfo.num_tqps; i++) {
|
for (i = 0; i < kinfo->num_tqps; i++) {
|
||||||
/* ring enable */
|
/* ring enable */
|
||||||
queue_id = hclgevf_get_queue_id(handle->kinfo.tqp[i]);
|
queue_id = hclgevf_get_queue_id(kinfo->tqp[i]);
|
||||||
if (queue_id < 0) {
|
if (queue_id < 0) {
|
||||||
dev_warn(&hdev->pdev->dev,
|
dev_warn(&hdev->pdev->dev,
|
||||||
"Get invalid queue id, ignore it\n");
|
"Get invalid queue id, ignore it\n");
|
||||||
|
@ -1448,14 +1445,15 @@ static int hclgevf_ae_start(struct hnae3_handle *handle)
|
||||||
|
|
||||||
static void hclgevf_ae_stop(struct hnae3_handle *handle)
|
static void hclgevf_ae_stop(struct hnae3_handle *handle)
|
||||||
{
|
{
|
||||||
|
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
|
||||||
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
|
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
|
||||||
int i, queue_id;
|
int i, queue_id;
|
||||||
|
|
||||||
set_bit(HCLGEVF_STATE_DOWN, &hdev->state);
|
set_bit(HCLGEVF_STATE_DOWN, &hdev->state);
|
||||||
|
|
||||||
for (i = 0; i < hdev->num_tqps; i++) {
|
for (i = 0; i < kinfo->num_tqps; i++) {
|
||||||
/* Ring disable */
|
/* Ring disable */
|
||||||
queue_id = hclgevf_get_queue_id(handle->kinfo.tqp[i]);
|
queue_id = hclgevf_get_queue_id(kinfo->tqp[i]);
|
||||||
if (queue_id < 0) {
|
if (queue_id < 0) {
|
||||||
dev_warn(&hdev->pdev->dev,
|
dev_warn(&hdev->pdev->dev,
|
||||||
"Get invalid queue id, ignore it\n");
|
"Get invalid queue id, ignore it\n");
|
||||||
|
|
Loading…
Reference in New Issue