From patchwork Tue Dec 3 11:31:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 846951 Delivered-To: patch@linaro.org Received: by 2002:a5d:44cd:0:b0:385:e875:8a9e with SMTP id z13csp424591wrr; Tue, 3 Dec 2024 03:33:06 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWUO9VukIIYK3/mCA/Ka+rRCSnIfsew1DyqkLQCWAIISy7HsXQqns8Ld/dr36I+IpIv3pGP0A==@linaro.org X-Google-Smtp-Source: AGHT+IEwMLWmDzkX7MpFjHa9BN6fGAIL84hn74HygC3ZxuPFLVVsnMKr46Dx6D7msMIVHO7lgvVA X-Received: by 2002:ad4:5768:0:b0:6d4:215d:91b5 with SMTP id 6a1803df08f44-6d8b73083b5mr30761136d6.11.1733225585981; Tue, 03 Dec 2024 03:33:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733225585; cv=none; d=google.com; s=arc-20240605; b=HF/VnK4wlCz74AtlRuFJIKsVv4dR5eu2gfzUlrYeBhWqxghNb46nzBtVeY5QmQUKWK ZHGS4gaoEMw68XYdr/AxjAHL4IWvtP1fQ6GCX2YNt/5AvYoeHBDvo4zVjHMqkY6AidyS oImESxWJamzqqmxBz1X/a47obXPkFu6luFqB6pz0yw5viPjbEEh5NnkmUKQVwQuOfHIU LSXa/pQzZxo/BF7DOxuu44HqaayPe1+JA4TOjOfm9Ol3X4Dqwa/Ut+X+Sj55etGsQMQ9 Y6CWEeLPhiO3+UZdIiKgOQIIurqkw9JZQOVTGl+JOqn0CBolTkYZskvTv3XXTmcpm7yV D63Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GJvSsd8dR9/3SHrqkOdjWUtSWpDGfzavxvd+Z0C+v1Q=; fh=YN/nZ5OGvfh0ZEPp6b/lO5lvfU2jXDgLoNmPtocUoJM=; b=BA7LQbE6S9T6g4iYqju7/PzVKeQAYokWmIoTcz7jSYUniNwHyqgO9ScqCChjpVMUGe DrRCfxB+vf6pufSQgU3zeZmC0291rBw3zNVHlryyTKYVp0EhUNTAdw1HrlnLqlhWyCmk F5rDoJIV2Uy/M8kjqCVDBsKcQy+xdxlrRI6pDPoVkyuyLKXtj1JpSAmvTnWC8l1qJN/z 41nrGiCeVJn1Rdjw5XMC6IVZtDJFCvDeKi8tCziDg7SFhUXvC4ZV+kOfP27GpBHH3sy1 TG3aV6MhKVEVMYuxMqHe8zrSJOGaJ13hd9YUUg/Uih5613k9fgw7lFRr8DV7N+Rzttdt SPVw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RbbrPkYL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6d89c51918fsi72222106d6.364.2024.12.03.03.33.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Dec 2024 03:33:05 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RbbrPkYL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIR8i-0000cM-3q; Tue, 03 Dec 2024 06:32:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIR8g-0000YV-UD for qemu-devel@nongnu.org; Tue, 03 Dec 2024 06:32:22 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIR8f-0000ai-B1 for qemu-devel@nongnu.org; Tue, 03 Dec 2024 06:32:22 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-385e1f12c82so3576524f8f.2 for ; Tue, 03 Dec 2024 03:32:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733225539; x=1733830339; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GJvSsd8dR9/3SHrqkOdjWUtSWpDGfzavxvd+Z0C+v1Q=; b=RbbrPkYLUgh0OkvoPxNUo44GBV5SVr2sZ7XqwWzVUdG8ZRFnQSHkI8WGlPa9RNyNRk A7N7RLjFoE9YAiICO6CKAQ0OF5xp1JoWSeE8rjFDDnWXikJFCPB84EAtmWbqGMErmzdX NBFK1+JPOlslIbYwbpo+1lqAlj1tAQzQVPYAWGgZ4wRVrL/fOTp0iYjJMkDxa/oWq8SN FjUdnDb3nmrJ/XkmD9LERvh8mKQ80KstZdxa/uJYlM+I2+Ahv29E/ZRwdnI0a7bpq0Yx qXEALUN5WUEXp94L6999fL4gelWPHKpSAlxoujaW/h0d91cz2URF4gDp0Nm8Ir9t3ZxW /YWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733225539; x=1733830339; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GJvSsd8dR9/3SHrqkOdjWUtSWpDGfzavxvd+Z0C+v1Q=; b=aW6lqZFkLhRNZk0z4aL3r4nJpWtSJ3Xi1n96R8vQQAQ5gWSQ4+AdkcnGdzKqNBbflL totH9sA+hYyhIrYI8MFhc0/sxUj7DjjXvDzwHhQm8Jby7ksgclvTWimzjp4J8x0Ozdxq aOy+kaRlBkCzPykxuP7sHvx14F2HeFf4kzrWW/WAcMt1uwBIgFnekXCkJ+dxK3uw7Yx1 zXwxYa7lWehOaq9iAF54UbaQfo6ETFoOcOaSf/XnSfnSSE+uZgx5xbwOj2hdgaddDgrB hZSH5Vedw/SQwqaWTwpceI/9LZ6+nK7au4KJaQAV9jw6Yu6KY72o8yOD25j5WGpi1c3U DRog== X-Gm-Message-State: AOJu0YwjYMsylXjt6X/Zs1a6l2yiA+m6eGuyBtjnsUrRLU/a3UhFH21M 1lbCQ8fwKzD4rBEXg88GdUZOt7H/1TpDhFUhll4BHMIhAym9N+5MfgRR//dmAaTVqOY2l/ETonX N8n4= X-Gm-Gg: ASbGncsYoLDtlblISmTAI+al1aJGS58nnSrGVU3rIQXV2yDTXuUScW/Yeol7nbBolqj k2L1HB3XjlRfnodtgebALtcrOSuWAgWwhzBNAwY72Tt75RAyAz9hLDupKo04GYfWncGoHCVGe1o GnRQ1G/uIMBRfvl0xoqPCW9S25H8gCgIYQ9rh91GDn4dlEtHWoGhPXvGE3zYQ5k1SL4AhhmoBUx rmsnYfKoISBs0Yk+hTV7Po1fZLO3V5cnjRcz+AeOPpT2sYSyBELmf0PUslSAOvNnlqA3H4o X-Received: by 2002:a05:6000:156c:b0:385:e88a:7037 with SMTP id ffacd0b85a97d-385fd3cd72emr1942211f8f.6.1733225538921; Tue, 03 Dec 2024 03:32:18 -0800 (PST) Received: from localhost.localdomain ([176.187.209.146]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-385f8448d32sm3687037f8f.96.2024.12.03.03.32.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 03:32:18 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Ani Sinha , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 07/13] hw/core/machine: diagnose wrapping of maxmem Date: Tue, 3 Dec 2024 12:31:34 +0100 Message-ID: <20241203113140.63513-8-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241203113140.63513-1-philmd@linaro.org> References: <20241203113140.63513-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=philmd@linaro.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: 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é Tested-by: Ani Sinha Reviewed-by: Ani Sinha Message-ID: <20241127114057.255995-1-berrange@redhat.com> Signed-off-by: Philippe Mathieu-Daudé --- 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 a35c4a8faec..f29fe959647 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 "