Re: [PATCH 1/3] KVM, SEV: Refactor out function for unregistering encrypted regions

From: Sean Christopherson
Date: Tue Jul 13 2021 - 17:41:05 EST


On Mon, Jun 21, 2021, Peter Gonda wrote:
> Factor out helper function for freeing the encrypted region list.

...

> arch/x86/kvm/svm/sev.c | 26 +++++++++++++++++---------
> 1 file changed, 17 insertions(+), 9 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 46e339c84998..5af46ff6ec48 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -1767,11 +1767,25 @@ int svm_vm_copy_asid_from(struct kvm *kvm, unsigned int source_fd)
> return ret;
> }
>
> +static void __unregister_region_list_locked(struct kvm *kvm,
> + struct list_head *mem_regions)

I don't think the underscores or the "locked" qualifier are necessary. Unlike
__unregister_enc_region_locked(), there is no unregister_region_list() to avoid.

I'd also votes to drop "list" and instead use a plural "regions". Without the
plural form, it's not immediately obvious that the difference is that this
helper deletes multiple regions.

Last nit, I assume these are all encrypted regions? If so, unregister_enc_regions()
seems like the natural choice.

> +{
> + struct enc_region *pos, *q;
> +
> + lockdep_assert_held(&kvm->lock);

This locked (big thumbs up) is part of why I think it's a-ok to drop the "locked"
qualifier.

> +
> + if (list_empty(mem_regions))
> + return;
> +
> + list_for_each_entry_safe(pos, q, mem_regions, list) {
> + __unregister_enc_region_locked(kvm, pos);
> + cond_resched();
> + }
> +}