Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp749598lqc; Fri, 8 Mar 2024 10:26:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX50FxxJoMoiHAwU3rPnie17aryOUQHFc2RHOQ6WrkYoXgK8tp5bLS3nD/JAHZJdsrVsvPavc6PeEiC2d1LlXhNdJUxgzFB6HRN1SaiOg== X-Google-Smtp-Source: AGHT+IGhhoQLnX27SkXI1gE79QL0tiPTLebXyblTkCz0+srDi4UjELJsLyhQzME/jHjMHQ+2EAfM X-Received: by 2002:a17:90a:cb97:b0:29b:7921:6b93 with SMTP id a23-20020a17090acb9700b0029b79216b93mr722933pju.47.1709922419591; Fri, 08 Mar 2024 10:26:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709922419; cv=pass; d=google.com; s=arc-20160816; b=ScWjeufBdBuE+2cebztIjTngTVN+BBjE9R9fjeeGnSU3bpOGLSNQ4yLXJkFhyfKXQX RBAj6O//LKSd8CPb4zH/uRP7La6yP3/POfNr9+IWpfrkn+529v4LVZ4nh3naKpapHRWK nxkD5rdERJZ6bNpgisbAmnF+cboHrz1+Jh6TWp9Z2wOV83REPBmV2D2nV3o+FpfzzZ0K sSSkwD8OF+ddv7JtfdrUsil06b7mIBbH/kpL2yUo5pqab7nahoUslPDjBCK75isuRce6 vMlx7JNXudA5vUnkCvshzGK4bVXjNbvb3vb0/BwW1KZ8ZL67hb5rwGJ9GTQwyaLwmFpD jicA== 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=wAwK8nUxqsm2fVKO5/NKBWHelWNeE5kyT/bzOOn3lnI=; b=WSOLBZkfM8jHGvPFxME2o1XDL4QAxRZ481yYndyAz9fHFTf1LFXIjRzFzbKWizyQK6 8MrFQDQsXh9V3h3h/7rMLtrupfywnVQ0v5Zoc0CEiTTukqJiwvY+H9UvzdFUcyPl3tQa mIk1MG/Zke0gOW3g7MVQmrpcUXHi7Hh+alNm3GlKk0feWOruOae6ifDFiGebdUvpGASM F1a04b8REpopo7eRlLK+uF9rJnH8ObTm6tYz97CiSCJ56bfRIXKdSEVJ9etdZsdVzpSu 0BhXO0QbF+zbd5t3kBfwrFa+/tlGbwsnuXaxv7cC7ILEYduczUZDPqp0QeuGPfAYs4NL Px1A==; 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=kwcZ02Oy; 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-97454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97454-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p4-20020a17090a348400b002997165bd74si4313480pjb.83.2024.03.08.10.26.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 10:26:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=kwcZ02Oy; 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-97454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97454-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 59CF9B2209E for ; Fri, 8 Mar 2024 18:26:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 415AC5A7B6; Fri, 8 Mar 2024 18:26:07 +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="kwcZ02Oy" Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 B9DA55788F for ; Fri, 8 Mar 2024 18:26:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709922366; cv=none; b=dnPr4gowzWemX0HplOO52ryev0ZtnIQP8n0wJKNwzcdH2OvYj05c4sW7NLACbhdQRDMWJkROgIqu+pwPzhxvdp8pyBhzWvb21b58OF7cFakwikVXS/cInF15PQk1LcCyNRjgyZxg9PEQFuDfzr4m4A3yMasOY7+lr4tvkfdaTLY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709922366; c=relaxed/simple; bh=IaoDcAIGwiU84s3iFQFa7IKKT21z3ZbSgM4n2pSHuEQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KXFCelqIGJJs44lNOPtScXtbFPENd0r8DA89NC2UOf4jOQjsp8X8DzGMY93FrM36bFnLfuZX3QxjV0+3qCheU9fEZt7S/mgLT6/YX84p0Y7ZwXRo6oNTtX5C70P5MQhLOfsCxYcFzSNKGF4d10I3gQBGSKWk5nKGwoAOcEVP5Rs= 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=kwcZ02Oy; arc=none smtp.client-ip=209.85.215.181 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-pg1-f181.google.com with SMTP id 41be03b00d2f7-5d8b70b39efso880653a12.0 for ; Fri, 08 Mar 2024 10:26:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709922364; x=1710527164; 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=kwcZ02Oy/o/ZXB1sCbZCkfBAbmzPmnTyAlhjCMT1q/A9RrgI0MhXoO+LvXaOnHPnYR 03WKVoNAxN3AxZx/muhCKDkNY+F/spTbZqD/rklz8hjfOIOeICc7LW63l2sDjXvIyT7F 8dyxsZYxVJx5mrGOLojXiaxyh+vTwDRSPTEMEJe4M7/CrI7H05D8oUJtokxjWPVU+C6h 6uVLm5Dt7grcvwjJSSsZ4JFOp9O3criJ9v+JCNPqpJWQ4efRhJornfDE4ytU9l52RIa7 xCHhPVcd9Pl17/sjtVjxmHDwVY7Y9JF9GgOP69KHTnyUkanJm14kKqmTbSaybqlhruz6 Jheg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709922364; x=1710527164; 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=LqyJvdPhyCupSRj5q0ScXjnIRPpIsQAD4/IggUlaZGZCKWgQKPMQxQZk2fyYGjGvI1 KxCnuypEQbh7+boyIr4a2Shba8K0ygMoGCtWsQ4ICoi/cQGFhMFxYZY7MJQ0XvuM4+Bg yaNOAOd7EW+rEf3anDvbVV9yINYYwn+DLprU3LTffw1hI21/i5J0PZeXOXrZjWr/8X0n 516Hy1MICirbwZcOyR1kGIN+h+hdkU/uEOKHL/yq7JUlvKqgskgQli6R0Mjx3V6Q9soK svw/jm6b/1Ocf7VbVhLAQYP6rA3ea5Ft1fB/yAJ4n/KONTSfU2EhTQrhPzYuk17o3zyh puuQ== X-Forwarded-Encrypted: i=1; AJvYcCVQWxRtFCKmmmj52qjV/G0vKz4ac0tQ4n9fNfAegNXti873FvKyIE43FC0i4oIgo9AeGVZPozACifmkCVjsj+LE1nbGlfSAL5WE0dlv X-Gm-Message-State: AOJu0YzKLlYfqRuuPNbkERXX2Y8Q94uamZbH84xBx3tNd7LcUrJbUXZL quo6VEz/im2UA0ohpBqlU/kg94nZLV4VZVnc6pSD8sZiQns/I/jgAeJXHs/zFp0= X-Received: by 2002:a17:90a:fd0e:b0:299:4269:b8c9 with SMTP id cv14-20020a17090afd0e00b002994269b8c9mr954346pjb.26.1709922364103; Fri, 08 Mar 2024 10:26:04 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 10:26:03 -0800 (PST) From: Charlie Jenkins Date: Fri, 08 Mar 2024 10:25:57 -0800 Subject: [PATCH v9 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: <20240308-disable_misaligned_probe_config-v9-3-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=4202; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=IaoDcAIGwiU84s3iFQFa7IKKT21z3ZbSgM4n2pSHuEQ=; b=D3NiSToMkJgM3ochOOiN4oilLBmEEQASczQi6/yCbCi3BMgcdcf1bmege+8fRzDPEEdyES10L ZsVeSsvKAlqBFE64TiUx0lgNGZdkZt6k+7+Hmox2EI2GfuHZcyBynmQ 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