linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] firmware: make sure builtin firmware is page alignment
@ 2018-08-03  1:45 Zhang Ning
  2018-08-03  5:39 ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Zhang Ning @ 2018-08-03  1:45 UTC (permalink / raw)
  To: gregkh, kstewart, pombredanne, yamada.masahiro, markus, linux-kernel
  Cc: Zhang Ning, Li, Ting

when firmware is in filesystem, request_firmware will load it,
and copy it to vmalloc memory, that is page align memory.

but when firmware is builtin, it is 8 bytes or 4 bytes alignment.

make sure builtin firmware is page algnment, that can simplify algorithm
to handle firmware.

Signed-off-by: Zhang Ning <ning.a.zhang@intel.com>
Signed-off-by: Li, Ting <ting.li@intel.com>
---
 firmware/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/firmware/Makefile b/firmware/Makefile
index 29641383e136..d7bfce56378f 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -16,10 +16,11 @@ quiet_cmd_fwbin = MK_FW   $@
 				firmware/%.gen.S,%,$@))))";		     \
 		  ASM_WORD=$(if $(CONFIG_64BIT),.quad,.long);		     \
 		  ASM_ALIGN=$(if $(CONFIG_64BIT),3,2);			     \
+		  ASM_FW_ALIGN=12;			  	   	     \
 		  PROGBITS=$(if $(CONFIG_ARM),%,@)progbits;		     \
 		  echo "/* Generated by firmware/Makefile */"		> $@;\
 		  echo "    .section .rodata"				>>$@;\
-		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
+		  echo "    .p2align $${ASM_FW_ALIGN}"			>>$@;\
 		  echo "_fw_$${FWSTR}_bin:"				>>$@;\
 		  echo "    .incbin \"$(2)\""				>>$@;\
 		  echo "_fw_end:"					>>$@;\
-- 
2.18.0


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

* Re: [PATCH] firmware: make sure builtin firmware is page alignment
  2018-08-03  1:45 [PATCH] firmware: make sure builtin firmware is page alignment Zhang Ning
@ 2018-08-03  5:39 ` Greg KH
  2018-08-03  8:42   ` Zhang, Ning A
  0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2018-08-03  5:39 UTC (permalink / raw)
  To: Zhang Ning
  Cc: kstewart, pombredanne, yamada.masahiro, markus, linux-kernel, Ting

On Fri, Aug 03, 2018 at 09:45:21AM +0800, Zhang Ning wrote:
> when firmware is in filesystem, request_firmware will load it,
> and copy it to vmalloc memory, that is page align memory.
> 
> but when firmware is builtin, it is 8 bytes or 4 bytes alignment.
> 
> make sure builtin firmware is page algnment, that can simplify algorithm
> to handle firmware.

How is it simplified?  I don't see any such change like that here :(


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

* Re: [PATCH] firmware: make sure builtin firmware is page alignment
  2018-08-03  5:39 ` Greg KH
@ 2018-08-03  8:42   ` Zhang, Ning A
  2018-08-03 10:31     ` gregkh
  0 siblings, 1 reply; 9+ messages in thread
From: Zhang, Ning A @ 2018-08-03  8:42 UTC (permalink / raw)
  To: gregkh
  Cc: pombredanne, linux-kernel, Li, Ting, yamada.masahiro, kstewart, markus

在 2018-08-03五的 07:39 +0200,Greg KH写道:
> On Fri, Aug 03, 2018 at 09:45:21AM +0800, Zhang Ning wrote:
> > when firmware is in filesystem, request_firmware will load it,
> > and copy it to vmalloc memory, that is page align memory.
> > 
> > but when firmware is builtin, it is 8 bytes or 4 bytes alignment.
> > 
> > make sure builtin firmware is page algnment, that can simplify
> > algorithm
> > to handle firmware.
> 
> How is it simplified?  I don't see any such change like that here :(
> 
Thank you for review this patch.

When driver handles its firmware based on  page, like below:

	struct page *p;
	p = vmalloc_to_page(fw->data);  // for filesystem firmware
	p = virt_to_page(fw->data); // for builtin firmware

but if builtin firmware is not page alignment, page pointer for builtin
firmware is wrong, it contains memory not belong to firmware. drivers
has to use additional code to handle this. 

if builtin firmware is also page alignment, no need additional code to
handle builtin firmware. simplified.

BR.
Ning.

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

* Re: [PATCH] firmware: make sure builtin firmware is page alignment
  2018-08-03  8:42   ` Zhang, Ning A
