All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] efi/tpm: fix a compilation warning
@ 2019-06-11 12:59 Qian Cai
  2019-06-13  8:55 ` Arnd Bergmann
  0 siblings, 1 reply; 5+ messages in thread
From: Qian Cai @ 2019-06-11 12:59 UTC (permalink / raw)
  To: ard.biesheuvel
  Cc: mjg59, linux-efi, bsz, jarkko.sakkinen, linux-kernel, Qian Cai

The linux-next "tpm: Reserve the TPM final events table" [1] introduced
a compilation warning,

drivers/firmware/efi/tpm.c: In function 'efi_tpm_eventlog_init':
drivers/firmware/efi/tpm.c:80:10: warning: passing argument 1 of
'tpm2_calc_event_log_size' makes pointer from integer without a cast
[-Wint-conversion]
  tbl_size = tpm2_calc_event_log_size(efi.tpm_final_log
drivers/firmware/efi/tpm.c:19:43: note: expected 'void *' but argument
is of type 'long unsigned int'

Fix it by making a necessary cast for the argument 1 of
tpm2_calc_event_log_size().

[1] https://lore.kernel.org/linux-efi/20190520205501.177637-3-matthewgarrett@google.com/

Signed-off-by: Qian Cai <cai@lca.pw>
---
 drivers/firmware/efi/tpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
index 74d0cd1647b8..1d3f5ca3eaaf 100644
--- a/drivers/firmware/efi/tpm.c
+++ b/drivers/firmware/efi/tpm.c
@@ -75,7 +75,7 @@ int __init efi_tpm_eventlog_init(void)
 		goto out;
 	}
 
-	tbl_size = tpm2_calc_event_log_size(efi.tpm_final_log
+	tbl_size = tpm2_calc_event_log_size((void *)efi.tpm_final_log
 					    + sizeof(final_tbl->version)
 					    + sizeof(final_tbl->nr_events),
 					    final_tbl->nr_events,
-- 
2.20.1 (Apple Git-117)


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

* Re: [PATCH -next] efi/tpm: fix a compilation warning
  2019-06-11 12:59 [PATCH -next] efi/tpm: fix a compilation warning Qian Cai
@ 2019-06-13  8:55 ` Arnd Bergmann
  2019-06-13 11:41   ` Bartosz Szczepanek
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2019-06-13  8:55 UTC (permalink / raw)
  To: Qian Cai
  Cc: Ard Biesheuvel, mjg59, linux-efi, bsz, Jarkko Sakkinen,
	Linux Kernel Mailing List

On Tue, Jun 11, 2019 at 3:59 PM Qian Cai <cai@lca.pw> wrote:
>
> The linux-next "tpm: Reserve the TPM final events table" [1] introduced
> a compilation warning,
>
> drivers/firmware/efi/tpm.c: In function 'efi_tpm_eventlog_init':
> drivers/firmware/efi/tpm.c:80:10: warning: passing argument 1 of
> 'tpm2_calc_event_log_size' makes pointer from integer without a cast
> [-Wint-conversion]
>   tbl_size = tpm2_calc_event_log_size(efi.tpm_final_log
> drivers/firmware/efi/tpm.c:19:43: note: expected 'void *' but argument
> is of type 'long unsigned int'
>
> Fix it by making a necessary cast for the argument 1 of
> tpm2_calc_event_log_size().
>
> [1] https://lore.kernel.org/linux-efi/20190520205501.177637-3-matthewgarrett@google.com/
>
> Signed-off-by: Qian Cai <cai@lca.pw>

I see the same build warning, but I don't think adding a cast here
solves the problem:

- efi.tpm_final_log is a physical address that gets passed into
  memremap() to return a pointer
- tpm2_calc_event_log_size() takes a pointer argument and
  dereferences it.

My best guess is that we should pass the output of memremap()
here rather than the input:

--- a/drivers/firmware/efi/tpm.c
+++ b/drivers/firmware/efi/tpm.c
@@ -75,7 +75,7 @@ int __init efi_tpm_eventlog_init(void)
                goto out;
        }

-       tbl_size = tpm2_calc_event_log_size(efi.tpm_final_log
+       tbl_size = tpm2_calc_event_log_size(final_tbl
                                            + sizeof(final_tbl->version)
                                            + sizeof(final_tbl->nr_events),
                                            final_tbl->nr_events,

No idea if that is actually what was intended here, but it makes
the code look more plausible.

        Arnd

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

* Re: [PATCH -next] efi/tpm: fix a compilation warning
  2019-06-13  8:55 ` Arnd Bergmann
@ 2019-06-13 11:41   ` Bartosz Szczepanek
  2019-06-13 12:40     ` Arnd Bergmann
  0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Szczepanek @ 2019-06-13 11:41 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Qian Cai, Ard Biesheuvel, Matthew Garrett, linux-efi,
	Jarkko Sakkinen, Linux Kernel Mailing List

On Thu, Jun 13, 2019 at 10:55 AM Arnd Bergmann <arnd@arndb.de> wrote:
>
> - efi.tpm_final_log is a physical address that gets passed into
>   memremap() to return a pointer
> - tpm2_calc_event_log_size() takes a pointer argument and
>   dereferences it.

Where does it? It's passed with some added offset to
__calc_tpm2_event_size, which does the remapping part. That's why
physical address is used here.

> My best guess is that we should pass the output of memremap()
> here rather than the input:
>
> --- a/drivers/firmware/efi/tpm.c
> +++ b/drivers/firmware/efi/tpm.c
> @@ -75,7 +75,7 @@ int __init efi_tpm_eventlog_init(void)
>                 goto out;
>         }
>
> -       tbl_size = tpm2_calc_event_log_size(efi.tpm_final_log
> +       tbl_size = tpm2_calc_event_log_size(final_tbl
>                                             + sizeof(final_tbl->version)
>                                             + sizeof(final_tbl->nr_events),
>                                             final_tbl->nr_events,
>
> No idea if that is actually what was intended here, but it makes
> the code look more plausible.

Passing final_tbl will lead to failure, as it will be remapped for
second time. Cast is needed here. Changing the type from void* to
unsigned long or phys_addr_t (and casting later) would also do the
job. I'm fine with both options.

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

* Re: [PATCH -next] efi/tpm: fix a compilation warning
  2019-06-13 11:41   ` Bartosz Szczepanek
@ 2019-06-13 12:40     ` Arnd Bergmann
  2019-06-13 13:23       ` Bartosz Szczepanek
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2019-06-13 12:40 UTC (permalink / raw)
  To: Bartosz Szczepanek
  Cc: Qian Cai, Ard Biesheuvel, Matthew Garrett, linux-efi,
	Jarkko Sakkinen, Linux Kernel Mailing List

On Thu, Jun 13, 2019 at 1:41 PM Bartosz Szczepanek <bsz@semihalf.com> wrote:
>
> On Thu, Jun 13, 2019 at 10:55 AM Arnd Bergmann <arnd@arndb.de> wrote:
> >
> > - efi.tpm_final_log is a physical address that gets passed into
> >   memremap() to return a pointer
> > - tpm2_calc_event_log_size() takes a pointer argument and
> >   dereferences it.
>
> Where does it? It's passed with some added offset to
> __calc_tpm2_event_size, which does the remapping part. That's why
> physical address is used here.

Ah, right. I was confused by how __calc_tpm2_event_size()
may or may not do the mapping again based on the 'bool do_mapping'
argument, which is 'true' here.

Would it be correct to change that to 'false' then (or completely remove
the additional remap, given that the other two callers pass false
already) and pass final_tbl?

         Arnd

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

* Re: [PATCH -next] efi/tpm: fix a compilation warning
  2019-06-13 12:40     ` Arnd Bergmann
@ 2019-06-13 13:23       ` Bartosz Szczepanek
  0 siblings, 0 replies; 5+ messages in thread
From: Bartosz Szczepanek @ 2019-06-13 13:23 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Qian Cai, Ard Biesheuvel, Matthew Garrett, linux-efi,
	Jarkko Sakkinen, Linux Kernel Mailing List

On Thu, Jun 13, 2019 at 2:40 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> Would it be correct to change that to 'false' then (or completely remove
> the additional remap, given that the other two callers pass false
> already) and pass final_tbl?

The problem is that we don't know the final_tbl size before running
tpm2_calc_event_log_size on it, so we cannot map it's entire content.
Only table header is mapped at the beginning.

After size of entire table is calculated it can be mapped as a whole
and no additional remap is needed, hence the calls with do_mapping =
false.

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

end of thread, other threads:[~2019-06-13 15:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-11 12:59 [PATCH -next] efi/tpm: fix a compilation warning Qian Cai
2019-06-13  8:55 ` Arnd Bergmann
2019-06-13 11:41   ` Bartosz Szczepanek
2019-06-13 12:40     ` Arnd Bergmann
2019-06-13 13:23       ` Bartosz Szczepanek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.