Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1070660iob; Fri, 13 May 2022 21:59:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJf887FY8IEeRb8SWhoaEyvl4Grb4bp3k5xEcOwr9p0bbY/TDtaUC1IA3+clYoyQZ2Dv6f X-Received: by 2002:a05:600c:1c95:b0:394:709f:a0db with SMTP id k21-20020a05600c1c9500b00394709fa0dbmr7511412wms.82.1652504366493; Fri, 13 May 2022 21:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652504366; cv=none; d=google.com; s=arc-20160816; b=DWo4k1c+DDDyIjngaKebxoIFHBpQIb0uU7HNurKgpjdB7IkfYs1xb8jSO41EibKja+ zG4Lukql+vgLlE3UoaOV2dxJtQ2F6C24VpDyqTi5+uqMLqEUaAW3I2Aph5VVnwsrl1Uy 8p3paW6SYhIjinoPnffW45uM9uwpMsAkReufEoLAxwkEadP5dGWXthhKVwhPpf/gDVo7 td9i3aF1v38YGpu0Mb53VCsVBsBKmvFMwGl5/7P7FXHFRkgeDLLRLCjJC3T0vsxI/o7W fPiah18i9oVLM6AbmMBk6wwueSMIY4yYmcJY8nuReobCRb8Md1svGXzNIXcpgRTXbv0c hTxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LbqWA0ma3Gj0jvWCSxtRNJBD3Bf6tu8RmToQD/S/1tA=; b=YcdpjtK05FVC4GzypCTn7eBb41gwagrSJk7MuFIhn2xnmPPq5QRsWUq105yksezcni CvbY8L+f75cwYRf/U9WRBuSGYDf5ZMmXBc9b57rQ5CK0edFdbFRxp1bO2PP2bZPCy/4B kLmtJBKWl0eNcy3YsgubPgxIgUtrU5hdd4lOmRHDn1/hSI+WEiWHMvVAFxDJ2tr6I1B+ epR/kKitjzd1xB2Tx5IEoKaovKziCEk1CPJlh/S8GOGL+a6EfnkgeuCdOlIaRlV/zi0r SegcGCpTn8mcS4UVWnH3gjAivHHJlsvRo3Pe93KCxnoY5sEYYYGZlVAd+SrkL4cl7PZl Htkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gtq9z1Gj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b4-20020a05600018a400b00203e9019690si5676800wri.1044.2022.05.13.21.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 21:59:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gtq9z1Gj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 039B7C9EC2; Fri, 13 May 2022 20:35:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231506AbiENDfA (ORCPT + 99 others); Fri, 13 May 2022 23:35:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231383AbiENDe5 (ORCPT ); Fri, 13 May 2022 23:34:57 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC58C93458 for ; Fri, 13 May 2022 20:34:55 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id w4so13546446wrg.12 for ; Fri, 13 May 2022 20:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LbqWA0ma3Gj0jvWCSxtRNJBD3Bf6tu8RmToQD/S/1tA=; b=gtq9z1Gj/PCfH+6jFgOvMnLRXGDONoKZuJaDEtvtAB+Pm/dztH9DvgrU6IAK4GHSvx 2QVOEMjMwI/eT5uc3gxko0aNgtLwRLxBEXKz950r/3llvBuFiuS54qlX3ymMogGVyUaC 6wcgTEom4pnkmhKZ39vK8KU1a7C/3oSZ4r8M61A05BaJLLEILmITjPQaOLc7nFsuywfr cuzbLh8GYTS9+50CUcFm/f953Evh84EpYvwInJlyRBVsB8/U1l2Vz/rrjsh2OlCKsIN+ YLiFJcUe7wVFO5O93J41chW+UnzT8KscgSDdJ5bLFAjA2toRqCggSV8FKgzHoQGfLv/+ 9EhQ== 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=LbqWA0ma3Gj0jvWCSxtRNJBD3Bf6tu8RmToQD/S/1tA=; b=jU99lYWMoK+iAGHVe0kNieJffxzYeVMML/SDvlguVoc1n82UWl8LAtz3lGUPh2enSt M5XYZfVWAKTUJse9zGRLURzQxtEDMTPIupmhZSxx+zMt41xcdP/ZswaSLt0jcnXyXSwk TeJLXygHUqSzlZqL8YqoKVs4fw+pRAjF3HPvfn4H/wZWTbfMSecp204nRKO+dWTWEBEZ TK3lqOGM/qbnmpD8AY8H2MgP/1ZWXnqSY8lXvUVXuxI23vB4iqQEYe6qwB+Fqm8bZQhl 18tQWMEEvHRQiRs+M8YRBpDKbreFbzHy+DpwaxXalIZ3qK35a/k2r1JphsggBreC5v3c diJg== X-Gm-Message-State: AOAM532y2bwJY73WBpoFJHnjkRXNHuMphOXKeXgDJVElYmvAwANILdF0 nKroQ8iA1hlUik3LUuTI6er5MlBT8xGsAQ== X-Received: by 2002:adf:f691:0:b0:20c:d5a4:79f1 with SMTP id v17-20020adff691000000b0020cd5a479f1mr6368906wrp.380.1652499294508; Fri, 13 May 2022 20:34:54 -0700 (PDT) Received: from octofox.metropolis ([178.134.103.46]) by smtp.gmail.com with ESMTPSA id h1-20020adfaa81000000b0020c66310845sm3542638wrc.55.2022.05.13.20.34.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:34:54 -0700 (PDT) From: Max Filippov To: linux-xtensa@linux-xtensa.org Cc: Chris Zankel , linux-kernel@vger.kernel.org, Max Filippov Subject: [PATCH v2 1/3] xtensa: add trap handler for division by zero Date: Fri, 13 May 2022 20:34:35 -0700 Message-Id: <20220514033437.4182899-2-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220514033437.4182899-1-jcmvbkbc@gmail.com> References: <20220514033437.4182899-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, FROM_LOCAL_NOVOWEL,HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add c-level handler for the division by zero exception and kill the task if it was thrown from the kernel space or send SIGFPE otherwise. Signed-off-by: Max Filippov --- arch/xtensa/kernel/traps.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/xtensa/kernel/traps.c b/arch/xtensa/kernel/traps.c index 138a86fbe9d7..24d11b44fa57 100644 --- a/arch/xtensa/kernel/traps.c +++ b/arch/xtensa/kernel/traps.c @@ -49,6 +49,7 @@ */ static void do_illegal_instruction(struct pt_regs *regs); +static void do_div0(struct pt_regs *regs); static void do_interrupt(struct pt_regs *regs); #if XTENSA_FAKE_NMI static void do_nmi(struct pt_regs *regs); @@ -95,7 +96,7 @@ static dispatch_init_table_t __initdata dispatch_init_table[] = { #ifdef SUPPORT_WINDOWED { EXCCAUSE_ALLOCA, USER|KRNL, fast_alloca }, #endif -/* EXCCAUSE_INTEGER_DIVIDE_BY_ZERO unhandled */ +{ EXCCAUSE_INTEGER_DIVIDE_BY_ZERO, 0, do_div0 }, /* EXCCAUSE_PRIVILEGED unhandled */ #if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION #ifdef CONFIG_XTENSA_UNALIGNED_USER @@ -307,6 +308,11 @@ static void do_illegal_instruction(struct pt_regs *regs) force_sig(SIGILL); } +static void do_div0(struct pt_regs *regs) +{ + __die_if_kernel("Unhandled division by 0 in kernel", regs, SIGKILL); + force_sig_fault(SIGFPE, FPE_INTDIV, (void __user *)regs->pc); +} /* * Handle unaligned memory accesses from user space. Kill task. -- 2.30.2