From patchwork Thu Jan 20 12:36:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 533587 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp55702imr; Thu, 20 Jan 2022 10:34:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJy325M6+5aXMq10vVTJyNqQSPOpWBhCjDbP6gZqtEEq3sDRzkp0fN0aUl8tQyfy0Sc5bz/J X-Received: by 2002:a5b:34a:: with SMTP id q10mr442812ybp.563.1642703653019; Thu, 20 Jan 2022 10:34:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642703653; cv=none; d=google.com; s=arc-20160816; b=RMixf6xqBxDIVicwJjKik67bjJ/JI8FfPLRUSB2nxALxsu/dhmEr/ojwjUkYIO0DTx 8eMAzGH2wXIdEFUx+prZ3V7sx8wpshYIEwWxwT+ldRYFrfIXcSFLWOLt4JXc0MBabY7s 0hesrxrNtIfHJO4usV+6+u55AM+wZzwQhYnQCnoqXbxW5X6OiJjVPTLKYNu9sns5wgwI RZDgMkr5+KgfZ33QDPJg1+kGOyJQG6GKq2bKRYvZ7lLEvB/8rjWW3othEA/oFKO3Qcj9 AveCyqzZi4yAb5L6GQqoTk1MZi83t+VK7aFH4WbSFPTYwYNRh1gvrNw2PUlxx0h0zxun iM+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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:to:from :dkim-signature; bh=j8Qp4NuYu0YJhHUjPY9NQXtXjfHNFnQLrtAOoxiHuYQ=; b=KXx+nQe19SbLPf5cFgfQhClBPIePIPlj/DD6DASUCubnf/kM5EZddm+bIoHlgBmXzh 8HisFIb7ZjuqpGF5RHfNw+mCMgSo3JWlN6yMmVqoHNzGMabI19YsdM1BONEiSoYrfU+C 5Z6+52JuIeAr2BpkN/rtmJv1TSGR+Hhv4eoIAQeean+bC7NsaZcQylE3fR+yKdtguhaI N3TfWnOFE34W536DaoZ/K//+156rzitb/cox750RjN/juI7FqG7YQaijaggAtMydnD59 CxqBCCThyZgJeN4B7YlFuHrMZ/abxcBVWPk1UNYkRkaMe7Nqpv9AgqvZTI8DPho8ftcb t9Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LSNtpn9Q; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v62si157298ywa.278.2022.01.20.10.34.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Jan 2022 10:34:13 -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=LSNtpn9Q; 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 Received: from localhost ([::1]:52214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAcGC-0008O4-Fx for patch@linaro.org; Thu, 20 Jan 2022 13:34:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAWgW-0004G4-NF for qemu-devel@nongnu.org; Thu, 20 Jan 2022 07:37:02 -0500 Received: from [2a00:1450:4864:20::335] (port=37566 helo=mail-wm1-x335.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nAWgU-0003HZ-Or for qemu-devel@nongnu.org; Thu, 20 Jan 2022 07:37:00 -0500 Received: by mail-wm1-x335.google.com with SMTP id l12-20020a7bc34c000000b003467c58cbdfso21599637wmj.2 for ; Thu, 20 Jan 2022 04:36:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=j8Qp4NuYu0YJhHUjPY9NQXtXjfHNFnQLrtAOoxiHuYQ=; b=LSNtpn9QM+Uo+XBQ5jseyw8sBh+09dGSBGWCsS1CeiptOIJSd9JoH1of2NDDCc4h9/ L+q2OwBSvJtm8frZ2EQSaoD0QscScN051PecyFGvE3WYHFXLwzrjHmUjd2AAQmSBCfbJ 7XwzyNoHUQryuDL+zTpph9X2NLBytHiuQb0cEJ88Gy2Mku0ww6vCQNic7jB0jpMgeVWV urqQK/Jyhio8GK/n6Cu/73v3KXwEn5jorUFa6TN8DYNwgs3khufeExiEGrFL/Foo74/0 4+Tf3LuGXF1LWvuuQxd2oveKGwTULafQ2t327Yow9etveQzFlyWQRWcI8nTZYd/J+QNH kfJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j8Qp4NuYu0YJhHUjPY9NQXtXjfHNFnQLrtAOoxiHuYQ=; b=S+s5vvAo0hqvQR9O8Kip3XldNZozdQhQ5q9qGyEBpS9TRPJd6uxXq4bGn6X1T4Sxra b4I6eXoQGDovbdTfGCEB4g9XSIbbo+IVb/4FiXvWE/2rpPeDHN5/H3G0+f3kDln+x+qs vxMuGkRd93ToSQ1Gx+a1HnJwh1LXGkaRT3xD7NawGpp7RDrYzmjgvN8q5LXWw0uc9ix+ p53SzWnaoHczL/gRqtLKKK2wCiTU8oZAdF4qy8avSqbnaIJ0zePaMzNXsa3lT28y9qFI +emHR3LI/mwjEjhvrcyNWA7Wr5GNPkMTeOERIJxGUBlkVDEU75ljjVoBbA4C3YhqqTFM beaQ== X-Gm-Message-State: AOAM531wo3jYxdEZmutPMlQjGc39HXYUrUa0xuqJTSSwLN7ZiZzK1dlp Bn7SzUYx8wzkl3oOS51MMOV3XK7g4AQAiA== X-Received: by 2002:a5d:5601:: with SMTP id l1mr33999201wrv.213.1642682217519; Thu, 20 Jan 2022 04:36:57 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id t8sm7993324wmq.43.2022.01.20.04.36.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 04:36:57 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 20/38] hw/arm/virt: Disable highmem devices that don't fit in the PA range Date: Thu, 20 Jan 2022 12:36:12 +0000 Message-Id: <20220120123630.267975-21-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220120123630.267975-1-peter.maydell@linaro.org> References: <20220120123630.267975-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::335 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x335.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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" From: Marc Zyngier In order to only keep the highmem devices that actually fit in the PA range, check their location against the range and update highest_gpa if they fit. If they don't, mark them as disabled. Signed-off-by: Marc Zyngier Reviewed-by: Eric Auger Message-id: 20220114140741.1358263-6-maz@kernel.org Signed-off-by: Peter Maydell --- hw/arm/virt.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 8627f5ab953..8d02c2267d0 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1719,21 +1719,43 @@ static void virt_set_memmap(VirtMachineState *vms, int pa_bits) base = vms->memmap[VIRT_MEM].base + LEGACY_RAMLIMIT_BYTES; } + /* We know for sure that at least the memory fits in the PA space */ + vms->highest_gpa = memtop - 1; + for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) { hwaddr size = extended_memmap[i].size; + bool fits; base = ROUND_UP(base, size); vms->memmap[i].base = base; vms->memmap[i].size = size; + + /* + * Check each device to see if they fit in the PA space, + * moving highest_gpa as we go. + * + * For each device that doesn't fit, disable it. + */ + fits = (base + size) <= BIT_ULL(pa_bits); + if (fits) { + vms->highest_gpa = base + size - 1; + } + + switch (i) { + case VIRT_HIGH_GIC_REDIST2: + vms->highmem_redists &= fits; + break; + case VIRT_HIGH_PCIE_ECAM: + vms->highmem_ecam &= fits; + break; + case VIRT_HIGH_PCIE_MMIO: + vms->highmem_mmio &= fits; + break; + } + base += size; } - /* - * If base fits within pa_bits, all good. If it doesn't, limit it - * to the end of RAM, which is guaranteed to fit within pa_bits. - */ - vms->highest_gpa = (base <= BIT_ULL(pa_bits) ? base : memtop) - 1; - if (device_memory_size > 0) { ms->device_memory = g_malloc0(sizeof(*ms->device_memory)); ms->device_memory->base = device_memory_base;