From nobody Tue Nov 4 18:34:30 2025 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 1530598983807352.01419620890977; Mon, 2 Jul 2018 23:23:03 -0700 (PDT) Received: from localhost ([::1]:38074 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faEiN-0005u1-0s for importer@patchew.org; Tue, 03 Jul 2018 02:23:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faEKf-00032T-G5 for qemu-devel@nongnu.org; Tue, 03 Jul 2018 01:58:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faEKa-0007A8-BQ for qemu-devel@nongnu.org; Tue, 03 Jul 2018 01:58:33 -0400 Received: from ozlabs.org ([203.11.71.1]:54741) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faEKZ-00074u-Fv; Tue, 03 Jul 2018 01:58:28 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 41KYMD6ldMz9sC3; Tue, 3 Jul 2018 15:58:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1530597496; bh=v5NN2gbLXuPij3ieoipV27WuA7ERCrEMrSVgDnu/wnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mklAmQcmsGt5QHvnoXgyu2fg5/XgfrqxDQ/9KAfIuZyaYiXm6SEnsbudbPGH+F3ke Vm9GWHpA4C+kOelHh63dYgKYG/3Yet6bpa+d7QtB1Y+xKpf+BHSh93WwWTuu7wG00z jBatr3nO1xuYhzMitmXMEEsqlHj/AR7tN6rAUHYo= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 3 Jul 2018 15:57:59 +1000 Message-Id: <20180703055804.13449-31-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180703055804.13449-1-david@gibson.dropbear.id.au> References: <20180703055804.13449-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] [PULL 30/35] target/ppc/kvm: get rid of kvm_get_fallback_smmu_info() 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: qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com, agraf@suse.de, aik@ozlabs.ru, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, David Gibson 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" From: Greg Kurz Now that we're checking our MMU configuration is supported by KVM, rather than adjusting it to KVM, it doesn't really make sense to have a fallback for kvm_get_smmu_info(). If KVM is too old or buggy to provide the details, we should rather treat this as an error. This patch thus adds error reporting to kvm_get_smmu_info() and get rid of the fallback code. QEMU will now terminate if KVM fails to provide MMU details. This may break some very old setups, but the simplification is worth the sacrifice. Signed-off-by: Greg Kurz Signed-off-by: David Gibson --- target/ppc/kvm.c | 117 ++++++++--------------------------------------- 1 file changed, 20 insertions(+), 97 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 4df4ff6cbf..b6000f12b9 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -248,107 +248,25 @@ static int kvm_booke206_tlb_init(PowerPCCPU *cpu) =20 =20 #if defined(TARGET_PPC64) -static void kvm_get_fallback_smmu_info(PowerPCCPU *cpu, - struct kvm_ppc_smmu_info *info) +static void kvm_get_smmu_info(PowerPCCPU *cpu, struct kvm_ppc_smmu_info *i= nfo, + Error **errp) { - CPUPPCState *env =3D &cpu->env; CPUState *cs =3D CPU(cpu); + int ret; =20 - memset(info, 0, sizeof(*info)); - - /* We don't have the new KVM_PPC_GET_SMMU_INFO ioctl, so - * need to "guess" what the supported page sizes are. - * - * For that to work we make a few assumptions: - * - * - Check whether we are running "PR" KVM which only supports 4K - * and 16M pages, but supports them regardless of the backing - * store characteritics. We also don't support 1T segments. - * - * This is safe as if HV KVM ever supports that capability or PR - * KVM grows supports for more page/segment sizes, those versions - * will have implemented KVM_CAP_PPC_GET_SMMU_INFO and thus we - * will not hit this fallback - * - * - Else we are running HV KVM. This means we only support page - * sizes that fit in the backing store. Additionally we only - * advertize 64K pages if the processor is ARCH 2.06 and we assume - * P7 encodings for the SLB and hash table. Here too, we assume - * support for any newer processor will mean a kernel that - * implements KVM_CAP_PPC_GET_SMMU_INFO and thus doesn't hit - * this fallback. - */ - if (kvmppc_is_pr(cs->kvm_state)) { - /* No flags */ - info->flags =3D 0; - info->slb_size =3D 64; - - /* Standard 4k base page size segment */ - info->sps[0].page_shift =3D 12; - info->sps[0].slb_enc =3D 0; - info->sps[0].enc[0].page_shift =3D 12; - info->sps[0].enc[0].pte_enc =3D 0; - - /* Standard 16M large page size segment */ - info->sps[1].page_shift =3D 24; - info->sps[1].slb_enc =3D SLB_VSID_L; - info->sps[1].enc[0].page_shift =3D 24; - info->sps[1].enc[0].pte_enc =3D 0; - } else { - int i =3D 0; - - /* HV KVM has backing store size restrictions */ - info->flags =3D KVM_PPC_PAGE_SIZES_REAL; - - if (ppc_hash64_has(cpu, PPC_HASH64_1TSEG)) { - info->flags |=3D KVM_PPC_1T_SEGMENTS; - } - - if (env->mmu_model =3D=3D POWERPC_MMU_2_06 || - env->mmu_model =3D=3D POWERPC_MMU_2_07) { - info->slb_size =3D 32; - } else { - info->slb_size =3D 64; - } - - /* Standard 4k base page size segment */ - info->sps[i].page_shift =3D 12; - info->sps[i].slb_enc =3D 0; - info->sps[i].enc[0].page_shift =3D 12; - info->sps[i].enc[0].pte_enc =3D 0; - i++; - - /* 64K on MMU 2.06 and later */ - if (env->mmu_model =3D=3D POWERPC_MMU_2_06 || - env->mmu_model =3D=3D POWERPC_MMU_2_07) { - info->sps[i].page_shift =3D 16; - info->sps[i].slb_enc =3D 0x110; - info->sps[i].enc[0].page_shift =3D 16; - info->sps[i].enc[0].pte_enc =3D 1; - i++; - } - - /* Standard 16M large page size segment */ - info->sps[i].page_shift =3D 24; - info->sps[i].slb_enc =3D SLB_VSID_L; - info->sps[i].enc[0].page_shift =3D 24; - info->sps[i].enc[0].pte_enc =3D 0; + if (!kvm_check_extension(cs->kvm_state, KVM_CAP_PPC_GET_SMMU_INFO)) { + error_setg(errp, "KVM doesn't expose the MMU features it supports"= ); + error_append_hint(errp, "Consider switching to a newer KVM\n"); + return; } -} - -static void kvm_get_smmu_info(PowerPCCPU *cpu, struct kvm_ppc_smmu_info *i= nfo) -{ - CPUState *cs =3D CPU(cpu); - int ret; =20 - if (kvm_check_extension(cs->kvm_state, KVM_CAP_PPC_GET_SMMU_INFO)) { - ret =3D kvm_vm_ioctl(cs->kvm_state, KVM_PPC_GET_SMMU_INFO, info); - if (ret =3D=3D 0) { - return; - } + ret =3D kvm_vm_ioctl(cs->kvm_state, KVM_PPC_GET_SMMU_INFO, info); + if (ret =3D=3D 0) { + return; } =20 - kvm_get_fallback_smmu_info(cpu, info); + error_setg_errno(errp, -ret, + "KVM failed to provide the MMU features it supports"); } =20 struct ppc_radix_page_info *kvm_get_radix_page_info(void) @@ -415,7 +333,7 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void) return false; } =20 - kvm_get_smmu_info(cpu, &smmu_info); + kvm_get_smmu_info(cpu, &smmu_info, &error_fatal); return !!(smmu_info.flags & KVM_PPC_PAGE_SIZES_REAL); } =20 @@ -423,13 +341,18 @@ void kvm_check_mmu(PowerPCCPU *cpu, Error **errp) { struct kvm_ppc_smmu_info smmu_info; int iq, ik, jq, jk; + Error *local_err =3D NULL; =20 /* For now, we only have anything to check on hash64 MMUs */ if (!cpu->hash64_opts || !kvm_enabled()) { return; } =20 - kvm_get_smmu_info(cpu, &smmu_info); + kvm_get_smmu_info(cpu, &smmu_info, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 if (ppc_hash64_has(cpu, PPC_HASH64_1TSEG) && !(smmu_info.flags & KVM_PPC_1T_SEGMENTS)) { @@ -2168,7 +2091,7 @@ uint64_t kvmppc_rma_size(uint64_t current_size, unsig= ned int hash_shift) =20 /* Find the largest hardware supported page size that's less than * or equal to the (logical) backing page size of guest RAM */ - kvm_get_smmu_info(POWERPC_CPU(first_cpu), &info); + kvm_get_smmu_info(POWERPC_CPU(first_cpu), &info, &error_fatal); rampagesize =3D qemu_getrampagesize(); best_page_shift =3D 0; =20 --=20 2.17.1