Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3052534rwe; Sun, 16 Apr 2023 10:34:41 -0700 (PDT) X-Google-Smtp-Source: AKy350ZPiUsM+1Ks40tgmKmkCAH5M7hcRu8K6ssiXgeZtOic4watqU25aH6yaPMlxCCux7zOxNXh X-Received: by 2002:a17:90a:c24b:b0:247:40f1:79d7 with SMTP id d11-20020a17090ac24b00b0024740f179d7mr8968856pjx.34.1681666481156; Sun, 16 Apr 2023 10:34:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681666481; cv=none; d=google.com; s=arc-20160816; b=UX+J8dI160n8sxnqDI/UUcu9y7v0kCKDK73L4T1pkgFNfQ267zqtgp/b1ttFFwKbqC u5Jmv06O9CTiO2WHtKuNpLZdN7SKcxc/TyaOl1QBL5wXxSPcmIhXXluRnFK80HT6Td9z VUouISdJnnLoaCk3Evzbw2bLG0zDuCILuiDQCK71V78sVm8HusFzOwmP8aWm2wCs6Mug RPNQTiIWNQmuITZ5W6dRDKoL32oEVGDBSRB2qnmPH/jGY2lthnZdQs2VmPr7HOE2R+VX dUBXIsbIHXbRBNTg3DO1b3t1xZJaUr3kvElNPe3SrQm0gKNqIcyE2PoG6nh8rNuxXqym uOTA== 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=SZ2CLUZlxIzR46IsKGXUZhdpIGgRBcGQEYUp7cKtTaw=; b=hLSMgvRk4ZK8AVCYsPywpIBJ9WAUpH1HGiD3dtgNJ8N3sSg1sH6Q1HCVcbH6K77B78 VvoVKZKuB7q17Y6E3/4WZ11fctnuynmqzR0g0Tu3EC8+bScwCu78DZjPc3zJwa8PHOQ7 wXUssqjEh0NHfu5MoMFLO35LDDtsolcKeBgmqOumUrGdOURWR4G67aZKFkbi+OHFzlAT iGLjCIXnGzxm6com+2qfqdc4RIe5//s7JFa6E0ZA5BwTfDqKXeaQ3y4hRZkfnOUp+bJO TU+gwUho4cnSyzigAtlQhKu1qeEiLjZsFU5aJgxEijsV+41daxoOOx9NX0/11a1V/q7P RTww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=QeUEGgyp; 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 6-20020a630d46000000b004fb8f5e1a8dsi9525650pgn.111.2023.04.16.10.34.29; Sun, 16 Apr 2023 10:34:41 -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=QeUEGgyp; 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 S229647AbjDPReO (ORCPT + 99 others); Sun, 16 Apr 2023 13:34:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229494AbjDPReO (ORCPT ); Sun, 16 Apr 2023 13:34:14 -0400 Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5C80199E; Sun, 16 Apr 2023 10:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1681666435; bh=C3MiRL1+jYzT7/gFD6IpyMpli5bJnPrV9TtMIyTDig0=; h=From:To:Cc:Subject:Date:From; b=QeUEGgypVv4OEKyF6o72zsRqKKb2xLx+r3jI4AiNLXafL4929vXhDtQGx6No9mlFc cGcFRC9F7/EcnqQhbvuLgsmyr2sh8vKhwga8Bsnj4YiRnv6VcnXECOtfo9j9PTfGmD pVfqmjMVGuqDpVi0kKDsGTKFgBs+ZoSNd1q3mPd8= 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 9B0436011C; Mon, 17 Apr 2023 01:33:52 +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 0/2] LoongArch: Make bounds-checking instructions useful Date: Mon, 17 Apr 2023 01:33:24 +0800 Message-Id: <20230416173326.3995295-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 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/include/asm/kdebug.h | 1 + arch/loongarch/kernel/genex.S | 1 + arch/loongarch/kernel/traps.c | 107 ++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) -- 2.40.0