Re: KVM: s390/mm: Clarification for two return value checks in gmap_shadow()

From: David Hildenbrand
Date: Sat May 02 2020 - 13:27:50 EST


On 02.05.20 17:43, Markus Elfring wrote:
> Hello,
>
> I have tried another small script out for the semantic patch language.
> This source code analysis approach points out that the function âgmap_find_shadowâ
> is called two times by the function âgmap_shadowâ.
> https://elixir.bootlin.com/linux/v5.7-rc3/source/arch/s390/mm/gmap.c#L1628
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/arch/s390/mm/gmap.c
>
> Null pointer checks are performed at these places.

Right, in case we have already a shadow, we return it. In case we are
just concurrently creating/initializing another one, we return -EINVAL
so the caller will retry (and find the fully initialized one). In case
we get NULL, we have to create a new one.

> The function âgmap_find_shadowâ is documented in the same source file
> that the pointer âERR_PTR(-EAGAIN)â can eventually be returned.
> Are the referenced gmap data structures always initialised here?

-EAGAIN makes sure that we are not touching partially initialized one.
In case we find a valid gmap shadow, it is fully initialized. That's
what we have the ->initialized field for.

Hope that answers your question.

--
Thanks,

David / dhildenb