bugfix some driver issues
Longfang Liu
maintainerv4 cover bugfix some driver issues
As the test scenarios for the live migration function become more and more extensive. Some previously undiscovered driver issues were found.
Update and fix through this patchset.
Change v3 -> v4
Modify version matching scheme
Change v2 -> v3
Modify the magic digital field segment
Change v1 -> v2
Add fixes line for patch comment
Longfang Liu (5):
hisi_acc_vfio_pci: fix XQE dma address error
hisi_acc_vfio_pci: add eq and aeq interruption restore
hisi_acc_vfio_pci: bugfix cache write-back issue
hisi_acc_vfio_pci: bugfix the problem of uninstalling driver
hisi_acc_vfio_pci: bugfix live migration function without VF device
driver
.../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 89 ++++++++++++++++--- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.h | 14 ++- 2 files changed, 88 insertions(+), 15 deletions(-)
Signature · 1 line
2.24.0
Longfang Liu
maintainerPATCH v4 1/5 hisi_acc_vfio_pci: fix XQE dma address error
The dma addresses of EQE and AEQE are wrong after migration and results in guest kernel-mode encryption services failure. Comparing the definition of hardware registers, we found that there was an error when the data read from the register was combined into an address. Therefore, the address combination sequence needs to be corrected.
Even after fixing the above problem, we still have an issue where the Guest from an old kernel can get migrated to new kernel and may result in wrong data.
In order to ensure that the address is correct after migration, if an old magic number is detected, the dma address needs to be updated.
--- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 40 ++++++++++++++++--- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.h | 14 ++++++- 2 files changed, 46 insertions(+), 8 deletions(-)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +34 -6
@@ -350,6 +350,31 @@ static int vf_qm_func_stop(struct hisi_qm *qm)return hisi_qm_mb (qm,QM_MB_CMD_PAUSE_QM ,0 ,0 ,0 ); } +static int vf_qm_version_check (struct acc_vf_data *vf_data,struct device *dev) +{ +switch (vf_data->acc_magic) { +case ACC_DEV_MAGIC_V2 : +if (vf_data->major_ver <ACC_DRV_MAJOR_VER || + vf_data->minor_ver <ACC_DRV_MINOR_VER ) +dev_info (dev,"migration driver version not match!\n" ); +return -EINVAL ; +break ; +case ACC_DEV_MAGIC_V1 : +/* Correct dma address */ + vf_data->eqe_dma = vf_data->qm_eqc_dw[QM_XQC_ADDR_HIGH ]; + vf_data->eqe_dma <<=QM_XQC_ADDR_OFFSET ; + vf_data->eqe_dma |= vf_data->qm_eqc_dw[QM_XQC_ADDR_LOW ]; + vf_data->aeqe_dma = vf_data->qm_aeqc_dw[QM_XQC_ADDR_HIGH ]; + vf_data->aeqe_dma <<=QM_XQC_ADDR_OFFSET ; + vf_data->aeqe_dma |= vf_data->qm_aeqc_dw[QM_XQC_ADDR_LOW ]; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} +static int vf_qm_check_match (struct hisi_acc_vf_core_device *hisi_acc_vdev,struct hisi_acc_vf_migration_file *migf) {
@@ -363,7 +388,8 @@ static int vf_qm_check_match(struct hisi_acc_vf_core_device *hisi_acc_vdev,if (migf->total_length <QM_MATCH_SIZE || hisi_acc_vdev->match_done)return 0 ; -if (vf_data->acc_magic !=ACC_DEV_MAGIC ) { + ret =vf_qm_version_check (vf_data, dev); +if (ret) {dev_err (dev,"failed to match ACC_DEV_MAGIC\n" );return -EINVAL ; }
@@ -418,7 +444,9 @@ static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev,int vf_id = hisi_acc_vdev->vf_id;int ret; - vf_data->acc_magic =ACC_DEV_MAGIC ; + vf_data->acc_magic =ACC_DEV_MAGIC_V2 ; + vf_data->major_ver =ACC_DRV_MAR ; + vf_data->minor_ver =ACC_DRV_MIN ;/* Save device id */ vf_data->dev_id = hisi_acc_vdev->vf_dev->device;
@@ -496,12 +524,12 @@ static int vf_qm_read_data(struct hisi_qm *vf_qm, struct acc_vf_data *vf_data)return -EINVAL ;/* Every reg is 32 bit, the dma address is 64 bit. */ - vf_data->eqe_dma = vf_data->qm_eqc_dw[1 ]; + vf_data->eqe_dma = vf_data->qm_eqc_dw[QM_XQC_ADDR_HIGH ]; vf_data->eqe_dma <<=QM_XQC_ADDR_OFFSET ; - vf_data->eqe_dma |= vf_data->qm_eqc_dw[0 ]; - vf_data->aeqe_dma = vf_data->qm_aeqc_dw[1 ]; + vf_data->eqe_dma |= vf_data->qm_eqc_dw[QM_XQC_ADDR_LOW ]; + vf_data->aeqe_dma = vf_data->qm_aeqc_dw[QM_XQC_ADDR_HIGH ]; vf_data->aeqe_dma <<=QM_XQC_ADDR_OFFSET ; - vf_data->aeqe_dma |= vf_data->qm_aeqc_dw[0 ]; + vf_data->aeqe_dma |= vf_data->qm_aeqc_dw[QM_XQC_ADDR_LOW ];/* Through SQC_BT/CQC_BT to get sqc and cqc address */ ret =qm_get_sqc (vf_qm, &vf_data->sqc_dma);
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h +12 -2
@@ -39,6 +39,9 @@#define QM_REG_ADDR_OFFSET 0x0004#define QM_XQC_ADDR_OFFSET 32U +#define QM_XQC_ADDR_LOW 0x1 +#define QM_XQC_ADDR_HIGH 0x2 +#define QM_VF_AEQ_INT_MASK 0x0004#define QM_VF_EQ_INT_MASK 0x000c#define QM_IFC_INT_SOURCE_V 0x0020
@@ -50,10 +53,15 @@#define QM_EQC_DW0 0X8000#define QM_AEQC_DW0 0X8020 +#define ACC_DRV_MAJOR_VER 1 +#define ACC_DRV_MINOR_VER 0 + +#define ACC_DEV_MAGIC_V1 0XCDCDCDCDFEEDAACC +#define ACC_DEV_MAGIC_V2 0xAACCFEEDDECADEDE +struct acc_vf_data {#define QM_MATCH_SIZE offsetofend(struct acc_vf_data, qm_rsv_state)/* QM match information */ -#define ACC_DEV_MAGIC 0XCDCDCDCDFEEDAACCu64 acc_magic;u32 qp_num;u32 dev_id;
@@ -61,7 +69,9 @@ struct acc_vf_data {u32 qp_base;u32 vf_qm_state;/* QM reserved match information */ -u32 qm_rsv_state[3 ]; +u16 major_ver; +u16 minor_ver; +u32 qm_rsv_state[2 ];/* QM RW regs */ u32 aeq_int_mask;
Signature · 1 line
2.24.0
Re: [PATCH v4 1/5] hisi_acc_vfio_pci: fix XQE dma address error
Quoted 29 lines · On Tue, 25 Feb 2025 14:27:53 +0800 Longfang Liu <[email protected]> wrote:
The dma addresses of EQE and AEQE are wrong after migration and results in guest kernel-mode encryption services failure. Comparing the definition of hardware registers, we found that there was an error when the data read from the register was combined into an address. Therefore, the address combination sequence needs to be corrected.
Even after fixing the above problem, we still have an issue where the Guest from an old kernel can get migrated to new kernel and may result in wrong data.
In order to ensure that the address is correct after migration, if an old magic number is detected, the dma address needs to be updated.
Fixes b0eed085903e ("hisi_acc_vfio_pci: Add support for VFIO live migration")Signed-off-by Longfang Liu <[email protected]>--- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 40 ++++++++++++++++--- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.h | 14 ++++++- 2 files changed, 46 insertions(+), 8 deletions(-)drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +0
-0@@ -350,6 +350,31 @@ static int vf_qm_func_stop(struct hisi_qm *qm)return hisi_qm_mb (qm,QM_MB_CMD_PAUSE_QM ,0 ,0 ,0 ); }
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_func_stop(struct hisi_qm *qm) · line 361
Quoted 10 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +9
-0+static int vf_qm_version_check (struct acc_vf_data *vf_data,struct device *dev) +{ +switch (vf_data->acc_magic) { +case ACC_DEV_MAGIC_V2 : +if (vf_data->major_ver <ACC_DRV_MAJOR_VER || + vf_data->minor_ver <ACC_DRV_MINOR_VER ) +dev_info (dev,"migration driver version not match!\n" ); +return -EINVAL ; +break ;
What's your major/minor update strategy?
Note that minor_ver is a u16 and ACC_DRV_MINOR_VER is defined as 0, so testing less than 0 against an unsigned is useless.
Arguably testing major and minor independently is pretty useless too.
You're defining what a future "old" driver version will accept, which is very nearly anything, so any breaking change *again* requires a new magic, so we're accomplishing very little here.
Maybe you want to consider a strategy where you'd increment the major number for a breaking change and minor for a compatible feature. In that case you'd want to verify the major_ver matches ACC_DRV_MAJOR_VER exactly and minor_ver would be more of a feature level.
Quoted 30 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +18
-1+case ACC_DEV_MAGIC_V1 : +/* Correct dma address */ + vf_data->eqe_dma = vf_data->qm_eqc_dw[QM_XQC_ADDR_HIGH ]; + vf_data->eqe_dma <<=QM_XQC_ADDR_OFFSET ; + vf_data->eqe_dma |= vf_data->qm_eqc_dw[QM_XQC_ADDR_LOW ]; + vf_data->aeqe_dma = vf_data->qm_aeqc_dw[QM_XQC_ADDR_HIGH ]; + vf_data->aeqe_dma <<=QM_XQC_ADDR_OFFSET ; + vf_data->aeqe_dma |= vf_data->qm_aeqc_dw[QM_XQC_ADDR_LOW ]; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} +static int vf_qm_check_match (struct hisi_acc_vf_core_device *hisi_acc_vdev,struct hisi_acc_vf_migration_file *migf) {@@ -363,7 +388,8 @@ static int vf_qm_check_match(struct hisi_acc_vf_core_device *hisi_acc_vdev,if (migf->total_length <QM_MATCH_SIZE || hisi_acc_vdev->match_done)return 0 ; -if (vf_data->acc_magic !=ACC_DEV_MAGIC ) { + ret =vf_qm_version_check (vf_data, dev); +if (ret) {dev_err (dev,"failed to match ACC_DEV_MAGIC\n" );return -EINVAL ; }
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev, · line 449
Quoted 7 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +3
-1@@ -418,7 +444,9 @@ static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev,int vf_id = hisi_acc_vdev->vf_id;int ret; - vf_data->acc_magic =ACC_DEV_MAGIC ; + vf_data->acc_magic =ACC_DEV_MAGIC_V2 ; + vf_data->major_ver =ACC_DRV_MAR ; + vf_data->minor_ver =ACC_DRV_MIN ;
Where are "MAR" and "MIN" defined? I can't see how this would even compile. Thanks,
Alex
Quoted 62 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +4
-4/* Save device id */ vf_data->dev_id = hisi_acc_vdev->vf_dev->device;@@ -496,12 +524,12 @@ static int vf_qm_read_data(struct hisi_qm *vf_qm, struct acc_vf_data *vf_data)return -EINVAL ;/* Every reg is 32 bit, the dma address is 64 bit. */ - vf_data->eqe_dma = vf_data->qm_eqc_dw[1 ]; + vf_data->eqe_dma = vf_data->qm_eqc_dw[QM_XQC_ADDR_HIGH ]; vf_data->eqe_dma <<=QM_XQC_ADDR_OFFSET ; - vf_data->eqe_dma |= vf_data->qm_eqc_dw[0 ]; - vf_data->aeqe_dma = vf_data->qm_aeqc_dw[1 ]; + vf_data->eqe_dma |= vf_data->qm_eqc_dw[QM_XQC_ADDR_LOW ]; + vf_data->aeqe_dma = vf_data->qm_aeqc_dw[QM_XQC_ADDR_HIGH ]; vf_data->aeqe_dma <<=QM_XQC_ADDR_OFFSET ; - vf_data->aeqe_dma |= vf_data->qm_aeqc_dw[0 ]; + vf_data->aeqe_dma |= vf_data->qm_aeqc_dw[QM_XQC_ADDR_LOW ];/* Through SQC_BT/CQC_BT to get sqc and cqc address */ ret =qm_get_sqc (vf_qm, &vf_data->sqc_dma);drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h +12
-2@@ -39,6 +39,9 @@#define QM_REG_ADDR_OFFSET 0x0004#define QM_XQC_ADDR_OFFSET 32U +#define QM_XQC_ADDR_LOW 0x1 +#define QM_XQC_ADDR_HIGH 0x2 +#define QM_VF_AEQ_INT_MASK 0x0004#define QM_VF_EQ_INT_MASK 0x000c#define QM_IFC_INT_SOURCE_V 0x0020@@ -50,10 +53,15 @@#define QM_EQC_DW0 0X8000#define QM_AEQC_DW0 0X8020 +#define ACC_DRV_MAJOR_VER 1 +#define ACC_DRV_MINOR_VER 0 + +#define ACC_DEV_MAGIC_V1 0XCDCDCDCDFEEDAACC +#define ACC_DEV_MAGIC_V2 0xAACCFEEDDECADEDE +struct acc_vf_data {#define QM_MATCH_SIZE offsetofend(struct acc_vf_data, qm_rsv_state)/* QM match information */ -#define ACC_DEV_MAGIC 0XCDCDCDCDFEEDAACCu64 acc_magic;u32 qp_num;u32 dev_id;@@ -61,7 +69,9 @@ struct acc_vf_data {u32 qp_base;u32 vf_qm_state;/* QM reserved match information */ -u32 qm_rsv_state[3 ]; +u16 major_ver; +u16 minor_ver; +u32 qm_rsv_state[2 ];/* QM RW regs */ u32 aeq_int_mask;
RE: [PATCH v4 1/5] hisi_acc_vfio_pci: fix XQE dma address error
Quoted 70 lines
-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Wednesday, February 26, 2025 12:10 AM
To: liulongfang <[email protected]>
Cc: [email protected]; Shameerali Kolothum Thodi <[email protected]>; Jonathan Cameron <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v4 1/5]hisi_acc_vfio_pci: fix XQE dma address errorQuoted 11 lines · On Tue, 25 Feb 2025 14:27:53 +0800 Longfang Liu <[email protected]> wrote:
The dma addresses of EQE and AEQE are wrong after migration and results in guest kernel-mode encryption services failure. Comparing the definition of hardware registers, we found that there was an error when the data read from the register was combined into an address. Therefore, the address combination sequence needs to be corrected.
Even after fixing the above problem, we still have an issue where the Guest from an old kernel can get migrated to new kernel and may result in wrong data.
Quoted 5 lines
In order to ensure that the address is correct after migration, if an old magic number is detected, the dma address needs to be updated.
Fixes b0eed085903e ("hisi_acc_vfio_pci: Add support for VFIO livemigration")
Review
Quoted 7 lines
Signed-off-by Longfang Liu <[email protected]>--- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 40 ++++++++++++++++--- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.h | 14 ++++++- 2 files changed, 46 insertions(+), 8 deletions(-)(quoted diff) +0
-0
b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.cdrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_func_stop(struct hisi_qm *qm) · line 353
Quoted 8 lines
index
451c639299eb..35316984089b100644drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +1
-0@@ -350,6 +350,31 @@ static int vf_qm_func_stop(struct hisi_qm *qm)return hisi_qm_mb (qm,QM_MB_CMD_PAUSE_QM ,0 ,0 ,0 ); } +static int vf_qm_version_check(struct acc_vf_data *vf_data, struct device*dev)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_func_stop(struct hisi_qm *qm)
Quoted 6 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +6
-0+{ +switch (vf_data->acc_magic) { +case ACC_DEV_MAGIC_V2 : +if (vf_data->major_ver <ACC_DRV_MAJOR_VER || + vf_data->minor_ver <ACC_DRV_MINOR_VER ) + dev_info(dev, "migration driver version notmatch!\n");
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_func_stop(struct hisi_qm *qm) · line 361
Quoted 2 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +2
-0+return -EINVAL ; +break ;What's your major/minor update strategy?
Note that
minor_veris a u16 andACC_DRV_MINOR_VERis defined as 0, so testing less than 0 against an unsigned is useless.Arguably testing major and minor independently is pretty useless too.
You're defining what a future "old" driver version will accept, which is very nearly anything, so any breaking change *again* requires a new magic, so we're accomplishing very little here.
Quoted 5 lines
Maybe you want to consider a strategy where you'd increment the major number for a breaking change and minor for a compatible feature. In that case you'd want to verify the
major_vermatchesACC_DRV_MAJOR_VER
exactly andminor_verwould be more of a feature level.
Agree. I think the above check should be just major_ver != ACC_DRV_MAJOR_VER and we can make use of minor version whenever we need a specific handling for a feature support.
Also I think it would be good to print the version info above in case of mismatch.
Quoted 42 lines
Quoted 13 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +8
-0+case ACC_DEV_MAGIC_V1 : +/* Correct dma address */ + vf_data->eqe_dma = vf_data- qm_eqc_dw[QM_XQC_ADDR_HIGH ]; + vf_data->eqe_dma <<=QM_XQC_ADDR_OFFSET ; + vf_data->eqe_dma |= vf_data- qm_eqc_dw[QM_XQC_ADDR_LOW ]; + vf_data->aeqe_dma = vf_data- qm_aeqc_dw[QM_XQC_ADDR_HIGH ]; + vf_data->aeqe_dma <<=QM_XQC_ADDR_OFFSET ; + vf_data->aeqe_dma |= vf_data-qm_aeqc_dw[QM_XQC_ADDR_LOW];
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_func_stop(struct hisi_qm *qm)
Quoted 9 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +8
-0+break ; +default : +return -EINVAL ; + } + +return 0 ; +} + static int vf_qm_check_match(struct hisi_acc_vf_core_device
*hisi_acc_vdev,drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_check_match(struct
Quoted 3 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +0
-0struct hisi_acc_vf_migration_file *migf) {@@ -363,7 +388,8 @@ static int vf_qm_check_match(struct
hisi_acc_vf_core_device*hisi_acc_vdev,drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_get_match_data(struct
Quoted 11 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +2
-1if (migf->total_length <QM_MATCH_SIZE || hisi_acc_vdev- match_done)return 0 ; -if (vf_data->acc_magic !=ACC_DEV_MAGIC ) { + ret =vf_qm_version_check (vf_data, dev); +if (ret) {dev_err (dev,"failed to match ACC_DEV_MAGIC\n" );return -EINVAL ;drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +0
-0}@@ -418,7 +444,9 @@ static int vf_qm_get_match_data(struct
hisi_acc_vf_core_device*hisi_acc_vdev,Quoted 3 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +0
-0int vf_id = hisi_acc_vdev->vf_id;int ret;
Quoted 7 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev, · line 449
Quoted 4 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +3
-1- vf_data->acc_magic =ACC_DEV_MAGIC ; + vf_data->acc_magic =ACC_DEV_MAGIC_V2 ; + vf_data->major_ver =ACC_DRV_MAR ; + vf_data->minor_ver =ACC_DRV_MIN ;Where are "MAR" and "MIN" defined? I can't see how this would even compile. Thanks,
Yes. Please make sure to do a compile test and run basic sanity tested even if you think the changes are minor. Chances are there that you will miss out things like this.
Thanks,
Shameer
liulongfang
maintainerRe: [PATCH v4 1/5] hisi_acc_vfio_pci: fix XQE dma address error
Quoted 76 lines · Shameerali Kolothum Thodi
Quoted 70 lines
-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Wednesday, February 26, 2025 12:10 AM
To: liulongfang <[email protected]>
Cc: [email protected]; Shameerali Kolothum Thodi <[email protected]>; Jonathan Cameron <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v4 1/5]hisi_acc_vfio_pci: fix XQE dma address errorQuoted 11 lines · On Tue, 25 Feb 2025 14:27:53 +0800 Longfang Liu <[email protected]> wrote:
The dma addresses of EQE and AEQE are wrong after migration and results in guest kernel-mode encryption services failure. Comparing the definition of hardware registers, we found that there was an error when the data read from the register was combined into an address. Therefore, the address combination sequence needs to be corrected.
Even after fixing the above problem, we still have an issue where the Guest from an old kernel can get migrated to new kernel and may result in wrong data.
Quoted 5 lines
In order to ensure that the address is correct after migration, if an old magic number is detected, the dma address needs to be updated.
Fixes b0eed085903e ("hisi_acc_vfio_pci: Add support for VFIO livemigration")
Review
Quoted 7 lines
Signed-off-by Longfang Liu <[email protected]>--- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 40 ++++++++++++++++--- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.h | 14 ++++++- 2 files changed, 46 insertions(+), 8 deletions(-)(quoted diff) +0
-0
b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.cdrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_func_stop(struct hisi_qm *qm) · line 353
Quoted 8 lines
index
451c639299eb..35316984089b100644drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +1
-0@@ -350,6 +350,31 @@ static int vf_qm_func_stop(struct hisi_qm *qm)return hisi_qm_mb (qm,QM_MB_CMD_PAUSE_QM ,0 ,0 ,0 ); } +static int vf_qm_version_check(struct acc_vf_data *vf_data, struct device*dev)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_func_stop(struct hisi_qm *qm)
Quoted 6 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +6
-0+{ +switch (vf_data->acc_magic) { +case ACC_DEV_MAGIC_V2 : +if (vf_data->major_ver <ACC_DRV_MAJOR_VER || + vf_data->minor_ver <ACC_DRV_MINOR_VER ) + dev_info(dev, "migration driver version notmatch!\n");
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_func_stop(struct hisi_qm *qm) · line 361
Quoted 2 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +2
-0+return -EINVAL ; +break ;What's your major/minor update strategy?
Note that
minor_veris a u16 andACC_DRV_MINOR_VERis defined as 0, so testing less than 0 against an unsigned is useless.Arguably testing major and minor independently is pretty useless too.
You're defining what a future "old" driver version will accept, which is very nearly anything, so any breaking change *again* requires a new magic, so we're accomplishing very little here.
Quoted 5 lines
Maybe you want to consider a strategy where you'd increment the major number for a breaking change and minor for a compatible feature. In that case you'd want to verify the
major_vermatchesACC_DRV_MAJOR_VER
exactly andminor_verwould be more of a feature level.
Quoted 4 lines
Agree. I think the above check should be just
major_ver!=ACC_DRV_MAJOR_VERand we can make use of minor version whenever we need a specific handling for a feature support.
Well, that's a good way.
We only use minor_ver to record important updates of the driver. When there is an important update, minor_ver increases by 1.Major_ver is used to distinguish migration versions. After major_ver is updated, minor_ver returns to 0.
Therefore, we can change it to only check major_ver.
Quoted 2 lines
Also I think it would be good to print the version info above in case of mismatch.
OK.
Thanks.
Longfang.
Quoted 59 lines
Quoted 42 lines
Quoted 13 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +8
-0+case ACC_DEV_MAGIC_V1 : +/* Correct dma address */ + vf_data->eqe_dma = vf_data- qm_eqc_dw[QM_XQC_ADDR_HIGH ]; + vf_data->eqe_dma <<=QM_XQC_ADDR_OFFSET ; + vf_data->eqe_dma |= vf_data- qm_eqc_dw[QM_XQC_ADDR_LOW ]; + vf_data->aeqe_dma = vf_data- qm_aeqc_dw[QM_XQC_ADDR_HIGH ]; + vf_data->aeqe_dma <<=QM_XQC_ADDR_OFFSET ; + vf_data->aeqe_dma |= vf_data-qm_aeqc_dw[QM_XQC_ADDR_LOW];
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_func_stop(struct hisi_qm *qm)
Quoted 9 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +8
-0+break ; +default : +return -EINVAL ; + } + +return 0 ; +} + static int vf_qm_check_match(struct hisi_acc_vf_core_device
*hisi_acc_vdev,drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_check_match(struct
Quoted 3 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +0
-0struct hisi_acc_vf_migration_file *migf) {@@ -363,7 +388,8 @@ static int vf_qm_check_match(struct
hisi_acc_vf_core_device*hisi_acc_vdev,drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_get_match_data(struct
Quoted 11 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +2
-1if (migf->total_length <QM_MATCH_SIZE || hisi_acc_vdev- match_done)return 0 ; -if (vf_data->acc_magic !=ACC_DEV_MAGIC ) { + ret =vf_qm_version_check (vf_data, dev); +if (ret) {dev_err (dev,"failed to match ACC_DEV_MAGIC\n" );return -EINVAL ;drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +0
-0}@@ -418,7 +444,9 @@ static int vf_qm_get_match_data(struct
hisi_acc_vf_core_device*hisi_acc_vdev,Quoted 3 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +0
-0int vf_id = hisi_acc_vdev->vf_id;int ret;Quoted 7 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev, · line 449
Quoted 4 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +3
-1- vf_data->acc_magic =ACC_DEV_MAGIC ; + vf_data->acc_magic =ACC_DEV_MAGIC_V2 ; + vf_data->major_ver =ACC_DRV_MAR ; + vf_data->minor_ver =ACC_DRV_MIN ;Where are "MAR" and "MIN" defined? I can't see how this would even compile. Thanks,
Yes. Please make sure to do a compile test and run basic sanity tested even if you think the changes are minor. Chances are there that you will miss out things like this.
Thanks,
Shameer.
liulongfang
maintainerRe: [PATCH v4 1/5] hisi_acc_vfio_pci: fix XQE dma address error
In reply to Longfang LiuQuoted 69 lines · Longfang Liu
The dma addresses of EQE and AEQE are wrong after migration and results in guest kernel-mode encryption services failure. Comparing the definition of hardware registers, we found that there was an error when the data read from the register was combined into an address. Therefore, the address combination sequence needs to be corrected.
Even after fixing the above problem, we still have an issue where the Guest from an old kernel can get migrated to new kernel and may result in wrong data.
In order to ensure that the address is correct after migration, if an old magic number is detected, the dma address needs to be updated.
Fixes b0eed085903e ("hisi_acc_vfio_pci: Add support for VFIO live migration")Signed-off-by Longfang Liu <[email protected]>--- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 40 ++++++++++++++++--- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.h | 14 ++++++- 2 files changed, 46 insertions(+), 8 deletions(-)drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +27
-1@@ -350,6 +350,31 @@ static int vf_qm_func_stop(struct hisi_qm *qm)return hisi_qm_mb (qm,QM_MB_CMD_PAUSE_QM ,0 ,0 ,0 ); } +static int vf_qm_version_check (struct acc_vf_data *vf_data,struct device *dev) +{ +switch (vf_data->acc_magic) { +case ACC_DEV_MAGIC_V2 : +if (vf_data->major_ver <ACC_DRV_MAJOR_VER || + vf_data->minor_ver <ACC_DRV_MINOR_VER ) +dev_info (dev,"migration driver version not match!\n" ); +return -EINVAL ; +break ; +case ACC_DEV_MAGIC_V1 : +/* Correct dma address */ + vf_data->eqe_dma = vf_data->qm_eqc_dw[QM_XQC_ADDR_HIGH ]; + vf_data->eqe_dma <<=QM_XQC_ADDR_OFFSET ; + vf_data->eqe_dma |= vf_data->qm_eqc_dw[QM_XQC_ADDR_LOW ]; + vf_data->aeqe_dma = vf_data->qm_aeqc_dw[QM_XQC_ADDR_HIGH ]; + vf_data->aeqe_dma <<=QM_XQC_ADDR_OFFSET ; + vf_data->aeqe_dma |= vf_data->qm_aeqc_dw[QM_XQC_ADDR_LOW ]; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} +static int vf_qm_check_match (struct hisi_acc_vf_core_device *hisi_acc_vdev,struct hisi_acc_vf_migration_file *migf) {@@ -363,7 +388,8 @@ static int vf_qm_check_match(struct hisi_acc_vf_core_device *hisi_acc_vdev,if (migf->total_length <QM_MATCH_SIZE || hisi_acc_vdev->match_done)return 0 ; -if (vf_data->acc_magic !=ACC_DEV_MAGIC ) { + ret =vf_qm_version_check (vf_data, dev); +if (ret) {dev_err (dev,"failed to match ACC_DEV_MAGIC\n" );return -EINVAL ; }
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev, · line 449
Quoted 7 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +3
-1@@ -418,7 +444,9 @@ static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev,int vf_id = hisi_acc_vdev->vf_id;int ret; - vf_data->acc_magic =ACC_DEV_MAGIC ; + vf_data->acc_magic =ACC_DEV_MAGIC_V2 ; + vf_data->major_ver =ACC_DRV_MAR ; + vf_data->minor_ver =ACC_DRV_MIN ;
The values here should be ACC_DRV_MAJOR_VER and ACC_DRV_MINOR_VER I will fix this in the next version.
Thanks.
Longfang.
Quoted 63 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +4
-4/* Save device id */ vf_data->dev_id = hisi_acc_vdev->vf_dev->device;@@ -496,12 +524,12 @@ static int vf_qm_read_data(struct hisi_qm *vf_qm, struct acc_vf_data *vf_data)return -EINVAL ;/* Every reg is 32 bit, the dma address is 64 bit. */ - vf_data->eqe_dma = vf_data->qm_eqc_dw[1 ]; + vf_data->eqe_dma = vf_data->qm_eqc_dw[QM_XQC_ADDR_HIGH ]; vf_data->eqe_dma <<=QM_XQC_ADDR_OFFSET ; - vf_data->eqe_dma |= vf_data->qm_eqc_dw[0 ]; - vf_data->aeqe_dma = vf_data->qm_aeqc_dw[1 ]; + vf_data->eqe_dma |= vf_data->qm_eqc_dw[QM_XQC_ADDR_LOW ]; + vf_data->aeqe_dma = vf_data->qm_aeqc_dw[QM_XQC_ADDR_HIGH ]; vf_data->aeqe_dma <<=QM_XQC_ADDR_OFFSET ; - vf_data->aeqe_dma |= vf_data->qm_aeqc_dw[0 ]; + vf_data->aeqe_dma |= vf_data->qm_aeqc_dw[QM_XQC_ADDR_LOW ];/* Through SQC_BT/CQC_BT to get sqc and cqc address */ ret =qm_get_sqc (vf_qm, &vf_data->sqc_dma);drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h +12
-2@@ -39,6 +39,9 @@#define QM_REG_ADDR_OFFSET 0x0004#define QM_XQC_ADDR_OFFSET 32U +#define QM_XQC_ADDR_LOW 0x1 +#define QM_XQC_ADDR_HIGH 0x2 +#define QM_VF_AEQ_INT_MASK 0x0004#define QM_VF_EQ_INT_MASK 0x000c#define QM_IFC_INT_SOURCE_V 0x0020@@ -50,10 +53,15 @@#define QM_EQC_DW0 0X8000#define QM_AEQC_DW0 0X8020 +#define ACC_DRV_MAJOR_VER 1 +#define ACC_DRV_MINOR_VER 0 + +#define ACC_DEV_MAGIC_V1 0XCDCDCDCDFEEDAACC +#define ACC_DEV_MAGIC_V2 0xAACCFEEDDECADEDE +struct acc_vf_data {#define QM_MATCH_SIZE offsetofend(struct acc_vf_data, qm_rsv_state)/* QM match information */ -#define ACC_DEV_MAGIC 0XCDCDCDCDFEEDAACCu64 acc_magic;u32 qp_num;u32 dev_id;@@ -61,7 +69,9 @@ struct acc_vf_data {u32 qp_base;u32 vf_qm_state;/* QM reserved match information */ -u32 qm_rsv_state[3 ]; +u16 major_ver; +u16 minor_ver; +u32 qm_rsv_state[2 ];/* QM RW regs */ u32 aeq_int_mask;
kernel test robot
build botRe: [PATCH v4 1/5] hisi_acc_vfio_pci: fix XQE dma address error
In reply to Longfang Liukernel test robot noticed the following build warnings:
Hi Longfang,
kernel test robot noticed the following build warnings:
[auto build test WARNING on awilliam-vfio/next]
[also build test WARNING on awilliam-vfio/for-linus linus/master v6.14-rc4 next-20250227] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Longfang-Liu/hisi_acc_vfio_pci-fix-XQE-dma-address-error/20250225-143347 base: https://github.com/awilliam/linux-vfio.git next patch link: https://lore.kernel.org/r/20250225062757.19692-2-liulongfang%40huawei.com patch subject: [PATCH v4 1/5] hisi_acc_vfio_pci: fix XQE dma address error config: loongarch-allyesconfig (https://download.01.org/0day-ci/archive/20250228/[email protected]/config) compiler: loongarch64-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250228/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c: In function 'vf_qm_version_check':
>> drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:357:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
357 | if (vf_data->major_ver < ACC_DRV_MAJOR_VER ||
| ^~
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:360:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
360 | return -EINVAL;
| ^~~~~~
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c: In function 'vf_qm_get_match_data':
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:448:30: error: 'ACC_DRV_MAR' undeclared (first use in this function)
448 | vf_data->major_ver = ACC_DRV_MAR;
| ^~~~~~~~~~~
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:448:30: note: each undeclared identifier is reported only once for each function it appears in
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:449:30: error: 'ACC_DRV_MIN' undeclared (first use in this function)
449 | vf_data->minor_ver = ACC_DRV_MIN;
| ^~~~~~~~~~~vim +/if +357 drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
352
353 static int vf_qm_version_check(struct acc_vf_data *vf_data, struct device *dev)
354 {
355 switch (vf_data->acc_magic) {
356 case ACC_DEV_MAGIC_V2:
> 357 if (vf_data->major_ver < ACC_DRV_MAJOR_VER ||
358 vf_data->minor_ver < ACC_DRV_MINOR_VER)
359 dev_info(dev, "migration driver version not match!\n");
360 return -EINVAL;
361 break;
362 case ACC_DEV_MAGIC_V1:
363 /* Correct dma address */
364 vf_data->eqe_dma = vf_data->qm_eqc_dw[QM_XQC_ADDR_HIGH];
365 vf_data->eqe_dma <<= QM_XQC_ADDR_OFFSET;
366 vf_data->eqe_dma |= vf_data->qm_eqc_dw[QM_XQC_ADDR_LOW];
367 vf_data->aeqe_dma = vf_data->qm_aeqc_dw[QM_XQC_ADDR_HIGH];
368 vf_data->aeqe_dma <<= QM_XQC_ADDR_OFFSET;
369 vf_data->aeqe_dma |= vf_data->qm_aeqc_dw[QM_XQC_ADDR_LOW];
370 break;
371 default:
372 return -EINVAL;
373 }
374
375 return 0;
376 }
377
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v4 1/5] hisi_acc_vfio_pci: fix XQE dma address error
In reply to Longfang Liukernel test robot noticed the following build errors:
Hi Longfang,
kernel test robot noticed the following build errors:
[auto build test ERROR on awilliam-vfio/next]
[also build test ERROR on awilliam-vfio/for-linus linus/master v6.14-rc4 next-20250227] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Longfang-Liu/hisi_acc_vfio_pci-fix-XQE-dma-address-error/20250225-143347 base: https://github.com/awilliam/linux-vfio.git next patch link: https://lore.kernel.org/r/20250225062757.19692-2-liulongfang%40huawei.com patch subject: [PATCH v4 1/5] hisi_acc_vfio_pci: fix XQE dma address error config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20250228/[email protected]/config) compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250228/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:9:
In file included from include/linux/hisi_acc_qm.h:10:
In file included from include/linux/pci.h:1644:
In file included from include/linux/dmapool.h:14:
In file included from include/linux/scatterlist.h:8:
In file included from include/linux/mm.h:2224:
include/linux/vmstat.h:504:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
504 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
505 | item];
| ~~~~
include/linux/vmstat.h:511:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
511 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
512 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
include/linux/vmstat.h:524:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
524 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
525 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
>> drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:448:23: error: use of undeclared identifier 'ACC_DRV_MAR'
448 | vf_data->major_ver = ACC_DRV_MAR;
| ^
>> drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:449:23: error: use of undeclared identifier 'ACC_DRV_MIN'
449 | vf_data->minor_ver = ACC_DRV_MIN;
| ^3 warnings and 2 errors generated.
vim +/ACC_DRV_MAR +448 drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
438
439 static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev,
440 struct acc_vf_data *vf_data)
441 {
442 struct hisi_qm *pf_qm = hisi_acc_vdev->pf_qm;
443 struct device *dev = &pf_qm->pdev->dev;
444 int vf_id = hisi_acc_vdev->vf_id;
445 int ret;
446
447 vf_data->acc_magic = ACC_DEV_MAGIC_V2;
> 448 vf_data->major_ver = ACC_DRV_MAR; > 449 vf_data->minor_ver = ACC_DRV_MIN;
450 /* Save device id */
451 vf_data->dev_id = hisi_acc_vdev->vf_dev->device;
452
453 /* VF qp num save from PF */
454 ret = pf_qm_get_qp_num(pf_qm, vf_id, &vf_data->qp_base);
455 if (ret <= 0) {
456 dev_err(dev, "failed to get vft qp nums!\n");
457 return -EINVAL;
458 }
459
460 vf_data->qp_num = ret;
461
462 /* VF isolation state save from PF */
463 ret = qm_read_regs(pf_qm, QM_QUE_ISO_CFG_V, &vf_data->que_iso_cfg, 1);
464 if (ret) {
465 dev_err(dev, "failed to read QM_QUE_ISO_CFG_V!\n");
466 return ret;
467 }
468
469 return 0;
470 }
471
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
liulongfang
maintainerRe: [PATCH v4 1/5] hisi_acc_vfio_pci: fix XQE dma address error
Quoted 83 lines · kernel test robot
Hi Longfang,
kernel test robot noticed the following build errors:
[auto build test ERROR on awilliam-vfio/next]
[also build test ERROR on awilliam-vfio/for-linus linus/master v6.14-rc4 next-20250227] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Longfang-Liu/hisi_acc_vfio_pci-fix-XQE-dma-address-error/20250225-143347 base: https://github.com/awilliam/linux-vfio.git next patch link: https://lore.kernel.org/r/20250225062757.19692-2-liulongfang%40huawei.com patch subject: [PATCH v4 1/5] hisi_acc_vfio_pci: fix XQE dma address error config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20250228/[email protected]/config) compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250228/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All errors (new ones prefixed by >>):
In file included from
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:9:
In file included frominclude/linux/hisi_acc_qm.h:10:
In file included frominclude/linux/pci.h:1644:
In file included frominclude/linux/dmapool.h:14:
In file included frominclude/linux/scatterlist.h:8:
In file included frominclude/linux/mm.h:2224:
include/linux/vmstat.h:504:43: warning: arithmetic between different enumeration types ('enumzone_stat_item' and 'enumnuma_stat_item') [-Wenum-enum-conversion]504 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS + | ~~~~~~~~~~~~~~~~~~~~~ ^ 505 | item]; | ~~~~ include/linux/vmstat.h:511:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion] 511 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS + | ~~~~~~~~~~~~~~~~~~~~~ ^ 512 | NR_VM_NUMA_EVENT_ITEMS + | ~~~~~~~~~~~~~~~~~~~~~~ include/linux/vmstat.h:524:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion] 524 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS + | ~~~~~~~~~~~~~~~~~~~~~ ^ 525 | NR_VM_NUMA_EVENT_ITEMS + | ~~~~~~~~~~~~~~~~~~~~~~Quoted 1 line
Quoted 1 line
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:448:23: error: use of undeclared identifier 'ACC_DRV_MAR'448 | vf_data->major_ver = ACC_DRV_MAR; | ^Quoted 1 line
Quoted 1 line
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:449:23: error: use of undeclared identifier 'ACC_DRV_MIN'449 | vf_data->minor_ver = ACC_DRV_MIN; | ^3 warnings and 2 errors generated.
vim +/ACC_DRV_MAR +448
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c438 439 static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev, 440 struct acc_vf_data *vf_data) 441 { 442 struct hisi_qm *pf_qm = hisi_acc_vdev->pf_qm; 443 struct device *dev = &pf_qm->pdev->dev; 444 int vf_id = hisi_acc_vdev->vf_id; 445 int ret; 446 447 vf_data->acc_magic = ACC_DEV_MAGIC_V2;Quoted 2 lines
448
vf_data->major_ver=ACC_DRV_MAR;
449vf_data->minor_ver=ACC_DRV_MIN;450 /* Save device id */
451 vf_data->dev_id = hisi_acc_vdev->vf_dev->device; 452 453 /* VF qp num save from PF */ 454 ret = pf_qm_get_qp_num(pf_qm, vf_id, &vf_data->qp_base); 455 if (ret <= 0) { 456 dev_err(dev, "failed to get vft qp nums!\n"); 457 return -EINVAL; 458 } 459 460 vf_data->qp_num = ret; 461 462 /* VF isolation state save from PF */ 463 ret = qm_read_regs(pf_qm, QM_QUE_ISO_CFG_V, &vf_data->que_iso_cfg, 1);
Quoted 9 lines
464 if (ret) {
465 dev_err(dev, "failed to read QM_QUE_ISO_CFG_V!\n");
466 return ret;
467 }
468
469 return 0;
470 }
471 Thank you for your test, I will fix it in the next version.
Thanks.
Longfang.
Longfang Liu
maintainerPATCH v4 2/5 hisi_acc_vfio_pci: add eq and aeq interruption restore
In reply to Longfang LiuIn order to ensure that the task packets of the accelerator device are not lost during the migration process, it is necessary to send an EQ and AEQ command to the device after the live migration is completed and to update the completion position of the task queue.
Let the device recheck the completed tasks data and if there are uncollected packets, device resend a task completion interrupt to the software.
--- drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +16 -0
@@ -469,6 +469,19 @@ static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev,return 0 ; } +static void vf_qm_xeqc_save (struct hisi_qm *qm, +struct hisi_acc_vf_migration_file *migf) +{ +struct acc_vf_data *vf_data = &migf->vf_data; +u16 eq_head, aeq_head; + + eq_head = vf_data->qm_eqc_dw[0 ] &0xFFFF ; +qm_db (qm,0 ,QM_DOORBELL_CMD_EQ , eq_head,0 ); + + aeq_head = vf_data->qm_aeqc_dw[0 ] &0xFFFF ; +qm_db (qm,0 ,QM_DOORBELL_CMD_AEQ , aeq_head,0 ); +} +static int vf_qm_load_data (struct hisi_acc_vf_core_device *hisi_acc_vdev,struct hisi_acc_vf_migration_file *migf) {
@@ -577,6 +590,9 @@ static int vf_qm_state_save(struct hisi_acc_vf_core_device *hisi_acc_vdev,return -EINVAL ; migf->total_length =sizeof (struct acc_vf_data ); +/* Save eqc and aeqc interrupt information */ +vf_qm_xeqc_save (vf_qm, migf); +return 0 ; }
Signature · 1 line
2.24.0
Longfang Liu
maintainerPATCH v4 3/5 hisi_acc_vfio_pci: bugfix cache write-back issue
In reply to Longfang LiuAt present, cache write-back is placed in the device data copy stage after stopping the device operation. Writing back to the cache at this stage will cause the data obtained by the cache to be written back to be empty.
In order to ensure that the cache data is written back successfully, the data needs to be written back into the stop device stage.
--- drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +7 -7
@@ -565,7 +565,6 @@ static int vf_qm_state_save(struct hisi_acc_vf_core_device *hisi_acc_vdev, {struct acc_vf_data *vf_data = &migf->vf_data;struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm; -struct device *dev = &vf_qm->pdev->dev;int ret;if (unlikely (qm_wait_dev_not_ready (vf_qm))) {
@@ -579,12 +578,6 @@ static int vf_qm_state_save(struct hisi_acc_vf_core_device *hisi_acc_vdev, vf_data->vf_qm_state =QM_READY ; hisi_acc_vdev->vf_qm_state = vf_data->vf_qm_state; - ret =vf_qm_cache_wb (vf_qm); -if (ret) { -dev_err (dev,"failed to writeback QM Cache!\n" ); -return ret; - } - ret =vf_qm_read_data (vf_qm, vf_data);if (ret)return -EINVAL ;
@@ -1011,6 +1004,13 @@ static int hisi_acc_vf_stop_device(struct hisi_acc_vf_core_device *hisi_acc_vdevdev_err (dev,"failed to check QM INT state!\n" );return ret; } + + ret =vf_qm_cache_wb (vf_qm); +if (ret) { +dev_err (dev,"failed to writeback QM cache!\n" ); +return ret; + } +return 0 ; }
Signature · 1 line
2.24.0
Longfang Liu
maintainerPATCH v4 4/5 hisi_acc_vfio_pci: bugfix the problem of uninstalling driver
In reply to Longfang LiuIn a live migration scenario. If the number of VFs at the destination is greater than the source, the recovery operation will fail and qemu will not be able to complete the process and exit after shutting down the device FD.
This will cause the driver to be unable to be unloaded normally due to abnormal reference counting of the live migration driver caused by the abnormal closing operation of fd.
--- drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 1 + 1 file changed, 1 insertion(+)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +1 -0
@@ -1507,6 +1507,7 @@ static void hisi_acc_vfio_pci_close_device(struct vfio_device *core_vdev)struct hisi_acc_vf_core_device *hisi_acc_vdev =hisi_acc_get_vf_dev (core_vdev);struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm; +hisi_acc_vf_disable_fds (hisi_acc_vdev);mutex_lock (&hisi_acc_vdev->open_mutex); hisi_acc_vdev->dev_opened = false;iounmap (vf_qm->io_base);
Signature · 1 line
2.24.0
Longfang Liu
maintainerPATCH v4 5/5 hisi_acc_vfio_pci: bugfix live migration function without VF device driver
In reply to Longfang LiuIf the driver of the VF device is not loaded in the Guest OS, then perform device data migration. The migrated data address will be NULL.
The live migration recovery operation on the destination side will access a null address value, which will cause access errors.
Therefore, live migration of VMs without added VF device drivers does not require device data migration.
In addition, when the queue address data obtained by the destination is empty, device queue recovery processing will not be performed.
--- drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +18 -0
@@ -440,6 +440,7 @@ static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev, struct acc_vf_data *vf_data) {struct hisi_qm *pf_qm = hisi_acc_vdev->pf_qm; +struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm;struct device *dev = &pf_qm->pdev->dev;int vf_id = hisi_acc_vdev->vf_id;int ret;
@@ -466,6 +467,13 @@ static int vf_qm_get_match_data(struct hisi_acc_vf_core_device *hisi_acc_vdev,return ret; } +/* Get VF driver insmod state */ + ret =qm_read_regs (vf_qm,QM_VF_STATE , &vf_data->vf_qm_state,1 ); +if (ret) { +dev_err (dev,"failed to read QM_VF_STATE!\n" ); +return ret; + } +return 0 ; }
@@ -505,6 +513,12 @@ static int vf_qm_load_data(struct hisi_acc_vf_core_device *hisi_acc_vdev, qm->qp_base = vf_data->qp_base; qm->qp_num = vf_data->qp_num; +if (!vf_data->eqe_dma || !vf_data->aeqe_dma || + !vf_data->sqc_dma || !vf_data->cqc_dma) { +dev_err (dev,"resume dma addr is NULL!\n" ); +return -EINVAL ; + } + ret =qm_set_regs (qm, vf_data);if (ret) {dev_err (dev,"set VF regs failed\n" );
@@ -727,6 +741,9 @@ static int hisi_acc_vf_load_state(struct hisi_acc_vf_core_device *hisi_acc_vdev)struct hisi_acc_vf_migration_file *migf = hisi_acc_vdev->resuming_migf;int ret; +if (hisi_acc_vdev->vf_qm_state !=QM_READY ) +return 0 ; +/* Recover data to VF */ ret =vf_qm_load_data (hisi_acc_vdev, migf);if (ret) {
@@ -1530,6 +1547,7 @@ static int hisi_acc_vfio_pci_migrn_init_dev(struct vfio_device *core_vdev) hisi_acc_vdev->vf_id =pci_iov_vf_id (pdev) +1 ; hisi_acc_vdev->pf_qm = pf_qm; hisi_acc_vdev->vf_dev = pdev; + hisi_acc_vdev->vf_qm_state =QM_NOT_READY ;mutex_init (&hisi_acc_vdev->state_mutex);mutex_init (&hisi_acc_vdev->open_mutex);
Signature · 1 line
2.24.0
RE: [PATCH v4 5/5] hisi_acc_vfio_pci: bugfix live migration function without VF device driver
Quoted 13 lines
-----Original Message-----
From: liulongfang <[email protected]>
Sent: Tuesday, February 25, 2025 6:28 AM
To: [email protected]; [email protected]; Shameerali Kolothum Thodi <[email protected]>; Jonathan Cameron <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; liulongfang <[email protected]>
Subject: [PATCH v4 5/5]hisi_acc_vfio_pci: bugfix live migration function without VF device driver
Quoted 3 lines
If the driver of the VF device is not loaded in the Guest OS, then perform device data migration. The migrated data address will be NULL.
May be rephrase:
If the VF device driver is not loaded in the Guest OS and we attempt to perform device data migration, the address of the migrated data will be NULL.
Quoted 30 lines
The live migration recovery operation on the destination side will access a null address value, which will cause access errors.
Therefore, live migration of VMs without added VF device drivers does not require device data migration.
In addition, when the queue address data obtained by the destination is empty, device queue recovery processing will not be performed.Fixes b0eed085903e ("hisi_acc_vfio_pci: Add support for VFIO livemigration")
Signed-off-by Longfang Liu <[email protected]>--- drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +1
-0@@ -440,6 +440,7 @@ static int vf_qm_get_match_data(structhisi_acc_vf_core_device *hisi_acc_vdev, struct acc_vf_data *vf_data) { struct hisi_qm *pf_qm = hisi_acc_vdev->pf_qm; +struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm;struct device *dev = &pf_qm->pdev->dev;int vf_id = hisi_acc_vdev->vf_id;drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +0
-0int ret;
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_get_match_data(struct · line 473
Quoted 7 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +2
-0@@ -466,6 +467,13 @@ static int vf_qm_get_match_data(structhisi_acc_vf_core_device *hisi_acc_vdev, return ret; } +/* Get VF driver insmod state */ + ret =qm_read_regs (vf_qm,QM_VF_STATE , &vf_data->vf_qm_state,1 );
We already have qm_wait_dev_not_ready() function that checks the QM_VF_STATE. Why can't we use that here?
Also we are getting this vf_qm_state already in vf_qm_state_save(). And you don't seem to check the vf_qm_state in vf_qm_check_match(). So why it is read early in this function?
Thanks,
Shameer
Quoted 45 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +5
-0+if (ret) { +dev_err (dev,"failed to read QM_VF_STATE!\n" ); +return ret; + } +return 0 ;}
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +6
-0@@ -505,6 +513,12 @@ static int vf_qm_load_data(struct hisi_acc_vf_core_device *hisi_acc_vdev, qm->qp_base = vf_data->qp_base; qm->qp_num = vf_data->qp_num; +if (!vf_data->eqe_dma || !vf_data->aeqe_dma || + !vf_data->sqc_dma || !vf_data->cqc_dma) { +dev_err (dev,"resume dma addr is NULL!\n" ); +return -EINVAL ; + } + ret =qm_set_regs (qm, vf_data);if (ret) {drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +3
-0dev_err (dev,"set VF regs failed\n" );@@ -727,6 +741,9 @@ static int hisi_acc_vf_load_state(struct hisi_acc_vf_core_device *hisi_acc_vdev)struct hisi_acc_vf_migration_file *migf = hisi_acc_vdev- >resuming_migf;int ret; +if (hisi_acc_vdev->vf_qm_state !=QM_READY ) +return 0 ; +/* Recover data to VF */ drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +1
-1ret =vf_qm_load_data (hisi_acc_vdev, migf);if (ret) {@@ -1530,6 +1547,7 @@ static int hisi_acc_vfio_pci_migrn_init_dev(struct vfio_device *core_vdev) hisi_acc_vdev->vf_id = pci_iov_vf_id(pdev) + 1; hisi_acc_vdev->pf_qm = pf_qm; hisi_acc_vdev->vf_dev = pdev; + hisi_acc_vdev->vf_qm_state =QM_NOT_READY ;mutex_init (&hisi_acc_vdev->state_mutex);mutex_init (&hisi_acc_vdev->open_mutex); --2.24.0
liulongfang
maintainerRe: [PATCH v4 5/5] hisi_acc_vfio_pci: bugfix live migration function without VF device driver
Quoted 17 lines · Shameerali Kolothum Thodi
Quoted 13 lines
-----Original Message-----
From: liulongfang <[email protected]>
Sent: Tuesday, February 25, 2025 6:28 AM
To: [email protected]; [email protected]; Shameerali Kolothum Thodi <[email protected]>; Jonathan Cameron <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; liulongfang <[email protected]>
Subject: [PATCH v4 5/5]hisi_acc_vfio_pci: bugfix live migration function without VF device driverQuoted 3 lines
If the driver of the VF device is not loaded in the Guest OS, then perform device data migration. The migrated data address will be NULL.
Quoted 6 lines
May be rephrase:
If the VF device driver is not loaded in the Guest OS and we attempt to perform device data migration, the address of the migrated data will be NULL.
OK.
Quoted 34 lines
Quoted 34 lines
The live migration recovery operation on the destination side will access a null address value, which will cause access errors.
Therefore, live migration of VMs without added VF device drivers does not require device data migration.
In addition, when the queue address data obtained by the destination is empty, device queue recovery processing will not be performed.Fixes b0eed085903e ("hisi_acc_vfio_pci: Add support for VFIO livemigration")
Signed-off-by Longfang Liu <[email protected]>--- drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +1
-0@@ -440,6 +440,7 @@ static int vf_qm_get_match_data(structhisi_acc_vf_core_device *hisi_acc_vdev, struct acc_vf_data *vf_data) { struct hisi_qm *pf_qm = hisi_acc_vdev->pf_qm; +struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm;struct device *dev = &pf_qm->pdev->dev;int vf_id = hisi_acc_vdev->vf_id;drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +0
-0int ret;@@ -466,6 +467,13 @@ static int vf_qm_get_match_data(structhisi_acc_vf_core_device *hisi_acc_vdev, return ret; }
Quoted 7 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c static int vf_qm_get_match_data(struct · line 473
Quoted 3 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +2
-0+/* Get VF driver insmod state */ + ret =qm_read_regs (vf_qm,QM_VF_STATE , &vf_data->vf_qm_state,1 );We already have
qm_wait_dev_not_ready()function that checks theQM_VF_STATE. Why can't we use that here?
Here we need to compare with the passed state vf_qm_state. qm_wait_dev_not_ready() is to check whether the current VM has loaded the driver.
The two functions are different
Quoted 4 lines
Also we are getting this
vf_qm_statealready invf_qm_state_save(). And you don't seem to check thevf_qm_stateinvf_qm_check_match(). So why it is read early in this function?
There is no need to check whether the driver is loaded in vf_qm_check_match(). Loading the driver or not does not affect live migration recovery. When the driver is loaded, the xqc address data needs to be restored. If it is not loaded, there is no need to restore the data,then we only need to restore the VM status.
Thanks.
Longfang.
Quoted 52 lines
Thanks,
ShameerQuoted 44 lines
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +5
-0+if (ret) { +dev_err (dev,"failed to read QM_VF_STATE!\n" ); +return ret; + } +return 0 ;}
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +6
-0@@ -505,6 +513,12 @@ static int vf_qm_load_data(struct hisi_acc_vf_core_device *hisi_acc_vdev, qm->qp_base = vf_data->qp_base; qm->qp_num = vf_data->qp_num; +if (!vf_data->eqe_dma || !vf_data->aeqe_dma || + !vf_data->sqc_dma || !vf_data->cqc_dma) { +dev_err (dev,"resume dma addr is NULL!\n" ); +return -EINVAL ; + } + ret =qm_set_regs (qm, vf_data);if (ret) {drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +3
-0dev_err (dev,"set VF regs failed\n" );@@ -727,6 +741,9 @@ static int hisi_acc_vf_load_state(struct hisi_acc_vf_core_device *hisi_acc_vdev)struct hisi_acc_vf_migration_file *migf = hisi_acc_vdev- > resuming_migf;int ret; +if (hisi_acc_vdev->vf_qm_state !=QM_READY ) +return 0 ; +/* Recover data to VF */ drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +1
-1ret =vf_qm_load_data (hisi_acc_vdev, migf);if (ret) {@@ -1530,6 +1547,7 @@ static int hisi_acc_vfio_pci_migrn_init_dev(struct vfio_device *core_vdev) hisi_acc_vdev->vf_id = pci_iov_vf_id(pdev) + 1; hisi_acc_vdev->pf_qm = pf_qm; hisi_acc_vdev->vf_dev = pdev; + hisi_acc_vdev->vf_qm_state =QM_NOT_READY ;mutex_init (&hisi_acc_vdev->state_mutex);mutex_init (&hisi_acc_vdev->open_mutex); --Quoted 1 line
2.24.0
.