Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3753863rwr; Sat, 22 Apr 2023 11:01:03 -0700 (PDT) X-Google-Smtp-Source: AKy350Y3FnsnNA0vf88T+uM1U5qSlnEj1agl6oyIl9wIR3MaK093KOkOAiZzM6EUF5789i+ZdKjC X-Received: by 2002:a05:6a00:230a:b0:63d:2d6a:47be with SMTP id h10-20020a056a00230a00b0063d2d6a47bemr10661470pfh.2.1682186463417; Sat, 22 Apr 2023 11:01:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682186463; cv=none; d=google.com; s=arc-20160816; b=ZbD2JSzYD6FVGbBQrSe0xCyd5o8fQPORSamJmRrofMWTqLymC2TCMZ3DIZx7NbTs4N pCWmwhDELM2jEATaCfiQM8MRkMwvy5rdSU6FL15+gVh5iFCYzdoU6HWV0yVckhfviZS4 vMgVQF6/xyvD1m9icUcp5rYP2+we1AGkBIqStybSfjGQdGJIsSqV4P1HpFN5lVKFSFXU qh44EK9Ucxg8d3Yqo3M85yb8g7UfTbOcgymAeT0LeSE3/JBHRpQ9WvD+oMsYmaash3N1 rafY6NOsp41ACN5Ti0z/1rf9r8YzLcZ7B1JOFP4ExVhdFSkXb7BCRYP3/vciDHaoHA1w +UbA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=pLky5rq4V+AW4qhVjIAbU1KO+FcyWlwIf2Qw3zFY94Y=; b=Q9anN9KMNnzGJsE+eDmaCq/LRZf8JWP4AOZciaXh13LH5J7cQUBvSrbQELxKobuKLd +bJHQp6+ywMjN1lvoVorVq8ag7CJzkP+7Rjkrpr1wvmO4ZNZnTtdqUl4zCgRvnCA/nJ5 a20F8LfJNiHlXBaYyFA0+dstcbtc128GKjV01Gr6TBJeUicepttjVuH67qlq6TM9JEgJ wkcKOmnCb7iNX4GgMtDCzlWZ9SWKQaAZ2LDtLZfAc5qjFu7Ei3IkoUgjm+EuYGD3hh3t dV2/D73wLi5CK+55zgZdCa3QWKcm6TutxUty6ZYN70gzgomgeP9Ec3taM8kVOrNfAhnN ghmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=Fz3ZgnjO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020aa79611000000b005ee01126a92si7437294pfg.120.2023.04.22.11.00.39; Sat, 22 Apr 2023 11:01:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=Fz3ZgnjO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229697AbjDVR5U (ORCPT + 99 others); Sat, 22 Apr 2023 13:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbjDVR5T (ORCPT ); Sat, 22 Apr 2023 13:57:19 -0400 Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE92C1FF6; Sat, 22 Apr 2023 10:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1682186234; bh=Av45NfRoNWrmwrDlg/7iwNEk5cNcTXe/Apg381TE9cc=; h=From:To:Cc:Subject:Date:From; b=Fz3ZgnjO3hS4PjxTm80vD2yKCWd/OhZHTccXsoeXvyYk49q27YYpqPCX6h087K4Ux bj4CNpZBPvl4ssChpsidAIzxGTTVBAja4Scox2QrJ3FK1GEgM8Yrpd/OIS9fxYINAn b/P1BkV3UjmEJX0MZvlAuB/z7DMNCX704gJA+2NA= Received: from ld50.lan (unknown [101.228.138.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 0F92F600BD; Sun, 23 Apr 2023 01:57:13 +0800 (CST) From: WANG Xuerui To: loongarch@lists.linux.dev Cc: WANG Xuerui , Huacai Chen , Xi Ruoyao , Eric Biederman , Al Viro , Arnd Bergmann , linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 0/2] LoongArch: Make bounds-checking instructions useful Date: Sun, 23 Apr 2023 01:57:03 +0800 Message-Id: <20230422175705.3444561-1-kernel@xen0n.name> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 From: WANG Xuerui Hi, The LoongArch-64 base architecture is capable of performing bounds-checking either before memory accesses or alone, with specialized instructions generating BCEs (bounds-checking error) in case of failed assertions (ISA manual Volume 1, Sections 2.2.6.1 [1] and 2.2.10.3 [2]). This could be useful for managed runtimes, but the exception is not being handled so far, resulting in SIGSYSes in these cases, which is incorrect and warrants a fix in itself. During experimentation, it was discovered that there is already UAPI for expressing such semantics: SIGSEGV with si_code=SEGV_BNDERR. This was originally added for Intel MPX, and there is currently no user (!) after the removal of MPX support a few years ago. Although the semantics is not a 1:1 match to that of LoongArch, still it is better than alternatives such as SIGTRAP or SIGBUS of BUS_OBJERR kind, due to being able to convey both the value that failed assertion and the bound value. This patch series implements just this approach: translating BCEs into SIGSEGVs with si_code=SEGV_BNDERR, si_value set to the offending value, and si_lower and si_upper set to resemble a range with both lower and upper bound while in fact there is only one. The instructions are not currently used anywhere yet in the fledgling LoongArch ecosystem, so it's not very urgent and we could take the time to figure out the best way forward (should SEGV_BNDERR turn out not suitable). [1]: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#bound-check-memory-access-instructions [2]: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_asrtlegt_d Changes since v1: - rebased on top of current loongarch-next - removed code related to the kprobe notifier mechanism WANG Xuerui (2): LoongArch: Add opcodes of bounds-checking instructions LoongArch: Relay BCE exceptions to userland as SIGSEGVs with si_code=SEGV_BNDERR arch/loongarch/include/asm/inst.h | 26 ++++++++ arch/loongarch/kernel/genex.S | 1 + arch/loongarch/kernel/traps.c | 99 +++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) -- 2.40.0