From patchwork Thu Jun 28 10:14:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 936034 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41GbKL3l51z9ryk for ; Thu, 28 Jun 2018 20:16:22 +1000 (AEST) Received: from localhost ([::1]:35520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYTyO-00008I-4s for incoming@patchwork.ozlabs.org; Thu, 28 Jun 2018 06:16:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYTxQ-0008Ki-VY for qemu-devel@nongnu.org; Thu, 28 Jun 2018 06:15:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYTxN-0005aZ-O6 for qemu-devel@nongnu.org; Thu, 28 Jun 2018 06:15:20 -0400 Received: from 9.mo3.mail-out.ovh.net ([87.98.184.141]:54982) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYTxN-0005Y3-DU for qemu-devel@nongnu.org; Thu, 28 Jun 2018 06:15:17 -0400 Received: from player738.ha.ovh.net (unknown [10.109.108.75]) by mo3.mail-out.ovh.net (Postfix) with ESMTP id 9BE2C1BFE5D for ; Thu, 28 Jun 2018 12:15:15 +0200 (CEST) Received: from [192.168.0.243] (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player738.ha.ovh.net (Postfix) with ESMTPA id 5BF3C5A84; Thu, 28 Jun 2018 12:14:57 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 12:14:51 +0200 Message-ID: <153018089136.336571.15410439376219137880.stgit@bahia> In-Reply-To: <153018086531.336571.17029459443980070626.stgit@bahia.lan> References: <153018086531.336571.17029459443980070626.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 X-Ovh-Tracer-Id: 13055090897630828886 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtiedrudelgddviecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.98.184.141 Subject: [Qemu-devel] [PATCH 1/3] target/ppc/kvm: don't pass cpu to kvm_get_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: Eduardo Habkost , qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric?= Le Goater , Paolo Bonzini , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In a future patch the machine code will need to retrieve the MMU information from KVM during machine initialization before the CPUs are created. Actually, KVM_PPC_GET_SMMU_INFO is a VM class ioctl, and thus, it only needs the kvm_state global variable to be set. The fallback code only needs informations from the machine's CPU model class. So this patch basically drops the CPU argument to kvm_get_smmu_info() and kvm_get_fallback_smmu_info(). The kvm_state and current_machine globals are used instead to reach out to KVM and CPU model details respectively. Signed-off-by: Greg Kurz Reviewed-by: Cédric Le Goater --- target/ppc/kvm.c | 37 ++++++++++++++++++------------------- target/ppc/mmu-hash64.h | 8 +++++++- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 4df4ff6cbff2..9fae89ff8175 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -248,11 +248,12 @@ static int kvm_booke206_tlb_init(PowerPCCPU *cpu) #if defined(TARGET_PPC64) -static void kvm_get_fallback_smmu_info(PowerPCCPU *cpu, - struct kvm_ppc_smmu_info *info) +static void kvm_get_fallback_smmu_info(struct kvm_ppc_smmu_info *info) { - CPUPPCState *env = &cpu->env; - CPUState *cs = CPU(cpu); + const PowerPCCPUClass *pcc; + + assert(current_machine != NULL); + pcc = POWERPC_CPU_CLASS(object_class_by_name(current_machine->cpu_type)); memset(info, 0, sizeof(*info)); @@ -278,7 +279,7 @@ static void kvm_get_fallback_smmu_info(PowerPCCPU *cpu, * implements KVM_CAP_PPC_GET_SMMU_INFO and thus doesn't hit * this fallback. */ - if (kvmppc_is_pr(cs->kvm_state)) { + if (kvmppc_is_pr(kvm_state)) { /* No flags */ info->flags = 0; info->slb_size = 64; @@ -300,12 +301,12 @@ static void kvm_get_fallback_smmu_info(PowerPCCPU *cpu, /* HV KVM has backing store size restrictions */ info->flags = KVM_PPC_PAGE_SIZES_REAL; - if (ppc_hash64_has(cpu, PPC_HASH64_1TSEG)) { + if (hash64_opts_has(pcc->hash64_opts, PPC_HASH64_1TSEG)) { info->flags |= KVM_PPC_1T_SEGMENTS; } - if (env->mmu_model == POWERPC_MMU_2_06 || - env->mmu_model == POWERPC_MMU_2_07) { + if (pcc->mmu_model == POWERPC_MMU_2_06 || + pcc->mmu_model == POWERPC_MMU_2_07) { info->slb_size = 32; } else { info->slb_size = 64; @@ -319,8 +320,8 @@ static void kvm_get_fallback_smmu_info(PowerPCCPU *cpu, i++; /* 64K on MMU 2.06 and later */ - if (env->mmu_model == POWERPC_MMU_2_06 || - env->mmu_model == POWERPC_MMU_2_07) { + if (pcc->mmu_model == POWERPC_MMU_2_06 || + pcc->mmu_model == POWERPC_MMU_2_07) { info->sps[i].page_shift = 16; info->sps[i].slb_enc = 0x110; info->sps[i].enc[0].page_shift = 16; @@ -336,19 +337,18 @@ static void kvm_get_fallback_smmu_info(PowerPCCPU *cpu, } } -static void kvm_get_smmu_info(PowerPCCPU *cpu, struct kvm_ppc_smmu_info *info) +static void kvm_get_smmu_info(struct kvm_ppc_smmu_info *info) { - CPUState *cs = CPU(cpu); int ret; - if (kvm_check_extension(cs->kvm_state, KVM_CAP_PPC_GET_SMMU_INFO)) { - ret = kvm_vm_ioctl(cs->kvm_state, KVM_PPC_GET_SMMU_INFO, info); + if (kvm_check_extension(kvm_state, KVM_CAP_PPC_GET_SMMU_INFO)) { + ret = kvm_vm_ioctl(kvm_state, KVM_PPC_GET_SMMU_INFO, info); if (ret == 0) { return; } } - kvm_get_fallback_smmu_info(cpu, info); + kvm_get_fallback_smmu_info(info); } struct ppc_radix_page_info *kvm_get_radix_page_info(void) @@ -408,14 +408,13 @@ target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, bool kvmppc_hpt_needs_host_contiguous_pages(void) { - PowerPCCPU *cpu = POWERPC_CPU(first_cpu); static struct kvm_ppc_smmu_info smmu_info; if (!kvm_enabled()) { return false; } - kvm_get_smmu_info(cpu, &smmu_info); + kvm_get_smmu_info(&smmu_info); return !!(smmu_info.flags & KVM_PPC_PAGE_SIZES_REAL); } @@ -429,7 +428,7 @@ void kvm_check_mmu(PowerPCCPU *cpu, Error **errp) return; } - kvm_get_smmu_info(cpu, &smmu_info); + kvm_get_smmu_info(&smmu_info); if (ppc_hash64_has(cpu, PPC_HASH64_1TSEG) && !(smmu_info.flags & KVM_PPC_1T_SEGMENTS)) { @@ -2168,7 +2167,7 @@ uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift) /* 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(&info); rampagesize = qemu_getrampagesize(); best_page_shift = 0; diff --git a/target/ppc/mmu-hash64.h b/target/ppc/mmu-hash64.h index f11efc9cbc1f..00a249f26bc3 100644 --- a/target/ppc/mmu-hash64.h +++ b/target/ppc/mmu-hash64.h @@ -169,9 +169,15 @@ struct PPCHash64Options { extern const PPCHash64Options ppc_hash64_opts_basic; extern const PPCHash64Options ppc_hash64_opts_POWER7; +static inline bool hash64_opts_has(const PPCHash64Options *opts, + unsigned feature) +{ + return !!(opts->flags & feature); +} + static inline bool ppc_hash64_has(PowerPCCPU *cpu, unsigned feature) { - return !!(cpu->hash64_opts->flags & feature); + return hash64_opts_has(cpu->hash64_opts, feature); } #endif /* CONFIG_USER_ONLY */ From patchwork Thu Jun 28 10:15:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 936033 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41GbKK2Vybz9ryk for ; Thu, 28 Jun 2018 20:16:21 +1000 (AEST) Received: from localhost ([::1]:35519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYTyM-000066-RY for incoming@patchwork.ozlabs.org; Thu, 28 Jun 2018 06:16:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYTxd-0008Ui-UV for qemu-devel@nongnu.org; Thu, 28 Jun 2018 06:15:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYTxa-0005wF-Nz for qemu-devel@nongnu.org; Thu, 28 Jun 2018 06:15:33 -0400 Received: from 4.mo173.mail-out.ovh.net ([46.105.34.219]:44888) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYTxa-0005v1-B7 for qemu-devel@nongnu.org; Thu, 28 Jun 2018 06:15:30 -0400 Received: from player159.ha.ovh.net (unknown [10.109.108.57]) by mo173.mail-out.ovh.net (Postfix) with ESMTP id C9496C753B for ; Thu, 28 Jun 2018 12:15:28 +0200 (CEST) Received: from [192.168.0.243] (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player159.ha.ovh.net (Postfix) with ESMTPA id F3FE44800B2; Thu, 28 Jun 2018 12:15:20 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 12:15:14 +0200 Message-ID: <153018091454.336571.7311461748726927045.stgit@bahia> In-Reply-To: <153018086531.336571.17029459443980070626.stgit@bahia.lan> References: <153018086531.336571.17029459443980070626.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 X-Ovh-Tracer-Id: 13060438921537689942 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtiedrudelgddviecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.34.219 Subject: [Qemu-devel] [PATCH 2/3] spapr: compute default value of "hpt-max-page-size" later 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: Eduardo Habkost , qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric?= Le Goater , Paolo Bonzini , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It is currently not possible to run a pseries-2.12 or older machine with HV KVM. QEMU prints the following and exits right away. qemu-system-ppc64: KVM doesn't support for base page shift 34 The "hpt-max-page-size" capability was recently added to spapr to hide host configuration details from HPT mode guests. Its default value for newer machine types is 64k. For backwards compatibility, pseries-2.12 and older machine types need a different value. This is handled as usual in a class init function. The default value is 16G, ie, all page sizes supported by POWER7 and newer CPUs, but HV KVM requires guest pages to be hpa contiguous as well as gpa contiguous. The default value is the page size used to back the guest RAM in this case. Unfortunately kvmppc_hpt_needs_host_contiguous_pages()->kvm_enabled() is called way before KVM init and returns false, even if the user requested KVM. We thus end up selecting 16G, which isn't supported by HV KVM. We fix this by moving the logic to spapr_machine_init() because this is the earliest call where we're sure kvm_enabled() can be trusted. Since the user cannot pass cap-hpt-max-page-size=0, we set the default to 0 in the pseries-2.12 class init function and use that as a flag in spapr_machine_init() to do the real work. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 8cc996d0b822..1eb45cd8c424 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2527,6 +2527,18 @@ static void spapr_machine_init(MachineState *machine) QLIST_INIT(&spapr->phbs); QTAILQ_INIT(&spapr->pending_dimm_unplugs); + /* This is for pseries-2.12 and older machine types */ + if (!smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE]) { + uint8_t mps; + + if (kvmppc_hpt_needs_host_contiguous_pages()) { + mps = ctz64(qemu_getrampagesize()); + } else { + mps = 34; /* allow everything up to 16GiB, i.e. everything */ + } + smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE] = mps; + } + /* Determine capabilities to run with */ spapr_caps_init(spapr); @@ -4103,17 +4115,16 @@ static void spapr_machine_2_12_instance_options(MachineState *machine) static void spapr_machine_2_12_class_options(MachineClass *mc) { sPAPRMachineClass *smc = 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 = ctz64(qemu_getrampagesize()); - } else { - mps = 34; /* allow everything up to 16GiB, i.e. everything */ - } - smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE] = mps; + /* We depend on kvm_enabled() to choose a default value for the + * hpt-max-page-size capability. Of course we can't do it here + * because this is too early and the HW accelerator isn't initialzed + * yet. Postpone this to spapr_machine_init(). + */ + smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE] = 0; } DEFINE_SPAPR_MACHINE(2_12, "2.12", false); From patchwork Thu Jun 28 10:15:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 936036 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41GbMs44w5z9ryk for ; Thu, 28 Jun 2018 20:18:33 +1000 (AEST) Received: from localhost ([::1]:35527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYU0V-0001hD-5v for incoming@patchwork.ozlabs.org; Thu, 28 Jun 2018 06:18:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36569) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYTxw-0000IK-7g for qemu-devel@nongnu.org; Thu, 28 Jun 2018 06:15:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYTxt-0006BK-2u for qemu-devel@nongnu.org; Thu, 28 Jun 2018 06:15:52 -0400 Received: from 7.mo2.mail-out.ovh.net ([188.165.48.182]:43264) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYTxs-00069j-P8 for qemu-devel@nongnu.org; Thu, 28 Jun 2018 06:15:49 -0400 Received: from player687.ha.ovh.net (unknown [10.109.105.112]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 1079913E300 for ; Thu, 28 Jun 2018 12:15:46 +0200 (CEST) Received: from [192.168.0.243] (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player687.ha.ovh.net (Postfix) with ESMTPA id 835E92C00CF; Thu, 28 Jun 2018 12:15:39 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 12:15:33 +0200 Message-ID: <153018093372.336571.7266716996862582164.stgit@bahia> In-Reply-To: <153018086531.336571.17029459443980070626.stgit@bahia.lan> References: <153018086531.336571.17029459443980070626.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 X-Ovh-Tracer-Id: 13065505470375500118 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtiedrudelgddvgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.48.182 Subject: [Qemu-devel] [PATCH 3/3] accel: forbid early use of kvm_enabled() and friends 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: Eduardo Habkost , qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric?= Le Goater , Paolo Bonzini , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It is unsafe to rely on *_enabled() helpers before the accelerator has been initialized, ie, accel_init_machine() has succeeded, because they always return false. But it is still possible to end up calling them indirectly by inadvertance, and cause QEMU to misbehave. This patch causes QEMU to abort if we try to check for an accelerator before it has been set up. This will help to catch bugs earlier. Signed-off-by: Greg Kurz Reviewed-by: David Gibson --- accel/accel.c | 7 +++++++ include/qemu-common.h | 3 ++- include/sysemu/accel.h | 1 + include/sysemu/kvm.h | 3 ++- qom/cpu.c | 1 + stubs/Makefile.objs | 1 + stubs/accel.c | 14 ++++++++++++++ target/i386/hax-all.c | 2 +- target/i386/whpx-all.c | 2 +- 9 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 stubs/accel.c diff --git a/accel/accel.c b/accel/accel.c index 966b2d8f536c..27900aac9cc5 100644 --- a/accel/accel.c +++ b/accel/accel.c @@ -51,6 +51,13 @@ static AccelClass *accel_find(const char *opt_name) return ac; } +bool assert_accelerator_initialized(bool allowed) +{ + assert(current_machine != NULL); + assert(current_machine->accelerator != NULL); + return allowed; +} + static int accel_init_machine(AccelClass *acc, MachineState *ms) { ObjectClass *oc = OBJECT_CLASS(acc); diff --git a/include/qemu-common.h b/include/qemu-common.h index 85f4749aefb7..01d5e4d97dbf 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -82,7 +82,8 @@ int qemu_openpty_raw(int *aslave, char *pty_name); extern bool tcg_allowed; void tcg_exec_init(unsigned long tb_size); #ifdef CONFIG_TCG -#define tcg_enabled() (tcg_allowed) +#include "sysemu/accel.h" +#define tcg_enabled() (assert_accelerator_initialized(tcg_allowed)) #else #define tcg_enabled() 0 #endif diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h index 637358f43014..76965cb69cc9 100644 --- a/include/sysemu/accel.h +++ b/include/sysemu/accel.h @@ -71,5 +71,6 @@ void configure_accelerator(MachineState *ms); void accel_register_compat_props(AccelState *accel); /* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post(MachineState *ms); +bool assert_accelerator_initialized(bool allowed); #endif diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 0b64b8e06786..ac4dbb2d6d6d 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -18,6 +18,7 @@ #include "qom/cpu.h" #include "exec/memattrs.h" #include "hw/irq.h" +#include "sysemu/accel.h" #ifdef NEED_CPU_H # ifdef CONFIG_KVM @@ -46,7 +47,7 @@ extern bool kvm_direct_msi_allowed; extern bool kvm_ioeventfd_any_length_allowed; extern bool kvm_msi_use_devid; -#define kvm_enabled() (kvm_allowed) +#define kvm_enabled() (assert_accelerator_initialized(kvm_allowed)) /** * kvm_irqchip_in_kernel: * diff --git a/qom/cpu.c b/qom/cpu.c index 92599f35413b..65a8f03a66a4 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -23,6 +23,7 @@ #include "qemu-common.h" #include "qom/cpu.h" #include "sysemu/hw_accel.h" +#include "sysemu/accel.h" #include "qemu/notify.h" #include "qemu/log.h" #include "exec/log.h" diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 53d3f32cb258..2d5142287525 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -43,3 +43,4 @@ stub-obj-y += xen-common.o stub-obj-y += xen-hvm.o stub-obj-y += pci-host-piix.o stub-obj-y += ram-block.o +stub-obj-y += accel.o diff --git a/stubs/accel.c b/stubs/accel.c new file mode 100644 index 000000000000..4f480f2d3f29 --- /dev/null +++ b/stubs/accel.c @@ -0,0 +1,14 @@ +/* + * accel stubs + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "sysemu/accel.h" + +bool assert_accelerator_initialized(bool allowed) +{ + return allowed; +} diff --git a/target/i386/hax-all.c b/target/i386/hax-all.c index d2e512856bb8..7c78bd7d094d 100644 --- a/target/i386/hax-all.c +++ b/target/i386/hax-all.c @@ -57,7 +57,7 @@ static int hax_arch_get_registers(CPUArchState *env); int hax_enabled(void) { - return hax_allowed; + return assert_accelerator_initialized(hax_allowed); } int valid_hax_tunnel_size(uint16_t size) diff --git a/target/i386/whpx-all.c b/target/i386/whpx-all.c index 6b42096698ee..e7f6bc5958e7 100644 --- a/target/i386/whpx-all.c +++ b/target/i386/whpx-all.c @@ -1422,7 +1422,7 @@ static int whpx_accel_init(MachineState *ms) int whpx_enabled(void) { - return whpx_allowed; + return assert_accelerator_initialized(whpx_allowed); } static void whpx_accel_class_init(ObjectClass *oc, void *data)