Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp477462rdb; Thu, 19 Oct 2023 09:32:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjrnspWtlV4ALg2R3cTblFnSeYpyOKbpzBkk+pNPN/jEWkolPSZTPFj0kbMFsZASIjomVA X-Received: by 2002:a17:902:ea09:b0:1c1:f6d1:3118 with SMTP id s9-20020a170902ea0900b001c1f6d13118mr3074472plg.27.1697733176674; Thu, 19 Oct 2023 09:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697733176; cv=none; d=google.com; s=arc-20160816; b=fdQW2FXzHHOt+ltyle2TjUCLGxj/WGRbaYagNXeXcZow3J4QNHOpoivuv8X0SvPVh9 1okO1obMVDrVrT1aysBNlx8V1MgCjgDSCOS0IsD/b9MKKQ0Xo5Wag5uG85/bORJfhmbx GQp8YguNFHfsN/lp0Yfiqv0ScMMRyHvF245HIrxFcGriAPa9WZFbtplhhDXAbaUk/ugc +GLXAQ/m8LAI58aQQfBqIbT0RKc/nA8GeKCX2V1SRdowW6HhB4VIx2nZ3ergB/yE1DvT ECTtk26jX7OWGSSM7dS4uJOK2pJl1xEtCxEUFRZe0wPesZeNyr+mhOQL+h2bGWxYblqx agOg== 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=vVTjD06nPjN4qlm/QAgywdMGwl3XPRjema1T2xfU6+4=; fh=/Dnf++/2xG0Xi30TGscvcX3UaoYjzLSxPPap0bUcRsE=; b=EhdPd6+UGtAiLgkVbv5isLE7KkzSjRfP84xhKZUMUyHgknLO2OJd/Uzy9sufp6MB7O 6LNMv9yxj9xs40o6h93DbNCf6pLhDDQkNo6gIwiyT+3Q8zvvutwelkE0N6muV3P4Z65p 9rBSUmN/iHEfKQEG7wW7yXbX7ZtrUgj2vlGR3PeUVKdahGheUITRBWyCW9CDyh4os5lF Phdnn7L4G18C3sBXa9RK+LMwbzk1eeStpy6rRV77Ff4BVAO0uTPtQrE9OiE20Sx7hBbL 8tVRsdOk9Ry8pieM5Ihp9eCk1oCUW7pB/EJ/LgOfjxtUQ61XdelwLBQ69qIJxzhJ0KfX Pp6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DOXoNpJE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id u1-20020a170902e80100b001bbbbb61c71si2742146plg.399.2023.10.19.09.32.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 09:32:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DOXoNpJE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 776CD825F121; Thu, 19 Oct 2023 09:32:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233027AbjJSQcl (ORCPT + 99 others); Thu, 19 Oct 2023 12:32:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231837AbjJSQcj (ORCPT ); Thu, 19 Oct 2023 12:32:39 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AFCC11D for ; Thu, 19 Oct 2023 09:32:37 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-53db3811d8fso2163038a12.1 for ; Thu, 19 Oct 2023 09:32:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697733155; x=1698337955; 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=vVTjD06nPjN4qlm/QAgywdMGwl3XPRjema1T2xfU6+4=; b=DOXoNpJEJx1Nb5cq3Z6dADVHqYFZnoo7Y0jGhQkM7mGHnNem4DN1ZTYFeOKU/W8zLd ZiSfsHE2I3bU78k9RP7uOBywd93rVdpskwQkDPGEqu9NOl3Gs5xc2cXU3YQcSNfQMODz CgtKmHtzRhxv3kVtZUuHnv6WIyrBUIhW6OSGlLZsay2Fobvyr3MnpJo3gwSZzGX3FvW/ QpbKUNCIIxxGh+DwQUvwyRQGWgwn/Qz+wBPabG3VhNf9E3CPJay099IV2WJY5gdEkliH aT/1yv3fDHihfvRsYeTD9FpJKUVFGGj5zCOxmeQup7JflKnFdXXnxChFIOwrv+AwCiaW Ql8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697733155; x=1698337955; 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=vVTjD06nPjN4qlm/QAgywdMGwl3XPRjema1T2xfU6+4=; b=Y4IW4VQo0ktIPaofTS8fuzgOUs2h2/U0V0UMcTn0ZPL2a+L6nvpYEHhUHzI4nEXBQl Py4AV19KvlYzMNGAi4zlpHZeFkzLV7fkN4Vdw7UTYTg1iLYD8Zc5QYsbKlSoPtup6sih 48bGHZS6d9bGAswEY+rfCKoW1tD5W5fMwyz5D9ULp0sKb7mKnsCjHcK1lDrIQf21MqZp jRfyaXlYyA+dyXaPTompmw+r1WsA3wNcT+Yxcj7ZQnP4U2R1yH+Q15LMhvVyOZU2HAvA VskFxJpkHeCQMpoUUmTOKkIVklwHbmCFu6hyz2Udk+9Nm0LrLjWZ/lah4AW5DWQbneq6 /Qvg== X-Gm-Message-State: AOJu0YzNKI9KBmYJVNnNvda6RoxoalzlsLSO1N0dNu58+SegqA6epYdv DHzrLAkARkQpsbRUHstyav5cFbcTwkuuOfxXcsxh4zJnKks5ORMt X-Received: by 2002:a50:cc03:0:b0:533:4a89:5b2e with SMTP id m3-20020a50cc03000000b005334a895b2emr2237858edi.1.1697733155449; Thu, 19 Oct 2023 09:32:35 -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: Thu, 19 Oct 2023 18:32:21 +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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 19 Oct 2023 09:32:54 -0700 (PDT) On Wed, Oct 18, 2023 at 10:22=E2=80=AFPM Linus Torvalds wrote: > > On Wed, 18 Oct 2023 at 12:33, Uros Bizjak wrote: > > > > This pach works for me: > > Looks fine. > > But you actually bring up another issue: > > > BTW: I also don't understand the comment from include/linux/smp.h: > > > > /* > > * Allow the architecture to differentiate between a stable and unstabl= e read. > > * For example, x86 uses an IRQ-safe asm-volatile read for the unstable= but a > > * regular asm read for the stable. > > I think the comment is badly worded, but I think the issue may actually b= e real. > > One word: rematerialization. > > The thing is, turning inline asm accesses to regular compiler loads > has a *very* bad semantic problem: the compiler may now feel like it > can not only combine the loads (ok), but also possibly rematerialize > values by re-doing the loads (NOT OK!). > > IOW, the kernel often has very strict requirements of "at most once" > behavior, because doing two loads might give different results. > > The cpu number is a good example of this. > > And yes, sometimes we use actual volatile accesses for them > (READ_ONCE() and WRITE_ONCE()) but those are *horrendous* in general, > and are much too strict. Not only does gcc generally lose its mind > when it sees volatile (ie it stops doing various sane combinations > that would actually be perfectly valid), but it obviously also stops > doing CSE on the loads (as it has to). > > So the "non-volatile asm" has been a great way to get the "at most > one" behavior: it's safe wrt interrupts changing the value, because > you will see *one* value, not two. As far as we know, gcc never > rematerializes the output of an inline asm. So when you use an inline > asm, you may have the result CSE'd, but you'll never see it generate > more than *one* copy of the inline asm. > > (Of course, as with so much about inline asm, that "knowledge" is not > necessarily explicitly spelled out anywhere, and it's just "that's how > it has always worked"). Perhaps you will be interested in chapter 6.47.2.1, "Volatile" of GCC manual that says: " Under certain circumstances, GCC may duplicate (or remove duplicates of) your assembly code when optimizing." The compiler may re-materialize non-volatile asm in the same way it may re-materialize arguments from non-volatile memory. To avoid this, volatile asm is necessary when unstable memory arguments are accessed using this_* variants. Uros.