-
Notifications
You must be signed in to change notification settings - Fork 490
Do not discard high 32 bits of length in send #1436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bitonic
wants to merge
1
commit into
axboe:master
Choose a base branch
from
bitonic:safe-send-length
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+12
−6
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -919,17 +919,23 @@ IOURINGINLINE void io_uring_prep_statx(struct io_uring_sqe *sqe, int dfd, | |
| sqe->statx_flags = (__u32) flags; | ||
| } | ||
|
|
||
| static inline __u32 __io_uring_cap_len(size_t len) | ||
| { | ||
| size_t mask = -(size_t)(len > UINT32_MAX); | ||
| return (len & ~mask) | (UINT32_MAX & mask); | ||
| } | ||
|
|
||
| IOURINGINLINE void io_uring_prep_fadvise(struct io_uring_sqe *sqe, int fd, | ||
| __u64 offset, __u32 len, int advice) | ||
| { | ||
| io_uring_prep_rw(IORING_OP_FADVISE, sqe, fd, NULL, (__u32) len, offset); | ||
| io_uring_prep_rw(IORING_OP_FADVISE, sqe, fd, NULL, __io_uring_cap_len(len), offset); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| sqe->fadvise_advice = (__u32) advice; | ||
| } | ||
|
|
||
| IOURINGINLINE void io_uring_prep_madvise(struct io_uring_sqe *sqe, void *addr, | ||
| __u32 length, int advice) | ||
| { | ||
| io_uring_prep_rw(IORING_OP_MADVISE, sqe, -1, addr, (__u32) length, 0); | ||
| io_uring_prep_rw(IORING_OP_MADVISE, sqe, -1, addr, __io_uring_cap_len(length), 0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| sqe->fadvise_advice = (__u32) advice; | ||
| } | ||
|
|
||
|
|
@@ -951,7 +957,7 @@ IOURINGINLINE void io_uring_prep_madvise64(struct io_uring_sqe *sqe, void *addr, | |
| IOURINGINLINE void io_uring_prep_send(struct io_uring_sqe *sqe, int sockfd, | ||
| const void *buf, size_t len, int flags) | ||
| { | ||
| io_uring_prep_rw(IORING_OP_SEND, sqe, sockfd, buf, (__u32) len, 0); | ||
| io_uring_prep_rw(IORING_OP_SEND, sqe, sockfd, buf, __io_uring_cap_len(len), 0); | ||
| sqe->msg_flags = (__u32) flags; | ||
| } | ||
|
|
||
|
|
@@ -983,7 +989,7 @@ IOURINGINLINE void io_uring_prep_send_zc(struct io_uring_sqe *sqe, int sockfd, | |
| const void *buf, size_t len, int flags, | ||
| unsigned zc_flags) | ||
| { | ||
| io_uring_prep_rw(IORING_OP_SEND_ZC, sqe, sockfd, buf, (__u32) len, 0); | ||
| io_uring_prep_rw(IORING_OP_SEND_ZC, sqe, sockfd, buf, __io_uring_cap_len(len), 0); | ||
| sqe->msg_flags = (__u32) flags; | ||
| sqe->ioprio = zc_flags; | ||
| } | ||
|
|
@@ -1021,7 +1027,7 @@ IOURINGINLINE void io_uring_prep_sendmsg_zc_fixed(struct io_uring_sqe *sqe, | |
| IOURINGINLINE void io_uring_prep_recv(struct io_uring_sqe *sqe, int sockfd, | ||
| void *buf, size_t len, int flags) | ||
| { | ||
| io_uring_prep_rw(IORING_OP_RECV, sqe, sockfd, buf, (__u32) len, 0); | ||
| io_uring_prep_rw(IORING_OP_RECV, sqe, sockfd, buf, __io_uring_cap_len(len), 0); | ||
| sqe->msg_flags = (__u32) flags; | ||
| } | ||
|
|
||
|
|
@@ -1131,7 +1137,7 @@ IOURINGINLINE void io_uring_prep_provide_buffers(struct io_uring_sqe *sqe, | |
| void *addr, int len, int nr, | ||
| int bgid, int bid) | ||
| { | ||
| io_uring_prep_rw(IORING_OP_PROVIDE_BUFFERS, sqe, nr, addr, (__u32) len, | ||
| io_uring_prep_rw(IORING_OP_PROVIDE_BUFFERS, sqe, nr, addr, __io_uring_cap_len(len), | ||
| (__u64) bid); | ||
| sqe->buf_group = (__u16) bgid; | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on https://godbolt.org/z/zGeqGGMeh, I'd suggest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had this back and forth with @axboe already. I think the cmov or branching version is better than the current version too (and moreover it'll leverage max instructions for architectures that have them, like aarch64). But since @axboe has stated that he prefers the bit twiddling version I'll let him decide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read @axboe's comments here and on #1435, and to me they only indicated preference for something branchless over a branch. But all 3 alternatives I tried compile to branchless code, and only the last one is optimal on both GCC and Clang.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not how I understood #1436 (comment) , given that it's replying to a comment that explicitly mentions cmov. But I'll let him comment.