Skip to contentSkip to conversation

ASoC: SOF: Add firmware, loader support

PATCH Bard liao 4 participants 6 messages Dec 20, 2018 – Dec 21, 2018 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Bard liao

author
#1 lore raw
Quoted 16 lines

Date: Wed, 12 Dec 2018 12:23:33 +0100
From: Takashi Iwai <[email protected]>
To: Pierre-Louis Bossart <[email protected]>
Cc: [email protected], [email protected], Daniel
Baluta <[email protected]>, [email protected], [email protected], [email protected], Alan Cox <[email protected]>, [email protected]
Subject: Re: [alsa-devel] [PATCH v3 09/14] ASoC: SOF: Add firmware
loader support
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

On Tue, 11 Dec 2018 22:23:13 +0100,
Pierre-Louis Bossart wrote:

Quoted 8 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+
+		snd_sof_dsp_block_write(sdev, offset,
+					(void *)block + sizeof(*block),
+					block->size);
+
+		/* next block */
+		block = (void *)block + sizeof(*block) + block->size;

This may lead to an unaligned access.

Did you mean we should double check the block->size to prevent access to an invalid address?

Quoted 1 line

Also how is the endianess guaranteed?

Did you mean we should guarantee the driver can work no matter what kernel's endianess is?
ie. Use le32_to_cpu() to handle it?

Quoted 7 lines

thanks,

Takashi

#2 lore raw
Quoted 26 lines · Bard liao
Quoted 17 lines

Date: Wed, 12 Dec 2018 12:23:33 +0100
From: Takashi Iwai <[email protected]>
To: Pierre-Louis Bossart <[email protected]>
Cc: [email protected], [email protected], Daniel
Baluta <[email protected]>, [email protected], [email protected], [email protected], Alan Cox <[email protected]>, [email protected]
Subject: Re: [alsa-devel] [PATCH v3 09/14] ASoC: SOF: Add firmware
loader support
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

On Tue, 11 Dec 2018 22:23:13 +0100,
Pierre-Louis Bossart wrote:

Quoted 8 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+
+		snd_sof_dsp_block_write(sdev, offset,
+					(void *)block + sizeof(*block),
+					block->size);
+
+		/* next block */
+		block = (void *)block + sizeof(*block) + block->size;

This may lead to an unaligned access.

Quoted 2 lines

Did you mean we should double check the block->size to prevent access to an invalid address?

You need two types of checks for the given data:
- The bounce check of block->size;
We need to avoid out-of-bounce access.

- Alignment of block->size;
For some non-x86 platforms, the access to an unaligned address might be illegal.

Oh, and recently another thing is sometimes needed for avoiding Spectre. This can be covered by array_index_nospec().

Quoted 5 lines
Quoted 1 line

Also how is the endianess guaranteed?

Did you mean we should guarantee the driver can work no matter what kernel's endianess is?
ie. Use le32_to_cpu() to handle it?

Depends on the implementation. IIRC, topology API refuses the data in a different endianess by checking the magic number at beginning.

thanks,

Takashi

#3 lore raw
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 7 lines
(quoted diff) +6 -0
+		snd_sof_dsp_block_write(sdev, offset,
+					(void *)block + sizeof(*block),
+					block->size);
+
+		/* next block */
+		block = (void *)block + sizeof(*block) + block->size;

This may lead to an unaligned access.

Quoted 5 lines
Quoted 2 lines

Did you mean we should double check the block->size to prevent access to an invalid address?

You need two types of checks for the given data:
- The bounce check of block->size;
We need to avoid out-of-bounce access.

s/bounce/bounds ?

Quoted 4 lines

- Alignment of block->size;
For some non-x86 platforms, the access to an unaligned address might be illegal.

Maybe I am missing something but I don't see any sort of explicit restriction on alignment in the SOF tools. it looks implicit based on address offsets and bases.

Liam, do you see any negative side effects if we enforce a 32-bit alignment for all blocks (which essentially means all block sizes are multiple of 4)? we can try and experiment but it's better if we have an agreement on the design.

Quoted 11 lines

Oh, and recently another thing is sometimes needed for avoiding Spectre. This can be covered by array_index_nospec().

Quoted 4 lines
Quoted 1 line

Also how is the endianess guaranteed?

Did you mean we should guarantee the driver can work no matter what kernel's endianess is?
ie. Use le32_to_cpu() to handle it?

