From patchwork Tue Feb 27 23:13:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 207501 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3020033dyb; Tue, 27 Feb 2024 15:16:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU2AMMl1H7B4H9IxF2J3tTbx2zzX4UMtV4jJc9WV8m2HC0WQJYMg7Bzqg3yQMG8R2LUJXaSgpj5U0Zpu7sh24CgKp/pQg== X-Google-Smtp-Source: AGHT+IHcxsgnUtkeoRfUXCBNMPu1h9suDI2xELLE6R0C1GUd9bYGopkvoj25GRz6damcORGda9Vs X-Received: by 2002:ac8:7d92:0:b0:42e:a139:9042 with SMTP id c18-20020ac87d92000000b0042ea1399042mr2611875qtd.56.1709075804884; Tue, 27 Feb 2024 15:16:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709075804; cv=pass; d=google.com; s=arc-20160816; b=qg7IHofnljhYThiA2aJRIyAG2IvCWlGjA1y4ZkdEIZ+LtX2VWktFHzO+nNdRxJDiV3 wLQ5JQxJFJConW7sY5ZFE5uzlipB0mcGXdTt4EyEXIo/bUdbGxZSNUmS3h86hcJtL814 aC6xnDejLrh0uKeeKXzfvrimrhQ0nPBA6Kfs4f3EkCROrbid8G5HNVgy2Uj6Wmdk5kcS wXlFAddQITXV79Zyg/kMVlG+876rbWEjU0sdb96ijJiYF4S6wt4jC7AjT7xTwS/L7Dqx knYdjI3jjuGOvsE9bDg2h5gwmVvKPDbOBWbjBcDbN/zEyWL8NU/5EDRjNgk8CX2pRPdm 9q1w== 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=3EVtHtZkQ3gl1JI+EwyEBrvg+iHnnWLYEsQB5N3MR4A=; fh=dFrnh3UScj8jJvGLQbGLgZmWa/u4QPImnEw+gSG1iBk=; b=mFStsLHpdeow2BgkHOvw5QR4J5fd1I7mPEKhICZBa1+NA6S+su8mLdM3nKyv9thXw6 wLNBuw7FGw/AhXLzg/30n1IROIyjuo6taktrS7uAqy3p1vR/l+Te+aFkyQhFfwOcKUBU blTwQz7kuKK3zmHKNI21itL45LWuPinNAfQPYI1D/Bt3/eou9Ilkh4RNpGKdX8+AaMji YZizqIpp5+eRPyN9c00ekPAFAjoj3qT/v/Z7elNyLwkqKlS14AJSnG8hHeIfrmcOKyup 3xV+EC9001X6/7wT95jb7gSy0sG52ZGOFYhvo7IMC7cE2War8lrhd+dwq024oodH9e4i CI9Q==; 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=w1O03XbF; 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-84183-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84183-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b2-20020ac85402000000b0042c80a273cesi8405891qtq.510.2024.02.27.15.16.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 15:16:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84183-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=w1O03XbF; 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-84183-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84183-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8745D1C24DE9 for ; Tue, 27 Feb 2024 23:15:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B281858119; Tue, 27 Feb 2024 23:14:49 +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="w1O03XbF" Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) (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 1A04457867 for ; Tue, 27 Feb 2024 23:14:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709075686; cv=none; b=nzgq+2EDwue9RRt30u9yf1wWshZtPSYtQytn19zGKGNy7NrTlQ0BhWzrTFDiZi//Ecgwt/J3lpVv4UZboGdga7qbjk1/IsKT9VwO0mpR788gMXVlw/u9y9/fUlSC5tlJqPVOAviNaGMw+mnWlbbMzzGwtRHN6urD2l8zXnkXgzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709075686; c=relaxed/simple; bh=FzR0GpkIwoZRYWxFyEryVlUwRX7agq76vtFdOU7VZ+M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M6cE1mmQlzd1XBlML8xThrnWLmCg47t3OWvza3k/facTrNXiyHCYGCSsTp5B2Kcro43lbApkZie6fSul/VcJgB8eS7Bx5ALpiyRJxK/ByKaLcKjLwbbCsCO10naG1j1waRidzR43ZhhA+ty5ymZGan9vvXoM/YaI8/mPTJVhGCI= 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=w1O03XbF; arc=none smtp.client-ip=209.85.167.171 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-oi1-f171.google.com with SMTP id 5614622812f47-3bb9d54575cso3809075b6e.2 for ; Tue, 27 Feb 2024 15:14:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709075684; x=1709680484; 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=3EVtHtZkQ3gl1JI+EwyEBrvg+iHnnWLYEsQB5N3MR4A=; b=w1O03XbFtiSXk9gDaVzpnV/Zi299K0dSwlNNXPTkRm9NmBIMJN04TgoCYw9MVhRVBT D3Th3WOp62N7CGL3/XRCmUnz+xd6XBkSunhQx7E5ecCSJRWxvv4ANGgR4UaAUYqhw2oy CPnCbWakCbaujQHAaDEIfLu9FwbxxCr+ipf4DQ1zTuxb/ww6are/bSpxRoTX9fErpfLE 8rLvYbP7Kij0pD/N/YIpzfofjM5pJlEYL+xI18BmfBAEZZvOxsyA4Kmq+cgdhjJ+4Y8b ZTvzteC+akfaQWAHMULM63zEueZsy2RPjMwUX4TXa+9zjg+5H9YCvdvYUnOUHZuhtXGP RGpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709075684; x=1709680484; 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=3EVtHtZkQ3gl1JI+EwyEBrvg+iHnnWLYEsQB5N3MR4A=; b=C4CdTREOLAIgtWFNUiT13rxTLDBUbUS/wQYF8RZ5XN2b8uDlE1/nIJjINRsu3E9vXZ FSoE2Bf+jylZGdtve39a6xa4i7G+zwZtXzKuv6AB2H/JLBUci1tGYUAqKgF6dQ7o7VSz VZ+5QEaOLRyCy7+EPyHOovwOK/1NzfTsGRWEX9TULVf2EuXOv2aB+/Pbe4gzSUzgR2Yv EciUOV+rKtVlbxlrSADTXDWTkULFsMEff+eQrd4GRTyoD9pvsjTNT6a4cxFTlPfbmJK/ AHZ14ctCEoR4M6vR7p4spEGgfRvJ4bQrKvvJsx0DMZdnJlylh8SoyjpYpJP9IZuCqWsh S6ww== X-Forwarded-Encrypted: i=1; AJvYcCVwT62Z30bNbDVfD3toIGZdXya+2lUoNiatj/V4TG2elRZJ2dn5ZZTvLW858D+IikBqktPuk61KXVqxP2SPqtP1Smjy8uRooXHIY+zS X-Gm-Message-State: AOJu0Yzhe8BuiND1uf9i8zUN7sOkB/LLE8Poroz50vR4KW4M6NCmOVVF PHojVt93cmXxl0t+wokzsp/7i379nNqQm70wNt3k7eimkBW1LV82f3O+yuNK/bY= X-Received: by 2002:a05:6808:13c9:b0:3c1:7c22:c62c with SMTP id d9-20020a05680813c900b003c17c22c62cmr4524328oiw.40.1709075684262; Tue, 27 Feb 2024 15:14:44 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id l9-20020a635709000000b005ce998b9391sm5455645pgb.67.2024.02.27.15.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 15:14:43 -0800 (PST) From: Charlie Jenkins Date: Tue, 27 Feb 2024 15:13:13 -0800 Subject: [PATCH v5 1/2] riscv: lib: Introduce has_fast_unaligned_access function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240227-disable_misaligned_probe_config-v5-1-b6853846e27a@rivosinc.com> References: <20240227-disable_misaligned_probe_config-v5-0-b6853846e27a@rivosinc.com> In-Reply-To: <20240227-disable_misaligned_probe_config-v5-0-b6853846e27a@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , Evan Green , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , 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=1709075681; l=3372; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=FzR0GpkIwoZRYWxFyEryVlUwRX7agq76vtFdOU7VZ+M=; b=5y5R/N2D/Izd61qDhY+QzsoZDbkw4sD+B7NwvE2jC4w/xh3hOu1ij8PyYt+mXFR/AYxl45x0n pT8slOgGASxDYjzi7bPNXDa+gv/FdP5MbL/e/2C3zZR8eBhTPoT66Fi X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792095871260134833 X-GMAIL-MSGID: 1792095871260134833 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 --- 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);