Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp578081lqh; Tue, 7 May 2024 07:57:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9nzYExf53ViKCV4U9FcdWTwEy+EDBsrUybKxJEMAhKIEDe8zthH4iknrLYaAnztbZBK9fY4E4jWdK7YujfmytqChfRKVA3hgKy+6L5Q== X-Google-Smtp-Source: AGHT+IEl6f5EGu1sZYmVqTacMFiEyiaogO/Pfp5YfRftyjz29fVtQOtEbey8M8o8hkGgETVLG7eL X-Received: by 2002:a05:6a20:7f9b:b0:1a7:99c5:802 with SMTP id d27-20020a056a207f9b00b001a799c50802mr18690331pzj.37.1715093862859; Tue, 07 May 2024 07:57:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715093862; cv=pass; d=google.com; s=arc-20160816; b=u2dguXumausj/pL/QkhNXoxjuvPu1N9iQ1pprLHckaYw+jel+/veFyQJTWLxbf++7m V34NNI+wgKNg3AbI/xOC9T/CXCa6lU9YhDGOffCvqLYmi0QnAco+kc5+hjHaoXmrZgcd A4/yIJeYkRO7H3XAA9QxO3gk8GU0/BIgGXDOArsef8bFnJM0RLbG55JO61zUn6ZyuzK7 GLQMEUroPo4dHib9W+b3T5MOeVSeJgQ3QUvywbkfQWtVSeaGMXJPE8ButaVjRe2rGxfX 0Yo77SHWujK74pnJNK3+cu4ev2D5rIaGDCl43mOTssk1E577pKZNZkptuindxjTAltB+ Smqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=ccdcdxoTUst48BbVMc29RWX1ezrhEuEALEGynGxUPzY=; fh=hsU8yKOpo3egerRyubdPcF44xMSOE+3O1j3ZuxdZQYY=; b=Me7nB8uTEhu+LINWKpbNSCw+/Iz/vPpQrbhl4HD/PcxcaItT5u4pPJm7g2YJbYuVV3 D0L5Ee46ppzB1U6EcT9RjER4rm4GycL3ZFQ2CJH0/6Jnc7cBF6gvkA/B308WU7spsd3t v1bEHwfU9+yopWGf4uJ1Bragk59vCeXwbmchLlIpze6u/1Ec2jFNy4v9etU3ttxG91RD a04y1/QJPMI7rSyfdZjf3K86SCEle3DsqbcRp2WbL14+6pS4AoItmW3apv99I3k9OhaB 2iaqznaljuhGb2pOpbgXT5SF7sC1ZqDhWerMdgyvk1lJ2cbOim32qaC2PNxFleuD0Ixe 3QDQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="WQzhVbB/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171626-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w12-20020a056a0014cc00b006f471be24fbsi5394156pfu.272.2024.05.07.07.57.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:57:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="WQzhVbB/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171626-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 110822840FA for ; Tue, 7 May 2024 14:53:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D24A3161914; Tue, 7 May 2024 14:53:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WQzhVbB/" 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 DB1CA15FD1D for ; Tue, 7 May 2024 14:53:06 +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=1715093586; cv=none; b=VwdVbv2v2DMX4oXRXvbqY8I3Y4AR6iKnQfGYGft2dcOkvr5DAX+GvdRBFqgA5/FEpRcqNSQApgfvC59F3PFHoqPXffyLqnLGPfKILMMf5322ijPEFF55It33+pxNom+CIyCXo5Aar49k4BLJxIWixVg0HJzaSTNrFaMaJB0IiAA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715093586; c=relaxed/simple; bh=SM4uZsG+ZWU6pdCh+KmiT6fjGXAk/BqY7E2j+X8XI4c=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=D+Z8GRS1/OvZ2FG19N5T4gAtAh1m2eIk3FORBd0AWAumKyqAt4bf/Qwt3foyQW8dyaFQoeonwrwgXCF4EL7bclRWayjrdW/XZg5Sehkk85lLmyqeB4RpAe8BQxo+QBucoGpgWx4QAAzMSV6cb+v+FjRQRTGqZwwZ4rfhvGPzbu4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WQzhVbB/; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74DBAC4AF18 for ; Tue, 7 May 2024 14:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715093586; bh=SM4uZsG+ZWU6pdCh+KmiT6fjGXAk/BqY7E2j+X8XI4c=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=WQzhVbB/fda7TB78952CC1FEynnAydSEv8hqNeH4gltwW5b4TL0e3A0nCSQ3xOqy6 Y8F2H780LQc6R5wOIMk2gU7xTgHzC6y7F99/bqvdUMvVVZYh4SIRwr1v+9K7ZuL0Je Vi73J5KiYQ4zXQxxSH3OQplyxA5vgkxxKIDxOx/8PcCtjriqLBTLPkI1UdJS334dAW iweDOTMO30pkPMFhylJk44bSxlYmsiNcu0yAWBCSuaUlSj3+VjdcT1XZFpNaXUX3FP zWTA8uZsaLiPxskSEy4kc+0HarFmYtu6Gu9t5V4vcv/GenV1mKnOJxdrqofn+VacbZ jUk/BSvjVHuRw== Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2e3fa13f018so8986611fa.3 for ; Tue, 07 May 2024 07:53:06 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVutT3PO7kRVgek5P+IKZJVrInqnrUmKygLn1eCxQSKkwsV9CEqfaAk8vj4xq1u9QgDBVWi6cdUJBkXeWjoETLK9jL1WKK5r1LdHync X-Gm-Message-State: AOJu0Yz2Yzoz0897vvOCKKbMQ5mvPIDXxtGEkcu7YcRXcAPuV6HyW5gD yIxuHB+rxwipvzwCS7pSrT34kmoKNFHjaoILxgwFyNkkcT4wl38GgXls7XIqK03z/Pjk4IlatC+ 3QHT9uPbEcN5EoJmwvdlVp73BY3Y= X-Received: by 2002:a2e:a41a:0:b0:2e2:b716:e67c with SMTP id p26-20020a2ea41a000000b002e2b716e67cmr6828012ljn.7.1715093564082; Tue, 07 May 2024 07:52:44 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240411-tso-v1-0-754f11abfbff@marcan.st> <20240411132853.GA26481@willie-the-truck> <87seythqct.fsf@draig.linaro.org> In-Reply-To: <87seythqct.fsf@draig.linaro.org> From: Ard Biesheuvel Date: Tue, 7 May 2024 16:52:30 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/4] arm64: Support the TSO memory model To: =?UTF-8?B?QWxleCBCZW5uw6ll?= Cc: Will Deacon , Hector Martin , Catalin Marinas , Marc Zyngier , Mark Rutland , Zayd Qumsieh , Justin Lu , Ryan Houdek , Mark Brown , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 7 May 2024 at 12:24, Alex Benn=C3=A9e wrot= e: > > Will Deacon writes: > > > 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 expensiv= e > >> 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 thinkin= g > > 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. > > These all just seem like cases of engineers hiding from their very real > problems. I don't know if its really the kernels place to avoid giving > them the foot gun. Would it assuage your concerns at all if we set a > taint flag so bug reports/core dumps indicated we were in a > non-architectural memory mode? > > > 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 TS= O > > 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. > > I think the main use case here is for emulation. When we run x86-on-arm > in QEMU we do currently insert lots of extra barrier instructions on > every load and store. If we can probe and set a TSO mode I can assure > you we'll do the right thing ;-) > Without a public specification of what TSO mode actually entails, deciding which of those barriers can be dropped is not going to be as straight-forward as you make it out to be. Apple's TSO mode is vertically integrated with Rosetta, which means that TSO mode provides whatever Rosetta needs to run x86 code correctly, and that it could mean different things on different generations of the micro-architecture. And whether Apple's TSO is the same as Fujitsu's is anyone's guess afaik. Running a game and seeing it perform better is great, but it is not the kind of rigor we usually attempt to apply when adding support for architectural features. Hopefully, there will be some architectural support for this in the future, but without any spec that defines the memory model it implements, I am not convinced we should merge this.