linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH kvmtool] arm64: pvtime: Use correct region size
@ 2022-06-29 10:39 Alexandru Elisei
  2022-06-29 14:33 ` Andre Przywara
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alexandru Elisei @ 2022-06-29 10:39 UTC (permalink / raw)
  To: will, julien.thierry.kdev, maz, linux-arm-kernel, kvmarm,
	andre.przywara, pierre.gondois, sebastianene

pvtime uses ARM_PVTIME_BASE instead of ARM_PVTIME_SIZE for the size of the
memory region given to the guest, which causes to the following error when
creating a flash device (via the -F/--flash command line argument):

  Error: RAM (read-only) region [2000000-27fffff] would overlap RAM region [1020000-203ffff]

The read-only region represents the guest memory where the flash image is
copied by kvmtool. The region starting at 0x102_0000 (ARM_PVTIME_BASE) is
the pvtime region, which should be 64K in size. kvmtool erroneously creates
the region to be ARM_PVTIME_BASE in size instead, and the last address
becomes:

ARM_PVTIME_BASE + ARM_PVTIME_BASE - 1 = 0x102_0000 + 0x102_0000 - 1 = 0x203_ffff

which corresponds to the end of the region from the error message.

Do the right thing and make the pvtime memory region ARM_PVTIME_SIZE = 64K
bytes, as it was intended.

Fixes: 7d4671e5d372 ("aarch64: Add stolen time support")
Reported-by: Pierre Gondois <pierre.gondois@arm.com>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arm/aarch64/pvtime.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arm/aarch64/pvtime.c b/arm/aarch64/pvtime.c
index a49cf3ed5478..2933ac7ca959 100644
--- a/arm/aarch64/pvtime.c
+++ b/arm/aarch64/pvtime.c
@@ -14,15 +14,15 @@ static int pvtime__alloc_region(struct kvm *kvm)
 	char *mem;
 	int ret = 0;
 
-	mem = mmap(NULL, ARM_PVTIME_BASE, PROT_RW,
+	mem = mmap(NULL, ARM_PVTIME_SIZE, PROT_RW,
 		   MAP_ANON_NORESERVE, -1, 0);
 	if (mem == MAP_FAILED)
 		return -errno;
 
 	ret = kvm__register_ram(kvm, ARM_PVTIME_BASE,
-				ARM_PVTIME_BASE, mem);
+				ARM_PVTIME_SIZE, mem);
 	if (ret) {
-		munmap(mem, ARM_PVTIME_BASE);
+		munmap(mem, ARM_PVTIME_SIZE);
 		return ret;
 	}
 
@@ -36,8 +36,8 @@ static int pvtime__teardown_region(struct kvm *kvm)
 		return 0;
 
 	kvm__destroy_mem(kvm, ARM_PVTIME_BASE,
-			 ARM_PVTIME_BASE, usr_mem);
-	munmap(usr_mem, ARM_PVTIME_BASE);
+			 ARM_PVTIME_SIZE, usr_mem);
+	munmap(usr_mem, ARM_PVTIME_SIZE);
 	usr_mem = NULL;
 	return 0;
 }
-- 
2.36.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] 4+ messages in thread

* Re: [PATCH kvmtool] arm64: pvtime: Use correct region size
  2022-06-29 10:39 [PATCH kvmtool] arm64: pvtime: Use correct region size Alexandru Elisei
@ 2022-06-29 14:33 ` Andre Przywara
  2022-07-01 15:29 ` Sebastian Ene
  2022-07-01 15:41 ` Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: Andre Przywara @ 2022-06-29 14:33 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: will, julien.thierry.kdev, maz, linux-arm-kernel, kvmarm,
	pierre.gondois, sebastianene

On Wed, 29 Jun 2022 11:39:05 +0100
Alexandru Elisei <alexandru.elisei@arm.com> wrote:

Hi,

