From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751493AbeEVPce (ORCPT ); Tue, 22 May 2018 11:32:34 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:32854 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751317AbeEVPca (ORCPT ); Tue, 22 May 2018 11:32:30 -0400 X-Google-Smtp-Source: AB8JxZoRc4lssU9Ca8zZRuMfbh3bVOrm8gOw63J+k6gge5qUtR0CyabIWw49obeH3peyDq5ZUtqUdA== Subject: Re: [PATCH v6 2/5] fs: Convert kiocb rw_hint from enum to u16 To: adam.manzanares@wdc.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, bcrl@kvack.org Cc: tglx@linutronix.de, mingo@kernel.org, pombredanne@nexb.com, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, bigeasy@linutronix.de, jack@suse.cz, darrick.wong@oracle.com, rgoldwyn@suse.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-aio@kvack.org, linux-api@vger.kernel.org, hch@infradread.org, jmoyer@redhat.com References: <20180522150737.9893-1-adam.manzanares@wdc.com> <20180522150737.9893-3-adam.manzanares@wdc.com> From: Jens Axboe Message-ID: <11fb2ee5-8352-2d35-3154-68637d99b096@kernel.dk> Date: Tue, 22 May 2018 09:32:26 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20180522150737.9893-3-adam.manzanares@wdc.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/22/18 9:07 AM, adam.manzanares@wdc.com wrote: > From: Adam Manzanares > > In order to avoid kiocb bloat for per command iopriority support, rw_hint > is converted from enum to a u16. Added a guard around ki_hint assignment. > > Signed-off-by: Adam Manzanares > Reviewed-by: Christoph Hellwig > --- > include/linux/fs.h | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 7f07977bdfd7..50de40dbbb85 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -284,6 +284,8 @@ enum rw_hint { > WRITE_LIFE_EXTREME = RWH_WRITE_LIFE_EXTREME, > }; > > +#define MAX_KI_HINT ((1 << 16) - 1) /* ki_hint type is u16 */ Instead of having to do this and now rely on those now being synced, how about something like the below. diff --git a/include/linux/fs.h b/include/linux/fs.h index 760d8da1b6c7..070438d0b62d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -299,7 +299,7 @@ struct kiocb { void (*ki_complete)(struct kiocb *iocb, long ret, long ret2); void *private; int ki_flags; - enum rw_hint ki_hint; + u16 ki_hint; } __randomize_layout; static inline bool is_sync_kiocb(struct kiocb *kiocb) @@ -1927,12 +1927,22 @@ static inline enum rw_hint file_write_hint(struct file *file) static inline int iocb_flags(struct file *file); +static inline u16 ki_hint_validate(enum rw_hint hint) +{ + typeof(((struct kiocb *)0)->ki_hint) max_hint = -1; + + if (hint <= max_hint) + return hint; + + return 0; +} + static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) { *kiocb = (struct kiocb) { .ki_filp = filp, .ki_flags = iocb_flags(filp), - .ki_hint = file_write_hint(filp), + .ki_hint = ki_hint_validate(file_write_hint(filp)), }; } -- Jens Axboe