From nobody Tue Feb 10 12:39:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524119501660281.41967353914083; Wed, 18 Apr 2018 23:31:41 -0700 (PDT) Received: from localhost ([::1]:53050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f936a-0006xr-GV for importer@patchew.org; Thu, 19 Apr 2018 02:31:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f934P-0005Wz-DZ for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f934O-0005QL-5V for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:25 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:40063) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f934N-0005OU-GK; Thu, 19 Apr 2018 02:29:24 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40RTbh6k53z9s1j; Thu, 19 Apr 2018 16:29:20 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1524119360; bh=e2hSvx2GiyKGqkeENfDtdZHT5ereW5Xj5I59kdrfMq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HJFOhY6IHKzaD0KD9DTFBg+OdWSK9+bhbuRL+oHRDDzwj6DhcrQAMxXZcTKCzwtkl 6EnR16Xk38K0MVK6dDiscAzTBGG47Oi9XofVw+0p8cY44SqqbpuuPZQOXxGhBAO/DQ CpuGmYQitMk1IezCMN5IzGfisRhp5kxSCjTRU1O8= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Thu, 19 Apr 2018 16:29:12 +1000 Message-Id: <20180419062917.31486-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180419062917.31486-1-david@gibson.dropbear.id.au> References: <20180419062917.31486-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [RFC for-2.13 2/7] spapr: Use maximum page size capability to simplify memory backend checking X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aik@ozlabs.ru, David Gibson , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, clg@kaod.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The way we used to handle KVM allowable guest pagesizes for PAPR guests required some convoluted checking of memory attached to the guest. The allowable pagesizes advertised to the guest cpus depended on the memory which was attached at boot, but then we needed to ensure that any memory later hotplugged didn't change which pagesizes were allowed. Now that we have an explicit machine option to control the allowable maximum pagesize we can simplify this. We just check all memory backends against that declared pagesize. We check base and cold-plugged memory at reset time, and hotplugged memory at pre_plug() time. Signed-off-by: David Gibson --- hw/ppc/spapr.c | 17 +++++++---------- hw/ppc/spapr_caps.c | 20 ++++++++++++++++++++ include/hw/ppc/spapr.h | 3 +++ target/ppc/kvm.c | 19 ++++++++++--------- target/ppc/kvm_ppc.h | 6 +++--- 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 36e41aff71..0a0fec4140 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3035,11 +3035,13 @@ out: static void spapr_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState= *dev, Error **errp) { + sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_dev); PCDIMMDevice *dimm =3D PC_DIMM(dev); PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *mr; uint64_t size; - char *mem_dev; + Object *memdev; + hwaddr pagesize; =20 mr =3D ddc->get_memory_region(dimm, errp); if (!mr) { @@ -3053,15 +3055,10 @@ static void spapr_memory_pre_plug(HotplugHandler *h= otplug_dev, DeviceState *dev, return; } =20 - mem_dev =3D object_property_get_str(OBJECT(dimm), PC_DIMM_MEMDEV_PROP,= NULL); - if (mem_dev && !kvmppc_is_mem_backend_page_size_ok(mem_dev)) { - error_setg(errp, "Memory backend has bad page size. " - "Use 'memory-backend-file' with correct mem-path."); - goto out; - } - -out: - g_free(mem_dev); + memdev =3D object_property_get_link(OBJECT(dimm), PC_DIMM_MEMDEV_PROP, + &error_abort); + pagesize =3D host_memory_backend_pagesize(MEMORY_BACKEND(memdev)); + spapr_check_pagesize(spapr, pagesize, errp); } =20 struct sPAPRDIMMState { diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index cbc41f5b20..5762b88689 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -26,6 +26,7 @@ #include "qapi/error.h" #include "qapi/visitor.h" #include "sysemu/hw_accel.h" +#include "exec/ram_addr.h" #include "target/ppc/cpu.h" #include "target/ppc/mmu-hash64.h" #include "cpu-models.h" @@ -299,6 +300,23 @@ static void cap_safe_indirect_branch_apply(sPAPRMachin= eState *spapr, =20 #define VALUE_DESC_TRISTATE " (broken, workaround, fixed)" =20 +void spapr_check_pagesize(sPAPRMachineState *spapr, hwaddr pagesize, + Error **errp) +{ + hwaddr maxpagesize =3D (1ULL << spapr->eff.caps[SPAPR_CAP_HPT_MPS]); + + if (!kvmppc_hpt_needs_host_contiguous_pages()) { + return; + } + + if (maxpagesize > pagesize) { + error_setg(errp, + "Can't support %"HWADDR_PRIu" kiB guest pages with %" + HWADDR_PRIu" kiB host pages with this KVM implementatio= n", + maxpagesize >> 10, pagesize >> 10); + } +} + static void cap_hpt_mps_apply(sPAPRMachineState *spapr, uint8_t val, Error **errp) { @@ -307,6 +325,8 @@ static void cap_hpt_mps_apply(sPAPRMachineState *spapr, } else if (val < 16) { warn_report("Many PAPR guests require 64kiB pages (cap-hpt-mps >= =3D 16)"); } + + spapr_check_pagesize(spapr, qemu_getrampagesize(), errp); } =20 sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] =3D { diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 60ed3a5657..a3d616c612 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -805,4 +805,7 @@ void spapr_caps_reset(sPAPRMachineState *spapr); void spapr_caps_add_properties(sPAPRMachineClass *smc, Error **errp); int spapr_caps_post_migration(sPAPRMachineState *spapr); =20 +void spapr_check_pagesize(sPAPRMachineState *spapr, hwaddr pagesize, + Error **errp); + #endif /* HW_SPAPR_H */ diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index e4341d6ff7..defbb08931 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -490,12 +490,18 @@ static void kvm_fixup_page_sizes(PowerPCCPU *cpu) } } =20 -bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path) +bool kvmppc_hpt_needs_host_contiguous_pages(void) { - Object *mem_obj =3D object_resolve_path(obj_path, NULL); - long pagesize =3D host_memory_backend_pagesize(MEMORY_BACKEND(mem_obj)= ); + PowerPCCPU *cpu =3D POWERPC_CPU(first_cpu); + static struct kvm_ppc_smmu_info smmu_info; + + if (!kvm_enabled()) { + return false; + } =20 - return pagesize >=3D max_cpu_page_size; + kvm_get_smmu_info(cpu, &smmu_info); + + return !!(smmu_info.flags & KVM_PPC_PAGE_SIZES_REAL); } =20 #else /* defined (TARGET_PPC64) */ @@ -504,11 +510,6 @@ static inline void kvm_fixup_page_sizes(PowerPCCPU *cp= u) { } =20 -bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path) -{ - return true; -} - #endif /* !defined (TARGET_PPC64) */ =20 unsigned long kvm_arch_vcpu_id(CPUState *cpu) diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index e2840e1d33..443fca0a4e 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -70,7 +70,7 @@ int kvmppc_resize_hpt_prepare(PowerPCCPU *cpu, target_ulo= ng flags, int shift); int kvmppc_resize_hpt_commit(PowerPCCPU *cpu, target_ulong flags, int shif= t); bool kvmppc_pvr_workaround_required(PowerPCCPU *cpu); =20 -bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path); +bool kvmppc_hpt_needs_host_contiguous_pages(void); =20 #else =20 @@ -222,9 +222,9 @@ static inline uint64_t kvmppc_rma_size(uint64_t current= _size, return ram_size; } =20 -static inline bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path) +static inline bool kvmppc_hpt_needs_host_contiguous_pages(void) { - return true; + return false; } =20 static inline bool kvmppc_has_cap_spapr_vfio(void) --=20 2.14.3