> pvtime uses ARM_PVTIME_BASE instead of ARM_PVTIME_SIZE for the size of the
> memory region given to the guest, which causes to the following error when
> creating a flash device (via the -F/--flash command line argument):
> 
>   Error: RAM (read-only) region [2000000-27fffff] would overlap RAM region [1020000-203ffff]
> 
> The read-only region represents the guest memory where the flash image is
> copied by kvmtool. The region starting at 0x102_0000 (ARM_PVTIME_BASE) is
> the pvtime region, which should be 64K in size. kvmtool erroneously creates
> the region to be ARM_PVTIME_BASE in size instead, and the last address
> becomes:
> 
> ARM_PVTIME_BASE + ARM_PVTIME_BASE - 1 = 0x102_0000 + 0x102_0000 - 1 = 0x203_ffff
> 
> which corresponds to the end of the region from the error message.
> 
> Do the right thing and make the pvtime memory region ARM_PVTIME_SIZE = 64K
> bytes, as it was intended.
> 
> Fixes: 7d4671e5d372 ("aarch64: Add stolen time support")
> Reported-by: Pierre Gondois <pierre.gondois@arm.com>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Oops, this looks indeed like a glaring bug, PVTIME_SIZE was not used
anywhere.

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> ---
>  arm/aarch64/pvtime.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/arm/aarch64/pvtime.c b/arm/aarch64/pvtime.c
> index a49cf3ed5478..2933ac7ca959 100644
> --- a/arm/aarch64/pvtime.c
> +++ b/arm/aarch64/pvtime.c
> @@ -14,15 +14,15 @@ static int pvtime__alloc_region(struct kvm *kvm)
>  	char *mem;
>  	int ret = 0;
>  
> -	mem = mmap(NULL, ARM_PVTIME_BASE, PROT_RW,
> +	mem = mmap(NULL, ARM_PVTIME_SIZE, PROT_RW,
>  		   MAP_ANON_NORESERVE, -1, 0);
>  	if (mem == MAP_FAILED)
>  		return -errno;
>  
>  	ret = kvm__register_ram(kvm, ARM_PVTIME_BASE,
> -				ARM_PVTIME_BASE, mem);
> +				ARM_PVTIME_SIZE, mem);
>  	if (ret) {
> -		munmap(mem, ARM_PVTIME_BASE);
> +		munmap(mem, ARM_PVTIME_SIZE);
>  		return ret;
>  	}
>  
> @@ -36,8 +36,8 @@ static int pvtime__teardown_region(struct kvm *kvm)
>  		return 0;
>  
>  	kvm__destroy_mem(kvm, ARM_PVTIME_BASE,
> -			 ARM_PVTIME_BASE, usr_mem);
> -	munmap(usr_mem, ARM_PVTIME_BASE);
> +			 ARM_PVTIME_SIZE, usr_mem);
> +	munmap(usr_mem, ARM_PVTIME_SIZE);
>  	usr_mem = NULL;
>  	return 0;
>  }


_______________________________________________
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] 4+ messages in thread

