From nobody Sat May 4 11:46:54 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 1529303926874952.7046773417063; Sun, 17 Jun 2018 23:38:46 -0700 (PDT) Received: from localhost ([::1]:33126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnoI-0001Bs-1Q for importer@patchew.org; Mon, 18 Jun 2018 02:38:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41243) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnm1-0008MF-E1 for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUnly-0001Nl-79 for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:21 -0400 Received: from ozlabs.org ([203.11.71.1]:34635) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fUnlx-0001LA-Ip; Mon, 18 Jun 2018 02:36:18 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 418Lvv3xqBz9s3Z; Mon, 18 Jun 2018 16:36:10 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1529303771; bh=TmJbr6RpPxDS9yQBf2rQ1/GtoIuEk8+td+SCvOzuTIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M3vVSeWrCsUl1QnzP8fjiat+36XiDF3aPH/EqMpp2AB1dKrmlDKFTzWWzmtoacIPw kqCwMXlX5mMS66UXlGEgb2QEfEUs5aEICtTWJ8OP36faQHWdtdgX2wqwA87TyOJ1FV QvJ0i1/Dl2uHu7q2uzH4DHCyK7A/AcJemT3eYRF4= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Mon, 18 Jun 2018 16:35:58 +1000 Message-Id: <20180618063606.2513-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618063606.2513-1-david@gibson.dropbear.id.au> References: <20180618063606.2513-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] [PATCH 1/9] target/ppc: Allow cpu compatiblity checks based on type, not instance 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, clg@kaod.org, qemu-devel@nongnu.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" ppc_check_compat() is used in a number of places to check if a cpu object supports a certain compatiblity mode, subject to various constraints. It takes a PowerPCCPU *, however it really only depends on the cpu's class. We have upcoming cases where it would be useful to make compatibility checks before we fully instantiate the cpu objects. ppc_type_check_compat() will now make an equivalent check, but based on a CPU's QOM typename instead of an instantiated CPU object. We make use of the new interface in several places in spapr, where we're essentially making a global check, rather than one specific to a particular cpu. This avoids some ugly uses of first_cpu to grab a "representative" instance. Signed-off-by: David Gibson Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- hw/ppc/spapr.c | 10 ++++------ hw/ppc/spapr_caps.c | 19 +++++++++---------- target/ppc/compat.c | 27 +++++++++++++++++++++------ target/ppc/cpu.h | 4 ++++ 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index db0fb385d4..b0b94fc1f0 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1616,8 +1616,8 @@ static void spapr_machine_reset(void) =20 first_ppc_cpu =3D POWERPC_CPU(first_cpu); if (kvm_enabled() && kvmppc_has_cap_mmu_radix() && - ppc_check_compat(first_ppc_cpu, CPU_POWERPC_LOGICAL_3_00, 0, - spapr->max_compat_pvr)) { + ppc_type_check_compat(machine->cpu_type, CPU_POWERPC_LOGICAL_3_00,= 0, + spapr->max_compat_pvr)) { /* If using KVM with radix mode available, VCPUs can be started * without a HPT because KVM will start them in radix mode. * Set the GR bit in PATB so that we know there is no HPT. */ @@ -2520,7 +2520,6 @@ static void spapr_machine_init(MachineState *machine) long load_limit, fw_size; char *filename; Error *resize_hpt_err =3D NULL; - PowerPCCPU *first_ppc_cpu; =20 msi_nonbroken =3D true; =20 @@ -2618,10 +2617,9 @@ static void spapr_machine_init(MachineState *machine) /* init CPUs */ spapr_init_cpus(spapr); =20 - first_ppc_cpu =3D POWERPC_CPU(first_cpu); if ((!kvm_enabled() || kvmppc_has_cap_mmu_radix()) && - ppc_check_compat(first_ppc_cpu, CPU_POWERPC_LOGICAL_3_00, 0, - spapr->max_compat_pvr)) { + ppc_type_check_compat(machine->cpu_type, CPU_POWERPC_LOGICAL_3_00,= 0, + spapr->max_compat_pvr)) { /* KVM and TCG always allow GTSE with radix... */ spapr_ovec_set(spapr->ov5, OV5_MMU_RADIX_GTSE); } diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 00e43a9ba7..469f38f0ef 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -327,27 +327,26 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = =3D { }; =20 static sPAPRCapabilities default_caps_with_cpu(sPAPRMachineState *spapr, - CPUState *cs) + const char *cputype) { sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(spapr); - PowerPCCPU *cpu =3D POWERPC_CPU(cs); sPAPRCapabilities caps; =20 caps =3D smc->default_caps; =20 - if (!ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_2_07, - 0, spapr->max_compat_pvr)) { + if (!ppc_type_check_compat(cputype, CPU_POWERPC_LOGICAL_2_07, + 0, spapr->max_compat_pvr)) { caps.caps[SPAPR_CAP_HTM] =3D SPAPR_CAP_OFF; caps.caps[SPAPR_CAP_CFPC] =3D SPAPR_CAP_BROKEN; } =20 - if (!ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_2_06_PLUS, - 0, spapr->max_compat_pvr)) { + if (!ppc_type_check_compat(cputype, CPU_POWERPC_LOGICAL_2_06_PLUS, + 0, spapr->max_compat_pvr)) { caps.caps[SPAPR_CAP_SBBC] =3D SPAPR_CAP_BROKEN; } =20 - if (!ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_2_06, - 0, spapr->max_compat_pvr)) { + if (!ppc_type_check_compat(cputype, CPU_POWERPC_LOGICAL_2_06, + 0, spapr->max_compat_pvr)) { caps.caps[SPAPR_CAP_VSX] =3D SPAPR_CAP_OFF; caps.caps[SPAPR_CAP_DFP] =3D SPAPR_CAP_OFF; caps.caps[SPAPR_CAP_IBS] =3D SPAPR_CAP_BROKEN; @@ -384,7 +383,7 @@ int spapr_caps_post_migration(sPAPRMachineState *spapr) sPAPRCapabilities dstcaps =3D spapr->eff; sPAPRCapabilities srccaps; =20 - srccaps =3D default_caps_with_cpu(spapr, first_cpu); + srccaps =3D default_caps_with_cpu(spapr, MACHINE(spapr)->cpu_type); for (i =3D 0; i < SPAPR_CAP_NUM; i++) { /* If not default value then assume came in with the migration */ if (spapr->mig.caps[i] !=3D spapr->def.caps[i]) { @@ -446,7 +445,7 @@ void spapr_caps_reset(sPAPRMachineState *spapr) int i; =20 /* First compute the actual set of caps we're running with.. */ - default_caps =3D default_caps_with_cpu(spapr, first_cpu); + default_caps =3D default_caps_with_cpu(spapr, MACHINE(spapr)->cpu_type= ); =20 for (i =3D 0; i < SPAPR_CAP_NUM; i++) { /* Store the defaults */ diff --git a/target/ppc/compat.c b/target/ppc/compat.c index 807c906f68..7de4bf3122 100644 --- a/target/ppc/compat.c +++ b/target/ppc/compat.c @@ -105,17 +105,13 @@ static const CompatInfo *compat_by_pvr(uint32_t pvr) return NULL; } =20 -bool ppc_check_compat(PowerPCCPU *cpu, uint32_t compat_pvr, - uint32_t min_compat_pvr, uint32_t max_compat_pvr) +static bool pcc_compat(PowerPCCPUClass *pcc, uint32_t compat_pvr, + uint32_t min_compat_pvr, uint32_t max_compat_pvr) { - PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); const CompatInfo *compat =3D compat_by_pvr(compat_pvr); const CompatInfo *min =3D compat_by_pvr(min_compat_pvr); const CompatInfo *max =3D compat_by_pvr(max_compat_pvr); =20 -#if !defined(CONFIG_USER_ONLY) - g_assert(cpu->vhyp); -#endif g_assert(!min_compat_pvr || min); g_assert(!max_compat_pvr || max); =20 @@ -134,6 +130,25 @@ bool ppc_check_compat(PowerPCCPU *cpu, uint32_t compat= _pvr, return true; } =20 +bool ppc_check_compat(PowerPCCPU *cpu, uint32_t compat_pvr, + uint32_t min_compat_pvr, uint32_t max_compat_pvr) +{ + PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); + +#if !defined(CONFIG_USER_ONLY) + g_assert(cpu->vhyp); +#endif + + return pcc_compat(pcc, compat_pvr, min_compat_pvr, max_compat_pvr); +} + +bool ppc_type_check_compat(const char *cputype, uint32_t compat_pvr, + uint32_t min_compat_pvr, uint32_t max_compat_pv= r) +{ + PowerPCCPUClass *pcc =3D POWERPC_CPU_CLASS(object_class_by_name(cputyp= e)); + return pcc_compat(pcc, compat_pvr, min_compat_pvr, max_compat_pvr); +} + void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp) { const CompatInfo *compat =3D compat_by_pvr(compat_pvr); diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 874da6efbc..c7f3fb6b73 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1369,7 +1369,11 @@ static inline int cpu_mmu_index (CPUPPCState *env, b= ool ifetch) #if defined(TARGET_PPC64) bool ppc_check_compat(PowerPCCPU *cpu, uint32_t compat_pvr, uint32_t min_compat_pvr, uint32_t max_compat_pvr); +bool ppc_type_check_compat(const char *cputype, uint32_t compat_pvr, + uint32_t min_compat_pvr, uint32_t max_compat_pv= r); + void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp); + #if !defined(CONFIG_USER_ONLY) void ppc_set_compat_all(uint32_t compat_pvr, Error **errp); #endif --=20 2.17.1 From nobody Sat May 4 11:46:54 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 1529303926803108.52895065751841; Sun, 17 Jun 2018 23:38:46 -0700 (PDT) Received: from localhost ([::1]:33124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnoD-00017l-6L for importer@patchew.org; Mon, 18 Jun 2018 02:38:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnlz-0008Lw-BP for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUnly-0001O8-A8 for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:19 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:38187) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fUnlx-0001LB-Ik; Mon, 18 Jun 2018 02:36:18 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 418Lvt6b31z9s0W; Mon, 18 Jun 2018 16:36:10 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1529303770; bh=2x55o4Lgn4Pyzqd+zb/lxeIAkiYzqiWIDGk11qJ1Lso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G+EpVvDcdeMD99wUBFSHM0kalNEgFEF5UKsX9YdqJAwJyJSySWfTuLxG1CdUEJ2ta yIc0bswxqqwQF7cYtef9vS5Ul+yc2yb8ZeVZOhsRf3fRWEybRoCQRrlOUrzPHiq49h QrBT4bSe23Y0N8gLlK6Tp++tkoKbYvD020E7zn1E= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Mon, 18 Jun 2018 16:35:59 +1000 Message-Id: <20180618063606.2513-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618063606.2513-1-david@gibson.dropbear.id.au> References: <20180618063606.2513-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] [PATCH 2/9] spapr: Compute effective capability values earlier 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, clg@kaod.org, qemu-devel@nongnu.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" Previously, the effective values of the various spapr capability flags were only determined at machine reset time. That was a lazy way of making sure it was after cpu initialization so it could use the cpu object to inform the defaults. But we've now improved the compat checking code so that we don't need to instantiate the cpus to use it. That lets us move the resolution of the capability defaults much earlier. This is going to be necessary for some future capabilities. Signed-off-by: David Gibson Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- hw/ppc/spapr.c | 6 ++++-- hw/ppc/spapr_caps.c | 9 ++++++--- include/hw/ppc/spapr.h | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index b0b94fc1f0..40858d047c 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1612,7 +1612,7 @@ static void spapr_machine_reset(void) void *fdt; int rc; =20 - spapr_caps_reset(spapr); + spapr_caps_apply(spapr); =20 first_ppc_cpu =3D POWERPC_CPU(first_cpu); if (kvm_enabled() && kvmppc_has_cap_mmu_radix() && @@ -2526,7 +2526,9 @@ static void spapr_machine_init(MachineState *machine) QLIST_INIT(&spapr->phbs); QTAILQ_INIT(&spapr->pending_dimm_unplugs); =20 - /* Check HPT resizing availability */ + /* Determine capabilities to run with */ + spapr_caps_init(spapr); + kvmppc_check_papr_resize_hpt(&resize_hpt_err); if (spapr->resize_hpt =3D=3D SPAPR_RESIZE_HPT_DEFAULT) { /* diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 469f38f0ef..dabed817d1 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -439,12 +439,12 @@ SPAPR_CAP_MIG_STATE(cfpc, SPAPR_CAP_CFPC); SPAPR_CAP_MIG_STATE(sbbc, SPAPR_CAP_SBBC); SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS); =20 -void spapr_caps_reset(sPAPRMachineState *spapr) +void spapr_caps_init(sPAPRMachineState *spapr) { sPAPRCapabilities default_caps; int i; =20 - /* First compute the actual set of caps we're running with.. */ + /* Compute the actual set of caps we should run with */ default_caps =3D default_caps_with_cpu(spapr, MACHINE(spapr)->cpu_type= ); =20 for (i =3D 0; i < SPAPR_CAP_NUM; i++) { @@ -455,8 +455,11 @@ void spapr_caps_reset(sPAPRMachineState *spapr) spapr->eff.caps[i] =3D default_caps.caps[i]; } } +} =20 - /* .. then apply those caps to the virtual hardware */ +void spapr_caps_apply(sPAPRMachineState *spapr) +{ + int i; =20 for (i =3D 0; i < SPAPR_CAP_NUM; i++) { sPAPRCapabilityInfo *info =3D &capability_table[i]; diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 3388750fc7..9dbd6010f5 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -798,7 +798,8 @@ static inline uint8_t spapr_get_cap(sPAPRMachineState *= spapr, int cap) return spapr->eff.caps[cap]; } =20 -void spapr_caps_reset(sPAPRMachineState *spapr); +void spapr_caps_init(sPAPRMachineState *spapr); +void spapr_caps_apply(sPAPRMachineState *spapr); void spapr_caps_add_properties(sPAPRMachineClass *smc, Error **errp); int spapr_caps_post_migration(sPAPRMachineState *spapr); =20 --=20 2.17.1 From nobody Sat May 4 11:46:54 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 15293039268638.979586231101962; Sun, 17 Jun 2018 23:38:46 -0700 (PDT) Received: from localhost ([::1]:33123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnoC-00017N-Ef for importer@patchew.org; Mon, 18 Jun 2018 02:38:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnlz-0008Lv-7v for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUnly-0001Nw-7i for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:19 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:33963) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fUnlx-0001LC-Ih; Mon, 18 Jun 2018 02:36:18 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 418Lvv5d94z9s3T; Mon, 18 Jun 2018 16:36:11 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1529303771; bh=CnU6/o+muomCEWBYcwetKz1bqjx7eyNwfAed29A6b7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lq6GO4DeOHeV377oY67pyf63TSjZF+AD+k94hc7EaG96yeWr9GvJ3wk/TnVY+Ql86 I6u7q403pJb5USfoLhw5+IervcWCTrMKjvPj6ak62LPlJMySzIMe76s++9vFrxXGEh mcknC3EKwGrrrxHWm8muzFdaNfErxzFnG13RQ6yQ= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Mon, 18 Jun 2018 16:36:00 +1000 Message-Id: <20180618063606.2513-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618063606.2513-1-david@gibson.dropbear.id.au> References: <20180618063606.2513-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] [PATCH 3/9] 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, clg@kaod.org, qemu-devel@nongnu.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 Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- 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 dabed817d1..68a4243efc 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -59,6 +59,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, @@ -472,6 +474,23 @@ void spapr_caps_apply(sPAPRMachineState *spapr) } } =20 +void spapr_caps_cpu_apply(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 aef3be33a3..324623190d 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -76,6 +76,8 @@ static void spapr_cpu_reset(void *opaque) spapr_cpu->slb_shadow_size =3D 0; spapr_cpu->dtl_addr =3D 0; spapr_cpu->dtl_size =3D 0; + + spapr_caps_cpu_apply(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 9dbd6010f5..9dd46a72f6 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -800,6 +800,7 @@ static inline uint8_t spapr_get_cap(sPAPRMachineState *= spapr, int cap) =20 void spapr_caps_init(sPAPRMachineState *spapr); void spapr_caps_apply(sPAPRMachineState *spapr); +void spapr_caps_cpu_apply(sPAPRMachineState *spapr, PowerPCCPU *cpu); void spapr_caps_add_properties(sPAPRMachineClass *smc, Error **errp); int spapr_caps_post_migration(sPAPRMachineState *spapr); =20 --=20 2.17.1 From nobody Sat May 4 11:46:54 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 1529303926137993.2677970275906; Sun, 17 Jun 2018 23:38:46 -0700 (PDT) Received: from localhost ([::1]:33125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnoE-00018f-EX for importer@patchew.org; Mon, 18 Jun 2018 02:38:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnlz-0008Lx-GE for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUnly-0001O2-8O for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:19 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:58963) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fUnlx-0001LD-Ie; Mon, 18 Jun 2018 02:36:18 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 418Lvv6r5Qz9s31; Mon, 18 Jun 2018 16:36:11 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1529303771; bh=0yLqPMlZHdn226EmRB5o90nLUdqh68TwLUa5Cw9qg8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lYfmcueLZHFwdNbJCl9nSvFdQCnKnT5c8FHy2/YE/kiVrasuucw4nfvuXMSn/xneA T5qcAv1Vo1gUzUJODovwHU//jFAB+1QFIuPyFf0mecNaittMLtiYwz15Xhnh6VBk0g k6tP4tgFhvpFowiXqUtPoPDSy/3QAbdyRZhNBA78= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Mon, 18 Jun 2018 16:36:01 +1000 Message-Id: <20180618063606.2513-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618063606.2513-1-david@gibson.dropbear.id.au> References: <20180618063606.2513-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] [PATCH 4/9] target/ppc: Add kvmppc_hpt_needs_host_contiguous_pages() helper 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, clg@kaod.org, qemu-devel@nongnu.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 a restriction that for HPT mode guests, guest pages must be hpa contiguous as well as gpa contiguous. We have to account for that in various places. We determine whether we're subject to this restriction from the SMMU information exposed by KVM. Planned cleanups to the way we handle this will require knowing whether this restriction is in play in wider parts of the code. So, expose a helper function which returns it. This does mean some redundant calls to kvm_get_smmu_info(), but they'll go away again with future cleanups. Signed-off-by: David Gibson Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- target/ppc/kvm.c | 17 +++++++++++++++-- target/ppc/kvm_ppc.h | 6 ++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 5c0e313ca6..50b5d01432 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -406,9 +406,22 @@ target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, } } =20 +bool kvmppc_hpt_needs_host_contiguous_pages(void) +{ + PowerPCCPU *cpu =3D POWERPC_CPU(first_cpu); + static struct kvm_ppc_smmu_info smmu_info; + + if (!kvm_enabled()) { + return false; + } + + kvm_get_smmu_info(cpu, &smmu_info); + return !!(smmu_info.flags & KVM_PPC_PAGE_SIZES_REAL); +} + static bool kvm_valid_page_size(uint32_t flags, long rampgsize, uint32_t s= hift) { - if (!(flags & KVM_PPC_PAGE_SIZES_REAL)) { + if (!kvmppc_hpt_needs_host_contiguous_pages()) { return true; } =20 @@ -445,7 +458,7 @@ static void kvm_fixup_page_sizes(PowerPCCPU *cpu) /* 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 (kvmppc_hpt_needs_host_contiguous_pages()) { if (getpagesize() >=3D 0x10000) { cpu->hash64_opts->flags |=3D PPC_HASH64_CI_LARGEPAGE; } else { diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index e2840e1d33..a7ddb8a5d6 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -70,6 +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_hpt_needs_host_contiguous_pages(void); bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path); =20 #else @@ -222,6 +223,11 @@ static inline uint64_t kvmppc_rma_size(uint64_t curren= t_size, return ram_size; } =20 +static inline bool kvmppc_hpt_needs_host_contiguous_pages(void) +{ + return false; +} + static inline bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path) { return true; --=20 2.17.1 From nobody Sat May 4 11:46:54 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 1529304147745516.8841579804695; Sun, 17 Jun 2018 23:42:27 -0700 (PDT) Received: from localhost ([::1]:33150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnru-0004In-UW for importer@patchew.org; Mon, 18 Jun 2018 02:42:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnm3-0008OU-Lz for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUnm1-0001RO-Ps for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:23 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:44909) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fUnm1-0001OU-1s; Mon, 18 Jun 2018 02:36:21 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 418Lvw1T7Hz9s5b; Mon, 18 Jun 2018 16:36:11 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1529303772; bh=mr0nLLpy6Cgfz0mBtFQ1gJfiLpUCn+r3kvvdafdmZxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iRq5GblHSiang3dGaFm/xP3FiJ1c2+GjbAVoJXfuQVshJTXoHQ8XD4r33cNRUGCpg Z81XCA6AO4sMk8Z1ZHrxNuE70ehNyvt4ChKtVcXXpNHZ1CQRH0K2v8pn7z+7xy7PZJ pPPhgA5zjM6vwJiCuplRY6ZeIV14JLK+eAkK+Qio= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Mon, 18 Jun 2018 16:36:02 +1000 Message-Id: <20180618063606.2513-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618063606.2513-1-david@gibson.dropbear.id.au> References: <20180618063606.2513-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] [PATCH 5/9] 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, clg@kaod.org, qemu-devel@nongnu.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. For backwards compatibility, on older machine types we set it to the max available page size for the host. For the 3.0 machine type, we fix it to 16, the intention being to only allow HPT pagesizes up to 64kiB by default in future. Signed-off-by: David Gibson Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- hw/ppc/spapr.c | 12 +++++++++ hw/ppc/spapr_caps.c | 56 ++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 4 ++- 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 40858d047c..74a76e7e09 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -63,6 +63,7 @@ #include "hw/virtio/vhost-scsi-common.h" =20 #include "exec/address-spaces.h" +#include "exec/ram_addr.h" #include "hw/usb.h" #include "qemu/config-file.h" #include "qemu/error-report.h" @@ -4043,6 +4044,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_MAXPAGESIZE] =3D 16; /* 64kiB */ spapr_caps_add_properties(smc, &error_abort); } =20 @@ -4126,8 +4128,18 @@ static void spapr_machine_2_12_instance_options(Mach= ineState *machine) =20 static void spapr_machine_2_12_class_options(MachineClass *mc) { + sPAPRMachineClass *smc =3D SPAPR_MACHINE_CLASS(mc); + uint8_t mps; + spapr_machine_3_0_class_options(mc); SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_12); + + if (kvmppc_hpt_needs_host_contiguous_pages()) { + mps =3D ctz64(qemu_getrampagesize()); + } else { + mps =3D 34; /* allow everything up to 16GiB, i.e. everything */ + } + smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE] =3D mps; } =20 DEFINE_SPAPR_MACHINE(2_12, "2.12", false); diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 68a4243efc..6cdc0c94e7 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 @@ -144,6 +145,42 @@ out: g_free(val); } =20 +static void spapr_cap_get_pagesize(Object *obj, Visitor *v, const char *na= me, + void *opaque, Error **errp) +{ + sPAPRCapabilityInfo *cap =3D opaque; + sPAPRMachineState *spapr =3D SPAPR_MACHINE(obj); + uint8_t val =3D spapr_get_cap(spapr, cap->index); + uint64_t pagesize =3D (1ULL << val); + + visit_type_size(v, name, &pagesize, errp); +} + +static void spapr_cap_set_pagesize(Object *obj, Visitor *v, const char *na= me, + void *opaque, Error **errp) +{ + sPAPRCapabilityInfo *cap =3D opaque; + sPAPRMachineState *spapr =3D SPAPR_MACHINE(obj); + uint64_t pagesize; + uint8_t val; + Error *local_err =3D NULL; + + visit_type_size(v, name, &pagesize, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (!is_power_of_2(pagesize)) { + error_setg(errp, "cap-%s must be a power of 2", cap->name); + return; + } + + val =3D ctz64(pagesize); + spapr->cmd_line_caps[cap->index] =3D true; + spapr->eff.caps[cap->index] =3D val; +} + static void cap_htm_apply(sPAPRMachineState *spapr, uint8_t val, Error **e= rrp) { if (!val) { @@ -267,6 +304,16 @@ static void cap_safe_indirect_branch_apply(sPAPRMachin= eState *spapr, =20 #define VALUE_DESC_TRISTATE " (broken, workaround, fixed)" =20 +static void cap_hpt_maxpagesize_apply(sPAPRMachineState *spapr, + uint8_t val, Error **errp) +{ + if (val < 12) { + error_setg(errp, "Require at least 4kiB hpt-max-page-size"); + } else if (val < 16) { + warn_report("Many guests require at least 64kiB hpt-max-page-size"= ); + } +} + sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] =3D { [SPAPR_CAP_HTM] =3D { .name =3D "htm", @@ -326,6 +373,15 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = =3D { .possible =3D &cap_ibs_possible, .apply =3D cap_safe_indirect_branch_apply, }, + [SPAPR_CAP_HPT_MAXPAGESIZE] =3D { + .name =3D "hpt-max-page-size", + .description =3D "Maximum page size for Hash Page Table guests", + .index =3D SPAPR_CAP_HPT_MAXPAGESIZE, + .get =3D spapr_cap_get_pagesize, + .set =3D spapr_cap_set_pagesize, + .type =3D "int", + .apply =3D cap_hpt_maxpagesize_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 9dd46a72f6..c97593d032 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 Size (encoded as a shift) */ +#define SPAPR_CAP_HPT_MAXPAGESIZE 0x06 /* Num Caps */ -#define SPAPR_CAP_NUM (SPAPR_CAP_IBS + 1) +#define SPAPR_CAP_NUM (SPAPR_CAP_HPT_MAXPAGESIZE + 1) =20 /* * Capability Values --=20 2.17.1 From nobody Sat May 4 11:46:54 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 1529304278051488.79220841467725; Sun, 17 Jun 2018 23:44:38 -0700 (PDT) Received: from localhost ([::1]:33164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUntx-00063E-2e for importer@patchew.org; Mon, 18 Jun 2018 02:44:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnm3-0008OK-IH for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUnm1-0001RN-Pw for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:23 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:58505) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fUnm0-0001OW-V9; Mon, 18 Jun 2018 02:36:21 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 418Lvw2fGGz9s4V; Mon, 18 Jun 2018 16:36:11 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1529303772; bh=jqcl9dfi86OlG5Hc0zKh7bGPgaBsCLszKS7K0jS14Tw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fqtdqgOfoM3Wr59uOfgHZFbbCIniOtLVkG1K+stkLN9CizaNiABfKfMRtc029NZze gJKWqJL57UFFsUlNTPopJDebFqnoIFvOIrBF0u1nmVtfi2+1LvKrqA2+yiWk6msy+x F2IY6u5zghR5Uo74giIDq7bD96h4e3Q+XEV3v5A0= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Mon, 18 Jun 2018 16:36:03 +1000 Message-Id: <20180618063606.2513-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618063606.2513-1-david@gibson.dropbear.id.au> References: <20180618063606.2513-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] [PATCH 6/9] 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, clg@kaod.org, qemu-devel@nongnu.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 Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- hw/ppc/spapr.c | 17 +++++++---------- hw/ppc/spapr_caps.c | 20 ++++++++++++++++++++ include/hw/ppc/spapr.h | 3 +++ target/ppc/kvm.c | 14 -------------- target/ppc/kvm_ppc.h | 6 ------ 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 74a76e7e09..efd36e92e2 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3192,11 +3192,13 @@ static void spapr_memory_pre_plug(HotplugHandler *h= otplug_dev, DeviceState *dev, Error **errp) { const sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(hotplug_dev); + 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 if (!smc->dr_lmb_enabled) { error_setg(errp, "Memory hotplug not supported for this machine"); @@ -3215,15 +3217,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 6cdc0c94e7..9fc739b3f5 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" @@ -304,6 +305,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_maxpagesize_apply(sPAPRMachineState *spapr, uint8_t val, Error **errp) { @@ -312,6 +330,8 @@ static void cap_hpt_maxpagesize_apply(sPAPRMachineState= *spapr, } else if (val < 16) { warn_report("Many guests require at least 64kiB hpt-max-page-size"= ); } + + 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 c97593d032..75e2cf2687 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -806,4 +806,7 @@ void spapr_caps_cpu_apply(sPAPRMachineState *spapr, Pow= erPCCPU *cpu); 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 50b5d01432..9cfbd388ad 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -500,26 +500,12 @@ static void kvm_fixup_page_sizes(PowerPCCPU *cpu) cpu->hash64_opts->flags &=3D ~PPC_HASH64_1TSEG; } } - -bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path) -{ - Object *mem_obj =3D object_resolve_path(obj_path, NULL); - long pagesize =3D host_memory_backend_pagesize(MEMORY_BACKEND(mem_obj)= ); - - return pagesize >=3D max_cpu_page_size; -} - #else /* defined (TARGET_PPC64) */ =20 static inline void kvm_fixup_page_sizes(PowerPCCPU *cpu) { } =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 a7ddb8a5d6..443fca0a4e 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -71,7 +71,6 @@ 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); -bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path); =20 #else =20 @@ -228,11 +227,6 @@ static inline bool kvmppc_hpt_needs_host_contiguous_pa= ges(void) return false; } =20 -static inline bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path) -{ - return true; -} - static inline bool kvmppc_has_cap_spapr_vfio(void) { return false; --=20 2.17.1 From nobody Sat May 4 11:46:54 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 1529304109961467.91961397323337; Sun, 17 Jun 2018 23:41:49 -0700 (PDT) Received: from localhost ([::1]:33149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnrJ-0003oE-19 for importer@patchew.org; Mon, 18 Jun 2018 02:41:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnm2-0008N7-H1 for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUnm1-0001QN-9A for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:22 -0400 Received: from ozlabs.org ([203.11.71.1]:43021) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fUnm0-0001OQ-LQ; Mon, 18 Jun 2018 02:36:21 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 418Lvw0KbMz9s47; Mon, 18 Jun 2018 16:36:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1529303772; bh=Jq5eo+xyoP3ErpLjDascjZfbkze66Zo0ztz2Mnvr55w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GSTPsw/YaopiyAadWSFB2z80y2OZGjEjFITV+oIyYrhE/DKsoxfYen7pnGSEtR8rf /xmYeBvCTOJJCpjtLMwg7WqsnQWDc1O8gf7YWd2iAk1dKKFNGpU2qWq1/Zg5kAE+VR SOTPAweyoOMfQDhwmV8/yIlN+hoOiEvXg4tuHdCs= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Mon, 18 Jun 2018 16:36:04 +1000 Message-Id: <20180618063606.2513-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618063606.2513-1-david@gibson.dropbear.id.au> References: <20180618063606.2513-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] [PATCH 7/9] 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, clg@kaod.org, qemu-devel@nongnu.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 Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- 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 aa200cba4c..276d9015e7 100644 --- a/target/ppc/mmu-hash64.c +++ b/target/ppc/mmu-hash64.c @@ -1166,3 +1166,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 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 53dcec5b93..f11efc9cbc 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.17.1 From nobody Sat May 4 11:46:54 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 152930410027953.6634774354211; Sun, 17 Jun 2018 23:41:40 -0700 (PDT) Received: from localhost ([::1]:33148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnr9-0003f5-HD for importer@patchew.org; Mon, 18 Jun 2018 02:41:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnm2-0008Ma-40 for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUnm0-0001QA-VL for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:22 -0400 Received: from ozlabs.org ([203.11.71.1]:38033) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fUnm0-0001OP-JZ; Mon, 18 Jun 2018 02:36:20 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 418Lvw3J9pz9s4s; Mon, 18 Jun 2018 16:36:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1529303772; bh=BhSg7zhaWOSzsTVqPuMJ45vKD3+mlLYrdd5yZO+obBY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BBx+D9PpncJNl70ncuYpZ1isJQWTSEwv7PCtLkUkghkgQbV3EMDsNTlrss7Jh0omX QwLW0TLt8mGnDYb5x8Gb2XOFG19NKeU24CgxwfvG8IjLi3hnW4e15KjOazfw1JV2zG nC3LiATTP4lgoFOcHcAj68r2xzvKXMTKuJ60aNFg= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Mon, 18 Jun 2018 16:36:05 +1000 Message-Id: <20180618063606.2513-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618063606.2513-1-david@gibson.dropbear.id.au> References: <20180618063606.2513-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] [PATCH 8/9] 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, clg@kaod.org, qemu-devel@nongnu.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 Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- 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 9fc739b3f5..0584c7c6ab 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -334,6 +334,38 @@ static void cap_hpt_maxpagesize_apply(sPAPRMachineStat= e *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_maxpagesize_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", @@ -401,6 +433,7 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] =3D= { .set =3D spapr_cap_set_pagesize, .type =3D "int", .apply =3D cap_hpt_maxpagesize_apply, + .cpu_apply =3D cap_hpt_maxpagesize_cpu_apply, }, }; =20 --=20 2.17.1 From nobody Sat May 4 11:46:54 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 1529304267851750.129601405915; Sun, 17 Jun 2018 23:44:27 -0700 (PDT) Received: from localhost ([::1]:33163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnti-0005sK-M9 for importer@patchew.org; Mon, 18 Jun 2018 02:44:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUnm3-0008OF-H7 for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUnm1-0001Re-Sh for qemu-devel@nongnu.org; Mon, 18 Jun 2018 02:36:23 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:56627) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fUnm1-0001OV-41; Mon, 18 Jun 2018 02:36:21 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 418Lvw440mz9s6v; Mon, 18 Jun 2018 16:36:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1529303772; bh=Y+BeLfYVuAkbgcuTHCnE68h2g09oQChtXJD7OpjVdLA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YnO3iB0uxojVGNoKwrmcpOQmm1lTa35Jcr7WkrvHOwuYT1R8g6HLIU4mAQN9w+jvV xi3ybFuiEjjpeLpdMWaJIIPpR97Kl9+Elylr1YqeUcpWG4SHBTIPsINlV22SvTmQA8 cb6ZacxSnhOAGmVeE8+RRFHJxTcQQuML8pgUbC/U= From: David Gibson To: groug@kaod.org, abologna@redhat.com Date: Mon, 18 Jun 2018 16:36:06 +1000 Message-Id: <20180618063606.2513-10-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618063606.2513-1-david@gibson.dropbear.id.au> References: <20180618063606.2513-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] [PATCH 9/9] 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, clg@kaod.org, qemu-devel@nongnu.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 Reviewed-by: C=C3=A9dric Le Goater --- hw/ppc/spapr_caps.c | 2 +- hw/ppc/spapr_cpu_core.c | 2 + target/ppc/kvm.c | 133 ++++++++++++++++++++-------------------- target/ppc/kvm_ppc.h | 5 ++ 4 files changed, 73 insertions(+), 69 deletions(-) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 0584c7c6ab..bc89a4cd70 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -308,7 +308,7 @@ static void cap_safe_indirect_branch_apply(sPAPRMachine= State *spapr, void spapr_check_pagesize(sPAPRMachineState *spapr, hwaddr pagesize, Error **errp) { - hwaddr maxpagesize =3D (1ULL << spapr->eff.caps[SPAPR_CAP_HPT_MPS]); + hwaddr maxpagesize =3D (1ULL << spapr->eff.caps[SPAPR_CAP_HPT_MAXPAGES= IZE]); =20 if (!kvmppc_hpt_needs_host_contiguous_pages()) { return; diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 324623190d..4e8fa28796 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -78,6 +78,8 @@ static void spapr_cpu_reset(void *opaque) spapr_cpu->dtl_size =3D 0; =20 spapr_caps_cpu_apply(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 9cfbd388ad..b386335014 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -419,93 +419,93 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void) return !!(smmu_info.flags & KVM_PPC_PAGE_SIZES_REAL); } =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 (!kvmppc_hpt_needs_host_contiguous_pages()) { - 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 hash64 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 (kvmppc_hpt_needs_host_contiguous_pages()) { - 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; - } -} -#else /* defined (TARGET_PPC64) */ =20 -static inline void kvm_fixup_page_sizes(PowerPCCPU *cpu) -{ + 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"); + } + } } - #endif /* !defined (TARGET_PPC64) */ =20 unsigned long kvm_arch_vcpu_id(CPUState *cpu) @@ -551,9 +551,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.17.1