Received: from eggs.gnu.org ([2001:4830:134:3::10]:48526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bRgd4-0007fH-Rr for qemu-devel@nongnu.org; Mon, 25 Jul 2016 10:13:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bRgcz-0007Wo-P7 for qemu-devel@nongnu.org; Mon, 25 Jul 2016 10:13:09 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33174) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bRgcz-0007Wj-Ez for qemu-devel@nongnu.org; Mon, 25 Jul 2016 10:13:05 -0400 Received: by mail-wm0-x242.google.com with SMTP id o80so16951985wme.0 for ; Mon, 25 Jul 2016 07:13:05 -0700 (PDT) Sender: Richard Henderson References: <1469364141.8568.251.camel@kernel.crashing.org> <441c89df-0830-ab0c-6298-89374b1cbe9d@twiddle.net> <1469423736.5978.13.camel@kernel.crashing.org> From: Richard Henderson Message-ID: <8a2d56b8-d328-bfd0-bdb1-f65fd4f479e2@twiddle.net> Date: Mon, 25 Jul 2016 19:42:58 +0530 MIME-Version: 1.0 In-Reply-To: <1469423736.5978.13.camel@kernel.crashing.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] TCG problem with cpu_{st,ld}x_data ? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Benjamin Herrenschmidt , qemu-devel@nongnu.org Cc: Paolo Bonzini , Christian Borntraeger On 07/25/2016 10:45 AM, Benjamin Herrenschmidt wrote: > On Mon, 2016-07-25 at 06:04 +0530, Richard Henderson wrote: >> I noticed a related problem recently, while working on the cmpxchg patch set. >> >> In my opinion, we should (1) merge GETRA and GETPC so there's no confusion >> between the two, (2) push all adjustment down to the final moment before use, >> perhaps in cpu_restore_state. >> >> Thus a null value would be properly retained until checked, and one can easily >> call the memory helper functions without confusion. > > Ok, after a bit more scrubbing of the code I think I understand what you > mean. > > Now assuming we fix that, there is still a problem if the target code, such > as the PPC code, calls a helper that might cause a fault without first > updating the PC in the env, right ? IE. On powerpc for example, that means > that any instruction using a helper that might potentially do loads or stores > needs to first call gen_update_nip(). Well, that's the bug with the current code, yes. But what we gain by transforming this code to use (via indirection) cpu_loop_exit_restore, is the ability to reconstruct values, like NIP, without first having saved them. Any data that you give to tcg_gen_insn_start will be given to restore_state_to_opc. PPC currently does tcg_gen_insn_start(ctx.nip); and env->nip = data[0]; so you're good there. For some targets, we also restore part of the flags computation with this mechanism. With more trickery, ARM is (intending to?) compute exception syndrome information with this. As I understand it, this is very much akin to the PPC gen_set_access_type, so perhaps in future there's some savings to be had there. > Either that, or change the helpers to capture the PC using GETPC/GETRA from > the first level of helper function (so as to ensure the return address is > correct). > > Am I right ? You are right. > IE. Even if we fix the 0 vs. -2 problem, I still need this patch: > > --- a/target-ppc/translate.c > +++ b/target-ppc/translate.c > @@ -6916,6 +6916,7 @@ static void gen_lve##name(DisasContext *ctx) \ > if (size > 1) { \ > tcg_gen_andi_tl(EA, EA, ~(size - 1)); \ > } \ > + gen_update_nip(ctx, ctx->nip - 4); \ > rs = gen_avr_ptr(rS(ctx->opcode)); \ > gen_helper_lve##name(cpu_env, rs, EA); \ > tcg_temp_free(EA); \ > @@ -6937,6 +6938,7 @@ static void gen_stve##name(DisasContext *ctx) \ > if (size > 1) { \ > tcg_gen_andi_tl(EA, EA, ~(size - 1)); \ > } \ > + gen_update_nip(ctx, ctx->nip - 4); \ > rs = gen_avr_ptr(rS(ctx->opcode)); \ > gen_helper_stve##name(cpu_env, rs, EA); \ > tcg_temp_free(EA); \ > > (And possibly others I haven't yet audited) Yes indeed. I'm amused by this, since I read your emails in the wrong order, and so discovered exactly this problem while answering the other email. r~