qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/core/machine: diagnose wrapping of maxmem
@ 2024-11-27 11:40 Daniel P. Berrangé
  2024-11-27 13:04 ` Ani Sinha
  2024-12-03 15:39 ` Philippe Mathieu-Daudé
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel P. Berrangé @ 2024-11-27 11:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yanan Wang, Eduardo Habkost, Ani Sinha, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Zhao Liu, Daniel P. Berrangé

The 'maxmem' parameter parsed on the command line is held in uint64_t
and then assigned to the MachineState field that is 'ram_addr_t'. This
assignment will wrap on 32-bit hosts, silently changing the user's
config request if it were over-sized.

Improve the existing diagnositics for validating 'size', and add the
same diagnostics for 'maxmem'

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/core/machine.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index a35c4a8fae..f29fe95964 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -598,11 +598,19 @@ static void machine_set_mem(Object *obj, Visitor *v, const char *name,
         mem->size = mc->fixup_ram_size(mem->size);
     }
     if ((ram_addr_t)mem->size != mem->size) {
-        error_setg(errp, "ram size too large");
+        error_setg(errp, "ram size %llu exceeds permitted maximum %llu",
+                   (unsigned long long)mem->size,
+                   (unsigned long long)RAM_ADDR_MAX);
         goto out_free;
     }
 
     if (mem->has_max_size) {
+        if ((ram_addr_t)mem->max_size != mem->max_size) {
+            error_setg(errp, "ram size %llu exceeds permitted maximum %llu",
+                       (unsigned long long)mem->max_size,
+                       (unsigned long long)RAM_ADDR_MAX);
+            goto out_free;
+        }
         if (mem->max_size < mem->size) {
             error_setg(errp, "invalid value of maxmem: "
                        "maximum memory size (0x%" PRIx64 ") must be at least "
-- 
2.46.0



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

* Re: [PATCH] hw/core/machine: diagnose wrapping of maxmem
  2024-11-27 11:40 [PATCH] hw/core/machine: diagnose wrapping of maxmem Daniel P. Berrangé
@ 2024-11-27 13:04 ` Ani Sinha
  2024-12-03 15:39 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 3+ messages in thread
From: Ani Sinha @ 2024-11-27 13:04 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Yanan Wang, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Zhao Liu

On Wed, Nov 27, 2024 at 5:11 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> The 'maxmem' parameter parsed on the command line is held in uint64_t
> and then assigned to the MachineState field that is 'ram_addr_t'. This
> assignment will wrap on 32-bit hosts, silently changing the user's
> config request if it were over-sized.

With this patch, for the failing test_mem_addr_space test in 32-bit, we get:

Traceback (most recent call last):
  File "/builds/qemu/tests/functional/test_mem_addr_space.py", line
256, in test_phybits_low_tcg_q35_71_amd_41bits
    self.assertRegex(self.vm.get_log(), r'phys-bits too low')
AssertionError: Regex didn't match: 'phys-bits too low' not found in
'qemu-system-x86_64: ram size 1065151889408 exceeds permitted maximum
4294967295\n'

Traceback (most recent call last):
  File "/builds/qemu/tests/functional/test_mem_addr_space.py", line
294, in test_phybits_low_tcg_q35_intel_cxl
    self.assertRegex(self.vm.get_log(), r'phys-bits too low')
AssertionError: Regex didn't match: 'phys-bits too low' not found in
'qemu-system-x86_64: ram size 1059783180288 exceeds permitted maximum
4294967295\n'

etc.

>
> Improve the existing diagnositics for validating 'size', and add the
> same diagnostics for 'maxmem'
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Tested by: Ani Sinha <anisinha@redhat.com>
Reviewed-by: Ani Sinha <anisinha@redhat.com>

> ---
>  hw/core/machine.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index a35c4a8fae..f29fe95964 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -598,11 +598,19 @@ static void machine_set_mem(Object *obj, Visitor *v, const char *name,
>          mem->size = mc->fixup_ram_size(mem->size);
>      }
>      if ((ram_addr_t)mem->size != mem->size) {
> -        error_setg(errp, "ram size too large");
> +        error_setg(errp, "ram size %llu exceeds permitted maximum %llu",
> +                   (unsigned long long)mem->size,
> +                   (unsigned long long)RAM_ADDR_MAX);
>          goto out_free;
>      }
>
>      if (mem->has_max_size) {
> +        if ((ram_addr_t)mem->max_size != mem->max_size) {
> +            error_setg(errp, "ram size %llu exceeds permitted maximum %llu",
> +                       (unsigned long long)mem->max_size,
> +                       (unsigned long long)RAM_ADDR_MAX);
> +            goto out_free;
> +        }
>          if (mem->max_size < mem->size) {
>              error_setg(errp, "invalid value of maxmem: "
>                         "maximum memory size (0x%" PRIx64 ") must be at least "
> --
> 2.46.0
>



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

* Re: [PATCH] hw/core/machine: diagnose wrapping of maxmem
  2024-11-27 11:40 [PATCH] hw/core/machine: diagnose wrapping of maxmem Daniel P. Berrangé
  2024-11-27 13:04 ` Ani Sinha
@ 2024-12-03 15:39 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-03 15:39 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Yanan Wang, Eduardo Habkost, Ani Sinha, Marcel Apfelbaum,
	Zhao Liu

On 27/11/24 12:40, Daniel P. Berrangé wrote:
> The 'maxmem' parameter parsed on the command line is held in uint64_t
> and then assigned to the MachineState field that is 'ram_addr_t'. This
> assignment will wrap on 32-bit hosts, silently changing the user's
> config request if it were over-sized.
> 
> Improve the existing diagnositics for validating 'size', and add the
> same diagnostics for 'maxmem'
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   hw/core/machine.c | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)

Patch queued, thanks.


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

end of thread, other threads:[~2024-12-03 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-27 11:40 [PATCH] hw/core/machine: diagnose wrapping of maxmem Daniel P. Berrangé
2024-11-27 13:04 ` Ani Sinha
2024-12-03 15:39 ` Philippe Mathieu-Daudé

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