Re: [RFC PATCH v2 12/58] KVM: arm64: Add __pkvm_{use, unuse}_dma()

From: Quentin Perret
Date: Thu Dec 19 2024 - 06:23:16 EST


On Thursday 12 Dec 2024 at 18:03:36 (+0000), Mostafa Saleh wrote:
> +int __pkvm_host_unuse_dma(phys_addr_t phys_addr, size_t size)
> +{
> + int i;
> + size_t nr_pages = size >> PAGE_SHIFT;
> +
> + if (WARN_ON(!PAGE_ALIGNED(phys_addr | size)))
> + return -EINVAL;
> +
> + host_lock_component();
> + if (!range_is_memory(phys_addr, phys_addr + size))
> + goto out_ret;

Nit: I think you can do this out of the critical section -- the memblock
list is guaranteed stable by construction.

> + /*
> + * We end up here after the caller successfully unmapped the page from
> + * the IOMMU table. Which means that a ref is held, the page is shared
> + * in the host s2, there can be no failure.
> + */
> + for (i = 0; i < nr_pages; i++)
> + __pkvm_host_unuse_dma_page(phys_addr + i * PAGE_SIZE);
> +
> +out_ret:
> + host_unlock_component();
> + return 0;
> +}
> +
> int __pkvm_host_share_guest(u64 pfn, u64 gfn, struct pkvm_hyp_vcpu *vcpu,
> enum kvm_pgtable_prot prot)
> {
> --
> 2.47.0.338.g60cca15819-goog
>