Re: [PATCH v2 08/20] KVM: s390: KVM page table management functions: allocation

Claudio Imbrenda
2025-09-17T11:26:09Z

On Wed, 17 Sep 2025 09:27:33 +0200
Heiko Carstens <hca@linux.ibm.com> wrote:

> On Tue, Sep 16, 2025 at 07:36:44PM +0200, Heiko Carstens wrote:
> > On Tue, Sep 16, 2025 at 07:06:06PM +0200, Christian Borntraeger wrote:
> > >
> > > Am 16.09.25 um 19:05 schrieb Claudio Imbrenda:
> > >
> > > > > > I think GFP_ATOMIC actually gives more guarantees?
> > > > >
> > > > > In real life GFP_ATOMIC can fail, GFP_KERNEL does not.All gfp allocation failures
> > > > > are usually the atomic ones.
> > > >
> > > > interesting... then I guess I need GFP_KERNEL | GFP_ATOMIC ?
> > >
> > > No. ATOMIC always means: can fail.

my issue is that GFP_KERNEL can sleep, and this allocation is sometimes
called from atomic contexts (e.g. while holding spinlocks)

the right way to do this would be with mempools, to allocate memory
(and potentially sleep) when we are not in atomic context, and use it
whenever needed. this is on my to-do list for the future, but right now
I'd like to avoid having to refactor a ton of code.

> >
> > So GFP_KERNEL alone is what is needed here. It is undocumented that
> > small GFP_KERNEL allocations will never fail (retried for ever):

define "small" ?

>
> Another correction: it should be GFP_KERNEL_ACCOUNT instead, like it
> used to be before in gmap_alloc_crst() since those page tables should
> be accounted to the process which is allocating them.

gfp_types.h says:

* %GFP_KERNEL_ACCOUNT is the same as GFP_KERNEL, except the allocation is
* accounted to kmemcg.

I thought that without GFP_KERNEL_ACCOUNT, it would be accounted toward
the process?
The documentation is a little confusing here