From patchwork Fri Feb 7 15:31:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 862993 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e42:0:b0:385:e875:8a9e with SMTP id r2csp385737wrt; Fri, 7 Feb 2025 07:38:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW9s5k9xKbkb98VTJyGMnNIw/QbitMKfABrUJP3LY9DX+uWsjzWOxn94Ioc8dtsE/42nvMp9Q==@linaro.org X-Google-Smtp-Source: AGHT+IEbRgf3buTePmwxfRTaC9xGf6prVHYWYG0IUz16saoOQhhUPBYgHET+9qMwEKppIsdgSw0J X-Received: by 2002:a05:6102:1492:b0:4b1:130f:9fd5 with SMTP id ada2fe7eead31-4ba85eedc49mr3331063137.19.1738942713827; Fri, 07 Feb 2025 07:38:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738942713; cv=none; d=google.com; s=arc-20240605; b=kJgx7sdPGKpz2nUSde1kJqesQSMu6sWyTU1nvKvOp/xPe2DJ4RrIv5LnrqcSoqJuMG c8Q02bx09moCqR640WV91+TOQcpX48wzllvMbhloMH0vQOyvs5tSXdGCo5W6BkwZJUT8 LgEhHMQtah0hzgFvZUk/xq8mJyhPSQ1j3KwQjADmlRHpl+Bsh3rW5xnfG+XRKdLOr5Ii PqfxSCr+mVLCR4hdcreu5q8VJOsPCddDP6wlLqL8IinuJqnET/2uqkw1M1DScxcAtn+6 +k5OqCDNVcV6I3bUratSzhPY8RttLiRlnWnjCHbhKgm7GE8VK88qaHHJfwioDy5JxUtp YfEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to: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=Vu9pOked5UqOucuAkIMsH1wV3NsjfZIqorCbgdhJbNs=; fh=htMF8hQWTZiOGUJHuB6bq90yox4j6xv33yHiWqKjtG8=; b=i8Y1cxk3MiOk4vbCiH5kCiTuWRAoI7TI9LoXa50TSx0S6PnV47kwe5y0wPuKFwo1b7 quUOB4wYPoVyGSHYKGdbPkooRbTUd1etzzcfuwSCI69SJ9mVdGrjiUoa1S8WTi6HzZTE m1tIADoUQT/RbvqYmU27Oa3KENGcyspfQCMQw6TAp/2US9FvOsMqKD6yR71cQBFp+RI1 nT8BzkLsRs5LU2++IGIp+HH0pp/4TifW4ZLbaVqtkQ7JV7vuYcNhlt7kF7KGLaZbJ/z9 vh0aOBB0KQTJJREhdgd0vziqDQ/F+Ahg9aphYjkwKXKFZ3kcjdNDnVMg3TOTeglu9Z8j Jj0g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sO2Ojvfq; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ada2fe7eead31-4ba77656bbbsi803446137.56.2025.02.07.07.38.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Feb 2025 07:38:33 -0800 (PST) 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=sO2Ojvfq; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tgQMD-00021Y-NL; Fri, 07 Feb 2025 10:33:33 -0500 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 1tgQKO-0008AC-JP for qemu-devel@nongnu.org; Fri, 07 Feb 2025 10:31:38 -0500 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tgQKB-00041Z-Vw for qemu-devel@nongnu.org; Fri, 07 Feb 2025 10:31:36 -0500 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-aaeec07b705so381705466b.2 for ; Fri, 07 Feb 2025 07:31:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738942282; x=1739547082; darn=nongnu.org; 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=Vu9pOked5UqOucuAkIMsH1wV3NsjfZIqorCbgdhJbNs=; b=sO2OjvfqiiWe2p8l3aOp1BdGD2+U56p4FUnTUK+u7P0BQ4AjG/1paYX4r0lRjoRthL Eowj6IiQHjyaf8Gi3AYHa2UV62qAHS0Bsy8kY1vqnOm8ehDcMFHZiEnnrf6UAm1/GjLi dSsh3fiU95ejH9DXGGc5ubinfy19SlyQioj7vcoWMCUmTQQEG51ZYHZr3DsV57ioN2TT Sh+LNQO1y3dg9/eqhNUvk5NYdiZny9ArZDQbw+OD03txwIg6EIWgI/yE9tg+p10maZLh I9luOO4Q3NO30wkcZ+dTto/2bEX6reqslVZXy1gQbOwTwVdt3l1s/5R745Gu0EkPrtMp lizg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738942282; x=1739547082; 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=Vu9pOked5UqOucuAkIMsH1wV3NsjfZIqorCbgdhJbNs=; b=nM1uPQ2OMITGMEWhl0ROnzysKojkOHy+l4khuvZ5bRcZQy8GoXsqPq6+VHLFibj+P0 bnQfQ7IDxlPY7K+bV00nXclZDaVj5S2ktcTCh3KFTwV4BPt8jDpTJ/c1RQt3CSNxgSyx 7UUPAqJ2Lrz7Q1qzSw2Y0swlJPtIOyv/VlFeFrEWObz+Y1KZ2spcrbZe1f//3+ZErGRu RKWMwZkAY+T+nD5DzCoujgygDiqpC/iM9VJZY4i3E7G/dJWORcdOb8h7rm6Z5fZOLBEb cES8MIASf+ECFZ2laQHyJIlEDItF8hdjYBOAorDVK9wmSrzyw4E62V+RMAVq0/elh6Q8 F/eg== X-Gm-Message-State: AOJu0Ywh1rqeQNJgEGtL7g/PGMvvDWLcukyCqo8nJ58tcxEttHB62Dxb EOP5J7MFK+e99iZpZBpUR0nJcde1kVaWeeLLyiKU9xhDUCFTZTqO5zXvkuKbqGM= X-Gm-Gg: ASbGnctCDNJitykS3WzGZvW00myrsqPDlRgqjT81uyzWZ+hQJZ19QfV06QRT5tFo/7u fZ1xJG0k2zb0IRmBOb7z/YbQcA4n2vEGQptAo6tK8wEDoF37pyrJXyJAgPV+oZCXW+mdVtCI7bf Q+9Xcf2AxztOH5mWqIP0s0aGf8kuRfZ7eBeiBv2hKBuxLV811yaXlp4lPx31+ahQDLo0DpJrwrH 0Uno5P52U9/bCWQ9FKDWiq0AmhUiH8SAvJwcBuX9EbDMIdOje7RpsCNidFG0IZ7bR9lTYM4IAYS HTmGZyg7pOvJHPGqyA== X-Received: by 2002:a17:907:9719:b0:ab6:e10e:2f5 with SMTP id a640c23a62f3a-ab789bf6ae5mr405155466b.37.1738942281797; Fri, 07 Feb 2025 07:31:21 -0800 (PST) Received: from draig.lan ([185.126.160.109]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab7885e032fsm155043666b.115.2025.02.07.07.31.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2025 07:31:18 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 9520C60BD2; Fri, 7 Feb 2025 15:31:13 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Peter Xu , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Weiwei Li , qemu-arm@nongnu.org, Nicholas Piggin , Liu Zhiwei , Bin Meng , Tyrone Ting , Hao Wu , Kyle Evans , Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier , Riku Voipio , Harsh Prateek Bora , Fabiano Rosas , Alexandre Iooss , Laurent Vivier , Daniel Henrique Barboza , Warner Losh , Pierrick Bouvier , Palmer Dabbelt , Mahmoud Mandour , qemu-ppc@nongnu.org, Paolo Bonzini , qemu-rust@nongnu.org, qemu-riscv@nongnu.org, Ilya Leoshkevich Subject: [PATCH v2 13/17] user: Introduce host_interrupt_signal Date: Fri, 7 Feb 2025 15:31:08 +0000 Message-Id: <20250207153112.3939799-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250207153112.3939799-1-alex.bennee@linaro.org> References: <20250207153112.3939799-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62b.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Ilya Leoshkevich Attaching to the gdbstub of a running process requires stopping its threads. For threads that run on a CPU, cpu_exit() is enough, but the only way to grab attention of a thread that is stuck in a long-running syscall is to interrupt it with a signal. Reserve a host realtime signal for this, just like it's already done for TARGET_SIGABRT on Linux. This may reduce the number of available guest realtime signals by one, but this is acceptable, since there are quite a lot of them, and it's unlikely that there are apps that need them all. Set signal_pending for the safe_sycall machinery to prevent invoking the syscall. This is a lie, since we don't queue a guest signal, but process_pending_signals() can handle the absence of pending signals. The syscall returns with QEMU_ERESTARTSYS errno, which arranges for the automatic restart. This is important, because it helps avoiding disturbing poorly written guests. Reviewed-by: Warner Losh Signed-off-by: Ilya Leoshkevich Message-Id: <20250117001542.8290-5-iii@linux.ibm.com> Signed-off-by: Alex Bennée --- include/user/signal.h | 2 ++ bsd-user/signal.c | 12 ++++++++++++ linux-user/signal.c | 25 ++++++++++++++++++++----- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/user/signal.h b/include/user/signal.h index 19b6b9e5dd..7fa33b05d9 100644 --- a/include/user/signal.h +++ b/include/user/signal.h @@ -20,4 +20,6 @@ */ int target_to_host_signal(int sig); +extern int host_interrupt_signal; + #endif diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 8c51f6ce65..ff2ccbbf60 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -51,6 +51,8 @@ static inline int sas_ss_flags(TaskState *ts, unsigned long sp) on_sig_stack(ts, sp) ? SS_ONSTACK : 0; } +int host_interrupt_signal = SIGRTMAX; + /* * The BSD ABIs use the same signal numbers across all the CPU architectures, so * (unlike Linux) these functions are just the identity mapping. This might not @@ -491,6 +493,12 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) uintptr_t pc = 0; bool sync_sig = false; + if (host_sig == host_interrupt_signal) { + ts->signal_pending = 1; + cpu_exit(thread_cpu); + return; + } + /* * Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special * handling wrt signal blocking and unwinding. @@ -854,6 +862,9 @@ void signal_init(void) for (i = 1; i <= TARGET_NSIG; i++) { host_sig = target_to_host_signal(i); + if (host_sig == host_interrupt_signal) { + continue; + } sigaction(host_sig, NULL, &oact); if (oact.sa_sigaction == (void *)SIG_IGN) { sigact_table[i - 1]._sa_handler = TARGET_SIG_IGN; @@ -872,6 +883,7 @@ void signal_init(void) sigaction(host_sig, &act, NULL); } } + sigaction(host_interrupt_signal, &act, NULL); } static void handle_pending_signal(CPUArchState *env, int sig, diff --git a/linux-user/signal.c b/linux-user/signal.c index bffbef235c..81a98c6d02 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -517,6 +517,8 @@ static int core_dump_signal(int sig) } } +int host_interrupt_signal; + static void signal_table_init(const char *rtsig_map) { int hsig, tsig, count; @@ -580,10 +582,10 @@ static void signal_table_init(const char *rtsig_map) * Attempts for configure "missing" signals via sigaction will be * silently ignored. * - * Reserve one signal for internal usage (see below). + * Reserve two signals for internal usage (see below). */ - hsig = SIGRTMIN + 1; + hsig = SIGRTMIN + 2; for (tsig = TARGET_SIGRTMIN; hsig <= SIGRTMAX && tsig <= TARGET_NSIG; hsig++, tsig++) { @@ -604,12 +606,17 @@ static void signal_table_init(const char *rtsig_map) host_to_target_signal_table[SIGABRT] = 0; for (hsig = SIGRTMIN; hsig <= SIGRTMAX; hsig++) { if (!host_to_target_signal_table[hsig]) { - host_to_target_signal_table[hsig] = TARGET_SIGABRT; - break; + if (host_interrupt_signal) { + host_to_target_signal_table[hsig] = TARGET_SIGABRT; + break; + } else { + host_interrupt_signal = hsig; + } } } if (hsig > SIGRTMAX) { - fprintf(stderr, "No rt signals left for SIGABRT mapping\n"); + fprintf(stderr, + "No rt signals left for interrupt and SIGABRT mapping\n"); exit(EXIT_FAILURE); } @@ -689,6 +696,8 @@ void signal_init(const char *rtsig_map) } sigact_table[tsig - 1]._sa_handler = thand; } + + sigaction(host_interrupt_signal, &act, NULL); } /* Force a synchronously taken signal. The kernel force_sig() function @@ -1036,6 +1045,12 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) bool sync_sig = false; void *sigmask; + if (host_sig == host_interrupt_signal) { + ts->signal_pending = 1; + cpu_exit(thread_cpu); + return; + } + /* * Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special * handling wrt signal blocking and unwinding. Non-spoofed SIGILL,