mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master] remoteproc: use I/O memory variants of memcpy/memset
@ 2024-11-15 13:52 Ahmad Fatoum
  2024-11-15 14:03 ` Ahmad Fatoum
  2024-11-25  9:38 ` Sascha Hauer
  0 siblings, 2 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-11-15 13:52 UTC (permalink / raw)
  To: barebox; +Cc: Stefano Manni, Ahmad Fatoum

Reserved memory is unmapped strongly ordered in barebox and calling
normal optimized memcpy on may trigger an abort due to misalignment.

Fix this by using the slower I/O variants of memcpy/memset, which are
do not expect bufferable memory like the optimized variants and thus
don't cause unaligned accesses.

Fixes: 66e233b8c04b ("ARM: mmu64: map reserved regions uncached")
Reported-by: Stefano Manni <stefano.manni@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/remoteproc/remoteproc_core.c       | 2 +-
 drivers/remoteproc/remoteproc_elf_loader.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 7590c1f9305b..17159316ee31 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -75,7 +75,7 @@ static int rproc_firmware_write_buf(struct firmware_handler *fh, const void *buf
 		return -ENOMEM;
 	}
 
-	memcpy(rproc->fw_buf + rproc->fw_buf_ofs, buf, size);
+	memcpy_toio(rproc->fw_buf + rproc->fw_buf_ofs, buf, size);
 	rproc->fw_buf_ofs += size;
 
 	return 0;
diff --git a/drivers/remoteproc/remoteproc_elf_loader.c b/drivers/remoteproc/remoteproc_elf_loader.c
index f3bf93df2c4a..740ce8765165 100644
--- a/drivers/remoteproc/remoteproc_elf_loader.c
+++ b/drivers/remoteproc/remoteproc_elf_loader.c
@@ -70,7 +70,7 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
 
 		/* put the segment where the remote processor expects it */
 		if (phdr->p_filesz)
-			memcpy(ptr, elf_data + phdr->p_offset, filesz);
+			memcpy_toio(ptr, elf_data + phdr->p_offset, filesz);
 
 		/*
 		 * Zero out remaining memory for this segment.
@@ -80,7 +80,7 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
 		 * this.
 		 */
 		if (memsz > filesz)
-			memset(ptr + filesz, 0, memsz - filesz);
+			memset_io(ptr + filesz, 0, memsz - filesz);
 	}
 
 	return ret;
-- 
2.39.5




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH master] remoteproc: use I/O memory variants of memcpy/memset
  2024-11-15 13:52 [PATCH master] remoteproc: use I/O memory variants of memcpy/memset Ahmad Fatoum
@ 2024-11-15 14:03 ` Ahmad Fatoum
  2024-11-15 14:14   ` Yann Sionneau
  2024-11-15 14:34   ` Stefano Manni
  2024-11-25  9:38 ` Sascha Hauer
  1 sibling, 2 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-11-15 14:03 UTC (permalink / raw)
  To: barebox; +Cc: Stefano Manni

On 15.11.24 14:52, Ahmad Fatoum wrote:
> Reserved memory is unmapped strongly ordered in barebox and calling

argh, `is mapped' is what's meant of course.

> normal optimized memcpy on may trigger an abort due to misalignment.
> 
> Fix this by using the slower I/O variants of memcpy/memset, which are
> do not expect bufferable memory like the optimized variants and thus
> don't cause unaligned accesses.
> 
> Fixes: 66e233b8c04b ("ARM: mmu64: map reserved regions uncached")
> Reported-by: Stefano Manni <stefano.manni@gmail.com>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/remoteproc/remoteproc_core.c       | 2 +-
>  drivers/remoteproc/remoteproc_elf_loader.c | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 7590c1f9305b..17159316ee31 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -75,7 +75,7 @@ static int rproc_firmware_write_buf(struct firmware_handler *fh, const void *buf
>  		return -ENOMEM;
>  	}
>  
> -	memcpy(rproc->fw_buf + rproc->fw_buf_ofs, buf, size);
> +	memcpy_toio(rproc->fw_buf + rproc->fw_buf_ofs, buf, size);
>  	rproc->fw_buf_ofs += size;
>  
>  	return 0;
> diff --git a/drivers/remoteproc/remoteproc_elf_loader.c b/drivers/remoteproc/remoteproc_elf_loader.c
> index f3bf93df2c4a..740ce8765165 100644
> --- a/drivers/remoteproc/remoteproc_elf_loader.c
> +++ b/drivers/remoteproc/remoteproc_elf_loader.c
> @@ -70,7 +70,7 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
>  
>  		/* put the segment where the remote processor expects it */
>  		if (phdr->p_filesz)
> -			memcpy(ptr, elf_data + phdr->p_offset, filesz);
> +			memcpy_toio(ptr, elf_data + phdr->p_offset, filesz);
>  
>  		/*
>  		 * Zero out remaining memory for this segment.
> @@ -80,7 +80,7 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
>  		 * this.
>  		 */
>  		if (memsz > filesz)
> -			memset(ptr + filesz, 0, memsz - filesz);
> +			memset_io(ptr + filesz, 0, memsz - filesz);
>  	}
>  
>  	return ret;


-- 
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 |



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH master] remoteproc: use I/O memory variants of memcpy/memset
  2024-11-15 14:03 ` Ahmad Fatoum
