From: Nikunj A Dadhania <nikunj@amd.com>
To: <qemu-devel@nongnu.org>, Paolo Bonzini <pbonzini@redhat.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
Sean Christopherson <sean.j.christopherson@intel.com>,
<f4bug@amsat.org>, <Abraham.Shaju@amd.com>, <bharata@amd.com>,
<nikunj@amd.com>
Subject: [PATCH] x86: cpu: Error out if memory exceeds addressable range
Date: Mon, 18 Jul 2022 13:47:34 +0530 [thread overview]
Message-ID: <20220718081734.135598-1-nikunj@amd.com> (raw)
Currently it is possible to start a guest with memory that is beyond
the addressable range of CPU and QEMU does not even warn about it.
The default phys_bits is 40 and can address 1TB. However it allows to
start a guest with greater than 1TB memory.
Prevent this by erroring out in such a scenario.
Reported-by: Shaju Abraham <Abraham.Shaju@amd.com>
Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
---
target/i386/cpu.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 6a57ef13af..1afbdbac7d 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6376,6 +6376,7 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu)
static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
{
+ MachineState *machine = MACHINE(qdev_get_machine());
CPUState *cs = CPU(dev);
X86CPU *cpu = X86_CPU(dev);
X86CPUClass *xcc = X86_CPU_GET_CLASS(dev);
@@ -6541,6 +6542,15 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
}
}
+ if (BIT_ULL(cpu->phys_bits) < machine->maxram_size) {
+ error_setg(&local_err, "cannot setup guest memory: "
+ "%s memory(%lu MiB) exceeds addressable limit(%llu MiB)",
+ machine->maxram_size == machine->ram_size ? "" : "max",
+ machine->maxram_size / MiB,
+ BIT_ULL(cpu->phys_bits) / MiB);
+ goto out;
+ }
+
/* Cache information initialization */
if (!cpu->legacy_cache) {
if (!xcc->model || !xcc->model->cpudef->cache_info) {
--
2.32.0
next reply other threads:[~2022-07-18 8:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-18 8:17 Nikunj A Dadhania [this message]
2022-07-18 12:42 ` [PATCH] x86: cpu: Error out if memory exceeds addressable range Igor Mammedov
2022-07-18 13:10 ` Nikunj A. Dadhania
2022-07-18 13:45 ` Joao Martins
2022-07-18 13:54 ` Nikunj A. Dadhania
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220718081734.135598-1-nikunj@amd.com \
--to=nikunj@amd.com \
--cc=Abraham.Shaju@amd.com \
--cc=bharata@amd.com \
--cc=f4bug@amsat.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sean.j.christopherson@intel.com \
--cc=vkuznets@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).