Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp4084607rdg; Wed, 18 Oct 2023 14:41:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyNG+7+cCIfd8fn3KjcpyTg0Fx1I4i6H1r7ybddU8k+tObNDp9x7M2fjl70akT00FnfTeo X-Received: by 2002:a05:6359:1a0b:b0:166:a518:d447 with SMTP id rt11-20020a0563591a0b00b00166a518d447mr208517rwb.22.1697665301606; Wed, 18 Oct 2023 14:41:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697665301; cv=none; d=google.com; s=arc-20160816; b=B2n5Uog4ccYKZqRXnr7NGC5jVWgFIKr3S1fdq6Gs9eTCTyanBpK3FTkfH7d+E7Benj 4FWETGl/tLuNJ7MjalMEmWj9levWGBlIqvsT7hSUfvIYOZTczFjGtXKxZZk0AJbGnMYk ftxlDQfm2Vk8Cmccn6jKuA2EVwmW/EUaeQSZXsWA7q2gW/A4as5qdQ7hYgK7ZYgoW7wh k8vPFTicaeL9SvBM5GDTX3cL8Co0i6piL1aGb4S6f+rl/fiCFx+nKdTLrImlTT9zC7Jo mQ/gafSProzCyZmNNO7cbQfjYzyiboLovq4cCPawTWSNHJz7zH+1pVYvRmj86c18/lzD D1wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=282qgW426ecEuopzF8jbvOzMje/HUlZNH6e92nVI8WY=; fh=/Dnf++/2xG0Xi30TGscvcX3UaoYjzLSxPPap0bUcRsE=; b=mPeTW3GIDGC+CYWb7xPV812r72/7KeRYtJcnhxCDJXslEAgvJNUoM5w+kAmzmUv3Hu nWnwdH926Oxs6cWhrzefPB5NNrcguepQ4QUZMHVOZ+bWkMrtX2dthdOKjxaQSMUZt51Q NYiKpfQ1yfC1LrKtgwJA9DiwP8GWVuLzbJ1qLnoPQhRe1+KsPKRc9McVCBJPKI1/4RoH UaERW32DJJgHHQIiBui2OF5eh1+2SK+mUo2ivj0Uf6jFqzJYlXONbBstVb+c8cRks4sl hiX/stC+UdjXKUg5jz+5ByfH9m40ObaQaae1E1wfl2Mj8v5vswo6JYwPgD+GVQ3m4fUx 9qBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ebRf3TFg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id l2-20020a656802000000b0059cdf90b9b2si2861662pgt.685.2023.10.18.14.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 14:41:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ebRf3TFg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id CC34180BC3FA; Wed, 18 Oct 2023 14:41:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbjJRVk7 (ORCPT + 99 others); Wed, 18 Oct 2023 17:40:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjJRVk6 (ORCPT ); Wed, 18 Oct 2023 17:40:58 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AB30EA for ; Wed, 18 Oct 2023 14:40:56 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-53e07db272cso11482274a12.3 for ; Wed, 18 Oct 2023 14:40:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697665255; x=1698270055; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=282qgW426ecEuopzF8jbvOzMje/HUlZNH6e92nVI8WY=; b=ebRf3TFglxricBN6ZBjV8FRTGmgKBy1gDYqT1R+4XPopDYV7NPgknezC1ZjO1NZeIa Jx6pgstOWXlso8nkjAQHYBTzTDE4IifM1HFa29DjaQ03n/OeLVpNrMOzkal+at7o0N6S ansPExPFr6a8Teo9usdsQ87spZ6PqBtXORkXyEG8AdWRnzkuSewJ0NXOAibkLHhFbmIV ubAejL8LKCKD5q8UbGnUYC7je9ZgLUrbnrNKY8XmyuI3/LXJhB/5waURTJtIhMq7Q2it +zCkh7RhHqtb3uXMb54OmQKcFgJa4e4Gxm0STTOmO1J/UKAh8TduvDsmnYzQ5TF4PR+W A34w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697665255; x=1698270055; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=282qgW426ecEuopzF8jbvOzMje/HUlZNH6e92nVI8WY=; b=KnNQmERkdIku08sa97x9U929hD/vSk1FmYfrLmMyjXdg1AoLfGAigBpvnNr10pOZZB xSiBRIadLMovD6fKefX68ke0RWDBwc393oHE38rR6ZqsmDo2OysXseBIRtMWES3iqGUU jMKDmg+mv3DavBTMGdX1N86pZ7iKtQ9SM+tBDuF1opmljNj3t3Sl8S8YZN/PwubsQoZ3 uQf0RGZKsBKU3ayO5WpJyqONf3V7Peu4nwmHxDxTq0fCZUYN7YCFhRI+jz3AzfjKyhhj /eyqI5WczKE3AfHCws0Xaez0hHCWkRj8RAYpP5yr/azaphwSngDqtkC+rhmqUdu1aRcv CaRg== X-Gm-Message-State: AOJu0Yx647Nei+idaXgcHK2aMFsoVIO18SgEOrzhtt03W7Y77Z4cMFdi Da8bTPmWAjsb4OyknQgeFp/819VW+OgdZ6rVhxM= X-Received: by 2002:a50:d79b:0:b0:53e:5cde:b3c6 with SMTP id w27-20020a50d79b000000b0053e5cdeb3c6mr163892edi.31.1697665254606; Wed, 18 Oct 2023 14:40:54 -0700 (PDT) MIME-Version: 1.0 References: <20231010164234.140750-1-ubizjak@gmail.com> <0617BB2F-D08F-410F-A6EE-4135BB03863C@vmware.com> <7D77A452-E61E-4B8B-B49C-949E1C8E257C@vmware.com> <9F926586-20D9-4979-AB7A-71124BBAABD3@vmware.com> <3F9D776E-AD7E-4814-9E3C-508550AD9287@vmware.com> <28B9471C-4FB0-4AB0-81DD-4885C3645E95@vmware.com> In-Reply-To: From: Uros Bizjak Date: Wed, 18 Oct 2023 23:40:42 +0200 Message-ID: Subject: Re: [PATCH v2 -tip] x86/percpu: Use C for arch_raw_cpu_ptr() To: Linus Torvalds Cc: Nadav Amit , "the arch/x86 maintainers" , Linux Kernel Mailing List , Andy Lutomirski , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Peter Zijlstra , Thomas Gleixner , Josh Poimboeuf , Nick Desaulniers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 18 Oct 2023 14:41:17 -0700 (PDT) On Wed, Oct 18, 2023 at 11:11=E2=80=AFPM Linus Torvalds wrote: > > On Wed, 18 Oct 2023 at 13:52, Uros Bizjak wrote: > > > > FYI: This is the reason RMW instructions in percpu.h are not (blindly) > > converted to C ops. They will remain in their (volatile or not) asm > > form because of the above reason, and due to the fact that they don't > > combine with anything. > > Well, also because converting them to C would be HORRIBYL BUGGY. > > They absolutely have to be a single instruction. We have architectures > that can't do rmw instructions, and then they have to do lots of extra > horrid crud (disable interrupts or whatever) to make a percpu 'add' be > a valid thing. > > > > Actually, RMW insns are better written in asm, while simple "mov" > > should be converted to (volatile or not) memory access. > > No. > > This remat issue has convinced me that the *only* thing that should be > converted to a memory access is the "stable" case (which in practice > is mainly just 'current'). > > Because if you make them 'volatile' memory instructions, then the > simple "mov" inline asm is simply better. It still allows CSE on the > asm (in the "raw" form). The ones in "raw" form are not IRQ safe and these are implemented without volatile qualifier. The safe variant are ones with "this" form. These were implemented as volatile-asm and are now implemented as volatile reads. They do not rematerialize, the number of memory accesses stays the same. They do not CSE (volatile-asm also doesn't), but they can propagate into follow-up instructions. > And if you make them memory instructions _without_ the 'volatile', the > memory access is simply buggy until we have some 'nomaterialize' > model. This is the reason that almost all percpu access is implemented using this_* accessors. raw_* is a relaxed version without IRQ guarantees that should be (and is) used in a controlled manner in a special places: https://elixir.bootlin.com/linux/latest/A/ident/this_cpu_read https://elixir.bootlin.com/linux/latest/A/ident/raw_cpu_read > > So the *only* situation where a memory access is better is that > 'stable' case. In all other cases they are the same or strictly worse > than 'asm'. No, argument propagation is non-existent with "asm" version. Uros.