Commit a4ae8bb6 authored by Jens Axboe's avatar Jens Axboe Committed by sanglipeng
Browse files

io_uring: io_kiocb_update_pos() should not touch file for non -1 offset

stable inclusion
from stable-v5.10.165
commit 89a77271d254752d83507fc347dc2d675885fe07
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7T7G4

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=89a77271d254752d83507fc347dc2d675885fe07



--------------------------------

commit 6f83ab22 upstream.

-1 tells use to use the current position, but we check if the file is
a stream regardless of that. Fix up io_kiocb_update_pos() to only
dip into file if we need to. This is both more efficient and also drops
12 bytes of text on aarch64 and 64 bytes on x86-64.

Fixes: b4aec400 ("io_uring: do not recalculate ppos unnecessarily")
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarsanglipeng <sanglipeng1@jd.com>
parent ef6dd321
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -3014,20 +3014,19 @@ static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret)
static inline loff_t *io_kiocb_update_pos(struct io_kiocb *req)
{
	struct kiocb *kiocb = &req->rw.kiocb;
	bool is_stream = req->file->f_mode & FMODE_STREAM;

	if (kiocb->ki_pos == -1) {
		if (!is_stream) {
	if (kiocb->ki_pos != -1)
		return &kiocb->ki_pos;

	if (!(req->file->f_mode & FMODE_STREAM)) {
		req->flags |= REQ_F_CUR_POS;
		kiocb->ki_pos = req->file->f_pos;
		return &kiocb->ki_pos;
		} else {
	}

	kiocb->ki_pos = 0;
	return NULL;
}
	}
	return is_stream ? NULL : &kiocb->ki_pos;
}

static void kiocb_done(struct kiocb *kiocb, ssize_t ret,
		       unsigned int issue_flags)