* Re: [PATCH kvmtool] arm64: pvtime: Use correct region size
  2022-06-29 10:39 [PATCH kvmtool] arm64: pvtime: Use correct region size Alexandru Elisei
  2022-06-29 14:33 ` Andre Przywara
@ 2022-07-01 15:29 ` Sebastian Ene
  2022-07-01 15:41 ` Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Ene @ 2022-07-01 15:29 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: will, julien.thierry.kdev, maz, linux-arm-kernel, kvmarm, pierre.gondois

On Wed, Jun 29, 2022 at 11:39:05AM +0100, Alexandru Elisei wrote:
> pvtime uses ARM_PVTIME_BASE instead of ARM_PVTIME_SIZE for the size of the
> memory region given to the guest, which causes to the following error when
> creating a flash device (via the -F/--flash command line argument):
> 
>   Error: RAM (read-only) region [2000000-27fffff] would overlap RAM region [1020000-203ffff]
> 
> The read-only region represents the guest memory where the flash image is
> copied by kvmtool. The region starting at 0x102_0000 (ARM_PVTIME_BASE) is
> the pvtime region, which should be 64K in size. kvmtool erroneously creates
> the region to be ARM_PVTIME_BASE in size instead, and the last address
> becomes:
> 
> ARM_PVTIME_BASE + ARM_PVTIME_BASE - 1 = 0x102_0000 + 0x102_0000 - 1 = 0x203_ffff
> 
> which corresponds to the end of the region from the error message.
> 
> Do the right thing and make the pvtime memory region ARM_PVTIME_SIZE = 64K
> bytes, as it was intended.
> 
> Fixes: 7d4671e5d372 ("aarch64: Add stolen time support")
> Reported-by: Pierre Gondois <pierre.gondois@arm.com>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  arm/aarch64/pvtime.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 

Hi,

Thanks for fixing this.
Reviewed-by: Sebastian Ene <sebastianene@google.com>

> diff --git a/arm/aarch64/pvtime.c b/arm/aarch64/pvtime.c
> index a49cf3ed5478..2933ac7ca959 100644
> --- a/arm/aarch64/pvtime.c
> +++ b/arm/aarch64/pvtime.c
> @@ -14,15 +14,15 @@ static int pvtime__alloc_region(struct kvm *kvm)
>  	char *mem;
>  	int ret = 0;
>  
> -	mem = mmap(NULL, ARM_PVTIME_BASE, PROT_RW,
> +	mem = mmap(NULL, ARM_PVTIME_SIZE, PROT_RW,
>  		   MAP_ANON_NORESERVE, -1, 0);
>  	if (mem == MAP_FAILED)
>  		return -errno;
>  
>  	ret = kvm__register_ram(kvm, ARM_PVTIME_BASE,
> -				ARM_PVTIME_BASE, mem);
> +				ARM_PVTIME_SIZE, mem);
>  	if (ret) {
> -		munmap(mem, ARM_PVTIME_BASE);
> +		munmap(mem, ARM_PVTIME_SIZE);
>  		return ret;
>  	}
>  
> @@ -36,8 +36,8 @@ static int pvtime__teardown_region(struct kvm *kvm)
>  		return 0;
>  
>  	kvm__destroy_mem(kvm, ARM_PVTIME_BASE,
> -			 ARM_PVTIME_BASE, usr_mem);
> -	munmap(usr_mem, ARM_PVTIME_BASE);
> +			 ARM_PVTIME_SIZE, usr_mem);
> +	munmap(usr_mem, ARM_PVTIME_SIZE);
>  	usr_mem = NULL;
>  	return 0;
>  }
> -- 
> 2.36.1
> 

_______________________________________________
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] 4+ messages in thread

* Re: [PATCH kvmtool] arm64: pvtime: Use correct region size
  2022-06-29 10:39 [PATCH kvmtool] arm64: pvtime: Use correct region size Alexandru Elisei
  2022-06-29 14:33 ` Andre Przywara
  2022-07-01 15:29 ` Sebastian Ene
@ 2022-07-01 15:41 ` Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2022-07-01 15:41 UTC (permalink / raw)
  To: julien.thierry.kdev, andre.przywara, maz, Alexandru Elisei,
	sebastianene, pierre.gondois, kvmarm, linux-arm-kernel
  Cc: catalin.marinas, kernel-team, Will Deacon

On Wed, 29 Jun 2022 11:39:05 +0100, Alexandru Elisei wrote:
> pvtime uses ARM_PVTIME_BASE instead of ARM_PVTIME_SIZE for the size of the
> memory region given to the guest, which causes to the following error when
> creating a flash device (via the -F/--flash command line argument):
> 
>   Error: RAM (read-only) region [2000000-27fffff] would overlap RAM region [1020000-203ffff]
> 
> The read-only region represents the guest memory where the flash image is
> copied by kvmtool. The region starting at 0x102_0000 (ARM_PVTIME_BASE) is
> the pvtime region, which should be 64K in size. kvmtool erroneously creates
> the region to be ARM_PVTIME_BASE in size instead, and the last address
> becomes:
> 
> [...]

Applied to kvmtool (master), thanks!

[1/1] arm64: pvtime: Use correct region size
      https://git.kernel.org/will/kvmtool/c/6a1f699108e5

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

_______________________________________________
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] 4+ messages in thread

end of thread, other threads:[~2022-07-01 15:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29 10:39 [PATCH kvmtool] arm64: pvtime: Use correct region size Alexandru Elisei
2022-06-29 14:33 ` Andre Przywara
2022-07-01 15:29 ` Sebastian Ene
2022-07-01 15:41 ` Will Deacon

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