From patchwork Sun Nov 6 02:37:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 622085 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp1285534pvb; Sat, 5 Nov 2022 19:39:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4fZVu+9sVineAV+GuR7r2QcTpcNaGACaqyz3PqsFIVdqvtVTzXerjSAASl5OkEwLC/lU0Y X-Received: by 2002:a05:6214:c88:b0:4bb:5b29:e96a with SMTP id r8-20020a0562140c8800b004bb5b29e96amr38831401qvr.6.1667702344845; Sat, 05 Nov 2022 19:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667702344; cv=none; d=google.com; s=arc-20160816; b=Evu4r45l8CiqQpjQKuzUkFOzQUvYMAL88Zxd/En0z9BsGWfWAts9T8UQGXGwKaYvBN majI/13KM7srJr/5Tq/jzJxTDGK0mb/VAd1TUoQbGN9n3Bvzi3X4Dxr6e9jKMiANSy12 sh6zkvU+WnGQp2NMDZsfpu9G5kYDcVyV6hCNE7is5L+fqCP9nKLPdSZpiQ6d/OIM6hyh uRxlWld6HL+Y/XscgDQ7KDExoCnjruQNZn1Mg9e0oBRKne+Kwf+s6nz/q/ymXH1BdXhl EGA8tyZcuk6qa1+4qa9pbvNOEdt+gqBxLeJyuP8gsIM2woC7EvnNmciUeP4tIDFzfOne pgfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=j7WXfOWK53ahgYMgHy1i+j/q7xrqgYKDWQCtOds9hEc=; b=L0aBltWCOYYy509zPVbx9b1a7I+AzX2DPx2tTiWaMwd1O5TmI6s9KGzzGI9MtLM939 9RVUNJtTYGxczYTgpMMeGcAhtZSO4GvAYs8UJNSWAnzIk1Rp0EgjLj0Vm627jW33dHrv IgGfKD6ixGIRKC7Jags7Wlw/OJE1jtFGkbtFzDXJ9hY8fFIIabUEeLrK29uVTiCWiHdE Az3Vvq8OoOa2jqLOuIbyPiTqAYhQtYlSt32Akl8rDvyDx90IjxpYSSEAJ1y+UnplXB/Y 98TSBJKcrYZOi+NKHSFv6OVcOu25uigCRlO6X/WTQNcCCykj9uO8+Oc/qp78ejKrHp9l DWiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wsaGAT4T; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fv13-20020a056214240d00b004bbff08b6casi2226683qvb.102.2022.11.05.19.39.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Nov 2022 19:39:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wsaGAT4T; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1orVXz-0000VU-2b; Sat, 05 Nov 2022 22:38:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1orVXw-0000TA-Ow for qemu-devel@nongnu.org; Sat, 05 Nov 2022 22:38:04 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1orVXu-0003Kf-M8 for qemu-devel@nongnu.org; Sat, 05 Nov 2022 22:38:04 -0400 Received: by mail-pl1-x636.google.com with SMTP id l2so8198188pld.13 for ; Sat, 05 Nov 2022 19:38:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j7WXfOWK53ahgYMgHy1i+j/q7xrqgYKDWQCtOds9hEc=; b=wsaGAT4T6SmnR4faXM1n3hLPx9BoU3RInTpVobHXXwy/Ad07Sp4VlNrQkkiyDt+SXn F2nyw3vZT8mKcN9F0n2gw2b/nU+qHbm8ULVZ5sm56RwCTDHk8d25vvmvjd174WrM+xA3 9p1vEqK0vPJIaMo4xCvVf232F3bZ4AXSOAVLekb3eiUaDdzRzzR88/rivpM29pT+t8yM dpAPYQRzgSPdVfI7ue35uqc3PgZlG7SFSSdVSzVouEBlUctlu86kgjiSyuFhniCy5KC6 r5B+h3Ljz8dOjTFRaGhQN7AIbotcTcwkVYvuWIn1watPLDu+GYq+H7lq0GQ951rYxhjM 0zKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j7WXfOWK53ahgYMgHy1i+j/q7xrqgYKDWQCtOds9hEc=; b=bl209WG9BhLJusiZNLk1GkaWp2sgP4O2tg+I8QeqjpNnub9h/Ctqv1R1UCWzDXD/xk zWWiqU+LjMMDCPS87tNoHyZIh8FgC3Gc2ojCr+7c2+Oj78f3Wr8dIKSNZAqo9Z0aw+6v gMXmZT0GBEwRftUiMDKm5us5S6VGSXCm0RoBDqBV9OjyvAVO4cGzXPJeJHvVjznGGTID 40iasiSrOXEaeYetu1ksbY4JnV7V1Zyp6m7d2snFwRunev2Mi6JWEjH1KbardDuaWJwF xRDlP3MVyYvFtbJaFfS5GnamlqGGF3e4GG6Sn4+bAg/hns+Ji4RhiqsFfB5vHQC7/Ex3 Q6rQ== X-Gm-Message-State: ACrzQf39mZYOymzL/xKuPfBn8Za+IKZNSnTRYF7yg/QWjT+3fpFLpKI2 obNgphs2ss6S0jMn5pl8lRF+T32KcHpQgA2N X-Received: by 2002:a17:902:e846:b0:187:2127:cbb with SMTP id t6-20020a170902e84600b0018721270cbbmr35070168plg.125.1667702280878; Sat, 05 Nov 2022 19:38:00 -0700 (PDT) Received: from localhost.localdomain ([2001:8003:d918:7a00:e617:679e:af7:63d]) by smtp.gmail.com with ESMTPSA id m21-20020a170902d19500b0018862bb3976sm2259457plb.308.2022.11.05.19.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 19:37:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: philmd@linaro.org, sw@weilnetz.de Subject: [RESEND PATCH 6/6] accel/tcg: Split out setjmp_gen_code Date: Sun, 6 Nov 2022 13:37:35 +1100 Message-Id: <20221106023735.5277-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106023735.5277-1-richard.henderson@linaro.org> References: <20221106023735.5277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Isolate the code protected by setjmp. Fixes: translate-all.c: In function ‘tb_gen_code’: translate-all.c:748:51: error: argument ‘cflags’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered] Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- accel/tcg/translate-all.c | 58 ++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 9ee21f7f52..ac3ee3740c 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -742,6 +742,37 @@ void page_collection_unlock(struct page_collection *set) #endif /* !CONFIG_USER_ONLY */ +/* + * Isolate the portion of code gen which can setjmp/longjmp. + * Return the size of the generated code, or negative on error. + */ +static int setjmp_gen_code(CPUArchState *env, TranslationBlock *tb, + target_ulong pc, void *host_pc, + int *max_insns, int64_t *ti) +{ + int ret = sigsetjmp(tcg_ctx->jmp_trans, 0); + if (unlikely(ret != 0)) { + return ret; + } + + tcg_func_start(tcg_ctx); + + tcg_ctx->cpu = env_cpu(env); + gen_intermediate_code(env_cpu(env), tb, *max_insns, pc, host_pc); + assert(tb->size != 0); + tcg_ctx->cpu = NULL; + *max_insns = tb->icount; + +#ifdef CONFIG_PROFILER + qatomic_set(&tcg_ctx->prof.tb_count, tcg_ctx->prof.tb_count + 1); + qatomic_set(&tcg_ctx->prof.interm_time, + tcg_ctx->prof.interm_time + profile_getclock() - *ti); + *ti = profile_getclock(); +#endif + + return tcg_gen_code(tcg_ctx, tb, pc); +} + /* Called with mmap_lock held for user mode emulation. */ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, @@ -754,8 +785,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, int gen_code_size, search_size, max_insns; #ifdef CONFIG_PROFILER TCGProfile *prof = &tcg_ctx->prof; - int64_t ti; #endif + int64_t ti; void *host_pc; assert_memory_lock(); @@ -805,33 +836,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu, ti = profile_getclock(); #endif - gen_code_size = sigsetjmp(tcg_ctx->jmp_trans, 0); - if (unlikely(gen_code_size != 0)) { - goto error_return; - } - - tcg_func_start(tcg_ctx); - - tcg_ctx->cpu = env_cpu(env); - gen_intermediate_code(cpu, tb, max_insns, pc, host_pc); - assert(tb->size != 0); - tcg_ctx->cpu = NULL; - max_insns = tb->icount; - trace_translate_block(tb, pc, tb->tc.ptr); - /* generate machine code */ - -#ifdef CONFIG_PROFILER - qatomic_set(&prof->tb_count, prof->tb_count + 1); - qatomic_set(&prof->interm_time, - prof->interm_time + profile_getclock() - ti); - ti = profile_getclock(); -#endif - - gen_code_size = tcg_gen_code(tcg_ctx, tb, pc); + gen_code_size = setjmp_gen_code(env, tb, pc, host_pc, &max_insns, &ti); if (unlikely(gen_code_size < 0)) { - error_return: switch (gen_code_size) { case -1: /*