From patchwork Tue Sep 26 15:03:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13399310 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6AD2AE7E649 for ; Tue, 26 Sep 2023 15:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=W6lN1RFFFGlRSPbxTMoIHe6DN8upixj/kmXPvBYxV+k=; b=KjgsDQI2tirDcQ akfFN55nCAMSYR55O43HwnVEr/IipLJuo7S2VVjINdTguMCPcECGfvIXLRJaRaaMhAiTeO/z9cNAs rRWWC+Tmwn2tAOEaWTjxTYWT00Nvi7qbOXDZQ6UsH+cfX12hq3K7SLwZeLzENN6Z3nbKW6IbkEUf6 QSDa6CZLqXlPCvGMnYgSWpHImfh1gtJC1Zx9sG75pG7yq/nCP27+Gizdj+ub45369Z+u+RCzxbSWB Xba0x6ugbustm8nOW7tSGm6isXDzT6mBzL3fTvVYBHac+U/osg1+MmMafqA8VKKXzgz6vgUu5S8nz SC2mfBbISjENbttqHFKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ql9bT-00GbLg-1F; Tue, 26 Sep 2023 15:03:59 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ql9bQ-00GbJ9-0h for linux-riscv@lists.infradead.org; Tue, 26 Sep 2023 15:03:58 +0000 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40471c054f9so26828585e9.0 for ; Tue, 26 Sep 2023 08:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1695740632; x=1696345432; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RIpK3OqmG3E1OUm0KgMySKOtKP9RNzbuGFCeuFimfhg=; b=aWhZJ7n/QugXxarqK96UuFcs9yYTiHHzzRkC1aNq599GdltVOTf7GeA2ndJy2WVi9k +dzjJocEOy5bDn/F1srAfjKueoJDr8s30hgtJlh/pxzNNrQzxBkhkNOibaNWckpfzNLK WSA2HX7F/jTPkkBTudbLyj1Aw74m8je5C0AS0Enxb9LgQ0zOwCIz02tstJ0ntAPmzGfu TwJZ12QuQP+g1CV+wGqD50Sqcnvr7L1SQ+Gdml8OgRsn6Rsq/PmJmgw/F7QscMSEGnzg 8BU0S8H0q7qcVRJ/Kui6+SKWHiBDbwvL6CqZKsozxNFeuzwFuzcp5rgDm7ePsdfhud5N /OsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695740632; x=1696345432; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RIpK3OqmG3E1OUm0KgMySKOtKP9RNzbuGFCeuFimfhg=; b=eMc06j4Mc+if3fTMveb+a/EiQo8kIfAcZkryH0g31+KdVpA+kKk7ObBj57AL8rpHrf y28lhlorC59W4ke2TCEwslNzBD29oerwbGSZ65D8ZnQjO7GscazNtYAjzaomvvAPDXFN XqEENTA5HmEM+nUMBmYFU2IKJ5ZSwkfXTfxi+JmjZ3Y+CtuJy3RboE3DRTCjIKMSiDkI oxvEbsoxtP/5vsW9mzDaSMfv5Ev/Jfu9Pxou1z2QET3ytgSvKAe6VzE3l83puOGeZVlX R8pSGphsPX1J2ITji9J+n+8edf2/g/55/qxWtR4M2+zH2hXJ7d7suVtDmdhXIcho96f3 chpw== X-Gm-Message-State: AOJu0Yy8+CbOZ/3NQKzMMUg/ENSevJ8kWoNA0KRoZhVBtx37i/Rn0Cii SetHPSSY2rDSXGYot7ZAQpxhjA== X-Google-Smtp-Source: AGHT+IFNTxn3ZjlQ5+Jtwf6UwRV/FhwgHLgxdXUERSMM8USfscRNhwx3BHgmb3Lm8sPO6lia6aTOAA== X-Received: by 2002:a05:600c:1d82:b0:401:c07f:72bd with SMTP id p2-20020a05600c1d8200b00401c07f72bdmr8988881wms.4.1695740631744; Tue, 26 Sep 2023 08:03:51 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:2b3d:6c70:9dbf:5ede]) by smtp.gmail.com with ESMTPSA id x11-20020a5d650b000000b00318147fd2d3sm14926060wru.41.2023.09.26.08.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 08:03:51 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra , Andrew Jones , Evan Green , =?utf-8?q?Bj=C3=B6rn_Topel?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Ron Minnich , Daniel Maslowski Subject: [PATCH 0/7] Add support to handle misaligned accesses in S-mode Date: Tue, 26 Sep 2023 17:03:09 +0200 Message-Id: <20230926150316.1129648-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230926_080356_491464_65A52415 X-CRM114-Status: GOOD ( 13.27 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Since commit 61cadb9 ("Provide new description of misaligned load/store behavior compatible with privileged architecture.") in the RISC-V ISA manual, it is stated that misaligned load/store might not be supported. However, the RISC-V kernel uABI describes that misaligned accesses are supported. In order to support that, this series adds support for S-mode handling of misaligned accesses as well support for prctl(PR_UNALIGN). Handling misaligned access in kernel allows for a finer grain control of the misaligned accesses behavior, and thanks to the prctl call, can allow disabling misaligned access emulation to generate SIGBUS. User space can then optimize its software by removing such access based on SIGBUS generation. Currently, this series is useful for people that uses a SBI that does not handled misaligned traps. In a near future, this series will make use a SBI extension [1] allowing to request delegation of the misaligned load/store traps to the S-mode software. This extension has been submitted for review to the riscv tech-prs group. An OpenSBI implementation for this spec is available at [2]. This series can be tested using the spike simulator [3] and an openSBI version [4] which allows to always delegate misaligned load/store to S-mode. [1] https://lists.riscv.org/g/tech-prs/message/540 [2] https://github.com/rivosinc/opensbi/tree/dev/cleger/fw_feature_upstream [3] https://github.com/riscv-software-src/riscv-isa-sim [4] https://github.com/rivosinc/opensbi/tree/dev/cleger/no_misaligned Clément Léger (7): riscv: remove unused functions in traps_misaligned.c riscv: add support for misaligned handling in S-mode riscv: report perf event for misaligned fault riscv: add floating point insn support to misaligned access emulation riscv: add support for sysctl unaligned_enabled control riscv: report misaligned accesses emulation to hwprobe riscv: add support for PR_SET_UNALIGN and PR_GET_UNALIGN arch/riscv/Kconfig | 1 + arch/riscv/include/asm/cpufeature.h | 6 + arch/riscv/include/asm/entry-common.h | 3 + arch/riscv/include/asm/processor.h | 9 + arch/riscv/kernel/Makefile | 2 +- arch/riscv/kernel/cpufeature.c | 6 +- arch/riscv/kernel/fpu.S | 117 ++++++++ arch/riscv/kernel/process.c | 18 ++ arch/riscv/kernel/setup.c | 1 + arch/riscv/kernel/traps.c | 9 - arch/riscv/kernel/traps_misaligned.c | 374 ++++++++++++++++++++++---- 11 files changed, 488 insertions(+), 58 deletions(-)