fs: add partial file read support
Subsystems (6)
cover fs: add partial file read support
This patch series adds partial file read support to the kernel via kernel_pread_file functions. request_firmware_into_buf function enhanced to allow partial file read support and single qcom driver using existing function updated.
Change to core kernel file support allows new drivers to read partial file to memory as necessary in memory constrained systems.
Scott Branden (3):
fs: introduce kernel_pread_file* support
firmware: add offset to request_firmware_into_buf
soc: qcom: mdt_loader: add offset to request_firmware_into_buf
drivers/base/firmware_loader/firmware.h | 5 ++ drivers/base/firmware_loader/main.c | 49 +++++++++++----- drivers/soc/qcom/mdt_loader.c | 7 ++- fs/exec.c | 77 +++++++++++++++++++------ include/linux/firmware.h | 8 ++- include/linux/fs.h | 15 +++++ 6 files changed, 125 insertions(+), 36 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 fs: introduce kernel_pread_file* support
Add kernel_pread_file* support to kernel to allow for partial read of files with an offset into the file. Existing kernel_read_file functions call new kernel_pread_file functions with offset=0 and flags=KERNEL_PREAD_FLAG_WHOLE.
--- fs/exec.c | 77 ++++++++++++++++++++++++++++++++++++---------- include/linux/fs.h | 15 +++++++++ 2 files changed, 75 insertions(+), 17 deletions(-)
fs/exec.c +60 -17
@@ -892,10 +892,14 @@ struct file *open_exec(const char *name) }EXPORT_SYMBOL (open_exec); -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; +int kernel_pread_file (struct file *file,void **buf,loff_t *size, +loff_t pos,loff_t max_size,unsigned int flags, +enum kernel_read_file_id id) +{ +loff_t alloc_size; +loff_t buf_pos; +loff_t read_end; +loff_t i_size;ssize_t bytes =0 ;int ret;
@@ -915,21 +919,31 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size, ret = -EINVAL ; goto out; } -if (i_size >SIZE_MAX || (max_size >0 && i_size > max_size)) { + +/* Default read to end of file */ + read_end = i_size; + +/* Allow reading partial portion of file */ +if ((flags &KERNEL_PREAD_FLAG_PART ) && + (i_size > (pos + max_size))) + read_end = pos + max_size; + + alloc_size = read_end - pos; +if (i_size >SIZE_MAX || (max_size >0 && alloc_size > max_size)) { ret = -EFBIG ; goto out; }if (id !=READING_FIRMWARE_PREALLOC_BUFFER ) - *buf =vmalloc (i_size); + *buf =vmalloc (alloc_size);if (!*buf) { ret = -ENOMEM ; goto out; } - pos =0 ; -while (pos < i_size) { - bytes =kernel_read (file, *buf + pos, i_size - pos, &pos); + buf_pos =0 ; +while (pos < read_end) { + bytes =kernel_read (file, *buf + buf_pos, read_end - pos, &pos);if (bytes <0 ) { ret = bytes; goto out_free;
@@ -937,14 +951,16 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size,if (bytes ==0 )break ; + + buf_pos += bytes; } -if (pos != i_size) { +if (pos != read_end) { ret = -EIO ; goto out_free; } - ret =security_kernel_post_read_file (file, *buf, i_size, id); + ret =security_kernel_post_read_file (file, *buf, alloc_size, id);if (!ret) *size = pos;
@@ -960,10 +976,20 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size,allow_write_access (file);return ret; } +EXPORT_SYMBOL_GPL (kernel_pread_file); + +int kernel_read_file (struct file *file,void **buf,loff_t *size, +loff_t max_size,enum kernel_read_file_id id) +{ +return kernel_pread_file (file, buf, size,0 , max_size, +KERNEL_PREAD_FLAG_WHOLE , id); +}EXPORT_SYMBOL_GPL (kernel_read_file); -int kernel_read_file_from_path (const char *path,void **buf,loff_t *size, -loff_t max_size,enum kernel_read_file_id id) +int kernel_pread_file_from_path (const char *path,void **buf, +loff_t *size,loff_t pos, +loff_t max_size,unsigned int flags, +enum kernel_read_file_id id) {struct file *file;int ret;
@@ -975,14 +1001,23 @@ int kernel_read_file_from_path(const char *path, void **buf, loff_t *size,if (IS_ERR (file))return PTR_ERR (file); - ret =kernel_read_file (file, buf, size, max_size, id); + ret =kernel_pread_file (file, buf, size, pos, max_size, flags, id);fput (file);return ret; } +EXPORT_SYMBOL_GPL (kernel_pread_file_from_path); + +int kernel_read_file_from_path (const char *path,void **buf,loff_t *size, +loff_t max_size,enum kernel_read_file_id id) +{ +return kernel_pread_file_from_path (path, buf, size,0 , max_size, +KERNEL_PREAD_FLAG_WHOLE , id); +}EXPORT_SYMBOL_GPL (kernel_read_file_from_path); -int kernel_read_file_from_fd (int fd,void **buf,loff_t *size,loff_t max_size, -enum kernel_read_file_id id) +int kernel_pread_file_from_fd (int fd,void **buf,loff_t *size,loff_t pos, +loff_t max_size,unsigned int flags, +enum kernel_read_file_id id) {struct fd f =fdget (fd);int ret = -EBADF ;
@@ -990,11 +1025,19 @@ int kernel_read_file_from_fd(int fd, void **buf, loff_t *size, loff_t max_size,if (!f.file) goto out; - ret =kernel_read_file (f.file, buf, size, max_size, id); + ret =kernel_pread_file (f.file, buf, size, pos, max_size, flags, id); out:fdput (f);return ret; } +EXPORT_SYMBOL_GPL (kernel_pread_file_from_fd); + +int kernel_read_file_from_fd (int fd,void **buf,loff_t *size,loff_t max_size, +enum kernel_read_file_id id) +{ +return kernel_pread_file_from_fd (fd, buf, size,0 , max_size, +KERNEL_PREAD_FLAG_WHOLE , id); +}EXPORT_SYMBOL_GPL (kernel_read_file_from_fd);ssize_t read_code (struct file *file,unsigned long addr,loff_t pos,size_t len)
include/linux/fs.h +15 -0
@@ -2942,10 +2942,25 @@ static inline const char *kernel_read_file_id_str(enum kernel_read_file_id id)return kernel_read_file_str[id]; } +/* Flags used by kernel_pread_file functions */ +#define KERNEL_PREAD_FLAG_WHOLE 0x0000/* Only Allow reading of whole file */ +#define KERNEL_PREAD_FLAG_PART 0x0001/* Allow reading part of file */ + +extern int kernel_pread_file (struct file *file,void **buf,loff_t *size, +loff_t pos,loff_t max_size,unsigned int flags, +enum kernel_read_file_id id);extern int kernel_read_file (struct file *,void **,loff_t *,loff_t ,enum kernel_read_file_id ); +extern int kernel_pread_file_from_path (const char *path,void **buf, +loff_t *size,loff_t pos, +loff_t max_size,unsigned int flags, +enum kernel_read_file_id id);extern int kernel_read_file_from_path (const char *,void **,loff_t *,loff_t ,enum kernel_read_file_id ); +extern int kernel_pread_file_from_fd (int fd,void **buf,loff_t *size, +loff_t pos,loff_t max_size, +unsigned int flags, +enum kernel_read_file_id id);extern int kernel_read_file_from_fd (int ,void **,loff_t *,loff_t ,enum kernel_read_file_id );extern ssize_t kernel_read (struct file *,void *,size_t ,loff_t *);
Signature · 1 line
2.17.1
PATCH 2/3 firmware: add offset to request_firmware_into_buf
In reply to Scott BrandenAdd offset to request_firmware_into_buf to allow for portions of firmware file to be read into a buffer. Necessary where firmware needs to be loaded in portions from file in memory constrained systems.
--- drivers/base/firmware_loader/firmware.h | 5 +++ drivers/base/firmware_loader/main.c | 49 +++++++++++++++++-------- include/linux/firmware.h | 8 +++- 3 files changed, 45 insertions(+), 17 deletions(-)
drivers/base/firmware_loader/firmware.h +5 -0
@@ -29,6 +29,8 @@* firmware caching mechanism. * @FW_OPT_NOFALLBACK: Disable the fallback mechanism. Takes precedence over * &FW_OPT_UEVENT and &FW_OPT_USERHELPER. +* @FW_OPT_PARTIAL: Allow partial read of firmware instead of needing to read +* entire file. */ enum fw_opt {FW_OPT_UEVENT =BIT (0 ),
@@ -37,6 +39,7 @@ enum fw_opt {FW_OPT_NO_WARN =BIT (3 ),FW_OPT_NOCACHE =BIT (4 ),FW_OPT_NOFALLBACK =BIT (5 ), + FW_OPT_PARTIAL = BIT(6), }; enum fw_status {
@@ -64,6 +67,8 @@ struct fw_priv {void *data;size_t size;size_t allocated_size; +size_t offset; +unsigned int flags;#ifdef CONFIG_FW_LOADER_USER_HELPER bool is_paged_buf;bool need_uevent;
drivers/base/firmware_loader/main.c +34 -15
149 lines not on this page · raw message
include/linux/firmware.h +6 -2
@@ -4,6 +4,7 @@#include <linux/types.h> #include <linux/compiler.h> +#include <linux/fs.h> #include <linux/gfp.h> #define FW_ACTION_NOHOTPLUG 0
@@ -51,7 +52,9 @@ int request_firmware_nowait(int request_firmware_direct (const struct firmware **fw,const char *name,struct device *device);int request_firmware_into_buf (const struct firmware **firmware_p, -const char *name,struct device *device,void *buf,size_t size); +const char *name,struct device *device, +void *buf,size_t size, +size_t offset,unsigned int pread_flags);void release_firmware (const struct firmware *fw);#else
@@ -89,7 +92,8 @@ static inline int request_firmware_direct(const struct firmware **fw, }static inline int request_firmware_into_buf (const struct firmware **firmware_p, -const char *name,struct device *device,void *buf,size_t size) +const char *name,struct device *device,void *buf,size_t size, +size_t offset,unsigned int pread_flags); {return -EINVAL ; }
Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerRe: [PATCH 2/3] firmware: add offset to request_firmware_into_buf
Quoted 10 lines · Scott Branden
Add offset to
request_firmware_into_bufto allow for portions of firmware file to be read into a buffer. Necessary where firmware needs to be loaded in portions from file in memory constrained systems.Signed-off-by Scott Branden <[email protected]>--- drivers/base/firmware_loader/firmware.h | 5 +++ drivers/base/firmware_loader/main.c | 49 +++++++++++++++++-------- include/linux/firmware.h | 8 +++- 3 files changed, 45 insertions(+), 17 deletions(-)
No new firmware test for this new option? How do we know it even works? :)
thanks,
greg k-h
Re: [PATCH 2/3] firmware: add offset to request_firmware_into_buf
Hi Greg,
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Scott Branden
Add offset to
request_firmware_into_bufto allow for portions of firmware file to be read into a buffer. Necessary where firmware needs to be loaded in portions from file in memory constrained systems.
Quoted 7 lines
Quoted 6 lines
Signed-off-by Scott Branden <[email protected]>--- drivers/base/firmware_loader/firmware.h | 5 +++ drivers/base/firmware_loader/main.c | 49 +++++++++++++++++-------- include/linux/firmware.h | 8 +++- 3 files changed, 45 insertions(+), 17 deletions(-)No new firmware test for this new option? How do we know it even works?
I was unaware there are existing firmware tests. Please let me know where these tests exists and I can add a test for this new option.
We have tested this with a new driver in development which requires the firmware file to be read in portions into memory. I can add my tested-by and others to the commit message if desired.
Quoted 5 lines
:)
thanks,
greg k-h
Regards,
Scott
Greg Kroah-Hartman
maintainerRe: [PATCH 2/3] firmware: add offset to request_firmware_into_buf
Quoted 14 lines · Scott Branden
Hi Greg,
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Scott Branden
Add offset to
request_firmware_into_bufto allow for portions of firmware file to be read into a buffer. Necessary where firmware needs to be loaded in portions from file in memory constrained systems.Signed-off-by Scott Branden <[email protected]>--- drivers/base/firmware_loader/firmware.h | 5 +++ drivers/base/firmware_loader/main.c | 49 +++++++++++++++++-------- include/linux/firmware.h | 8 +++- 3 files changed, 45 insertions(+), 17 deletions(-)
Quoted 4 lines
Quoted 1 line
No new firmware test for this new option? How do we know it even works?
I was unaware there are existing firmware tests. Please let me know where these tests exists and I can add a test for this new option.
tools/testing/selftests/firmware/
Quoted 3 lines
We have tested this with a new driver in development which requires the firmware file to be read in portions into memory. I can add my tested-by and others to the commit message if desired.
I can't take new apis without an in-kernel user, you all know this...
thanks,
greg k-h
Re: [PATCH 2/3] firmware: add offset to request_firmware_into_buf
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Scott Branden
Hi Greg,
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Scott Branden
Add offset to
request_firmware_into_bufto allow for portions of firmware file to be read into a buffer. Necessary where firmware needs to be loaded in portions from file in memory constrained systems.Signed-off-by Scott Branden <[email protected]>--- drivers/base/firmware_loader/firmware.h | 5 +++ drivers/base/firmware_loader/main.c | 49 +++++++++++++++++-------- include/linux/firmware.h | 8 +++- 3 files changed, 45 insertions(+), 17 deletions(-)
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
No new firmware test for this new option? How do we know it even works?
I was unaware there are existing firmware tests. Please let me know where these tests exists and I can add a test for this new option.
tools/testing/selftests/firmware/
Unfortunately, there doesn't seem to be a test for the existing request_firmware_into_buf api.
Looks like it will be more work that I thought enhancing a test that doesn't exist.
Quoted 5 lines
Quoted 4 lines
We have tested this with a new driver in development which requires the firmware file to be read in portions into memory. I can add my tested-by and others to the commit message if desired.
I can't take new apis without an in-kernel user, you all know this...
OK, It will have to wait then as I was hoping to get this in before my leave.
But adding a selftest and upstreaming the necessary driver
won't be possible for a few months now.
Quoted 4 lines
thanks,
greg k-h
Thanks for explaining the requirements.
Scott
Greg Kroah-Hartman
maintainerRe: [PATCH 2/3] firmware: add offset to request_firmware_into_buf
Quoted 17 lines · Scott Branden
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Scott Branden
Hi Greg,
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Scott Branden
Add offset to
request_firmware_into_bufto allow for portions of firmware file to be read into a buffer. Necessary where firmware needs to be loaded in portions from file in memory constrained systems.Signed-off-by Scott Branden <[email protected]>--- drivers/base/firmware_loader/firmware.h | 5 +++ drivers/base/firmware_loader/main.c | 49 +++++++++++++++++-------- include/linux/firmware.h | 8 +++- 3 files changed, 45 insertions(+), 17 deletions(-)
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
No new firmware test for this new option? How do we know it even works?
I was unaware there are existing firmware tests. Please let me know where these tests exists and I can add a test for this new option.
tools/testing/selftests/firmware/Unfortunately, there doesn't seem to be a test for the existing
request_firmware_into_bufapi.
Are you sure? The test is for userspace functionality, there isn't kernel unit tests here. You need to verify that you didn't break existing functionality as well as verify that your new functionality works.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
We have tested this with a new driver in development which requires the firmware file to be read in portions into memory. I can add my tested-by and others to the commit message if desired.
I can't take new apis without an in-kernel user, you all know this...
OK, It will have to wait then as I was hoping to get this in before my leave.
Throwing new code over the wall and running away is a sure way to ensure that your code will be ignored :)
thanks,
greg k-h
Re: [PATCH 2/3] firmware: add offset to request_firmware_into_buf
Hi Greg,
I am now back from leave to continue this patch. Comment below.
Quoted 20 lines · Greg Kroah-Hartman
Quoted 19 lines · Scott Branden
Quoted 18 lines · Greg Kroah-Hartman
Quoted 17 lines · Scott Branden
Hi Greg,
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Scott Branden
Add offset to
request_firmware_into_bufto allow for portions of firmware file to be read into a buffer. Necessary where firmware needs to be loaded in portions from file in memory constrained systems.Quoted 7 lines
Quoted 6 lines
Signed-off-by Scott Branden <[email protected]>--- drivers/base/firmware_loader/firmware.h | 5 +++ drivers/base/firmware_loader/main.c | 49 +++++++++++++++++-------- include/linux/firmware.h | 8 +++- 3 files changed, 45 insertions(+), 17 deletions(-)No new firmware test for this new option? How do we know it even works?
I was unaware there are existing firmware tests. Please let me know where these tests exists and I can add a test for this new option.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
tools/testing/selftests/firmware/Unfortunately, there doesn't seem to be a test for the existing
request_firmware_into_bufapi.Are you sure? The test is for userspace functionality, there isn't kernel unit tests here. You need to verify that you didn't break existing functionality as well as verify that your new functionality works.
I managed to figure out how to build and run tools/testing/selftest/firmware/fw_run_tests.sh
and my changes don't break existing functionality.
But, I find no use of request_firmware_into_buf in lib/test_firmware.c (triggered by fw_run_tests.sh).
Is there another test for request_firmware_into_buf?
Quoted 12 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
We have tested this with a new driver in development which requires the firmware file to be read in portions into memory. I can add my tested-by and others to the commit message if desired.
I can't take new apis without an in-kernel user, you all know this...
OK, It will have to wait then as I was hoping to get this in before my leave.
Throwing new code over the wall and running away is a sure way to ensure that your code will be ignored :)
thanks,
greg k-h
Greg Kroah-Hartman
maintainerRe: [PATCH 2/3] firmware: add offset to request_firmware_into_buf
Quoted 36 lines · Scott Branden
Hi Greg,
I am now back from leave to continue this patch. Comment below.
Quoted 20 lines · Greg Kroah-Hartman
Quoted 19 lines · Scott Branden
Quoted 18 lines · Greg Kroah-Hartman
Quoted 17 lines · Scott Branden
Hi Greg,
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Scott Branden
Add offset to
request_firmware_into_bufto allow for portions of firmware file to be read into a buffer. Necessary where firmware needs to be loaded in portions from file in memory constrained systems.Quoted 7 lines
Quoted 6 lines
Signed-off-by Scott Branden <[email protected]>--- drivers/base/firmware_loader/firmware.h | 5 +++ drivers/base/firmware_loader/main.c | 49 +++++++++++++++++-------- include/linux/firmware.h | 8 +++- 3 files changed, 45 insertions(+), 17 deletions(-)No new firmware test for this new option? How do we know it even works?
I was unaware there are existing firmware tests. Please let me know where these tests exists and I can add a test for this new option.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
tools/testing/selftests/firmware/Unfortunately, there doesn't seem to be a test for the existing
request_firmware_into_bufapi.Are you sure? The test is for userspace functionality, there isn't kernel unit tests here. You need to verify that you didn't break existing functionality as well as verify that your new functionality works.
I managed to figure out how to build and run
tools/testing/selftest/firmware/fw_run_tests.sh
Quoted 6 lines
and my changes don't break existing functionality.
But, I find no use of
request_firmware_into_bufinlib/test_firmware.c(triggered byfw_run_tests.sh).Is there another test for
request_firmware_into_buf?
I have no idea, sorry.
greg k-h
Luis Chamberlain
maintainerRe: [PATCH 2/3] firmware: add offset to request_firmware_into_buf
Quoted 34 lines · Greg Kroah-Hartman
Quoted 33 lines · Scott Branden
Hi Greg,
I am now back from leave to continue this patch. Comment below.
Quoted 27 lines · Greg Kroah-Hartman
Quoted 16 lines · Scott Branden
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Scott Branden
Hi Greg,
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Scott Branden
Add offset to
request_firmware_into_bufto allow for portions of firmware file to be read into a buffer. Necessary where firmware needs to be loaded in portions from file in memory constrained systems.Signed-off-by Scott Branden <[email protected]>--- drivers/base/firmware_loader/firmware.h | 5 +++ drivers/base/firmware_loader/main.c | 49 +++++++++++++++++-------- include/linux/firmware.h | 8 +++- 3 files changed, 45 insertions(+), 17 deletions(-)Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
No new firmware test for this new option? How do we know it even works?
I was unaware there are existing firmware tests. Please let me know where these tests exists and I can add a test for this new option.
tools/testing/selftests/firmware/Unfortunately, there doesn't seem to be a test for the existing
request_firmware_into_bufapi.Are you sure? The test is for userspace functionality, there isn't kernel unit tests here. You need to verify that you didn't break existing functionality as well as verify that your new functionality works.
Quoted 4 lines
Quoted 4 lines
I managed to figure out how to build and run
tools/testing/selftest/firmware/fw_run_tests.shand my changes don't break existing functionality.
I'm soon going to release something that is going to let you do this faster and easier, let me know if you had troubles in trying to figure out how to not regress the kernel using this.
Quoted 6 lines
Quoted 4 lines
But, I find no use of
request_firmware_into_bufinlib/test_firmware.c(triggered byfw_run_tests.sh).Is there another test for
request_firmware_into_buf?I have no idea, sorry.
The folks who implemented request_firmware_into_buf() didn't add a respective test, because, well, this API went upstream IMO without much ACKs / review, and even no damn users. Now we have a user so we're stuck with it.
So new testing calls for it would be appreciated. If you have questions I am happy to help.
Luis
Re: [PATCH 2/3] firmware: add offset to request_firmware_into_buf
Hi Luis,
Quoted 34 lines · Luis Chamberlain
Quoted 33 lines · Greg Kroah-Hartman
Quoted 32 lines · Scott Branden
Hi Greg,
I am now back from leave to continue this patch. Comment below.
Quoted 27 lines · Greg Kroah-Hartman
Quoted 16 lines · Scott Branden
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Scott Branden
Hi Greg,
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Scott Branden
Add offset to
request_firmware_into_bufto allow for portions of firmware file to be read into a buffer. Necessary where firmware needs to be loaded in portions from file in memory constrained systems.Signed-off-by Scott Branden <[email protected]>--- drivers/base/firmware_loader/firmware.h | 5 +++ drivers/base/firmware_loader/main.c | 49 +++++++++++++++++-------- include/linux/firmware.h | 8 +++- 3 files changed, 45 insertions(+), 17 deletions(-)Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
No new firmware test for this new option? How do we know it even works?
I was unaware there are existing firmware tests. Please let me know where these tests exists and I can add a test for this new option.
tools/testing/selftests/firmware/Unfortunately, there doesn't seem to be a test for the existing
request_firmware_into_bufapi.Are you sure? The test is for userspace functionality, there isn't kernel unit tests here. You need to verify that you didn't break existing functionality as well as verify that your new functionality works.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
I managed to figure out how to build and run
tools/testing/selftest/firmware/fw_run_tests.shand my changes don't break existing functionality.
I'm soon going to release something that is going to let you do this faster and easier, let me know if you had troubles in trying to figure out how to not regress the kernel using this.
Yes, I had troubles in trying to figure it out. The kernel build should
create an entire initrd with all the necessary components in it for testing purposes.
And the firmware test will now take me some time to figure out how it all works.
Could you please explain what you are going to release soon? I don't want to waste
my time getting something working if everything is going to change on me right away?
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
But, I find no use of
request_firmware_into_bufinlib/test_firmware.c(triggered byfw_run_tests.sh).Is there another test for
request_firmware_into_buf?I have no idea, sorry.
The folks who implemented
request_firmware_into_buf()didn't add a respective test, because, well, this API went upstream IMO without much ACKs / review, and even no damn users. Now we have a user so we're stuck with it.
The request_firmware_into_buf is a necessity for me as well
(along with the need for a partial request of the file which I'm adding).
Quoted 3 lines
So new testing calls for it would be appreciated. If you have questions I am happy to help.
If you're an expert on the firmware test and can quickly add a simple test of request_firmware_into_buf
it would be appreciated. If not, I'm going to have to dig further into this and send early versions of
a test out which would be great for you to comment on.
Quoted 2 lines
Luis
Thanks,
Scott
Luis Chamberlain
maintainerRe: [PATCH 2/3] firmware: add offset to request_firmware_into_buf
Quoted 47 lines · Scott Branden
Hi Luis,
Quoted 34 lines · Luis Chamberlain
Quoted 33 lines · Greg Kroah-Hartman
Quoted 32 lines · Scott Branden
Hi Greg,
I am now back from leave to continue this patch. Comment below.
Quoted 27 lines · Greg Kroah-Hartman
Quoted 16 lines · Scott Branden
Quoted 15 lines · Greg Kroah-Hartman
Quoted 14 lines · Scott Branden
Hi Greg,
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Scott Branden
Add offset to
request_firmware_into_bufto allow for portions of firmware file to be read into a buffer. Necessary where firmware needs to be loaded in portions from file in memory constrained systems.Signed-off-by Scott Branden <[email protected]>--- drivers/base/firmware_loader/firmware.h | 5 +++ drivers/base/firmware_loader/main.c | 49 +++++++++++++++++-------- include/linux/firmware.h | 8 +++- 3 files changed, 45 insertions(+), 17 deletions(-)Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
No new firmware test for this new option? How do we know it even works?
I was unaware there are existing firmware tests. Please let me know where these tests exists and I can add a test for this new option.
tools/testing/selftests/firmware/Unfortunately, there doesn't seem to be a test for the existing
request_firmware_into_bufapi.Are you sure? The test is for userspace functionality, there isn't kernel unit tests here. You need to verify that you didn't break existing functionality as well as verify that your new functionality works.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
I managed to figure out how to build and run
tools/testing/selftest/firmware/fw_run_tests.shand my changes don't break existing functionality.
I'm soon going to release something that is going to let you do this faster and easier, let me know if you had troubles in trying to figure out how to not regress the kernel using this.
Yes, I had troubles in trying to figure it out. The kernel build should
Quoted 8 lines
create an entire initrd with all the necessary components in it for testing purposes.
And the firmware test will now take me some time to figure out how it all works.
Could you please explain what you are going to release soon? I don't want to waste
Sorry for the delay but I promise that I tried hard to get this out ASAP.
https://github.com/mcgrof/fw-kdevops
This now can be used to more easily let you start an environment to test the firmware API.
Too late for you I gather, but perhaps others can take advantage.
Luis
PATCH 3/3 soc: qcom: mdt_loader: add offset to request_firmware_into_buf
In reply to Scott BrandenAdjust request_firmware_into_buf API to allow for portions of firmware file to be read into a buffer. mdt_loader still retricts request fo whole file read into buffer.
--- drivers/soc/qcom/mdt_loader.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/soc/qcom/mdt_loader.c +5 -2
@@ -172,8 +172,11 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,if (phdr->p_filesz) {sprintf (fw_name + fw_name_len -3 ,"b%02d" , i); - ret =request_firmware_into_buf (&seg_fw, fw_name, dev, - ptr, phdr->p_filesz); + ret =request_firmware_into_buf + (&seg_fw, fw_name, dev, + ptr, phdr->p_filesz, +0 , +KERNEL_PREAD_FLAG_WHOLE );if (ret) {dev_err (dev,"failed to load %s\n" , fw_name);break ;
Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerRe: [PATCH 3/3] soc: qcom: mdt_loader: add offset to request_firmware_into_buf
Quoted 14 lines · Scott Branden
Adjust
request_firmware_into_bufAPI to allow for portions of firmware file to be read into a buffer.mdt_loaderstill retricts request fo whole file read into buffer.Signed-off-by Scott Branden <[email protected]>--- drivers/soc/qcom/mdt_loader.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/soc/qcom/mdt_loader.c +0
-0
drivers/soc/qcom/mdt_loader.c static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, · line 179
Quoted 10 lines
drivers/soc/qcom/mdt_loader.c +5
-2@@ -172,8 +172,11 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,if (phdr->p_filesz) {sprintf (fw_name + fw_name_len -3 ,"b%02d" , i); - ret =request_firmware_into_buf (&seg_fw, fw_name, dev, - ptr, phdr->p_filesz); + ret =request_firmware_into_buf + (&seg_fw, fw_name, dev, + ptr, phdr->p_filesz, +0 , +KERNEL_PREAD_FLAG_WHOLE );
So, all that work in the first 2 patches for no real change at all? Why are these changes even needed?
And didn't you break this driver in patch 2/3? You can't fix it up later here, you need to also resolve that in the 2nd patch.
thanks,
greg k-h
Re: [PATCH 3/3] soc: qcom: mdt_loader: add offset to request_firmware_into_buf
Hi Greg,
Quoted 16 lines · Greg Kroah-Hartman
Quoted 15 lines · Scott Branden
Adjust
request_firmware_into_bufAPI to allow for portions of firmware file to be read into a buffer.mdt_loaderstill retricts request fo whole file read into buffer.Signed-off-by Scott Branden <[email protected]>--- drivers/soc/qcom/mdt_loader.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/soc/qcom/mdt_loader.c +0
-0@@ -172,8 +172,11 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,
Quoted 11 lines
drivers/soc/qcom/mdt_loader.c static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, · line 179
Quoted 9 lines
drivers/soc/qcom/mdt_loader.c +5
-2if (phdr->p_filesz) {sprintf (fw_name + fw_name_len -3 ,"b%02d" , i); - ret =request_firmware_into_buf (&seg_fw, fw_name, dev, - ptr, phdr->p_filesz); + ret =request_firmware_into_buf + (&seg_fw, fw_name, dev, + ptr, phdr->p_filesz, +0 , +KERNEL_PREAD_FLAG_WHOLE );So, all that work in the first 2 patches for no real change at all? Why are these changes even needed?
The first two patches allow partial read of files into memory.
Existing kernel drivers haven't need such functionality so, yes, there should be no real change
with first two patches other than adding such partial file read support.
We have a new driver in development which needs partial read of files supported in the kernel.
Quoted 3 lines
And didn't you break this driver in patch 2/3? You can't fix it up later here, you need to also resolve that in the 2nd patch.
I thought the driver changes needs to be in a different patch. If required I can squash this
driver change in with the request_firmware_into_buf change.
But the 2nd patch won't work without the 1st patch either.
So that would mean you now want all 3 patches for different subsystems squashed together?
Please let me know how you would like the patch series submitted.
Quoted 4 lines
thanks,
greg k-h
Regards,
Scott
Greg Kroah-Hartman
maintainerRe: [PATCH 3/3] soc: qcom: mdt_loader: add offset to request_firmware_into_buf
Quoted 32 lines · Scott Branden
Hi Greg,
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Scott Branden
Adjust
request_firmware_into_bufAPI to allow for portions of firmware file to be read into a buffer.mdt_loaderstill retricts request fo whole file read into buffer.Signed-off-by Scott Branden <[email protected]>--- drivers/soc/qcom/mdt_loader.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)Quoted 16 lines
Quoted 5 lines
drivers/soc/qcom/mdt_loader.c +0
-0drivers/soc/qcom/mdt_loader.c static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, · line 178
Quoted 9 lines
drivers/soc/qcom/mdt_loader.c +5
-2@@ -172,8 +172,11 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,if (phdr->p_filesz) {sprintf (fw_name + fw_name_len -3 ,"b%02d" , i); - ret =request_firmware_into_buf (&seg_fw, fw_name, dev, - ptr, phdr->p_filesz); + ret =request_firmware_into_buf + (&seg_fw, fw_name, dev, + ptr, phdr->p_filesz, +0 , +KERNEL_PREAD_FLAG_WHOLE );So, all that work in the first 2 patches for no real change at all? Why are these changes even needed?
The first two patches allow partial read of files into memory.
Quoted 7 lines
Existing kernel drivers haven't need such functionality so, yes, there should be no real change
with first two patches other than adding such partial file read support.
We have a new driver in development which needs partial read of files supported in the kernel.
As I said before, I can not take new apis without any in-kernel user. So let's wait for your new code that thinks it needs this, and then we will be glad to evaluate all of this at that point in time.
To do so otherwise is to have loads of unused "features" aquiring cruft in the kernel source, and you do not want that.
Quoted 5 lines
Quoted 2 lines
And didn't you break this driver in patch 2/3? You can't fix it up later here, you need to also resolve that in the 2nd patch.
I thought the driver changes needs to be in a different patch. If required I can squash this
You can NEVER break the build with any individual kernel patch, that should be well known by now as we have been doing this for over a decade.
thanks,
greg k-h
Re: [PATCH 3/3] soc: qcom: mdt_loader: add offset to request_firmware_into_buf
Quoted 36 lines · Greg Kroah-Hartman
Quoted 35 lines · Scott Branden
Hi Greg,
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Scott Branden
Adjust
request_firmware_into_bufAPI to allow for portions of firmware file to be read into a buffer.mdt_loaderstill retricts request fo whole file read into buffer.Signed-off-by Scott Branden <[email protected]>--- drivers/soc/qcom/mdt_loader.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)Quoted 16 lines
Quoted 5 lines
drivers/soc/qcom/mdt_loader.c +0
-0drivers/soc/qcom/mdt_loader.c static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, · line 178
Quoted 9 lines
drivers/soc/qcom/mdt_loader.c +5
-2@@ -172,8 +172,11 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,if (phdr->p_filesz) {sprintf (fw_name + fw_name_len -3 ,"b%02d" , i); - ret =request_firmware_into_buf (&seg_fw, fw_name, dev, - ptr, phdr->p_filesz); + ret =request_firmware_into_buf + (&seg_fw, fw_name, dev, + ptr, phdr->p_filesz, +0 , +KERNEL_PREAD_FLAG_WHOLE );So, all that work in the first 2 patches for no real change at all? Why are these changes even needed?
The first two patches allow partial read of files into memory.
Existing kernel drivers haven't need such functionality so, yes, there should be no real change
Quoted 9 lines
Quoted 4 lines
with first two patches other than adding such partial file read support.
We have a new driver in development which needs partial read of files supported in the kernel.
As I said before, I can not take new apis without any in-kernel user. So let's wait for your new code that thinks it needs this, and then we will be glad to evaluate all of this at that point in time.
The .mdt files are ELF files split to avoid having to allocate large (5-60MB) chunks of temporary firmware buffers while installing the segments.
But for multiple reasons it would be nice to be able to load the non-split ELF files and the proposed interface would allow this.
So I definitely like the gist of the series.
Quoted 3 lines
To do so otherwise is to have loads of unused "features" aquiring cruft in the kernel source, and you do not want that.
Agreed.
I'll take the opportunity and see if I can implement this (support for non-split Qualcomm firmware) based on the patches in this series.
Regards,
Bjorn
Re: [PATCH 3/3] soc: qcom: mdt_loader: add offset to request_firmware_into_buf
Hi Bjorn,
Quoted 54 lines · Bjorn Andersson
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · Scott Branden
Hi Greg,
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Scott Branden
Adjust
request_firmware_into_bufAPI to allow for portions of firmware file to be read into a buffer.mdt_loaderstill retricts request fo whole file read into buffer.Signed-off-by Scott Branden <[email protected]>--- drivers/soc/qcom/mdt_loader.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)Quoted 16 lines
Quoted 5 lines
drivers/soc/qcom/mdt_loader.c +0
-0drivers/soc/qcom/mdt_loader.c static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, · line 178
Quoted 9 lines
drivers/soc/qcom/mdt_loader.c +5
-2@@ -172,8 +172,11 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,if (phdr->p_filesz) {sprintf (fw_name + fw_name_len -3 ,"b%02d" , i); - ret =request_firmware_into_buf (&seg_fw, fw_name, dev, - ptr, phdr->p_filesz); + ret =request_firmware_into_buf + (&seg_fw, fw_name, dev, + ptr, phdr->p_filesz, +0 , +KERNEL_PREAD_FLAG_WHOLE );So, all that work in the first 2 patches for no real change at all? Why are these changes even needed?
The first two patches allow partial read of files into memory.
Existing kernel drivers haven't need such functionality so, yes, there should be no real change
Quoted 8 lines
Quoted 4 lines
with first two patches other than adding such partial file read support.
We have a new driver in development which needs partial read of files supported in the kernel.
As I said before, I can not take new apis without any in-kernel user. So let's wait for your new code that thinks it needs this, and then we will be glad to evaluate all of this at that point in time.
The .mdt files are ELF files split to avoid having to allocate large (5-60MB) chunks of temporary firmware buffers while installing the segments.
But for multiple reasons it would be nice to be able to load the non-split ELF files and the proposed interface would allow this.
So I definitely like the gist of the series.
Quoted 7 lines
Quoted 3 lines
To do so otherwise is to have loads of unused "features" aquiring cruft in the kernel source, and you do not want that.
Agreed.
I'll take the opportunity and see if I can implement this (support for non-split Qualcomm firmware) based on the patches in this series.
I'm back from my leave now.
Have you managed to utilize my partial firmware read in your driver yet?
Quoted 3 lines
Regards,
Bjorn
Re: [PATCH 3/3] soc: qcom: mdt_loader: add offset to request_firmware_into_buf
In reply to Greg Kroah-HartmanHi Greg,
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · Scott Branden
Hi Greg,
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Scott Branden
Adjust
request_firmware_into_bufAPI to allow for portions of firmware file to be read into a buffer.mdt_loaderstill retricts request fo whole file read into buffer.Signed-off-by Scott Branden <[email protected]>--- drivers/soc/qcom/mdt_loader.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)Quoted 16 lines
Quoted 5 lines
drivers/soc/qcom/mdt_loader.c +0
-0drivers/soc/qcom/mdt_loader.c static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, · line 178
Quoted 9 lines
drivers/soc/qcom/mdt_loader.c +5
-2@@ -172,8 +172,11 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,if (phdr->p_filesz) {sprintf (fw_name + fw_name_len -3 ,"b%02d" , i); - ret =request_firmware_into_buf (&seg_fw, fw_name, dev, - ptr, phdr->p_filesz); + ret =request_firmware_into_buf + (&seg_fw, fw_name, dev, + ptr, phdr->p_filesz, +0 , +KERNEL_PREAD_FLAG_WHOLE );So, all that work in the first 2 patches for no real change at all? Why are these changes even needed?
The first two patches allow partial read of files into memory.
Existing kernel drivers haven't need such functionality so, yes, there should be no real change
Quoted 7 lines
Quoted 4 lines
with first two patches other than adding such partial file read support.
We have a new driver in development which needs partial read of files supported in the kernel.
As I said before, I can not take new apis without any in-kernel user. So let's wait for your new code that thinks it needs this, and then we will be glad to evaluate all of this at that point in time.
I have submitted all the necessary patches you requested here.
These include first adding tests for existing API that never had a kernel selftest:
https://lkml.org/lkml/2019/8/22/1367
Followed by API enhancement, tests updated, and a new driver requiring enhanced API:
https://lkml.org/lkml/2019/8/22/1404
Quoted 7 lines
To do so otherwise is to have loads of unused "features" aquiring cruft in the kernel source, and you do not want that.
thanks,
greg k-h
Thanks,
Scott