Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp403280lqg; Thu, 11 Apr 2024 06:40:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVM+b7paZG8xyWp0rJ70Fcms0lWPVyD6wmycgclaZSmsVpfDkZqJceOJjKUJpQVaayoSgq6sHC3b4xS5XCrTOmnjopRKK7hhUaYFfl4TA== X-Google-Smtp-Source: AGHT+IE+4xCnFgrlbQW86FCfhKafsRrsep4MFwVOX1eUrUox8/KIUWrXN5qNuuJUETq+OLrmq+lv X-Received: by 2002:a05:6e02:1feb:b0:36a:2538:d70d with SMTP id dt11-20020a056e021feb00b0036a2538d70dmr6255016ilb.28.1712842843964; Thu, 11 Apr 2024 06:40:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712842843; cv=pass; d=google.com; s=arc-20160816; b=ifAAVDpqKHmeQcXCFQ3v38vwdVCF0WoRp2ZvbLqnRAZQh5w296dokp29TLcrwMkAhC s0F0s58fBvdoQV2xIv3iXJBnkeq65SS+VzmQ7z4YUHAZKrp7sq/ttLjicSm+D1BEjznY rGOrHaaT8HO8nZqVKQKuFGe39HpGLTr9ZCoq+AKRrOORAy0blwZtcasyrJWcGJegS6sC roLr3Kek1eVnol0SfiONIsZzJ7zHTyR3bVyHuw2M693YfqRrC84GUXbu3w0tmrHyvP2/ MepN/moCPtew5tHvOKYt+wMXWv8khVivaLp5MW4Ome/VSlcy2s27myk4b6knjwQlng5L Vw6A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent: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=2lD57MeXBu50AgNIsbRnVapmimztsk2CZ+KFufM9FWg=; fh=+la4B1/V5qoHqqlXLW/XwKd6CEFLK0nQaKDdA/6WLWE=; b=YpqSyiD3VylvboK1Q2ywuWR2ngI/Voz97DmOXLtob9joSjhG/Uj5yBetvFZNST8OT6 b6o6Y/oV4obxly2y7gXRiNRcz/jFiJhf8Xxlw2K9tX+dUy/j+ZKpqqLbhdKOjfnA/oXd XnLyqDaDdeiqCgAjOE+hpVeBdkYM2STffUzolPnUD0rmTYFaKLxNdL8lmZOsbRq0DjTr 2STCpoSAQvzIHXR4tpuyDT7ZWQhgMjXEUCdglvnCQZBAXE0uj9Ci23NqY4PoATTqKctc cfdwediF+40BL9sanbIC4GE10jd50DKvx9gbzKCPOCZpK3jPdahhuas7U9DwEn+ghVgc oKPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fKoSzUBS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-140506-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140506-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 j15-20020a63e74f000000b005f4371d151dsi1295059pgk.212.2024.04.11.06.40.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 06:40:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140506-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=@kernel.org header.s=k20201202 header.b=fKoSzUBS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-140506-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140506-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 704BEB261FD for ; Thu, 11 Apr 2024 13:29:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1285314EC5C; Thu, 11 Apr 2024 13:29:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fKoSzUBS" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3360714D432; Thu, 11 Apr 2024 13:29:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712842144; cv=none; b=bf6RsdA8sSUx4ADsfPzEHnhWHfJUrml+3xdQGdT0a9jkv5bCYD48ObUhoukAefF+DLpoaueUJAOgTCuhHHYDM/KwmrReV8qRQ4aS70sDIhth1DZcVo9RJiEe6ySwdre/K0Y4MQzhRcuz2WGww/md12BB8k2kphlp6tD6MWJMZdY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712842144; c=relaxed/simple; bh=gUdPGNpqUc9YmdjxtvqHwxuSQo6lbsOe/wMJ91M4o0o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DJkm3g2Os+vZ3BMaGz4CXZSo4RRVmXXj9EB2rUm90bPvMEAmk2Q2AIM2E4Dpmvk1AJkKLBjuAchpO1k4CiUpFmdgsx4hKg4JejtdS4A43k5kK921Cw3Z8JDLfxaQZk9iDODh+VKrlQj5GgrJ1swoRh73S2CcLh+waK1Nqoxqovc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fKoSzUBS; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DB70C2BBFC; Thu, 11 Apr 2024 13:23:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712841795; bh=gUdPGNpqUc9YmdjxtvqHwxuSQo6lbsOe/wMJ91M4o0o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fKoSzUBSJR3KbMhdCG1CHI6hpF0gXlRuAvgMgnJu3Btuu7SakSzaUvgpYTcIqkIEc jgmJGBdpkyTo0lA+qAr0005WzjFF+rKzBEeaWW2AJ1BxyLdtuuDmzyM+CHRqXSfxEs H6rZNWX8bJ7fmqEkP4X4qFKPD24zqJfBSDiSWnTE+jSaqUrzTf5mGMl/ZZg4s1fYdp ucoWdQToXGS8Xvysk5dNy3OEIQzLISY9ijErrqIZQ6csx46lZ6JO76X+mukuZXZdQH LCzebE+5MA3IfDrazx2LsqtBN2CHGRafShYpWzoI7CTN5Xsx+GrJsNV0g5/lUIAOxk gLYmU8Zrcw2Gw== Date: Thu, 11 Apr 2024 14:28:54 +0100 From: Will Deacon To: Hector Martin Cc: Catalin Marinas , Marc Zyngier , Mark Rutland , Zayd Qumsieh , Justin Lu , Ryan Houdek , Mark Brown , Ard Biesheuvel , Mateusz Guzik , Anshuman Khandual , Oliver Upton , Miguel Luis , Joey Gouly , Christoph Paasch , Kees Cook , Sami Tolvanen , Baoquan He , Joel Granados , Dawei Li , Andrew Morton , Florent Revest , David Hildenbrand , Stefan Roesch , Andy Chiu , Josh Triplett , Oleg Nesterov , Helge Deller , Zev Weiss , Ondrej Mosnacek , Miguel Ojeda , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Asahi Linux Subject: Re: [PATCH 0/4] arm64: Support the TSO memory model Message-ID: <20240411132853.GA26481@willie-the-truck> References: <20240411-tso-v1-0-754f11abfbff@marcan.st> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240411-tso-v1-0-754f11abfbff@marcan.st> User-Agent: Mutt/1.10.1 (2018-07-13) Hi Hector, On Thu, Apr 11, 2024 at 09:51:19AM +0900, Hector Martin wrote: > x86 CPUs implement a stricter memory modern than ARM64 (TSO). For this > reason, x86 emulation on baseline ARM64 systems requires very expensive > memory model emulation. Having hardware that supports this natively is > therefore very attractive. Such hardware, in fact, exists. This series > adds support for userspace to identify when TSO is available and > toggle it on, if supported. I'm probably going to make myself hugely unpopular here, but I have a strong objection to this patch series as it stands. I firmly believe that providing a prctl() to query and toggle the memory model to/from TSO is going to lead to subtle fragmentation of arm64 Linux userspace. It's not difficult to envisage this TSO switch being abused for native arm64 applications: * A program no longer crashes when TSO is enabled, so the developer just toggles TSO to meet a deadline. * Some legacy x86 sources are being ported to arm64 but concurrency is hard so the developer just enables TSO to (mostly) avoid thinking about it. * Some binaries in a distribution exhibit instability which goes away in TSO mode, so a taskset-like program is used to run them with TSO enabled. In all these cases, we end up with native arm64 applications that will either fail to load or will crash in subtle ways on CPUs without the TSO feature. Assuming that the application cannot be fixed, a better approach would be to recompile using stronger instructions (e.g. LDAR/STLR) so that at least the resulting binary is portable. Now, it's true that some existing CPUs are TSO by design (this is a perfectly valid implementation of the arm64 memory model), but I think there's a big difference between quietly providing more ordering guarantees than software may be relying on and providing a mechanism to discover, request and ultimately rely upon the stronger behaviour. An alternative option is to go down the SPARC RMO route and just enable TSO statically (although presumably in the firmware) for Apple silicon. I'm assuming that has a performance impact for native code? Will P.S. I briefly pondered the idea of the kernel toggling the bit in the ELF loader when e.g. it sees an x86 machine type but I suspect that doesn't really help with existing emulators and you'd still need a way to tell the emulator whether or not it was enabled.