Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp749244lqc; Fri, 8 Mar 2024 10:26:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVcVMZuiQzIhD1S7DD6JLPvtnTrvrEE0ctv5/JAmWcSd7EG0kgFtTcjEqyccq9fHSIbMj0hsxrVngSCW4j5/KQ3Ym176Vp2c3PpLlhD0g== X-Google-Smtp-Source: AGHT+IEaqNC7ItkImPSUzLMSsIeo474a/82g4Qs1QaYcXwJj3jauMtBLQJVSkL2HuigT9AxJA0Ja X-Received: by 2002:a50:9b17:0:b0:564:5150:76a2 with SMTP id o23-20020a509b17000000b00564515076a2mr65735edi.4.1709922377676; Fri, 08 Mar 2024 10:26:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709922377; cv=pass; d=google.com; s=arc-20160816; b=DkAz2NAF033LW5wLzPjT9n/DU0WNNBYf90eAF1vwwZbZQ01atj2Wx+yVwQ+DBVgGZg DW0Apr8Rt5UQutnD36LshcyeSzHQHBcZRDci0qLxf17rXs+lzJh9P333OMtkat0HxiB7 ZwWpKCwaDkpB22dIrL9d4JyKVaqC5Q0qwtTPQ4yDnmD3TbuPNlRGMX8K2MrqdSHaR62R OUM6RYInTw0bMuDnnIua01nMBe4fzWW8FsJGOHdiXXsEhQmS0BvCuCwTtniwZXcJX69n c27BRWqByxRCJt5CJRQgE+qSz62P3ghc78Ufl3vkHKCZcJukkyfCo2sEfYzChgEDF7QG qjsQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=akMpdDedBfqF60/fNsk+O8npKk5JqF+ySZ0f9xW5/1M=; fh=7jf5Pfv+mtyBr5y4dOo/lsZdjjKDVprvc5tNZILB3KE=; b=L5J1eKPl4g3UVA4jrblO7yp22bjOplfjZOOVIgLpHHyLIT9m9YI/waF0DQkBypyLCJ MM7h7/XgqmPbXI77uEhlK2iECs2LJYvd6wsr8V2y1LY9QmDV1zZh6RbDIN6mVXYlo08o G5ZpwWoJJliHX/FYgW+kxVk55vVul8izpICy0kzNMDxOQYdwHr0Bb46yVo2HThRF7Lzb PyqOOiAQLBIxDMmtyyUg89qdkW5ch0UngGpxLCbPjNpAzGqUZ+/Cn4eHPDRh+l0t4Cd6 D70ardAds/kiDCNR1AuXAkxFSZPXgiZ/L06LmPa/votTVDcwL8rpIfpxqa+dxGpH7vEq JKIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=EfsJ06ds; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-97452-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97452-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dg6-20020a0564021d0600b00566a1dd07e4si25555edb.495.2024.03.08.10.26.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 10:26:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97452-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=EfsJ06ds; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-97452-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97452-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3D7BA1F22528 for ; Fri, 8 Mar 2024 18:26:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A115257885; Fri, 8 Mar 2024 18:26:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="EfsJ06ds" Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30D6A54792 for ; Fri, 8 Mar 2024 18:26:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709922363; cv=none; b=DNn+/lcDUJKDxGRWxkGprCd6xMPNg2ZYgnEBuyl+V+erzvz2sgAID1UPVGTWD9P3JxTZxKRcQuVlEyxVoV2zF0i2+Oe+DthWs6IwjkgRqfW8kpv5KEQ0p4SshYDO612RpIhPPAoWEPZ57r+xJS525v3U1711zslLDrqXw6AgX4U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709922363; c=relaxed/simple; bh=ejS3FVJ1L+bLL4KR96q6ZNDMwke6NlmAthP91enITHI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EYYn7z42yA6KqQfursfS5uasJ11PufP5+s+Od8Wz9mIuutGai0JXEzTINre1Jroz7swBj3Vr5TTTYQHnbxOj5QXIRCI9qLQHliJDzwqoVI8abhYvD5NS+Ak97sDj+85tZ/cxYh4nHS3+NfeDDtZV/XedmvmU46Q2Q9D/GeUFPNc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=EfsJ06ds; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-29acdf99d5aso1648288a91.2 for ; Fri, 08 Mar 2024 10:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709922361; x=1710527161; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=akMpdDedBfqF60/fNsk+O8npKk5JqF+ySZ0f9xW5/1M=; b=EfsJ06dstPNrOk7teIsWGrajE3Mqrn9DvcSIz2pJAW9T8/G9kuFyP7CzEVm49oglU/ ZGvvqgA8Naem9Ui1EivntfUF7/RXijfucg83Z+r1+JWYcxtKww1oDnvNvb+sjv/xO5nR Syg2J120NptFpv34britAGMftaZPk3jvbbSXSbL7VEdH82ngOjZEy/27Y1t7omziZmsD M5Uxe7hvUi+2aUQHl09D6KtpTOPGRfQU7gijeI4wHmVMVEZ3g407RffvhWIFTgX88DsH vPiH6JoZBH/iV8VbiGefrRMDdGOJWDYWHbsyhGAdMLD5/Fj1uMQ7/XFvVu8rIjFNdgFQ 6Adg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709922361; x=1710527161; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=akMpdDedBfqF60/fNsk+O8npKk5JqF+ySZ0f9xW5/1M=; b=hXRQ8aF/M5IR0nQeT1BYJWtEJfBncq8rrvFlyaVw6Eouo8I6y42KAsXNlSK7E5szBN cedrL2J6zlTdt0X7IG94mEGql65Q36oMniX/RzhkH7YHncl7WNld7SLhmHunVIqxW3Zs JfxPTaoQNrhWg4bSbTJHOHb8dgRN9zjP7ifauDIR02ym7tHS2fG/itFpTNXGQHxNGuw7 FgY2CdvgUPC9hmIGl65gMHXD2hHuecBGNEEOVoZIXWG6zScJ3iL8FhiI1e/VSN5uKG7l 4pMbv4xdpXFhPFOYUjYjev81SK+sWA05Pp+3zFuxPreGJkWBPXVCvVUfdAQFHT7HO9ES wcfA== X-Forwarded-Encrypted: i=1; AJvYcCWaSF0pujNO1/PLuvkRrnUHuT8lHBfcOjSiNvt9XygKVHshtNsANvMWIF6Bzi/ILVMLimfXiOi/jN7gc8/1w9BvpA5Ehqo3oNF3/DTb X-Gm-Message-State: AOJu0YxpexLvD5v/KPkKcafghNZSbytktuOhrRjSfJUHHsNPC/27wEht quaReEoV3ZzZNEYRwYihkGyt4UoA3YbwTuJR3bFMjNm/x8cmId+q8KluO/9Vyx8= X-Received: by 2002:a17:90b:216:b0:29b:c179:9ba with SMTP id fy22-20020a17090b021600b0029bc17909bamr730495pjb.47.1709922361463; Fri, 08 Mar 2024 10:26:01 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id e13-20020a17090ac20d00b0029bb1bb298dsm44821pjt.35.2024.03.08.10.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 10:26:00 -0800 (PST) From: Charlie Jenkins Date: Fri, 08 Mar 2024 10:25:55 -0800 Subject: [PATCH v9 1/4] riscv: lib: Introduce has_fast_unaligned_access() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240308-disable_misaligned_probe_config-v9-1-a388770ba0ce@rivosinc.com> References: <20240308-disable_misaligned_probe_config-v9-0-a388770ba0ce@rivosinc.com> In-Reply-To: <20240308-disable_misaligned_probe_config-v9-0-a388770ba0ce@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , Evan Green , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Eric Biggers , Elliot Berman , Charles Lohr , Conor Dooley Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1709922358; l=3428; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=ejS3FVJ1L+bLL4KR96q6ZNDMwke6NlmAthP91enITHI=; b=SJMPynNndVY7EsAyEorrdTi5vigiwbschT4Hh2s6NWRzNuKQv7kmdQH1jlqRP0WwxvdIrlvD5 dLhky32sTVtCvLuntQiohAff3ZBkbKDJ0Ms+9YYieJh871kgkrrcG6J X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Create has_fast_unaligned_access to avoid needing to explicitly check the fast_misaligned_access_speed_key static key. Signed-off-by: Charlie Jenkins Reviewed-by: Evan Green Reviewed-by: Conor Dooley --- arch/riscv/include/asm/cpufeature.h | 11 ++++++++--- arch/riscv/kernel/cpufeature.c | 6 +++--- arch/riscv/lib/csum.c | 7 ++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index 5a626ed2c47a..466e1f591919 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * Copyright 2022-2023 Rivos, Inc + * Copyright 2022-2024 Rivos, Inc */ #ifndef _ASM_CPUFEATURE_H @@ -53,6 +53,13 @@ static inline bool check_unaligned_access_emulated(int cpu) static inline void unaligned_emulation_finish(void) {} #endif +DECLARE_STATIC_KEY_FALSE(fast_unaligned_access_speed_key); + +static __always_inline bool has_fast_unaligned_accesses(void) +{ + return static_branch_likely(&fast_unaligned_access_speed_key); +} + unsigned long riscv_get_elf_hwcap(void); struct riscv_isa_ext_data { @@ -135,6 +142,4 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsi return __riscv_isa_extension_available(hart_isa[cpu].isa, ext); } -DECLARE_STATIC_KEY_FALSE(fast_misaligned_access_speed_key); - #endif diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 89920f84d0a3..7878cddccc0d 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -810,14 +810,14 @@ static void check_unaligned_access_nonboot_cpu(void *param) check_unaligned_access(pages[cpu]); } -DEFINE_STATIC_KEY_FALSE(fast_misaligned_access_speed_key); +DEFINE_STATIC_KEY_FALSE(fast_unaligned_access_speed_key); static void modify_unaligned_access_branches(cpumask_t *mask, int weight) { if (cpumask_weight(mask) == weight) - static_branch_enable_cpuslocked(&fast_misaligned_access_speed_key); + static_branch_enable_cpuslocked(&fast_unaligned_access_speed_key); else - static_branch_disable_cpuslocked(&fast_misaligned_access_speed_key); + static_branch_disable_cpuslocked(&fast_unaligned_access_speed_key); } static void set_unaligned_access_static_branches_except_cpu(int cpu) diff --git a/arch/riscv/lib/csum.c b/arch/riscv/lib/csum.c index af3df5274ccb..7178e0acfa22 100644 --- a/arch/riscv/lib/csum.c +++ b/arch/riscv/lib/csum.c @@ -3,7 +3,7 @@ * Checksum library * * Influenced by arch/arm64/lib/csum.c - * Copyright (C) 2023 Rivos Inc. + * Copyright (C) 2023-2024 Rivos Inc. */ #include #include @@ -318,10 +318,7 @@ unsigned int do_csum(const unsigned char *buff, int len) * branches. The largest chunk of overlap was delegated into the * do_csum_common function. */ - if (static_branch_likely(&fast_misaligned_access_speed_key)) - return do_csum_no_alignment(buff, len); - - if (((unsigned long)buff & OFFSET_MASK) == 0) + if (has_fast_unaligned_accesses() || (((unsigned long)buff & OFFSET_MASK) == 0)) return do_csum_no_alignment(buff, len); return do_csum_with_alignment(buff, len); -- 2.43.2