@ 2024-11-15 14:14   ` Yann Sionneau
  2024-11-15 14:34   ` Stefano Manni
  1 sibling, 0 replies; 5+ messages in thread
From: Yann Sionneau @ 2024-11-15 14:14 UTC (permalink / raw)
  To: barebox


On 15/11/2024 15:03, Ahmad Fatoum wrote:
> On 15.11.24 14:52, Ahmad Fatoum wrote:
>> Reserved memory is unmapped strongly ordered in barebox and calling
> argh, `is mapped' is what's meant of course.
>
>> normal optimized memcpy on may trigger an abort due to misalignment.
>>
>> Fix this by using the slower I/O variants of memcpy/memset, which are
I guess the "which are do not expect" is a typo also.
>> do not expect bufferable memory like the optimized variants and thus
>> don't cause unaligned accesses.
>>
>> Fixes: 66e233b8c04b ("ARM: mmu64: map reserved regions uncached")
>> Reported-by: Stefano Manni <stefano.manni@gmail.com>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>>  drivers/remoteproc/remoteproc_core.c       | 2 +-
>>  drivers/remoteproc/remoteproc_elf_loader.c | 4 ++--
>>  2 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
>> index 7590c1f9305b..17159316ee31 100644
>> --- a/drivers/remoteproc/remoteproc_core.c
>> +++ b/drivers/remoteproc/remoteproc_core.c
>> @@ -75,7 +75,7 @@ static int rproc_firmware_write_buf(struct firmware_handler *fh, const void *buf
>>  		return -ENOMEM;
>>  	}
>>  
>> -	memcpy(rproc->fw_buf + rproc->fw_buf_ofs, buf, size);
>> +	memcpy_toio(rproc->fw_buf + rproc->fw_buf_ofs, buf, size);
>>  	rproc->fw_buf_ofs += size;
>>  
>>  	return 0;
>> diff --git a/drivers/remoteproc/remoteproc_elf_loader.c b/drivers/remoteproc/remoteproc_elf_loader.c
>> index f3bf93df2c4a..740ce8765165 100644
>> --- a/drivers/remoteproc/remoteproc_elf_loader.c
>> +++ b/drivers/remoteproc/remoteproc_elf_loader.c
>> @@ -70,7 +70,7 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
>>  
>>  		/* put the segment where the remote processor expects it */
>>  		if (phdr->p_filesz)
>> -			memcpy(ptr, elf_data + phdr->p_offset, filesz);
>> +			memcpy_toio(ptr, elf_data + phdr->p_offset, filesz);
>>  
>>  		/*
>>  		 * Zero out remaining memory for this segment.
>> @@ -80,7 +80,7 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
>>  		 * this.
>>  		 */
>>  		if (memsz > filesz)
>> -			memset(ptr + filesz, 0, memsz - filesz);
>> +			memset_io(ptr + filesz, 0, memsz - filesz);
>>  	}
>>  
>>  	return ret;
>







^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH master] remoteproc: use I/O memory variants of memcpy/memset
  2024-11-15 14:03 ` Ahmad Fatoum
  2024-11-15 14:14   ` Yann Sionneau
@ 2024-11-15 14:34   ` Stefano Manni
  1 sibling, 0 replies; 5+ messages in thread
