[{"id":3687491,"web_url":"http://patchwork.ozlabs.org/comment/3687491/","msgid":"<9794589b-0f4e-4f0a-9d67-ab7e9c1d749e@linaro.org>","list_archive_url":null,"date":"2026-05-07T04:58:48","subject":"Re: [PATCH 2/5] accel/tcg: move jit thread manipulation into\n do_tb_phys_invalidate","submitter":{"id":72104,"url":"http://patchwork.ozlabs.org/api/people/72104/","name":"Richard Henderson","email":"richard.henderson@linaro.org"},"content":"On 5/5/26 05:36, Alex Bennée wrote:\n> To invalidate a TB on MacOS we need to enable write access to the JIT\n> buffer. We were doing this for tb_phys_invalidate__locked but that is\n> not the only path into do_tb_phys_invalidate. Move the manipulation\n> into the shared function that does the work.\n> \n> This enables watchpoints to work in MacOS TCG guests.\n> \n> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3444\n> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>\n> ---\n>   accel/tcg/tb-maint.c | 5 +++--\n>   1 file changed, 3 insertions(+), 2 deletions(-)\n> \n> diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c\n> index cd7c32361bb..9a648f97865 100644\n> --- a/accel/tcg/tb-maint.c\n> +++ b/accel/tcg/tb-maint.c\n> @@ -925,6 +925,7 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)\n>       uint32_t orig_cflags = tb_cflags(tb);\n>   \n>       assert_memory_lock();\n> +    qemu_thread_jit_write();\n>   \n>       /* make sure no further incoming jumps will be chained to this TB */\n>       qemu_spin_lock(&tb->jmp_lock);\n> @@ -954,15 +955,15 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)\n>       /* suppress any remaining jumps to this TB */\n>       tb_jmp_unlink(tb);\n>   \n> +    qemu_thread_jit_execute();\n\nYou've missed the early return path from the middle of the function, which should be fatal.\n\nBut the place that needs this is tb_reset_jump, which is called from \ntb_remove_from_jmp_list and tb_jmp_unlink.  Which is entirely covered by moving this down \ntoward the end of the function like so:\n\n---\n+   qemu_thread_jit_write();\n\n     /* suppress this TB from the two jump lists */\n     tb_remove_from_jmp_list(tb, 0);\n     tb_remove_from_jmp_list(tb, 1);\n\n     /* suppress any remaining jumps to this TB */\n     tb_jmp_unlink(tb);\n\n+   qemu_thread_jit_execute();\n---\n\n\n> +\n>       qatomic_set(&tb_ctx.tb_phys_invalidate_count,\n>                   tb_ctx.tb_phys_invalidate_count + 1);\n>   }\n>   \n>   static void tb_phys_invalidate__locked(TranslationBlock *tb)\n>   {\n> -    qemu_thread_jit_write();\n>       do_tb_phys_invalidate(tb, true);\n> -    qemu_thread_jit_execute();\n>   }\n\nMight as well remove tb_phys_invalidate__locked entirely, and propagate the direct call to \ndo_tb_phys_invalidate.\n\nThe __locked suffix does appear to be for the user assert_memory_locked().  As evidenced \nby tb_phys_invalidate, for system mode, we only sometimes take the page lock.\n\nGiven that this jit protection is via pthread_jit_write_protect_np, I assume the W^X \nprotection is a magic Apple per-thread bit.  If so, we don't actually require cross-thread \nlocking at all, and all is well.\n\n\nr~","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=ZoDBF/HC;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4gB0RW0P4jz1yKd\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 07 May 2026 14:59:49 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wKqp9-0006DK-Ez; Thu, 07 May 2026 00:59:00 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <richard.henderson@linaro.org>)\n id 1wKqp6-0006D5-VQ\n for qemu-devel@nongnu.org; Thu, 07 May 2026 00:58:57 -0400","from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <richard.henderson@linaro.org>)\n id 1wKqp4-0007Gr-Gn\n for qemu-devel@nongnu.org; Thu, 07 May 2026 00:58:56 -0400","by mail-oo1-xc31.google.com with SMTP id\n 006d021491bc7-6949f3eeaf6so784882eaf.0\n for <qemu-devel@nongnu.org>; Wed, 06 May 2026 21:58:52 -0700 (PDT)","from ?IPV6:2600:381:c938:6375:6efd:4d9e:6f84:a7eb?\n ([2600:381:c938:6375:6efd:4d9e:6f84:a7eb])\n by smtp.gmail.com with ESMTPSA id\n 586e51a60fabf-43454cbcbcasm19141128fac.9.2026.05.06.21.58.50\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Wed, 06 May 2026 21:58:51 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1778129931; x=1778734731; darn=nongnu.org;\n h=content-transfer-encoding:in-reply-to:content-language:from\n :references:to:subject:user-agent:mime-version:date:message-id:from\n :to:cc:subject:date:message-id:reply-to;\n bh=2rN1rZatelrTPRmpKDfXM7r+xfjdh7QJxRCY0Ts7LBI=;\n b=ZoDBF/HCrBMcn/D9nRkZnY2OcTnfaxRFxfFAgtAQuUmZXOfNfQXHmxtl79hlr2n2pE\n b26LWduqeQ4Wr3nT5mwLPi5UcZUUjYPTVLySFxyPR9YnS9tTsvhv3wpUPHGFTrKJO9uR\n Y1ZiMcKIpSPwgpHxAgNQ24xR8spM2XbO/6V+tDvaBZ3Gvsgl6c3YL6o3RsUSqTztVb0F\n JyDiqpF9zxHtwzGit+MKjvQEBfKQTn7YY8DFUy5vdOY6VvDktp7+0H3zP83WeA3BzZ+m\n dT7rXw6ylGdfT86YbPKVZqKXb8Q0JtTWIj3wgZYQdnj+GbXzPjTuAty+cO7M6CUWuUaA\n g8Zw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1778129931; x=1778734731;\n h=content-transfer-encoding:in-reply-to:content-language:from\n :references:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=2rN1rZatelrTPRmpKDfXM7r+xfjdh7QJxRCY0Ts7LBI=;\n b=atIUuAAmgorHjvz8VHxJuUx7FfYThRNWyjHGhG2VhUdJFPPSgWnhOFeuc+YHJSdMah\n yzJpAyqQINsE3/anCGZ5VwERgO8LhAvNdLpXLo2JgSs6WBI94sJVL9ps5buV6OLR9trH\n GocLLJDgic3DSurxtXnCHSgdGOiuQbvD5wXGW7cDOOhFuVllvZ7jvGNgPbviOkOlF8K8\n yNayfRNo7XyaP0tquEUX+VVVsq/fABN3ybYfG9zwNHC5vYrmps0XmirbgcIvBTMRo29i\n j4fwYp0nWx/1JTH8FtH6V9+1mSqk79J0pLzKeszwzCifSCw/SmA5G+Ox/DoH/cq9NHQ0\n 7v1Q==","X-Forwarded-Encrypted":"i=1;\n AFNElJ+RI/blme1tNA8HG8fH1OPNuJ+en1MXMh/8hf74jcL/g8li8EnFLJpJAD9fMfgbUBba0AYBlBVmKzod@nongnu.org","X-Gm-Message-State":"AOJu0Yz5unSRvyBlHmwvW8xEGIG8hdLqoPyYAGXTOAXpnyKkKqJLxGXK\n tnW6qXzHFo+xAln8XPZL8dsAAP0JK7xj1eBfzoFjrje+5MItYU5glASAgwwrdtAaYak=","X-Gm-Gg":"AeBDiev0Rq9T6hkm3rbDLTy0wwGJc+Uzm4AyJR3C3NZbBOkI6ZWdK4lbPmPKPykuZpY\n 5wl/92LS6m/ad3FVJ69r3deMBS0V945/4PiI0gunA0tuvxu3eSXsRMcJUp+A3nowjBOG00YIoN+\n aj9XP+h0Ofk0wABMslX12XduopXGkNxERR6mQ5o+ZAzToY69q4ZBA6bEZPHdYH+M1ZIe7ILtzgx\n 4zur1k5l7eWhUW7CvLGbSUhk9jz7MVCMUQf1jpzPp7shQ290oyjXfQxOl5eVODjk+6tqsg7dOnI\n 72bGgzB08MLqM/TMeKt9rjo0b2b2SIKcKk+ki4tIeep9Bo7LY6Wn6elV313IuQMVI8y6mektiY0\n 5C8Xtq+vyzrBC49O1EvLg8PCtPNWShM0mAEcVYobQwrNg8n5e3RChay6y5XCDQxPUzUd0EucAQK\n Blef90JQqjrIYNaGA0un+uPzIhtvO6UUernxZmg+4HxMppBOXyX2TGgD6lMG2QGVGMdQBRPPyMv\n GkK8kqcP99HQC/TuO2m","X-Received":"by 2002:a4a:e918:0:b0:694:9910:f78f with SMTP id\n 006d021491bc7-699ab5727d4mr842155eaf.3.1778129931441;\n Wed, 06 May 2026 21:58:51 -0700 (PDT)","Message-ID":"<9794589b-0f4e-4f0a-9d67-ab7e9c1d749e@linaro.org>","Date":"Wed, 6 May 2026 23:58:48 -0500","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH 2/5] accel/tcg: move jit thread manipulation into\n do_tb_phys_invalidate","To":"=?utf-8?q?Alex_Benn=C3=A9e?= <alex.bennee@linaro.org>,\n qemu-devel@nongnu.org","References":"<20260505103649.68361-1-alex.bennee@linaro.org>\n <20260505103649.68361-3-alex.bennee@linaro.org>","From":"Richard Henderson <richard.henderson@linaro.org>","Content-Language":"en-US","In-Reply-To":"<20260505103649.68361-3-alex.bennee@linaro.org>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=2607:f8b0:4864:20::c31;\n envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc31.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,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n 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":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}}]