Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp89789lqc; Thu, 7 Mar 2024 11:06:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX2jaNNKU/V7BNCJcqdOR7NSdzFHZmPdkLOyqbV5wUmgVhGYcs/GvZPKy5CBIyOux4g5ymx+HfbSJxFxnkCCM25zj19jJXyN/a/CyxaWQ== X-Google-Smtp-Source: AGHT+IFGBZ3S7hbfdWgIdCOBTTxMtFokq30PMVz/egbN5YomyD0SmtXUY36PMT0Ne2FSvdUt1fdd X-Received: by 2002:a05:6359:4594:b0:17c:1bef:4084 with SMTP id no20-20020a056359459400b0017c1bef4084mr10593543rwb.6.1709838406345; Thu, 07 Mar 2024 11:06:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709838406; cv=pass; d=google.com; s=arc-20160816; b=WYxlXtBewujliktdm9WepCg/SgTWBBcI4FqpQToRNobhBN8qC7qra9kdahRgpgA5Hq MkUWDXoEelP0rEzkzX+NoQrbNjwegJp98XZsPFjudQYLfWnf3O6LPCSJSXRjnP/LBFYM 2V7BYxGbl5px96wN1qXqO8Uc6FdmG+e8/R7dhlZZhzPHXYNyP9tRORZ28hy6enXnd97s nnJk6CzdwMbAhMhP9x9/RC3quSL3YLLQ2z0lUMAJnP7KXJPGiutEkIh7DXZeqyU7cTws w1E5WuKtgo3EKQqMSbC37zLcnbuLAAKbr7GiRoP55Z6KwFoLdhrH7s4IHwm9XmJ355nx LZkg== 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=rcFiymo+h5H2KYUaV+euAHpHhZgWsCrhqFiINsYj2NQ=; fh=3bnkUuKIDH8R3qb9lPKyF/q9ybtgj/3Br4yankk+fsE=; b=YZV7zbx/2gjwV8vod6hC5a2BRN5XEmglbsD3bt3yKPruaXYRipODRtP0km6DDolFej 3PuJtO3rn93TBIMVC2aoDExptWYAcB/xdyfCkuPsp83SRBSF373Cy4f7qBNXyqx3W2mx nBQ5fsTOISLRvRaESS90AabPpI+SsK9hv0/lsqwYDy3PULgJoRXRRLC7KNH/FPMlld/O Iikiw9rLqEqXuImgkU3vAee62IBiiVnV9u0yAN0OML7ZqYqlZEZsPB1k1KEqfiO4XiIu 0sCtXCQuTfo1VNRKoCrBlIhRmB9CJWtlGD1odQ1ofhYCM8eJv3cJNQbZboybIx+5/Krb E1VQ==; 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=H+MfpdE5; 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-96054-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96054-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s16-20020ac85cd0000000b0042ee0ecb1e1si11613472qta.13.2024.03.07.11.06.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 11:06:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96054-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=H+MfpdE5; 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-96054-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96054-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 042CB1C20A2D for ; Thu, 7 Mar 2024 19:06:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5A11137C37; Thu, 7 Mar 2024 19:06:00 +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="H+MfpdE5" Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 C8CA813665C for ; Thu, 7 Mar 2024 19:05:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709838359; cv=none; b=AmLsK4lgfIBy/bTRVY2C5odCkV41kPefVIaCeCPa7FtL8Y2Tjo8Om5HwlmO5E0LEXzTVE/R2pbL0JD5btFlaT1bWs479xIlBvRvuZQPhwsp5C4rqeRD7dZl+wvC/eNeYJZDdd1mGEHTfxsv6DunPfW7zR6PK1ynzun5MexnwqT4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709838359; c=relaxed/simple; bh=IaoDcAIGwiU84s3iFQFa7IKKT21z3ZbSgM4n2pSHuEQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WcZz81vAPKkfkt70WypZgs++tTxB2j3tufQA3t+OOHBJLxAS2TmjORb3IyEQweFXP1tuHMGWDCeoHRUldYkUf36uGQG0e/elD07wKhazbL1GjXeiwu/d2Ydl19EwONZ0nuoVk/BcvvkBcDfbeJxOxezEp3VlVWPfUC/En588jlA= 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=H+MfpdE5; arc=none smtp.client-ip=209.85.214.178 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-pl1-f178.google.com with SMTP id d9443c01a7336-1d944e8f367so10903525ad.0 for ; Thu, 07 Mar 2024 11:05:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709838357; x=1710443157; 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=rcFiymo+h5H2KYUaV+euAHpHhZgWsCrhqFiINsYj2NQ=; b=H+MfpdE5RjxaxOzspqY43kXNOK/QIzBYdzkWuPqbc2gKU8BIpd1l+Kd4246DOsYewe SFFs4ZfP0ZcZh38GiWtwDedjFAKLlbiJbxlNjVXCfKKIIQjcf4IiWlDdo0h6wBRNAFRq OGDljpX+/bIuvMqaBVj0hXXi+ei7MAM2mJd37A0+L8E2hZAy+SUfJ0EsHxUCZ6ChZL7k jjsrYktpXHkFr0jsVsRW8WadGupSOcZ2gQYm3PP/utq0NRusF8IM+DUAdpaCX5at75CI ErQMOK3qo+Ca2V/DX9j1sMagGcfb5TpcK6IUjS3nd/L8xMyclMPGAnuqE+2lA9cHU3Zm h/WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709838357; x=1710443157; 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=rcFiymo+h5H2KYUaV+euAHpHhZgWsCrhqFiINsYj2NQ=; b=Ty/4ZR3ddwz6Qk7BtnvUJuNyxmlWzs4ioU8TViJI7XGPSMBlLs3bK80VqVjqolWVPp ZGXBMUFTqpfcKT/prz7XwTm7At1Qu0EUOZjnY33ZeedtH1AbCG0xh5CCQSHzKjjwYltZ W5AqKTMtQIr2bbbktm7qDkl8F+/9j/UvqTZdb5vMsNa7ZFBopDZ/xJtQ3kJyvpI3osK3 +9oZUNvZL7/f5V4xr10bxPrJnWPi49TTQPE8I7TtNh+IrZycd+wnlbefFx01usq7qUT5 dJEsCn+Y1XPm+QlQyz3LLnjNdAZlobDjF2hX9J82bnkdMMPXY8zUKKqz5EOMLm9oq4YS vJ8g== X-Forwarded-Encrypted: i=1; AJvYcCVTvm2Wnuk+qY9wcy/8xdpvUISi6AXB2LVh8iCPd2/nIDbpsYXEWiBJVOkXRyCGCxrLzJA+54iEVsYrP4KV1HuZgtQ8hazG9TMlGwvf X-Gm-Message-State: AOJu0YwxW+5aGXu+sDF1jwpiyyA1Zq5QSurvy4R31gQpRjM7DL9vT8us Kog7IQ6k35vPGjGQiYAyXqDQmjnqX/dkqb5tLuKVjv4dERHstlKB9UVjvt0iQhc/nGnJ1uj3dKi f X-Received: by 2002:a17:902:b202:b0:1dc:fb12:abbc with SMTP id t2-20020a170902b20200b001dcfb12abbcmr7992411plr.61.1709838357144; Thu, 07 Mar 2024 11:05:57 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id h3-20020a170902680300b001dd526af36csm1747338plk.295.2024.03.07.11.05.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 11:05:56 -0800 (PST) From: Charlie Jenkins Date: Thu, 07 Mar 2024 11:05:47 -0800 Subject: [PATCH v8 3/4] riscv: Decouple emulated unaligned accesses from access speed 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: <20240307-disable_misaligned_probe_config-v8-3-55d696cb398b@rivosinc.com> References: <20240307-disable_misaligned_probe_config-v8-0-55d696cb398b@rivosinc.com> In-Reply-To: <20240307-disable_misaligned_probe_config-v8-0-55d696cb398b@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=1709838351; l=4202; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=IaoDcAIGwiU84s3iFQFa7IKKT21z3ZbSgM4n2pSHuEQ=; b=Gd/AFd9UPYuU9gsHq8mkyXcCsBgVRVzPdcuQYH+roI4KVNNrqQUITF4Emy6vygu23m3rPxwio U5tr57dBkG8BJE6C+mIDw5LFGt6Z3a+kGFeNFUsbIiIjDF7+dODt76C X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Detecting if a system traps into the kernel on an unaligned access can be performed separately from checking the speed of unaligned accesses. This decoupling will make it possible to selectively enable or disable each of these checks. Signed-off-by: Charlie Jenkins Reviewed-by: Conor Dooley --- arch/riscv/include/asm/cpufeature.h | 2 +- arch/riscv/kernel/cpufeature.c | 25 +++++++++++++++++++++---- arch/riscv/kernel/traps_misaligned.c | 15 +++++++-------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index 466e1f591919..6fec91845aa0 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -37,7 +37,7 @@ void riscv_user_isa_enable(void); #ifdef CONFIG_RISCV_MISALIGNED bool unaligned_ctl_available(void); -bool check_unaligned_access_emulated(int cpu); +bool check_unaligned_access_emulated_all_cpus(void); void unaligned_emulation_finish(void); #else static inline bool unaligned_ctl_available(void) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 7878cddccc0d..abb3a2f53106 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -719,7 +719,8 @@ static int check_unaligned_access(void *param) void *src; long speed = RISCV_HWPROBE_MISALIGNED_SLOW; - if (check_unaligned_access_emulated(cpu)) + if (IS_ENABLED(CONFIG_RISCV_MISALIGNED) && + per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_UNKNOWN) return 0; /* Make an unaligned destination buffer. */ @@ -896,8 +897,8 @@ static int riscv_offline_cpu(unsigned int cpu) return 0; } -/* Measure unaligned access on all CPUs present at boot in parallel. */ -static int check_unaligned_access_all_cpus(void) +/* Measure unaligned access speed on all CPUs present at boot in parallel. */ +static int check_unaligned_access_speed_all_cpus(void) { unsigned int cpu; unsigned int cpu_count = num_possible_cpus(); @@ -935,7 +936,6 @@ static int check_unaligned_access_all_cpus(void) riscv_online_cpu, riscv_offline_cpu); out: - unaligned_emulation_finish(); for_each_cpu(cpu, cpu_online_mask) { if (bufs[cpu]) __free_pages(bufs[cpu], MISALIGNED_BUFFER_ORDER); @@ -945,6 +945,23 @@ static int check_unaligned_access_all_cpus(void) return 0; } +#ifdef CONFIG_RISCV_MISALIGNED +static int check_unaligned_access_all_cpus(void) +{ + bool all_cpus_emulated = check_unaligned_access_emulated_all_cpus(); + + if (!all_cpus_emulated) + return check_unaligned_access_speed_all_cpus(); + + return 0; +} +#else +static int check_unaligned_access_all_cpus(void) +{ + return check_unaligned_access_speed_all_cpus(); +} +#endif + arch_initcall(check_unaligned_access_all_cpus); void riscv_user_isa_enable(void) diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c index c2ed4e689bf9..e55718179f42 100644 --- a/arch/riscv/kernel/traps_misaligned.c +++ b/arch/riscv/kernel/traps_misaligned.c @@ -596,7 +596,7 @@ int handle_misaligned_store(struct pt_regs *regs) return 0; } -bool check_unaligned_access_emulated(int cpu) +static bool check_unaligned_access_emulated(int cpu) { long *mas_ptr = per_cpu_ptr(&misaligned_access_speed, cpu); unsigned long tmp_var, tmp_val; @@ -623,7 +623,7 @@ bool check_unaligned_access_emulated(int cpu) return misaligned_emu_detected; } -void unaligned_emulation_finish(void) +bool check_unaligned_access_emulated_all_cpus(void) { int cpu; @@ -632,13 +632,12 @@ void unaligned_emulation_finish(void) * accesses emulated since tasks requesting such control can run on any * CPU. */ - for_each_online_cpu(cpu) { - if (per_cpu(misaligned_access_speed, cpu) != - RISCV_HWPROBE_MISALIGNED_EMULATED) { - return; - } - } + for_each_online_cpu(cpu) + if (!check_unaligned_access_emulated(cpu)) + return false; + unaligned_ctl = true; + return true; } bool unaligned_ctl_available(void) -- 2.43.2