public inbox for [email protected]
 help / color / mirror / Atom feed
* Memory uninitialized after "io_uring: keep table of pointers to ubufs"
@ 2021-05-29  0:33 Andres Freund
  2021-05-29 11:03 ` Pavel Begunkov
  0 siblings, 1 reply; 5+ messages in thread
From: Andres Freund @ 2021-05-29  0:33 UTC (permalink / raw)
  To: Pavel Begunkov, Jens Axboe, io-uring, linux-kernel

Hi,

I started to see buffer registration randomly failing with ENOMEM on
5.13. Registering buffer or two often succeeds, but more than that
rarely. Running the same program as root succeeds - but the user has a high
rlimit.

The issue is that io_sqe_buffer_register() doesn't initialize
imu. io_buffer_account_pin() does imu->acct_pages++, before calling
io_account_mem(ctx, imu->acct_pages);

Which means that a random amount of memory is being accounted for. On the first
few allocations this sometimes fails to fail because the memory is zero, but
after a bit of reuse...

It only doesn't fail as root because the rlimit doesn't apply.

This is caused by

commit 41edf1a5ec967bf4bddedb83c48e02dfea8315b4
Author: Pavel Begunkov <[email protected]>
Date:   2021-04-25 14:32:23 +0100

    io_uring: keep table of pointers to ubufs

Greetings,

Andres Freund

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Memory uninitialized after "io_uring: keep table of pointers to ubufs"
  2021-05-29  0:33 Memory uninitialized after "io_uring: keep table of pointers to ubufs" Andres Freund
@ 2021-05-29 11:03 ` Pavel Begunkov
  2021-06-03 18:06   ` Andres Freund
  0 siblings, 1 reply; 5+ messages in thread
From: Pavel Begunkov @ 2021-05-29 11:03 UTC (permalink / raw)
  To: Andres Freund, Jens Axboe, io-uring, linux-kernel

On 5/29/21 1:33 AM, Andres Freund wrote:
> Hi,
> 
> I started to see buffer registration randomly failing with ENOMEM on
> 5.13. Registering buffer or two often succeeds, but more than that
> rarely. Running the same program as root succeeds - but the user has a high
> rlimit.
> 
> The issue is that io_sqe_buffer_register() doesn't initialize
> imu. io_buffer_account_pin() does imu->acct_pages++, before calling
> io_account_mem(ctx, imu->acct_pages);
> 
> Which means that a random amount of memory is being accounted for. On the first
> few allocations this sometimes fails to fail because the memory is zero, but
> after a bit of reuse...

Makes sense, thanks for digging in. I've just sent a patch, would
be great if you can test it or send your own.


> It only doesn't fail as root because the rlimit doesn't apply.
> 
> This is caused by
> 
> commit 41edf1a5ec967bf4bddedb83c48e02dfea8315b4
> Author: Pavel Begunkov <[email protected]>
> Date:   2021-04-25 14:32:23 +0100
> 
>     io_uring: keep table of pointers to ubufs
> 
> Greetings,
> 
> Andres Freund
> 

-- 
Pavel Begunkov

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Memory uninitialized after "io_uring: keep table of pointers to ubufs"
  2021-05-29 11:03 ` Pavel Begunkov
@ 2021-06-03 18:06   ` Andres Freund
  2021-06-03 18:13     ` Jens Axboe
  2021-06-04 14:16     ` Pavel Begunkov
  0 siblings, 2 replies; 5+ messages in thread
From: Andres Freund @ 2021-06-03 18:06 UTC (permalink / raw)
  To: Pavel Begunkov; +Cc: Jens Axboe, io-uring, linux-kernel

Hi,

On 2021-05-29 12:03:12 +0100, Pavel Begunkov wrote:
> On 5/29/21 1:33 AM, Andres Freund wrote:
> > Hi,
> > 
> > I started to see buffer registration randomly failing with ENOMEM on
> > 5.13. Registering buffer or two often succeeds, but more than that
> > rarely. Running the same program as root succeeds - but the user has a high
> > rlimit.
> > 
> > The issue is that io_sqe_buffer_register() doesn't initialize
> > imu. io_buffer_account_pin() does imu->acct_pages++, before calling
> > io_account_mem(ctx, imu->acct_pages);
> > 
> > Which means that a random amount of memory is being accounted for. On the first
> > few allocations this sometimes fails to fail because the memory is zero, but
> > after a bit of reuse...
> 
> Makes sense, thanks for digging in. I've just sent a patch, would
> be great if you can test it or send your own.

Sorry for the slow response, I'm off this week. I did just get around to
test and unsurprisingly: The patch does fix the issue.

Greetings,

Andres Freund

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Memory uninitialized after "io_uring: keep table of pointers to ubufs"
  2021-06-03 18:06   ` Andres Freund
