Re: [PATCH v4 1/3] KVM: s390: Add map/unmap ioctl and clean mappings post-guest

Douglas Freimuth
2026-05-05T17:21:58Z

On 4/30/26 11:31 AM, Claudio Imbrenda wrote:
> On Wed, 29 Apr 2026 10:44:51 -0400
> Matthew Rosato <mjrosato@linux.ibm.com> wrote:
>
> [...]
>
>>
>>> + if (locked)
>>> + mmap_read_unlock(mm);
>>> + mmput(mm);
>>> + }
>>> +
>>> + return page;
>>> +}
>>> +
>>> +static int kvm_s390_adapter_map(struct kvm *kvm, unsigned int id, __u64 addr)
>>> +{
>>> + struct s390_io_adapter *adapter = get_io_adapter(kvm, id);
>>> + struct s390_map_info *map;
>>> + unsigned long flags;
>>> + __u64 host_addr;
>>> + int ret, idx;
>>> +
>>> + if (!adapter || !addr)
>>> + return -EINVAL;
>>> +
>>> + map = kzalloc_obj(*map, GFP_KERNEL_ACCOUNT);
>>> + if (!map)
>>> + return -ENOMEM;
>>> +
>>> + INIT_LIST_HEAD(&map->list);
>>> + idx = srcu_read_lock(&kvm->srcu);
>>> + host_addr = gpa_to_hva(kvm, addr);
>>> + if (kvm_is_error_hva(host_addr)) {
>>> + srcu_read_unlock(&kvm->srcu, idx);
>>> + kfree(map);
>>
>> Drop this kfree(), you already do this when you goto out
>
> have you considered using __free(kvfree) and let the compiler free map
> for you automatically? (or it doesn't work here?)
>
> [...]

Claudio good suggestion to consider, thank you. At this stage I will
consider it for follow-on including looking at how you have used in
other parts of the kernel. And will consider for new projects too.