Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1859693rbb; Tue, 27 Feb 2024 03:42:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUiXEcQvxCQW/+GD5f62u8x5Uh/ig45pm0b1AjqAthKiRK6UxJKp3A1Q3JhX2MGapq8LX45NFFheJp0dUP6VAMGHBOdptDawib8V0hHxA== X-Google-Smtp-Source: AGHT+IHgZvqLn9AV8eAtf01VR8SgLdoZju4HZJXP+2rxou3+iY2jf6oUuvLr0Yd8/dQ7U/qE4rA1 X-Received: by 2002:a17:903:246:b0:1d4:4df7:22ab with SMTP id j6-20020a170903024600b001d44df722abmr9627908plh.55.1709034122162; Tue, 27 Feb 2024 03:42:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709034122; cv=pass; d=google.com; s=arc-20160816; b=RsqLqUdSP8UPoGi4M/RpFspRNghXP/DFNpAlvwHbHU9xEyArqA8aZ2RevPMUbIMGOF BQuCRIqsHcE0H76tlcaFr3EFSHyrNxvUrhg8oRDoggk4FpxKhhofBTMpQp+wniYjrVnj cPJAu2AcbXRedvFUBrM3lMEsdRiwq5wgV/Qa4ZR9M4+bCg9gR5jxzLalu0q0acdpjs3A Zn7hTH7NqvsPJfQCKJbiHHhOPNOMOcw9LQdy0FXXui/UxabG2UlxnP2v+yf6z6F+piWv y7f8ZmrpO6D8a/NhKQJHDZHymnneOzGIgm+SKCVQNSVYBWE4QzcoWdTiTjhwiex9L/Yy gNPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ihMY9S2PkhXp6gMjk69ElA7l7GvSUZt/38EOflDaX6U=; fh=9PTrdyZGceCOWFVD4ofsjYrTkS4qSjA9/9YUDEUVxrk=; b=b84b5ooMWpXoXS1ER/EHAkcLYaFIM+BTetHrC8bGYUeNMrmY5AzQUc3jHVtLATjQ8C YCKreFlPb94OOu1k9Ni965riKuKyKR3cXtoq/mDMyXqwCJYWNFQNKioajabzbgRdfpzQ AyCEApykEZru9KqClufPcT59gaqBl9E3Vzm87UHTulk42HzKX73vXRcJnMiXasdblvXK bJc6mLy5blXfjRT0/hegJdsYBa/rsI6qQ0CqalpFiL+NePGL3N4aAMGzeD8fsgq7H3Wz mab0i+WSOBdH0TKKNRB1DO+MCNt3gPl+RCt4n7xu9KaTKnLtLF/9zmFhynPwZaQJFhoh GPXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="IMK/m4+t"; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-83135-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83135-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=microchip.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s5-20020a170902ea0500b001dca618ff90si1270926plg.526.2024.02.27.03.42.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:42:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83135-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="IMK/m4+t"; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-83135-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83135-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=microchip.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E63B7284E9F for ; Tue, 27 Feb 2024 11:40:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9159313959B; Tue, 27 Feb 2024 11:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="IMK/m4+t" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 454D412F581 for ; Tue, 27 Feb 2024 11:40:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709034037; cv=none; b=sfUfOMozyi8LvN15C5sl/P5+1m2GfghnjjQbxIWoSPfzHKWyLAhlR4ciLDTRYgoLXN13hCSuUQ3BD+2xkExfzSRcbjnALhgup2j7/5gOEcDdEk3pIqx6jfyA+C6BBzx8E4r3ntE2sX41bZLB2PDkOqwh2kx3dQXvY3YJQtAqz4Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709034037; c=relaxed/simple; bh=nAcqQcoVlavgogzMMv0AJtTW2BknoALl9ZTHNc2lkI8=; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iv/QGKoDwIpYDIBLpmAA+IFiE/nF0dr5sliKbowlhMJsSAd1vzi5t21I10bXT3DJn2kyIJzw1r/M5bkmw99eF29tijnfZzbgEZnDUqO+dCMpHmULiUatY6MZw+WqF5EkHNZHt3Pj8HQ7TOaEPxBEGsbxef8IL8npTmZIbPk3MBk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=IMK/m4+t; arc=none smtp.client-ip=68.232.153.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1709034035; x=1740570035; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=nAcqQcoVlavgogzMMv0AJtTW2BknoALl9ZTHNc2lkI8=; b=IMK/m4+txu4CIy/y+vADJWCfXfSQyJVGg/H9eFdUSaTiXvAPXA3qaKWZ rQ2Dzml3Db4f0vcLONf8fl84FI+BB0xk2U3GYoqz02ADAQ/CO/sQafbcm tYyHwXK8dJuOHuMrri0gL2s7xN2xkWo/s9nreTd7gW2L38aHkaPDQOIXV g05GJEO0op90X1i5aXUsJyShjwWVufzM/NIy+63sgeTlZf4v1k8XJnKaq xeopy1bBrI8i2wFo8g2ndUX7zQYAFGN5QgRTwRgvqpFrbWJb2YvmuzBuz 5p7UPzULtyHuvB+IQ1XZ1RdSa1uxnskSYSPUC5sMh6GJV/XEiIGD59D2/ Q==; X-CSE-ConnectionGUID: bVyENMktQsa0J3zoirwwlw== X-CSE-MsgGUID: KyHdUvHKQ+mwrCRxqQUDzg== X-IronPort-AV: E=Sophos;i="6.06,187,1705388400"; d="asc'?scan'208";a="18453223" X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Feb 2024 04:40:33 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 27 Feb 2024 04:40:10 -0700 Received: from wendy (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Tue, 27 Feb 2024 04:40:08 -0700 Date: Tue, 27 Feb 2024 11:39:25 +0000 From: Conor Dooley To: Charlie Jenkins CC: Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , Evan Green , =?iso-8859-1?Q?Cl=E9ment_L=E9ger?= , Eric Biggers , Elliot Berman , Charles Lohr , , Subject: Re: [PATCH v4 2/2] riscv: Set unalignment speed at compile time Message-ID: <20240227-condone-impeach-9469dffc6b47@wendy> References: <20240216-disable_misaligned_probe_config-v4-0-dc01e581c0ac@rivosinc.com> <20240216-disable_misaligned_probe_config-v4-2-dc01e581c0ac@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="qwP6EXChpel/sZvo" Content-Disposition: inline In-Reply-To: <20240216-disable_misaligned_probe_config-v4-2-dc01e581c0ac@rivosinc.com> --qwP6EXChpel/sZvo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 16, 2024 at 12:33:19PM -0800, Charlie Jenkins wrote: > Introduce Kconfig options to set the kernel unaligned access support. > These options provide a non-portable alternative to the runtime > unaligned access probe. >=20 > To support this, the unaligned access probing code is moved into it's > own file and gated behind a new RISCV_PROBE_UNALIGNED_ACCESS_SUPPORT > option. >=20 > Signed-off-by: Charlie Jenkins > --- > arch/riscv/Kconfig | 58 +++++- > arch/riscv/include/asm/cpufeature.h | 30 +++- > arch/riscv/kernel/Makefile | 6 +- > arch/riscv/kernel/cpufeature.c | 255 ----------------------= ---- > arch/riscv/kernel/misaligned_access_speed.c | 265 ++++++++++++++++++++++= ++++++ > arch/riscv/kernel/probe_emulated_access.c | 64 +++++++ > arch/riscv/kernel/sys_hwprobe.c | 25 +++ > arch/riscv/kernel/traps_misaligned.c | 54 +----- > 8 files changed, 442 insertions(+), 315 deletions(-) >=20 > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index bffbd869a068..3cf700adc43b 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -690,25 +690,71 @@ config THREAD_SIZE_ORDER > config RISCV_MISALIGNED Why can we not make up our minds on what to call this? The majority of users are "unaligned" but the file you add and this config option are "misaligned." > bool "Support misaligned load/store traps for kernel and userspace" > select SYSCTL_ARCH_UNALIGN_ALLOW > + depends on RISCV_PROBE_UNALIGNED_ACCESS || RISCV_EMULATED_UNALIGNED_ACC= ESS > default y > help > Say Y here if you want the kernel to embed support for misaligned > load/store for both kernel and userspace. When disable, misaligned > accesses will generate SIGBUS in userspace and panic in kernel. > =20 > +choice > + prompt "Unaligned Accesses Support" > + default RISCV_PROBE_UNALIGNED_ACCESS > + help > + This selects the hardware support for unaligned accesses. This > + information is used by the kernel to perform optimizations. It is also > + exposed to user space via the hwprobe syscall. The hardware will be > + probed at boot by default. > + > +config RISCV_PROBE_UNALIGNED_ACCESS > + bool "Probe for hardware unaligned access support" > + help > + During boot, the kernel will run a series of tests to determine the > + speed of unaligned accesses. This is the only portable option. This > + probing will dynamically determine the speed of unaligned accesses on > + the boot hardware. > + > +config RISCV_EMULATED_UNALIGNED_ACCESS > + bool "Assume the CPU expects emulated unaligned memory accesses" > + depends on NONPORTABLE This is portable too, right? > + select RISCV_MISALIGNED > + help > + Assume that the CPU expects emulated unaligned memory accesses. > + When enabled, this option notifies the kernel and userspace that > + unaligned memory accesses will be emulated by the kernel. > To enforce > + this expectation, RISCV_MISALIGNED is selected by this option. Drop this IMO, let Kconfig handle displaying the dependencies. > + > +config RISCV_SLOW_UNALIGNED_ACCESS > + bool "Assume the CPU supports slow unaligned memory accesses" > + depends on NONPORTABLE > + help > + Assume that the CPU supports slow unaligned memory accesses. When > + enabled, this option improves the performance of the kernel on such > + CPUs. Does it? Are you sure that generating unaligned accesses on systems where they are slow is a performance increase? That said, I don't really see this option actually doing anything other than setting the value for hwprobe, so I don't actually know what the effect of this option actually is on the kernel's performance. Generally I would like to suggest a change from "CPU" to "system" here, since the slow cases that exist are mostly because the unaligned access is actually emulated in firmware. > However, the kernel will run much more slowly, or will not be > + able to run at all, on CPUs that do not support unaligned memory > + accesses. > + > config RISCV_EFFICIENT_UNALIGNED_ACCESS > bool "Assume the CPU supports fast unaligned memory accesses" > depends on NONPORTABLE > select DCACHE_WORD_ACCESS if MMU > select HAVE_EFFICIENT_UNALIGNED_ACCESS > help > - Say Y here if you want the kernel to assume that the CPU supports > - efficient unaligned memory accesses. When enabled, this option > - improves the performance of the kernel on such CPUs. However, the > - kernel will run much more slowly, or will not be able to run at all, > - on CPUs that do not support efficient unaligned memory accesses. > + Assume that the CPU supports fast unaligned memory accesses. When > + enabled, this option improves the performance of the kernel on such > + CPUs. However, the kernel will run much more slowly, or will not be > + able to run at all, on CPUs that do not support efficient unaligned > + memory accesses. > + > +config RISCV_UNSUPPORTED_UNALIGNED_ACCESS This option needs to be removed. The uabi states that unaligned access is supported in userspace, if the cpu or firmware does not implement unaligned access then the kernel must emulate it. > + bool "Assume the CPU doesn't support unaligned memory accesses" > + depends on NONPORTABLE > + help > + Assume that the CPU doesn't support unaligned memory accesses. Only > + select this option if there is no registered trap handler to emulate > + unaligned accesses. > =20 > - If unsure what to do here, say N. > +endchoice > =20 > endmenu # "Platform type" > diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm= /cpufeature.h > index eb3ac304fc42..928ad3384406 100644 > --- a/arch/riscv/include/asm/cpufeature.h > +++ b/arch/riscv/include/asm/cpufeature.h > @@ -33,10 +33,26 @@ extern struct riscv_isainfo hart_isa[NR_CPUS]; > =20 > void riscv_user_isa_enable(void); > =20 > -#ifdef CONFIG_RISCV_MISALIGNED > +#if defined(CONFIG_RISCV_MISALIGNED) > +#if defined(CONFIG_RISCV_PROBE_UNALIGNED_ACCESS) > bool unaligned_ctl_available(void); > bool check_unaligned_access_emulated(int cpu); > void unaligned_emulation_finish(void); > +#elif defined(CONFIG_RISCV_EMULATED_UNALIGNED_ACCESS) > +static inline bool unaligned_ctl_available(void) > +{ > + return true; > +} > + > +static inline bool check_unaligned_access_emulated(int cpu) > +{ > + return true; > +} > + > +static inline void unaligned_emulation_finish(void) {} > +#else > +#error "CONFIG_RISCV_MISALIGNED is only supported if CONFIG_RISCV_PROBE_= UNALIGNED_ACCESS or CONFIG_RISCV_EMULATED_UNALIGNED_ACCESS is selected." Why is this an error? Enforce this in Kconfig (you already have) and drop the clause. Cheers, Conor. --qwP6EXChpel/sZvo Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCZd3J7QAKCRB4tDGHoIJi 0ia+AQCU5YCXF9J0kaM+Tt9OAbetH7+JzZR2O/sLLeCFxZg9GQD+KADsdA0Xelx3 k1fmt+5ayKCVcruP4O6xdFtjtpGOUgo= =fwKH -----END PGP SIGNATURE----- --qwP6EXChpel/sZvo--