From patchwork Tue Nov 2 11:06:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516628 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp4396072iml; Tue, 2 Nov 2021 04:12:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKUCmWNeV4M3QpZOVLJpLeV8h8osjUMYsaOApoxgxo0J/d1U9Kso+EInS4CckuI8XjFKfq X-Received: by 2002:aca:f20a:: with SMTP id q10mr4465952oih.176.1635851555269; Tue, 02 Nov 2021 04:12:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635851555; cv=none; d=google.com; s=arc-20160816; b=sEcH5AGrRmSVGR9JDb6a1ZMZJEQ81wJck/s/GfkcmECsnJs+G7XS3AtGuUscxMvw31 k7ORiARkExe4LP0DNTikCZm4PfWkIZS2sAN9IOhgmRwBsnWSsQ3Ow87FOyOACM0s0Mwl zvKmM6LQ6E9+xiIrs/LX3Z6BQl0FXQDdnpvvRwJv7DFdiM5uL3+Erl/uH37SMaR630rP PoYSpltX7gKWxOiIVZoj2HpI+U9X1aBonmiQT694QWFQyQNMQ1qdKnk78F5fnkRqVmxB e82MIfJcW3nW2fY7z3pFD46AOQpI9rRUivPx199xB1Ac0Fmd+4k8lKeXLxNhFDA3jS+s h4kQ== 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 :dkim-signature; bh=nso+AlCV/s0wqCbT6fU5+I4rw6sZu+GDtrLSeOTW3Gg=; b=Llvki7K21To7L2Na1zr7fBHQlyaMV+/crdzVckFrGR1i4SJGfrgtE/2Sh1FuAnvw4a Pt9cR4qc4KoxVx8LIr/INLb+DBdEtDnXU2WxtLizEjR4iDUsBtstBIscAn18URKdD55H 3RWEpHa0niuv4mTz32EPVtD0/kOeE+rq2rVAYDI14KKo6tcy6IuPbS+lOTnkUIfidKLk vucO8qmTMbzLUJMK904C0fJFnFjWezu7+A91gZ3FH7LZiy7kM3EFCnQvlBzOMnllMsoM bleZdYMQ6FUdrpiWzmz8Jhj8ROFglzNPHptUTIpi+NwevsuIFfCm9iSb2cnHcAp0O2hh PZQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=l3DPIXJY; 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=fail (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 l16si14715069otb.314.2021.11.02.04.12.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Nov 2021 04:12:35 -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=fail header.i=@linaro.org header.s=google header.b=l3DPIXJY; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mhriU-0001tk-J8 for patch@linaro.org; Tue, 02 Nov 2021 07:12:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mhre3-0003kB-Kr for qemu-devel@nongnu.org; Tue, 02 Nov 2021 07:08:01 -0400 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]:45785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mhrdx-0000uH-5c for qemu-devel@nongnu.org; Tue, 02 Nov 2021 07:07:56 -0400 Received: by mail-qt1-x830.google.com with SMTP id r2so17167958qtw.12 for ; Tue, 02 Nov 2021 04:07:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nso+AlCV/s0wqCbT6fU5+I4rw6sZu+GDtrLSeOTW3Gg=; b=l3DPIXJYayE1PsikeaA0ecsAA8UAbKdyyQWvxbh2JnCxk2DeDTimnjReUg9jlQzLxw nMvSYdXqKd7iSWLROfYx38yX3YtXAxpvtz9eYWEivLU6EbunYRYsV32I2qi7Kpnfx7Gr EG2JArD8AmtJG54JEdfj4NwfzAG4ShRYj+yc1UaNfAl3lyUHPuSAD++d4N4NPnyTdAIA YiKUc0NsvRaJwBh8NgrSoZxtZNuLxPlAFe+Y3bRWYn1hnSDxuke0x6qWnuywhdU7fM3j YzvCy8XeuGue16H2cEY3murbmhd4VSfV06/tsrUyr+/xP6HPCbx/lI1Dak9yDVrPk9AD ugeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nso+AlCV/s0wqCbT6fU5+I4rw6sZu+GDtrLSeOTW3Gg=; b=w/W0qQf0ZzdJjPxFmki9PL3H88Zd5GIzK8OYtuZnwEB1m8aMwzzRPpoJ+JnEXHy63Z JZnSCLs3R9jgi8x8H16/8Y5YtEiOLnS1i1npgv0uLFgtyDXeZyfAftyg9R/pAczCvaC6 G9+SyqsdYk8aplhjEUIcGpDgqFwYTjWvOjse75Ne7kNo7SzBGjZga12CdpVUz2YcLvGq euIYwDaE6C5iVERhdglBKOspXJEP1mD2qprws0CtVI090MTDLd6hB5bMpM44vj2y3Y/l 8WVNTvHvx13jkQq/kJW1uWqolTNKC4bVGPvVctdmgd7W4Y2vNWh5HoYj/azD+j4hfdQT JM3w== X-Gm-Message-State: AOAM53378hqsFPXOoScnJZDgKcRF1YfCVvSPuuOae2qIS3m6LvqrxWnJ hrLOxaKejwo/uqP7632zibB8LZ8QpUeDjw== X-Received: by 2002:a05:622a:1716:: with SMTP id h22mr16410369qtk.224.1635851270626; Tue, 02 Nov 2021 04:07:50 -0700 (PDT) Received: from localhost.localdomain (rrcs-172-254-253-57.nyc.biz.rr.com. [172.254.253.57]) by smtp.gmail.com with ESMTPSA id bm7sm3568612qkb.86.2021.11.02.04.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 04:07:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 15/60] linux-user/host/riscv: Populate host_signal.h Date: Tue, 2 Nov 2021 07:06:55 -0400 Message-Id: <20211102110740.215699-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211102110740.215699-1-richard.henderson@linaro.org> References: <20211102110740.215699-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::830; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x830.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: , Cc: Alistair Francis , Warner Losh Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split host_signal_pc and host_signal_write out of user-exec.c. Reviewed-by: Warner Losh Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson --- linux-user/host/riscv/host-signal.h | 86 +++++++++++++++++- accel/tcg/user-exec.c | 134 ---------------------------- 2 files changed, 85 insertions(+), 135 deletions(-) -- 2.25.1 diff --git a/linux-user/host/riscv/host-signal.h b/linux-user/host/riscv/host-signal.h index f4b4d65031..df145b1527 100644 --- a/linux-user/host/riscv/host-signal.h +++ b/linux-user/host/riscv/host-signal.h @@ -1 +1,85 @@ -#define HOST_SIGNAL_PLACEHOLDER +/* + * host-signal.h: signal info dependent on the host architecture + * + * Copyright (c) 2003-2005 Fabrice Bellard + * Copyright (c) 2021 Linaro Limited + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef RISCV_HOST_SIGNAL_H +#define RISCV_HOST_SIGNAL_H + +static inline uintptr_t host_signal_pc(ucontext_t *uc) +{ + return uc->uc_mcontext.__gregs[REG_PC]; +} + +static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) +{ + uint32_t insn = *(uint32_t *)host_signal_pc(uc); + + /* + * Detect store by reading the instruction at the program + * counter. Note: we currently only generate 32-bit + * instructions so we thus only detect 32-bit stores + */ + switch (((insn >> 0) & 0b11)) { + case 3: + switch (((insn >> 2) & 0b11111)) { + case 8: + switch (((insn >> 12) & 0b111)) { + case 0: /* sb */ + case 1: /* sh */ + case 2: /* sw */ + case 3: /* sd */ + case 4: /* sq */ + return true; + default: + break; + } + break; + case 9: + switch (((insn >> 12) & 0b111)) { + case 2: /* fsw */ + case 3: /* fsd */ + case 4: /* fsq */ + return true; + default: + break; + } + break; + default: + break; + } + } + + /* Check for compressed instructions */ + switch (((insn >> 13) & 0b111)) { + case 7: + switch (insn & 0b11) { + case 0: /*c.sd */ + case 2: /* c.sdsp */ + return true; + default: + break; + } + break; + case 6: + switch (insn & 0b11) { + case 0: /* c.sw */ + case 3: /* c.swsp */ + return true; + default: + break; + } + break; + default: + break; + } + + return false; +} + +#endif diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 44c83acba5..a0cba61e83 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -137,64 +137,6 @@ bool handle_sigsegv_accerr_write(CPUState *cpu, sigset_t *old_set, } } -/* - * 'pc' is the host PC at which the exception was raised. - * 'address' is the effective address of the memory exception. - * 'is_write' is 1 if a write caused the exception and otherwise 0. - * 'old_set' is the signal set which should be restored. - */ -static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, - int is_write, sigset_t *old_set) -{ - CPUState *cpu = current_cpu; - CPUClass *cc; - unsigned long host_addr = (unsigned long)info->si_addr; - MMUAccessType access_type = adjust_signal_pc(&pc, is_write); - abi_ptr guest_addr; - - /* For synchronous signals we expect to be coming from the vCPU - * thread (so current_cpu should be valid) and either from running - * code or during translation which can fault as we cross pages. - * - * If neither is true then something has gone wrong and we should - * abort rather than try and restart the vCPU execution. - */ - if (!cpu || !cpu->running) { - printf("qemu:%s received signal outside vCPU context @ pc=0x%" - PRIxPTR "\n", __func__, pc); - abort(); - } - -#if defined(DEBUG_SIGNAL) - printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", - pc, host_addr, is_write, *(unsigned long *)old_set); -#endif - - /* Convert forcefully to guest address space, invalid addresses - are still valid segv ones */ - guest_addr = h2g_nocheck(host_addr); - - /* XXX: locking issue */ - if (is_write && - info->si_signo == SIGSEGV && - info->si_code == SEGV_ACCERR && - h2g_valid(host_addr) && - handle_sigsegv_accerr_write(cpu, old_set, pc, guest_addr)) { - return 1; - } - - /* - * There is no way the target can handle this other than raising - * an exception. Undo signal and retaddr state prior to longjmp. - */ - sigprocmask(SIG_SETMASK, old_set, NULL); - - cc = CPU_GET_CLASS(cpu); - cc->tcg_ops->tlb_fill(cpu, guest_addr, 0, access_type, - MMU_USER_IDX, false, pc); - g_assert_not_reached(); -} - static int probe_access_internal(CPUArchState *env, target_ulong addr, int fault_size, MMUAccessType access_type, bool nonfault, uintptr_t ra) @@ -253,82 +195,6 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, return size ? g2h(env_cpu(env), addr) : NULL; } -#if defined(__riscv) - -int cpu_signal_handler(int host_signum, void *pinfo, - void *puc) -{ - siginfo_t *info = pinfo; - ucontext_t *uc = puc; - greg_t pc = uc->uc_mcontext.__gregs[REG_PC]; - uint32_t insn = *(uint32_t *)pc; - int is_write = 0; - - /* Detect store by reading the instruction at the program - counter. Note: we currently only generate 32-bit - instructions so we thus only detect 32-bit stores */ - switch (((insn >> 0) & 0b11)) { - case 3: - switch (((insn >> 2) & 0b11111)) { - case 8: - switch (((insn >> 12) & 0b111)) { - case 0: /* sb */ - case 1: /* sh */ - case 2: /* sw */ - case 3: /* sd */ - case 4: /* sq */ - is_write = 1; - break; - default: - break; - } - break; - case 9: - switch (((insn >> 12) & 0b111)) { - case 2: /* fsw */ - case 3: /* fsd */ - case 4: /* fsq */ - is_write = 1; - break; - default: - break; - } - break; - default: - break; - } - } - - /* Check for compressed instructions */ - switch (((insn >> 13) & 0b111)) { - case 7: - switch (insn & 0b11) { - case 0: /*c.sd */ - case 2: /* c.sdsp */ - is_write = 1; - break; - default: - break; - } - break; - case 6: - switch (insn & 0b11) { - case 0: /* c.sw */ - case 3: /* c.swsp */ - is_write = 1; - break; - default: - break; - } - break; - default: - break; - } - - return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); -} -#endif - /* The softmmu versions of these helpers are in cputlb.c. */ /*