Depends on the implementation. IIRC, topology API refuses the data in a different endianess by checking the magic number at beginning.

snd_sof_dsp_block_write() is implemented with a platform-specific callback, I'd expect any endianess issues to be handled in that platform-specific code?

author
#4 lore raw
Quoted 13 lines · Pierre-Louis Bossart
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

+ snd_sof_dsp_block_write(sdev, offset,
+                    (void *)block + sizeof(*block), +                    block->size);
+
+        /* next block */
+        block = (void *)block + sizeof(*block) + block->size;

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

This may lead to an unaligned access.

Did you mean we should double check the block->size to prevent access to an invalid address?

You need two types of checks for the given data:
- The bounce check of block->size;
   We need to avoid out-of-bounce access.

Quoted 7 lines

s/bounce/bounds ?

Quoted 4 lines

- Alignment of block->size;
   For some non-x86 platforms, the access to an unaligned address might be illegal.

Maybe I am missing something but I don't see any sort of explicit restriction on alignment in the SOF tools. it looks implicit based on address offsets and bases.

Maybe get_unaligned() is good enough to avoid unaligned access?

Quoted 4 lines

Liam, do you see any negative side effects if we enforce a 32-bit alignment for all blocks (which essentially means all block sizes are multiple of 4)? we can try and experiment but it's better if we have an agreement on the design.

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#5 lore raw
Quoted 22 lines · Bard liao
Quoted 19 lines · Pierre-Louis Bossart
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

+ snd_sof_dsp_block_write(sdev, offset,
+                    (void *)block + sizeof(*block), +                    block->size);
+
+        /* next block */
+        block = (void *)block + sizeof(*block) + block->size;

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

This may lead to an unaligned access.

Did you mean we should double check the block->size to prevent access to an invalid address?

You need two types of checks for the given data:
- The bounce check of block->size;
   We need to avoid out-of-bounce access.

s/bounce/bounds ?

Quoted 4 lines

- Alignment of block->size;
   For some non-x86 platforms, the access to an unaligned address might be illegal.

Quoted 5 lines
Quoted 3 lines

Maybe I am missing something but I don't see any sort of explicit restriction on alignment in the SOF tools. it looks implicit based on address offsets and bases.

Maybe get_unaligned() is good enough to avoid unaligned access?

That's another option, but you'd need to put everywhere.

An alternative is to just copy the data on a new block header on the stack temporarily and refer it.

Or simply assuring the alignment by checking block->size as Pierre suggested...

Takashi

Quoted 9 lines
Quoted 8 lines

Liam, do you see any negative side effects if we enforce a 32-bit alignment for all blocks (which essentially means all block sizes are multiple of 4)? we can try and experiment but it's better if we have an agreement on the design.

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#6 lore raw
Quoted 27 lines · Takashi Iwai
Quoted 19 lines · Bard liao
Quoted 17 lines · Pierre-Louis Bossart
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

+ snd_sof_dsp_block_write(sdev, offset,

(quoted diff) +5 -0
+                    (void *)block + sizeof(*block),
+                    block->size);
+
+        /* next block */
+        block = (void *)block + sizeof(*block) + block->size;
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

This may lead to an unaligned access.

Did you mean we should double check the block->size to prevent access to an invalid address?

You need two types of checks for the given data:
- The bounce check of block->size;
We need to avoid out-of-bounce access.

s/bounce/bounds ?

Quoted 3 lines

- Alignment of block->size;
For some non-x86 platforms, the access to an unaligned address might be illegal.

Quoted 5 lines
Quoted 3 lines

Maybe I am missing something but I don't see any sort of explicit restriction on alignment in the SOF tools. it looks implicit based on address offsets and bases.

Maybe get_unaligned() is good enough to avoid unaligned access?

Quoted 7 lines

That's another option, but you'd need to put everywhere.

An alternative is to just copy the data on a new block header on the stack temporarily and refer it.

Or simply assuring the alignment by checking block->size as Pierre suggested...

Yep, checking size is good for me too.

Quoted 9 lines

Takashi

Quoted 4 lines
Quoted 4 lines

Liam, do you see any negative side effects if we enforce a 32-bit alignment for all blocks (which essentially means all block sizes are multiple of 4)? we can try and experiment but it's better if we have an agreement on the design.

This shouldn't cause any problems, iirc all block sizes are rounded up to nearest uint32_t anyway (as we have exception handler blocks that are 3 bytes of assembly in size and rounded up to 4).

Liam

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel