From nobody Sun May 5 07:10:30 2024 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 1524119901744270.4337431604688; Wed, 18 Apr 2018 23:38:21 -0700 (PDT) Received: from localhost ([::1]:53384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f93D2-0003bA-VW for importer@patchew.org; Thu, 19 Apr 2018 02:38:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f934S-0005Z8-U3 for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f934O-0005Qf-8j for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:28 -0400 Received: from ozlabs.org ([203.11.71.1]:43447) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f934N-0005Oe-LO; Thu, 19 Apr 2018 02:29:24 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40RTbj0cp1z9s2B; 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=1524119361; bh=Z35+tudioudIZPGIiZfByyUfrx+IRhbsWzqx0wrBawM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SVJ0BF7dKVF9xU6H1LI9PAdYcYVhB+jxUqQhOafn8OBH5uVTY7u81vlp8bCwyMDQe NImgIscPXf4gSsbnBjg2OzccPEPTKlVsPNygEvfWiGnsv09H1ZyLTG8IIiw/KgkufX ySJmf4ypXYTJkIE/DCNr0DJTzZ+QHSw1NjaBHfvg= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Thu, 19 Apr 2018 16:29:11 +1000 Message-Id: <20180419062917.31486-2-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: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [RFC for-2.13 1/7] spapr: Maximum (HPT) pagesize property 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 the POWER Hash Page Table (HPT) MMU is virtualized by KVM HV means that every page that the guest puts in the pagetables must be truly physically contiguous, not just GPA-contiguous. In effect this means that an HPT guest can't use any pagesizes greater than the host page size used to back its memory. At present we handle this by changing what we advertise to the guest based on the backing pagesizes. This is pretty bad, because it means the guest sees a different environment depending on what should be host configuration details. As a start on fixing this, we add a new capability parameter to the pseries machine type which gives the maximum allowed pagesizes for an HPT guest (as a shift). For now we just create and validate the parameter without making it do anything. Signed-off-by: David Gibson --- hw/ppc/spapr.c | 1 + hw/ppc/spapr_caps.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/ppc/spapr.h | 4 +++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index bdf72e1e89..36e41aff71 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3876,6 +3876,7 @@ static void spapr_machine_class_init(ObjectClass *oc,= void *data) smc->default_caps.caps[SPAPR_CAP_CFPC] =3D SPAPR_CAP_BROKEN; smc->default_caps.caps[SPAPR_CAP_SBBC] =3D SPAPR_CAP_BROKEN; smc->default_caps.caps[SPAPR_CAP_IBS] =3D SPAPR_CAP_BROKEN; + smc->default_caps.caps[SPAPR_CAP_HPT_MPS] =3D 16; /* Allow 64kiB pages= */ spapr_caps_add_properties(smc, &error_abort); } =20 diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 531e145114..cbc41f5b20 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -27,6 +27,7 @@ #include "qapi/visitor.h" #include "sysemu/hw_accel.h" #include "target/ppc/cpu.h" +#include "target/ppc/mmu-hash64.h" #include "cpu-models.h" #include "kvm_ppc.h" =20 @@ -142,6 +143,39 @@ out: g_free(val); } =20 +static void spapr_cap_get_int(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + sPAPRCapabilityInfo *cap =3D opaque; + sPAPRMachineState *spapr =3D SPAPR_MACHINE(obj); + int64_t value =3D spapr_get_cap(spapr, cap->index); + + visit_type_int(v, name, &value, errp); +} + +static void spapr_cap_set_int(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + sPAPRCapabilityInfo *cap =3D opaque; + sPAPRMachineState *spapr =3D SPAPR_MACHINE(obj); + int64_t value; + Error *local_err =3D NULL; + + visit_type_int(v, name, &value, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if ((value < 0) || (value > 255)) { + error_setg(errp, "Value for %s out of range (0..255)", name); + return; + } + + spapr->cmd_line_caps[cap->index] =3D true; + spapr->eff.caps[cap->index] =3D value; +} + static void cap_htm_apply(sPAPRMachineState *spapr, uint8_t val, Error **e= rrp) { if (!val) { @@ -265,6 +299,16 @@ static void cap_safe_indirect_branch_apply(sPAPRMachin= eState *spapr, =20 #define VALUE_DESC_TRISTATE " (broken, workaround, fixed)" =20 +static void cap_hpt_mps_apply(sPAPRMachineState *spapr, + uint8_t val, Error **errp) +{ + if (val < 12) { + error_setg(errp, "Require at least 4kiB pages (cap-hpt-mps >=3D 12= )"); + } else if (val < 16) { + warn_report("Many PAPR guests require 64kiB pages (cap-hpt-mps >= =3D 16)"); + } +} + sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] =3D { [SPAPR_CAP_HTM] =3D { .name =3D "htm", @@ -324,6 +368,15 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = =3D { .possible =3D &cap_ibs_possible, .apply =3D cap_safe_indirect_branch_apply, }, + [SPAPR_CAP_HPT_MPS] =3D { + .name =3D "hpt-mps", + .description =3D "Maximum page shift for Hash Page Table guests (1= 2, 16, 24, 34)", + .index =3D SPAPR_CAP_HPT_MPS, + .get =3D spapr_cap_get_int, + .set =3D spapr_cap_set_int, + .type =3D "int", + .apply =3D cap_hpt_mps_apply, + }, }; =20 static sPAPRCapabilities default_caps_with_cpu(sPAPRMachineState *spapr, diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index d60b7c6d7a..60ed3a5657 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -66,8 +66,10 @@ typedef enum { #define SPAPR_CAP_SBBC 0x04 /* Indirect Branch Serialisation */ #define SPAPR_CAP_IBS 0x05 +/* HPT Maximum Page Shift */ +#define SPAPR_CAP_HPT_MPS 0x06 /* Num Caps */ -#define SPAPR_CAP_NUM (SPAPR_CAP_IBS + 1) +#define SPAPR_CAP_NUM (SPAPR_CAP_HPT_MPS + 1) =20 /* * Capability Values --=20 2.14.3 From nobody Sun May 5 07:10:30 2024 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 From nobody Sun May 5 07:10:30 2024 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 1524119493599518.6577197358765; Wed, 18 Apr 2018 23:31:33 -0700 (PDT) Received: from localhost ([::1]:53047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f936S-0006uN-O2 for importer@patchew.org; Thu, 19 Apr 2018 02:31:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f934P-0005Wq-1v 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-0005Qm-9Q for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:25 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:55335) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f934N-0005Oj-Mu; Thu, 19 Apr 2018 02:29:24 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40RTbj1WDGz9s27; Thu, 19 Apr 2018 16:29:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1524119361; bh=yStT8YRU+SLEwsBsKAo4UEzFUGxG32PeG6I3gORZrxU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UxnuGsGkyYxxX9RWr+eQ07UXl/y0Nr6FWpIvcPDs6NqxEErdwOdUaEAwdODOBHwPL HM8HjXzbuEfVzrD7RL6C+6d299pBBP60kFa4oceqvb4WC2X5tsAvCfxxLi3hKdWuJN wi+DeY/wl5s9eEiKPXGCjvg51Ucx8yQ94MKvDyvU= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Thu, 19 Apr 2018 16:29:13 +1000 Message-Id: <20180419062917.31486-4-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 3/7] target/ppc: Add ppc_hash64_filter_pagesizes() 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 paravirtualized PAPR platform sometimes needs to restrict the guest to using only some of the page sizes actually supported by the host's MMU. At the moment this is handled in KVM specific code, but for consistency we want to apply the same limitations to all accelerators. This makes a start on this by providing a helper function in the cpu code to allow platform code to remove some of the cpu's page size definitions via a caller supplied callback. Signed-off-by: David Gibson --- target/ppc/mmu-hash64.c | 59 +++++++++++++++++++++++++++++++++++++++++++++= ++++ target/ppc/mmu-hash64.h | 3 +++ 2 files changed, 62 insertions(+) diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c index a1db20e3a8..b6e62864fd 100644 --- a/target/ppc/mmu-hash64.c +++ b/target/ppc/mmu-hash64.c @@ -1165,3 +1165,62 @@ const PPCHash64Options ppc_hash64_opts_POWER7 =3D { }, } }; + +void ppc_hash64_filter_pagesizes(PowerPCCPU *cpu, + bool (*cb)(void *, uint32_t, uint32_t), + void *opaque) +{ + PPCHash64Options *opts =3D cpu->hash64_opts; + int i; + int n =3D 0; + bool ci_largepage =3D false; + + assert(opts); + + n =3D 0; + for (i =3D 0; i < ARRAY_SIZE(opts->sps); i++) { + PPCHash64SegmentPageSizes *sps =3D &opts->sps[i]; + int j; + int m =3D 0; + + assert(n <=3D i); + + if (!sps->page_shift) { + break; + } + + for (j =3D 0; j < ARRAY_SIZE(sps->enc); j++) { + PPCHash64PageSize *ps =3D &sps->enc[j]; + + assert(m <=3D j); + if (!ps->page_shift) { + break; + } + + if (cb(opaque, sps->page_shift, ps->page_shift)) { + if (ps->page_shift =3D=3D 16) { + ci_largepage =3D true; + } + sps->enc[m++] =3D *ps; + } + } + + /* Clear rest of the row */ + for (j =3D m; j < ARRAY_SIZE(sps->enc); j++) { + memset(&sps->enc[j], 0, sizeof(sps->enc[j])); + } + + if (m) { + n++; + } + } + + /* Clear the rest of the table */ + for (i =3D n; i < ARRAY_SIZE(opts->sps); i++) { + memset(&opts->sps[i], 0, sizeof(opts->sps[i])); + } + + if (!ci_largepage) { + opts->flags &=3D ~PPC_HASH64_CI_LARGEPAGE; + } +} diff --git a/target/ppc/mmu-hash64.h b/target/ppc/mmu-hash64.h index f23b78d787..1aa2453497 100644 --- a/target/ppc/mmu-hash64.h +++ b/target/ppc/mmu-hash64.h @@ -20,6 +20,9 @@ unsigned ppc_hash64_hpte_page_shift_noslb(PowerPCCPU *cpu, void ppc_store_lpcr(PowerPCCPU *cpu, target_ulong val); void ppc_hash64_init(PowerPCCPU *cpu); void ppc_hash64_finalize(PowerPCCPU *cpu); +void ppc_hash64_filter_pagesizes(PowerPCCPU *cpu, + bool (*cb)(void *, uint32_t, uint32_t), + void *opaque); #endif =20 /* --=20 2.14.3 From nobody Sun May 5 07:10:30 2024 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 1524119715019673.788373264613; Wed, 18 Apr 2018 23:35:15 -0700 (PDT) Received: from localhost ([::1]:53162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f93A2-0001Jq-7V for importer@patchew.org; Thu, 19 Apr 2018 02:35:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f934S-0005Z4-Sw for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f934O-0005Qc-8J for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:28 -0400 Received: from ozlabs.org ([203.11.71.1]:59861) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f934N-0005Ov-Ry; Thu, 19 Apr 2018 02:29:24 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40RTbj2ZbPz9s2M; Thu, 19 Apr 2018 16:29:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1524119361; bh=MDJY9vDXEccULjJhRfFv5QyA/0T6mUcbgP+hcHmvZus=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dtPuSbvszdSTxhVPL7M5JahRcMoKPKVvD6xxhYhm0Q2ZatvSI/BBX8S4up9alPPQ7 1nqMexDzp5o2IJetii917B/phIieRP7sdt6nLMo4by6f2q0jRhOTRJsfldYCnuS/o8 rXStUAJnpmP6DxxUOOb2ApMzNPj3LSzYrHhdgqy4= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Thu, 19 Apr 2018 16:29:14 +1000 Message-Id: <20180419062917.31486-5-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: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [RFC for-2.13 4/7] spapr: Add cpu_apply hook to capabilities 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" spapr capabilities have an apply hook to actually activate (or deactivate) the feature in the system at reset time. However, a number of capabilities affect the setup of cpus, and need to be applied to each of them - including hotplugged cpus for extra complication. To make this simpler, add an optional cpu_apply hook that is called from spapr_cpu_reset(). Signed-off-by: David Gibson --- hw/ppc/spapr_caps.c | 19 +++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 2 ++ include/hw/ppc/spapr.h | 1 + 3 files changed, 22 insertions(+) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 5762b88689..e71de14ffb 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -61,6 +61,8 @@ typedef struct sPAPRCapabilityInfo { sPAPRCapPossible *possible; /* Make sure the virtual hardware can support this capability */ void (*apply)(sPAPRMachineState *spapr, uint8_t val, Error **errp); + void (*cpu_apply)(sPAPRMachineState *spapr, PowerPCCPU *cpu, + uint8_t val, Error **errp); } sPAPRCapabilityInfo; =20 static void spapr_cap_get_bool(Object *obj, Visitor *v, const char *name, @@ -547,6 +549,23 @@ void spapr_caps_reset(sPAPRMachineState *spapr) } } =20 +void spapr_caps_cpu_reset(sPAPRMachineState *spapr, PowerPCCPU *cpu) +{ + int i; + + for (i =3D 0; i < SPAPR_CAP_NUM; i++) { + sPAPRCapabilityInfo *info =3D &capability_table[i]; + + /* + * If the apply function can't set the desired level and thinks it= 's + * fatal, it should cause that. + */ + if (info->cpu_apply) { + info->cpu_apply(spapr, cpu, spapr->eff.caps[i], &error_fatal); + } + } +} + void spapr_caps_add_properties(sPAPRMachineClass *smc, Error **errp) { Error *local_err =3D NULL; diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 0a668b8954..f041182593 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -67,6 +67,8 @@ static void spapr_cpu_reset(void *opaque) =20 /* Set a full AMOR so guest can use the AMR as it sees fit */ env->spr[SPR_AMOR] =3D 0xffffffffffffffffull; + + spapr_caps_cpu_reset(SPAPR_MACHINE(qdev_get_machine()), cpu); } =20 void spapr_cpu_set_entry_state(PowerPCCPU *cpu, target_ulong nip, target_u= long r3) diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index a3d616c612..ced3246d0e 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -802,6 +802,7 @@ static inline uint8_t spapr_get_cap(sPAPRMachineState *= spapr, int cap) } =20 void spapr_caps_reset(sPAPRMachineState *spapr); +void spapr_caps_cpu_reset(sPAPRMachineState *spapr, PowerPCCPU *cpu); void spapr_caps_add_properties(sPAPRMachineClass *smc, Error **errp); int spapr_caps_post_migration(sPAPRMachineState *spapr); =20 --=20 2.14.3 From nobody Sun May 5 07:10:30 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524119696968660.7331825430796; Wed, 18 Apr 2018 23:34:56 -0700 (PDT) Received: from localhost ([::1]:53125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f939c-00012V-4p for importer@patchew.org; Thu, 19 Apr 2018 02:34:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f934T-0005ZZ-62 for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f934Q-0005Sw-OM for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:29 -0400 Received: from ozlabs.org ([203.11.71.1]:52301) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f934Q-0005R1-Cd; Thu, 19 Apr 2018 02:29:26 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40RTbj3x7cz9s2t; Thu, 19 Apr 2018 16:29:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1524119361; bh=lfY3w8LzHIIko8lE2OtC2uSTjHt/TL73R4QHS8HGubE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Od465xXWAYBKW20TdFcLIkhM84A1zfmZYuGF5b5hG0D5XStm9aD3gsxY0GBnggZQq V15gVvwF+IcEIavqkvF/dwWN8eVtPjx+AJDo10KVXT4P0thRFOIRoFEdaBHIlP7rqn pMXwTF9bi55dpNyWRDxfIc3DgFUffkqgDWhmn6NY= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Thu, 19 Apr 2018 16:29:15 +1000 Message-Id: <20180419062917.31486-6-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: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [RFC for-2.13 5/7] spapr: Limit available pagesizes to provide a consistent guest environment 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" KVM HV has some limitations (deriving from the hardware) that mean not all host-cpu supported pagesizes may be usable in the guest. At present this means that KVM guests and TCG guests may see different available page sizes even if they notionally have the same vcpu model. This is confusing and also prevents migration between TCG and KVM. This patch makes the environment consistent by always allowing the same set of pagesizes. Since we can't remove the KVM limitations, we do this by always applying the same limitations it has, even to TCG guests. Signed-off-by: David Gibson --- hw/ppc/spapr_caps.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index e71de14ffb..5a247f190f 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -331,6 +331,38 @@ static void cap_hpt_mps_apply(sPAPRMachineState *spapr, spapr_check_pagesize(spapr, qemu_getrampagesize(), errp); } =20 +static bool spapr_pagesize_cb(void *opaque, uint32_t seg_pshift, uint32_t = pshift) +{ + unsigned maxshift =3D *((unsigned *)opaque); + + assert(pshift >=3D seg_pshift); + + /* Don't allow the guest to use pages bigger than the configured + * maximum size */ + if (pshift > maxshift) { + return false; + } + + /* For whatever reason, KVM doesn't allow multiple pagesizes + * within a segment, *except* for the case of 16M pages in a 4k or + * 64k segment. Always exclude other cases, so that TCG and KVM + * guests see a consistent environment */ + if ((pshift !=3D seg_pshift) && (pshift !=3D 24)) { + return false; + } + + return true; +} + +static void cap_hpt_mps_cpu_apply(sPAPRMachineState *spapr, + PowerPCCPU *cpu, + uint8_t val, Error **errp) +{ + unsigned maxshift =3D val; + + ppc_hash64_filter_pagesizes(cpu, spapr_pagesize_cb, &maxshift); +} + sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] =3D { [SPAPR_CAP_HTM] =3D { .name =3D "htm", @@ -398,6 +430,7 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] =3D= { .set =3D spapr_cap_set_int, .type =3D "int", .apply =3D cap_hpt_mps_apply, + .cpu_apply =3D cap_hpt_mps_cpu_apply, }, }; =20 --=20 2.14.3 From nobody Sun May 5 07:10:30 2024 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 1524119815342962.6202106055401; Wed, 18 Apr 2018 23:36:55 -0700 (PDT) Received: from localhost ([::1]:53341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f93Be-0002lI-Hv for importer@patchew.org; Thu, 19 Apr 2018 02:36:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f934S-0005Yc-J4 for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f934Q-0005TD-Vl for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:28 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:42747) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f934Q-0005Qw-DA; Thu, 19 Apr 2018 02:29:26 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40RTbj4rR2z9s37; Thu, 19 Apr 2018 16:29:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1524119361; bh=RDNdtXAEczrXOe6Lj2YXSs6vbgDiwb+xhPrRrd/kBrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jfF06EZJ9BvBckLbjJA5JRRcNS9f/FWH+TwVEij8ovAPmfZbJeouqr/6xVGj7Uyz1 99pZ1GE1fukrLfexiWaSf6f0Ap0frYGf6wReBxqG3LDyd2N0lNo/fAlWawlh5qQIuM 2ioG89gL4SKtpTbi95lMH+wovWefUEyqUuKs3Lh0= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Thu, 19 Apr 2018 16:29:16 +1000 Message-Id: <20180419062917.31486-7-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 6/7] spapr: Don't rewrite mmu capabilities in KVM mode 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" Currently during KVM initialization on POWER, kvm_fixup_page_sizes() rewrites a bunch of information in the cpu state to reflect the capabilities of the host MMU and KVM. This overwrites the information that's already there reflecting how the TCG implementation of the MMU will operate. This means that we can get guest-visibly different behaviour between KVM and TCG (and between different KVM implementations). That's bad. It also prevents migration between KVM and TCG. The pseries machine type now has filtering of the pagesizes it allows the guest to use which means it can present a consistent model of the MMU across all accelerators. So, we can now replace kvm_fixup_page_sizes() with kvm_check_mmu() which merely verifies that the expected cpu model can be faithfully handled by KVM, rather than updating the cpu model to match KVM. We call kvm_check_mmu() from the spapr cpu reset code. This is a hack: conceptually it makes more sense where fixup_page_sizes() was - in the KVM cpu init path. However, doing that would require moving the platform's pagesize filtering much earlier, which would require a lot of work making further adjustments. There wouldn't be a lot of concrete point to doing that, since the only KVM implementation which has the awkward MMU restrictions is KVM HV, which can only work with an spapr guest anyway. Signed-off-by: David Gibson --- hw/ppc/spapr_cpu_core.c | 2 + target/ppc/kvm.c | 134 +++++++++++++++++++++++---------------------= ---- target/ppc/kvm_ppc.h | 5 ++ 3 files changed, 72 insertions(+), 69 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index f041182593..f00180a443 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -69,6 +69,8 @@ static void spapr_cpu_reset(void *opaque) env->spr[SPR_AMOR] =3D 0xffffffffffffffffull; =20 spapr_caps_cpu_reset(SPAPR_MACHINE(qdev_get_machine()), cpu); + + kvm_check_mmu(cpu, &error_fatal); } =20 void spapr_cpu_set_entry_state(PowerPCCPU *cpu, target_ulong nip, target_u= long r3) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index defbb08931..fa7e1b77b3 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -408,85 +408,91 @@ target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, } } =20 -static bool kvm_valid_page_size(uint32_t flags, long rampgsize, uint32_t s= hift) +void kvm_check_mmu(PowerPCCPU *cpu, Error **errp) { - if (!(flags & KVM_PPC_PAGE_SIZES_REAL)) { - return true; - } - - return (1ul << shift) <=3D rampgsize; -} - -static long max_cpu_page_size; - -static void kvm_fixup_page_sizes(PowerPCCPU *cpu) -{ - static struct kvm_ppc_smmu_info smmu_info; - static bool has_smmu_info; - CPUPPCState *env =3D &cpu->env; + struct kvm_ppc_smmu_info smmu_info; int iq, ik, jq, jk; =20 - /* We only handle page sizes for 64-bit server guests for now */ - if (!(env->mmu_model & POWERPC_MMU_64)) { + /* For now, we only have anything to check on has64 MMUs */ + if (!cpu->hash64_opts || !kvm_enabled()) { return; } =20 - /* Collect MMU info from kernel if not already */ - if (!has_smmu_info) { - kvm_get_smmu_info(cpu, &smmu_info); - has_smmu_info =3D true; - } + kvm_get_smmu_info(cpu, &smmu_info); =20 - if (!max_cpu_page_size) { - max_cpu_page_size =3D qemu_getrampagesize(); + if (ppc_hash64_has(cpu, PPC_HASH64_1TSEG) + && !(smmu_info.flags & KVM_PPC_1T_SEGMENTS)) { + error_setg(errp, + "KVM does not support 1TiB segments which guest expects= "); + return; } =20 - /* Convert to QEMU form */ - memset(cpu->hash64_opts->sps, 0, sizeof(*cpu->hash64_opts->sps)); - - /* If we have HV KVM, we need to forbid CI large pages if our - * host page size is smaller than 64K. - */ - if (smmu_info.flags & KVM_PPC_PAGE_SIZES_REAL) { - if (getpagesize() >=3D 0x10000) { - cpu->hash64_opts->flags |=3D PPC_HASH64_CI_LARGEPAGE; - } else { - cpu->hash64_opts->flags &=3D ~PPC_HASH64_CI_LARGEPAGE; - } + if (smmu_info.slb_size < cpu->hash64_opts->slb_size) { + error_setg(errp, "KVM only supports %u SLB entries, but guest need= s %u", + smmu_info.slb_size, cpu->hash64_opts->slb_size); + return; } =20 /* - * XXX This loop should be an entry wide AND of the capabilities that - * the selected CPU has with the capabilities that KVM supports. + * Verify that every pagesize supported by the cpu model is + * supported by KVM with the same encodings */ - for (ik =3D iq =3D 0; ik < KVM_PPC_PAGE_SIZES_MAX_SZ; ik++) { + for (iq =3D 0; iq < ARRAY_SIZE(cpu->hash64_opts->sps); iq++) { PPCHash64SegmentPageSizes *qsps =3D &cpu->hash64_opts->sps[iq]; - struct kvm_ppc_one_seg_page_size *ksps =3D &smmu_info.sps[ik]; + struct kvm_ppc_one_seg_page_size *ksps; =20 - if (!kvm_valid_page_size(smmu_info.flags, max_cpu_page_size, - ksps->page_shift)) { - continue; - } - qsps->page_shift =3D ksps->page_shift; - qsps->slb_enc =3D ksps->slb_enc; - for (jk =3D jq =3D 0; jk < KVM_PPC_PAGE_SIZES_MAX_SZ; jk++) { - if (!kvm_valid_page_size(smmu_info.flags, max_cpu_page_size, - ksps->enc[jk].page_shift)) { - continue; - } - qsps->enc[jq].page_shift =3D ksps->enc[jk].page_shift; - qsps->enc[jq].pte_enc =3D ksps->enc[jk].pte_enc; - if (++jq >=3D PPC_PAGE_SIZES_MAX_SZ) { + for (ik =3D 0; ik < ARRAY_SIZE(smmu_info.sps); ik++) { + if (qsps->page_shift =3D=3D smmu_info.sps[ik].page_shift) { break; } } - if (++iq >=3D PPC_PAGE_SIZES_MAX_SZ) { - break; + if (ik >=3D ARRAY_SIZE(smmu_info.sps)) { + error_setg(errp, "KVM doesn't support for base page shift %u", + qsps->page_shift); + return; + } + + ksps =3D &smmu_info.sps[ik]; + if (ksps->slb_enc !=3D qsps->slb_enc) { + error_setg(errp, +"KVM uses SLB encoding 0x%x for page shift %u, but guest expects 0x%x", + ksps->slb_enc, ksps->page_shift, qsps->slb_enc); + return; + } + + for (jq =3D 0; jq < ARRAY_SIZE(qsps->enc); jq++) { + for (jk =3D 0; jk < ARRAY_SIZE(ksps->enc); jk++) { + if (qsps->enc[jq].page_shift =3D=3D ksps->enc[jk].page_shi= ft) { + break; + } + } + + if (jk >=3D ARRAY_SIZE(ksps->enc)) { + error_setg(errp, "KVM doesn't support page shift %u/%u", + qsps->enc[jq].page_shift, qsps->page_shift); + return; + } + if (qsps->enc[jq].pte_enc !=3D ksps->enc[jk].pte_enc) { + error_setg(errp, +"KVM uses PTE encoding 0x%x for page shift %u/%u, but guest expects 0x%x", + ksps->enc[jk].pte_enc, qsps->enc[jq].page_shift, + qsps->page_shift, qsps->enc[jq].pte_enc); + return; + } } } - cpu->hash64_opts->slb_size =3D smmu_info.slb_size; - if (!(smmu_info.flags & KVM_PPC_1T_SEGMENTS)) { - cpu->hash64_opts->flags &=3D ~PPC_HASH64_1TSEG; + + if (ppc_hash64_has(cpu, PPC_HASH64_CI_LARGEPAGE)) { + /* Mostly what guest pagesizes we can use are related to the + * host pages used to map guest RAM, which is handled in the + * platform code. Cache-Inhibited largepages (64k) however are + * used for I/O, so if they're mapped to the host at all it + * will be a normal mapping, not a special hugepage one used + * for RAM. */ + if (getpagesize() < 0x10000) { + error_setg(errp, +"KVM can't supply 64kiB CI pages, which guest expects\n"); + } } } =20 @@ -503,13 +509,6 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void) =20 return !!(smmu_info.flags & KVM_PPC_PAGE_SIZES_REAL); } - -#else /* defined (TARGET_PPC64) */ - -static inline void kvm_fixup_page_sizes(PowerPCCPU *cpu) -{ -} - #endif /* !defined (TARGET_PPC64) */ =20 unsigned long kvm_arch_vcpu_id(CPUState *cpu) @@ -555,9 +554,6 @@ int kvm_arch_init_vcpu(CPUState *cs) CPUPPCState *cenv =3D &cpu->env; int ret; =20 - /* Gather server mmu info from KVM and update the CPU state */ - kvm_fixup_page_sizes(cpu); - /* Synchronize sregs with kvm */ ret =3D kvm_arch_sync_sregs(cpu); if (ret) { diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index 443fca0a4e..657582bb32 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -71,6 +71,7 @@ int kvmppc_resize_hpt_commit(PowerPCCPU *cpu, target_ulon= g flags, int shift); bool kvmppc_pvr_workaround_required(PowerPCCPU *cpu); =20 bool kvmppc_hpt_needs_host_contiguous_pages(void); +void kvm_check_mmu(PowerPCCPU *cpu, Error **errp); =20 #else =20 @@ -227,6 +228,10 @@ static inline bool kvmppc_hpt_needs_host_contiguous_pa= ges(void) return false; } =20 +static inline void kvm_check_mmu(PowerPCCPU *cpu, Error **errp) +{ +} + static inline bool kvmppc_has_cap_spapr_vfio(void) { return false; --=20 2.14.3 From nobody Sun May 5 07:10:30 2024 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 1524119502842310.64396732193427; Wed, 18 Apr 2018 23:31:42 -0700 (PDT) Received: from localhost ([::1]:53051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f936b-0006zS-TW for importer@patchew.org; Thu, 19 Apr 2018 02:31:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60592) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f934R-0005Xp-LN for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f934Q-0005Sr-Nd for qemu-devel@nongnu.org; Thu, 19 Apr 2018 02:29:27 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:55747) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f934Q-0005Qx-CA; Thu, 19 Apr 2018 02:29:26 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40RTbj5NJPz9s3D; Thu, 19 Apr 2018 16:29:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1524119361; bh=2FjuwKyYB4Mg64QQp85qqTtGmhRHaDnkAqczctqACAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OpwJENgBmslKEXTVOt6s/UX1jzkiF2nmHSWU2Ng/H2hI7/Li/qJyiObchWjDLJhj5 9ZSRxTzdUhqqp+UYtqDSoUYa6dk2KVdYm1zI9sTHbZMq2YGq0+lTHMO+JKfa6+Ub2p X3qS/OUbzrp4EhsaYlS46iicy7bOwr7spGVbKqGE= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Thu, 19 Apr 2018 16:29:17 +1000 Message-Id: <20180419062917.31486-8-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 7/7] spapr_pci: Remove unhelpful pagesize warning 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" By default, the IOMMU model built into the spapr virtual PCI host bridge supports 4kiB and 64kiB IOMMU page sizes. However this can be overridden which may be desirable to allow larger IOMMU page sizes when running a guest with hugepage backing and passthrough devices. For that reason a warning was printed when the device wasn't configured to allow the pagesize with which guest RAM is backed. Experience has proven, however, that this message is more confusing than useful. Worse it sometimes makes little sense when the host-available page sizes don't match those available on the guest, which can happen with a POWER8 guest running on a POWER9 KVM host. Long term we do want better handling to allow large IOMMU page sizes to be used, but for now this parameter and warning don't really accomplish it. So, remove the message, pending a better solution. Signed-off-by: David Gibson --- hw/ppc/spapr_pci.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 39a14980d3..f936ce63ef 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1717,13 +1717,6 @@ static void spapr_phb_realize(DeviceState *dev, Erro= r **errp) } =20 /* DMA setup */ - if (((sphb->page_size_mask & qemu_getrampagesize()) =3D=3D 0) - && kvm_enabled()) { - warn_report("System page size 0x%lx is not enabled in page_size_ma= sk " - "(0x%"PRIx64"). Performance may be slow", - qemu_getrampagesize(), sphb->page_size_mask); - } - for (i =3D 0; i < windows_supported; ++i) { tcet =3D spapr_tce_new_table(DEVICE(sphb), sphb->dma_liobn[i]); if (!tcet) { --=20 2.14.3