Skip to contentSkip to conversation

fs: don't randomized kiocb fields

PATCH In review Keith Busch 5 participants 6 messages Aug 12, 2022 – Aug 15, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: don't randomized kiocb fields

From: Keith Busch <[email protected]>

This is a size sensitive structure and randomizing can introduce extra padding that breaks io_uring's fixed size expectations. There are few fields here as it is, half of which need a fixed order to optimally pack, so the randomization isn't providing much.

---
 include/linux/fs.h | 5 -----
 1 file changed, 5 deletions(-)
include/linux/fs.h +0 -5
index 5113f65c786f..9eced4cc286e 100644
@@ -340,17 +340,12 @@ enum rw_hint {
 
 struct kiocb {
 	struct file		*ki_filp;
-
-	/* The 'ki_filp' pointer is shared in a union for aio */
-	randomized_struct_fields_start
-
 	loff_t			ki_pos;
 	void (*ki_complete)(struct kiocb *iocb, long ret);
 	void			*private;
 	int			ki_flags;
 	u16			ki_ioprio; /* See linux/ioprio.h */
 	struct wait_page_queue	*ki_waitq; /* for async buffered IO */
-	randomized_struct_fields_end
 };
 
 static inline bool is_sync_kiocb(struct kiocb *kiocb)
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 6 lines · Keith Busch

From: Keith Busch <[email protected]>

This is a size sensitive structure and randomizing can introduce extra padding that breaks io_uring's fixed size expectations. There are few fields here as it is, half of which need a fixed order to optimally pack, so the randomization isn't providing much.

I'll add the link to the previous discussion as well in the commit:

as it's pretty useful for context.

Signature · 1 line
Jens Axboe
maintainer
#3 lore raw
Quoted 3 lines · Christoph Hellwig

s/randomized/randomize/

in the subject?

I did notice that one and made the edit yesterday.

Signature · 1 line
Jens Axboe
#4 lore raw
In reply to Keith Busch
Quoted 4 lines · Keith Busch

struct kiocb {

include/linux/fs.h +0 -2
 	struct file		*ki_filp;
-
-	/* The 'ki_filp' pointer is shared in a union for aio */

include/linux/fs.h enum rw_hint { · line 349

Quoted 10 lines
include/linux/fs.h +0 -3
-	randomized_struct_fields_start
-
 	loff_t			ki_pos;
 	void (*ki_complete)(struct kiocb *iocb, long ret);
 	void			*private;
 	int			ki_flags;
 	u16			ki_ioprio; /* See linux/ioprio.h */
 	struct wait_page_queue	*ki_waitq; /* for async buffered IO */
-	randomized_struct_fields_end
 };

Now that I've read the thread ...

If we care about struct size on 32-bit, we should fit something into the 32-bit hole before the 64-bit loff_t (assuming at least some 32-bit arches want loff_t to be 64-bit aligned; I thik x86 doesn't?) Easiest seems to be to put ki_complete before ki_pos?

#5 lore raw
Quoted 18 lines · Matthew Wilcox
Quoted 4 lines · Keith Busch

struct kiocb {

include/linux/fs.h +0 -2
 	struct file		*ki_filp;
-
-	/* The 'ki_filp' pointer is shared in a union for aio */

include/linux/fs.h enum rw_hint { · line 349

Quoted 10 lines
include/linux/fs.h +0 -3
-	randomized_struct_fields_start
-
 	loff_t			ki_pos;
 	void (*ki_complete)(struct kiocb *iocb, long ret);
 	void			*private;
 	int			ki_flags;
 	u16			ki_ioprio; /* See linux/ioprio.h */
 	struct wait_page_queue	*ki_waitq; /* for async buffered IO */
-	randomized_struct_fields_end
 };

Now that I've read the thread ...

Quoted 4 lines

If we care about struct size on 32-bit, we should fit something into the 32-bit hole before the 64-bit loff_t (assuming at least some 32-bit arches want loff_t to be 64-bit aligned; I thik x86 doesn't?) Easiest seems to be to put ki_complete before ki_pos?

Yes, that would be a better compact arrangment. The immediate need was just to correct io_uring's max command struct size. The 32-bit verison isn't near the limit, so no additional optimizations were done in this patch.