From: Stefano Manni @ 2024-11-15 14:34 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

Tested-by: Stefano Manni <stefano.manni@gmail.com>

Il giorno ven 15 nov 2024 alle ore 15:03 Ahmad Fatoum
<a.fatoum@pengutronix.de> ha scritto:
>
> On 15.11.24 14:52, Ahmad Fatoum wrote:
> > Reserved memory is unmapped strongly ordered in barebox and calling
>
> argh, `is mapped' is what's meant of course.
>
> > normal optimized memcpy on may trigger an abort due to misalignment.
> >
> > Fix this by using the slower I/O variants of memcpy/memset, which are
> > do not expect bufferable memory like the optimized variants and thus
> > don't cause unaligned accesses.
> >
> > Fixes: 66e233b8c04b ("ARM: mmu64: map reserved regions uncached")
> > Reported-by: Stefano Manni <stefano.manni@gmail.com>
> > Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> > ---
> >  drivers/remoteproc/remoteproc_core.c       | 2 +-
> >  drivers/remoteproc/remoteproc_elf_loader.c | 4 ++--
> >  2 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> > index 7590c1f9305b..17159316ee31 100644
> > --- a/drivers/remoteproc/remoteproc_core.c
> > +++ b/drivers/remoteproc/remoteproc_core.c
> > @@ -75,7 +75,7 @@ static int rproc_firmware_write_buf(struct firmware_handler *fh, const void *buf
> >               return -ENOMEM;
> >       }
> >
> > -     memcpy(rproc->fw_buf + rproc->fw_buf_ofs, buf, size);
> > +     memcpy_toio(rproc->fw_buf + rproc->fw_buf_ofs, buf, size);
> >       rproc->fw_buf_ofs += size;
> >
> >       return 0;
> > diff --git a/drivers/remoteproc/remoteproc_elf_loader.c b/drivers/remoteproc/remoteproc_elf_loader.c
> > index f3bf93df2c4a..740ce8765165 100644
> > --- a/drivers/remoteproc/remoteproc_elf_loader.c
> > +++ b/drivers/remoteproc/remoteproc_elf_loader.c
> > @@ -70,7 +70,7 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
> >
> >               /* put the segment where the remote processor expects it */
> >               if (phdr->p_filesz)
> > -                     memcpy(ptr, elf_data + phdr->p_offset, filesz);
> > +                     memcpy_toio(ptr, elf_data + phdr->p_offset, filesz);
> >
> >               /*
> >                * Zero out remaining memory for this segment.
> > @@ -80,7 +80,7 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
> >                * this.
> >                */
> >               if (memsz > filesz)
> > -                     memset(ptr + filesz, 0, memsz - filesz);
> > +                     memset_io(ptr + filesz, 0, memsz - filesz);
> >       }
> >
> >       return ret;
>
>
> --
> 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 |



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH master] remoteproc: use I/O memory variants of memcpy/memset
  2024-11-15 13:52 [PATCH master] remoteproc: use I/O memory variants of memcpy/memset Ahmad Fatoum
  2024-11-15 14:03 ` Ahmad Fatoum
@ 2024-11-25  9:38 ` Sascha Hauer
  1 sibling, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-11-25  9:38 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum; +Cc: Stefano Manni


On Fri, 15 Nov 2024 14:52:42 +0100, Ahmad Fatoum wrote:
> Reserved memory is unmapped strongly ordered in barebox and calling
> normal optimized memcpy on may trigger an abort due to misalignment.
> 
> Fix this by using the slower I/O variants of memcpy/memset, which are
> do not expect bufferable memory like the optimized variants and thus
> don't cause unaligned accesses.
> 
> [...]

Applied, thanks!

[1/1] remoteproc: use I/O memory variants of memcpy/memset
      https://git.pengutronix.de/cgit/barebox/commit/?id=b0081505fff7 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-11-25 10:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-15 13:52 [PATCH master] remoteproc: use I/O memory variants of memcpy/memset Ahmad Fatoum
2024-11-15 14:03 ` Ahmad Fatoum
2024-11-15 14:14   ` Yann Sionneau
2024-11-15 14:34   ` Stefano Manni
2024-11-25  9:38 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox