From patchwork Fri Sep 24 13:56:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 514575 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1499044jao; Fri, 24 Sep 2021 07:01:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9lVPNXc/Wy4P39XQUBZEPx8ab/nCuNizfOh9r+U9RZfk798IpIqRMqlMPV+7X/RKal9Yq X-Received: by 2002:a67:f914:: with SMTP id t20mr1557832vsq.36.1632492062069; Fri, 24 Sep 2021 07:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632492062; cv=none; d=google.com; s=arc-20160816; b=ipHVfkmguGhU57D04Gu8dYet0qZcLxpKuGIfyCcDAvhSYomq5OUFxR3SlYNRk422ES Gi7IZMFv6mWXSO8GiLRRguF9GKeg1ixPUB4YCzrFUb1kW8aB3eEsPDFBNkfc1Rx124Y9 1eOXlS18OOJ9uAK38oCoUzFFBkbeI01WgncJ22YLY6n1DxYf83cojQxV3m8XxDqEVyYA Mx/F4sX7INyK5qKEziLmvfIPH0EWDfSTO1qjziZLz53/n4Gi/Wy53B5FCcdIYh9/CPCb M/pukZtDJsx8HCq5PdLU+lroRQi8XeeAz4cd5X5etqGmmqQLAzGaTEbOyrQ/WnRtyxRr dA2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from; bh=nKzyPXG/7bRh166i4e71Piga9rVkqzfkoVNi3HTq6/w=; b=nHqdvpvO1/VRCmOxb1S66BsCmNwZZNz6wrmGYX+wL1AaROxQH/0pnfX1zQ/1toMIrb e55DkSAVV++NZO5ucwlvFt8Bpq7pvicwjnvZ/hNBf/L8dVS+U6SuczGcNMzk4lsPsvUE zao9mV7ZwZUfWKL2s/v4BldSA7EhaeLK7kv7phhl1ek0c6ClRM9YuImtzSqUPEFwNu/s f1WVKLrfD957GdaQY4JouJtGz/2oCTyONSJYzKg1NF/tP4LtBWiNooQJIpLGvDuKfjjC yqOJw3OIWiAaXIGaNr6X3pH6b7Jt974tP3x0wEyeaFAjA5dlTq5bViXjM5OMqzFR2Zjx F+hQ== ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u2si6124688vsi.1.2021.09.24.07.01.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Sep 2021 07:01:02 -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; 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" Received: from localhost ([::1]:34384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTll6-0001K9-TS for patch@linaro.org; Fri, 24 Sep 2021 10:01:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTlgt-000314-UV for qemu-devel@nongnu.org; Fri, 24 Sep 2021 09:56:39 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:60799) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTlgr-00059W-4J for qemu-devel@nongnu.org; Fri, 24 Sep 2021 09:56:39 -0400 Received: from quad ([82.142.21.142]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1Mcp3E-1n3Ngm3ivS-00ZyOz; Fri, 24 Sep 2021 15:56:35 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 5/7] linux-user: Provide new force_sig_fault() function Date: Fri, 24 Sep 2021 15:56:29 +0200 Message-Id: <20210924135631.2067582-6-laurent@vivier.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210924135631.2067582-1-laurent@vivier.eu> References: <20210924135631.2067582-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Aa/W3+/9Dd/FWKEHqQrSMRuBgk3RRcCeVu9Z8Z4ztYIsgzvM0pR frAf6FULRJj5hXG6AFG0xeToUdC+jA1IePhgKUikjFKiX/UOq0bPHqKgqEyGBRHKIu69NgK j74TlMGV6DkFxddn18xq4wdERh3QbaEMDqV72SCfpTsgxuA7dtS3+Inz5GNfTUg8Js0QCqq anyYXLa4dXGDQr3cIkDhw== X-UI-Out-Filterresults: notjunk:1; V03:K0:gNsuaqKw5uw=:BRlI4WXHriuCEU09lruvwV MMqojHOBzyWENOd0kNRREKN3cEicKYGlh2LrOH7fufbZXsGP9y4DJf6cJUMUUyxz6Gl2IeWOL 9zqDdaUc1k9PFf3B/VukKu52EwjK9DCG41+u9WGRjQvCzm80tuy/88HTP9UpBqW52JUhCyN3u kwxEZibWcCc4G4KHKefQpwbpDOq48EXx1IvJ/zjLC5NF1xsPtEvtu4BDxiW1Y0+P4EKUyWXdz YOq0oVxf55fWXWXKFrbrtv4OCruFYi2cq9rc/8i5m/svnHoRw3bZpK3eTiBgkacb6kyN3WPHh A9UUYlVvVKIJdHwayJZN6stzCrlMwS17HxznjNNy6WtOyCoLPl0wYMpZTK+GtqtSFu7ASfBxt mbEibhEkQt1cWARPOj7bUloHb34Mhxd/6Ntf8at+/tkjVT80cSHNzjx1Yv7fgJ+9JfLXUwVzc tU6WPw3d5HPRqj/M9+j6EnFyipVHKkTikup4QQd+o7HtAWlBNSNK+0ioJcRVrfkyXjXGpnTg0 AJg9MpGuKjNabDIKExUYKsafsW3nq7ZzbN7wzeVej4wKCIoUrDi2fsY2FEgi+5inuvVtCfrVw evyLPeHdfSUnFLTTbEEFW1VgypZeZDSEFSHE1XwdVVVNDoMELOoIW/gJZf70H6782w6vGa2MM 7Ud4/f4MlfIjn1RduBzA3pDvhe5Zb0ciH0XwlOWMcj4xhLed526+zp126gBdRVLUZfsevO+db 5wZuOy1dRkKJ7pDgc0Rb8BEiJvTQiGqGckHH2w== Received-SPF: none client-ip=217.72.192.74; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Peter Maydell , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell In many places in the linux-user code we need to queue a signal for the guest using the QEMU_SI_FAULT si_type. This requires that the caller sets up and passes us a target_siginfo, including setting the appropriate part of the _sifields union for the si_type. In a number of places the code forgets to set the _sifields union field. Provide a new force_sig_fault() function, which does the same thing as the Linux kernel function of that name -- it takes the signal number, the si_code value and the address to use in _sifields._sigfault, and assembles the target_siginfo itself. This makes the callsites simpler and means it's harder to forget to pass in an address value. We follow force_sig() and the kernel's force_sig_fault() in not requiring the caller to pass in the CPU pointer but always acting on the CPU of the current thread. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-Id: <20210813131809.28655-6-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/signal-common.h | 1 + linux-user/signal.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) -- 2.31.1 diff --git a/linux-user/signal-common.h b/linux-user/signal-common.h index 58ea23f6ea94..79511becb4e7 100644 --- a/linux-user/signal-common.h +++ b/linux-user/signal-common.h @@ -40,6 +40,7 @@ void tswap_siginfo(target_siginfo_t *tinfo, void set_sigmask(const sigset_t *set); void force_sig(int sig); void force_sigsegv(int oldsig); +void force_sig_fault(int sig, int code, abi_ulong addr); #if defined(TARGET_ARCH_HAS_SETUP_FRAME) void setup_frame(int sig, struct target_sigaction *ka, target_sigset_t *set, CPUArchState *env); diff --git a/linux-user/signal.c b/linux-user/signal.c index 910b9dc6f7d1..203821645509 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -651,6 +651,23 @@ void force_sig(int sig) queue_signal(env, info.si_signo, QEMU_SI_KILL, &info); } +/* + * Force a synchronously taken QEMU_SI_FAULT signal. For QEMU the + * 'force' part is handled in process_pending_signals(). + */ +void force_sig_fault(int sig, int code, abi_ulong addr) +{ + CPUState *cpu = thread_cpu; + CPUArchState *env = cpu->env_ptr; + target_siginfo_t info = {}; + + info.si_signo = sig; + info.si_errno = 0; + info.si_code = code; + info._sifields._sigfault._addr = addr; + queue_signal(env, sig, QEMU_SI_FAULT, &info); +} + /* Force a SIGSEGV if we couldn't write to memory trying to set * up the signal frame. oldsig is the signal we were trying to handle * at the point of failure.