From patchwork Wed Oct 13 02:45:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 515678 Delivered-To: patch@linaro.org Received: by 2002:ac0:b5cc:0:0:0:0:0 with SMTP id x12csp6081583ime; Tue, 12 Oct 2021 19:51:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtCHXQOJPCdnzSpvsOVzRMwuETCXTfUCGp5SMHJNTY0fxu20fWA+RQHOR+AAIGXOVffbbJ X-Received: by 2002:a05:6214:628:: with SMTP id a8mr21961722qvx.21.1634093516381; Tue, 12 Oct 2021 19:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634093516; cv=none; d=google.com; s=arc-20160816; b=tuQPbwmLS+ewHD2oYn36Xy9Antx1cfFzalxvITN43ZUh/oD9RYVKbdgLuRkXcKatWy 4Z4175GvjeLmiD7LBSPvN6W0yO0HYaq+i/J/iRV429WpunqKGWxjGKLyoZZs1qrANn74 1KNewJs9NCNuvtdsBdeZwFKSG/ZhAPo7WkdMuGo8inDtp04ofQnr6u6JLi53sGE+csbN HGVM0WK4/oyXhNne6vXcuZ3eiELXzmEMwnoKJPnjNzV9oRHX6/p6byPZUyMeG5yQIyEQ bAbKZNwJOIia/hjVEBo1z+P87KXa1AD+dWQSw44w9sL1SFQTpg5ukqsYxrs6lwvyJv71 yoRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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:to:from :dkim-signature; bh=67r73sMxmFAFlBR0ViNOs8odKIpwZUQrX4e2focSvME=; b=dR5VDrgKByWhyUfX41f+42H8nkCgxVCCTuDFOesuy+6OwA8Z8mPUrCY4UqAuFcaHSi 2+smoZ4lu0pA+7uslpYZK253zH5wZHg/ohY98LJlGAuc1TqEdi78gh0GNdE/03jhA5Mv cN9QFxj3T0Y+pRGdQ2SRVbKKbhy1B8jteQ2clBfMYzxVlhP94DOQzpcjLKZovMNnLMgJ 0Up02SFFfMp3D6L60kqNM4SyeKF3CmwqHvZsQbFGaz3ueEsoPABj1IVv7Ao60NPS0YWP ZEwGbhB7NMjvm3otENSbyZN7DuKeMnxIWr3E9oidFIUATfSqEXVjFpl4ru5cb5Xp4iIK yDEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NQbkrqfs; 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 t21si9583255qkj.109.2021.10.12.19.51.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Oct 2021 19:51:56 -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=pass header.i=@linaro.org header.s=google header.b=NQbkrqfs; 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]:57470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1maUN1-0007Nh-TP for patch@linaro.org; Tue, 12 Oct 2021 22:51:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maUHY-00047b-Ql for qemu-devel@nongnu.org; Tue, 12 Oct 2021 22:46:16 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:40831) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1maUHV-0004iu-9V for qemu-devel@nongnu.org; Tue, 12 Oct 2021 22:46:16 -0400 Received: by mail-pg1-x536.google.com with SMTP id q5so880124pgr.7 for ; Tue, 12 Oct 2021 19:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=67r73sMxmFAFlBR0ViNOs8odKIpwZUQrX4e2focSvME=; b=NQbkrqfs0egp/cKGs4184FmagjnKIjA+4rI0Wpp55mzG0OycYcQ76V2fStyNyhsm/Y CixQhytSUYd2axE9lxCx61G4k96vi064v3Fbg+nVjB1pbKgaQcvJ+LUpdiayXGZ8yJDW ToNa76tWTHnPwA3M0dtX7bJ34VLcpteznj92sQN1Y9tGZrDvnCB4yaYgsWAjqTGZZK6A op3y9daij33C62Y1DKecuyybVS0pUMkWPya+7BaFNqD9zdC0j1b3bSgyKUMYYMmVh+1J acjndy/nUznqAjcodELPaXfD3tnGmeNB5/MlSYkFptLGwghGqMeRvbS4O7DLR4FedxRZ Eckw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=67r73sMxmFAFlBR0ViNOs8odKIpwZUQrX4e2focSvME=; b=WULtpRExxYS0GYBwhQekCAVN0fuKBdU1aY8DMFZy+w0O3IYBiW0w99UhmCc6AEDH3G h8TOQMRgFswTtqN8/7x4VikPPVTKAdW496XL8817tGOGJ8wnOQoGI0FvzHGCSXxzrEq1 XrdftnLJ6BKLGT8H+695kbcSrCFq9fZgTS8IJsk06WkLqYDryD12rzCu9C2ZQvHW/kwD KRQ4tdvvV8yEQWfOy2qVfZFmT31SNYqLIw28W3gT9AfS/d7vA1fbFBJF4wF/765TnnZW 2NLVpnQvEw2ONsOB+VDEJQY0j7KyoYj+SENotDIdY4XlektMtF0fUPB6MLZcsZns+8xJ eJrg== X-Gm-Message-State: AOAM530x79RSZqnzDHKQGVr4ulNbTZ3kRDVoTbgPeIUzVM2bx9c/zMX3 tjNcBd7CT7ZsAXW+4Oq6DlFkRO5eCZZ0hA== X-Received: by 2002:a63:d34f:: with SMTP id u15mr25585438pgi.200.1634093171930; Tue, 12 Oct 2021 19:46:11 -0700 (PDT) Received: from localhost.localdomain ([71.212.134.125]) by smtp.gmail.com with ESMTPSA id qe17sm4855014pjb.39.2021.10.12.19.46.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 19:46:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 02/48] linux-user: Add cpu_loop_exit_sigbus Date: Tue, 12 Oct 2021 19:45:21 -0700 Message-Id: <20211013024607.731881-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211013024607.731881-1-richard.henderson@linaro.org> References: <20211013024607.731881-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.google.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) 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.23 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" This is a new interface to be provided by the os emulator for raising SIGBUS on fault. Use the new record_sigbus target hook. Signed-off-by: Richard Henderson --- include/exec/exec-all.h | 14 ++++++++++++++ linux-user/signal.c | 14 ++++++++++++++ 2 files changed, 28 insertions(+) -- 2.25.1 diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index f74578500c..6bb2a0f7ec 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -700,6 +700,20 @@ void QEMU_NORETURN cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr, MMUAccessType access_type, bool maperr, uintptr_t ra); +/** + * cpu_loop_exit_sigbus: + * @cpu: the cpu context + * @addr: the guest address of the alignment fault + * @access_type: access was read/write/execute + * @ra: host pc for unwinding + * + * Use the TCGCPUOps hook to record cpu state, do guest operating system + * specific things to raise SIGBUS, and jump to the main cpu loop. + */ +void QEMU_NORETURN cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, + MMUAccessType access_type, + uintptr_t ra); + #else static inline void mmap_lock(void) {} static inline void mmap_unlock(void) {} diff --git a/linux-user/signal.c b/linux-user/signal.c index 9d60abc038..df2c8678d0 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -706,6 +706,20 @@ void cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr, cpu_loop_exit_restore(cpu, ra); } +void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, + MMUAccessType access_type, uintptr_t ra) +{ + const struct TCGCPUOps *tcg_ops = CPU_GET_CLASS(cpu)->tcg_ops; + + if (tcg_ops->record_sigbus) { + tcg_ops->record_sigbus(cpu, addr, access_type, ra); + } + + force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, addr); + cpu->exception_index = EXCP_INTERRUPT; + cpu_loop_exit_restore(cpu, ra); +} + /* abort execution with signal */ static void QEMU_NORETURN dump_core_and_abort(int target_sig) {