rproc: Add elf64 support in elf loader
Subsystems (6)
PATCH v4 5/5 remoteproc: Adapt coredump to generate correct elf type
In reply to Clement LegerNow that remoteproc can load an elf64, coredump elf class should be the same as the loaded elf class. In order to do that, add a elf_class field to rproc with default values. If an elf is loaded successfully, these fields will be updated with the loaded elf class. Then, the coredump core code has been modified to use the generic elf macro in order to create an elf file with correct class.
--- drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++-------------- drivers/remoteproc/remoteproc_elf_loader.c | 3 ++ include/linux/remoteproc.h | 1 + 3 files changed, 39 insertions(+), 32 deletions(-)
drivers/remoteproc/remoteproc_core.c +35 -32
@@ -38,6 +38,7 @@#include <linux/platform_device.h> #include "remoteproc_internal.h" +#include "remoteproc_elf_helpers.h" #define HIGH_BITS_MASK 0xFFFFFFFF00000000ULL
@@ -1564,20 +1565,21 @@ EXPORT_SYMBOL(rproc_coredump_add_custom_segment);static void rproc_coredump (struct rproc *rproc) {struct rproc_dump_segment *segment; -struct elf32_phdr *phdr; -struct elf32_hdr *ehdr; +void *phdr; +void *ehdr;size_t data_size;size_t offset;void *data;void *ptr; +u8 class = rproc->elf_class;int phnum =0 ;if (list_empty (&rproc->dump_segments))return ; - data_size =sizeof (*ehdr); + data_size =elf_size_of_hdr (class);list_for_each_entry (segment, &rproc->dump_segments, node) { - data_size +=sizeof (*phdr) + segment->size; + data_size +=elf_size_of_phdr (class) + segment->size; phnum++; }
@@ -1588,33 +1590,33 @@ static void rproc_coredump(struct rproc *rproc) ehdr = data; -memset (ehdr,0 ,sizeof (*ehdr)); -memcpy (ehdr->e_ident,ELFMAG ,SELFMAG ); - ehdr->e_ident[EI_CLASS ] =ELFCLASS32 ; - ehdr->e_ident[EI_DATA ] =ELFDATA2LSB ; - ehdr->e_ident[EI_VERSION ] =EV_CURRENT ; - ehdr->e_ident[EI_OSABI ] =ELFOSABI_NONE ; - ehdr->e_type =ET_CORE ; - ehdr->e_machine =EM_NONE ; - ehdr->e_version =EV_CURRENT ; - ehdr->e_entry = rproc->bootaddr; - ehdr->e_phoff =sizeof (*ehdr); - ehdr->e_ehsize =sizeof (*ehdr); - ehdr->e_phentsize =sizeof (*phdr); - ehdr->e_phnum = phnum; - - phdr = data + ehdr->e_phoff; - offset = ehdr->e_phoff +sizeof (*phdr) * ehdr->e_phnum; +memset (ehdr,0 ,elf_size_of_hdr (class)); +/* e_ident field is common for both elf32 and elf64 */ +elf_hdr_init_ident (ehdr, class); + +elf_hdr_set_e_type (class, ehdr,ET_CORE ); +elf_hdr_set_e_machine (class, ehdr,EM_NONE ); +elf_hdr_set_e_version (class, ehdr,EV_CURRENT ); +elf_hdr_set_e_entry (class, ehdr, rproc->bootaddr); +elf_hdr_set_e_phoff (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_ehsize (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_phentsize (class, ehdr,elf_size_of_phdr (class)); +elf_hdr_set_e_phnum (class, ehdr, phnum); + + phdr = data +elf_hdr_get_e_phoff (class, ehdr); + offset =elf_hdr_get_e_phoff (class, ehdr); + offset +=elf_size_of_phdr (class) *elf_hdr_get_e_phnum (class, ehdr); +list_for_each_entry (segment, &rproc->dump_segments, node) { -memset (phdr,0 ,sizeof (*phdr)); - phdr->p_type =PT_LOAD ; - phdr->p_offset = offset; - phdr->p_vaddr = segment->da; - phdr->p_paddr = segment->da; - phdr->p_filesz = segment->size; - phdr->p_memsz = segment->size; - phdr->p_flags =PF_R |PF_W |PF_X ; - phdr->p_align =0 ; +memset (phdr,0 ,elf_size_of_phdr (class)); +elf_phdr_set_p_type (class, phdr,PT_LOAD ); +elf_phdr_set_p_offset (class, phdr, offset); +elf_phdr_set_p_vaddr (class, phdr, segment->da); +elf_phdr_set_p_paddr (class, phdr, segment->da); +elf_phdr_set_p_filesz (class, phdr, segment->size); +elf_phdr_set_p_memsz (class, phdr, segment->size); +elf_phdr_set_p_flags (class, phdr,PF_R |PF_W |PF_X ); +elf_phdr_set_p_align (class, phdr,0 );if (segment->dump) { segment->dump (rproc, segment, data + offset);
@@ -1630,8 +1632,8 @@ static void rproc_coredump(struct rproc *rproc) } } - offset += phdr->p_filesz; - phdr++; + offset +=elf_phdr_get_p_filesz (class, phdr); + phdr +=elf_size_of_phdr (class); }dev_coredumpv (&rproc->dev, data, data_size,GFP_KERNEL );
@@ -2029,6 +2031,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->name = name; rproc->priv = &rproc[1 ]; rproc->auto_boot = true; + rproc->elf_class =ELFCLASS32 ;device_initialize (&rproc->dev); rproc->dev.parent = dev;
drivers/remoteproc/remoteproc_elf_loader.c +3 -0
@@ -220,6 +220,9 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)memset (ptr + filesz,0 , memsz - filesz); } +if (ret ==0 ) + rproc->elf_class = class; +return ret; }EXPORT_SYMBOL (rproc_elf_load_segments);
include/linux/remoteproc.h +1 -0
@@ -514,6 +514,7 @@ struct rproc {bool auto_boot;struct list_head dump_segments;int nb_vdev; +int elf_class; };/**
Signature · 1 line
2.15.0.276.g89ea799
Mathieu Poirier
maintainerRe: [PATCH v4 5/5] remoteproc: Adapt coredump to generate correct elf type
Quoted 124 lines · Clement Leger
Now that remoteproc can load an elf64, coredump elf class should be the same as the loaded elf class. In order to do that, add a
elf_classfield to rproc with default values. If an elf is loaded successfully, these fields will be updated with the loaded elf class. Then, the coredump core code has been modified to use the generic elf macro in order to create an elf file with correct class.Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++-------------- drivers/remoteproc/remoteproc_elf_loader.c | 3 ++ include/linux/remoteproc.h | 1 + 3 files changed, 39 insertions(+), 32 deletions(-)drivers/remoteproc/remoteproc_core.c +34
-32@@ -38,6 +38,7 @@#include <linux/platform_device.h> #include "remoteproc_internal.h" +#include "remoteproc_elf_helpers.h" #define HIGH_BITS_MASK 0xFFFFFFFF00000000ULL@@ -1564,20 +1565,21 @@ EXPORT_SYMBOL(rproc_coredump_add_custom_segment);static void rproc_coredump (struct rproc *rproc) {struct rproc_dump_segment *segment; -struct elf32_phdr *phdr; -struct elf32_hdr *ehdr; +void *phdr; +void *ehdr;size_t data_size;size_t offset;void *data;void *ptr; +u8 class = rproc->elf_class;int phnum =0 ;if (list_empty (&rproc->dump_segments))return ; - data_size =sizeof (*ehdr); + data_size =elf_size_of_hdr (class);list_for_each_entry (segment, &rproc->dump_segments, node) { - data_size +=sizeof (*phdr) + segment->size; + data_size +=elf_size_of_phdr (class) + segment->size; phnum++; }@@ -1588,33 +1590,33 @@ static void rproc_coredump(struct rproc *rproc) ehdr = data; -memset (ehdr,0 ,sizeof (*ehdr)); -memcpy (ehdr->e_ident,ELFMAG ,SELFMAG ); - ehdr->e_ident[EI_CLASS ] =ELFCLASS32 ; - ehdr->e_ident[EI_DATA ] =ELFDATA2LSB ; - ehdr->e_ident[EI_VERSION ] =EV_CURRENT ; - ehdr->e_ident[EI_OSABI ] =ELFOSABI_NONE ; - ehdr->e_type =ET_CORE ; - ehdr->e_machine =EM_NONE ; - ehdr->e_version =EV_CURRENT ; - ehdr->e_entry = rproc->bootaddr; - ehdr->e_phoff =sizeof (*ehdr); - ehdr->e_ehsize =sizeof (*ehdr); - ehdr->e_phentsize =sizeof (*phdr); - ehdr->e_phnum = phnum; - - phdr = data + ehdr->e_phoff; - offset = ehdr->e_phoff +sizeof (*phdr) * ehdr->e_phnum; +memset (ehdr,0 ,elf_size_of_hdr (class)); +/* e_ident field is common for both elf32 and elf64 */ +elf_hdr_init_ident (ehdr, class); + +elf_hdr_set_e_type (class, ehdr,ET_CORE ); +elf_hdr_set_e_machine (class, ehdr,EM_NONE ); +elf_hdr_set_e_version (class, ehdr,EV_CURRENT ); +elf_hdr_set_e_entry (class, ehdr, rproc->bootaddr); +elf_hdr_set_e_phoff (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_ehsize (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_phentsize (class, ehdr,elf_size_of_phdr (class)); +elf_hdr_set_e_phnum (class, ehdr, phnum); + + phdr = data +elf_hdr_get_e_phoff (class, ehdr); + offset =elf_hdr_get_e_phoff (class, ehdr); + offset +=elf_size_of_phdr (class) *elf_hdr_get_e_phnum (class, ehdr); +list_for_each_entry (segment, &rproc->dump_segments, node) { -memset (phdr,0 ,sizeof (*phdr)); - phdr->p_type =PT_LOAD ; - phdr->p_offset = offset; - phdr->p_vaddr = segment->da; - phdr->p_paddr = segment->da; - phdr->p_filesz = segment->size; - phdr->p_memsz = segment->size; - phdr->p_flags =PF_R |PF_W |PF_X ; - phdr->p_align =0 ; +memset (phdr,0 ,elf_size_of_phdr (class)); +elf_phdr_set_p_type (class, phdr,PT_LOAD ); +elf_phdr_set_p_offset (class, phdr, offset); +elf_phdr_set_p_vaddr (class, phdr, segment->da); +elf_phdr_set_p_paddr (class, phdr, segment->da); +elf_phdr_set_p_filesz (class, phdr, segment->size); +elf_phdr_set_p_memsz (class, phdr, segment->size); +elf_phdr_set_p_flags (class, phdr,PF_R |PF_W |PF_X ); +elf_phdr_set_p_align (class, phdr,0 );if (segment->dump) { segment->dump (rproc, segment, data + offset);@@ -1630,8 +1632,8 @@ static void rproc_coredump(struct rproc *rproc) } } - offset += phdr->p_filesz; - phdr++; + offset +=elf_phdr_get_p_filesz (class, phdr); + phdr +=elf_size_of_phdr (class); }dev_coredumpv (&rproc->dev, data, data_size,GFP_KERNEL );
drivers/remoteproc/remoteproc_core.c struct rproc *rproc_alloc(struct device *dev, const char *name, · line 2034
Quoted 4 lines
drivers/remoteproc/remoteproc_core.c +1
-0@@ -2029,6 +2031,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->name = name; rproc->priv = &rproc[1 ]; rproc->auto_boot = true; + rproc->elf_class =ELFCLASS32 ;
I suppose this is as good a place as any.
Quoted 22 lines
drivers/remoteproc/remoteproc_core.c +0
-0device_initialize (&rproc->dev); rproc->dev.parent = dev;drivers/remoteproc/remoteproc_elf_loader.c +3
-0@@ -220,6 +220,9 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)memset (ptr + filesz,0 , memsz - filesz); } +if (ret ==0 ) + rproc->elf_class = class; +return ret; }EXPORT_SYMBOL (rproc_elf_load_segments);include/linux/remoteproc.h +0
-0
include/linux/remoteproc.h struct rproc { · line 517
Quoted 4 lines
include/linux/remoteproc.h +1
-0@@ -514,6 +514,7 @@ struct rproc {bool auto_boot;struct list_head dump_segments;int nb_vdev; +int elf_class;
Type 'int'? I expected 'u8' as it is in the specification and in rproc_elf_load_segments().
Thanks,
Mathieu
Quoted 6 lines
include/linux/remoteproc.h +0
-0};/** Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v4 0/5] remoteproc: Add elf64 support
In reply to Clement LegerHi Clement,
I tested the series on the stm32 platform for remote proc firmwre load: no regression found. I do not test the da_to_va feature as not implemented on stm32 platform.
Regards,
Arnaud
Quoted 45 lines · Clement Leger
This serie add support for elf64 in remoteproc (elf loader, coredump). First two patches modifies the type of len argument (in
da_to_va) andboot_addrin order to allow loading elf64 segment with a u64 size and a u64 entry point.
Next patch introduce a set of macros to access elf64 and elf32 transparently.
Last two patches are the actual modification in the elf loader and remoteproc coredump support to add elf64 support.Changes from V3:
- Adapt coredump to elf64 file format
- Renameremoteproc_elf_loader.htoremoteproc_elf_helpers.h
- Update copyright year inremoteproc_elf_helpers.h
- Rename macros elf_hdr_* to elf_get_hdr_* for coherency with elf_hdr_set_*
- Split elf64 loader patch in 3:
-boot_addru64 change
-remoteproc_elf_helpers.hcreation
- elf64 loadingClement Leger (5):
remoteproc: Use u64 len forda_to_va
remoteproc: Use u64 type forboot_addr
remoteproc: Add elf helpers to access elf64 and elf32 fields
remoteproc: Add elf64 support in elf loader
remoteproc: Adapt coredump to generate correct elf typeDocumentation/remoteproc.txt | 2 +- drivers/remoteproc/imx_rproc.c | 11 +- drivers/remoteproc/keystone_remoteproc.c | 4 +- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/qcom_q6v5_pas.c | 2 +- drivers/remoteproc/qcom_q6v5_wcss.c | 2 +- drivers/remoteproc/qcom_wcnss.c | 2 +- drivers/remoteproc/remoteproc_core.c | 69 +++++++------ drivers/remoteproc/remoteproc_elf_helpers.h | 95 ++++++++++++++++++ drivers/remoteproc/remoteproc_elf_loader.c | 150 ++++++++++++++++++---------- drivers/remoteproc/remoteproc_internal.h | 4 +- drivers/remoteproc/st_remoteproc.c | 2 +- drivers/remoteproc/st_slim_rproc.c | 4 +- drivers/remoteproc/wkup_m3_rproc.c | 4 +- include/linux/remoteproc.h | 7 +- 16 files changed, 252 insertions(+), 110 deletions(-) create mode 100644 drivers/remoteproc/remoteproc_elf_helpers.h
Mathieu Poirier
maintainerRe: [PATCH v4 0/5] remoteproc: Add elf64 support
Quoted 4 lines · Arnaud POULIQUEN
Hi Clement,
I tested the series on the stm32 platform for remote proc firmwre load: no regression found. I do not test the
da_to_vafeature as not implemented on stm32 platform.
It would be very interesting if you could test the coredump, that would give us a lot more confidence in the implementation.
Thanks,
Mathieu
Quoted 52 lines
Regards,
ArnaudQuoted 45 lines · Clement Leger
This serie add support for elf64 in remoteproc (elf loader, coredump). First two patches modifies the type of len argument (in
da_to_va) andboot_addrin order to allow loading elf64 segment with a u64 size and a u64 entry point.
Next patch introduce a set of macros to access elf64 and elf32 transparently.
Last two patches are the actual modification in the elf loader and remoteproc coredump support to add elf64 support.Changes from V3:
- Adapt coredump to elf64 file format
- Renameremoteproc_elf_loader.htoremoteproc_elf_helpers.h
- Update copyright year inremoteproc_elf_helpers.h
- Rename macros elf_hdr_* to elf_get_hdr_* for coherency with elf_hdr_set_*
- Split elf64 loader patch in 3:
-boot_addru64 change
-remoteproc_elf_helpers.hcreation
- elf64 loadingClement Leger (5):
remoteproc: Use u64 len forda_to_va
remoteproc: Use u64 type forboot_addr
remoteproc: Add elf helpers to access elf64 and elf32 fields
remoteproc: Add elf64 support in elf loader
remoteproc: Adapt coredump to generate correct elf typeDocumentation/remoteproc.txt | 2 +- drivers/remoteproc/imx_rproc.c | 11 +- drivers/remoteproc/keystone_remoteproc.c | 4 +- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/qcom_q6v5_pas.c | 2 +- drivers/remoteproc/qcom_q6v5_wcss.c | 2 +- drivers/remoteproc/qcom_wcnss.c | 2 +- drivers/remoteproc/remoteproc_core.c | 69 +++++++------ drivers/remoteproc/remoteproc_elf_helpers.h | 95 ++++++++++++++++++ drivers/remoteproc/remoteproc_elf_loader.c | 150 ++++++++++++++++++---------- drivers/remoteproc/remoteproc_internal.h | 4 +- drivers/remoteproc/st_remoteproc.c | 2 +- drivers/remoteproc/st_slim_rproc.c | 4 +- drivers/remoteproc/wkup_m3_rproc.c | 4 +- include/linux/remoteproc.h | 7 +- 16 files changed, 252 insertions(+), 110 deletions(-) create mode 100644 drivers/remoteproc/remoteproc_elf_helpers.h
Re: [PATCH v4 0/5] remoteproc: Add elf64 support
Quoted 8 lines · Mathieu Poirier
Quoted 4 lines · Arnaud POULIQUEN
Hi Clement,
I tested the series on the stm32 platform for remote proc firmwre load: no regression found. I do not test the
da_to_vafeature as not implemented on stm32 platform.It would be very interesting if you could test the coredump, that would give us a lot more confidence in the implementation.
I also tested the coredump generation. LGTM
Quoted 56 lines
Thanks,
MathieuQuoted 52 lines
Regards,
ArnaudQuoted 45 lines · Clement Leger
This serie add support for elf64 in remoteproc (elf loader, coredump). First two patches modifies the type of len argument (in
da_to_va) andboot_addrin order to allow loading elf64 segment with a u64 size and a u64 entry point.
Next patch introduce a set of macros to access elf64 and elf32 transparently.
Last two patches are the actual modification in the elf loader and remoteproc coredump support to add elf64 support.Changes from V3:
- Adapt coredump to elf64 file format
- Renameremoteproc_elf_loader.htoremoteproc_elf_helpers.h
- Update copyright year inremoteproc_elf_helpers.h
- Rename macros elf_hdr_* to elf_get_hdr_* for coherency with elf_hdr_set_*
- Split elf64 loader patch in 3:
-boot_addru64 change
-remoteproc_elf_helpers.hcreation
- elf64 loadingClement Leger (5):
remoteproc: Use u64 len forda_to_va
remoteproc: Use u64 type forboot_addr
remoteproc: Add elf helpers to access elf64 and elf32 fields
remoteproc: Add elf64 support in elf loader
remoteproc: Adapt coredump to generate correct elf typeDocumentation/remoteproc.txt | 2 +- drivers/remoteproc/imx_rproc.c | 11 +- drivers/remoteproc/keystone_remoteproc.c | 4 +- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/qcom_q6v5_pas.c | 2 +- drivers/remoteproc/qcom_q6v5_wcss.c | 2 +- drivers/remoteproc/qcom_wcnss.c | 2 +- drivers/remoteproc/remoteproc_core.c | 69 +++++++------ drivers/remoteproc/remoteproc_elf_helpers.h | 95 ++++++++++++++++++ drivers/remoteproc/remoteproc_elf_loader.c | 150 ++++++++++++++++++---------- drivers/remoteproc/remoteproc_internal.h | 4 +- drivers/remoteproc/st_remoteproc.c | 2 +- drivers/remoteproc/st_slim_rproc.c | 4 +- drivers/remoteproc/wkup_m3_rproc.c | 4 +- include/linux/remoteproc.h | 7 +- 16 files changed, 252 insertions(+), 110 deletions(-) create mode 100644 drivers/remoteproc/remoteproc_elf_helpers.h
v5 cover remoteproc: Add elf64 support
In reply to Clement LegerThis serie add support for elf64 in remoteproc (elf loader, coredump). First three patches modifies the type of len argument (in da_to_va), boot_addr and rproc_mem_entry len field in order to allow loading elf64 segment with a u64 size and a u64 entry point.
Next patches introduce a set of macros to access elf64 and elf32 transparently.
Last patches are the actual modifications in the elf loader and remoteproc coredump support to add elf64 support.
Changes v4 -> v5:
- Add rproc_elf_sanity_check renaming to rproc_elf32_sanity_check
- Fix checkpatch warning on > 80 column line
- Change u64 len type for size_t in da_to_va and add checks in loader
- Modify rproc_mem_entry size field type from int to size_t
- Add a patch to override sanity_check function
Changes v3 -> v4:
- Adapt coredump to elf64 file format
- Rename remoteproc_elf_loader.h to remoteproc_elf_helpers.h
- Update copyright year in remoteproc_elf_helpers.h
- Rename macros elf_hdr_* to elf_get_hdr_* for coherency with elf_hdr_set_*
- Split elf64 loader patch in 3:
- boot_addr u64 change
- remoteproc_elf_helpers.h creation
- elf64 loading
Changes v2 -> v3:
- da_to_va len type changed from int to u64
- Add check for elf64 header size
- Add comments for name table parsing
- Fix typo in "accommodate
- Add ELF64 support in documentation
Clement Leger (8):
remoteproc: Use size_t type for len in da_to_va
remoteproc: Use size_t instead of int for rproc_mem_entry len
remoteproc: Use u64 type for boot_addr
remoteproc: Add elf helpers to access elf64 and elf32 fields
remoteproc: Rename rproc_elf_sanity_check for elf32
remoteproc: Add elf64 support in elf loader
remoteproc: Allow overriding only sanity_check
remoteproc: Adapt coredump to generate correct elf type
Documentation/remoteproc.txt | 2 +- drivers/remoteproc/imx_rproc.c | 11 +- drivers/remoteproc/keystone_remoteproc.c | 4 +- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/qcom_q6v5_pas.c | 2 +- drivers/remoteproc/qcom_q6v5_wcss.c | 2 +- drivers/remoteproc/qcom_wcnss.c | 2 +- drivers/remoteproc/remoteproc_core.c | 86 +++++++------ drivers/remoteproc/remoteproc_debugfs.c | 2 +- drivers/remoteproc/remoteproc_elf_helpers.h | 96 ++++++++++++++ drivers/remoteproc/remoteproc_elf_loader.c | 189 +++++++++++++++++++--------- drivers/remoteproc/remoteproc_internal.h | 14 ++- drivers/remoteproc/st_remoteproc.c | 4 +- drivers/remoteproc/st_slim_rproc.c | 6 +- drivers/remoteproc/stm32_rproc.c | 2 +- drivers/remoteproc/wkup_m3_rproc.c | 4 +- include/linux/remoteproc.h | 13 +- 18 files changed, 317 insertions(+), 126 deletions(-) create mode 100644 drivers/remoteproc/remoteproc_elf_helpers.h
Signature · 1 line
2.15.0.276.g89ea799
PATCH v5 1/8 remoteproc: Use size_t type for len in da_to_va
With upcoming changes in elf loader for elf64 support, section size will be a u64. When used with da_to_va, this will potentially lead to overflow if using the current "int" type for len argument. Change da_to_va prototype to use a size_t for len and fix all users of this function.
--- drivers/remoteproc/imx_rproc.c | 11 ++++++----- drivers/remoteproc/keystone_remoteproc.c | 4 ++-- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/qcom_q6v5_pas.c | 2 +- drivers/remoteproc/qcom_q6v5_wcss.c | 2 +- drivers/remoteproc/qcom_wcnss.c | 2 +- drivers/remoteproc/remoteproc_core.c | 2 +- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_slim_rproc.c | 4 ++-- drivers/remoteproc/wkup_m3_rproc.c | 4 ++-- include/linux/remoteproc.h | 2 +- 12 files changed, 20 insertions(+), 19 deletions(-)
drivers/remoteproc/imx_rproc.c +6 -5
@@ -186,7 +186,7 @@ static int imx_rproc_stop(struct rproc *rproc) }static int imx_rproc_da_to_sys (struct imx_rproc *priv,u64 da, -int len,u64 *sys) +size_t len,u64 *sys) {const struct imx_rproc_dcfg *dcfg = priv->dcfg;int i;
@@ -203,19 +203,19 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 da, } } -dev_warn (priv->dev,"Translation failed: da = 0x%llx len = 0x%x\n" , +dev_warn (priv->dev,"Translation failed: da = 0x%llx len = 0x%zx\n" , da, len);return -ENOENT ; } -static void *imx_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *imx_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct imx_rproc *priv = rproc->priv;void *va =NULL ;u64 sys;int i; -if (len <=0 ) +if (len ==0 )return NULL ;/*
@@ -235,7 +235,8 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, int len) } } -dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%x va = 0x%p\n" , da, len, va); +dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%zx va = 0x%p\n" , + da, len, va);return va; }
drivers/remoteproc/keystone_remoteproc.c +2 -2
@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int vqid)* can be used either by the remoteproc core for loading (when using kernel * remoteproc loader), or by any rpmsg bus drivers. */ -static void *keystone_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *keystone_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct keystone_rproc *ksproc = rproc->priv;void __iomem *va =NULL ;
@@ -255,7 +255,7 @@ static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, int len)size_t size;int i; -if (len <=0 ) +if (len ==0 )return NULL ;for (i =0 ; i < ksproc->num_mems; i++) {
drivers/remoteproc/qcom_q6v5_adsp.c +1 -1
@@ -270,7 +270,7 @@ static int adsp_stop(struct rproc *rproc)return ret; } -static void *adsp_da_to_va (struct rproc *rproc,u64 da,int len) +static void *adsp_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;int offset;
drivers/remoteproc/qcom_q6v5_mss.c +1 -1
@@ -1148,7 +1148,7 @@ static int q6v5_stop(struct rproc *rproc)return 0 ; } -static void *q6v5_da_to_va (struct rproc *rproc,u64 da,int len) +static void *q6v5_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct q6v5 *qproc = rproc->priv;int offset;
drivers/remoteproc/qcom_q6v5_pas.c +1 -1
@@ -159,7 +159,7 @@ static int adsp_stop(struct rproc *rproc)return ret; } -static void *adsp_da_to_va (struct rproc *rproc,u64 da,int len) +static void *adsp_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;int offset;
drivers/remoteproc/qcom_q6v5_wcss.c +1 -1
@@ -406,7 +406,7 @@ static int q6v5_wcss_stop(struct rproc *rproc)return 0 ; } -static void *q6v5_wcss_da_to_va (struct rproc *rproc,u64 da,int len) +static void *q6v5_wcss_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct q6v5_wcss *wcss = rproc->priv;int offset;
drivers/remoteproc/qcom_wcnss.c +1 -1
@@ -287,7 +287,7 @@ static int wcnss_stop(struct rproc *rproc)return ret; } -static void *wcnss_da_to_va (struct rproc *rproc,u64 da,int len) +static void *wcnss_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_wcnss *wcnss = (struct qcom_wcnss *)rproc->priv;int offset;
drivers/remoteproc/remoteproc_core.c +1 -1
@@ -185,7 +185,7 @@ EXPORT_SYMBOL(rproc_va_to_pa);* here the output of the DMA API for the carveouts, which should be more * correct. */ -void *rproc_da_to_va (struct rproc *rproc,u64 da,int len) +void *rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct rproc_mem_entry *carveout;void *ptr =NULL ;
drivers/remoteproc/remoteproc_internal.h +1 -1
@@ -50,7 +50,7 @@ void rproc_exit_sysfs(void);void rproc_free_vring (struct rproc_vring *rvring);int rproc_alloc_vring (struct rproc_vdev *rvdev,int i); -void *rproc_da_to_va (struct rproc *rproc,u64 da,int len); +void *rproc_da_to_va (struct rproc *rproc,u64 da,size_t len);phys_addr_t rproc_va_to_pa (void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc);
drivers/remoteproc/st_slim_rproc.c +2 -2
@@ -174,7 +174,7 @@ static int slim_rproc_stop(struct rproc *rproc)return 0 ; } -static void *slim_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *slim_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct st_slim_rproc *slim_rproc = rproc->priv;void *va =NULL ;
@@ -191,7 +191,7 @@ static void *slim_rproc_da_to_va(struct rproc *rproc, u64 da, int len) } } -dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%x va = 0x%pK\n" , +dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%zx va = 0x%pK\n" , da, len, va);return va;
drivers/remoteproc/wkup_m3_rproc.c +2 -2
@@ -80,14 +80,14 @@ static int wkup_m3_rproc_stop(struct rproc *rproc)return 0 ; } -static void *wkup_m3_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *wkup_m3_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct wkup_m3_rproc *wkupm3 = rproc->priv;void *va =NULL ;int i;u32 offset; -if (len <=0 ) +if (len ==0 )return NULL ;for (i =0 ; i <WKUPM3_MEM_MAX ; i++) {
include/linux/remoteproc.h +1 -1
@@ -374,7 +374,7 @@ struct rproc_ops {int (*start)(struct rproc *rproc);int (*stop)(struct rproc *rproc);void (*kick)(struct rproc *rproc,int vqid); -void * (*da_to_va)(struct rproc *rproc,u64 da,int len); +void * (*da_to_va)(struct rproc *rproc,u64 da,size_t len);int (*parse_fw)(struct rproc *rproc,const struct firmware *fw);int (*handle_rsc)(struct rproc *rproc,u32 rsc_type,void *rsc,int offset,int avail);
Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 1/8] remoteproc: Use size_t type for len in da_to_va
Quoted 7 lines · Clement Leger
With upcoming changes in elf loader for elf64 support, section size will be a u64. When used with
da_to_va, this will potentially lead to overflow if using the current "int" type for len argument. Changeda_to_vaprototype to use asize_tfor len and fix all users of this function.Signed-off-by Clement Leger <[email protected]>
Quoted 233 lines
--- drivers/remoteproc/imx_rproc.c | 11 ++++++----- drivers/remoteproc/keystone_remoteproc.c | 4 ++-- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/qcom_q6v5_pas.c | 2 +- drivers/remoteproc/qcom_q6v5_wcss.c | 2 +- drivers/remoteproc/qcom_wcnss.c | 2 +- drivers/remoteproc/remoteproc_core.c | 2 +- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_slim_rproc.c | 4 ++-- drivers/remoteproc/wkup_m3_rproc.c | 4 ++-- include/linux/remoteproc.h | 2 +- 12 files changed, 20 insertions(+), 19 deletions(-)drivers/remoteproc/imx_rproc.c +6
-5@@ -186,7 +186,7 @@ static int imx_rproc_stop(struct rproc *rproc) }static int imx_rproc_da_to_sys (struct imx_rproc *priv,u64 da, -int len,u64 *sys) +size_t len,u64 *sys) {const struct imx_rproc_dcfg *dcfg = priv->dcfg;int i;@@ -203,19 +203,19 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 da, } } -dev_warn (priv->dev,"Translation failed: da = 0x%llx len = 0x%x\n" , +dev_warn (priv->dev,"Translation failed: da = 0x%llx len = 0x%zx\n" , da, len);return -ENOENT ; } -static void *imx_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *imx_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct imx_rproc *priv = rproc->priv;void *va =NULL ;u64 sys;int i; -if (len <=0 ) +if (len ==0 )return NULL ;/* @@ -235,7 +235,8 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, int len) } } -dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%x va = 0x%p\n" , da, len, va); +dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%zx va = 0x%p\n" , + da, len, va);return va; }drivers/remoteproc/keystone_remoteproc.c +2
-2@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int vqid)* can be used either by the remoteproc core for loading (when using kernel * remoteproc loader), or by any rpmsg bus drivers. */ -static void *keystone_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *keystone_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct keystone_rproc *ksproc = rproc->priv;void __iomem *va =NULL ;@@ -255,7 +255,7 @@ static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, int len)size_t size;int i; -if (len <=0 ) +if (len ==0 )return NULL ;for (i =0 ; i < ksproc->num_mems; i++) {drivers/remoteproc/qcom_q6v5_adsp.c +1
-1@@ -270,7 +270,7 @@ static int adsp_stop(struct rproc *rproc)return ret; } -static void *adsp_da_to_va (struct rproc *rproc,u64 da,int len) +static void *adsp_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;int offset;drivers/remoteproc/qcom_q6v5_mss.c +1
-1@@ -1148,7 +1148,7 @@ static int q6v5_stop(struct rproc *rproc)return 0 ; } -static void *q6v5_da_to_va (struct rproc *rproc,u64 da,int len) +static void *q6v5_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct q6v5 *qproc = rproc->priv;int offset;drivers/remoteproc/qcom_q6v5_pas.c +1
-1@@ -159,7 +159,7 @@ static int adsp_stop(struct rproc *rproc)return ret; } -static void *adsp_da_to_va (struct rproc *rproc,u64 da,int len) +static void *adsp_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;int offset;drivers/remoteproc/qcom_q6v5_wcss.c +1
-1@@ -406,7 +406,7 @@ static int q6v5_wcss_stop(struct rproc *rproc)return 0 ; } -static void *q6v5_wcss_da_to_va (struct rproc *rproc,u64 da,int len) +static void *q6v5_wcss_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct q6v5_wcss *wcss = rproc->priv;int offset;drivers/remoteproc/qcom_wcnss.c +1
-1@@ -287,7 +287,7 @@ static int wcnss_stop(struct rproc *rproc)return ret; } -static void *wcnss_da_to_va (struct rproc *rproc,u64 da,int len) +static void *wcnss_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_wcnss *wcnss = (struct qcom_wcnss *)rproc->priv;int offset;drivers/remoteproc/remoteproc_core.c +1
-1@@ -185,7 +185,7 @@ EXPORT_SYMBOL(rproc_va_to_pa);* here the output of the DMA API for the carveouts, which should be more * correct. */ -void *rproc_da_to_va (struct rproc *rproc,u64 da,int len) +void *rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct rproc_mem_entry *carveout;void *ptr =NULL ;drivers/remoteproc/remoteproc_internal.h +1
-1@@ -50,7 +50,7 @@ void rproc_exit_sysfs(void);void rproc_free_vring (struct rproc_vring *rvring);int rproc_alloc_vring (struct rproc_vdev *rvdev,int i); -void *rproc_da_to_va (struct rproc *rproc,u64 da,int len); +void *rproc_da_to_va (struct rproc *rproc,u64 da,size_t len);phys_addr_t rproc_va_to_pa (void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc);drivers/remoteproc/st_slim_rproc.c +2
-2@@ -174,7 +174,7 @@ static int slim_rproc_stop(struct rproc *rproc)return 0 ; } -static void *slim_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *slim_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct st_slim_rproc *slim_rproc = rproc->priv;void *va =NULL ;@@ -191,7 +191,7 @@ static void *slim_rproc_da_to_va(struct rproc *rproc, u64 da, int len) } } -dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%x va = 0x%pK\n" , +dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%zx va = 0x%pK\n" , da, len, va);return va;drivers/remoteproc/wkup_m3_rproc.c +2
-2@@ -80,14 +80,14 @@ static int wkup_m3_rproc_stop(struct rproc *rproc)return 0 ; } -static void *wkup_m3_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *wkup_m3_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct wkup_m3_rproc *wkupm3 = rproc->priv;void *va =NULL ;int i;u32 offset; -if (len <=0 ) +if (len ==0 )return NULL ;for (i =0 ; i <WKUPM3_MEM_MAX ; i++) {include/linux/remoteproc.h +1
-1@@ -374,7 +374,7 @@ struct rproc_ops {int (*start)(struct rproc *rproc);int (*stop)(struct rproc *rproc);void (*kick)(struct rproc *rproc,int vqid); -void * (*da_to_va)(struct rproc *rproc,u64 da,int len); +void * (*da_to_va)(struct rproc *rproc,u64 da,size_t len);int (*parse_fw)(struct rproc *rproc,const struct firmware *fw);int (*handle_rsc)(struct rproc *rproc,u32 rsc_type,void *rsc,int offset,int avail);Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 1/8] remoteproc: Use size_t type for len in da_to_va
In reply to Clement LegerQuoted 7 lines · Clement Leger
With upcoming changes in elf loader for elf64 support, section size will be a u64. When used with
da_to_va, this will potentially lead to overflow if using the current "int" type for len argument. Changeda_to_vaprototype to use asize_tfor len and fix all users of this function.Signed-off-by Clement Leger <[email protected]>
Quoted 233 lines
--- drivers/remoteproc/imx_rproc.c | 11 ++++++----- drivers/remoteproc/keystone_remoteproc.c | 4 ++-- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/qcom_q6v5_pas.c | 2 +- drivers/remoteproc/qcom_q6v5_wcss.c | 2 +- drivers/remoteproc/qcom_wcnss.c | 2 +- drivers/remoteproc/remoteproc_core.c | 2 +- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_slim_rproc.c | 4 ++-- drivers/remoteproc/wkup_m3_rproc.c | 4 ++-- include/linux/remoteproc.h | 2 +- 12 files changed, 20 insertions(+), 19 deletions(-)drivers/remoteproc/imx_rproc.c +6
-5@@ -186,7 +186,7 @@ static int imx_rproc_stop(struct rproc *rproc) }static int imx_rproc_da_to_sys (struct imx_rproc *priv,u64 da, -int len,u64 *sys) +size_t len,u64 *sys) {const struct imx_rproc_dcfg *dcfg = priv->dcfg;int i;@@ -203,19 +203,19 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 da, } } -dev_warn (priv->dev,"Translation failed: da = 0x%llx len = 0x%x\n" , +dev_warn (priv->dev,"Translation failed: da = 0x%llx len = 0x%zx\n" , da, len);return -ENOENT ; } -static void *imx_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *imx_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct imx_rproc *priv = rproc->priv;void *va =NULL ;u64 sys;int i; -if (len <=0 ) +if (len ==0 )return NULL ;/* @@ -235,7 +235,8 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, int len) } } -dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%x va = 0x%p\n" , da, len, va); +dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%zx va = 0x%p\n" , + da, len, va);return va; }drivers/remoteproc/keystone_remoteproc.c +2
-2@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int vqid)* can be used either by the remoteproc core for loading (when using kernel * remoteproc loader), or by any rpmsg bus drivers. */ -static void *keystone_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *keystone_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct keystone_rproc *ksproc = rproc->priv;void __iomem *va =NULL ;@@ -255,7 +255,7 @@ static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, int len)size_t size;int i; -if (len <=0 ) +if (len ==0 )return NULL ;for (i =0 ; i < ksproc->num_mems; i++) {drivers/remoteproc/qcom_q6v5_adsp.c +1
-1@@ -270,7 +270,7 @@ static int adsp_stop(struct rproc *rproc)return ret; } -static void *adsp_da_to_va (struct rproc *rproc,u64 da,int len) +static void *adsp_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;int offset;drivers/remoteproc/qcom_q6v5_mss.c +1
-1@@ -1148,7 +1148,7 @@ static int q6v5_stop(struct rproc *rproc)return 0 ; } -static void *q6v5_da_to_va (struct rproc *rproc,u64 da,int len) +static void *q6v5_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct q6v5 *qproc = rproc->priv;int offset;drivers/remoteproc/qcom_q6v5_pas.c +1
-1@@ -159,7 +159,7 @@ static int adsp_stop(struct rproc *rproc)return ret; } -static void *adsp_da_to_va (struct rproc *rproc,u64 da,int len) +static void *adsp_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;int offset;drivers/remoteproc/qcom_q6v5_wcss.c +1
-1@@ -406,7 +406,7 @@ static int q6v5_wcss_stop(struct rproc *rproc)return 0 ; } -static void *q6v5_wcss_da_to_va (struct rproc *rproc,u64 da,int len) +static void *q6v5_wcss_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct q6v5_wcss *wcss = rproc->priv;int offset;drivers/remoteproc/qcom_wcnss.c +1
-1@@ -287,7 +287,7 @@ static int wcnss_stop(struct rproc *rproc)return ret; } -static void *wcnss_da_to_va (struct rproc *rproc,u64 da,int len) +static void *wcnss_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_wcnss *wcnss = (struct qcom_wcnss *)rproc->priv;int offset;drivers/remoteproc/remoteproc_core.c +1
-1@@ -185,7 +185,7 @@ EXPORT_SYMBOL(rproc_va_to_pa);* here the output of the DMA API for the carveouts, which should be more * correct. */ -void *rproc_da_to_va (struct rproc *rproc,u64 da,int len) +void *rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct rproc_mem_entry *carveout;void *ptr =NULL ;drivers/remoteproc/remoteproc_internal.h +1
-1@@ -50,7 +50,7 @@ void rproc_exit_sysfs(void);void rproc_free_vring (struct rproc_vring *rvring);int rproc_alloc_vring (struct rproc_vdev *rvdev,int i); -void *rproc_da_to_va (struct rproc *rproc,u64 da,int len); +void *rproc_da_to_va (struct rproc *rproc,u64 da,size_t len);phys_addr_t rproc_va_to_pa (void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc);drivers/remoteproc/st_slim_rproc.c +2
-2@@ -174,7 +174,7 @@ static int slim_rproc_stop(struct rproc *rproc)return 0 ; } -static void *slim_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *slim_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct st_slim_rproc *slim_rproc = rproc->priv;void *va =NULL ;@@ -191,7 +191,7 @@ static void *slim_rproc_da_to_va(struct rproc *rproc, u64 da, int len) } } -dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%x va = 0x%pK\n" , +dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%zx va = 0x%pK\n" , da, len, va);return va;drivers/remoteproc/wkup_m3_rproc.c +2
-2@@ -80,14 +80,14 @@ static int wkup_m3_rproc_stop(struct rproc *rproc)return 0 ; } -static void *wkup_m3_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *wkup_m3_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct wkup_m3_rproc *wkupm3 = rproc->priv;void *va =NULL ;int i;u32 offset; -if (len <=0 ) +if (len ==0 )return NULL ;for (i =0 ; i <WKUPM3_MEM_MAX ; i++) {include/linux/remoteproc.h +1
-1@@ -374,7 +374,7 @@ struct rproc_ops {int (*start)(struct rproc *rproc);int (*stop)(struct rproc *rproc);void (*kick)(struct rproc *rproc,int vqid); -void * (*da_to_va)(struct rproc *rproc,u64 da,int len); +void * (*da_to_va)(struct rproc *rproc,u64 da,size_t len);int (*parse_fw)(struct rproc *rproc,const struct firmware *fw);int (*handle_rsc)(struct rproc *rproc,u32 rsc_type,void *rsc,int offset,int avail);Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 1/8] remoteproc: Use size_t type for len in da_to_va
In reply to Clement LegerQuoted 9 lines · Clement Leger
With upcoming changes in elf loader for elf64 support, section size will be a u64. When used with
da_to_va, this will potentially lead to overflow if using the current "int" type for len argument. Changeda_to_vaprototype to use asize_tfor len and fix all users of this function.Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/imx_rproc.c | 11 ++++++-----
Quoted 233 lines
drivers/remoteproc/keystone_remoteproc.c | 4 ++-- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/qcom_q6v5_pas.c | 2 +- drivers/remoteproc/qcom_q6v5_wcss.c | 2 +- drivers/remoteproc/qcom_wcnss.c | 2 +- drivers/remoteproc/remoteproc_core.c | 2 +- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_slim_rproc.c | 4 ++-- drivers/remoteproc/wkup_m3_rproc.c | 4 ++-- include/linux/remoteproc.h | 2 +- 12 files changed, 20 insertions(+), 19 deletions(-)drivers/remoteproc/imx_rproc.c +6
-5@@ -186,7 +186,7 @@ static int imx_rproc_stop(struct rproc *rproc) }static int imx_rproc_da_to_sys (struct imx_rproc *priv,u64 da, -int len,u64 *sys) +size_t len,u64 *sys) {const struct imx_rproc_dcfg *dcfg = priv->dcfg;int i;@@ -203,19 +203,19 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 da, } } -dev_warn (priv->dev,"Translation failed: da = 0x%llx len = 0x%x\n" , +dev_warn (priv->dev,"Translation failed: da = 0x%llx len = 0x%zx\n" , da, len);return -ENOENT ; } -static void *imx_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *imx_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct imx_rproc *priv = rproc->priv;void *va =NULL ;u64 sys;int i; -if (len <=0 ) +if (len ==0 )return NULL ;/* @@ -235,7 +235,8 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, int len) } } -dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%x va = 0x%p\n" , da, len, va); +dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%zx va = 0x%p\n" , + da, len, va);return va; }drivers/remoteproc/keystone_remoteproc.c +2
-2@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int vqid)* can be used either by the remoteproc core for loading (when using kernel * remoteproc loader), or by any rpmsg bus drivers. */ -static void *keystone_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *keystone_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct keystone_rproc *ksproc = rproc->priv;void __iomem *va =NULL ;@@ -255,7 +255,7 @@ static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, int len)size_t size;int i; -if (len <=0 ) +if (len ==0 )return NULL ;for (i =0 ; i < ksproc->num_mems; i++) {drivers/remoteproc/qcom_q6v5_adsp.c +1
-1@@ -270,7 +270,7 @@ static int adsp_stop(struct rproc *rproc)return ret; } -static void *adsp_da_to_va (struct rproc *rproc,u64 da,int len) +static void *adsp_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;int offset;drivers/remoteproc/qcom_q6v5_mss.c +1
-1@@ -1148,7 +1148,7 @@ static int q6v5_stop(struct rproc *rproc)return 0 ; } -static void *q6v5_da_to_va (struct rproc *rproc,u64 da,int len) +static void *q6v5_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct q6v5 *qproc = rproc->priv;int offset;drivers/remoteproc/qcom_q6v5_pas.c +1
-1@@ -159,7 +159,7 @@ static int adsp_stop(struct rproc *rproc)return ret; } -static void *adsp_da_to_va (struct rproc *rproc,u64 da,int len) +static void *adsp_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;int offset;drivers/remoteproc/qcom_q6v5_wcss.c +1
-1@@ -406,7 +406,7 @@ static int q6v5_wcss_stop(struct rproc *rproc)return 0 ; } -static void *q6v5_wcss_da_to_va (struct rproc *rproc,u64 da,int len) +static void *q6v5_wcss_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct q6v5_wcss *wcss = rproc->priv;int offset;drivers/remoteproc/qcom_wcnss.c +1
-1@@ -287,7 +287,7 @@ static int wcnss_stop(struct rproc *rproc)return ret; } -static void *wcnss_da_to_va (struct rproc *rproc,u64 da,int len) +static void *wcnss_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct qcom_wcnss *wcnss = (struct qcom_wcnss *)rproc->priv;int offset;drivers/remoteproc/remoteproc_core.c +1
-1@@ -185,7 +185,7 @@ EXPORT_SYMBOL(rproc_va_to_pa);* here the output of the DMA API for the carveouts, which should be more * correct. */ -void *rproc_da_to_va (struct rproc *rproc,u64 da,int len) +void *rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct rproc_mem_entry *carveout;void *ptr =NULL ;drivers/remoteproc/remoteproc_internal.h +1
-1@@ -50,7 +50,7 @@ void rproc_exit_sysfs(void);void rproc_free_vring (struct rproc_vring *rvring);int rproc_alloc_vring (struct rproc_vdev *rvdev,int i); -void *rproc_da_to_va (struct rproc *rproc,u64 da,int len); +void *rproc_da_to_va (struct rproc *rproc,u64 da,size_t len);phys_addr_t rproc_va_to_pa (void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc);drivers/remoteproc/st_slim_rproc.c +2
-2@@ -174,7 +174,7 @@ static int slim_rproc_stop(struct rproc *rproc)return 0 ; } -static void *slim_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *slim_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct st_slim_rproc *slim_rproc = rproc->priv;void *va =NULL ;@@ -191,7 +191,7 @@ static void *slim_rproc_da_to_va(struct rproc *rproc, u64 da, int len) } } -dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%x va = 0x%pK\n" , +dev_dbg (&rproc->dev,"da = 0x%llx len = 0x%zx va = 0x%pK\n" , da, len, va);return va;drivers/remoteproc/wkup_m3_rproc.c +2
-2@@ -80,14 +80,14 @@ static int wkup_m3_rproc_stop(struct rproc *rproc)return 0 ; } -static void *wkup_m3_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +static void *wkup_m3_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len) {struct wkup_m3_rproc *wkupm3 = rproc->priv;void *va =NULL ;int i;u32 offset; -if (len <=0 ) +if (len ==0 )return NULL ;for (i =0 ; i <WKUPM3_MEM_MAX ; i++) {include/linux/remoteproc.h +1
-1@@ -374,7 +374,7 @@ struct rproc_ops {int (*start)(struct rproc *rproc);int (*stop)(struct rproc *rproc);void (*kick)(struct rproc *rproc,int vqid); -void * (*da_to_va)(struct rproc *rproc,u64 da,int len); +void * (*da_to_va)(struct rproc *rproc,u64 da,size_t len);int (*parse_fw)(struct rproc *rproc,const struct firmware *fw);int (*handle_rsc)(struct rproc *rproc,u32 rsc_type,void *rsc,int offset,int avail);Signature · 1 line
2.15.0.276.g89ea799
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH v5 2/8 remoteproc: Use size_t instead of int for rproc_mem_entry len
In reply to Clement LegerNow that rproc_da_to_va uses a size_t for length, use a size_t for len field of rproc_mem_entry. Function used to create such structures now takes a size_t instead of int to allow full size range to be handled.
--- drivers/remoteproc/remoteproc_core.c | 14 ++++++++------ drivers/remoteproc/remoteproc_debugfs.c | 2 +- include/linux/remoteproc.h | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-)
drivers/remoteproc/remoteproc_core.c +8 -6
@@ -318,8 +318,9 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i)struct device *dev = &rproc->dev;struct rproc_vring *rvring = &rvdev->vring[i];struct fw_rsc_vdev *rsc; -int ret, size, notifyid; +int ret, notifyid;struct rproc_mem_entry *mem; +size_t size;/* actual size of vring (in bytes) */ size =PAGE_ALIGN (vring_size (rvring->len, rvring->align));
@@ -746,11 +747,12 @@ static int rproc_alloc_carveout(struct rproc *rproc, va =dma_alloc_coherent (dev->parent, mem->len, &dma,GFP_KERNEL );if (!va) {dev_err (dev->parent, -"failed to allocate dma memory: len 0x%x\n" , mem->len); +"failed to allocate dma memory: len 0x%zx\n" , + mem->len);return -ENOMEM ; } -dev_dbg (dev,"carveout va %pK, dma %pad, len 0x%x\n" , +dev_dbg (dev,"carveout va %pK, dma %pad, len 0x%zx\n" , va, &dma, mem->len);if (mem->da !=FW_RSC_ADDR_ANY && !rproc->domain) {
@@ -957,7 +959,7 @@ EXPORT_SYMBOL(rproc_add_carveout);*/ struct rproc_mem_entry *rproc_mem_entry_init (struct device *dev, -void *va,dma_addr_t dma,int len,u32 da, +void *va,dma_addr_t dma,size_t len,u32 da,int (*alloc)(struct rproc *,struct rproc_mem_entry *),int (*release)(struct rproc *,struct rproc_mem_entry *),const char *name, ...)
@@ -999,7 +1001,7 @@ EXPORT_SYMBOL(rproc_mem_entry_init);* provided by client. */ struct rproc_mem_entry * -rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,int len, +rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,size_t len,u32 da,const char *name, ...) {struct rproc_mem_entry *mem;
@@ -1270,7 +1272,7 @@ static void rproc_resource_cleanup(struct rproc *rproc) unmapped =iommu_unmap (rproc->domain, entry->da, entry->len);if (unmapped != entry->len) {/* nothing much to do besides complaining */ -dev_err (dev,"failed to unmap %u/%zu\n" , entry->len, +dev_err (dev,"failed to unmap %zx/%zu\n" , entry->len, unmapped); }
drivers/remoteproc/remoteproc_debugfs.c +1 -1
@@ -293,7 +293,7 @@ static int rproc_carveouts_show(struct seq_file *seq, void *p)seq_printf (seq,"\tVirtual address: %pK\n" , carveout->va);seq_printf (seq,"\tDMA address: %pad\n" , &carveout->dma);seq_printf (seq,"\tDevice address: 0x%x\n" , carveout->da); -seq_printf (seq,"\tLength: 0x%x Bytes\n\n" , carveout->len); +seq_printf (seq,"\tLength: 0x%zx Bytes\n\n" , carveout->len); }return 0 ;
include/linux/remoteproc.h +3 -3
@@ -329,7 +329,7 @@ struct rproc;struct rproc_mem_entry {void *va;dma_addr_t dma; -int len; +size_t len;u32 da;void *priv;char name[32 ];
@@ -599,13 +599,13 @@ void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);struct rproc_mem_entry *rproc_mem_entry_init (struct device *dev, -void *va,dma_addr_t dma,int len,u32 da, +void *va,dma_addr_t dma,size_t len,u32 da,int (*alloc)(struct rproc *,struct rproc_mem_entry *),int (*release)(struct rproc *,struct rproc_mem_entry *),const char *name, ...);struct rproc_mem_entry * -rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,int len, +rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,size_t len,u32 da,const char *name, ...);int rproc_boot (struct rproc *rproc);
Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 2/8] remoteproc: Use size_t instead of int for rproc_mem_entry len
Quoted 5 lines · Clement Leger
Now that
rproc_da_to_vauses asize_tfor length, use asize_tfor len field ofrproc_mem_entry. Function used to create such structures now takes asize_tinstead of int to allow full size range to be handled.Signed-off-by Clement Leger <[email protected]>
Quoted 108 lines
--- drivers/remoteproc/remoteproc_core.c | 14 ++++++++------ drivers/remoteproc/remoteproc_debugfs.c | 2 +- include/linux/remoteproc.h | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-)drivers/remoteproc/remoteproc_core.c +8
-6@@ -318,8 +318,9 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i)struct device *dev = &rproc->dev;struct rproc_vring *rvring = &rvdev->vring[i];struct fw_rsc_vdev *rsc; -int ret, size, notifyid; +int ret, notifyid;struct rproc_mem_entry *mem; +size_t size;/* actual size of vring (in bytes) */ size =PAGE_ALIGN (vring_size (rvring->len, rvring->align));@@ -746,11 +747,12 @@ static int rproc_alloc_carveout(struct rproc *rproc, va =dma_alloc_coherent (dev->parent, mem->len, &dma,GFP_KERNEL );if (!va) {dev_err (dev->parent, -"failed to allocate dma memory: len 0x%x\n" , mem->len); +"failed to allocate dma memory: len 0x%zx\n" , + mem->len);return -ENOMEM ; } -dev_dbg (dev,"carveout va %pK, dma %pad, len 0x%x\n" , +dev_dbg (dev,"carveout va %pK, dma %pad, len 0x%zx\n" , va, &dma, mem->len);if (mem->da !=FW_RSC_ADDR_ANY && !rproc->domain) {@@ -957,7 +959,7 @@ EXPORT_SYMBOL(rproc_add_carveout);*/ struct rproc_mem_entry *rproc_mem_entry_init (struct device *dev, -void *va,dma_addr_t dma,int len,u32 da, +void *va,dma_addr_t dma,size_t len,u32 da,int (*alloc)(struct rproc *,struct rproc_mem_entry *),int (*release)(struct rproc *,struct rproc_mem_entry *),const char *name, ...)@@ -999,7 +1001,7 @@ EXPORT_SYMBOL(rproc_mem_entry_init);* provided by client. */ struct rproc_mem_entry * -rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,int len, +rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,size_t len,u32 da,const char *name, ...) {struct rproc_mem_entry *mem;@@ -1270,7 +1272,7 @@ static void rproc_resource_cleanup(struct rproc *rproc) unmapped =iommu_unmap (rproc->domain, entry->da, entry->len);if (unmapped != entry->len) {/* nothing much to do besides complaining */ -dev_err (dev,"failed to unmap %u/%zu\n" , entry->len, +dev_err (dev,"failed to unmap %zx/%zu\n" , entry->len, unmapped); }drivers/remoteproc/remoteproc_debugfs.c +1
-1@@ -293,7 +293,7 @@ static int rproc_carveouts_show(struct seq_file *seq, void *p)seq_printf (seq,"\tVirtual address: %pK\n" , carveout->va);seq_printf (seq,"\tDMA address: %pad\n" , &carveout->dma);seq_printf (seq,"\tDevice address: 0x%x\n" , carveout->da); -seq_printf (seq,"\tLength: 0x%x Bytes\n\n" , carveout->len); +seq_printf (seq,"\tLength: 0x%zx Bytes\n\n" , carveout->len); }return 0 ;include/linux/remoteproc.h +3
-3@@ -329,7 +329,7 @@ struct rproc;struct rproc_mem_entry {void *va;dma_addr_t dma; -int len; +size_t len;u32 da;void *priv;char name[32 ];@@ -599,13 +599,13 @@ void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);struct rproc_mem_entry *rproc_mem_entry_init (struct device *dev, -void *va,dma_addr_t dma,int len,u32 da, +void *va,dma_addr_t dma,size_t len,u32 da,int (*alloc)(struct rproc *,struct rproc_mem_entry *),int (*release)(struct rproc *,struct rproc_mem_entry *),const char *name, ...);struct rproc_mem_entry * -rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,int len, +rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,size_t len,u32 da,const char *name, ...);int rproc_boot (struct rproc *rproc);Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 2/8] remoteproc: Use size_t instead of int for rproc_mem_entry len
In reply to Clement LegerQuoted 5 lines · Clement Leger
Now that
rproc_da_to_vauses asize_tfor length, use asize_tfor len field ofrproc_mem_entry. Function used to create such structures now takes asize_tinstead of int to allow full size range to be handled.Signed-off-by Clement Leger <[email protected]>
With the checkpatch warning fixed:
Quoted 108 lines
--- drivers/remoteproc/remoteproc_core.c | 14 ++++++++------ drivers/remoteproc/remoteproc_debugfs.c | 2 +- include/linux/remoteproc.h | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-)drivers/remoteproc/remoteproc_core.c +8
-6@@ -318,8 +318,9 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i)struct device *dev = &rproc->dev;struct rproc_vring *rvring = &rvdev->vring[i];struct fw_rsc_vdev *rsc; -int ret, size, notifyid; +int ret, notifyid;struct rproc_mem_entry *mem; +size_t size;/* actual size of vring (in bytes) */ size =PAGE_ALIGN (vring_size (rvring->len, rvring->align));@@ -746,11 +747,12 @@ static int rproc_alloc_carveout(struct rproc *rproc, va =dma_alloc_coherent (dev->parent, mem->len, &dma,GFP_KERNEL );if (!va) {dev_err (dev->parent, -"failed to allocate dma memory: len 0x%x\n" , mem->len); +"failed to allocate dma memory: len 0x%zx\n" , + mem->len);return -ENOMEM ; } -dev_dbg (dev,"carveout va %pK, dma %pad, len 0x%x\n" , +dev_dbg (dev,"carveout va %pK, dma %pad, len 0x%zx\n" , va, &dma, mem->len);if (mem->da !=FW_RSC_ADDR_ANY && !rproc->domain) {@@ -957,7 +959,7 @@ EXPORT_SYMBOL(rproc_add_carveout);*/ struct rproc_mem_entry *rproc_mem_entry_init (struct device *dev, -void *va,dma_addr_t dma,int len,u32 da, +void *va,dma_addr_t dma,size_t len,u32 da,int (*alloc)(struct rproc *,struct rproc_mem_entry *),int (*release)(struct rproc *,struct rproc_mem_entry *),const char *name, ...)@@ -999,7 +1001,7 @@ EXPORT_SYMBOL(rproc_mem_entry_init);* provided by client. */ struct rproc_mem_entry * -rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,int len, +rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,size_t len,u32 da,const char *name, ...) {struct rproc_mem_entry *mem;@@ -1270,7 +1272,7 @@ static void rproc_resource_cleanup(struct rproc *rproc) unmapped =iommu_unmap (rproc->domain, entry->da, entry->len);if (unmapped != entry->len) {/* nothing much to do besides complaining */ -dev_err (dev,"failed to unmap %u/%zu\n" , entry->len, +dev_err (dev,"failed to unmap %zx/%zu\n" , entry->len, unmapped); }drivers/remoteproc/remoteproc_debugfs.c +1
-1@@ -293,7 +293,7 @@ static int rproc_carveouts_show(struct seq_file *seq, void *p)seq_printf (seq,"\tVirtual address: %pK\n" , carveout->va);seq_printf (seq,"\tDMA address: %pad\n" , &carveout->dma);seq_printf (seq,"\tDevice address: 0x%x\n" , carveout->da); -seq_printf (seq,"\tLength: 0x%x Bytes\n\n" , carveout->len); +seq_printf (seq,"\tLength: 0x%zx Bytes\n\n" , carveout->len); }return 0 ;include/linux/remoteproc.h +3
-3@@ -329,7 +329,7 @@ struct rproc;struct rproc_mem_entry {void *va;dma_addr_t dma; -int len; +size_t len;u32 da;void *priv;char name[32 ];@@ -599,13 +599,13 @@ void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);struct rproc_mem_entry *rproc_mem_entry_init (struct device *dev, -void *va,dma_addr_t dma,int len,u32 da, +void *va,dma_addr_t dma,size_t len,u32 da,int (*alloc)(struct rproc *,struct rproc_mem_entry *),int (*release)(struct rproc *,struct rproc_mem_entry *),const char *name, ...);struct rproc_mem_entry * -rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,int len, +rproc_of_resm_mem_entry_init (struct device *dev,u32 of_resm_idx,size_t len,u32 da,const char *name, ...);int rproc_boot (struct rproc *rproc);Signature · 1 line
2.15.0.276.g89ea799
PATCH v5 3/8 remoteproc: Use u64 type for boot_addr
In reply to Clement Legerelf64 entry is defined as a u64. Since boot_addr is used to store the elf entry point, change boot_addr type to u64 to support both elf32 and elf64. In the same time, fix users that were using this variable.
--- drivers/remoteproc/remoteproc_elf_loader.c | 2 +- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- include/linux/remoteproc.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)
drivers/remoteproc/remoteproc_elf_loader.c +1 -1
@@ -102,7 +102,7 @@ EXPORT_SYMBOL(rproc_elf_sanity_check);* Note that the boot address is not a configurable property of all remote * processors. Some will always boot at a specific hard-coded address. */ -u32 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw) +u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw) {struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data;
drivers/remoteproc/remoteproc_internal.h +1 -1
@@ -55,7 +55,7 @@ phys_addr_t rproc_va_to_pa(void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc);int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); -u32 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw); +u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw); struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
drivers/remoteproc/st_remoteproc.c +1 -1
@@ -190,7 +190,7 @@ static int st_rproc_start(struct rproc *rproc) } } -dev_info (&rproc->dev,"Started from 0x%x\n" , rproc->bootaddr); +dev_info (&rproc->dev,"Started from 0x%llx\n" , rproc->bootaddr);return 0 ;
include/linux/remoteproc.h +2 -2
@@ -382,7 +382,7 @@ struct rproc_ops { struct rproc *rproc, const struct firmware *fw);int (*load)(struct rproc *rproc,const struct firmware *fw);int (*sanity_check)(struct rproc *rproc,const struct firmware *fw); -u32 (*get_boot_addr)(struct rproc *rproc,const struct firmware *fw); +u64 (*get_boot_addr)(struct rproc *rproc,const struct firmware *fw); };/**
@@ -498,7 +498,7 @@ struct rproc {int num_traces;struct list_head carveouts;struct list_head mappings; -u32 bootaddr; +u64 bootaddr;struct list_head rvdevs;struct list_head subdevs;struct idr notifyids;
Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 3/8] remoteproc: Use u64 type for boot_addr
Quoted 5 lines · Clement Leger
elf64 entry is defined as a u64. Since
boot_addris used to store the elf entry point, changeboot_addrtype to u64 to support both elf32 and elf64. In the same time, fix users that were using this variable.Signed-off-by Clement Leger <[email protected]>
Quoted 71 lines
--- drivers/remoteproc/remoteproc_elf_loader.c | 2 +- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- include/linux/remoteproc.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)drivers/remoteproc/remoteproc_elf_loader.c +1
-1@@ -102,7 +102,7 @@ EXPORT_SYMBOL(rproc_elf_sanity_check);* Note that the boot address is not a configurable property of all remote * processors. Some will always boot at a specific hard-coded address. */ -u32 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw) +u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw) {struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data;drivers/remoteproc/remoteproc_internal.h +1
-1@@ -55,7 +55,7 @@ phys_addr_t rproc_va_to_pa(void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc);int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); -u32 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw); +u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw); struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,drivers/remoteproc/st_remoteproc.c +1
-1@@ -190,7 +190,7 @@ static int st_rproc_start(struct rproc *rproc) } } -dev_info (&rproc->dev,"Started from 0x%x\n" , rproc->bootaddr); +dev_info (&rproc->dev,"Started from 0x%llx\n" , rproc->bootaddr);return 0 ;include/linux/remoteproc.h +2
-2@@ -382,7 +382,7 @@ struct rproc_ops { struct rproc *rproc, const struct firmware *fw);int (*load)(struct rproc *rproc,const struct firmware *fw);int (*sanity_check)(struct rproc *rproc,const struct firmware *fw); -u32 (*get_boot_addr)(struct rproc *rproc,const struct firmware *fw); +u64 (*get_boot_addr)(struct rproc *rproc,const struct firmware *fw); };/** @@ -498,7 +498,7 @@ struct rproc {int num_traces;struct list_head carveouts;struct list_head mappings; -u32 bootaddr; +u64 bootaddr;struct list_head rvdevs;struct list_head subdevs;struct idr notifyids;Signature · 1 line
2.15.0.276.g89ea799
Mathieu Poirier
maintainerRe: [PATCH v5 3/8] remoteproc: Use u64 type for boot_addr
In reply to Clement LegerQuoted 30 lines · Clement Leger
elf64 entry is defined as a u64. Since
boot_addris used to store the elf entry point, changeboot_addrtype to u64 to support both elf32 and elf64. In the same time, fix users that were using this variable.Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_elf_loader.c | 2 +- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- include/linux/remoteproc.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)drivers/remoteproc/remoteproc_elf_loader.c +1
-1@@ -102,7 +102,7 @@ EXPORT_SYMBOL(rproc_elf_sanity_check);* Note that the boot address is not a configurable property of all remote * processors. Some will always boot at a specific hard-coded address. */ -u32 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw) +u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw) {struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data;drivers/remoteproc/remoteproc_internal.h +0
-0
drivers/remoteproc/remoteproc_internal.h phys_addr_t rproc_va_to_pa(void *cpu_addr); · line 61
Quoted 8 lines
drivers/remoteproc/remoteproc_internal.h +1
-1@@ -55,7 +55,7 @@ phys_addr_t rproc_va_to_pa(void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc);int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); -u32 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw); +u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw); struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
The return type of function rproc_get_boot_addr() should also be changed from u32 to u64. Or perhaps this is intentional to make sure rproc->bootaddr never occupies more than 32bit?
Quoted 38 lines
drivers/remoteproc/st_remoteproc.c +1
-1@@ -190,7 +190,7 @@ static int st_rproc_start(struct rproc *rproc) } } -dev_info (&rproc->dev,"Started from 0x%x\n" , rproc->bootaddr); +dev_info (&rproc->dev,"Started from 0x%llx\n" , rproc->bootaddr);return 0 ;include/linux/remoteproc.h +2
-2@@ -382,7 +382,7 @@ struct rproc_ops { struct rproc *rproc, const struct firmware *fw);int (*load)(struct rproc *rproc,const struct firmware *fw);int (*sanity_check)(struct rproc *rproc,const struct firmware *fw); -u32 (*get_boot_addr)(struct rproc *rproc,const struct firmware *fw); +u64 (*get_boot_addr)(struct rproc *rproc,const struct firmware *fw); };/** @@ -498,7 +498,7 @@ struct rproc {int num_traces;struct list_head carveouts;struct list_head mappings; -u32 bootaddr; +u64 bootaddr;struct list_head rvdevs;struct list_head subdevs;struct idr notifyids;Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 3/8] remoteproc: Use u64 type for boot_addr
Quoted 35 lines · ----- On 9 Mar, 2020, at 20:52, Mathieu Poirier [email protected]…
Quoted 34 lines · Clement Leger
elf64 entry is defined as a u64. Since
boot_addris used to store the elf entry point, changeboot_addrtype to u64 to support both elf32 and elf64. In the same time, fix users that were using this variable.Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_elf_loader.c | 2 +- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- include/linux/remoteproc.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)drivers/remoteproc/remoteproc_elf_loader.c +1
-1@@ -102,7 +102,7 @@ EXPORT_SYMBOL(rproc_elf_sanity_check);* Note that the boot address is not a configurable property of all remote * processors. Some will always boot at a specific hard-coded address. */ -u32 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw) +u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw) {struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data;drivers/remoteproc/remoteproc_internal.h +0
-0@@ -55,7 +55,7 @@ phys_addr_t rproc_va_to_pa(void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc);
Quoted 10 lines
drivers/remoteproc/remoteproc_internal.h phys_addr_t rproc_va_to_pa(void *cpu_addr); · line 61
Quoted 6 lines
drivers/remoteproc/remoteproc_internal.h +1
-1int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); -u32 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw); +u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw); struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,The return type of function
rproc_get_boot_addr()should also be changed from u32 to u64. Or perhaps this is intentional to make surerproc->bootaddrnever occupies more than 32bit?
No, this is a mistake clearly. I haven't been able to test with a 64 bit boot address since our remote processors always boot in the 32 bits space. But since the elf64 boot address is on 64 bitsn this was a logical modification. I will fix that.
Quoted 39 lines
Quoted 39 lines
drivers/remoteproc/st_remoteproc.c +1
-1@@ -190,7 +190,7 @@ static int st_rproc_start(struct rproc *rproc) } } -dev_info (&rproc->dev,"Started from 0x%x\n" , rproc->bootaddr); +dev_info (&rproc->dev,"Started from 0x%llx\n" , rproc->bootaddr);return 0 ;include/linux/remoteproc.h +2
-3@@ -382,7 +382,7 @@ struct rproc_ops { struct rproc *rproc, const struct firmware *fw);int (*load)(struct rproc *rproc,const struct firmware *fw);int (*sanity_check)(struct rproc *rproc,const struct firmware *fw); -u32 (*get_boot_addr)(struct rproc *rproc,const struct firmware *fw); +u64 (*get_boot_addr)(struct rproc *rproc,const struct firmware *fw); };/** @@ -498,7 +498,7 @@ struct rproc {int num_traces;struct list_head carveouts;struct list_head mappings; -u32 bootaddr; +u64 bootaddr;struct list_head rvdevs;struct list_head subdevs;struct idr notifyids; --2.15.0.276.g89ea799
Re: [PATCH v5 3/8] remoteproc: Use u64 type for boot_addr
Quoted 50 lines · Cl?ment Leger
Quoted 35 lines · ----- On 9 Mar, 2020, at 20:52, Mathieu Poirier [email protected]…
Quoted 34 lines · Clement Leger
elf64 entry is defined as a u64. Since
boot_addris used to store the elf entry point, changeboot_addrtype to u64 to support both elf32 and elf64. In the same time, fix users that were using this variable.Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_elf_loader.c | 2 +- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- include/linux/remoteproc.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)drivers/remoteproc/remoteproc_elf_loader.c +1
-1@@ -102,7 +102,7 @@ EXPORT_SYMBOL(rproc_elf_sanity_check);* Note that the boot address is not a configurable property of all remote * processors. Some will always boot at a specific hard-coded address. */ -u32 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw) +u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw) {struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data;drivers/remoteproc/remoteproc_internal.h +0
-0@@ -55,7 +55,7 @@ phys_addr_t rproc_va_to_pa(void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc);Quoted 10 lines
drivers/remoteproc/remoteproc_internal.h phys_addr_t rproc_va_to_pa(void *cpu_addr); · line 61
Quoted 6 lines
drivers/remoteproc/remoteproc_internal.h +1
-1int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); -u32 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw); +u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw); struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,The return type of function
rproc_get_boot_addr()should also be changed from u32 to u64. Or perhaps this is intentional to make surerproc->bootaddrnever occupies more than 32bit?
Quoted 5 lines
No, this is a mistake clearly. I haven't been able to test with a 64 bit boot address since our remote processors always boot in the 32 bits space. But since the elf64 boot address is on 64 bitsn this was a logical modification. I will fix that.
Sorry, I forgot to reply to this one. I fixed it up while applying the patch.
Thanks,
Bjorn
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
drivers/remoteproc/st_remoteproc.c +1
-1@@ -190,7 +190,7 @@ static int st_rproc_start(struct rproc *rproc) } } -dev_info (&rproc->dev,"Started from 0x%x\n" , rproc->bootaddr); +dev_info (&rproc->dev,"Started from 0x%llx\n" , rproc->bootaddr);return 0 ;include/linux/remoteproc.h +2
-3@@ -382,7 +382,7 @@ struct rproc_ops { struct rproc *rproc, const struct firmware *fw);int (*load)(struct rproc *rproc,const struct firmware *fw);int (*sanity_check)(struct rproc *rproc,const struct firmware *fw); -u32 (*get_boot_addr)(struct rproc *rproc,const struct firmware *fw); +u64 (*get_boot_addr)(struct rproc *rproc,const struct firmware *fw); };/** @@ -498,7 +498,7 @@ struct rproc {int num_traces;struct list_head carveouts;struct list_head mappings; -u32 bootaddr; +u64 bootaddr;struct list_head rvdevs;struct list_head subdevs;struct idr notifyids; --2.15.0.276.g89ea799
PATCH v5 4/8 remoteproc: Add elf helpers to access elf64 and elf32 fields
In reply to Clement Legerelf32 and elf64 mainly differ by their types. In order to avoid copy/pasting the whole loader code, generate static inline functions which will access values according to the elf class. It allows to keep a common loader basis.
In order to accommodate both elf types sizes, the maximum size for a elf header member is chosen using the maximum value of the field for both elf class.
--- drivers/remoteproc/remoteproc_elf_helpers.h | 96 +++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 drivers/remoteproc/remoteproc_elf_helpers.h
drivers/remoteproc/remoteproc_elf_helpers.h new file +96 -0
@@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Remote processor elf helpers defines +* +* Copyright (C) 2020 Kalray, Inc. +*/ + +#ifndef REMOTEPROC_ELF_LOADER_H +#define REMOTEPROC_ELF_LOADER_H + +#include <linux/elf.h> +#include <linux/types.h> + +/** +* fw_elf_get_class - Get elf class +* @fw: the ELF firmware image +* +* Note that we use and elf32_hdr to access the class since the start of the +* struct is the same for both elf class +* +* Return: elf class of the firmware +*/ +static inline u8 fw_elf_get_class (const struct firmware *fw) +{ +struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data; + +return ehdr->e_ident[EI_CLASS ]; +} + +static inline void elf_hdr_init_ident (struct elf32_hdr *hdr,u8 class) +{ +memcpy (hdr->e_ident,ELFMAG ,SELFMAG ); + hdr->e_ident[EI_CLASS ] = class; + hdr->e_ident[EI_DATA ] =ELFDATA2LSB ; + hdr->e_ident[EI_VERSION ] =EV_CURRENT ; + hdr->e_ident[EI_OSABI ] =ELFOSABI_NONE ; +} + +/* Generate getter and setter for a specific elf struct/field */ +#define ELF_GEN_FIELD_GET_SET (__s, __field, __type) \ +static inline __type elf_##__s##_get_##__field(u8 class, const void *arg) \ +{ \ + if (class == ELFCLASS32) \ + return (__type) ((const struct elf32_##__s *) arg)->__field; \ + else \ + return (__type) ((const struct elf64_##__s *) arg)->__field; \ +} \ +static inline void elf_##__s##_set_##__field(u8 class, void *arg, \ + __type value) \ +{ \ + if (class == ELFCLASS32) \ + ((struct elf32_##__s *) arg)->__field = (__type) value; \ + else \ + ((struct elf64_##__s *) arg)->__field = (__type) value; \ +} + +ELF_GEN_FIELD_GET_SET(hdr, e_entry, u64) +ELF_GEN_FIELD_GET_SET(hdr, e_phnum, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_shnum, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_phoff, u64) +ELF_GEN_FIELD_GET_SET(hdr, e_shoff, u64) +ELF_GEN_FIELD_GET_SET(hdr, e_shstrndx, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_machine, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_type, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_version, u32) +ELF_GEN_FIELD_GET_SET(hdr, e_ehsize, u32) +ELF_GEN_FIELD_GET_SET(hdr, e_phentsize, u16) + +ELF_GEN_FIELD_GET_SET(phdr, p_paddr, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_vaddr, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_filesz, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_memsz, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_type, u32) +ELF_GEN_FIELD_GET_SET(phdr, p_offset, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_flags, u32) +ELF_GEN_FIELD_GET_SET(phdr, p_align, u64) + +ELF_GEN_FIELD_GET_SET(shdr, sh_size, u64) +ELF_GEN_FIELD_GET_SET(shdr, sh_offset, u64) +ELF_GEN_FIELD_GET_SET(shdr, sh_name, u32) +ELF_GEN_FIELD_GET_SET(shdr, sh_addr, u64) + +#define ELF_STRUCT_SIZE (__s) \ +static inline unsigned long elf_size_of_##__s(u8 class) \ +{ \ + if (class == ELFCLASS32)\ + return sizeof(struct elf32_##__s); \ + else \ + return sizeof(struct elf64_##__s); \ +} + +ELF_STRUCT_SIZE(shdr) +ELF_STRUCT_SIZE(phdr) +ELF_STRUCT_SIZE(hdr) + +#endif /* REMOTEPROC_ELF_LOADER_H */
Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 4/8] remoteproc: Add elf helpers to access elf64 and elf32 fields
Quoted 9 lines · Clement Leger
elf32 and elf64 mainly differ by their types. In order to avoid copy/pasting the whole loader code, generate static inline functions which will access values according to the elf class. It allows to keep a common loader basis.
In order to accommodate both elf types sizes, the maximum size for a elf header member is chosen using the maximum value of the field for both elf class.Signed-off-by Clement Leger <[email protected]>
Quoted 110 lines
--- drivers/remoteproc/remoteproc_elf_helpers.h | 96 +++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 drivers/remoteproc/remoteproc_elf_helpers.hdrivers/remoteproc/remoteproc_elf_helpers.h new file +96
-0@@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Remote processor elf helpers defines +* +* Copyright (C) 2020 Kalray, Inc. +*/ + +#ifndef REMOTEPROC_ELF_LOADER_H +#define REMOTEPROC_ELF_LOADER_H + +#include <linux/elf.h> +#include <linux/types.h> + +/** +* fw_elf_get_class - Get elf class +* @fw: the ELF firmware image +* +* Note that we use and elf32_hdr to access the class since the start of the +* struct is the same for both elf class +* +* Return: elf class of the firmware +*/ +static inline u8 fw_elf_get_class (const struct firmware *fw) +{ +struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data; + +return ehdr->e_ident[EI_CLASS ]; +} + +static inline void elf_hdr_init_ident (struct elf32_hdr *hdr,u8 class) +{ +memcpy (hdr->e_ident,ELFMAG ,SELFMAG ); + hdr->e_ident[EI_CLASS ] = class; + hdr->e_ident[EI_DATA ] =ELFDATA2LSB ; + hdr->e_ident[EI_VERSION ] =EV_CURRENT ; + hdr->e_ident[EI_OSABI ] =ELFOSABI_NONE ; +} + +/* Generate getter and setter for a specific elf struct/field */ +#define ELF_GEN_FIELD_GET_SET (__s, __field, __type) \ +static inline __type elf_##__s##_get_##__field(u8 class, const void *arg) \ +{ \ + if (class == ELFCLASS32) \ + return (__type) ((const struct elf32_##__s *) arg)->__field; \ + else \ + return (__type) ((const struct elf64_##__s *) arg)->__field; \ +} \ +static inline void elf_##__s##_set_##__field(u8 class, void *arg, \ + __type value) \ +{ \ + if (class == ELFCLASS32) \ + ((struct elf32_##__s *) arg)->__field = (__type) value; \ + else \ + ((struct elf64_##__s *) arg)->__field = (__type) value; \ +} + +ELF_GEN_FIELD_GET_SET(hdr, e_entry, u64) +ELF_GEN_FIELD_GET_SET(hdr, e_phnum, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_shnum, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_phoff, u64) +ELF_GEN_FIELD_GET_SET(hdr, e_shoff, u64) +ELF_GEN_FIELD_GET_SET(hdr, e_shstrndx, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_machine, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_type, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_version, u32) +ELF_GEN_FIELD_GET_SET(hdr, e_ehsize, u32) +ELF_GEN_FIELD_GET_SET(hdr, e_phentsize, u16) + +ELF_GEN_FIELD_GET_SET(phdr, p_paddr, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_vaddr, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_filesz, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_memsz, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_type, u32) +ELF_GEN_FIELD_GET_SET(phdr, p_offset, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_flags, u32) +ELF_GEN_FIELD_GET_SET(phdr, p_align, u64) + +ELF_GEN_FIELD_GET_SET(shdr, sh_size, u64) +ELF_GEN_FIELD_GET_SET(shdr, sh_offset, u64) +ELF_GEN_FIELD_GET_SET(shdr, sh_name, u32) +ELF_GEN_FIELD_GET_SET(shdr, sh_addr, u64) + +#define ELF_STRUCT_SIZE (__s) \ +static inline unsigned long elf_size_of_##__s(u8 class) \ +{ \ + if (class == ELFCLASS32)\ + return sizeof(struct elf32_##__s); \ + else \ + return sizeof(struct elf64_##__s); \ +} + +ELF_STRUCT_SIZE(shdr) +ELF_STRUCT_SIZE(phdr) +ELF_STRUCT_SIZE(hdr) + +#endif /* REMOTEPROC_ELF_LOADER_H */ Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 4/8] remoteproc: Add elf helpers to access elf64 and elf32 fields
In reply to Clement LegerQuoted 9 lines · Clement Leger
elf32 and elf64 mainly differ by their types. In order to avoid copy/pasting the whole loader code, generate static inline functions which will access values according to the elf class. It allows to keep a common loader basis.
In order to accommodate both elf types sizes, the maximum size for a elf header member is chosen using the maximum value of the field for both elf class.Signed-off-by Clement Leger <[email protected]>
Quoted 110 lines
--- drivers/remoteproc/remoteproc_elf_helpers.h | 96 +++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 drivers/remoteproc/remoteproc_elf_helpers.hdrivers/remoteproc/remoteproc_elf_helpers.h new file +96
-0@@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Remote processor elf helpers defines +* +* Copyright (C) 2020 Kalray, Inc. +*/ + +#ifndef REMOTEPROC_ELF_LOADER_H +#define REMOTEPROC_ELF_LOADER_H + +#include <linux/elf.h> +#include <linux/types.h> + +/** +* fw_elf_get_class - Get elf class +* @fw: the ELF firmware image +* +* Note that we use and elf32_hdr to access the class since the start of the +* struct is the same for both elf class +* +* Return: elf class of the firmware +*/ +static inline u8 fw_elf_get_class (const struct firmware *fw) +{ +struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data; + +return ehdr->e_ident[EI_CLASS ]; +} + +static inline void elf_hdr_init_ident (struct elf32_hdr *hdr,u8 class) +{ +memcpy (hdr->e_ident,ELFMAG ,SELFMAG ); + hdr->e_ident[EI_CLASS ] = class; + hdr->e_ident[EI_DATA ] =ELFDATA2LSB ; + hdr->e_ident[EI_VERSION ] =EV_CURRENT ; + hdr->e_ident[EI_OSABI ] =ELFOSABI_NONE ; +} + +/* Generate getter and setter for a specific elf struct/field */ +#define ELF_GEN_FIELD_GET_SET (__s, __field, __type) \ +static inline __type elf_##__s##_get_##__field(u8 class, const void *arg) \ +{ \ + if (class == ELFCLASS32) \ + return (__type) ((const struct elf32_##__s *) arg)->__field; \ + else \ + return (__type) ((const struct elf64_##__s *) arg)->__field; \ +} \ +static inline void elf_##__s##_set_##__field(u8 class, void *arg, \ + __type value) \ +{ \ + if (class == ELFCLASS32) \ + ((struct elf32_##__s *) arg)->__field = (__type) value; \ + else \ + ((struct elf64_##__s *) arg)->__field = (__type) value; \ +} + +ELF_GEN_FIELD_GET_SET(hdr, e_entry, u64) +ELF_GEN_FIELD_GET_SET(hdr, e_phnum, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_shnum, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_phoff, u64) +ELF_GEN_FIELD_GET_SET(hdr, e_shoff, u64) +ELF_GEN_FIELD_GET_SET(hdr, e_shstrndx, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_machine, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_type, u16) +ELF_GEN_FIELD_GET_SET(hdr, e_version, u32) +ELF_GEN_FIELD_GET_SET(hdr, e_ehsize, u32) +ELF_GEN_FIELD_GET_SET(hdr, e_phentsize, u16) + +ELF_GEN_FIELD_GET_SET(phdr, p_paddr, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_vaddr, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_filesz, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_memsz, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_type, u32) +ELF_GEN_FIELD_GET_SET(phdr, p_offset, u64) +ELF_GEN_FIELD_GET_SET(phdr, p_flags, u32) +ELF_GEN_FIELD_GET_SET(phdr, p_align, u64) + +ELF_GEN_FIELD_GET_SET(shdr, sh_size, u64) +ELF_GEN_FIELD_GET_SET(shdr, sh_offset, u64) +ELF_GEN_FIELD_GET_SET(shdr, sh_name, u32) +ELF_GEN_FIELD_GET_SET(shdr, sh_addr, u64) + +#define ELF_STRUCT_SIZE (__s) \ +static inline unsigned long elf_size_of_##__s(u8 class) \ +{ \ + if (class == ELFCLASS32)\ + return sizeof(struct elf32_##__s); \ + else \ + return sizeof(struct elf64_##__s); \ +} + +ELF_STRUCT_SIZE(shdr) +ELF_STRUCT_SIZE(phdr) +ELF_STRUCT_SIZE(hdr) + +#endif /* REMOTEPROC_ELF_LOADER_H */ Signature · 1 line
2.15.0.276.g89ea799
PATCH v5 5/8 remoteproc: Rename rproc_elf_sanity_check for elf32
In reply to Clement LegerSince this function will be modified to support both elf32 and elf64, rename the existing one to elf32 (which is the only supported format at the moment). This will allow not to introduce possible side effect when adding elf64 support (ie: all backends will still support only elf32 if not requested explicitely using rproc_elf_sanity_check).
--- drivers/remoteproc/remoteproc_core.c | 2 +- drivers/remoteproc/remoteproc_elf_loader.c | 6 +++--- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- drivers/remoteproc/st_slim_rproc.c | 2 +- drivers/remoteproc/stm32_rproc.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)
drivers/remoteproc/remoteproc_core.c +1 -1
@@ -2055,7 +2055,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->ops->load = rproc_elf_load_segments; rproc->ops->parse_fw = rproc_elf_load_rsc_table; rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; - rproc->ops->sanity_check = rproc_elf_sanity_check; + rproc->ops->sanity_check = rproc_elf32_sanity_check; rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; }
drivers/remoteproc/remoteproc_elf_loader.c +3 -3
@@ -25,13 +25,13 @@#include "remoteproc_internal.h" /** -* rproc_elf_sanity_check() - Sanity Check ELF firmware image +* rproc_elf_sanity_check() - Sanity Check ELF32 firmware image * @rproc: the remote processor handle * @fw: the ELF firmware image * * Make sure this fw image is sane. */ -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw) +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw) {const char *name = rproc->firmware;struct device *dev = &rproc->dev;
@@ -89,7 +89,7 @@ int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)return 0 ; } -EXPORT_SYMBOL (rproc_elf_sanity_check); +EXPORT_SYMBOL (rproc_elf32_sanity_check);/** * rproc_elf_get_boot_addr() - Get rproc's boot address.
drivers/remoteproc/remoteproc_internal.h +1 -1
@@ -54,7 +54,7 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len);phys_addr_t rproc_va_to_pa (void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc); -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw);u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw);
drivers/remoteproc/st_remoteproc.c +1 -1
@@ -233,7 +233,7 @@ static const struct rproc_ops st_rproc_ops = { .parse_fw = st_rproc_parse_fw, .load = rproc_elf_load_segments, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, };
drivers/remoteproc/st_slim_rproc.c +1 -1
@@ -203,7 +203,7 @@ static const struct rproc_ops slim_rproc_ops = { .da_to_va = slim_rproc_da_to_va, .get_boot_addr = rproc_elf_get_boot_addr, .load = rproc_elf_load_segments, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, };/**
drivers/remoteproc/stm32_rproc.c +1 -1
@@ -505,7 +505,7 @@ static struct rproc_ops st_rproc_ops = { .load = rproc_elf_load_segments, .parse_fw = stm32_rproc_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, };
Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 5/8] remoteproc: Rename rproc_elf_sanity_check for elf32
Quoted 6 lines · Clement Leger
Since this function will be modified to support both elf32 and elf64, rename the existing one to elf32 (which is the only supported format at the moment). This will allow not to introduce possible side effect when adding elf64 support (ie: all backends will still support only elf32 if not requested explicitely using
rproc_elf_sanity_check).
Is there a reason for preventing ELF64 binaries be loaded?
Regards,
Bjorn
Quoted 107 lines
Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 2 +- drivers/remoteproc/remoteproc_elf_loader.c | 6 +++--- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- drivers/remoteproc/st_slim_rproc.c | 2 +- drivers/remoteproc/stm32_rproc.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)drivers/remoteproc/remoteproc_core.c +1
-1@@ -2055,7 +2055,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->ops->load = rproc_elf_load_segments; rproc->ops->parse_fw = rproc_elf_load_rsc_table; rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; - rproc->ops->sanity_check = rproc_elf_sanity_check; + rproc->ops->sanity_check = rproc_elf32_sanity_check; rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; }drivers/remoteproc/remoteproc_elf_loader.c +3
-3@@ -25,13 +25,13 @@#include "remoteproc_internal.h" /** -* rproc_elf_sanity_check() - Sanity Check ELF firmware image +* rproc_elf_sanity_check() - Sanity Check ELF32 firmware image * @rproc: the remote processor handle * @fw: the ELF firmware image * * Make sure this fw image is sane. */ -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw) +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw) {const char *name = rproc->firmware;struct device *dev = &rproc->dev;@@ -89,7 +89,7 @@ int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)return 0 ; } -EXPORT_SYMBOL (rproc_elf_sanity_check); +EXPORT_SYMBOL (rproc_elf32_sanity_check);/** * rproc_elf_get_boot_addr() - Get rproc's boot address. drivers/remoteproc/remoteproc_internal.h +1
-1@@ -54,7 +54,7 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len);phys_addr_t rproc_va_to_pa (void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc); -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw);u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw);drivers/remoteproc/st_remoteproc.c +1
-1@@ -233,7 +233,7 @@ static const struct rproc_ops st_rproc_ops = { .parse_fw = st_rproc_parse_fw, .load = rproc_elf_load_segments, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, };drivers/remoteproc/st_slim_rproc.c +1
-1@@ -203,7 +203,7 @@ static const struct rproc_ops slim_rproc_ops = { .da_to_va = slim_rproc_da_to_va, .get_boot_addr = rproc_elf_get_boot_addr, .load = rproc_elf_load_segments, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, };/** drivers/remoteproc/stm32_rproc.c +1
-1@@ -505,7 +505,7 @@ static struct rproc_ops st_rproc_ops = { .load = rproc_elf_load_segments, .parse_fw = stm32_rproc_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, };Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 5/8] remoteproc: Rename rproc_elf_sanity_check for elf32
Hi Bjorn,
Quoted 10 lines · ----- On 3 Mar, 2020, at 00:13, Bjorn Andersson [email protected]…
Quoted 6 lines · Clement Leger
Since this function will be modified to support both elf32 and elf64, rename the existing one to elf32 (which is the only supported format at the moment). This will allow not to introduce possible side effect when adding elf64 support (ie: all backends will still support only elf32 if not requested explicitely using
rproc_elf_sanity_check).Is there a reason for preventing ELF64 binaries be loaded?
I decided to go this way to let driver maintainer decide if they want to support elf64 to avoid problems with 64bits addresses/sizes which do not fit in their native type (size_t for instance). This is probably not going to happen and there are additionnal checks before calling rproc_da_to_va. And addresses should be filtered by rproc_da_to_va. So, actually it seems there is no reason to forbid supporting elf32/64 for all drivers.
Regards,
Clément
Quoted 117 lines
Regards,
BjornQuoted 113 lines
Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 2 +- drivers/remoteproc/remoteproc_elf_loader.c | 6 +++--- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- drivers/remoteproc/st_slim_rproc.c | 2 +- drivers/remoteproc/stm32_rproc.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)drivers/remoteproc/remoteproc_core.c +1
-1@@ -2055,7 +2055,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->ops->load = rproc_elf_load_segments; rproc->ops->parse_fw = rproc_elf_load_rsc_table; rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; - rproc->ops->sanity_check = rproc_elf_sanity_check; + rproc->ops->sanity_check = rproc_elf32_sanity_check; rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; }drivers/remoteproc/remoteproc_elf_loader.c +3
-3@@ -25,13 +25,13 @@#include "remoteproc_internal.h" /** -* rproc_elf_sanity_check() - Sanity Check ELF firmware image +* rproc_elf_sanity_check() - Sanity Check ELF32 firmware image * @rproc: the remote processor handle * @fw: the ELF firmware image * * Make sure this fw image is sane. */ -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw) +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw) {const char *name = rproc->firmware;struct device *dev = &rproc->dev;@@ -89,7 +89,7 @@ int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)return 0 ; } -EXPORT_SYMBOL (rproc_elf_sanity_check); +EXPORT_SYMBOL (rproc_elf32_sanity_check);/** *
rproc_elf_get_boot_addr()- Get rproc's boot address.drivers/remoteproc/remoteproc_internal.h +1
-1@@ -54,7 +54,7 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len);phys_addr_t rproc_va_to_pa (void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc); -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw);u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw);drivers/remoteproc/st_remoteproc.c +1
-1@@ -233,7 +233,7 @@ static const struct rproc_ops st_rproc_ops = { .parse_fw = st_rproc_parse_fw, .load = rproc_elf_load_segments, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, };drivers/remoteproc/st_slim_rproc.c +1
-1@@ -203,7 +203,7 @@ static const struct rproc_ops slim_rproc_ops = { .da_to_va = slim_rproc_da_to_va, .get_boot_addr = rproc_elf_get_boot_addr, .load = rproc_elf_load_segments, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, };/** drivers/remoteproc/stm32_rproc.c +1
-2@@ -505,7 +505,7 @@ static struct rproc_ops st_rproc_ops = { .load = rproc_elf_load_segments, .parse_fw = stm32_rproc_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, }; --2.15.0.276.g89ea799
Re: [PATCH v5 5/8] remoteproc: Rename rproc_elf_sanity_check for elf32
Quoted 15 lines · Cl?ment Leger
Hi Bjorn,
Quoted 10 lines · ----- On 3 Mar, 2020, at 00:13, Bjorn Andersson [email protected]…
Quoted 6 lines · Clement Leger
Since this function will be modified to support both elf32 and elf64, rename the existing one to elf32 (which is the only supported format at the moment). This will allow not to introduce possible side effect when adding elf64 support (ie: all backends will still support only elf32 if not requested explicitely using
rproc_elf_sanity_check).Is there a reason for preventing ELF64 binaries be loaded?
Quoted 8 lines
I decided to go this way to let driver maintainer decide if they want to support elf64 to avoid problems with 64bits addresses/sizes which do not fit in their native type (
size_tfor instance). This is probably not going to happen and there are additionnal checks before callingrproc_da_to_va. And addresses should be filtered byrproc_da_to_va. So, actually it seems there is no reason to forbid supporting elf32/64 for all drivers.
I was hoping to hear some additional feedback on this from others.
I've merge the patch as is, but think it would be nice to clean this up and just have the driver ignore if fed a 32 or 64-elf.
Regards,
Bjorn
Quoted 121 lines
Regards,
Cl�ment
Quoted 117 lines
Regards,
BjornQuoted 113 lines
Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 2 +- drivers/remoteproc/remoteproc_elf_loader.c | 6 +++--- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- drivers/remoteproc/st_slim_rproc.c | 2 +- drivers/remoteproc/stm32_rproc.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)drivers/remoteproc/remoteproc_core.c +1
-1@@ -2055,7 +2055,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->ops->load = rproc_elf_load_segments; rproc->ops->parse_fw = rproc_elf_load_rsc_table; rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; - rproc->ops->sanity_check = rproc_elf_sanity_check; + rproc->ops->sanity_check = rproc_elf32_sanity_check; rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; }drivers/remoteproc/remoteproc_elf_loader.c +3
-3@@ -25,13 +25,13 @@#include "remoteproc_internal.h" /** -* rproc_elf_sanity_check() - Sanity Check ELF firmware image +* rproc_elf_sanity_check() - Sanity Check ELF32 firmware image * @rproc: the remote processor handle * @fw: the ELF firmware image * * Make sure this fw image is sane. */ -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw) +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw) {const char *name = rproc->firmware;struct device *dev = &rproc->dev;@@ -89,7 +89,7 @@ int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)return 0 ; } -EXPORT_SYMBOL (rproc_elf_sanity_check); +EXPORT_SYMBOL (rproc_elf32_sanity_check);/** *
rproc_elf_get_boot_addr()- Get rproc's boot address.drivers/remoteproc/remoteproc_internal.h +1
-1@@ -54,7 +54,7 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len);phys_addr_t rproc_va_to_pa (void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc); -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw);u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw);drivers/remoteproc/st_remoteproc.c +1
-1@@ -233,7 +233,7 @@ static const struct rproc_ops st_rproc_ops = { .parse_fw = st_rproc_parse_fw, .load = rproc_elf_load_segments, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, };drivers/remoteproc/st_slim_rproc.c +1
-1@@ -203,7 +203,7 @@ static const struct rproc_ops slim_rproc_ops = { .da_to_va = slim_rproc_da_to_va, .get_boot_addr = rproc_elf_get_boot_addr, .load = rproc_elf_load_segments, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, };/** drivers/remoteproc/stm32_rproc.c +1
-2@@ -505,7 +505,7 @@ static struct rproc_ops st_rproc_ops = { .load = rproc_elf_load_segments, .parse_fw = stm32_rproc_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, }; --2.15.0.276.g89ea799
Mathieu Poirier
maintainerRe: [PATCH v5 5/8] remoteproc: Rename rproc_elf_sanity_check for elf32
Quoted 26 lines · Bjorn Andersson
Quoted 15 lines · Cl?ment Leger
Hi Bjorn,
Quoted 10 lines · ----- On 3 Mar, 2020, at 00:13, Bjorn Andersson [email protected]…
Quoted 6 lines · Clement Leger
Since this function will be modified to support both elf32 and elf64, rename the existing one to elf32 (which is the only supported format at the moment). This will allow not to introduce possible side effect when adding elf64 support (ie: all backends will still support only elf32 if not requested explicitely using
rproc_elf_sanity_check).Is there a reason for preventing ELF64 binaries be loaded?
Quoted 8 lines
I decided to go this way to let driver maintainer decide if they want to support elf64 to avoid problems with 64bits addresses/sizes which do not fit in their native type (
size_tfor instance). This is probably not going to happen and there are additionnal checks before callingrproc_da_to_va. And addresses should be filtered byrproc_da_to_va. So, actually it seems there is no reason to forbid supporting elf32/64 for all drivers.
Quoted 1 line
I was hoping to hear some additional feedback on this from others.
I didn't follow up on this one because I agreed with your assesment and didn't think it was needed.
Simply put I would rather see rproc_elf_sanity_check() gain support for elf64 and let the platform code decide what to do with format they don't support rather than spinning a new function.
Quoted 3 lines
I've merge the patch as is, but think it would be nice to clean this up and just have the driver ignore if fed a 32 or 64-elf.
It would be really nice to see this cleaned up in time for the coming merge window...
Thanks
Mathieu
Quoted 125 lines
Regards,
BjornQuoted 121 lines
Regards,
Cl�ment
Quoted 117 lines
Regards,
BjornQuoted 113 lines
Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 2 +- drivers/remoteproc/remoteproc_elf_loader.c | 6 +++--- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- drivers/remoteproc/st_slim_rproc.c | 2 +- drivers/remoteproc/stm32_rproc.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)drivers/remoteproc/remoteproc_core.c +1
-1@@ -2055,7 +2055,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->ops->load = rproc_elf_load_segments; rproc->ops->parse_fw = rproc_elf_load_rsc_table; rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; - rproc->ops->sanity_check = rproc_elf_sanity_check; + rproc->ops->sanity_check = rproc_elf32_sanity_check; rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; }drivers/remoteproc/remoteproc_elf_loader.c +3
-3@@ -25,13 +25,13 @@#include "remoteproc_internal.h" /** -* rproc_elf_sanity_check() - Sanity Check ELF firmware image +* rproc_elf_sanity_check() - Sanity Check ELF32 firmware image * @rproc: the remote processor handle * @fw: the ELF firmware image * * Make sure this fw image is sane. */ -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw) +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw) {const char *name = rproc->firmware;struct device *dev = &rproc->dev;@@ -89,7 +89,7 @@ int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)return 0 ; } -EXPORT_SYMBOL (rproc_elf_sanity_check); +EXPORT_SYMBOL (rproc_elf32_sanity_check);/** *
rproc_elf_get_boot_addr()- Get rproc's boot address.drivers/remoteproc/remoteproc_internal.h +1
-1@@ -54,7 +54,7 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len);phys_addr_t rproc_va_to_pa (void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc); -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw);u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw);drivers/remoteproc/st_remoteproc.c +1
-1@@ -233,7 +233,7 @@ static const struct rproc_ops st_rproc_ops = { .parse_fw = st_rproc_parse_fw, .load = rproc_elf_load_segments, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, };drivers/remoteproc/st_slim_rproc.c +1
-1@@ -203,7 +203,7 @@ static const struct rproc_ops slim_rproc_ops = { .da_to_va = slim_rproc_da_to_va, .get_boot_addr = rproc_elf_get_boot_addr, .load = rproc_elf_load_segments, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, };/** drivers/remoteproc/stm32_rproc.c +1
-2@@ -505,7 +505,7 @@ static struct rproc_ops st_rproc_ops = { .load = rproc_elf_load_segments, .parse_fw = stm32_rproc_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, }; --2.15.0.276.g89ea799
Re: [PATCH v5 5/8] remoteproc: Rename rproc_elf_sanity_check for elf32
Hi Mathieu,
Quoted 38 lines · ----- On 10 Mar, 2020, at 16:20, Mathieu Poirier [email protected]…
Quoted 27 lines · Bjorn Andersson
Quoted 16 lines · Cl?ment Leger
Hi Bjorn,
----- On 3 Mar, 2020, at 00:13, Bjorn Andersson [email protected]
Quoted 10 lines · wrote:
Quoted 6 lines · Clement Leger
Since this function will be modified to support both elf32 and elf64, rename the existing one to elf32 (which is the only supported format at the moment). This will allow not to introduce possible side effect when adding elf64 support (ie: all backends will still support only elf32 if not requested explicitely using
rproc_elf_sanity_check).Is there a reason for preventing ELF64 binaries be loaded?
Quoted 8 lines
I decided to go this way to let driver maintainer decide if they want to support elf64 to avoid problems with 64bits addresses/sizes which do not fit in their native type (
size_tfor instance). This is probably not going to happen and there are additionnal checks before callingrproc_da_to_va. And addresses should be filtered byrproc_da_to_va. So, actually it seems there is no reason to forbid supporting elf32/64 for all drivers.Quoted 1 line
I was hoping to hear some additional feedback on this from others.
I didn't follow up on this one because I agreed with your assesment and didn't think it was needed.
Simply put I would rather see
rproc_elf_sanity_check()gain support for elf64 and let the platform code decide what to do with format they don't support rather than spinning a new function.Quoted 1 line
Quoted 5 lines
Quoted 2 lines
I've merge the patch as is, but think it would be nice to clean this up and just have the driver ignore if fed a 32 or 64-elf.
It would be really nice to see this cleaned up in time for the coming merge window...
I could have sent a V7, but Bjorn was faster than my comment ;) Bjorn, Is there any way to revert that or it's already pushed ? I already have a clean V7.
Thanks,
Clément
Quoted 129 lines
Thanks
MathieuQuoted 125 lines
Regards,
BjornQuoted 121 lines
Regards,
Clément
Quoted 117 lines
Regards,
BjornQuoted 113 lines
Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 2 +- drivers/remoteproc/remoteproc_elf_loader.c | 6 +++--- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- drivers/remoteproc/st_slim_rproc.c | 2 +- drivers/remoteproc/stm32_rproc.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)drivers/remoteproc/remoteproc_core.c +1
-1@@ -2055,7 +2055,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->ops->load = rproc_elf_load_segments; rproc->ops->parse_fw = rproc_elf_load_rsc_table; rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; - rproc->ops->sanity_check = rproc_elf_sanity_check; + rproc->ops->sanity_check = rproc_elf32_sanity_check; rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; }drivers/remoteproc/remoteproc_elf_loader.c +3
-3@@ -25,13 +25,13 @@#include "remoteproc_internal.h" /** -* rproc_elf_sanity_check() - Sanity Check ELF firmware image +* rproc_elf_sanity_check() - Sanity Check ELF32 firmware image * @rproc: the remote processor handle * @fw: the ELF firmware image * * Make sure this fw image is sane. */ -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw) +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw) {const char *name = rproc->firmware;struct device *dev = &rproc->dev;@@ -89,7 +89,7 @@ int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)return 0 ; } -EXPORT_SYMBOL (rproc_elf_sanity_check); +EXPORT_SYMBOL (rproc_elf32_sanity_check);/** *
rproc_elf_get_boot_addr()- Get rproc's boot address.drivers/remoteproc/remoteproc_internal.h +1
-1@@ -54,7 +54,7 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len);phys_addr_t rproc_va_to_pa (void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc); -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw);u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw);drivers/remoteproc/st_remoteproc.c +1
-1@@ -233,7 +233,7 @@ static const struct rproc_ops st_rproc_ops = { .parse_fw = st_rproc_parse_fw, .load = rproc_elf_load_segments, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, };drivers/remoteproc/st_slim_rproc.c +1
-1@@ -203,7 +203,7 @@ static const struct rproc_ops slim_rproc_ops = { .da_to_va = slim_rproc_da_to_va, .get_boot_addr = rproc_elf_get_boot_addr, .load = rproc_elf_load_segments, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, };/** drivers/remoteproc/stm32_rproc.c +1
-2@@ -505,7 +505,7 @@ static struct rproc_ops st_rproc_ops = { .load = rproc_elf_load_segments, .parse_fw = stm32_rproc_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, }; --2.15.0.276.g89ea799
Mathieu Poirier
maintainerRe: [PATCH v5 5/8] remoteproc: Rename rproc_elf_sanity_check for elf32
Quoted 46 lines · Clément Leger
Hi Mathieu,
Quoted 41 lines · ----- On 10 Mar, 2020, at 16:20, Mathieu Poirier [email protected]…
Quoted 27 lines · Bjorn Andersson
Quoted 16 lines · Cl?ment Leger
Hi Bjorn,
----- On 3 Mar, 2020, at 00:13, Bjorn Andersson [email protected]
Quoted 10 lines · wrote:
Quoted 6 lines · Clement Leger
Since this function will be modified to support both elf32 and elf64, rename the existing one to elf32 (which is the only supported format at the moment). This will allow not to introduce possible side effect when adding elf64 support (ie: all backends will still support only elf32 if not requested explicitely using
rproc_elf_sanity_check).Is there a reason for preventing ELF64 binaries be loaded?
Quoted 8 lines
I decided to go this way to let driver maintainer decide if they want to support elf64 to avoid problems with 64bits addresses/sizes which do not fit in their native type (
size_tfor instance). This is probably not going to happen and there are additionnal checks before callingrproc_da_to_va. And addresses should be filtered byrproc_da_to_va. So, actually it seems there is no reason to forbid supporting elf32/64 for all drivers.Quoted 1 line
I was hoping to hear some additional feedback on this from others.
I didn't follow up on this one because I agreed with your assesment and didn't think it was needed.
Simply put I would rather see
rproc_elf_sanity_check()gain support for elf64 and let the platform code decide what to do with format they don't support rather than spinning a new function.Quoted 3 lines
I've merge the patch as is, but think it would be nice to clean this up and just have the driver ignore if fed a 32 or 64-elf.
Quoted 6 lines
Quoted 2 lines
It would be really nice to see this cleaned up in time for the coming merge window...
I could have sent a V7, but Bjorn was faster than my comment ;) Bjorn, Is there any way to revert that or it's already pushed ? I already have a clean V7.
Just send another patchset that applies on top of this one.
Quoted 134 lines
Thanks,
Clément
Quoted 129 lines
Thanks
MathieuQuoted 125 lines
Regards,
BjornQuoted 121 lines
Regards,
Clément
Quoted 117 lines
Regards,
BjornQuoted 113 lines
Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 2 +- drivers/remoteproc/remoteproc_elf_loader.c | 6 +++--- drivers/remoteproc/remoteproc_internal.h | 2 +- drivers/remoteproc/st_remoteproc.c | 2 +- drivers/remoteproc/st_slim_rproc.c | 2 +- drivers/remoteproc/stm32_rproc.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)drivers/remoteproc/remoteproc_core.c +1
-1@@ -2055,7 +2055,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->ops->load = rproc_elf_load_segments; rproc->ops->parse_fw = rproc_elf_load_rsc_table; rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; - rproc->ops->sanity_check = rproc_elf_sanity_check; + rproc->ops->sanity_check = rproc_elf32_sanity_check; rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; }drivers/remoteproc/remoteproc_elf_loader.c +3
-3@@ -25,13 +25,13 @@#include "remoteproc_internal.h" /** -* rproc_elf_sanity_check() - Sanity Check ELF firmware image +* rproc_elf_sanity_check() - Sanity Check ELF32 firmware image * @rproc: the remote processor handle * @fw: the ELF firmware image * * Make sure this fw image is sane. */ -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw) +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw) {const char *name = rproc->firmware;struct device *dev = &rproc->dev;@@ -89,7 +89,7 @@ int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)return 0 ; } -EXPORT_SYMBOL (rproc_elf_sanity_check); +EXPORT_SYMBOL (rproc_elf32_sanity_check);/** *
rproc_elf_get_boot_addr()- Get rproc's boot address.drivers/remoteproc/remoteproc_internal.h +1
-1@@ -54,7 +54,7 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len);phys_addr_t rproc_va_to_pa (void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc); -int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw); +int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw);u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw);drivers/remoteproc/st_remoteproc.c +1
-1@@ -233,7 +233,7 @@ static const struct rproc_ops st_rproc_ops = { .parse_fw = st_rproc_parse_fw, .load = rproc_elf_load_segments, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, };drivers/remoteproc/st_slim_rproc.c +1
-1@@ -203,7 +203,7 @@ static const struct rproc_ops slim_rproc_ops = { .da_to_va = slim_rproc_da_to_va, .get_boot_addr = rproc_elf_get_boot_addr, .load = rproc_elf_load_segments, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, };/** drivers/remoteproc/stm32_rproc.c +1
-2@@ -505,7 +505,7 @@ static struct rproc_ops st_rproc_ops = { .load = rproc_elf_load_segments, .parse_fw = stm32_rproc_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, - .sanity_check = rproc_elf_sanity_check, + .sanity_check = rproc_elf32_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, }; --2.15.0.276.g89ea799
Re: [PATCH v5 5/8] remoteproc: Rename rproc_elf_sanity_check for elf32
In reply to Clément LegerQuoted 42 lines · Cl?ment Leger
Hi Mathieu,
Quoted 38 lines · ----- On 10 Mar, 2020, at 16:20, Mathieu Poirier [email protected]…
Quoted 27 lines · Bjorn Andersson
Quoted 16 lines · Cl?ment Leger
Hi Bjorn,
----- On 3 Mar, 2020, at 00:13, Bjorn Andersson [email protected]
Quoted 10 lines · wrote:
Quoted 6 lines · Clement Leger
Since this function will be modified to support both elf32 and elf64, rename the existing one to elf32 (which is the only supported format at the moment). This will allow not to introduce possible side effect when adding elf64 support (ie: all backends will still support only elf32 if not requested explicitely using
rproc_elf_sanity_check).Is there a reason for preventing ELF64 binaries be loaded?
Quoted 8 lines
I decided to go this way to let driver maintainer decide if they want to support elf64 to avoid problems with 64bits addresses/sizes which do not fit in their native type (
size_tfor instance). This is probably not going to happen and there are additionnal checks before callingrproc_da_to_va. And addresses should be filtered byrproc_da_to_va. So, actually it seems there is no reason to forbid supporting elf32/64 for all drivers.Quoted 1 line
I was hoping to hear some additional feedback on this from others.
I didn't follow up on this one because I agreed with your assesment and didn't think it was needed.
Simply put I would rather see
rproc_elf_sanity_check()gain support for elf64 and let the platform code decide what to do with format they don't support rather than spinning a new function.Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
I've merge the patch as is, but think it would be nice to clean this up and just have the driver ignore if fed a 32 or 64-elf.
It would be really nice to see this cleaned up in time for the coming merge window...
I could have sent a V7, but Bjorn was faster than my comment ;)
I figured it had been maturing on the list long enough and expected the cleanup to be a nice incremental patch.
Quoted 3 lines
Bjorn, Is there any way to revert that or it's already pushed ? I already have a clean V7.
Please base your changes on what's in rproc-next (and today's linux-next).
Thank you,
Bjorn
PATCH v5 6/8 remoteproc: Add elf64 support in elf loader
In reply to Clement LegerIn order to support elf64, use macros from remoteproc_elf_helpers.h to access elf headers depending on elf class.
To allow new drivers to support elf64, add rproc_elf_sanity_check function which make more sense than adding a elf64 named one since it will support both elf versions.
Driver which need to support both elf32/elf64 should use this new function for elf sanity check instead of the elf32 one.
--- Documentation/remoteproc.txt | 2 +- drivers/remoteproc/remoteproc_elf_loader.c | 186 ++++++++++++++++++++--------- drivers/remoteproc/remoteproc_internal.h | 10 ++ 3 files changed, 141 insertions(+), 57 deletions(-)
Documentation/remoteproc.txt +1 -1
@@ -230,7 +230,7 @@ in the used rings. Binary Firmware Structure ========================= -At this point remoteproc only supports ELF32 firmware binaries. However, +At this point remoteproc supports ELF32 and ELF64 firmware binaries. However, it is quite expected that other platforms/devices which we'd want to support with this framework will be based on different binary formats.
drivers/remoteproc/remoteproc_elf_loader.c +130 -56
311 lines not on this page · raw message
drivers/remoteproc/remoteproc_internal.h +10 -0
@@ -55,6 +55,7 @@ phys_addr_t rproc_va_to_pa(void *cpu_addr);int rproc_trigger_recovery (struct rproc *rproc);int rproc_elf32_sanity_check (struct rproc *rproc,const struct firmware *fw); +int rproc_elf_sanity_check (struct rproc *rproc,const struct firmware *fw);u64 rproc_elf_get_boot_addr (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_segments (struct rproc *rproc,const struct firmware *fw);int rproc_elf_load_rsc_table (struct rproc *rproc,const struct firmware *fw);
@@ -119,4 +120,13 @@ struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc, return NULL; } +static inline +bool rproc_u64_fit_in_size_t (u64 val) +{ +if (sizeof (size_t ) ==sizeof (u64)) +return true; + +return (val <= (size_t )-1 ); +} +#endif /* REMOTEPROC_INTERNAL_H */
Signature · 1 line
2.15.0.276.g89ea799
PATCH v5 7/8 remoteproc: Allow overriding only sanity_check
In reply to Clement LegerNow that rproc_elf_sanity_check can be used by external drivers, allow to only overwrite the sanity_check member of rproc_ops. This will allow drivers to handle elf32 and elf64 by overwriting sanity_check with rproc_elf_sanity_check function.
--- drivers/remoteproc/remoteproc_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +2 -1
@@ -2055,7 +2055,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->ops->load = rproc_elf_load_segments; rproc->ops->parse_fw = rproc_elf_load_rsc_table; rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; - rproc->ops->sanity_check = rproc_elf32_sanity_check; +if (!rproc->ops->sanity_check) + rproc->ops->sanity_check = rproc_elf32_sanity_check; rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; }
Signature · 1 line
2.15.0.276.g89ea799
PATCH v5 8/8 remoteproc: Adapt coredump to generate correct elf type
In reply to Clement LegerNow that remoteproc can load an elf64, coredump elf class should be the same as the loaded elf class. In order to do that, add a elf_class field to rproc with default values. If an elf is loaded successfully, this field will be updated with the loaded elf class. Then, the coredump core code has been modified to use the generic elf macro in order to create an elf file with correct class.
--- drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++-------------- drivers/remoteproc/remoteproc_elf_loader.c | 3 ++ include/linux/remoteproc.h | 1 + 3 files changed, 39 insertions(+), 32 deletions(-)
drivers/remoteproc/remoteproc_core.c +35 -32
@@ -38,6 +38,7 @@#include <linux/platform_device.h> #include "remoteproc_internal.h" +#include "remoteproc_elf_helpers.h" #define HIGH_BITS_MASK 0xFFFFFFFF00000000ULL
@@ -1566,20 +1567,21 @@ EXPORT_SYMBOL(rproc_coredump_add_custom_segment);static void rproc_coredump (struct rproc *rproc) {struct rproc_dump_segment *segment; -struct elf32_phdr *phdr; -struct elf32_hdr *ehdr; +void *phdr; +void *ehdr;size_t data_size;size_t offset;void *data;void *ptr; +u8 class = rproc->elf_class;int phnum =0 ;if (list_empty (&rproc->dump_segments))return ; - data_size =sizeof (*ehdr); + data_size =elf_size_of_hdr (class);list_for_each_entry (segment, &rproc->dump_segments, node) { - data_size +=sizeof (*phdr) + segment->size; + data_size +=elf_size_of_phdr (class) + segment->size; phnum++; }
@@ -1590,33 +1592,33 @@ static void rproc_coredump(struct rproc *rproc) ehdr = data; -memset (ehdr,0 ,sizeof (*ehdr)); -memcpy (ehdr->e_ident,ELFMAG ,SELFMAG ); - ehdr->e_ident[EI_CLASS ] =ELFCLASS32 ; - ehdr->e_ident[EI_DATA ] =ELFDATA2LSB ; - ehdr->e_ident[EI_VERSION ] =EV_CURRENT ; - ehdr->e_ident[EI_OSABI ] =ELFOSABI_NONE ; - ehdr->e_type =ET_CORE ; - ehdr->e_machine =EM_NONE ; - ehdr->e_version =EV_CURRENT ; - ehdr->e_entry = rproc->bootaddr; - ehdr->e_phoff =sizeof (*ehdr); - ehdr->e_ehsize =sizeof (*ehdr); - ehdr->e_phentsize =sizeof (*phdr); - ehdr->e_phnum = phnum; - - phdr = data + ehdr->e_phoff; - offset = ehdr->e_phoff +sizeof (*phdr) * ehdr->e_phnum; +memset (ehdr,0 ,elf_size_of_hdr (class)); +/* e_ident field is common for both elf32 and elf64 */ +elf_hdr_init_ident (ehdr, class); + +elf_hdr_set_e_type (class, ehdr,ET_CORE ); +elf_hdr_set_e_machine (class, ehdr,EM_NONE ); +elf_hdr_set_e_version (class, ehdr,EV_CURRENT ); +elf_hdr_set_e_entry (class, ehdr, rproc->bootaddr); +elf_hdr_set_e_phoff (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_ehsize (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_phentsize (class, ehdr,elf_size_of_phdr (class)); +elf_hdr_set_e_phnum (class, ehdr, phnum); + + phdr = data +elf_hdr_get_e_phoff (class, ehdr); + offset =elf_hdr_get_e_phoff (class, ehdr); + offset +=elf_size_of_phdr (class) *elf_hdr_get_e_phnum (class, ehdr); +list_for_each_entry (segment, &rproc->dump_segments, node) { -memset (phdr,0 ,sizeof (*phdr)); - phdr->p_type =PT_LOAD ; - phdr->p_offset = offset; - phdr->p_vaddr = segment->da; - phdr->p_paddr = segment->da; - phdr->p_filesz = segment->size; - phdr->p_memsz = segment->size; - phdr->p_flags =PF_R |PF_W |PF_X ; - phdr->p_align =0 ; +memset (phdr,0 ,elf_size_of_phdr (class)); +elf_phdr_set_p_type (class, phdr,PT_LOAD ); +elf_phdr_set_p_offset (class, phdr, offset); +elf_phdr_set_p_vaddr (class, phdr, segment->da); +elf_phdr_set_p_paddr (class, phdr, segment->da); +elf_phdr_set_p_filesz (class, phdr, segment->size); +elf_phdr_set_p_memsz (class, phdr, segment->size); +elf_phdr_set_p_flags (class, phdr,PF_R |PF_W |PF_X ); +elf_phdr_set_p_align (class, phdr,0 );if (segment->dump) { segment->dump (rproc, segment, data + offset);
@@ -1632,8 +1634,8 @@ static void rproc_coredump(struct rproc *rproc) } } - offset += phdr->p_filesz; - phdr++; + offset +=elf_phdr_get_p_filesz (class, phdr); + phdr +=elf_size_of_phdr (class); }dev_coredumpv (&rproc->dev, data, data_size,GFP_KERNEL );
@@ -2031,6 +2033,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->name = name; rproc->priv = &rproc[1 ]; rproc->auto_boot = true; + rproc->elf_class =ELFCLASS32 ;device_initialize (&rproc->dev); rproc->dev.parent = dev;
drivers/remoteproc/remoteproc_elf_loader.c +3 -0
@@ -248,6 +248,9 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)memset (ptr + filesz,0 , memsz - filesz); } +if (ret ==0 ) + rproc->elf_class = class; +return ret; }EXPORT_SYMBOL (rproc_elf_load_segments);
include/linux/remoteproc.h +1 -0
@@ -514,6 +514,7 @@ struct rproc {bool auto_boot;struct list_head dump_segments;int nb_vdev; +u8 elf_class; };/**
Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 8/8] remoteproc: Adapt coredump to generate correct elf type
Quoted 8 lines · Clement Leger
Now that remoteproc can load an elf64, coredump elf class should be the same as the loaded elf class. In order to do that, add a
elf_classfield to rproc with default values. If an elf is loaded successfully, this field will be updated with the loaded elf class. Then, the coredump core code has been modified to use the generic elf macro in order to create an elf file with correct class.Signed-off-by Clement Leger <[email protected]>
Quoted 152 lines
--- drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++-------------- drivers/remoteproc/remoteproc_elf_loader.c | 3 ++ include/linux/remoteproc.h | 1 + 3 files changed, 39 insertions(+), 32 deletions(-)drivers/remoteproc/remoteproc_core.c +35
-32@@ -38,6 +38,7 @@#include <linux/platform_device.h> #include "remoteproc_internal.h" +#include "remoteproc_elf_helpers.h" #define HIGH_BITS_MASK 0xFFFFFFFF00000000ULL@@ -1566,20 +1567,21 @@ EXPORT_SYMBOL(rproc_coredump_add_custom_segment);static void rproc_coredump (struct rproc *rproc) {struct rproc_dump_segment *segment; -struct elf32_phdr *phdr; -struct elf32_hdr *ehdr; +void *phdr; +void *ehdr;size_t data_size;size_t offset;void *data;void *ptr; +u8 class = rproc->elf_class;int phnum =0 ;if (list_empty (&rproc->dump_segments))return ; - data_size =sizeof (*ehdr); + data_size =elf_size_of_hdr (class);list_for_each_entry (segment, &rproc->dump_segments, node) { - data_size +=sizeof (*phdr) + segment->size; + data_size +=elf_size_of_phdr (class) + segment->size; phnum++; }@@ -1590,33 +1592,33 @@ static void rproc_coredump(struct rproc *rproc) ehdr = data; -memset (ehdr,0 ,sizeof (*ehdr)); -memcpy (ehdr->e_ident,ELFMAG ,SELFMAG ); - ehdr->e_ident[EI_CLASS ] =ELFCLASS32 ; - ehdr->e_ident[EI_DATA ] =ELFDATA2LSB ; - ehdr->e_ident[EI_VERSION ] =EV_CURRENT ; - ehdr->e_ident[EI_OSABI ] =ELFOSABI_NONE ; - ehdr->e_type =ET_CORE ; - ehdr->e_machine =EM_NONE ; - ehdr->e_version =EV_CURRENT ; - ehdr->e_entry = rproc->bootaddr; - ehdr->e_phoff =sizeof (*ehdr); - ehdr->e_ehsize =sizeof (*ehdr); - ehdr->e_phentsize =sizeof (*phdr); - ehdr->e_phnum = phnum; - - phdr = data + ehdr->e_phoff; - offset = ehdr->e_phoff +sizeof (*phdr) * ehdr->e_phnum; +memset (ehdr,0 ,elf_size_of_hdr (class)); +/* e_ident field is common for both elf32 and elf64 */ +elf_hdr_init_ident (ehdr, class); + +elf_hdr_set_e_type (class, ehdr,ET_CORE ); +elf_hdr_set_e_machine (class, ehdr,EM_NONE ); +elf_hdr_set_e_version (class, ehdr,EV_CURRENT ); +elf_hdr_set_e_entry (class, ehdr, rproc->bootaddr); +elf_hdr_set_e_phoff (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_ehsize (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_phentsize (class, ehdr,elf_size_of_phdr (class)); +elf_hdr_set_e_phnum (class, ehdr, phnum); + + phdr = data +elf_hdr_get_e_phoff (class, ehdr); + offset =elf_hdr_get_e_phoff (class, ehdr); + offset +=elf_size_of_phdr (class) *elf_hdr_get_e_phnum (class, ehdr); +list_for_each_entry (segment, &rproc->dump_segments, node) { -memset (phdr,0 ,sizeof (*phdr)); - phdr->p_type =PT_LOAD ; - phdr->p_offset = offset; - phdr->p_vaddr = segment->da; - phdr->p_paddr = segment->da; - phdr->p_filesz = segment->size; - phdr->p_memsz = segment->size; - phdr->p_flags =PF_R |PF_W |PF_X ; - phdr->p_align =0 ; +memset (phdr,0 ,elf_size_of_phdr (class)); +elf_phdr_set_p_type (class, phdr,PT_LOAD ); +elf_phdr_set_p_offset (class, phdr, offset); +elf_phdr_set_p_vaddr (class, phdr, segment->da); +elf_phdr_set_p_paddr (class, phdr, segment->da); +elf_phdr_set_p_filesz (class, phdr, segment->size); +elf_phdr_set_p_memsz (class, phdr, segment->size); +elf_phdr_set_p_flags (class, phdr,PF_R |PF_W |PF_X ); +elf_phdr_set_p_align (class, phdr,0 );if (segment->dump) { segment->dump (rproc, segment, data + offset);@@ -1632,8 +1634,8 @@ static void rproc_coredump(struct rproc *rproc) } } - offset += phdr->p_filesz; - phdr++; + offset +=elf_phdr_get_p_filesz (class, phdr); + phdr +=elf_size_of_phdr (class); }dev_coredumpv (&rproc->dev, data, data_size,GFP_KERNEL );@@ -2031,6 +2033,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->name = name; rproc->priv = &rproc[1 ]; rproc->auto_boot = true; + rproc->elf_class =ELFCLASS32 ;device_initialize (&rproc->dev); rproc->dev.parent = dev;drivers/remoteproc/remoteproc_elf_loader.c +3
-0@@ -248,6 +248,9 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)memset (ptr + filesz,0 , memsz - filesz); } +if (ret ==0 ) + rproc->elf_class = class; +return ret; }EXPORT_SYMBOL (rproc_elf_load_segments);include/linux/remoteproc.h +1
-0@@ -514,6 +514,7 @@ struct rproc {bool auto_boot;struct list_head dump_segments;int nb_vdev; +u8 elf_class; };/** Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 8/8] remoteproc: Adapt coredump to generate correct elf type
In reply to Clement LegerQuoted 124 lines · Clement Leger
Now that remoteproc can load an elf64, coredump elf class should be the same as the loaded elf class. In order to do that, add a
elf_classfield to rproc with default values. If an elf is loaded successfully, this field will be updated with the loaded elf class. Then, the coredump core code has been modified to use the generic elf macro in order to create an elf file with correct class.Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++-------------- drivers/remoteproc/remoteproc_elf_loader.c | 3 ++ include/linux/remoteproc.h | 1 + 3 files changed, 39 insertions(+), 32 deletions(-)drivers/remoteproc/remoteproc_core.c +34
-32@@ -38,6 +38,7 @@#include <linux/platform_device.h> #include "remoteproc_internal.h" +#include "remoteproc_elf_helpers.h" #define HIGH_BITS_MASK 0xFFFFFFFF00000000ULL@@ -1566,20 +1567,21 @@ EXPORT_SYMBOL(rproc_coredump_add_custom_segment);static void rproc_coredump (struct rproc *rproc) {struct rproc_dump_segment *segment; -struct elf32_phdr *phdr; -struct elf32_hdr *ehdr; +void *phdr; +void *ehdr;size_t data_size;size_t offset;void *data;void *ptr; +u8 class = rproc->elf_class;int phnum =0 ;if (list_empty (&rproc->dump_segments))return ; - data_size =sizeof (*ehdr); + data_size =elf_size_of_hdr (class);list_for_each_entry (segment, &rproc->dump_segments, node) { - data_size +=sizeof (*phdr) + segment->size; + data_size +=elf_size_of_phdr (class) + segment->size; phnum++; }@@ -1590,33 +1592,33 @@ static void rproc_coredump(struct rproc *rproc) ehdr = data; -memset (ehdr,0 ,sizeof (*ehdr)); -memcpy (ehdr->e_ident,ELFMAG ,SELFMAG ); - ehdr->e_ident[EI_CLASS ] =ELFCLASS32 ; - ehdr->e_ident[EI_DATA ] =ELFDATA2LSB ; - ehdr->e_ident[EI_VERSION ] =EV_CURRENT ; - ehdr->e_ident[EI_OSABI ] =ELFOSABI_NONE ; - ehdr->e_type =ET_CORE ; - ehdr->e_machine =EM_NONE ; - ehdr->e_version =EV_CURRENT ; - ehdr->e_entry = rproc->bootaddr; - ehdr->e_phoff =sizeof (*ehdr); - ehdr->e_ehsize =sizeof (*ehdr); - ehdr->e_phentsize =sizeof (*phdr); - ehdr->e_phnum = phnum; - - phdr = data + ehdr->e_phoff; - offset = ehdr->e_phoff +sizeof (*phdr) * ehdr->e_phnum; +memset (ehdr,0 ,elf_size_of_hdr (class)); +/* e_ident field is common for both elf32 and elf64 */ +elf_hdr_init_ident (ehdr, class); + +elf_hdr_set_e_type (class, ehdr,ET_CORE ); +elf_hdr_set_e_machine (class, ehdr,EM_NONE ); +elf_hdr_set_e_version (class, ehdr,EV_CURRENT ); +elf_hdr_set_e_entry (class, ehdr, rproc->bootaddr); +elf_hdr_set_e_phoff (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_ehsize (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_phentsize (class, ehdr,elf_size_of_phdr (class)); +elf_hdr_set_e_phnum (class, ehdr, phnum); + + phdr = data +elf_hdr_get_e_phoff (class, ehdr); + offset =elf_hdr_get_e_phoff (class, ehdr); + offset +=elf_size_of_phdr (class) *elf_hdr_get_e_phnum (class, ehdr); +list_for_each_entry (segment, &rproc->dump_segments, node) { -memset (phdr,0 ,sizeof (*phdr)); - phdr->p_type =PT_LOAD ; - phdr->p_offset = offset; - phdr->p_vaddr = segment->da; - phdr->p_paddr = segment->da; - phdr->p_filesz = segment->size; - phdr->p_memsz = segment->size; - phdr->p_flags =PF_R |PF_W |PF_X ; - phdr->p_align =0 ; +memset (phdr,0 ,elf_size_of_phdr (class)); +elf_phdr_set_p_type (class, phdr,PT_LOAD ); +elf_phdr_set_p_offset (class, phdr, offset); +elf_phdr_set_p_vaddr (class, phdr, segment->da); +elf_phdr_set_p_paddr (class, phdr, segment->da); +elf_phdr_set_p_filesz (class, phdr, segment->size); +elf_phdr_set_p_memsz (class, phdr, segment->size); +elf_phdr_set_p_flags (class, phdr,PF_R |PF_W |PF_X ); +elf_phdr_set_p_align (class, phdr,0 );if (segment->dump) { segment->dump (rproc, segment, data + offset);@@ -1632,8 +1634,8 @@ static void rproc_coredump(struct rproc *rproc) } } - offset += phdr->p_filesz; - phdr++; + offset +=elf_phdr_get_p_filesz (class, phdr); + phdr +=elf_size_of_phdr (class); }dev_coredumpv (&rproc->dev, data, data_size,GFP_KERNEL );
drivers/remoteproc/remoteproc_core.c struct rproc *rproc_alloc(struct device *dev, const char *name, · line 2036
Quoted 4 lines
drivers/remoteproc/remoteproc_core.c +1
-0@@ -2031,6 +2033,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->name = name; rproc->priv = &rproc[1 ]; rproc->auto_boot = true; + rproc->elf_class =ELFCLASS32 ;
I would initialise this to ELFCLASSNONE to make sure that if a platform driver overwrites rproc_elf_load_segments or doesn't provide one, we don't falsely deduce the elf type. It goes without saying that if elf_class == ELFCLASSNONE, a coredump is not generated.
Unless you think this is a seriously bad idea or Bjorn over rules me,
Thanks,
Mathieu
Quoted 32 lines
drivers/remoteproc/remoteproc_core.c +0
-0device_initialize (&rproc->dev); rproc->dev.parent = dev;drivers/remoteproc/remoteproc_elf_loader.c +3
-0@@ -248,6 +248,9 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)memset (ptr + filesz,0 , memsz - filesz); } +if (ret ==0 ) + rproc->elf_class = class; +return ret; }EXPORT_SYMBOL (rproc_elf_load_segments);include/linux/remoteproc.h +1
-0@@ -514,6 +514,7 @@ struct rproc {bool auto_boot;struct list_head dump_segments;int nb_vdev; +u8 elf_class; };/** Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 8/8] remoteproc: Adapt coredump to generate correct elf type
Quoted 123 lines · Mathieu Poirier
Quoted 122 lines · Clement Leger
Now that remoteproc can load an elf64, coredump elf class should be the same as the loaded elf class. In order to do that, add a
elf_classfield to rproc with default values. If an elf is loaded successfully, this field will be updated with the loaded elf class. Then, the coredump core code has been modified to use the generic elf macro in order to create an elf file with correct class.Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++-------------- drivers/remoteproc/remoteproc_elf_loader.c | 3 ++ include/linux/remoteproc.h | 1 + 3 files changed, 39 insertions(+), 32 deletions(-)drivers/remoteproc/remoteproc_core.c +34
-32@@ -38,6 +38,7 @@#include <linux/platform_device.h> #include "remoteproc_internal.h" +#include "remoteproc_elf_helpers.h" #define HIGH_BITS_MASK 0xFFFFFFFF00000000ULL@@ -1566,20 +1567,21 @@ EXPORT_SYMBOL(rproc_coredump_add_custom_segment);static void rproc_coredump (struct rproc *rproc) {struct rproc_dump_segment *segment; -struct elf32_phdr *phdr; -struct elf32_hdr *ehdr; +void *phdr; +void *ehdr;size_t data_size;size_t offset;void *data;void *ptr; +u8 class = rproc->elf_class;int phnum =0 ;if (list_empty (&rproc->dump_segments))return ; - data_size =sizeof (*ehdr); + data_size =elf_size_of_hdr (class);list_for_each_entry (segment, &rproc->dump_segments, node) { - data_size +=sizeof (*phdr) + segment->size; + data_size +=elf_size_of_phdr (class) + segment->size; phnum++; }@@ -1590,33 +1592,33 @@ static void rproc_coredump(struct rproc *rproc) ehdr = data; -memset (ehdr,0 ,sizeof (*ehdr)); -memcpy (ehdr->e_ident,ELFMAG ,SELFMAG ); - ehdr->e_ident[EI_CLASS ] =ELFCLASS32 ; - ehdr->e_ident[EI_DATA ] =ELFDATA2LSB ; - ehdr->e_ident[EI_VERSION ] =EV_CURRENT ; - ehdr->e_ident[EI_OSABI ] =ELFOSABI_NONE ; - ehdr->e_type =ET_CORE ; - ehdr->e_machine =EM_NONE ; - ehdr->e_version =EV_CURRENT ; - ehdr->e_entry = rproc->bootaddr; - ehdr->e_phoff =sizeof (*ehdr); - ehdr->e_ehsize =sizeof (*ehdr); - ehdr->e_phentsize =sizeof (*phdr); - ehdr->e_phnum = phnum; - - phdr = data + ehdr->e_phoff; - offset = ehdr->e_phoff +sizeof (*phdr) * ehdr->e_phnum; +memset (ehdr,0 ,elf_size_of_hdr (class)); +/* e_ident field is common for both elf32 and elf64 */ +elf_hdr_init_ident (ehdr, class); + +elf_hdr_set_e_type (class, ehdr,ET_CORE ); +elf_hdr_set_e_machine (class, ehdr,EM_NONE ); +elf_hdr_set_e_version (class, ehdr,EV_CURRENT ); +elf_hdr_set_e_entry (class, ehdr, rproc->bootaddr); +elf_hdr_set_e_phoff (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_ehsize (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_phentsize (class, ehdr,elf_size_of_phdr (class)); +elf_hdr_set_e_phnum (class, ehdr, phnum); + + phdr = data +elf_hdr_get_e_phoff (class, ehdr); + offset =elf_hdr_get_e_phoff (class, ehdr); + offset +=elf_size_of_phdr (class) *elf_hdr_get_e_phnum (class, ehdr); +list_for_each_entry (segment, &rproc->dump_segments, node) { -memset (phdr,0 ,sizeof (*phdr)); - phdr->p_type =PT_LOAD ; - phdr->p_offset = offset; - phdr->p_vaddr = segment->da; - phdr->p_paddr = segment->da; - phdr->p_filesz = segment->size; - phdr->p_memsz = segment->size; - phdr->p_flags =PF_R |PF_W |PF_X ; - phdr->p_align =0 ; +memset (phdr,0 ,elf_size_of_phdr (class)); +elf_phdr_set_p_type (class, phdr,PT_LOAD ); +elf_phdr_set_p_offset (class, phdr, offset); +elf_phdr_set_p_vaddr (class, phdr, segment->da); +elf_phdr_set_p_paddr (class, phdr, segment->da); +elf_phdr_set_p_filesz (class, phdr, segment->size); +elf_phdr_set_p_memsz (class, phdr, segment->size); +elf_phdr_set_p_flags (class, phdr,PF_R |PF_W |PF_X ); +elf_phdr_set_p_align (class, phdr,0 );if (segment->dump) { segment->dump (rproc, segment, data + offset);@@ -1632,8 +1634,8 @@ static void rproc_coredump(struct rproc *rproc) } } - offset += phdr->p_filesz; - phdr++; + offset +=elf_phdr_get_p_filesz (class, phdr); + phdr +=elf_size_of_phdr (class); }
Quoted 12 lines
drivers/remoteproc/remoteproc_core.c struct rproc *rproc_alloc(struct device *dev, const char *name, · line 2036
Quoted 6 lines
drivers/remoteproc/remoteproc_core.c +1
-0dev_coredumpv (&rproc->dev, data, data_size,GFP_KERNEL );@@ -2031,6 +2033,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->name = name; rproc->priv = &rproc[1 ]; rproc->auto_boot = true; + rproc->elf_class =ELFCLASS32 ;I would initialise this to ELFCLASSNONE to make sure that if a platform driver overwrites
rproc_elf_load_segmentsor doesn't provide one, we don't falsely deduce the elf type. It goes without saying that ifelf_class== ELFCLASSNONE, a coredump is not generated.
I like the idea of making the choice explicit, perhaps even more explicit than the assumption that the coredumps should be of the same type as the ELF loaded. Note that it's different consumers of the two ELF files.
Quoted 4 lines
Unless you think this is a seriously bad idea or Bjorn over rules me,
Reviewed-by Mathieu Poirier <[email protected]>
Not sure if it count as "over ruling", I accept your suggestion but used your R-b to merge the patch as is, no need to hold this up any longer.
Clement, can you please follow up with a patch implementing this (don't forget that the qcom drivers doesn't use rproc_elf_load_segments())
Thanks Clement and thanks for the reviews Mathieu.
Regards,
Bjorn
Quoted 35 lines
Thanks,
MathieuQuoted 32 lines
drivers/remoteproc/remoteproc_core.c +0
-0device_initialize (&rproc->dev); rproc->dev.parent = dev;drivers/remoteproc/remoteproc_elf_loader.c +3
-0@@ -248,6 +248,9 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)memset (ptr + filesz,0 , memsz - filesz); } +if (ret ==0 ) + rproc->elf_class = class; +return ret; }EXPORT_SYMBOL (rproc_elf_load_segments);include/linux/remoteproc.h +1
-0@@ -514,6 +514,7 @@ struct rproc {bool auto_boot;struct list_head dump_segments;int nb_vdev; +u8 elf_class; };/** Signature · 1 line
2.15.0.276.g89ea799
Re: [PATCH v5 8/8] remoteproc: Adapt coredump to generate correct elf type
Hi Bjorn,
Quoted 140 lines · ----- On 10 Mar, 2020, at 00:57, Bjorn Andersson [email protected]…
Quoted 124 lines · Mathieu Poirier
Quoted 123 lines · Clement Leger
Now that remoteproc can load an elf64, coredump elf class should be the same as the loaded elf class. In order to do that, add a
elf_classfield to rproc with default values. If an elf is loaded successfully, this field will be updated with the loaded elf class. Then, the coredump core code has been modified to use the generic elf macro in order to create an elf file with correct class.Signed-off-by Clement Leger <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++-------------- drivers/remoteproc/remoteproc_elf_loader.c | 3 ++ include/linux/remoteproc.h | 1 + 3 files changed, 39 insertions(+), 32 deletions(-)drivers/remoteproc/remoteproc_core.c +34
-32@@ -38,6 +38,7 @@#include <linux/platform_device.h> #include "remoteproc_internal.h" +#include "remoteproc_elf_helpers.h" #define HIGH_BITS_MASK 0xFFFFFFFF00000000ULL@@ -1566,20 +1567,21 @@ EXPORT_SYMBOL(rproc_coredump_add_custom_segment);static void rproc_coredump (struct rproc *rproc) {struct rproc_dump_segment *segment; -struct elf32_phdr *phdr; -struct elf32_hdr *ehdr; +void *phdr; +void *ehdr;size_t data_size;size_t offset;void *data;void *ptr; +u8 class = rproc->elf_class;int phnum =0 ;if (list_empty (&rproc->dump_segments))return ; - data_size =sizeof (*ehdr); + data_size =elf_size_of_hdr (class);list_for_each_entry (segment, &rproc->dump_segments, node) { - data_size +=sizeof (*phdr) + segment->size; + data_size +=elf_size_of_phdr (class) + segment->size; phnum++; }@@ -1590,33 +1592,33 @@ static void rproc_coredump(struct rproc *rproc) ehdr = data; -memset (ehdr,0 ,sizeof (*ehdr)); -memcpy (ehdr->e_ident,ELFMAG ,SELFMAG ); - ehdr->e_ident[EI_CLASS ] =ELFCLASS32 ; - ehdr->e_ident[EI_DATA ] =ELFDATA2LSB ; - ehdr->e_ident[EI_VERSION ] =EV_CURRENT ; - ehdr->e_ident[EI_OSABI ] =ELFOSABI_NONE ; - ehdr->e_type =ET_CORE ; - ehdr->e_machine =EM_NONE ; - ehdr->e_version =EV_CURRENT ; - ehdr->e_entry = rproc->bootaddr; - ehdr->e_phoff =sizeof (*ehdr); - ehdr->e_ehsize =sizeof (*ehdr); - ehdr->e_phentsize =sizeof (*phdr); - ehdr->e_phnum = phnum; - - phdr = data + ehdr->e_phoff; - offset = ehdr->e_phoff +sizeof (*phdr) * ehdr->e_phnum; +memset (ehdr,0 ,elf_size_of_hdr (class)); +/* e_ident field is common for both elf32 and elf64 */ +elf_hdr_init_ident (ehdr, class); + +elf_hdr_set_e_type (class, ehdr,ET_CORE ); +elf_hdr_set_e_machine (class, ehdr,EM_NONE ); +elf_hdr_set_e_version (class, ehdr,EV_CURRENT ); +elf_hdr_set_e_entry (class, ehdr, rproc->bootaddr); +elf_hdr_set_e_phoff (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_ehsize (class, ehdr,elf_size_of_hdr (class)); +elf_hdr_set_e_phentsize (class, ehdr,elf_size_of_phdr (class)); +elf_hdr_set_e_phnum (class, ehdr, phnum); + + phdr = data +elf_hdr_get_e_phoff (class, ehdr); + offset =elf_hdr_get_e_phoff (class, ehdr); + offset +=elf_size_of_phdr (class) *elf_hdr_get_e_phnum (class, ehdr); +list_for_each_entry (segment, &rproc->dump_segments, node) { -memset (phdr,0 ,sizeof (*phdr)); - phdr->p_type =PT_LOAD ; - phdr->p_offset = offset; - phdr->p_vaddr = segment->da; - phdr->p_paddr = segment->da; - phdr->p_filesz = segment->size; - phdr->p_memsz = segment->size; - phdr->p_flags =PF_R |PF_W |PF_X ; - phdr->p_align =0 ; +memset (phdr,0 ,elf_size_of_phdr (class)); +elf_phdr_set_p_type (class, phdr,PT_LOAD ); +elf_phdr_set_p_offset (class, phdr, offset); +elf_phdr_set_p_vaddr (class, phdr, segment->da); +elf_phdr_set_p_paddr (class, phdr, segment->da); +elf_phdr_set_p_filesz (class, phdr, segment->size); +elf_phdr_set_p_memsz (class, phdr, segment->size); +elf_phdr_set_p_flags (class, phdr,PF_R |PF_W |PF_X ); +elf_phdr_set_p_align (class, phdr,0 );if (segment->dump) { segment->dump (rproc, segment, data + offset);@@ -1632,8 +1634,8 @@ static void rproc_coredump(struct rproc *rproc) } } - offset += phdr->p_filesz; - phdr++; + offset +=elf_phdr_get_p_filesz (class, phdr); + phdr +=elf_size_of_phdr (class); }Quoted 13 lines
drivers/remoteproc/remoteproc_core.c struct rproc *rproc_alloc(struct device *dev, const char · line 2037
Quoted 7 lines
drivers/remoteproc/remoteproc_core.c +1
-0dev_coredumpv (&rproc->dev, data, data_size,GFP_KERNEL );@@ -2031,6 +2033,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->name = name; rproc->priv = &rproc[1 ]; rproc->auto_boot = true; + rproc->elf_class =ELFCLASS32 ;I would initialise this to ELFCLASSNONE to make sure that if a platform driver overwrites
rproc_elf_load_segmentsor doesn't provide one, we don't falsely deduce the elf type. It goes without saying that ifelf_class== ELFCLASSNONE, a coredump is not generated.
Quoted 6 lines
I like the idea of making the choice explicit, perhaps even more explicit than the assumption that the coredumps should be of the same type as the ELF loaded. Note that it's different consumers of the two ELF files.
Quoted 1 line
Unless you think this is a seriously bad idea or Bjorn over rules me,
Ok, I tried to do the equivalent of what was existing (ie elf32 by default). But IMHO, letting the driver choose the elf type is a better idea.
Quoted 9 lines
Quoted 3 lines
Reviewed-by Mathieu Poirier <[email protected]>Not sure if it count as "over ruling", I accept your suggestion but used your R-b to merge the patch as is, no need to hold this up any longer.
Clement, can you please follow up with a patch implementing this (don't forget that the qcom drivers doesn't use
rproc_elf_load_segments())
I was going to send a v7, please tell me if you want to hold it a bit more. If not, I will address the remaining comments in next commits.
Quoted 42 lines
Thanks Clement and thanks for the reviews Mathieu.
Regards,
BjornQuoted 36 lines
Thanks,
MathieuQuoted 33 lines
drivers/remoteproc/remoteproc_core.c +0
-0device_initialize (&rproc->dev); rproc->dev.parent = dev;drivers/remoteproc/remoteproc_elf_loader.c +3
-0@@ -248,6 +248,9 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw) memset(ptr + filesz, 0, memsz - filesz); } +if (ret ==0 ) + rproc->elf_class = class; +return ret; }
EXPORT_SYMBOL(rproc_elf_load_segments);include/linux/remoteproc.h +1
-1@@ -514,6 +514,7 @@ struct rproc {bool auto_boot;struct list_head dump_segments;int nb_vdev; +u8 elf_class; };/** -- 2.15.0.276.g89ea799