From nobody Mon Feb 9 23:17:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552381538051864.4870552048963; Tue, 12 Mar 2019 02:05:38 -0700 (PDT) Received: from localhost ([127.0.0.1]:47688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3dLt-00010a-0N for importer@patchew.org; Tue, 12 Mar 2019 05:05:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3dCZ-00021e-Kc for qemu-devel@nongnu.org; Tue, 12 Mar 2019 04:56:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3dCY-0001oV-E9 for qemu-devel@nongnu.org; Tue, 12 Mar 2019 04:55:59 -0400 Received: from ozlabs.org ([203.11.71.1]:40961) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h3dCX-0001SB-Jt; Tue, 12 Mar 2019 04:55:58 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 44JTML4wR3z9sP3; Tue, 12 Mar 2019 19:55:25 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1552380926; bh=+7D9TKkDLfa7A2GaqxbDuEgM3U5UOSVXe+25Kr6WabI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nZYXGO2VRh4jZdfiTBAHktrUGzHBsuxKdtDGoKcDpw+6EPFTaOHwqFXA3EvpUal5s ZfUO332WJu/9h79P75BHeAxzToiBJLZtDTOh3vyGxpqaan83uA4jmruTZMXpVSGYEN J5etQbrSjryq1bGRMgqJjU5oKo7Vi7KjhhuafmhY= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 12 Mar 2019 19:54:15 +1100 Message-Id: <20190312085502.8203-16-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190312085502.8203-1-david@gibson.dropbear.id.au> References: <20190312085502.8203-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PULL 15/62] target/ppc: Refactor kvm_handle_debug 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: lvivier@redhat.com, Fabiano Rosas , Alexey Kardashevskiy , qemu-devel@nongnu.org, 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) Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas There are four scenarios being handled in this function: - single stepping - hardware breakpoints - software breakpoints - fallback (no debug supported) A future patch will add code to handle specific single step and software breakpoints cases so let's split each scenario into its own function now to avoid hurting readability. Signed-off-by: Fabiano Rosas Reviewed-by: Alexey Kardashevskiy Message-Id: <20190228225759.21328-5-farosas@linux.ibm.com> Signed-off-by: David Gibson --- target/ppc/kvm.c | 86 ++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index a54fb9f0a8..4a79a75f63 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -1624,52 +1624,66 @@ static int kvm_handle_hw_breakpoint(CPUState *cs, return handle; } =20 +static int kvm_handle_singlestep(void) +{ + return 1; +} + +static int kvm_handle_sw_breakpoint(void) +{ + return 1; +} + static int kvm_handle_debug(PowerPCCPU *cpu, struct kvm_run *run) { CPUState *cs =3D CPU(cpu); CPUPPCState *env =3D &cpu->env; struct kvm_debug_exit_arch *arch_info =3D &run->debug.arch; - int handle =3D 0; =20 if (cs->singlestep_enabled) { - handle =3D 1; - } else if (arch_info->status) { - handle =3D kvm_handle_hw_breakpoint(cs, arch_info); - } else if (kvm_find_sw_breakpoint(cs, arch_info->address)) { - handle =3D 1; - } else { - /* QEMU is not able to handle debug exception, so inject - * program exception to guest; - * Yes program exception NOT debug exception !! - * When QEMU is using debug resources then debug exception must - * be always set. To achieve this we set MSR_DE and also set - * MSRP_DEP so guest cannot change MSR_DE. - * When emulating debug resource for guest we want guest - * to control MSR_DE (enable/disable debug interrupt on need). - * Supporting both configurations are NOT possible. - * So the result is that we cannot share debug resources - * between QEMU and Guest on BOOKE architecture. - * In the current design QEMU gets the priority over guest, - * this means that if QEMU is using debug resources then guest - * cannot use them; - * For software breakpoint QEMU uses a privileged instruction; - * So there cannot be any reason that we are here for guest - * set debug exception, only possibility is guest executed a - * privileged / illegal instruction and that's why we are - * injecting a program interrupt. - */ + return kvm_handle_singlestep(); + } =20 - cpu_synchronize_state(cs); - /* env->nip is PC, so increment this by 4 to use - * ppc_cpu_do_interrupt(), which set srr0 =3D env->nip - 4. - */ - env->nip +=3D 4; - cs->exception_index =3D POWERPC_EXCP_PROGRAM; - env->error_code =3D POWERPC_EXCP_INVAL; - ppc_cpu_do_interrupt(cs); + if (arch_info->status) { + return kvm_handle_hw_breakpoint(cs, arch_info); } =20 - return handle; + if (kvm_find_sw_breakpoint(cs, arch_info->address)) { + return kvm_handle_sw_breakpoint(); + } + + /* + * QEMU is not able to handle debug exception, so inject + * program exception to guest; + * Yes program exception NOT debug exception !! + * When QEMU is using debug resources then debug exception must + * be always set. To achieve this we set MSR_DE and also set + * MSRP_DEP so guest cannot change MSR_DE. + * When emulating debug resource for guest we want guest + * to control MSR_DE (enable/disable debug interrupt on need). + * Supporting both configurations are NOT possible. + * So the result is that we cannot share debug resources + * between QEMU and Guest on BOOKE architecture. + * In the current design QEMU gets the priority over guest, + * this means that if QEMU is using debug resources then guest + * cannot use them; + * For software breakpoint QEMU uses a privileged instruction; + * So there cannot be any reason that we are here for guest + * set debug exception, only possibility is guest executed a + * privileged / illegal instruction and that's why we are + * injecting a program interrupt. + */ + cpu_synchronize_state(cs); + /* + * env->nip is PC, so increment this by 4 to use + * ppc_cpu_do_interrupt(), which set srr0 =3D env->nip - 4. + */ + env->nip +=3D 4; + cs->exception_index =3D POWERPC_EXCP_PROGRAM; + env->error_code =3D POWERPC_EXCP_INVAL; + ppc_cpu_do_interrupt(cs); + + return 0; } =20 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) --=20 2.20.1