@ 2018-08-03 10:31     ` gregkh
  2018-08-06  1:48       ` Zhang, Ning A
  0 siblings, 1 reply; 9+ messages in thread
From: gregkh @ 2018-08-03 10:31 UTC (permalink / raw)
  To: Zhang, Ning A
  Cc: pombredanne, linux-kernel, Li, Ting, yamada.masahiro, kstewart, markus

On Fri, Aug 03, 2018 at 08:42:25AM +0000, Zhang, Ning A wrote:
> 在 2018-08-03五的 07:39 +0200,Greg KH写道:
> > On Fri, Aug 03, 2018 at 09:45:21AM +0800, Zhang Ning wrote:
> > > when firmware is in filesystem, request_firmware will load it,
> > > and copy it to vmalloc memory, that is page align memory.
> > > 
> > > but when firmware is builtin, it is 8 bytes or 4 bytes alignment.
> > > 
> > > make sure builtin firmware is page algnment, that can simplify
> > > algorithm
> > > to handle firmware.
> > 
> > How is it simplified?  I don't see any such change like that here :(
> > 
> Thank you for review this patch.
> 
> When driver handles its firmware based on  page, like below:
> 
> 	struct page *p;
> 	p = vmalloc_to_page(fw->data);  // for filesystem firmware
> 	p = virt_to_page(fw->data); // for builtin firmware
> 
> but if builtin firmware is not page alignment, page pointer for builtin
> firmware is wrong, it contains memory not belong to firmware. drivers
> has to use additional code to handle this. 
> 
> if builtin firmware is also page alignment, no need additional code to
> handle builtin firmware. simplified.

But you did not change anything like this in your code, so why would I
know this?

Please fix this up submit this properly.

greg k-h

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

* Re: [PATCH] firmware: make sure builtin firmware is page alignment
  2018-08-03 10:31     ` gregkh
@ 2018-08-06  1:48       ` Zhang, Ning A
  2018-08-06  5:13         ` Zhang, Ning A
  2018-08-06 14:05         ` gregkh
  0 siblings, 2 replies; 9+ messages in thread
From: Zhang, Ning A @ 2018-08-06  1:48 UTC (permalink / raw)
  To: gregkh
  Cc: pombredanne, linux-kernel, Li, Ting, yamada.masahiro, kstewart, markus

