[PATCH v2 2/3] KVM: arm64: vgic-its: Clear dte when mapd unmaps a device
Jing Zhang
jingzhangos at google.com
Wed Oct 23 13:30:54 PDT 2024
Hi Kunkun,
On Thu, Jul 4, 2024 at 7:23 AM Kunkun Jiang <jiangkunkun at huawei.com> wrote:
>
> vgic_its_save_device_tables will traverse its->device_list to
> save dte for each device. vgic_its_restore_device_tables will
> traverse each entry of device table and check if it is valid.
> Restore if valid.
>
> But when mapd unmaps a devices, we do not invalidate the
type: devices -> device
> corresponding dte. In the scenario of continuous save
> and restore, there may be a situation where a device's dte
> is not saved but is restored. This is unreasonable and may
> cause restore to fail. This patch clears the corresponding
> dte when mapd unmaps a device.
>
> Co-developed-by: Shusen Li <lishusen2 at huawei.com>
> Singed-off-by: Shusen Li <lishusen2 at huawei.com>
typo: Signed
> Signed-off-by: Kunkun Jiang <jiangkunkun at huawei.com>
> ---
> arch/arm64/kvm/vgic/vgic-its.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
> index 344bd8c20f67..223a5f1d6a3d 100644
> --- a/arch/arm64/kvm/vgic/vgic-its.c
> +++ b/arch/arm64/kvm/vgic/vgic-its.c
> @@ -1140,8 +1140,9 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,
> u8 num_eventid_bits = its_cmd_get_size(its_cmd);
> gpa_t itt_addr = its_cmd_get_ittaddr(its_cmd);
> struct its_device *device;
> + gpa_t gpa;
>
> - if (!vgic_its_check_id(its, its->baser_device_table, device_id, NULL))
> + if (!vgic_its_check_id(its, its->baser_device_table, device_id, &gpa))
> return E_ITS_MAPD_DEVICE_OOR;
>
> if (valid && num_eventid_bits > VITS_TYPER_IDBITS)
> @@ -1161,8 +1162,17 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,
> * The spec does not say whether unmapping a not-mapped device
> * is an error, so we are done in any case.
> */
> - if (!valid)
> + if (!valid) {
> + struct kvm *kvm = its->dev->kvm;
> + int dte_esz = vgic_its_get_abi(its)->dte_esz;
> + u64 val = 0;
> +
> + if (KVM_BUG_ON(dte_esz != sizeof(val), kvm))
> + return -EINVAL;
> +
> + vgic_write_guest_lock(kvm, gpa, &val, dte_esz);
> return 0;
> + }
>
> device = vgic_its_alloc_device(its, device_id, itt_addr,
> num_eventid_bits);
> --
> 2.27.0
>
>
Jing
More information about the linux-arm-kernel
mailing list