Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp141241iob; Tue, 17 May 2022 21:38:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybeXlVEnE4xsRr4atS+HgkuxvUxP5eDRc3xgW2N8EjvJ+9HxYt7K/H4mfXSioU9nXZ6mOv X-Received: by 2002:a63:554c:0:b0:3f2:5a25:c20a with SMTP id f12-20020a63554c000000b003f25a25c20amr14205313pgm.453.1652848695360; Tue, 17 May 2022 21:38:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652848695; cv=none; d=google.com; s=arc-20160816; b=o3gvbhPMWCoRySMTBK1Zfi2UNRrEhIHTE/pGJnjlEahh+mNiMAdSPUjI/npkdaXDxz qLe/JwqYaBxnXgvkk7ivysv1hjYfcoKMj3dp+fjcgZaeenKOOzIIA99MVRHIKF6EqcV2 k6KELiCeb0SwexS4Xxn2QUm/ukiWM8ww7m6TnIxr89buprwNNf8DmgXncavJB5ZNYqoI 1Hs+kgh+kG4uXkmjJ1Tfug65xxBa5Oh7jQJAjahB/lTFr5l7tQiOWsQ0GG56ESUjNUa6 T5XvTFzIIU0QgzZkWrsw0j9t1vFScJjRqONnWa/wZvkopxEYNkkMf1e6lOiPdMQ+ADYI wB5Q== 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=EM5RWvyh6QKuoU3X77fGhLivSZmPpUopnFBI2UaPSjs=; b=j1KMMG4FAFZ10ZJegpWpKJIqUlttQLk2aFSYEYIeQSU+6m2Gzx0MTTFKw2i1O7Vo1N gsuNVHmgym3ydBj2bX1mwqpgiqV74Z3D/XtXsUghsBtcS5cIj1HTAahAhY9LERDCcZ+p 0o0n/ZVPAfocqMNTXoQn9ReZo6HtpjmBA36i9pnPIoI5xvZxG1drPmjPeDy3IFZ9glZr ZGqcAYka4u+YPElfldzjoeG4mmKOGlhay6hajR9i9wqfPs09nj2sbPDnEvELzH0fYMPy YLo+ldO999fkHNA6g1gK2JYGY0i9s0Fup2Lw83yDS+m/qez25ypGBSofNClSCms9utfG Gcdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Pletk8uN; 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 d19-20020a630e13000000b003c2777712d8si1235216pgl.468.2022.05.17.21.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 21:38:15 -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=Pletk8uN; 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 B0E36D681F; Tue, 17 May 2022 20:55:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343546AbiEQKqN (ORCPT + 99 others); Tue, 17 May 2022 06:46:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344576AbiEQKpN (ORCPT ); Tue, 17 May 2022 06:45:13 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3258232ED9 for ; Tue, 17 May 2022 03:45:12 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id m62so10181588wme.5 for ; Tue, 17 May 2022 03:45:12 -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=EM5RWvyh6QKuoU3X77fGhLivSZmPpUopnFBI2UaPSjs=; b=Pletk8uN1upMYIKNyvE8fT6x9oXX6zwAKVAbwgCAd3WGicm3ledePiiOA5CvpU7QP3 kzOiILDY17dYgt32foZUYZglLwIp5TymoxwAMaVW1Q8C5LZthjlbC9ydChlk4lmWsRLC nC6/Zjx25bh74u+Ya2x0gMkH71ly9QM0RPbdVC0cuAJxpXto4nSz2f2BwXRy1edPOZqP UFZY6MFRCo/qis9bRsIZVP1ao2GP0d+Hj0K840hrjTUoEzbgMNjI1atJ/GFrmE0e1VbO 2IrQZKqgX5EG6vyYUOfq+uR3J8bUkCdf1vtgU8EGoj8EJNuRLgRUe9ytqgwWEVSA+nPj tGqg== 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=EM5RWvyh6QKuoU3X77fGhLivSZmPpUopnFBI2UaPSjs=; b=t2Me96tSlqNaNALQ/w4Vt6oplJpAvQKrkn1UJEvkBKnq+yUv1Jnb5U2FCszNUfPkSH wS4ZWUWBQZ2Ids53+rCdvBA1lCjjEp/1SbJ29pB2h8QkdE4YXbJULQDN9ivBXUqBqkEB s/3WUmvnngj6FmWHrcaJI2DhnOm4nlFEFct4GpOv5rZlJjLKp9pWgTJ+ECbz8kbPXjkw ZeS8T+U1+6fNtBSZgw0YNNLC8t23CSCWRZFNabAdHT+QLjLck96C6TyYwpOuPielLhng NGevUEao1BHq3ExoHVgO2wPj+gbLQawdjnCB6WTvgcxj8nsNYC2vZ8XvhtbTRZfl8o8v 5nGw== X-Gm-Message-State: AOAM533j0/T4sRPwKPbuBZ+EkKMjuwgCZk7udR+rv/tvS9GXrfHtoMHy YDedTEqJClyZMBcEnLnNRdjcuWm5CJU= X-Received: by 2002:a05:600c:3d89:b0:397:104:b1c9 with SMTP id bi9-20020a05600c3d8900b003970104b1c9mr10768763wmb.84.1652784310841; Tue, 17 May 2022 03:45:10 -0700 (PDT) Received: from octofox.metropolis ([178.134.210.144]) by smtp.gmail.com with ESMTPSA id r5-20020adfbb05000000b0020d00174eabsm8612218wrg.94.2022.05.17.03.45.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 03:45:10 -0700 (PDT) From: Max Filippov To: linux-xtensa@linux-xtensa.org Cc: Chris Zankel , linux-kernel@vger.kernel.org, Max Filippov Subject: [PATCH v3 2/3] xtensa: support artificial division by 0 exception Date: Tue, 17 May 2022 03:44:57 -0700 Message-Id: <20220517104458.257799-3-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220517104458.257799-1-jcmvbkbc@gmail.com> References: <20220517104458.257799-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 On xtensa cores wihout hardware division option division support functions from libgcc react to division by 0 attempt by executing illegal instruction followed by the characters 'DIV0'. Recognize this pattern in illegal instruction exception handler and convert it to division by 0. Signed-off-by: Max Filippov --- Changes v2->v3: - simplify check_div0 by dropping check for the specific illegal instruction and only verifying the 'DIV0' signature Changes v1->v2: - split ABI probing improvement from the artificial division by 0 - don't limit artificial division by 0 pattern detection to configurations without HW division opcodes, do it always arch/xtensa/kernel/traps.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/xtensa/kernel/traps.c b/arch/xtensa/kernel/traps.c index 24d11b44fa57..2b75b252b626 100644 --- a/arch/xtensa/kernel/traps.c +++ b/arch/xtensa/kernel/traps.c @@ -293,12 +293,35 @@ static void do_interrupt(struct pt_regs *regs) set_irq_regs(old_regs); } +static bool check_div0(struct pt_regs *regs) +{ + static const u8 pattern[] = {'D', 'I', 'V', '0'}; + const u8 *p; + u8 buf[5]; + + if (user_mode(regs)) { + if (copy_from_user(buf, (void __user *)regs->pc + 2, 5)) + return 0; + p = buf; + } else { + p = (const u8 *)regs->pc + 2; + } + + return memcmp(p, pattern, sizeof(pattern)) == 0 || + memcmp(p + 1, pattern, sizeof(pattern)) == 0; +} + /* * Illegal instruction. Fatal if in kernel space. */ static void do_illegal_instruction(struct pt_regs *regs) { + if (check_div0(regs)) { + do_div0(regs); + return; + } + __die_if_kernel("Illegal instruction in kernel", regs, SIGKILL); /* If in user mode, send SIGILL signal to current process. */ -- 2.30.2