From nobody Fri Apr 19 19:34:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1574992580; cv=none; d=zohomail.com; s=zohoarc; b=eoUM3l/r3xkRKbXXDO6iFoXSLRxWVIV3kWOEFgmBUBKpn+y0Ijc5YL4SEUqC4aX1Ataqf/4gmObX1hPONUM5tWnqqoqAmJqQBanqeRcXd5x1mHSdr7oSxxBKDEYUA0owXeqfxiaeFYLd1vZptMz0cUwxHFaD2RhAfp0xoEs47Zo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574992580; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lwKzm3clWwghJhXF/hHfNdwXGVZpsAAHSXQsoDt7W5w=; b=ZFe5XHnsJBuZ4xLSIF+toOp1fgL5VEgcPmx2cWc+n2Q+zpTn5qFaEeR7inbdKk1FHUriWUPl16J8GqPXSxZpeT+5REAInhDxTfvp7dyA5zljkmQekWjgZ5ZuhlBuByaYpJctdRUEDru0H81ABFDaJ3yoZFLrV9j+Gf1UqWsEZD8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574992580716324.7881198620655; Thu, 28 Nov 2019 17:56:20 -0800 (PST) Received: from localhost ([::1]:54364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaVW4-000194-1k for importer@patchew.org; Thu, 28 Nov 2019 20:56:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56363) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaVBs-0002Xs-0t for qemu-devel@nongnu.org; Thu, 28 Nov 2019 20:35:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iaVBm-0003Mr-VP for qemu-devel@nongnu.org; Thu, 28 Nov 2019 20:35:20 -0500 Received: from ozlabs.org ([203.11.71.1]:36763) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iaVBj-0002uq-S3; Thu, 28 Nov 2019 20:35:17 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 47PHBM6Kxjz9sPZ; Fri, 29 Nov 2019 12:35:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1574991307; bh=Z/RibPu8alRi+iP9uoUSxLDuw1fy/hPaLz1Ra2kT/A0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iRRivz4Dq5pCz48wFsIPSE+se8SxY9btGQUC619DnFFabYKU7D0AekgIQQMevj6l7 gFpyYI8vAr1BbVIu1rtrakQMLhxHrIaFjoo9P7T5625pyCzcOPFpJH4X1AyTH73TlP yfEJbKaHknnz/SfunkY/xrHCjJvZBAqRS22lzhIQ= From: David Gibson To: groug@kaod.org, clg@kaod.org Subject: [for-5.0 1/4] spapr,ppc: Simplify signature of kvmppc_rma_size() Date: Fri, 29 Nov 2019 12:35:01 +1100 Message-Id: <20191129013504.145455-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191129013504.145455-1-david@gibson.dropbear.id.au> References: <20191129013504.145455-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 203.11.71.1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aik@ozlabs.ru, lvivier@redhat.com, qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) Content-Type: text/plain; charset="utf-8" This function calculates the maximum size of the RMA as implied by the host's page size of structure of the VRMA (there are a number of other constraints on the RMA size which will supersede this one in many circumstances). The current interface takes the current RMA size estimate, and clamps it to the VRMA derived size. The only current caller passes in an arguably wrong value (it will match the current RMA estimate in some but not all cases). We want to fix that, but for now just keep concerns separated by having the KVM helper function just return the VRMA derived limit, and let the caller combine it with other constraints. We call the new function kvmppc_vrma_limit() to more clearly indicate its limited responsibility. The helper should only ever be called in the KVM enabled case, so replace its !CONFIG_KVM stub with an assert() rather than a dummy value. Signed-off-by: David Gibson Reviewed-by: Alexey Kardashevskiy Reviewed-by: Cedric Le Goater Reviewed-by: Greg Kurz --- hw/ppc/spapr.c | 5 +++-- target/ppc/kvm.c | 5 ++--- target/ppc/kvm_ppc.h | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index d9c9a2bcee..069bd04a8d 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1635,8 +1635,9 @@ void spapr_setup_hpt_and_vrma(SpaprMachineState *spap= r) spapr_reallocate_hpt(spapr, hpt_shift, &error_fatal); =20 if (spapr->vrma_adjust) { - spapr->rma_size =3D kvmppc_rma_size(spapr_node0_size(MACHINE(spapr= )), - spapr->htab_shift); + hwaddr vrma_limit =3D kvmppc_vrma_limit(spapr->htab_shift); + + spapr->rma_size =3D MIN(spapr_node0_size(MACHINE(spapr)), vrma_lim= it); } } =20 diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index c77f9848ec..09b3bd6443 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2101,7 +2101,7 @@ void kvmppc_hint_smt_possible(Error **errp) =20 =20 #ifdef TARGET_PPC64 -uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift) +uint64_t kvmppc_vrma_limit(unsigned int hash_shift) { struct kvm_ppc_smmu_info info; long rampagesize, best_page_shift; @@ -2128,8 +2128,7 @@ uint64_t kvmppc_rma_size(uint64_t current_size, unsig= ned int hash_shift) } } =20 - return MIN(current_size, - 1ULL << (best_page_shift + hash_shift - 7)); + return 1ULL << (best_page_shift + hash_shift - 7)); } #endif =20 diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index 98bd7d5da6..4f0eec4c1b 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -45,7 +45,7 @@ void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t pa= ge_shift, int *pfd, bool need_vfio); int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size); int kvmppc_reset_htab(int shift_hint); -uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift); +uint64_t kvmppc_vrma_limit(unsigned int hash_shift); bool kvmppc_has_cap_spapr_vfio(void); #endif /* !CONFIG_USER_ONLY */ bool kvmppc_has_cap_epr(void); @@ -241,10 +241,9 @@ static inline int kvmppc_reset_htab(int shift_hint) return 0; } =20 -static inline uint64_t kvmppc_rma_size(uint64_t current_size, - unsigned int hash_shift) +static inline uint64_t kvmppc_vrma_limit(unsigned int hash_shift) { - return ram_size; + g_assert_not_reached(); } =20 static inline bool kvmppc_hpt_needs_host_contiguous_pages(void) --=20 2.23.0 From nobody Fri Apr 19 19:34:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1574991882; cv=none; d=zohomail.com; s=zohoarc; b=J5jU7evy9Yo2aKk6MYorBThFQOYKeERNeSZ1c6qstaq4TBSZ3BLAH3tVSbJBlR9e6mrWIQFRXXSGfcMQNSdfsCSShgjbeJH1M2BJ508M0041Q/ZA4kxGhHXKCbcc3QDp+jJ6oKDnHVF5ud+NKQfW8v8R6ibahYyRucbQ2y9OHcM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574991882; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MxTDJ9o5fI1uwOOegJJFwetflmPV0gU2x2dhQ3H92so=; b=mHoEfW7ftuUQMZzOey4KQZGJboTmr3LhZ2SSjwu5dwbV2BvhSD3qp8Z/ENnjnUp2Epf9LhcCkvCzbZuxSICeGzdTHMUsH3s7jMGvZbSmyz2KCc85UqRLI59eRYL/8ldpCz7ojkFjihM505w+4++3qGuWz3aWCVYAIYa1AyMmB4g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574991882259793.7701254496566; Thu, 28 Nov 2019 17:44:42 -0800 (PST) Received: from localhost ([::1]:54330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaVKp-0005bg-V7 for importer@patchew.org; Thu, 28 Nov 2019 20:44:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56364) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaVBs-0002Xt-2l for qemu-devel@nongnu.org; Thu, 28 Nov 2019 20:35:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iaVBn-0003NC-0x for qemu-devel@nongnu.org; Thu, 28 Nov 2019 20:35:20 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:46247) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iaVBl-0002u2-7I; Thu, 28 Nov 2019 20:35:18 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 47PHBN0dW6z9sR6; Fri, 29 Nov 2019 12:35:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1574991308; bh=hBSmOLjboYCs3LRhKB40PU6tAVskKufJMskhs1PoeXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E7tGhJgMdJAvaG7752UO4OXQEj/tx9zsEZ8fGIUTxudumaaM7LboRnx3GoawZVJH9 Y4yEcz5TFhy7ReHMPMpCftYs1F9MuGPmEawXkrSDfrq9nwuRtP6y0dIO8uE6BXW0mK 5CmUr+VJH/jVb5vMeeUou5zH7Qn0+ahzgdDXlZBw= From: David Gibson To: groug@kaod.org, clg@kaod.org Subject: [for-5.0 2/4] spapr: Don't attempt to clamp RMA to VRMA constraint Date: Fri, 29 Nov 2019 12:35:02 +1100 Message-Id: <20191129013504.145455-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191129013504.145455-1-david@gibson.dropbear.id.au> References: <20191129013504.145455-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aik@ozlabs.ru, lvivier@redhat.com, qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) Content-Type: text/plain; charset="utf-8" The Real Mode Area (RMA) is the part of memory which a guest can access when in real (MMU off) mode. Of course, for a guest under KVM, the MMU isn't really turned off, it's just in a special translation mode - Virtual Real Mode Area (VRMA) - which looks like real mode in guest mode. The mechanics of how this works when in Hashed Page Table (HPT) mode, put a constraint on the size of the RMA, which depends on the size of the HPT. So, the latter part of spapr_setup_hpt_and_vrma() clamps the RMA we advertise to the guest based on this VRMA limit. There are several things wrong with this: 1) spapr_setup_hpt_and_vrma() doesn't actually clamp, it takes the minimum of Node 0 memory size and the VRMA limit. That will *often* work the same as clamping, but there can be other constraints on RMA size which supersede Node 0 memory size. We have real bugs caused by this (currently worked around in the guest kernel) 2) Some callers of spapr_setup_hpt_and_vrma() are in a situation where we're past the point that we can actually advertise an RMA limit to the guest 3) But most fundamentally, the VRMA limit depends on host configuration (page size) which shouldn't be visible to the guest, but this partially exposes it. This can cause problems with migration in certain edge cases, although we will mostly get away with it. In practice, this clamping is almost never applied anyway. With 64kiB pages and the normal rules for sizing of the HPT, the theoretical VRMA limit will be 4x(guest memory size) and so never hit. It will hit with 4kiB pages, where it will be (guest memory size)/4. However all mainstream distro kernels for POWER have used a 64kiB page size for at least 10 years. So, simply replace this logic with a check that the RMA we've calculated based only on guest visible configuration will fit within the host implied VRMA limit. This can break if running HPT guests on a host kernel with 4kiB page size. As noted that's very rare. There also exist several possible workarounds: * Change the host kernel to use 64kiB pages * Use radix MMU (RPT) guests instead of HPT * Use 64kiB hugepages on the host to back guest memory * Increase the guest memory size so that the RMA hits one of the fixed limits before the RMA limit. This is relatively easy on POWER8 which has a 16GiB limit, harder on POWER9 which has a 1TiB limit. * Decrease guest memory size so that it's below the lower bound on VRMA limit (minimum HPT size is 256kiB, giving a minimum VRAM of 8MiB). Difficult in practice since modern guests tend to want 1-2GiB. * Use a guest NUMA configuration which artificially constrains the RMA within the VRMA limit (the RMA must always fit within Node 0). Previously, on KVM, we also temporarily reduced the rma_size to 256M so that the we'd load the kernel and initrd safely, regardless of the VRMA limit. This was a) confusing, b) could significantly limit the size of images we could load and c) introduced a behavioural difference between KVM and TCG. So we remove that as well. Signed-off-by: David Gibson Reviewed-by: Alexey Kardashevskiy --- hw/ppc/spapr.c | 28 ++++++++++------------------ hw/ppc/spapr_hcall.c | 4 ++-- include/hw/ppc/spapr.h | 3 +-- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 069bd04a8d..52c39daa99 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1618,7 +1618,7 @@ void spapr_reallocate_hpt(SpaprMachineState *spapr, i= nt shift, spapr_set_all_lpcrs(0, LPCR_HR | LPCR_UPRT); } =20 -void spapr_setup_hpt_and_vrma(SpaprMachineState *spapr) +void spapr_setup_hpt(SpaprMachineState *spapr) { int hpt_shift; =20 @@ -1634,10 +1634,16 @@ void spapr_setup_hpt_and_vrma(SpaprMachineState *sp= apr) } spapr_reallocate_hpt(spapr, hpt_shift, &error_fatal); =20 - if (spapr->vrma_adjust) { + if (kvm_enabled()) { hwaddr vrma_limit =3D kvmppc_vrma_limit(spapr->htab_shift); =20 - spapr->rma_size =3D MIN(spapr_node0_size(MACHINE(spapr)), vrma_lim= it); + /* Check our RMA fits in the possible VRMA */ + if (vrma_limit < spapr->rma_size) { + error_report("Unable to create %" HWADDR_PRIu + "MiB RMA (VRMA only allows %" HWADDR_PRIu "MiB", + spapr->rma_size / MiB, vrma_limit / MiB); + exit(EXIT_FAILURE); + } } } =20 @@ -1676,7 +1682,7 @@ static void spapr_machine_reset(MachineState *machine) spapr->patb_entry =3D PATE1_GR; spapr_set_all_lpcrs(LPCR_HR | LPCR_UPRT, LPCR_HR | LPCR_UPRT); } else { - spapr_setup_hpt_and_vrma(spapr); + spapr_setup_hpt(spapr); } =20 qemu_devices_reset(); @@ -2711,20 +2717,6 @@ static void spapr_machine_init(MachineState *machine) =20 spapr->rma_size =3D node0_size; =20 - /* With KVM, we don't actually know whether KVM supports an - * unbounded RMA (PR KVM) or is limited by the hash table size - * (HV KVM using VRMA), so we always assume the latter - * - * In that case, we also limit the initial allocations for RTAS - * etc... to 256M since we have no way to know what the VRMA size - * is going to be as it depends on the size of the hash table - * which isn't determined yet. - */ - if (kvm_enabled()) { - spapr->vrma_adjust =3D 1; - spapr->rma_size =3D MIN(spapr->rma_size, 0x10000000); - } - /* Actually we don't support unbounded RMA anymore since we added * proper emulation of HV mode. The max we can get is 16G which * also happens to be what we configure for PAPR mode so make sure diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 140f05c1c6..372ba8bd1c 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1456,7 +1456,7 @@ static void spapr_check_setup_free_hpt(SpaprMachineSt= ate *spapr, spapr_free_hpt(spapr); } else if (!(patbe_new & PATE1_GR)) { /* RADIX->HASH || NOTHING->HASH : Allocate HPT */ - spapr_setup_hpt_and_vrma(spapr); + spapr_setup_hpt(spapr); } return; } @@ -1772,7 +1772,7 @@ static target_ulong h_client_architecture_support(Pow= erPCCPU *cpu, * (because the guest isn't going to use radix) then set it up her= e. */ if ((spapr->patb_entry & PATE1_GR) && !guest_radix) { /* legacy hash or new hash: */ - spapr_setup_hpt_and_vrma(spapr); + spapr_setup_hpt(spapr); } spapr->cas_reboot =3D (spapr_h_cas_compose_response(spapr, args[1], args[2], diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index d5ab5ea7b2..85c33560c3 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -154,7 +154,6 @@ struct SpaprMachineState { SpaprPendingHpt *pending_hpt; /* in-progress resize */ =20 hwaddr rma_size; - int vrma_adjust; uint32_t fdt_size; uint32_t fdt_initial_size; void *fdt_blob; @@ -772,7 +771,7 @@ int spapr_h_cas_compose_response(SpaprMachineState *sm, target_ulong addr, target_ulong size, SpaprOptionVector *ov5_updates); void close_htab_fd(SpaprMachineState *spapr); -void spapr_setup_hpt_and_vrma(SpaprMachineState *spapr); +void spapr_setup_hpt(SpaprMachineState *spapr); void spapr_free_hpt(SpaprMachineState *spapr); SpaprTceTable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn); void spapr_tce_table_enable(SpaprTceTable *tcet, --=20 2.23.0 From nobody Fri Apr 19 19:34:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1574993366; cv=none; d=zohomail.com; s=zohoarc; b=PQcTt9s/wuWetqwrGpzTU4vERN5iGPiEUXBI3S3LuDjEFxGg1ngnOe+aPx4ZyrB5Pg8ackBQfSnCIqRC/gu45ZgdgwPbFs0WaK9yyQVGdzB7xcVvmontsyVLy10G4QLmgtQP/D2/iocq2i9taVF9aRiqsyl5if7r/fdlIsrhJ0U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574993366; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/5t6Etls/GHnS+JhQ3pnCTDj/nXgLXJV6PpGY0KeZp8=; b=aJcvXym5vMwkcSy9PQ4Y//Jas7RczJxQZnJoOORHhdpKHsCD29LJVniUT4H+zdEtDPlMKQginikrH7kZ8bB//BTl1mbnSw+Jr6XbKYlux+imTKEaQRpVdkn18SL0M06GVoZx0grYXnmkH8sgxEuZ9+5nYIQA9jYUy8vzb4Li+zE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574993366469935.9702327572796; Thu, 28 Nov 2019 18:09:26 -0800 (PST) Received: from localhost ([::1]:54398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaVik-0006tl-Jn for importer@patchew.org; Thu, 28 Nov 2019 21:09:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56319) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaVBo-0002Xk-54 for qemu-devel@nongnu.org; Thu, 28 Nov 2019 20:35:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iaVBk-0003Ht-Gl for qemu-devel@nongnu.org; Thu, 28 Nov 2019 20:35:18 -0500 Received: from bilbo.ozlabs.org ([203.11.71.1]:46095 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iaVBi-0002tc-Vc; Thu, 28 Nov 2019 20:35:16 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 47PHBN2j4tz9sRG; Fri, 29 Nov 2019 12:35:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1574991308; bh=55/r0wZVyzKD4cnomur2Zr9HJjTyRz7z6AB2879fBAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ur83RSAQ5EklczAC5H6aE42pb0DQAV37Gxz1itbDp4TaIC6eUftpECzt3omUPjlRA q+ySj0BMmbpLDckaQs3NxSLYq2+ppoY1gYf9sQeTeSmZBmYs+TBOSGgfUVsRLbLzoY 3ryOO4w2OFRQr2D2mwtvOZcdkXb40dCl878GKghQ= From: David Gibson To: groug@kaod.org, clg@kaod.org Subject: [for-5.0 3/4] spapr: Clean up RMA size calculation Date: Fri, 29 Nov 2019 12:35:03 +1100 Message-Id: <20191129013504.145455-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191129013504.145455-1-david@gibson.dropbear.id.au> References: <20191129013504.145455-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 203.11.71.1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aik@ozlabs.ru, lvivier@redhat.com, qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) Content-Type: text/plain; charset="utf-8" Move the calculation of the Real Mode Area (RMA) size into a helper function. While we're there clean it up and correct it in a few ways: * Add comments making it clearer where the various constraints come from * Remove a pointless check that the RMA fits within Node 0 (we've just clamped it so that it does) * The 16GiB limit we apply is only correct for POWER8, but there is also a 1TiB limit that applies on POWER9. Signed-off-by: David Gibson --- hw/ppc/spapr.c | 57 +++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 52c39daa99..7efd4f2b85 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2664,6 +2664,40 @@ static PCIHostState *spapr_create_default_phb(void) return PCI_HOST_BRIDGE(dev); } =20 +static hwaddr spapr_rma_size(SpaprMachineState *spapr, Error **errp) +{ + MachineState *machine =3D MACHINE(spapr); + hwaddr rma_size =3D machine->ram_size; + hwaddr node0_size =3D spapr_node0_size(machine); + + /* RMA has to fit in the first NUMA node */ + rma_size =3D MIN(rma_size, node0_size); + + /* + * VRMA access is via a special 1TiB SLB mapping, so the RMA can + * never exceed that + */ + rma_size =3D MIN(rma_size, TiB); + + /* + * RMA size is controlled in hardware by LPCR[RMLS]. On POWER8 + * the largest RMA that can be specified there is 16GiB + */ + if (!ppc_type_check_compat(machine->cpu_type, CPU_POWERPC_LOGICAL_3_00, + 0, spapr->max_compat_pvr)) { + rma_size =3D MIN(rma_size, 16 * GiB); + } + + if (rma_size < (MIN_RMA_SLOF * MiB)) { + error_setg(errp, +"pSeries SLOF firmware requires >=3D %ldMiB guest RMA (Real Mode Area)", + MIN_RMA_SLOF); + return -1; + } + + return rma_size; +} + /* pSeries LPAR / sPAPR hardware init */ static void spapr_machine_init(MachineState *machine) { @@ -2675,7 +2709,6 @@ static void spapr_machine_init(MachineState *machine) int i; MemoryRegion *sysmem =3D get_system_memory(); MemoryRegion *ram =3D g_new(MemoryRegion, 1); - hwaddr node0_size =3D spapr_node0_size(machine); long load_limit, fw_size; char *filename; Error *resize_hpt_err =3D NULL; @@ -2715,20 +2748,7 @@ static void spapr_machine_init(MachineState *machine) exit(1); } =20 - spapr->rma_size =3D node0_size; - - /* Actually we don't support unbounded RMA anymore since we added - * proper emulation of HV mode. The max we can get is 16G which - * also happens to be what we configure for PAPR mode so make sure - * we don't do anything bigger than that - */ - spapr->rma_size =3D MIN(spapr->rma_size, 0x400000000ull); - - if (spapr->rma_size > node0_size) { - error_report("Numa node 0 has to span the RMA (%#08"HWADDR_PRIx")", - spapr->rma_size); - exit(1); - } + spapr->rma_size =3D spapr_rma_size(spapr, &error_fatal); =20 /* Setup a load limit for the ramdisk leaving room for SLOF and FDT */ load_limit =3D MIN(spapr->rma_size, RTAS_MAX_ADDR) - FW_OVERHEAD; @@ -2956,13 +2976,6 @@ static void spapr_machine_init(MachineState *machine) } } =20 - if (spapr->rma_size < (MIN_RMA_SLOF * MiB)) { - error_report( - "pSeries SLOF firmware requires >=3D %ldM guest RMA (Real Mode= Area memory)", - MIN_RMA_SLOF); - exit(1); - } - if (kernel_filename) { uint64_t lowaddr =3D 0; =20 --=20 2.23.0 From nobody Fri Apr 19 19:34:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1574991850; cv=none; d=zohomail.com; s=zohoarc; b=UJ+3fibT/rDJxLfmi4xJLmpipxR1/Eg9X7oCCnrnfwoaC9RjnG0V0eTHwM72CVpH01WwWKpyxIrvjG3c2ntHUf8V729OU7ieFhaQ3LpODbcNwMJob6BIZLD2nAGq6SaYVMIDM7FXUdq+VhHj6lfR0V4QV5cJ7e+U3uQh0p+T9v8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574991850; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8pHrf8E+OtRiE+qikSKHEIcsgJkavgXctTO1BBSfWOo=; b=nTiXZrIho6XdmwAU3lLeB21lWeRdrr2XEaUdM9ZICCsbqgx48It6ikHMzn+jLgb+AKWlOSDeZD4G+jeFuExUh9n4V6cKlpDVft9N0asSuPEOormHDQPmBM0kDcP3sWI3WrhOHsRaa6LycH3CBzaRW1nkaMpTI8gVOdQIV/SIZ7o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574991850388359.8272270703262; Thu, 28 Nov 2019 17:44:10 -0800 (PST) Received: from localhost ([::1]:54326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaVKI-0005Q6-SL for importer@patchew.org; Thu, 28 Nov 2019 20:44:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56309) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaVBn-0002Xj-5j for qemu-devel@nongnu.org; Thu, 28 Nov 2019 20:35:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iaVBl-0003KF-CB for qemu-devel@nongnu.org; Thu, 28 Nov 2019 20:35:18 -0500 Received: from bilbo.ozlabs.org ([203.11.71.1]:32825 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iaVBk-0002u7-Rm; Thu, 28 Nov 2019 20:35:17 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 47PHBN1wbdz9sR7; Fri, 29 Nov 2019 12:35:08 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1574991308; bh=kVMG34bg0BfZw8om11xhIz2XVEZNaDRXs7q11jdpRyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mUEEZXoFdBg6uaXjXASAQhZ8DuDAMMxsKK8hO60JT6W/B1/W7oZ9hCz0lBGeaMO+f ODRos4UaEeERnaUN+BP+KDNnUokrpr6qdv5BJoa5+ndk5I2ER2623Zl+GdNz1BQ4Tl JFQ1w/ZAbXa/EIFLxw7dYUM+d/8FXXb34wcj2Fp8= From: David Gibson To: groug@kaod.org, clg@kaod.org Subject: [for-5.0 4/4] spapr: Correct clamping of RMA to Node 0 size Date: Fri, 29 Nov 2019 12:35:04 +1100 Message-Id: <20191129013504.145455-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191129013504.145455-1-david@gibson.dropbear.id.au> References: <20191129013504.145455-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 203.11.71.1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aik@ozlabs.ru, lvivier@redhat.com, qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) Content-Type: text/plain; charset="utf-8" The Real Mode Area (RMA) needs to fit within Node 0 in NUMA configurations. We use a helper function spapr_node0_size() to calculate this. But that function doesn't actually get the size of Node 0, it gets the minimum size of all nodes, ever since b082d65a300 "spapr: Add a helper for node0_size calculation". That was added, apparently, because Node 0 in qemu's terms might not have corresponded to Node 0 in PAPR terms (i.e. the node with memory at address 0). That might not have been the case at the time, but it *is* the case now that qemu node 0 must have the lowest address, which is the node we need. So, we can simplify this logic, folding it into spapr_rma_size(), the only remaining caller. Signed-off-by: David Gibson --- hw/ppc/spapr.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 7efd4f2b85..6611f75bdf 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -295,20 +295,6 @@ static void spapr_populate_pa_features(SpaprMachineSta= te *spapr, _FDT((fdt_setprop(fdt, offset, "ibm,pa-features", pa_features, pa_size= ))); } =20 -static hwaddr spapr_node0_size(MachineState *machine) -{ - if (machine->numa_state->num_nodes) { - int i; - for (i =3D 0; i < machine->numa_state->num_nodes; ++i) { - if (machine->numa_state->nodes[i].node_mem) { - return MIN(pow2floor(machine->numa_state->nodes[i].node_me= m), - machine->ram_size); - } - } - } - return machine->ram_size; -} - static void add_str(GString *s, const gchar *s1) { g_string_append_len(s, s1, strlen(s1) + 1); @@ -2668,10 +2654,13 @@ static hwaddr spapr_rma_size(SpaprMachineState *spa= pr, Error **errp) { MachineState *machine =3D MACHINE(spapr); hwaddr rma_size =3D machine->ram_size; - hwaddr node0_size =3D spapr_node0_size(machine); =20 /* RMA has to fit in the first NUMA node */ - rma_size =3D MIN(rma_size, node0_size); + if (machine->numa_state->num_nodes) { + hwaddr node0_size =3D machine->numa_state->nodes[0].node_mem; + + rma_size =3D MIN(rma_size, node0_size); + } =20 /* * VRMA access is via a special 1TiB SLB mapping, so the RMA can @@ -2688,6 +2677,11 @@ static hwaddr spapr_rma_size(SpaprMachineState *spap= r, Error **errp) rma_size =3D MIN(rma_size, 16 * GiB); } =20 + /* + * RMA size must be a power of 2 + */ + rma_size =3D pow2floor(rma_size); + if (rma_size < (MIN_RMA_SLOF * MiB)) { error_setg(errp, "pSeries SLOF firmware requires >=3D %ldMiB guest RMA (Real Mode Area)", --=20 2.23.0