在 2018-08-03五的 12:31 +0200,gregkh@linuxfoundation.org写道:
> On Fri, Aug 03, 2018 at 08:42:25AM +0000, Zhang, Ning A wrote:
> > 在 2018-08-03五的 07:39 +0200,Greg KH写道:
> > > On Fri, Aug 03, 2018 at 09:45:21AM +0800, Zhang Ning wrote:
> > > > when firmware is in filesystem, request_firmware will load it,
> > > > and copy it to vmalloc memory, that is page align memory.
> > > > 
> > > > but when firmware is builtin, it is 8 bytes or 4 bytes
> > > > alignment.
> > > > 
> > > > make sure builtin firmware is page algnment, that can simplify
> > > > algorithm
> > > > to handle firmware.
> > > 
> > > How is it simplified?  I don't see any such change like that here
> > > :(
> > > 
> > 
> > Thank you for review this patch.
> > 
> > When driver handles its firmware based on  page, like below:
> > 
> > 	struct page *p;
> > 	p = vmalloc_to_page(fw->data);  // for filesystem firmware
> > 	p = virt_to_page(fw->data); // for builtin firmware
> > 
> > but if builtin firmware is not page alignment, page pointer for
> > builtin
> > firmware is wrong, it contains memory not belong to firmware.
> > drivers
> > has to use additional code to handle this. 
> > 
> > if builtin firmware is also page alignment, no need additional code
> > to
> > handle builtin firmware. simplified.
> 
> But you did not change anything like this in your code, so why would
> I
> know this?

I understand it is very difficult to review this patch without context.
The driver is not opensource, I can't show the patch for driver.

this patch changes kernel common code, and it has value to upstream, so
I submit this patch for review and also look forward some advises from
community. Once we decide to opensource, the driver changes will be
there.




> Please fix this up submit this properly.
> 
> greg k-h

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

* Re: [PATCH] firmware: make sure builtin firmware is page alignment
  2018-08-06  1:48       ` Zhang, Ning A
@ 2018-08-06  5:13         ` Zhang, Ning A
  2018-08-06 14:05         ` gregkh
  1 sibling, 0 replies; 9+ messages in thread
From: Zhang, Ning A @ 2018-08-06  5:13 UTC (permalink / raw)
  To: gregkh
  Cc: pombredanne, linux-kernel, Li, Ting, yamada.masahiro, kstewart, markus

在 2018-08-06一的 01:48 +0000,Zhang, Ning A写道:
> 在 2018-08-03五的 12:31 +0200,gregkh@linuxfoundation.org写道:
> > On Fri, Aug 03, 2018 at 08:42:25AM +0000, Zhang, Ning A wrote:
> > > 在 2018-08-03五的 07:39 +0200,Greg KH写道:
> > > > On Fri, Aug 03, 2018 at 09:45:21AM +0800, Zhang Ning wrote:
> > > > > when firmware is in filesystem, request_firmware will load
> > > > > it,
> > > > > and copy it to vmalloc memory, that is page align memory.
> > > > > 
> > > > > but when firmware is builtin, it is 8 bytes or 4 bytes
> > > > > alignment.
> > > > > 
> > > > > make sure builtin firmware is page algnment, that can
> > > > > simplify
> > > > > algorithm
> > > > > to handle firmware.
> > > > 
> > > > How is it simplified?  I don't see any such change like that
> > > > here
> > > > :(
> > > > 
> > > 
> > > Thank you for review this patch.
> > > 
> > > When driver handles its firmware based on  page, like below:
> > > 
> > > 	struct page *p;
> > > 	p = vmalloc_to_page(fw->data);  // for filesystem firmware
> > > 	p = virt_to_page(fw->data); // for builtin firmware
> > > 
> > > but if builtin firmware is not page alignment, page pointer for
> > > builtin
> > > firmware is wrong, it contains memory not belong to firmware.
> > > drivers
> > > has to use additional code to handle this. 
> > > 
> > > if builtin firmware is also page alignment, no need additional
> > > code
> > > to
> > > handle builtin firmware. simplified.
> > 
> > But you did not change anything like this in your code, so why
> > would
> > I
> > know this?
> 
> I understand it is very difficult to review this patch without
> context.
> The driver is not opensource, I can't show the patch for driver.
> 
> this patch changes kernel common code, and it has value to upstream,
> so
> I submit this patch for review and also look forward some advises
> from
> community. Once we decide to opensource, the driver changes will be
> there.
> 
> 

as said our driver handles firmware based on page, and if firmware is
builtin, page point from virt_to_page(fw->data) contains memory doesn't
belong to firmware. there are two way to fix it.

1, copy builtin firmware to vmalloc memory, this is additional work to
handle firmware. I create a wrap function for firmware request.

int request_XYZ_fw(const struct firmware **firmware_p, const char
*name,
		 struct device *device)
{
	const struct firmware *fw;
	struct firmware *tmp;
	int ret;

	ret = request_firmware(&fw, name, device);

	if (ret < 0)
		return ret;

	if (is_vmalloc_addr(fw->data))
		*firmware_p = fw;
	else {
		tmp = (struct firmware *)kzalloc(sizeof(struct
firmware), GFP_KERNEL);
		if (!tmp)
			return -ENOMEM;
		tmp->size = fw->size;
		tmp->data = vmalloc(fw->size);
		memcpy(tmp->data, fw->data, fw->size);
		*firmware_p = tmp;
	}
	return ret;
}

2, make builtin firmware is also page alignment. the change in driver
code is to check memory type of fw->data, and use different XXX_to_page
function.

struct page *p;
if (is_vmalloc_addr(fw->data))  // new
	p = vmalloc_to_page(fw->data);
else                            // new
	p = virt_to_page(fw->data); // new


compare to solution, solution 2 is simple, this is what I said
simplified. and solution 2 also save memory (I don't know the affect
change memory alignment on memory usage.)

Hi, Greg
is this easier for you to review?

BR.
Ning.
> 

> 
Please fix this up submit this properly.

greg k-h

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

* Re: [PATCH] firmware: make sure builtin firmware is page alignment
  2018-08-06  1:48       ` Zhang, Ning A
  2018-08-06  5:13         ` Zhang, Ning A
@ 2018-08-06 14:05         ` gregkh
  2018-08-07  2:27           ` Zhang, Ning A
  1 sibling, 1 reply; 9+ messages in thread
From: gregkh @ 2018-08-06 14:05 UTC (permalink / raw)
  To: Zhang, Ning A
  Cc: pombredanne, linux-kernel, Li, Ting, yamada.masahiro, kstewart, markus

On Mon, Aug 06, 2018 at 01:48:44AM +0000, Zhang, Ning A wrote:
> 在 2018-08-03五的 12:31 +0200,gregkh@linuxfoundation.org写道:
> > On Fri, Aug 03, 2018 at 08:42:25AM +0000, Zhang, Ning A wrote:
> > > 在 2018-08-03五的 07:39 +0200,Greg KH写道:
> > > > On Fri, Aug 03, 2018 at 09:45:21AM +0800, Zhang Ning wrote:
> > > > > when firmware is in filesystem, request_firmware will load it,
> > > > > and copy it to vmalloc memory, that is page align memory.
> > > > > 
> > > > > but when firmware is builtin, it is 8 bytes or 4 bytes
> > > > > alignment.
> > > > > 
> > > > > make sure builtin firmware is page algnment, that can simplify
> > > > > algorithm
> > > > > to handle firmware.
> > > > 
> > > > How is it simplified?  I don't see any such change like that here
> > > > :(
> > > > 
> > > 
> > > Thank you for review this patch.
> > > 
> > > When driver handles its firmware based on  page, like below:
> > > 
> > > 	struct page *p;
> > > 	p = vmalloc_to_page(fw->data);  // for filesystem firmware
> > > 	p = virt_to_page(fw->data); // for builtin firmware
> > > 
> > > but if builtin firmware is not page alignment, page pointer for
> > > builtin
> > > firmware is wrong, it contains memory not belong to firmware.
> > > drivers
> > > has to use additional code to handle this. 
> > > 
> > > if builtin firmware is also page alignment, no need additional code
> > > to
> > > handle builtin firmware. simplified.
> > 
> > But you did not change anything like this in your code, so why would
> > I
> > know this?
> 
> I understand it is very difficult to review this patch without context.
> The driver is not opensource, I can't show the patch for driver.

Then I can not accept your patch.  Go talk to your corporate lawyers
about changing core kernel code for a closed source driver and what that
implies about that closed driver (hint, your driver can not be
closed...) :)

Then come back with a proper open sourced driver, that's the only way
Linux drivers can be written sorry.

best of luck,

greg k-h

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

* Re: [PATCH] firmware: make sure builtin firmware is page alignment
  2018-08-06 14:05         ` gregkh
@ 2018-08-07  2:27           ` Zhang, Ning A
  2018-08-07  8:12             ` gregkh
  0 siblings, 1 reply; 9+ messages in thread
From: Zhang, Ning A @ 2018-08-07  2:27 UTC (permalink / raw)
  To: gregkh
  Cc: pombredanne, linux-kernel, Li, Ting, yamada.masahiro, kstewart, markus

在 2018-08-06一的 16:05 +0200,gregkh@linuxfoundation.org写道:
> On Mon, Aug 06, 2018 at 01:48:44AM +0000, Zhang, Ning A wrote:
> > 在 2018-08-03五的 12:31 +0200,gregkh@linuxfoundation.org写道:
> > > On Fri, Aug 03, 2018 at 08:42:25AM +0000, Zhang, Ning A wrote:
> > > > 在 2018-08-03五的 07:39 +0200,Greg KH写道:
> > > > > On Fri, Aug 03, 2018 at 09:45:21AM +0800, Zhang Ning wrote:
> > > > > > when firmware is in filesystem, request_firmware will load
> > > > > > it,
> > > > > > and copy it to vmalloc memory, that is page align memory.
> > > > > > 
> > > > > > but when firmware is builtin, it is 8 bytes or 4 bytes
> > > > > > alignment.
> > > > > > 
> > > > > > make sure builtin firmware is page algnment, that can
> > > > > > simplify
> > > > > > algorithm
> > > > > > to handle firmware.
> > > > > 
> > > > > How is it simplified?  I don't see any such change like that
> > > > > here
> > > > > :(
> > > > > 
> > > > 
> > > > Thank you for review this patch.
> > > > 
> > > > When driver handles its firmware based on  page, like below:
> > > > 
> > > > 	struct page *p;
> > > > 	p = vmalloc_to_page(fw->data);  // for filesystem
> > > > firmware
> > > > 	p = virt_to_page(fw->data); // for builtin firmware
> > > > 
> > > > but if builtin firmware is not page alignment, page pointer for
> > > > builtin
> > > > firmware is wrong, it contains memory not belong to firmware.
> > > > drivers
> > > > has to use additional code to handle this. 
> > > > 
> > > > if builtin firmware is also page alignment, no need additional
> > > > code
> > > > to
> > > > handle builtin firmware. simplified.
> > > 
> > > But you did not change anything like this in your code, so why
> > > would
> > > I
> > > know this?
> > 
> > I understand it is very difficult to review this patch without
> > context.
> > The driver is not opensource, I can't show the patch for driver.
> 
> Then I can not accept your patch.  Go talk to your corporate lawyers
> about changing core kernel code for a closed source driver and what
> that
> implies about that closed driver (hint, your driver can not be
> closed...) :)

It's very sad, but anyway, thank you for your review.
your review will definitely help us improve our work.

BR.
Ning.

> 
> Then come back with a proper open sourced driver, that's the only way
> Linux drivers can be written sorry.
> 
> best of luck,
> 
> greg k-h
> 

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

* Re: [PATCH] firmware: make sure builtin firmware is page alignment
  2018-08-07  2:27           ` Zhang, Ning A
@ 2018-08-07  8:12             ` gregkh
  0 siblings, 0 replies; 9+ messages in thread
From: gregkh @ 2018-08-07  8:12 UTC (permalink / raw)
  To: Zhang, Ning A
  Cc: pombredanne, linux-kernel, Li, Ting, yamada.masahiro, kstewart, markus

On Tue, Aug 07, 2018 at 02:27:31AM +0000, Zhang, Ning A wrote:
> 在 2018-08-06一的 16:05 +0200,gregkh@linuxfoundation.org写道:
> > On Mon, Aug 06, 2018 at 01:48:44AM +0000, Zhang, Ning A wrote:
> > > 在 2018-08-03五的 12:31 +0200,gregkh@linuxfoundation.org写道:
> > > > On Fri, Aug 03, 2018 at 08:42:25AM +0000, Zhang, Ning A wrote:
> > > > > 在 2018-08-03五的 07:39 +0200,Greg KH写道:
> > > > > > On Fri, Aug 03, 2018 at 09:45:21AM +0800, Zhang Ning wrote:
> > > > > > > when firmware is in filesystem, request_firmware will load
> > > > > > > it,
> > > > > > > and copy it to vmalloc memory, that is page align memory.
> > > > > > > 
> > > > > > > but when firmware is builtin, it is 8 bytes or 4 bytes
> > > > > > > alignment.
> > > > > > > 
> > > > > > > make sure builtin firmware is page algnment, that can
> > > > > > > simplify
> > > > > > > algorithm
> > > > > > > to handle firmware.
> > > > > > 
> > > > > > How is it simplified?  I don't see any such change like that
> > > > > > here
> > > > > > :(
> > > > > > 
> > > > > 
> > > > > Thank you for review this patch.
> > > > > 
> > > > > When driver handles its firmware based on  page, like below:
> > > > > 
> > > > > 	struct page *p;
> > > > > 	p = vmalloc_to_page(fw->data);  // for filesystem
> > > > > firmware
> > > > > 	p = virt_to_page(fw->data); // for builtin firmware
> > > > > 
> > > > > but if builtin firmware is not page alignment, page pointer for
> > > > > builtin
> > > > > firmware is wrong, it contains memory not belong to firmware.
> > > > > drivers
> > > > > has to use additional code to handle this. 
> > > > > 
> > > > > if builtin firmware is also page alignment, no need additional
> > > > > code
> > > > > to
> > > > > handle builtin firmware. simplified.
> > > > 
> > > > But you did not change anything like this in your code, so why
> > > > would
> > > > I
> > > > know this?
> > > 
> > > I understand it is very difficult to review this patch without
> > > context.
> > > The driver is not opensource, I can't show the patch for driver.
> > 
> > Then I can not accept your patch.  Go talk to your corporate lawyers
> > about changing core kernel code for a closed source driver and what
> > that
> > implies about that closed driver (hint, your driver can not be
> > closed...) :)
> 
> It's very sad,

"sad"?  Again, please go discuss this with your corporate lawyers before
thinking that this is even something that is possible to do.  Hint, if
I _were_ to accept this, they would be _VERY_ upset at both me, and you.

I am trying to _save_ you problems, please realize this.

greg k-h

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

end of thread, other threads:[~2018-08-07  8:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-03  1:45 [PATCH] firmware: make sure builtin firmware is page alignment Zhang Ning
2018-08-03  5:39 ` Greg KH
2018-08-03  8:42   ` Zhang, Ning A
2018-08-03 10:31     ` gregkh
2018-08-06  1:48       ` Zhang, Ning A
2018-08-06  5:13         ` Zhang, Ning A
2018-08-06 14:05         ` gregkh
2018-08-07  2:27           ` Zhang, Ning A
2018-08-07  8:12             ` gregkh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).