From: Scott Branden <scott.branden@broadcom.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
Wolfram Sang <wsa@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
David Brown <david.brown@linaro.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Shuah Khan <shuah@kernel.org>,
bjorn.andersson@linaro.org,
Shuah Khan <skhan@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>, Mimi Zohar <zohar@linux.ibm.com>,
"Rafael J . Wysocki" <rafael@kernel.org>,
linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-fsdevel@vger.kernel.org,
BCM Kernel Feedback <bcm-kernel-feedback-list@broadcom.com>,
Olof Johansson <olof@lixom.net>,
Andrew Morton <akpm@linux-foundation.org>,
Dan Carpenter <dan.carpenter@oracle.com>,
Colin Ian King <colin.king@canonical.com>,
Kees Cook <keescook@chromium.org>, Takashi Iwai <tiwai@suse.de>,
linux-kselftest@vger.kernel.org, Andy Gross <agross@kernel.org>,
linux-integrity@vger.kernel.org,
linux-security-module@vger.kernel.org,
Christoph Hellwig <hch@infradead.org>
Subject: Re: [PATCH v7 1/8] fs: introduce kernel_pread_file* support
Date: Tue, 9 Jun 2020 15:55:15 -0700 [thread overview]
Message-ID: <c983b910-d216-559a-60b5-dc8b4b2435a2@broadcom.com> (raw)
In-Reply-To: <20200609132151.GC19604@bombadil.infradead.org>
Hi Matthew,
On 2020-06-09 6:21 a.m., Matthew Wilcox wrote:
> On Mon, Jun 08, 2020 at 03:29:22PM -0700, Scott Branden wrote:
>> Hi Matthew,
>>
>> I am requesting the experts in the filesystem subsystem to come to a
>> consensus here.
>> This is not my area of expertise at all but every time I have addressed all
>> of the
>> outstanding concerns someone else comes along and raises another one.
> I appreciate it's frustrating for you, but this is the nature of
> patch review. I haven't even read the first five or so submissions.
> I can see them in my inbox and they look like long threads. I'm not
> particularly inclined to read them. I happened to read v6, and reacted
> to the API being ugly.
Thanks for the review. Yes, I do see the enum being ugly now
and have removed it in v8 of the patch. Hopefully it addresses
your concerns. More comments below.
>
>> Please see me comments below.
>>
>> On 2020-06-06 8:52 a.m., Matthew Wilcox wrote:
>>> On Fri, Jun 05, 2020 at 10:04:51PM -0700, Scott Branden wrote:
>>>> -int kernel_read_file(struct file *file, void **buf, loff_t *size,
>>>> - loff_t max_size, enum kernel_read_file_id id)
>>>> -{
>>>> - loff_t i_size, pos;
>> Please note that how checkpatch generated the diff here. The code
>> modifications
>> below are for a new function kernel_pread_file, they do not modify the
>> existing API
>> kernel_read_file. kernel_read_file requests the ENTIRE file is read. So we
>> need to be
>> able to differentiate whether it is ok to read just a portion of the file or
>> not.
> You've gone about this in entirely the wrong way though. This enum to
> read the entire file or a partial is just bad design.
Your point on the enum is valid.
I've removed it from design. Hopefully it is cleaner now.
>
>>>> +int kernel_pread_file(struct file *file, void **buf, loff_t *size,
>>>> + loff_t pos, loff_t max_size,
>>>> + enum kernel_pread_opt opt,
>>>> + enum kernel_read_file_id id)
>> So, to share common code a new kernel_pread_opt needed to be added in order
>> to specify whether
>> it was ok to read a partial file or not, and provide an offset into the file
>> where to begin reading.
>> The meaning of parameters doesn't change in the bonkers API. max_size still
>> means max size, etc.
>> These options are needed so common code can be shared with kernel_read_file
>> api.
> Does pread() in userspace take seven parameters? No. It takes four.
> What you're doing is taking all the complexity of all of the interfaces
> and stuffing it all down into the bottom function instead of handling
> some of the complexity in the wrapper functions. For example, you
> could support the functionality of 'max_size' in kernel_read_file()
> and leave it out of the kernel_pread_file() interface.
I have removed the enum necessary in the kernel pread call now,
so it is down to 6.
The other 2 parameters are necessary as they are in kernel read.
max_size makes no sense to remove - it serves the same purpose
as in userspace pread and read functions. To specify the max size
to read.
>>> I think what we actually want is:
>>>
>>> ssize_t vmap_file_range(struct file *, loff_t start, loff_t end, void **bufp);
>>> void vunmap_file_range(struct file *, void *buf);
>>>
>>> If end > i_size, limit the allocation to i_size. Returns the number
>>> of bytes allocated, or a negative errno. Writes the pointer allocated
>>> to *bufp. Internally, it should use the page cache to read in the pages
>>> (taking appropriate reference counts). Then it maps them using vmap()
>>> instead of copying them to a private vmalloc() array.
>>> kernel_read_file() can be converted to use this API. The users will
>>> need to be changed to call kernel_read_end(struct file *file, void *buf)
>>> instead of vfree() so it can call allow_write_access() for them.
>>>
>>> vmap_file_range() has a lot of potential uses. I'm surprised we don't
>>> have it already, to be honest.
>> Such a change sounds like it could be done in a later patch series.
>> It's an incomplete solution. It would work for some of the needed
>> operations but not others.
>> For kernel_read_file, I don't see how in your new API it indicates if the
>> end of the file was reached or not.
> That's the point. It doesn't. If a caller needs that, then they can
> figure that out themselves.
No, they can't. The caller only calls kernel_read_file once and expects
the whole file to be read. The kernel_read_file doesn't work like
userspace.
There is no tracking like userspace of where in the file you read?
>
>> Also, please note that buffers may be preallocated and shouldn't be freed
>> by the kernel in some cases and
>> allocated and freed by the kernel in others.
> You're trying to build the swiss army knife of functions. Swiss army
> knives are useful, but they're no good for carving a steak.
Hopefully I'm carving steak now.
>> I would like the experts here to decide on what needs to be done so we can
>> move forward
>> and get kernel_pread_file support added soon.
> You know, you haven't even said _why_ you want this. The cover letter
> just says "I want this", and doesn't say why it's needed.
Cover letter updated.
Thanks,
Scott
next prev parent reply other threads:[~2020-06-09 22:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-06 5:04 [PATCH v7 0/8] firmware: add partial read support in request_firmware_into_buf Scott Branden
2020-06-06 5:04 ` [PATCH v7 1/8] fs: introduce kernel_pread_file* support Scott Branden
2020-06-06 15:52 ` Matthew Wilcox
2020-06-08 13:03 ` Mimi Zohar
2020-06-08 13:16 ` Matthew Wilcox
2020-06-08 13:22 ` Mimi Zohar
2020-06-08 13:27 ` Mimi Zohar
2020-06-08 13:32 ` Matthew Wilcox
2020-06-08 22:29 ` Scott Branden
2020-06-09 13:21 ` Matthew Wilcox
2020-06-09 22:55 ` Scott Branden [this message]
2020-06-06 5:04 ` [PATCH v7 2/8] firmware: add offset to request_firmware_into_buf Scott Branden
2020-06-09 14:34 ` Matthew Wilcox
2020-06-06 5:04 ` [PATCH v7 3/8] test_firmware: add partial read support for request_firmware_into_buf Scott Branden
2020-06-06 5:04 ` [PATCH v7 4/8] firmware: test partial file reads of request_firmware_into_buf Scott Branden
2020-06-06 5:04 ` [PATCH v7 5/8] bcm-vk: add bcm_vk UAPI Scott Branden
2020-06-06 5:04 ` [PATCH v7 6/8] misc: bcm-vk: add Broadcom VK driver Scott Branden
2020-06-06 5:04 ` [PATCH v7 7/8] MAINTAINERS: bcm-vk: add maintainer for Broadcom VK Driver Scott Branden
2020-06-06 5:04 ` [PATCH v7 8/8] ima: add FIRMWARE_PARTIAL_READ support Scott Branden
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c983b910-d216-559a-60b5-dc8b4b2435a2@broadcom.com \
--to=scott.branden@broadcom.com \
--cc=agross@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bjorn.andersson@linaro.org \
--cc=colin.king@canonical.com \
--cc=dan.carpenter@oracle.com \
--cc=david.brown@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=hch@infradead.org \
--cc=keescook@chromium.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=olof@lixom.net \
--cc=rafael@kernel.org \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tiwai@suse.de \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
--cc=wsa@kernel.org \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®