@ 2021-06-03 18:13     ` Jens Axboe
  2021-06-04 14:16     ` Pavel Begunkov
  1 sibling, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2021-06-03 18:13 UTC (permalink / raw)
  To: Andres Freund, Pavel Begunkov; +Cc: io-uring, linux-kernel

On 6/3/21 12:06 PM, Andres Freund wrote:
> Hi,
> 
> On 2021-05-29 12:03:12 +0100, Pavel Begunkov wrote:
>> On 5/29/21 1:33 AM, Andres Freund wrote:
>>> Hi,
>>>
>>> I started to see buffer registration randomly failing with ENOMEM on
>>> 5.13. Registering buffer or two often succeeds, but more than that
>>> rarely. Running the same program as root succeeds - but the user has a high
>>> rlimit.
>>>
>>> The issue is that io_sqe_buffer_register() doesn't initialize
>>> imu. io_buffer_account_pin() does imu->acct_pages++, before calling
>>> io_account_mem(ctx, imu->acct_pages);
>>>
>>> Which means that a random amount of memory is being accounted for. On the first
>>> few allocations this sometimes fails to fail because the memory is zero, but
>>> after a bit of reuse...
>>
>> Makes sense, thanks for digging in. I've just sent a patch, would
>> be great if you can test it or send your own.
> 
> Sorry for the slow response, I'm off this week. I did just get around to
> test and unsurprisingly: The patch does fix the issue.

OK good, thanks for confirming, I did ship it out earlier today so
should be in the next -rc.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Memory uninitialized after "io_uring: keep table of pointers to ubufs"
  2021-06-03 18:06   ` Andres Freund
  2021-06-03 18:13     ` Jens Axboe
@ 2021-06-04 14:16     ` Pavel Begunkov
  1 sibling, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2021-06-04 14:16 UTC (permalink / raw)
  To: Andres Freund; +Cc: Jens Axboe, io-uring, linux-kernel

On 6/3/21 7:06 PM, Andres Freund wrote:
> Hi,
> 
> On 2021-05-29 12:03:12 +0100, Pavel Begunkov wrote:
>> On 5/29/21 1:33 AM, Andres Freund wrote:
>>> Hi,
>>>
>>> I started to see buffer registration randomly failing with ENOMEM on
>>> 5.13. Registering buffer or two often succeeds, but more than that
>>> rarely. Running the same program as root succeeds - but the user has a high
>>> rlimit.
>>>
>>> The issue is that io_sqe_buffer_register() doesn't initialize
>>> imu. io_buffer_account_pin() does imu->acct_pages++, before calling
>>> io_account_mem(ctx, imu->acct_pages);
>>>
>>> Which means that a random amount of memory is being accounted for. On the first
>>> few allocations this sometimes fails to fail because the memory is zero, but
>>> after a bit of reuse...
>>
>> Makes sense, thanks for digging in. I've just sent a patch, would
>> be great if you can test it or send your own.
> 
> Sorry for the slow response, I'm off this week. I did just get around to
> test and unsurprisingly: The patch does fix the issue.

Yep, since you already narrowed it down. Thanks for testing

-- 
Pavel Begunkov

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-04 14:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-29  0:33 Memory uninitialized after "io_uring: keep table of pointers to ubufs" Andres Freund
2021-05-29 11:03 ` Pavel Begunkov
2021-06-03 18:06   ` Andres Freund
2021-06-03 18:13     ` Jens Axboe
2021-06-04 14:16     ` Pavel Begunkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox