From patchwork Tue Dec 21 02:50:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 526585 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4673364imb; Mon, 20 Dec 2021 18:51:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJw78hLlO0OlPtHp6CsPuosOpJXN4ecw4cXsA6NM5JPIQHLfCKcb51tBBKiagSNrSWXnHaFI X-Received: by 2002:a25:d393:: with SMTP id e141mr1691772ybf.244.1640055065909; Mon, 20 Dec 2021 18:51:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640055065; cv=none; d=google.com; s=arc-20160816; b=z6TqCd1aYOborT8w/CHLYntPQ8qmD1Q3D/RnH0weVRgIMwNA3wjuM3BnPS4dWmorOg hgKJJYuN5wtpRpvJGoAqN4iUcRXtEWZBR8n60yF6raF8gjYHwrghpQhb5ygTihNvJ024 jKDdoqkCCMyR+PkbrD+cobaNCpgtYMEGpMnUqxinhsCB8rO2ibshfH9agLdFWYvqZO3e 9ZM/sXAxioBIqS/QJ7TH4I7p13MkoYjScUUZVg07uUbWbc8JnQj2+LURB93MBstuN3qk u6KdcFrpZz/v/AHsz9y4aqXkjjMvEdJPHtOv4YxG/Im/AFG6uSDx6MA6i/fAwejPAY0E l5VQ== 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=Qz+xdjhIIVqjd9hJ/vGpCTslUdMVxxkBaypOe4lBkQo=; b=Q0bB0hJTHDpsV0wyxuHl+EI1PmRS7qAQWWOqb3mDc6IwbvSloS3gfFT6cTU8oU519q yCIY8MRBYmf7p+CLdNsYwZ3ISeGnDknBRCUzcKtwSIjswlI9LfnDVZ71ipNUfnJr7PYb 2qHlScYt9WtyN/h2QcwBVVRhD0oD2b9av8F1GRnRhEJIjMfpxhhs6BJSfBtN8M/+tMEw Tr9YXFkrBbUICaXhEkJWipPWVyZ5wOeeWZZivAvMPf9I/NVXV3Vgdfoud+pf1NW6Yv18 BEKCnDMhGtECdQ8Cf71fkX88sCXD/YjTpKIUlNhFgm4jPX0rtAPyPqPNsvB6l5eUt51k MiVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rt7uL8ty; 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 t8si28179843ybu.446.2021.12.20.18.51.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Dec 2021 18:51:05 -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=fail header.i=@linaro.org header.s=google header.b=rt7uL8ty; 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]:45578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzVF3-0003cU-Bk for patch@linaro.org; Mon, 20 Dec 2021 21:51:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzVEI-0003b0-H7 for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:18 -0500 Received: from [2607:f8b0:4864:20::52c] (port=43776 helo=mail-pg1-x52c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzVEG-0000A6-RY for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:18 -0500 Received: by mail-pg1-x52c.google.com with SMTP id 8so3467385pgc.10 for ; Mon, 20 Dec 2021 18:50:16 -0800 (PST) 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=Qz+xdjhIIVqjd9hJ/vGpCTslUdMVxxkBaypOe4lBkQo=; b=rt7uL8tyF2eVsXOh4ifpZoro0Ztm9DLC99lbq8Nw4uAmB/7g0ReWFreAYjKcMGzBgj 1wo2WdXK0aXrDMQPhdJzauz99sUBEigIQjaWJi2WFvl0sWR6TJHPiPnY/atut8M78EML 1NJQB3yAKG/RvBlHQXID0zqxvhgC35KRIUp2/ArqgVIoyDqYdt59Ew9Vsz2LWTAuN6pV MPsTLxT9yYRO3EjtvvwJ0F3RjPYOSz9665+JDo/15su9dHuEmGsyeCn8wzuTSEMm4rot K5zC+BkFAbP/HqRdOb66w6gCytab9vZ1IpExOEbeMeNXFeAhPq+mohS+U5gLMx84MFVA JQqQ== 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=Qz+xdjhIIVqjd9hJ/vGpCTslUdMVxxkBaypOe4lBkQo=; b=8Cp/PYMmUu9XL7V94TOZDye48DZiE0GstWsbYgadbczExLKD5nIs9eFrHZ4exrFTLX KohFanl1JYoaF4tQCd1gT/4YumGudX8LLcny+hHfX9cLRGK9VB4qYwHHcQuSVYnBkEkX pruu92EYYxbnlgE5gBt5yfC1JCaubKdC+j7bcvZvC1aj49LgpUTq9BfP1mFITIs7Ot7Q mUhOyEdEAdo8ZvrAe9rTR39b2ev1Qs8Y0dADH0NfzuXeMYp2jniDwp0RurBR8dFxhVtR EPV6O+nb1IfVWmKkdpCFYhcDzwfUMU/fUWCyZ6o3MT+76eqb0tmbZKhZ4GSKOj+OP18f xKOQ== X-Gm-Message-State: AOAM530XHlJ5yRmPK6ePjG4W/gUufZ5G3WiUjBWAZpOmPzIrNpPDQjEz ZgYCSt+Aly0cQrfylHP2TCCM5g9bI3gdgw== X-Received: by 2002:aa7:8891:0:b0:4ba:ee8a:8cdd with SMTP id z17-20020aa78891000000b004baee8a8cddmr1041442pfe.79.1640055015479; Mon, 20 Dec 2021 18:50:15 -0800 (PST) Received: from localhost.localdomain ([156.19.246.20]) by smtp.gmail.com with ESMTPSA id bg23sm694025pjb.24.2021.12.20.18.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 18:50:15 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 1/7] linux-user/nios2: Properly emulate EXCP_TRAP Date: Mon, 20 Dec 2021 18:50:06 -0800 Message-Id: <20211221025012.1057923-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221025012.1057923-1-richard.henderson@linaro.org> References: <20211221025012.1057923-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::52c (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: =?utf-8?q?Alex_Benn=C3=A9e?= , laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The real kernel has to load the instruction and extract the imm5 field; for qemu, modify the translator to do this. The use of R_AT for this in cpu_loop was a bug. Handle the other trap numbers as per the kernel's trap_table. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- target/nios2/cpu.h | 2 +- linux-user/nios2/cpu_loop.c | 40 ++++++++++++++++++++----------------- target/nios2/translate.c | 17 +++++++++++++++- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h index 1a69ed7a49..d2ba0c5bbd 100644 --- a/target/nios2/cpu.h +++ b/target/nios2/cpu.h @@ -160,9 +160,9 @@ struct CPUNios2State { #if !defined(CONFIG_USER_ONLY) Nios2MMU mmu; - uint32_t irq_pending; #endif + int error_code; }; /** diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c index 34290fb3b5..5c3d01d22d 100644 --- a/linux-user/nios2/cpu_loop.c +++ b/linux-user/nios2/cpu_loop.c @@ -26,7 +26,6 @@ void cpu_loop(CPUNios2State *env) { CPUState *cs = env_cpu(env); - Nios2CPU *cpu = NIOS2_CPU(cs); target_siginfo_t info; int trapnr, ret; @@ -39,9 +38,10 @@ void cpu_loop(CPUNios2State *env) case EXCP_INTERRUPT: /* just indicate that signals should be handled asap */ break; + case EXCP_TRAP: - if (env->regs[R_AT] == 0) { - abi_long ret; + switch (env->error_code) { + case 0: qemu_log_mask(CPU_LOG_INT, "\nSyscall\n"); ret = do_syscall(env, env->regs[2], @@ -55,26 +55,30 @@ void cpu_loop(CPUNios2State *env) env->regs[2] = abs(ret); /* Return value is 0..4096 */ - env->regs[7] = (ret > 0xfffffffffffff000ULL); - env->regs[CR_ESTATUS] = env->regs[CR_STATUS]; - env->regs[CR_STATUS] &= ~0x3; - env->regs[R_EA] = env->regs[R_PC] + 4; + env->regs[7] = ret > 0xfffff000u; env->regs[R_PC] += 4; break; - } else { - qemu_log_mask(CPU_LOG_INT, "\nTrap\n"); - env->regs[CR_ESTATUS] = env->regs[CR_STATUS]; - env->regs[CR_STATUS] &= ~0x3; - env->regs[R_EA] = env->regs[R_PC] + 4; - env->regs[R_PC] = cpu->exception_addr; - - info.si_signo = TARGET_SIGTRAP; - info.si_errno = 0; - info.si_code = TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + case 1: + qemu_log_mask(CPU_LOG_INT, "\nTrap 1\n"); + force_sig_fault(TARGET_SIGUSR1, 0, env->regs[R_PC]); + break; + case 2: + qemu_log_mask(CPU_LOG_INT, "\nTrap 2\n"); + force_sig_fault(TARGET_SIGUSR2, 0, env->regs[R_PC]); + break; + case 31: + qemu_log_mask(CPU_LOG_INT, "\nTrap 31\n"); + force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->regs[R_PC]); + break; + default: + qemu_log_mask(CPU_LOG_INT, "\nTrap %d\n", env->error_code); + force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLTRP, + env->regs[R_PC]); break; } + break; + case EXCP_DEBUG: info.si_signo = TARGET_SIGTRAP; info.si_errno = 0; diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 08d7ac5398..a759877519 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -636,6 +636,21 @@ static void divu(DisasContext *dc, uint32_t code, uint32_t flags) tcg_temp_free(t0); } +static void trap(DisasContext *dc, uint32_t code, uint32_t flags) +{ +#ifdef CONFIG_USER_ONLY + /* + * The imm5 field is not stored anywhere on real hw; the kernel + * has to load the insn and extract the field. But we can make + * things easier for cpu_loop if we pop this into env->error_code. + */ + R_TYPE(instr, code); + tcg_gen_st_i32(tcg_constant_i32(instr.imm5), cpu_env, + offsetof(CPUNios2State, error_code)); +#endif + t_gen_helper_raise_exception(dc, EXCP_TRAP); +} + static const Nios2Instruction r_type_instructions[] = { INSTRUCTION_ILLEGAL(), INSTRUCTION(eret), /* eret */ @@ -682,7 +697,7 @@ static const Nios2Instruction r_type_instructions[] = { INSTRUCTION_ILLEGAL(), INSTRUCTION_ILLEGAL(), INSTRUCTION_ILLEGAL(), - INSTRUCTION_FLG(gen_excp, EXCP_TRAP), /* trap */ + INSTRUCTION(trap), /* trap */ INSTRUCTION(wrctl), /* wrctl */ INSTRUCTION_ILLEGAL(), INSTRUCTION_FLG(gen_cmpxx, TCG_COND_LTU), /* cmpltu */ From patchwork Tue Dec 21 02:50:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 526587 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4675014imb; Mon, 20 Dec 2021 18:54:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdFvt+7XYfjR+cEGEPzFPTivcRCN2gtsm8P1jLiCmOBieW+fuk53C1Zn9gai+3yT2N5MrW X-Received: by 2002:a25:311:: with SMTP id 17mr1776498ybd.483.1640055241743; Mon, 20 Dec 2021 18:54:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640055241; cv=none; d=google.com; s=arc-20160816; b=uvZrR26hZRbFd5fA7rSUi5uC6Nv3XJ7hacubB7DaDaWEI07ctj+7q4tZGAlwlinmQw /K3y35opm8wseXwMMWHpYtZl8nynhbL/wkzKHPDBnvJnqddpo+ZIstcEn+KQ1TcWT54t 1iKlKq9iP/iaVjgO4rw1wAbgQldfVXappbF+trrrrPOfD3IJtzQOVhnFswVhgdr2T+R7 L0xTqsr/xmBwCqeE6Dq69Gx34b/NB2SZrciefxdwuUR6/EpYw1KH85M2LooWUNluT6Ao QhO9TyIJ1dqQ/LQx36092IyRgCNvQQVHJK0Vsf12LbIHBOzm9zu1tXww/iS+tE+llnC7 8bNw== 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=HbNBQfasK4f+xfMQiEwPjjsKiwcmSRl4Jt7JCBlYZlo=; b=jbSW2CK2+L3ZGr+1mrMuE05GmIuGtb7Ibj9yH7TZ70iTSLjc/8v5bhOMQYAVebpKju CWjLjZJAwopGo0bPXxRGHDCiCWvPgCS8OlVwOkTeckmrX8qMITUQVJ9ICEZC6abMdPnY wqRhvtS25C6Q3K/CptzSE3zqxlhue/EBhkijr2P+w51GSKQ+Mb3XN31fewJ0tV66sjG6 UVo8JXDJ/FlnitK8LZcVoPRVZukXCwJTWoTr3QgwIU/a5xm1xHvIRnaEvbMcacI5mo4l ssx/yAsPLb7JE0FV0pECoyyyO3oRfdfe3QyQQTLenziMyMVlaW6LIJGESZ02/X07iEXQ SJxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NfUfLCNI; 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 s13si20161298ybp.359.2021.12.20.18.54.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Dec 2021 18:54:01 -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=fail header.i=@linaro.org header.s=google header.b=NfUfLCNI; 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]:51970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzVHt-00080B-8L for patch@linaro.org; Mon, 20 Dec 2021 21:54:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzVEJ-0003bU-D7 for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:19 -0500 Received: from [2607:f8b0:4864:20::533] (port=33724 helo=mail-pg1-x533.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzVEH-0000AC-Jz for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:18 -0500 Received: by mail-pg1-x533.google.com with SMTP id f125so11082179pgc.0 for ; Mon, 20 Dec 2021 18:50:17 -0800 (PST) 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=HbNBQfasK4f+xfMQiEwPjjsKiwcmSRl4Jt7JCBlYZlo=; b=NfUfLCNIjMo8KMEKTAiv2uAEDlt0axISwbzsiOaD+OSocglWRo4Tx7kAlBR4tQfmml pvFCLm446w9QXbadzxKNpt034iCGmw+oX1New3O2pexBhh4ef9Qdylr3wtRN6alY6VXQ byyMj6mklHJp/LBIOz6J8Sw5vFb2B5PtYga/F0eyk2Rg24BPpRHr8DqMnO0x8162ovnd xv5lljWuTZ+9fZCZPq1O2Dd03SSNMICnoM4z/4RYHY2MufJ9Usf9oRJBORhXuQkWb+Y0 zp9YkyNdD3N5x8iCoXyJeOk9PQkvpxGe0UbvVRCXx8b8DKB/Ac1gS7uL0w216MIVwsYc 60/Q== 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=HbNBQfasK4f+xfMQiEwPjjsKiwcmSRl4Jt7JCBlYZlo=; b=12AaVBMhuHzR7N59lDJsgCotA+ZM/ezuWPN/VjENZIfvtIJq6K49MCMWD0z6HdXd/j hFx9DOzQTt0Iyrt90YqGQ+Ihqpanciocg6l6Ufv3Khi9isbkhexb9YMU2P/9ZzTH27Iw pwNEt0UDvs/MeUsbsdGr3dntFb/UkIORWnPQLOolPT9S8V6/+fxYZRl7fnzHp1iCKuTu IHWgcN36xoo4aQEcZcs8y3cxhQalJooFxTzeBVnMoQtNH4qfLsRycRqIZxaul5ceZX7s MFs5zxA6EGkttLnwrK2uoVmcpExvvfxTTvQPIyWATWZuAXxD9IaNlR406Ej3q1PPehRG o7Ug== X-Gm-Message-State: AOAM532cWvBmcEC0hILwS6kF/qxaCVn4W2aSZFILlz4QnK5nGK3r1NzK S/GiMd7Dys1/oOCnK2TaRO+P6lZ93oCTiA== X-Received: by 2002:a63:4c45:: with SMTP id m5mr1013980pgl.105.1640055016375; Mon, 20 Dec 2021 18:50:16 -0800 (PST) Received: from localhost.localdomain ([156.19.246.20]) by smtp.gmail.com with ESMTPSA id bg23sm694025pjb.24.2021.12.20.18.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 18:50:16 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 2/7] linux-user/nios2: Fixes for signal frame setup Date: Mon, 20 Dec 2021 18:50:07 -0800 Message-Id: <20211221025012.1057923-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221025012.1057923-1-richard.henderson@linaro.org> References: <20211221025012.1057923-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::533 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Do not confuse host and guest addresses. Lock and unlock the target_rt_sigframe structure in setup_rt_sigframe. Since rt_setup_ucontext always returns 0, drop the return value entirely. This eliminates the only write to the err variable in setup_rt_sigframe. Always copy the siginfo structure. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/nios2/signal.c | 49 ++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c index a77e8a40f4..adbffe32e3 100644 --- a/linux-user/nios2/signal.c +++ b/linux-user/nios2/signal.c @@ -42,7 +42,7 @@ struct target_rt_sigframe { struct target_ucontext uc; }; -static int rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env) +static void rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env) { unsigned long *gregs = uc->tuc_mcontext.gregs; @@ -75,8 +75,6 @@ static int rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env) __put_user(env->regs[R_GP], &gregs[25]); __put_user(env->regs[R_EA], &gregs[27]); __put_user(env->regs[R_SP], &gregs[28]); - - return 0; } static int rt_restore_ucontext(CPUNios2State *env, struct target_ucontext *uc, @@ -135,8 +133,8 @@ static int rt_restore_ucontext(CPUNios2State *env, struct target_ucontext *uc, return 0; } -static void *get_sigframe(struct target_sigaction *ka, CPUNios2State *env, - size_t frame_size) +static abi_ptr get_sigframe(struct target_sigaction *ka, CPUNios2State *env, + size_t frame_size) { unsigned long usp; @@ -144,7 +142,7 @@ static void *get_sigframe(struct target_sigaction *ka, CPUNios2State *env, usp = target_sigsp(get_sp_from_cpustate(env), ka); /* Verify, is it 32 or 64 bit aligned */ - return (void *)((usp - frame_size) & -8UL); + return (usp - frame_size) & -8; } void setup_rt_frame(int sig, struct target_sigaction *ka, @@ -153,26 +151,25 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, CPUNios2State *env) { struct target_rt_sigframe *frame; - int i, err = 0; + abi_ptr frame_addr; + int i; - frame = get_sigframe(ka, env, sizeof(*frame)); - - if (ka->sa_flags & SA_SIGINFO) { - tswap_siginfo(&frame->info, info); + frame_addr = get_sigframe(ka, env, sizeof(*frame)); + if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) { + force_sigsegv(sig); + return; } + tswap_siginfo(&frame->info, info); + /* Create the ucontext. */ __put_user(0, &frame->uc.tuc_flags); __put_user(0, &frame->uc.tuc_link); target_save_altstack(&frame->uc.tuc_stack, env); - err |= rt_setup_ucontext(&frame->uc, env); + rt_setup_ucontext(&frame->uc, env); for (i = 0; i < TARGET_NSIG_WORDS; i++) { __put_user((abi_ulong)set->sig[i], - (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]); - } - - if (err) { - goto give_sigsegv; + (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]); } /* Set up to return from userspace; jump to fixed address sigreturn @@ -180,19 +177,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, env->regs[R_RA] = (unsigned long) (0x1044); /* Set up registers for signal handler */ - env->regs[R_SP] = (unsigned long) frame; - env->regs[4] = (unsigned long) sig; - env->regs[5] = (unsigned long) &frame->info; - env->regs[6] = (unsigned long) &frame->uc; - env->regs[R_EA] = (unsigned long) ka->_sa_handler; - return; + env->regs[R_SP] = frame_addr; + env->regs[4] = sig; + env->regs[5] = frame_addr + offsetof(struct target_rt_sigframe, info); + env->regs[6] = frame_addr + offsetof(struct target_rt_sigframe, uc); + env->regs[R_EA] = ka->_sa_handler; -give_sigsegv: - if (sig == TARGET_SIGSEGV) { - ka->_sa_handler = TARGET_SIG_DFL; - } - force_sigsegv(sig); - return; + unlock_user_struct(frame, frame_addr, 1); } long do_sigreturn(CPUNios2State *env) From patchwork Tue Dec 21 02:50:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 526588 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4675045imb; Mon, 20 Dec 2021 18:54:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzWhFFV3wYQx2Q53VdlNHEjUT/sa/Ky2UtqdopZvGZgEy0qG/+E2B5Yr1ifTfCQ1cqT4yZF X-Received: by 2002:a25:f211:: with SMTP id i17mr1549134ybe.239.1640055244932; Mon, 20 Dec 2021 18:54:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640055244; cv=none; d=google.com; s=arc-20160816; b=RWPWEgTR3gZqrzS38D4JOFBNodmHhiZwK0SYX5+h0QWAq/1WtqkVUeER0Twe7WzcBb ohXAUTpBnB9Wx0HLKxdKpIBqZ0YRnGUdBmbHytm3T6SaTYsyinHsCMCPietyxhjMI7/M 8KEnLTVyZA3MuM9qvd+KsYzEMQNJznJXBqFWYZ8bTeqwWb5rYRjIhFosLNKFNXNz6QzP 3jEaUCG0mAqNhtA/nW6MGarPfkPbMGZGE7yblFQTjAuQej9maEDspnmfZNolq7AuxXLK xrYLHZx/RcE8jDjac53LC0v9tHX/1BBIyMGtkbScE6CyGzQYXKjkOHTRrvCNJ0W3PZMv iz5g== 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=Zi74zX03AzlDYSTcNyOeKzOi2PA59RfE+ydGeg7N9HY=; b=AfkGEe/DzNaY9xFNhz8x5XvdTCVG6RBS/xCy1xWt86UnMBIGShaH4wFu6UOtafLvSD vKo8vKaj+fgoBoYptjdlCMZLqAHuh6gqi24NelevkGdwd9VGxuyGP4uK1EBAP2o/e8Vl MFYTjolwGJjrLktfaeaiaGRAPG4NIedmGZaa8LzU7jAeH9M8Iu7d7YUq/3mhUZMmG/ex v8t6Wdj+dm5prQysJi8vnEqXAPpXjIitv/gCfDKHBYLsVhhue3VKyhzEoUVY1CoIvvAJ uwRrwELba29uCxS3mcIqAJVR90kOdVTzcG0l24FZes7H2XygjUPWnUduZ2C8SY30e+q8 eK2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Fw7zeAnK; 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 p129si20792508ybb.550.2021.12.20.18.54.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Dec 2021 18:54:04 -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=Fw7zeAnK; 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]:52294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzVHw-0008DF-E2 for patch@linaro.org; Mon, 20 Dec 2021 21:54:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54234) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzVEK-0003ck-5t for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:20 -0500 Received: from [2607:f8b0:4864:20::62c] (port=38787 helo=mail-pl1-x62c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzVEI-0000AT-Gn for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:19 -0500 Received: by mail-pl1-x62c.google.com with SMTP id c7so801932plg.5 for ; Mon, 20 Dec 2021 18:50:18 -0800 (PST) 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=Zi74zX03AzlDYSTcNyOeKzOi2PA59RfE+ydGeg7N9HY=; b=Fw7zeAnKqY9GgyMFP5//31pAZL4+H5ZEBINP2esOAQPdAaSQgYCkH/sALJz8g7B1lL EOiO2ylgEalGv50W52V2gnWJSkrqmHaMAidDpGOUlbOaVzLXLq3pbzX3sia5yDXGoQ7b OW+fEVcsGzl+dwA3rfuWIwHxendwJlfquk30LCfxW8v6QjNb+FqFDVxdrjoIbQQ5CK/W 58GEIBCHrehIywX98O0LQioKcxaxRCP4T6D+J1BCcI9vkYtKdhdKve9Y7EkduUsne9VJ lJ5Dp0zAFwpNsm08QRGxtESNx/wDo0bOUXOtoTlUDCcP121XSKuNW4xzBNv5Rue0/MPE zmkg== 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=Zi74zX03AzlDYSTcNyOeKzOi2PA59RfE+ydGeg7N9HY=; b=0mzZYDIX9bbc+wru2hsXMmHUtyebq07Ha3Bzfwj1W/Wra+OwoVBK0ewJvMi5n4MtyM z9e3jI8+8Z3fdn6csj5w8LcQs834syqOABE2JGa0Rk7N0V4SF0Y/auviPcEzr3pgKMnX 9W5I10ukIhe1wixMe1jVuBmmFW9OWuDvg+HnZx8w/s2qRSY5xAT8brtYH3FXhMM2oWJ8 yrmXcz4fNN4NVXNDNTaUMkokVJ8MPHlAv8B7uj0aYyOh/On4PPyqynu5ezsKGm5K35UJ u9XuZvuUa4Zj9QYly+d3P99GlRoOHb97FsXqrB1pcGb/iey0kvmYco3GwwdOBeNJnigv 3uLw== X-Gm-Message-State: AOAM532V5FWt8lNWOrgoaZCsOhghs1HMS91ataEN6e4tG6/8U3c6d+ZX cZHU5XnT4XkBnVkgL8vQydkpQ31Vaj8pfw== X-Received: by 2002:a17:90a:6b44:: with SMTP id x4mr1303915pjl.27.1640055017198; Mon, 20 Dec 2021 18:50:17 -0800 (PST) Received: from localhost.localdomain ([156.19.246.20]) by smtp.gmail.com with ESMTPSA id bg23sm694025pjb.24.2021.12.20.18.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 18:50:16 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 3/7] linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE Date: Mon, 20 Dec 2021 18:50:08 -0800 Message-Id: <20211221025012.1057923-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221025012.1057923-1-richard.henderson@linaro.org> References: <20211221025012.1057923-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::62c (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Arm will no longer be the only target requiring a commpage, but it will continue to be the only target placing the page at the high end of the address space. Reviewed-by: Laurent Vivier Signed-off-by: Richard Henderson --- linux-user/elfload.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 767f54c76d..d34cd4fe43 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -390,11 +390,11 @@ enum { /* The commpage only exists for 32 bit kernels */ -#define ARM_COMMPAGE (intptr_t)0xffff0f00u +#define HI_COMMPAGE (intptr_t)0xffff0f00u static bool init_guest_commpage(void) { - void *want = g2h_untagged(ARM_COMMPAGE & -qemu_host_page_size); + void *want = g2h_untagged(HI_COMMPAGE & -qemu_host_page_size); void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); @@ -2160,8 +2160,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, return sp; } -#ifndef ARM_COMMPAGE -#define ARM_COMMPAGE 0 +#ifndef HI_COMMPAGE +#define HI_COMMPAGE 0 #define init_guest_commpage() true #endif @@ -2361,7 +2361,7 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr, } loaddr &= -align; - if (ARM_COMMPAGE) { + if (HI_COMMPAGE) { /* * Extend the allocation to include the commpage. * For a 64-bit host, this is just 4GiB; for a 32-bit host we @@ -2372,14 +2372,14 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr, if (sizeof(uintptr_t) == 8 || loaddr >= 0x80000000u) { hiaddr = (uintptr_t) 4 << 30; } else { - offset = -(ARM_COMMPAGE & -align); + offset = -(HI_COMMPAGE & -align); } } addr = pgb_find_hole(loaddr, hiaddr - loaddr, align, offset); if (addr == -1) { /* - * If ARM_COMMPAGE, there *might* be a non-consecutive allocation + * If HI_COMMPAGE, there *might* be a non-consecutive allocation * that can satisfy both. But as the normal arm32 link base address * is ~32k, and we extend down to include the commpage, making the * overhead only ~96k, this is unlikely. @@ -2400,7 +2400,7 @@ static void pgb_dynamic(const char *image_name, long align) * All we need is a commpage that satisfies align. * If we do not need a commpage, leave guest_base == 0. */ - if (ARM_COMMPAGE) { + if (HI_COMMPAGE) { uintptr_t addr, commpage; /* 64-bit hosts should have used reserved_va. */ @@ -2410,7 +2410,7 @@ static void pgb_dynamic(const char *image_name, long align) * By putting the commpage at the first hole, that puts guest_base * just above that, and maximises the positive guest addresses. */ - commpage = ARM_COMMPAGE & -align; + commpage = HI_COMMPAGE & -align; addr = pgb_find_hole(commpage, -commpage, align, 0); assert(addr != -1); guest_base = addr; From patchwork Tue Dec 21 02:50:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 526590 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4676126imb; Mon, 20 Dec 2021 18:56:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJyj2qrmihQZSLZcS8yoWgNcWY48VcNjuGEM2NaZMG8RFXgKFeqOllaXgwgLiQGUzZ5e/LNG X-Received: by 2002:a25:6152:: with SMTP id v79mr1661259ybb.400.1640055367769; Mon, 20 Dec 2021 18:56:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640055367; cv=none; d=google.com; s=arc-20160816; b=CwJmzRPlb2IrKbF7E4UbWXB8kJMIyZ81gBz4vFWBtwwhxKCbzFJrNq8bHKXv3iTMT4 X+E97ugAzl+KtMfEb9wpngJOKz494yVsqUicnQyrUJZuTF8wCM1+tk/77YjEdOoSM4Mn 7RS1b5xT7fqrIc+x6AXtgkxX8mkyPXkuzxwvnM8360SahH/v2hhstBjgLp+ALtMWlocj gyuqYH2jfvSVU0qIQB+WH+0USCxy51H/FxxkBH4ECWeUVJ6zBvSE/So+j/nqnQPsza7M UzvPIRhYql+58yi5abxwCyf+am0JQYIjMlV7sfdTHvrbhGDWb7ckx1OX98y3qOswH1K6 dVkw== 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=WD5SX/a7MEJASWKLyGWdbzVbY06pcJ/VW3E6SnKv2TU=; b=vfSArcYFeXEqOuQmRAAQC/KrQKYgTXB9FHTnsFYoyw6JPW3FfWUnRB4u2fQKjitXf5 pQ3KqnFUA/hanzaJFz3ymspeQ4s2Jit2QwGwchW4PNIZcdWgN6vGQmPBrEzvO+2m9sJo 1vp5OZShfCo90ESrvWxmv5IGmLIbdkWu026fIplYYSvGf6Gm/5WOf2Gu5CjMRTAFMyi6 SSXjPYcY3UjBpSI2yZAZSjG4wcmBnpJSteeh5fGfTklWVs1Atjn7e3s3maFTy2zbaO/j pTpbsg2dp9IOvIn6cwyuDTm0b0d/xdwImJtAb3VMYXUceqJO3PKJcFAHIp01/6vwskkR q7kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vi5BzYdI; 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 j196si19322683ybj.445.2021.12.20.18.56.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Dec 2021 18:56:07 -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=vi5BzYdI; 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]:57248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzVJv-00033n-9j for patch@linaro.org; Mon, 20 Dec 2021 21:56:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzVEK-0003eW-UB for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:21 -0500 Received: from [2607:f8b0:4864:20::1036] (port=51153 helo=mail-pj1-x1036.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzVEJ-0000Al-7p for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:20 -0500 Received: by mail-pj1-x1036.google.com with SMTP id gj24so11203375pjb.0 for ; Mon, 20 Dec 2021 18:50:18 -0800 (PST) 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=WD5SX/a7MEJASWKLyGWdbzVbY06pcJ/VW3E6SnKv2TU=; b=vi5BzYdIS91HMr0rGrWK7j/4h2hDjkzdzR04Ol58IblVxqG9axbMu8jJ6furDOpz0j /d3wvfo2NzG7hlndTII5CsR9cnTFVnY1EijEZsUgD8NW4DDZOzshBH4gQJloBqFuOJaL /mY0M4AcVfxlhBKVci1OoK2QEPvs7i9I7XzWiQ/nva7BL/fewlmgnQvVeTHsK5rCLHnl QVPzhLvY8+Ir70PxU+L13fqZ+aE71luc3RilYD7BNnF7auZ73ihBQ8jLYbxMiK7uua/8 nv0TFxIuaF+9n7aVnw6Rv+pbb0ugfJWrpUPvz975FUN4XqpXycjQO5ERkLrdCT5flKsC MAVQ== 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=WD5SX/a7MEJASWKLyGWdbzVbY06pcJ/VW3E6SnKv2TU=; b=Y4xbuX+l0D1x0K1L6CU1WfiCfYGFl4sAvIK7IBr2rFjvB7zbSwjgTtNbRFrSHLMW2S Uwd/jXAGI70f2xon70mtCEBjkO5pTWWat6GerhqYQnlWWpXeUTnxgtJY0q6m9bpX6gv9 ezGT+v0nY8gShPsfLLldlSU+kg5hUZESC0gghO/AOw70X32CklxEPBzij4Jggb2GGPny q1nZ5Nmhy4Vl3I01G8SEJCGDZnfbjwunSTv3jfk0/YfQGxbB7Fy+vBc0tigdQgg+s+O4 tRCv8YBu+6Bib0g+IxLX1u52XFFY6IWryLFC82HmEvNMiawg+kQM7zkUZ2dwQ+k2Xh+L bBBg== X-Gm-Message-State: AOAM530XNci8B1JYloEbiLgEcecyxa7mNcvQUKuUxjM84tkcap1UxtY4 bkWz1N8XeYoWuO0NXSk42bwDhQwmYz5/Eg== X-Received: by 2002:a17:90b:1d09:: with SMTP id on9mr1280649pjb.191.1640055017936; Mon, 20 Dec 2021 18:50:17 -0800 (PST) Received: from localhost.localdomain ([156.19.246.20]) by smtp.gmail.com with ESMTPSA id bg23sm694025pjb.24.2021.12.20.18.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 18:50:17 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 4/7] linux-user/nios2: Map a real kuser page Date: Mon, 20 Dec 2021 18:50:09 -0800 Message-Id: <20211221025012.1057923-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221025012.1057923-1-richard.henderson@linaro.org> References: <20211221025012.1057923-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1036 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The first word of page1 is data, so the whole thing can't be implemented with emulation of addresses. Use init_guest_commpage for the allocation. Hijack trap number 16 to implement cmpxchg. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- linux-user/elfload.c | 50 ++++++++++++++++++++++++++++++++++++- linux-user/nios2/cpu_loop.c | 50 ++++++++++++++++++++----------------- target/nios2/translate.c | 9 ------- 3 files changed, 76 insertions(+), 33 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index d34cd4fe43..329b2375ef 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1099,6 +1099,47 @@ static void init_thread(struct target_pt_regs *regs, struct image_info *infop) regs->estatus = 0x3; } +#define LO_COMMPAGE TARGET_PAGE_SIZE + +static bool init_guest_commpage(void) +{ + static const uint8_t kuser_page[4 + 2 * 64] = { + /* __kuser_helper_version */ + [0x00] = 0x02, 0x00, 0x00, 0x00, + + /* __kuser_cmpxchg */ + [0x04] = 0x3a, 0x6c, 0x3b, 0x00, /* trap 16 */ + 0x3a, 0x28, 0x00, 0xf8, /* ret */ + + /* __kuser_sigtramp */ + [0x44] = 0xc4, 0x22, 0x80, 0x00, /* movi r2, __NR_rt_sigreturn */ + 0x3a, 0x68, 0x3b, 0x00, /* trap 0 */ + }; + + void *want = g2h_untagged(LO_COMMPAGE & -qemu_host_page_size); + void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); + + if (addr == MAP_FAILED) { + perror("Allocating guest commpage"); + exit(EXIT_FAILURE); + } + if (addr != want) { + return false; + } + + memcpy(addr, kuser_page, sizeof(kuser_page)); + + if (mprotect(addr, qemu_host_page_size, PROT_READ)) { + perror("Protecting guest commpage"); + exit(EXIT_FAILURE); + } + + page_set_flags(LO_COMMPAGE, LO_COMMPAGE + TARGET_PAGE_SIZE, + PAGE_READ | PAGE_EXEC | PAGE_VALID); + return true; +} + #define ELF_EXEC_PAGESIZE 4096 #define USE_ELF_CORE_DUMP @@ -2160,8 +2201,13 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, return sp; } -#ifndef HI_COMMPAGE +#if defined(HI_COMMPAGE) +#define LO_COMMPAGE 0 +#elif defined(LO_COMMPAGE) #define HI_COMMPAGE 0 +#else +#define HI_COMMPAGE 0 +#define LO_COMMPAGE 0 #define init_guest_commpage() true #endif @@ -2374,6 +2420,8 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr, } else { offset = -(HI_COMMPAGE & -align); } + } else if (LO_COMMPAGE) { + loaddr = MIN(loaddr, LO_COMMPAGE & -align); } addr = pgb_find_hole(loaddr, hiaddr - loaddr, align, offset); diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c index 5c3d01d22d..de0fc63e21 100644 --- a/linux-user/nios2/cpu_loop.c +++ b/linux-user/nios2/cpu_loop.c @@ -76,6 +76,32 @@ void cpu_loop(CPUNios2State *env) force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLTRP, env->regs[R_PC]); break; + + case 16: /* QEMU specific, for __kuser_cmpxchg */ + { + abi_ptr g = env->regs[4]; + uint32_t *h, n, o; + + if (g & 0x3) { + force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, g); + break; + } + ret = page_get_flags(g); + if (!(ret & PAGE_VALID)) { + force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, g); + break; + } + if (!(ret & PAGE_READ) || !(ret & PAGE_WRITE)) { + force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_ACCERR, g); + break; + } + h = g2h(cs, g); + o = env->regs[5]; + n = env->regs[6]; + env->regs[2] = qatomic_cmpxchg(h, o, n) - o; + env->regs[R_PC] += 4; + } + break; } break; @@ -86,29 +112,7 @@ void cpu_loop(CPUNios2State *env) queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); break; case 0xaa: - switch (env->regs[R_PC]) { - /*case 0x1000:*/ /* TODO:__kuser_helper_version */ - case 0x1004: /* __kuser_cmpxchg */ - start_exclusive(); - if (env->regs[4] & 0x3) { - goto kuser_fail; - } - ret = get_user_u32(env->regs[2], env->regs[4]); - if (ret) { - end_exclusive(); - goto kuser_fail; - } - env->regs[2] -= env->regs[5]; - if (env->regs[2] == 0) { - put_user_u32(env->regs[6], env->regs[4]); - } - end_exclusive(); - env->regs[R_PC] = env->regs[R_RA]; - break; - /*case 0x1040:*/ /* TODO:__kuser_sigtramp */ - default: - ; -kuser_fail: + { info.si_signo = TARGET_SIGSEGV; info.si_errno = 0; /* TODO: check env->error_code */ diff --git a/target/nios2/translate.c b/target/nios2/translate.c index a759877519..f9abc2fdd2 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -795,15 +795,6 @@ static void nios2_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) dc->base.pc_next = pc + 4; /* Decode an instruction */ - -#if defined(CONFIG_USER_ONLY) - /* FIXME: Is this needed ? */ - if (pc >= 0x1000 && pc < 0x2000) { - t_gen_helper_raise_exception(dc, 0xaa); - return; - } -#endif - code = cpu_ldl_code(env, pc); op = get_opcode(code); From patchwork Tue Dec 21 02:50:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 526586 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4673668imb; Mon, 20 Dec 2021 18:51:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXfUO4AwJuPOAAe0+7d7Qp+1fovZ7Kxqxv6vhUXwl1pjyauyRoMofY9OBzwjLvRDiBFOzl X-Received: by 2002:a25:2c85:: with SMTP id s127mr1698708ybs.250.1640055098495; Mon, 20 Dec 2021 18:51:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640055098; cv=none; d=google.com; s=arc-20160816; b=kLVbsB90BdYokD9d/IUGEq+IV38+Bn+6rWvoCp0/Vkw8T9fLrpkoae1nAskOKsHWaD UUL8tAXulE9tRlwyKMov1dg60iMSQ2qzc2Q72n4EejiuEg/hJ6YTGUB6+UONRda/OoIa CbI+7Yw/fsqIaxRU99F5pYgh8UBWGqbIwbKHHhiMp0lVNFa/aOVl74/pco0R8imKgXzl +tUru2TNJvxcSnnoHka3C10DPLarNnBZstHqcLpZ+g01HCiBhJuNgS1Sni0h0CGsOgBX nzT+fk9ifj/OpYKnQ5TpzwptDWrQ1ej1tnX4fHKbpsxHZsMBgeTzK+aAsMqM9gv45GQI +blQ== 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=F9yEwPrmR9xpxjbUMZcvWlIm4BrVKkXnEjUbM9qs6VM=; b=z9kvSoIYZVwxJnEEeOGdIB+HucO4e0n/QOXs+JRXtqTiqm4vbUSJA34qt67opSFGMo bkgvjVHFQWBHA39pEFAd5Y6low6Y9AqdjdimFY3Ef8j9VVo8ihrs7Au7Y+qHqRTV9UKw BHm7ZYh8sZWHSm919kAsRGThr6zlGGO7F6svHG+kuhH5XfjVCOiU8m9MCPfrk3hFMelq nX6WRNreP1H1dAfxhPEs4YXt0Z3lnqpBHH6A2So2Rs8sR33ayJTRxhGte/y0vFsF0YCs n4519MguK6zuBGihsqDREQ0KRAt8X5pfcXXgO5AX2wGGMYJexSqBPqFRLMWsh9nhQE0t OUjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D8TZnIfL; 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 d124si23972792ybd.289.2021.12.20.18.51.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Dec 2021 18:51:38 -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=D8TZnIfL; 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]:47730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzVFa-00053N-0I for patch@linaro.org; Mon, 20 Dec 2021 21:51:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzVEM-0003hK-5o for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:22 -0500 Received: from [2607:f8b0:4864:20::52d] (port=44924 helo=mail-pg1-x52d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzVEK-0000C3-6z for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:21 -0500 Received: by mail-pg1-x52d.google.com with SMTP id m15so11016644pgu.11 for ; Mon, 20 Dec 2021 18:50:19 -0800 (PST) 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=F9yEwPrmR9xpxjbUMZcvWlIm4BrVKkXnEjUbM9qs6VM=; b=D8TZnIfLabC0AmpSuzjzLdtK0EWfT+HTror9COebxvSfFoRHkl1YGeEJyI0Wcpfxoe IjuOb7QEmLSp11PIsk2KsMdkFDSfGPVhPXzinYzwQ9nj9kdliJM877tGBU4w1hWmdlzZ QeVL4YaKjXkFb4YSMLWUMq8Pjwf8DaXbasXAJFu+jy6PzL47peoKYbrfqeZ96KHZrl40 qz/WnFLdnLd91tD4vn9cbOjKyswNDyKmZu55rpooIwdXXAelgnG+lsUWceOF8ft9vXEB SlCbkAn37tnMHG5PN+UAU51JThg43Ncg9iOLetSiURpF0e0DD7ZcjLh5zAlw2ySM9NUe wNtg== 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=F9yEwPrmR9xpxjbUMZcvWlIm4BrVKkXnEjUbM9qs6VM=; b=HP4xgqSYHhllqXq6UHMdsyAFqPSEtNhWDzFb0FK8Xlrh8CByrPiclAz2saZZFw+EsF Z2q81Ye5FFDkXXEXcRi/+R3ly23l1D9J3SAocIAVfCBfhcTT00sPpQf7enoJDg0cDDjL vFOs84UOuPQ9vU8Y/07IfL5Uh4Op9C3dBy7t3ZhRw3p4MRJamj/ey2hKxbN2GzX53t7M 3mLTpKW/9qh+mb4S6iBKiRdyZlQB/16jFagJvQ73Q2XfzwYS6d6Eiu+P125fYMk2yaia KPIvmQhCbHvNAJLZsdnh30LKdCnMSRRvC++izXsuqZ5ljieoERWvtx8Njjj/87Io6o3G mexA== X-Gm-Message-State: AOAM530mPv2zzbIvAsxw3B5fWS/I7t0ok8JdEF6JLbVN1R6/CV31I+Fa ajkJAV7pZfpRIfp1FxQql/zaNEEU+5tY0g== X-Received: by 2002:a65:6411:: with SMTP id a17mr1043081pgv.203.1640055018869; Mon, 20 Dec 2021 18:50:18 -0800 (PST) Received: from localhost.localdomain ([156.19.246.20]) by smtp.gmail.com with ESMTPSA id bg23sm694025pjb.24.2021.12.20.18.50.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 18:50:18 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 5/7] linux-user/nios2: Fix EA vs PC confusion Date: Mon, 20 Dec 2021 18:50:10 -0800 Message-Id: <20211221025012.1057923-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221025012.1057923-1-richard.henderson@linaro.org> References: <20211221025012.1057923-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::52d (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52d.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The real kernel will talk about the user PC as EA, because that's where the hardware will have copied it, and where it expects to put it to then use ERET. But qemu does not emulate all of the exception stuff while emulating user-only. Manipulate PC directly. This fixes signal entry and return, and eliminates some slight confusion from target_cpu_copy_regs. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- linux-user/nios2/cpu_loop.c | 5 +---- linux-user/nios2/signal.c | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c index de0fc63e21..1e93ef34e6 100644 --- a/linux-user/nios2/cpu_loop.c +++ b/linux-user/nios2/cpu_loop.c @@ -155,9 +155,6 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) env->regs[R_SP] = regs->sp; env->regs[R_GP] = regs->gp; env->regs[CR_ESTATUS] = regs->estatus; - env->regs[R_EA] = regs->ea; - /* TODO: unsigned long orig_r7; */ - - /* Emulate eret when starting thread. */ env->regs[R_PC] = regs->ea; + /* TODO: unsigned long orig_r7; */ } diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c index adbffe32e3..20b65aa06e 100644 --- a/linux-user/nios2/signal.c +++ b/linux-user/nios2/signal.c @@ -73,7 +73,7 @@ static void rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env) __put_user(env->regs[R_RA], &gregs[23]); __put_user(env->regs[R_FP], &gregs[24]); __put_user(env->regs[R_GP], &gregs[25]); - __put_user(env->regs[R_EA], &gregs[27]); + __put_user(env->regs[R_PC], &gregs[27]); __put_user(env->regs[R_SP], &gregs[28]); } @@ -122,7 +122,7 @@ static int rt_restore_ucontext(CPUNios2State *env, struct target_ucontext *uc, __get_user(env->regs[R_GP], &gregs[25]); /* Not really necessary no user settable bits */ __get_user(temp, &gregs[26]); - __get_user(env->regs[R_EA], &gregs[27]); + __get_user(env->regs[R_PC], &gregs[27]); __get_user(env->regs[R_RA], &gregs[23]); __get_user(env->regs[R_SP], &gregs[28]); @@ -181,7 +181,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, env->regs[4] = sig; env->regs[5] = frame_addr + offsetof(struct target_rt_sigframe, info); env->regs[6] = frame_addr + offsetof(struct target_rt_sigframe, uc); - env->regs[R_EA] = ka->_sa_handler; + env->regs[R_PC] = ka->_sa_handler; unlock_user_struct(frame, frame_addr, 1); } From patchwork Tue Dec 21 02:50:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 526591 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4677689imb; Mon, 20 Dec 2021 18:59:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGkZux+U9jruV/Gaca2S4j8yFMslgzlCCSigUqtw1oTPFd6Zj4wHPerIcOOvbzRJdds+G6 X-Received: by 2002:a25:8505:: with SMTP id w5mr1838847ybk.570.1640055544764; Mon, 20 Dec 2021 18:59:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640055544; cv=none; d=google.com; s=arc-20160816; b=SgXgkV2tM95Zd4WIJu5w6Z8RL05FLjejcNGXtiS1LSwBC+m0VQc4FVnBhkkID6iPFW uJA52sCKzo/57hFS1uckZXA3H5IPr3gfbf9iv32ByjXMX+JYcpsvG2JBD1ody83W2Xjr S7i1M4EJRnOwntAPwfgAqDSy/JRzF2Ss4VZ6SUJVGVeyTk2cqETCt6FHBUBYlqyJvifl 0fUhEA2PUHXoevCHWrYC7xUQSlyLHBJUVX1uePw8PZvJmvq/M3sVQCRSlXeD7m9TUX1x +0IOSdI6NiOwMgz7a4Bx0Fp2wKwfYisyw+ztIAvsP3Sc39fEZ28UV4ogFldm91/5f7Ja KaYw== 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=iHsxRB8KyaG7WhuzCtkZtRVF4Ccf8PekyBx+hSykVAQ=; b=ByyAF/KOK7ul/T3Cx7H+tCpEqYyD0aI2HkFkYpGqyOQchaI0Lx0ETMkuP//LKRRXyt 9HNqv1TibUNPh7LsM6aU2FSdH0YgDeFdg4TkeAeYGOT+JUbdhxkyR+S8sKXI2pihGVg9 GRjjOnvZpgOzL6GXkDW7G7jxL25sCNYm2vIdALhdmmDirGgvYxE3l50VbQWPhEZn6//W CBlABcJYrXzEoYd/xhC4KsQX2cly5s0Ot/+mWCB2Ef9HKxMqPcreyoKCFOiDwRhSxVD5 NRp6/nbVSnVm+rm2ctX+8B8wc8mD7R9pnPA61edo59W5WFZFADrbXK4QGEjwLvVqSKw+ whcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rqalFPFk; 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 x6si32865365ybt.119.2021.12.20.18.59.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Dec 2021 18:59:04 -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=rqalFPFk; 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]:33238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzVMm-00067e-BE for patch@linaro.org; Mon, 20 Dec 2021 21:59:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzVEM-0003j6-Mf for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:22 -0500 Received: from [2607:f8b0:4864:20::1029] (port=43565 helo=mail-pj1-x1029.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzVEL-0000Cd-0z for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:22 -0500 Received: by mail-pj1-x1029.google.com with SMTP id a11-20020a17090a854b00b001b11aae38d6so1817611pjw.2 for ; Mon, 20 Dec 2021 18:50:20 -0800 (PST) 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=iHsxRB8KyaG7WhuzCtkZtRVF4Ccf8PekyBx+hSykVAQ=; b=rqalFPFkC7D6+9XeYByvlxdC413CYAZRlevg4Jbw3i3urdreKeqZwN4TWMEcQyTZfa ulvpXxBwyi2aJHbZsK1kE5f3VNrVVac2x6tVI6kCBA85drwa7aRxI8M4kWwbSQZ8KRHZ a2aKvrOZbzG7mhwLeWdhv1bK6khOydQJYuX8CWg9oUGUWAmwErt6ytQTRDmDeYRRJH7V Qx14bXB+q/YPVw7uZsEeHTxKGNyLfaQ9Q7tSZ+QLVb2O1NYqwG8p5HaI7cw9/HeN+/fr DgVLi5/WXMW519wM0cSl2dFX9GAmfNw3DzCr3ueehTcZ04y/pf/Qk4EF5ih2nFatTz7k UZjQ== 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=iHsxRB8KyaG7WhuzCtkZtRVF4Ccf8PekyBx+hSykVAQ=; b=N5aij3X96hWGrWCjZmK3BpEJhFuQ6w4F8zUl7TLGBSZNA7UsCYODyh3orPlLTYwYNI BAuLuEqBuAKBPgzBXsdE1fr85LutBYJhyLG/kb8BbjbIEqY1iDGulUOmexXW9k7Fyw74 0sjvgI9wm6MlP2yf4JK3IJeK3TpCbST7WipKPNnz8bOrYQcn2Tcj/acI0TMoZj2IuyJ6 8Y+Pv3IZofRs9+UsIRvd/dV3pl/XeLm1j5oInsfQ+5HFqMH1unEZHcr8VuHQSs03BTW9 o+54NcecHY8kNwZyUcx2nswLxN6yq0raocALAZL+GmySA/7lQ3Lxs2eC/IXD+zpRy90t PHTw== X-Gm-Message-State: AOAM5323iALJNlRYgpYqbICia4i7ytnmQPvuo0+fx3qr7z85Xaf04Az/ CPNGy+/aqBoKLjc+Q4zOv8XH8IhppmUJ0Q== X-Received: by 2002:a17:90b:1c0b:: with SMTP id oc11mr1349168pjb.174.1640055019680; Mon, 20 Dec 2021 18:50:19 -0800 (PST) Received: from localhost.localdomain ([156.19.246.20]) by smtp.gmail.com with ESMTPSA id bg23sm694025pjb.24.2021.12.20.18.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 18:50:19 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 6/7] linux-user/nios2: Fix sigmask in setup_rt_frame Date: Mon, 20 Dec 2021 18:50:11 -0800 Message-Id: <20211221025012.1057923-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221025012.1057923-1-richard.henderson@linaro.org> References: <20211221025012.1057923-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1029 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Do not cast the signal mask elements; trust __put_user. Reviewed-by: Laurent Vivier Signed-off-by: Richard Henderson --- linux-user/nios2/signal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c index 20b65aa06e..80e3d42fc9 100644 --- a/linux-user/nios2/signal.c +++ b/linux-user/nios2/signal.c @@ -168,8 +168,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, target_save_altstack(&frame->uc.tuc_stack, env); rt_setup_ucontext(&frame->uc, env); for (i = 0; i < TARGET_NSIG_WORDS; i++) { - __put_user((abi_ulong)set->sig[i], - (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]); + __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]); } /* Set up to return from userspace; jump to fixed address sigreturn From patchwork Tue Dec 21 02:50:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 526589 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4676099imb; Mon, 20 Dec 2021 18:56:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwafSg08gjivITMgWK4E/sqSIAlfksBp3CtF2+6VFHeHilgMHiF4CS8EbGT8+cFqOQpusJo X-Received: by 2002:a25:fc5:: with SMTP id 188mr1668336ybp.608.1640055364969; Mon, 20 Dec 2021 18:56:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640055364; cv=none; d=google.com; s=arc-20160816; b=1HxLT9Rw/MgiLaX1Z20lrOi5mz213JplT2Lls36OJJucQZBygeys4YspnSbQq2bLMJ AhbTVz6ghqItaxinaPzKqVPy7JViXvcQe4TRQBLWjZRzhZfnJ9eoeytpvgD5V0RFQ1No GGd/hW+BONoL5xtGeaij5qIhcIP58vy8fkm05pTIrKUyIBRSAXacuBWF4Utl8Jx3bl1E fZnbw8Jolehm6NmPghrpDMLjGo2hT0yQlfvA3XhxX454unXiLpB0KxNw8AfhgDnBM6bg J5hSD+9d7/1HmXkKbg10hYW25eCmdLp6BM9S0xSwBBs+f9JvNewu6YPeA48zoSbbQ+HB 4nDQ== 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=isjT3VM0fssSgBZyBVG7BinpIcaowlRssp8BNfIngDU=; b=q/rYKWtcqPbHr3Z3kbLydnpnUJlTMbI/OdhvFC7dbPfbZIWoozYnwiWVIGFRTRh3Rd d5eYQBQob70AGYjutEKRVVDD3ZKzGPy7yn/WIsEZuS2EJOIeYeKNkCjo/FfEbN2XxkOS B1ZmiSBuIP6itdgv+g/SViUmsodLQZZZMfUExXgONj1Sa8nnwRa+mpsb6OR0kWvYE8NH 8TazfsD7TfZnXTiApKrM4UP24s+Vz0QDEK0EdYyjwvUHAxQTeW7ancKZ20NMQ59I8yYq Xvuv0mrUxvB1JLq8unv59zi1u356k6DzgxeHaU3rRNdnn9aCiZl42RAbDebVhH5w0iSZ NIjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qEMK4bV0; 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 r13si21744327ybk.372.2021.12.20.18.56.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Dec 2021 18:56:04 -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=qEMK4bV0; 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]:57028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzVJs-0002vH-FI for patch@linaro.org; Mon, 20 Dec 2021 21:56:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzVEN-0003m6-KV for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:23 -0500 Received: from [2607:f8b0:4864:20::529] (port=37648 helo=mail-pg1-x529.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzVEL-0000DQ-UV for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:23 -0500 Received: by mail-pg1-x529.google.com with SMTP id a23so11037162pgm.4 for ; Mon, 20 Dec 2021 18:50:21 -0800 (PST) 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=isjT3VM0fssSgBZyBVG7BinpIcaowlRssp8BNfIngDU=; b=qEMK4bV0Ey3Oi/KzFEFwGRoC/Mg1tbvFb81ieKvcru8GgS8qARGWfLjChBna+mnzdk QhvK1qYQQt0Uwt/M1BJHXAoMTOzlHNAyIds+4WbQ6C0tC6QOPqFA6ihEVBJ3CXm0fj93 FJ6Fv37Rq9nsIfYXvN6cWrJWcH9A1Q9kEDzULB0yRP5BQornIe0FvL/xNxBnWpPskgFv hRWtw1BFm+1sXF+5orQum6eb44NH1OBbPNEFtk0NexNinpkF/YHxFFGEofkp91YoQQoN uHTbaLOS7efryPOofcHkl1q2dos/KGdrAR1qMarSPR8lF06iBy5YOo29kg6DeaQM6b8+ vv4Q== 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=isjT3VM0fssSgBZyBVG7BinpIcaowlRssp8BNfIngDU=; b=2j7yqlgK3BL4IzSOIDeWa6fqD7vEqM4ZU4/NlbWtHf5nf6Y7WWWA8ZzxG4WtKa5uIB a9itzcxYW03FiRwMS2EvSlcFkBjLpuyvx80raLfg1IjzHnKtzTAstUBH3UR06SqQRsbc xAU9yeZWvwCSSdByZAws+W7DzFVZjzzKqWDj182eZ01atsIgLiqm/l5ZWkeMrP+quUD0 Rb0rFv1Wp8OnMDQoBpycIdOYBmJXpv3PjHpv/yK7zWyR6QMf+z6mPbqsDA7N6rG4w8WA 6qGw+rvamVbscxAEpfnetvn5X75rCSNn70fxSvYrQMGc2INq44Ynu3RMJZbeoLI3ajQH Zgtw== X-Gm-Message-State: AOAM530TqTebOkH5L0jp+U/svwRDse+aeM3joOqdlIMwO9QzMPcOehik kgHsadzC3grD9YqJceLuSlFw998SoggmJw== X-Received: by 2002:a63:8448:: with SMTP id k69mr1044271pgd.268.1640055020610; Mon, 20 Dec 2021 18:50:20 -0800 (PST) Received: from localhost.localdomain ([156.19.246.20]) by smtp.gmail.com with ESMTPSA id bg23sm694025pjb.24.2021.12.20.18.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 18:50:20 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 7/7] linux-user/nios2: Use set_sigmask in do_rt_sigreturn Date: Mon, 20 Dec 2021 18:50:12 -0800 Message-Id: <20211221025012.1057923-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221025012.1057923-1-richard.henderson@linaro.org> References: <20211221025012.1057923-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::529 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Using do_sigprocmask directly was incorrect, as it will leave the signal blocked by the outer layers of linux-user. Reviewed-by: Laurent Vivier Signed-off-by: Richard Henderson --- linux-user/nios2/signal.c | 2 +- linux-user/signal.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c index 80e3d42fc9..517cd39270 100644 --- a/linux-user/nios2/signal.c +++ b/linux-user/nios2/signal.c @@ -205,7 +205,7 @@ long do_rt_sigreturn(CPUNios2State *env) } target_to_host_sigset(&set, &frame->uc.tuc_sigmask); - do_sigprocmask(SIG_SETMASK, &set, NULL); + set_sigmask(&set); if (rt_restore_ucontext(env, &frame->uc, &rval)) { goto badframe; diff --git a/linux-user/signal.c b/linux-user/signal.c index 6d5e5b698c..8cb33a351c 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -258,7 +258,6 @@ int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset) return 0; } -#if !defined(TARGET_NIOS2) /* Just set the guest's signal mask to the specified value; the * caller is assumed to have called block_signals() already. */ @@ -268,7 +267,6 @@ void set_sigmask(const sigset_t *set) ts->signal_mask = *set; } -#endif /* sigaltstack management */