Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp132400lqi; Wed, 6 Mar 2024 12:07:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXgD/JprmCSCBFPyak9Qwzxepn9MeLatIYQVTct/EYs9Esk1cKcF4WcSjTgw7ps9Z15xV9WW5BX0KsuX+PvwObDe7tHAOlEtF7Nwq3Yhw== X-Google-Smtp-Source: AGHT+IEJTq1SI81W+0r0m3yoIpnXrZ/ifkj052q5xFhV96e7bKwHwo8sjgDluVDuIo1rp/2D2eI7 X-Received: by 2002:ad4:4421:0:b0:690:513e:347 with SMTP id e1-20020ad44421000000b00690513e0347mr6247483qvt.30.1709755673958; Wed, 06 Mar 2024 12:07:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709755673; cv=pass; d=google.com; s=arc-20160816; b=V5SdBC/rErv8oFRqcz/JDPuRAAIxhE1XCri9cFd28cjTwdPylqcdNIqqzzA1ZsGJLs njXut9+uSLMywpaXmruACwrdRSozow2bAuEcZP3L/jy7OC4HUPQvVG+es+HYg78CF1By ObHNR9jFzO4ry/UBUFJdPr1FKUwjU1NqUlYj/kVg3XqblR5EivrzoVceyCou9UaBfT6m 2Nlta5Kga4nARvN1ffOiQnF5ptS3EqdAn3j6BJMnJTrEAljWE4oo62fVa2SeM0qM4bv+ kkvqOz3fLLxBknfgy8Eey6R3tlzCiPxPLOW8aLqCvt5PaQnJVvaWwJdcYEgd5+Fkn5FY VfHA== 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=T3h3l0Ycd0txaXwqtGKXZSurBo/SuGyYiZV4XuZZpag=; fh=l0z487aWq5JPJEPEgs1kh0M2DKR3vxnxdemIvF/7684=; b=oit7oHOTcB+kSLevxFbU5WGFAC9VuESpGirxZlczinkmCwpyXY5bWdK5zoAJ46UDU2 OkGxjBL24UPCjEaRe8H0DWl5b2vsZ88wg/XUT+CK2IW/e7Ia1zTaryELmTjJWpq47Epz eoJzotJFbfV42bkcI3DAlZvIppcds6HccX5XC/t9qFZ7Z2ZaRn3HtAvwcsMvF98xA4ez C7G9o/PfVugFTQP9X4t7/JlS0D8jh4Q04o5YGZajEthNfr1dnkxZLDq52B8DZACOEvwn FnjMgjv2xQZTx28G44CHVxjBxjWoEaSa2faimwC3OYk9/gFVR0Q1kiH+uvad+1ovW03l 4lPQ==; 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="Lvi/ZvPC"; 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-94539-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94539-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ks3-20020a056214310300b0068f4d4938eesi14700170qvb.615.2024.03.06.12.07.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 12:07:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94539-linux.lists.archive=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="Lvi/ZvPC"; 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-94539-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94539-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 8C0841C2150D for ; Wed, 6 Mar 2024 20:07:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7902146019; Wed, 6 Mar 2024 20:04:35 +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="Lvi/ZvPC" Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 4DEE11428E1 for ; Wed, 6 Mar 2024 20:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709755474; cv=none; b=PydJ0UDxIlCioV6TP1nxlH78cnr9+ZR9IpM/p5t3ndYY4AikSZa38i+TJK9k+U83xB+XeS6QEamMnkPL71TMG7EzjmJq3eAYD1oAOgWVgUPnpZ4XsYdN0pw/3wB2ngl2K/A2g8Nb2bG/OW9Fdop3zYUsqM/pFmKQpJjPjgfl1fk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709755474; c=relaxed/simple; bh=DInkzEsYPrFJ+waSF/dYqKLd0uhEiOzVtX3I13D+1lQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r12qHuJcsh8BOhQDpYzylhNYSHtuGEvHXpkCKwhdVOn2mZKxHLe5FWLUib/JQkowJ0itE7/FUpPZoKo6V2TPonmjN1XO7juNixZb/qpyRRrjy19ZRYYgS14YLFE0/ASwj2EB1e7m7nK/S3O9AwP+v7UoxJGWewgLPbk6GXIJj/k= 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=Lvi/ZvPC; arc=none smtp.client-ip=209.85.214.169 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-f169.google.com with SMTP id d9443c01a7336-1dd3bdb6e9eso818535ad.3 for ; Wed, 06 Mar 2024 12:04:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709755472; x=1710360272; 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=T3h3l0Ycd0txaXwqtGKXZSurBo/SuGyYiZV4XuZZpag=; b=Lvi/ZvPCvAo71WaarlpMKCkkcK+EiKd7t/j7dLIKWJ2gGXsnrIjtyVC1IYwPnBm1RR fuQ9NRKQVreHum0NgOZIvsMZoo+ld/gQAEoR5E2iO+dAbgjvcvmjm5Kkh8NAyvLZLlkV hgKt4EyGvDLtOOYPeZx5PiesUKZiulK44QmcVjvnIaACdE0jR62LzwvV4Z75tJcci4L5 wilqGLf94/mzheUHo8BxaNnKVl+0XmneP/lNRWUVUwXojmE5RjSpZOmEV2R4e0H6l+O1 r/oYpbhpNtsIFPp+XslKUHhzXugwBTsufC5CQn2bSxtLJmNZyV2ZwuNVCr3MqellS0f8 6ULw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709755472; x=1710360272; 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=T3h3l0Ycd0txaXwqtGKXZSurBo/SuGyYiZV4XuZZpag=; b=em82XrpfxyXDU7erccaAXiUOtXnrcBEmDJQX0JnEJdP31PKEhnmkmfiMntzuiEbi4U M9ToblgaZ2Wzf1KzIt9S6QGyzea8XLOR6Z3njMc/ekJqowYxU6zN8o9WnwG/f6cKqc/n dqC0+EvlZ3N3COnMq/7DEviLiKaEkPniwenTjERZ32h6fcNL9TQZG5Hu+SAHD0SfLFu1 1btqvT4IZKkvC+j2402QxSUyrAslG2VJXWo4fS1Yv8KI03s/FMmgbBoucPGKhhptYlxd tAzakXkhVj/lxcu5jb72ZSkpbyha9OOfx3f0RU46E/ZiE8fF8TYzvP+fXeF9dUlS6VkK Wwmw== X-Forwarded-Encrypted: i=1; AJvYcCWo97YqXl/RyY6coVf22vbTfGk2P69PUUGViyX3Skj/Tz6prrbTqOM1+uJHL3qs/sEEtyUbamuAPHM5nQAphdIOwyMxhRL220l4LQ1W X-Gm-Message-State: AOJu0YxlLfzDyXtyIed9+mCJZxV7sW5+eEAhycTK9vmhkcjk+C8kEYBt rg7mlWR8WCgPSGudvNhdRyQuMdpF+Av20Wry56XvOG68G/BnySHdBK5GJzaxWZg= X-Received: by 2002:a17:903:24d:b0:1dc:7845:537c with SMTP id j13-20020a170903024d00b001dc7845537cmr5928989plh.1.1709755472694; Wed, 06 Mar 2024 12:04:32 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id m10-20020a170902db0a00b001dd42bbb08asm874913plx.253.2024.03.06.12.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 12:04:32 -0800 (PST) From: Charlie Jenkins Date: Wed, 06 Mar 2024 12:00:03 -0800 Subject: [PATCH v7 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: <20240306-disable_misaligned_probe_config-v7-3-6c90419e7a96@rivosinc.com> References: <20240306-disable_misaligned_probe_config-v7-0-6c90419e7a96@rivosinc.com> In-Reply-To: <20240306-disable_misaligned_probe_config-v7-0-6c90419e7a96@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=1709755467; l=4180; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=DInkzEsYPrFJ+waSF/dYqKLd0uhEiOzVtX3I13D+1lQ=; b=jrlrelGypAUGPhL6WOlc+U5QG80c/2NUPxE//1G2xYp5fWrZqTju7D+5BYoGVZA8TyX+Yol9r f30a8KDNUw1DJosvrzrZ5/YaWsWWUht2zEvTFVWwrFNokvMxtasqojP 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 as is done in the following patch. Signed-off-by: Charlie Jenkins --- 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