io_uring/fdinfo: remove need for sqpoll lock for thread/pid retrieval
authorJens Axboe <axboe@kernel.dk>
Tue, 14 Nov 2023 16:55:50 +0000 (09:55 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 28 Nov 2023 17:19:52 +0000 (17:19 +0000)
commit5753dbb32648d7bb3530b022d5fa360868a983b1
treebbc3e4494b6f723cf987bcbf7f5c2fe56090f2b3
parentff33be9cecee28f021493369bddb826f068a1acb
io_uring/fdinfo: remove need for sqpoll lock for thread/pid retrieval

[ Upstream commit a0d45c3f596be53c1bd8822a1984532d14fdcea9 ]

A previous commit added a trylock for getting the SQPOLL thread info via
fdinfo, but this introduced a regression where we often fail to get it if
the thread is busy. For that case, we end up not printing the current CPU
and PID info.

Rather than rely on this lock, just print the pid we already stored in
the io_sq_data struct, and ensure we update the current CPU every time
we've slept or potentially rescheduled. The latter won't potentially be
100% accurate, but that wasn't the case before either as the task can
get migrated at any time unless it has been pinned at creation time.

We retain keeping the io_sq_data dereference inside the ctx->uring_lock,
as it has always been, as destruction of the thread and data happen below
that. We could make this RCU safe, but there's little point in doing that.

With this, we always print the last valid information we had, rather than
have spurious outputs with missing information.

Fixes: 7644b1a1c9a7 ("io_uring/fdinfo: lock SQ thread while retrieving thread cpu/pid")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
io_uring/fdinfo.c
io_uring/sqpoll.c