All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] efi/memreserve: deal with memreserve entries in unmapped memory
@ 2019-06-10 15:05 ` Ard Biesheuvel
  0 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2019-06-10 15:05 UTC (permalink / raw)
  To: linux-efi
  Cc: linux-arm-kernel, marc.zyngier, bhsharma, ray.jui,
	Ard Biesheuvel, Jonathan Richardson

Ensure that the EFI memreserve entries can be accessed, even if they
are located in memory that the kernel (e.g., a crashkernel) omits from
the linear map.

Reported-by: Jonathan Richardson <jonathan.richardson@broadcom.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 drivers/firmware/efi/efi.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 16b2137d117c..4b7cf7bc0ded 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -1009,14 +1009,16 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
 
 	/* first try to find a slot in an existing linked list entry */
 	for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) {
-		rsv = __va(prsv);
+		rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB);
 		index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size);
 		if (index < rsv->size) {
 			rsv->entry[index].base = addr;
 			rsv->entry[index].size = size;
 
+			memunmap(rsv);
 			return 0;
 		}
+		memunmap(rsv);
 	}
 
 	/* no slot found - allocate a new linked list entry */
@@ -1024,7 +1026,13 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
 	if (!rsv)
 		return -ENOMEM;
 
-	rsv->size = EFI_MEMRESERVE_COUNT(PAGE_SIZE);
+	/*
+	 * The memremap() call above assumes that a linux_efi_memreserve entry
+	 * never crosses a page boundary, so let's ensure that this remains true
+	 * even when kexec'ing a 4k pages kernel from a >4k pages kernel, by
+	 * using SZ_4K explicitly in the size calculation below.
+	 */
+	rsv->size = EFI_MEMRESERVE_COUNT(SZ_4K);
 	atomic_set(&rsv->count, 1);
 	rsv->entry[0].base = addr;
 	rsv->entry[0].size = size;
-- 
2.20.1


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

* [PATCH] efi/memreserve: deal with memreserve entries in unmapped memory
@ 2019-06-10 15:05 ` Ard Biesheuvel
  0 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2019-06-10 15:05 UTC (permalink / raw)
  To: linux-efi
  Cc: Jonathan Richardson, Ard Biesheuvel, marc.zyngier, bhsharma,
	ray.jui, linux-arm-kernel

Ensure that the EFI memreserve entries can be accessed, even if they
are located in memory that the kernel (e.g., a crashkernel) omits from
the linear map.

Reported-by: Jonathan Richardson <jonathan.richardson@broadcom.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 drivers/firmware/efi/efi.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 16b2137d117c..4b7cf7bc0ded 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -1009,14 +1009,16 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
 
 	/* first try to find a slot in an existing linked list entry */
 	for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) {
-		rsv = __va(prsv);
+		rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB);
 		index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size);
 		if (index < rsv->size) {
 			rsv->entry[index].base = addr;
 			rsv->entry[index].size = size;
 
+			memunmap(rsv);
 			return 0;
 		}
+		memunmap(rsv);
 	}
 
 	/* no slot found - allocate a new linked list entry */
@@ -1024,7 +1026,13 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
 	if (!rsv)
 		return -ENOMEM;
 
-	rsv->size = EFI_MEMRESERVE_COUNT(PAGE_SIZE);
+	/*
+	 * The memremap() call above assumes that a linux_efi_memreserve entry
+	 * never crosses a page boundary, so let's ensure that this remains true
+	 * even when kexec'ing a 4k pages kernel from a >4k pages kernel, by
+	 * using SZ_4K explicitly in the size calculation below.
+	 */
+	rsv->size = EFI_MEMRESERVE_COUNT(SZ_4K);
 	atomic_set(&rsv->count, 1);
 	rsv->entry[0].base = addr;
 	rsv->entry[0].size = size;
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] efi/memreserve: deal with memreserve entries in unmapped memory
  2019-06-10 15:05 ` Ard Biesheuvel
@ 2019-06-10 16:27   ` Ray Jui
  -1 siblings, 0 replies; 6+ messages in thread
From: Ray Jui @ 2019-06-10 16:27 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-efi
  Cc: linux-arm-kernel, marc.zyngier, bhsharma, Jonathan Richardson

Hi Ard,

On 6/10/2019 8:05 AM, Ard Biesheuvel wrote:
> Ensure that the EFI memreserve entries can be accessed, even if they
> are located in memory that the kernel (e.g., a crashkernel) omits from
> the linear map.
> 
> Reported-by: Jonathan Richardson <jonathan.richardson@broadcom.com>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Does it make sense to add a Fixes tag?

> ---
>  drivers/firmware/efi/efi.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
> index 16b2137d117c..4b7cf7bc0ded 100644
> --- a/drivers/firmware/efi/efi.c
> +++ b/drivers/firmware/efi/efi.c
> @@ -1009,14 +1009,16 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
>  
>  	/* first try to find a slot in an existing linked list entry */
>  	for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) {
> -		rsv = __va(prsv);
> +		rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB);
>  		index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size);
>  		if (index < rsv->size) {
>  			rsv->entry[index].base = addr;
>  			rsv->entry[index].size = size;
>  
> +			memunmap(rsv);
>  			return 0;
>  		}
> +		memunmap(rsv);
>  	}
>  
>  	/* no slot found - allocate a new linked list entry */
> @@ -1024,7 +1026,13 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
>  	if (!rsv)
>  		return -ENOMEM;
>  
> -	rsv->size = EFI_MEMRESERVE_COUNT(PAGE_SIZE);
> +	/*
> +	 * The memremap() call above assumes that a linux_efi_memreserve entry
> +	 * never crosses a page boundary, so let's ensure that this remains true
> +	 * even when kexec'ing a 4k pages kernel from a >4k pages kernel, by
> +	 * using SZ_4K explicitly in the size calculation below.
> +	 */
> +	rsv->size = EFI_MEMRESERVE_COUNT(SZ_4K);
>  	atomic_set(&rsv->count, 1);
>  	rsv->entry[0].base = addr;
>  	rsv->entry[0].size = size;
> 

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

* Re: [PATCH] efi/memreserve: deal with memreserve entries in unmapped memory
@ 2019-06-10 16:27   ` Ray Jui
  0 siblings, 0 replies; 6+ messages in thread
From: Ray Jui @ 2019-06-10 16:27 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-efi
  Cc: marc.zyngier, bhsharma, Jonathan Richardson, linux-arm-kernel

Hi Ard,

On 6/10/2019 8:05 AM, Ard Biesheuvel wrote:
> Ensure that the EFI memreserve entries can be accessed, even if they
> are located in memory that the kernel (e.g., a crashkernel) omits from
> the linear map.
> 
> Reported-by: Jonathan Richardson <jonathan.richardson@broadcom.com>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Does it make sense to add a Fixes tag?

> ---
>  drivers/firmware/efi/efi.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
> index 16b2137d117c..4b7cf7bc0ded 100644
> --- a/drivers/firmware/efi/efi.c
> +++ b/drivers/firmware/efi/efi.c
> @@ -1009,14 +1009,16 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
>  
>  	/* first try to find a slot in an existing linked list entry */
>  	for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) {
> -		rsv = __va(prsv);
> +		rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB);
>  		index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size);
>  		if (index < rsv->size) {
>  			rsv->entry[index].base = addr;
>  			rsv->entry[index].size = size;
>  
> +			memunmap(rsv);
>  			return 0;
>  		}
> +		memunmap(rsv);
>  	}
>  
>  	/* no slot found - allocate a new linked list entry */
> @@ -1024,7 +1026,13 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
>  	if (!rsv)
>  		return -ENOMEM;
>  
> -	rsv->size = EFI_MEMRESERVE_COUNT(PAGE_SIZE);
> +	/*
> +	 * The memremap() call above assumes that a linux_efi_memreserve entry
> +	 * never crosses a page boundary, so let's ensure that this remains true
> +	 * even when kexec'ing a 4k pages kernel from a >4k pages kernel, by
> +	 * using SZ_4K explicitly in the size calculation below.
> +	 */
> +	rsv->size = EFI_MEMRESERVE_COUNT(SZ_4K);
>  	atomic_set(&rsv->count, 1);
>  	rsv->entry[0].base = addr;
>  	rsv->entry[0].size = size;
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] efi/memreserve: deal with memreserve entries in unmapped memory
  2019-06-10 15:05 ` Ard Biesheuvel
@ 2019-06-11  1:00   ` Jonathan Richardson
  -1 siblings, 0 replies; 6+ messages in thread
From: Jonathan Richardson @ 2019-06-11  1:00 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-efi
  Cc: linux-arm-kernel, marc.zyngier, bhsharma, ray.jui

On 06/10/2019 08:05 AM, Ard Biesheuvel wrote:
> Ensure that the EFI memreserve entries can be accessed, even if they
> are located in memory that the kernel (e.g., a crashkernel) omits from
> the linear map.
> 
> Reported-by: Jonathan Richardson <jonathan.richardson@broadcom.com>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  drivers/firmware/efi/efi.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
> index 16b2137d117c..4b7cf7bc0ded 100644
> --- a/drivers/firmware/efi/efi.c
> +++ b/drivers/firmware/efi/efi.c
> @@ -1009,14 +1009,16 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
>  
>  	/* first try to find a slot in an existing linked list entry */
>  	for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) {
> -		rsv = __va(prsv);
> +		rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB);
>  		index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size);
>  		if (index < rsv->size) {
>  			rsv->entry[index].base = addr;
>  			rsv->entry[index].size = size;
>  
> +			memunmap(rsv);
>  			return 0;
>  		}
> +		memunmap(rsv);
>  	}
>  
>  	/* no slot found - allocate a new linked list entry */
> @@ -1024,7 +1026,13 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
>  	if (!rsv)
>  		return -ENOMEM;
>  
> -	rsv->size = EFI_MEMRESERVE_COUNT(PAGE_SIZE);
> +	/*
> +	 * The memremap() call above assumes that a linux_efi_memreserve entry
> +	 * never crosses a page boundary, so let's ensure that this remains true
> +	 * even when kexec'ing a 4k pages kernel from a >4k pages kernel, by
> +	 * using SZ_4K explicitly in the size calculation below.
> +	 */
> +	rsv->size = EFI_MEMRESERVE_COUNT(SZ_4K);
>  	atomic_set(&rsv->count, 1);
>  	rsv->entry[0].base = addr;
>  	rsv->entry[0].size = size;
> 

Thanks for the fix. Tested and reviewed.

Reviewed-by: Jonathan Richardson <jonathan.richardson@broadcom.com>

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

* Re: [PATCH] efi/memreserve: deal with memreserve entries in unmapped memory
@ 2019-06-11  1:00   ` Jonathan Richardson
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Richardson @ 2019-06-11  1:00 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-efi
  Cc: marc.zyngier, bhsharma, ray.jui, linux-arm-kernel

On 06/10/2019 08:05 AM, Ard Biesheuvel wrote:
> Ensure that the EFI memreserve entries can be accessed, even if they
> are located in memory that the kernel (e.g., a crashkernel) omits from
> the linear map.
> 
> Reported-by: Jonathan Richardson <jonathan.richardson@broadcom.com>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  drivers/firmware/efi/efi.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
> index 16b2137d117c..4b7cf7bc0ded 100644
> --- a/drivers/firmware/efi/efi.c
> +++ b/drivers/firmware/efi/efi.c
> @@ -1009,14 +1009,16 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
>  
>  	/* first try to find a slot in an existing linked list entry */
>  	for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) {
> -		rsv = __va(prsv);
> +		rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB);
>  		index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size);
>  		if (index < rsv->size) {
>  			rsv->entry[index].base = addr;
>  			rsv->entry[index].size = size;
>  
> +			memunmap(rsv);
>  			return 0;
>  		}
> +		memunmap(rsv);
>  	}
>  
>  	/* no slot found - allocate a new linked list entry */
> @@ -1024,7 +1026,13 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
>  	if (!rsv)
>  		return -ENOMEM;
>  
> -	rsv->size = EFI_MEMRESERVE_COUNT(PAGE_SIZE);
> +	/*
> +	 * The memremap() call above assumes that a linux_efi_memreserve entry
> +	 * never crosses a page boundary, so let's ensure that this remains true
> +	 * even when kexec'ing a 4k pages kernel from a >4k pages kernel, by
> +	 * using SZ_4K explicitly in the size calculation below.
> +	 */
> +	rsv->size = EFI_MEMRESERVE_COUNT(SZ_4K);
>  	atomic_set(&rsv->count, 1);
>  	rsv->entry[0].base = addr;
>  	rsv->entry[0].size = size;
> 

Thanks for the fix. Tested and reviewed.

Reviewed-by: Jonathan Richardson <jonathan.richardson@broadcom.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2019-06-11  1:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-10 15:05 [PATCH] efi/memreserve: deal with memreserve entries in unmapped memory Ard Biesheuvel
2019-06-10 15:05 ` Ard Biesheuvel
2019-06-10 16:27 ` Ray Jui
2019-06-10 16:27   ` Ray Jui
2019-06-11  1:00 ` Jonathan Richardson
2019-06-11  1:00   ` Jonathan Richardson

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.