From nobody Sun Apr 28 05:52:47 2024 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; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1563279265; cv=none; d=zoho.com; s=zohoarc; b=JhG8v2zT5hK76fkCzc7ZO+xlNMzBAhjygIjonP54HV/qu6htpP4VVMw9IMwSjjjTXL3uh2a6IFExlkcgADk6s7rkYgvvZ+3UQjsYA2oYHwAg6pveGtkd0vV22cPGLPlK+PuK4PiqJPvMXvA8ifCc66Spcu2IF7xq9XDTYX946hw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563279265; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=gJZSxxkesJ4xFyxOL/py9rKSL0eJjs0bk0rm4uZiEgw=; b=eEr20PeM/SGJKlbKV52hU07kCMNDHy/LebOdXerE8F0iNS/dj+G8FXBezQuO626OV1JybKeVfOABoAHi9DMHG/P/h4oDg8v57KFvN8B1yQOEqeXUd4NFbr8bcf2PWo2xBYs47+E8FbvJAmHhorG7BoniwMEXAhQuNd5fVbs+Qu8= ARC-Authentication-Results: i=1; mx.zoho.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563279265483430.60210973977325; Tue, 16 Jul 2019 05:14:25 -0700 (PDT) Received: from localhost ([::1]:47954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnMLa-0000hj-NN for importer@patchew.org; Tue, 16 Jul 2019 08:14:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52151) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnMLP-0000CL-4p for qemu-devel@nongnu.org; Tue, 16 Jul 2019 08:14:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnMLN-0000Us-PD for qemu-devel@nongnu.org; Tue, 16 Jul 2019 08:14:07 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:34144) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnMLN-0000Tq-GP for qemu-devel@nongnu.org; Tue, 16 Jul 2019 08:14:05 -0400 Received: by mail-wm1-x342.google.com with SMTP id w9so16616137wmd.1 for ; Tue, 16 Jul 2019 05:14:05 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g11sm20316918wru.24.2019.07.16.05.14.03 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 05:14:03 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B18AA1FF87; Tue, 16 Jul 2019 13:14:02 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gJZSxxkesJ4xFyxOL/py9rKSL0eJjs0bk0rm4uZiEgw=; b=eio8PVTCiQ4kRa/KtUGiUdqikyUZBSo/Fcr1S8/UOL/86uyIkbMsehqizQ26BWuphM yqAjFZ8D2XdlvYhi8QfsRGbhN0YrHrpLH+BMSBFnS+qVHj0XlV48sSVO3MjaTPAS0CGD kHlSBuJTxbELbOT7zSXSdjw8yeBZXogmaTObKS42BiagMXG0qv4jFM9DnptYXZUg1pcU v1JD2X1/O1f8QRLxB795jc1MmtW/dGt2Ow33kPv13SE8eCNAdTKQE2XvyqVOQwx2EXSM nZkFEiznGk9Soz5moR+azieWuGNF1f5l8xSXZ2hMxJLJhItsRNONSQwWv+rE4FrIHqxd uGwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gJZSxxkesJ4xFyxOL/py9rKSL0eJjs0bk0rm4uZiEgw=; b=lE+ca0b8BvxfG5c8pe2Je7nSZaBdsAJ7zePzk/LP16aOp5miUQO0VxBIKNyA7uEVT0 BzewsCeBO/FpHO+03pfdVMMtg7DFckx2aJCQDJobU2e27c9TyGjTnYABPAM3+oGkLdSv kxnq3MRAn2YsPNl88zVjeQq1fo4s37A6QuuJj4QM+QQo6hu52lO7jClk3DrR8H7Y0ryf PYMEED7bcP6dsBZmz/Y83oajGOyTPgW73DMPVaKBme+4MHZoEGrKOUnS18977l/LE8lx unXSy2bDQE15q86LyxYpYoYokr04c0EJ74MRF8dOWoL3C8g9FV9kNUVRfEf3aHKQ5+XS Vvkw== X-Gm-Message-State: APjAAAVuySIPii3RrexZJyn0gIbympzMgEOYFhZBoyBC1plAomxeBZbh Bf1Q400YkNsEK3jfV0dRQfsu0Q== X-Google-Smtp-Source: APXvYqwVZijL4S+YJWKU9Em2Nyl3QEsi7r8R8bdy1nvs4Uk19itNP+Jml3QCg2gBLT0EHl0595YAIw== X-Received: by 2002:a1c:630a:: with SMTP id x10mr32029283wmb.113.1563279243673; Tue, 16 Jul 2019 05:14:03 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 16 Jul 2019 13:13:52 +0100 Message-Id: <20190716121352.302-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [RFC PATCH for 4.1?] target/ppc: move opcode decode tables to PowerPCCPU X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:PowerPC TCG CPUs" , 1836558@bugs.launchpad.net, =?UTF-8?q?Alex=20Benn=C3=A9e?= , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The opcode decode tables aren't really part of the CPUPPCState but an internal implementation detail for the translator. This can cause problems with memcpy in cpu_copy as any table created during ppc_cpu_realize get written over causing a memory leak. To avoid this move the tables into PowerPCCPU which is better suited to hold internal implementation details. Attempts to fix: https://bugs.launchpad.net/qemu/+bug/1836558 Cc: 1836558@bugs.launchpad.net Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- target/ppc/cpu.h | 8 ++++---- target/ppc/translate.c | 3 ++- target/ppc/translate_init.inc.c | 16 +++++++--------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index c9beba2a5c0..10e34b69b75 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1104,10 +1104,6 @@ struct CPUPPCState { bool resume_as_sreset; #endif =20 - /* Those resources are used only during code translation */ - /* opcode handlers */ - opc_handler_t *opcodes[PPC_CPU_OPCODES_LEN]; - /* Those resources are used only in QEMU core */ target_ulong hflags; /* hflags is a MSR & HFLAGS_MASK */ target_ulong hflags_nmsr; /* specific hflags, not coming from MSR */ @@ -1191,6 +1187,10 @@ struct PowerPCCPU { int32_t node_id; /* NUMA node this CPU belongs to */ PPCHash64Options *hash64_opts; =20 + /* Those resources are used only during code translation */ + /* opcode handlers */ + opc_handler_t *opcodes[PPC_CPU_OPCODES_LEN]; + /* Fields related to migration compatibility hacks */ bool pre_2_8_migration; target_ulong mig_msr_mask; diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 4a5de280365..c0faab8a824 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -7857,6 +7857,7 @@ static bool ppc_tr_breakpoint_check(DisasContextBase = *dcbase, CPUState *cs, static void ppc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) { DisasContext *ctx =3D container_of(dcbase, DisasContext, base); + PowerPCCPU *cpu =3D POWERPC_CPU(cs); CPUPPCState *env =3D cs->env_ptr; opc_handler_t **table, *handler; =20 @@ -7874,7 +7875,7 @@ static void ppc_tr_translate_insn(DisasContextBase *d= cbase, CPUState *cs) opc3(ctx->opcode), opc4(ctx->opcode), ctx->le_mode ? "little" : "big"); ctx->base.pc_next +=3D 4; - table =3D env->opcodes; + table =3D cpu->opcodes; handler =3D table[opc1(ctx->opcode)]; if (is_indirect_opcode(handler)) { table =3D ind_table(handler); diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.in= c.c index 86fc8f2e316..9cd2033bb92 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -9440,14 +9440,13 @@ static void fix_opcode_tables(opc_handler_t **ppc_o= pcodes) static void create_ppc_opcodes(PowerPCCPU *cpu, Error **errp) { PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); - CPUPPCState *env =3D &cpu->env; opcode_t *opc; =20 - fill_new_table(env->opcodes, PPC_CPU_OPCODES_LEN); + fill_new_table(cpu->opcodes, PPC_CPU_OPCODES_LEN); for (opc =3D opcodes; opc < &opcodes[ARRAY_SIZE(opcodes)]; opc++) { if (((opc->handler.type & pcc->insns_flags) !=3D 0) || ((opc->handler.type2 & pcc->insns_flags2) !=3D 0)) { - if (register_insn(env->opcodes, opc) < 0) { + if (register_insn(cpu->opcodes, opc) < 0) { error_setg(errp, "ERROR initializing PowerPC instruction " "0x%02x 0x%02x 0x%02x", opc->opc1, opc->opc2, opc->opc3); @@ -9455,7 +9454,7 @@ static void create_ppc_opcodes(PowerPCCPU *cpu, Error= **errp) } } } - fix_opcode_tables(env->opcodes); + fix_opcode_tables(cpu->opcodes); fflush(stdout); fflush(stderr); } @@ -10023,7 +10022,6 @@ static void ppc_cpu_unrealize(DeviceState *dev, Err= or **errp) { PowerPCCPU *cpu =3D POWERPC_CPU(dev); PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); - CPUPPCState *env =3D &cpu->env; Error *local_err =3D NULL; opc_handler_t **table, **table_2; int i, j, k; @@ -10035,11 +10033,11 @@ static void ppc_cpu_unrealize(DeviceState *dev, E= rror **errp) } =20 for (i =3D 0; i < PPC_CPU_OPCODES_LEN; i++) { - if (env->opcodes[i] =3D=3D &invalid_handler) { + if (cpu->opcodes[i] =3D=3D &invalid_handler) { continue; } - if (is_indirect_opcode(env->opcodes[i])) { - table =3D ind_table(env->opcodes[i]); + if (is_indirect_opcode(cpu->opcodes[i])) { + table =3D ind_table(cpu->opcodes[i]); for (j =3D 0; j < PPC_CPU_INDIRECT_OPCODES_LEN; j++) { if (table[j] =3D=3D &invalid_handler) { continue; @@ -10057,7 +10055,7 @@ static void ppc_cpu_unrealize(DeviceState *dev, Err= or **errp) ~PPC_INDIRECT)); } } - g_free((opc_handler_t *)((uintptr_t)env->opcodes[i] & + g_free((opc_handler_t *)((uintptr_t)cpu->opcodes[i] & ~PPC_INDIRECT)); } } --=20 2.20.1