Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1844108rdb; Tue, 3 Oct 2023 02:49:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDJfyEejQFGDg4mzZVq/tTh9Z6YuU4+K9XjFpJJulFmra9xfQHEhElUXLMEZc3G9CVgbJR X-Received: by 2002:a54:4e81:0:b0:3a7:215c:e34 with SMTP id c1-20020a544e81000000b003a7215c0e34mr15281152oiy.15.1696326585562; Tue, 03 Oct 2023 02:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696326585; cv=none; d=google.com; s=arc-20160816; b=qhHEgHl9Kr5u5y+JBKAE7WubJhbLcQ07D7oW8qy4RBuU7z4+SJA9jq3V7P3IL6kT9y UNgk1lUIutcoPXIvtLAjLnRDORiaz1XiLhdNOBSy1fcFgqmQTL77rw5ZbB22OG92nvPM sx9dprbad+2eELsTzo9kVQql5xqvTlhKT9vr6x4Hmu5v9TiP4i6r3b97Hl+mz90aseIA ZQSGBQESQHak0leOt/7+8mltGLNfkdZQCZusyro7+uqdnPPEYOy2aqnbrdy+kwy1rVwt S5guPP3AJdaptXOKaFxYPfXHp8z2eDPOZ0PjNUYWFFq1WlxLODXj1QQhU2sEphLyOvAk /R1g== 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=E+N+tVGAA5egSmR75YiQ67ulIObp4L3VVB963HxoCgE=; fh=zwbJigGmtMHN6vqrIjVFPd/SX3dFuUxXArUvHNQE/uY=; b=E/036LbFs+RCwcyePSEacWStJ2OaOf7QHhGrqNsmbYTJPF7S20JCgnNgGG1czIcWGc F0+QnlnsHQQt/bbiye6Ag8wk+kDzNF0Q0vO+hhxheMGmiWQYbUeNZGAMo0Ir1FwtFM3M qnN5FeCLTmohcg82D/aoi3vSo4+ImICkRFcOwRkRh/mU837kcjd9T4y1PnPJLR6Keepf obPtWsoIi6MBeXwmJ2G3mVUGhAemAMWQqwZoPRJNSgZmlvM74FFaQ/GxqoB3yV9uc/sT KR4F6Fsul1eqoKmWh7rkuVL2XSBj6IooIjd2QI+/fUIvPZ+9+mUM+v81sk+Yj0liaqev KaVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Od5i2V2I; 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 r88-20020a17090a43e100b00277507f542bsi1071719pjg.156.2023.10.03.02.49.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 02:49:45 -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=Od5i2V2I; 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 4DE8A80BB56A; Tue, 3 Oct 2023 02:49:42 -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 S231968AbjJCJtR (ORCPT + 99 others); Tue, 3 Oct 2023 05:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231633AbjJCJtQ (ORCPT ); Tue, 3 Oct 2023 05:49:16 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 679EB91 for ; Tue, 3 Oct 2023 02:49:13 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-99de884ad25so117492066b.3 for ; Tue, 03 Oct 2023 02:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696326552; x=1696931352; 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=E+N+tVGAA5egSmR75YiQ67ulIObp4L3VVB963HxoCgE=; b=Od5i2V2IMVBvp41JP2n4jfank5c/ws6iQC6R8dDyGvsFEaNc4jhGaKsOJLTWhxnndC sHcClojGNqMJRkuElWlsxITg57E3QTRJmqpkSKUSSTPTT+5Bv1OoqfZ0ky5nu4r27Spi Pp54hPNiEFzSl8zQzf0aKH+iKQk1kulkLKkfUuJBg5UrrkYJnFs5fm2GAX+D7gE6qfpc Y4KUePs9oEI9eIgmmWqORWWFAfuCWTEDZovgViC2ozWFVX33IWrboV3YIN9kwTu5BEST Z0kqBFE7Fbl7UXfGR5XzJBo2QBV84R36XdEGmMhEqDI/uCcKWc0lyJshKCS4M5SfkOsM WDZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696326552; x=1696931352; 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=E+N+tVGAA5egSmR75YiQ67ulIObp4L3VVB963HxoCgE=; b=YXVf3BUYlPsqlDqt2hOEyDXvReHhq5IzMqxekoZBB/v1ZFcQZL6BCxbx4/BwytAYFa bKlVgvhLypz5kAgPZc9EyVES/DNdadN3Sov25YyQZMMGwKFYD6Rp4itnuFHQxaSzRB4+ ye1wdGL6mOvg2VvvUtBdyd8mt2/JvNKA2qNBU8IFeBDrIO0hlB+ouBAuHN1hjNaeD8ae BIucrOgF2hYSuU6/mt9OgB4AJjXFbkv2CtvW0r/3BMUpycvdxaQxO81d6o7ynh6SR/9N J9jwQOiJqx0FoCtaNqC+8bs0skLQgKEMf0GX7KDVPrvJgKKq8cXzlAaeUehoi2N5WWV3 D9bA== X-Gm-Message-State: AOJu0YwIjst4xUBpRyKtndxO63yGzNiuCkBw2fo6fYz8lLeBEmJQVuB4 UoCoBFR/osRWvMvzQrEhjLFaOyKbYqNb/piqdKI= X-Received: by 2002:a17:906:bca:b0:9b2:b149:b81a with SMTP id y10-20020a1709060bca00b009b2b149b81amr10462422ejg.64.1696326551645; Tue, 03 Oct 2023 02:49:11 -0700 (PDT) MIME-Version: 1.0 References: <20231001131620.112484-1-ubizjak@gmail.com> In-Reply-To: From: Uros Bizjak Date: Tue, 3 Oct 2023 11:49:00 +0200 Message-ID: Subject: Re: [RFC PATCH 0/4] x86/percpu: Use segment qualifiers To: Ingo Molnar Cc: Linus Torvalds , x86@kernel.org, linux-kernel@vger.kernel.org, Andy Lutomirski , Nadav Amit , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Peter Zijlstra , Thomas Gleixner , Borislav Petkov , Josh Poimboeuf 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]); Tue, 03 Oct 2023 02:49:42 -0700 (PDT) On Mon, Oct 2, 2023 at 3:22=E2=80=AFPM Ingo Molnar wrote= : > > > * Uros Bizjak wrote: > > > > > Clang isn't much better, but at least it doesn't generate bad code.= It > > > > just crashes with an internal compiler error on the above trivial > > > > test-case: > > > > > > > > fatal error: error in backend: cannot lower memory intrinsic in > > > > address space 257 > > > > > > > > which at least tells the user that they can't copy memory from that > > > > address space. But once again shows that no, this feature is not re= ady > > > > for prime-time. > > > > > > > > If literally the *first* thing I thought to test was this broken, w= hat > > > > else is broken in this model? > > > > > > > > And no, the kernel doesn't currently do the above kinds of things. > > > > That's not the point. The point was "how well is this compiler supp= ort > > > > tested". The answer is "not at all". > > > > I don't agree with the above claims. The generated code was the product > > of a too limited selection of available copy algorithms in unusual > > circumstances, but even in the case of generic fallback code, the > > generated code was *correct*. As said in the previous post, and > > re-confirmed by the patch in the PR, the same code in GCC handles > > implicit (__thread) and named address spaces. At the end of the day, th= e > > problematic code was merely a missing-optimization (the bug with the > > lowest severity in GCC). > > Yeah, so the feature generated really crappy code for Linus's > testcase. That's never a good sign for compiler features, full stop. > > Do we want the kernel to be at the bleeding edge of an > unusual compiler feature that is only used internally by the > compiler in a very specific fashion? I understand your reservations about the new feature, but please allow me to bring up some facts about it. The feature is *far* from being an unusual internal compiler feature in GCC. It was introduced for gcc-6 (mostly for embedded targets), but in 2017 the complete thread local storage (e.g. __thread) handling was switched to named address space and released in gcc-8. I don't remember any reported problem with this feature (and I know what I'm talking about, the switch to named AS in the compiler was done by myself [1]). Since named AS uses the same compiler code, I'm quite confident that it shouldn't be considered a bleeding edge unusual compiler feature. The "crappy code" happened due to the limitation in the completely different part of the compiler. It was stringop algorithm selection, a feature orthogonal to address spaces (tangential only in the sense that several algorithms are not available with non-default address space). Colorful language notwithstanding, the generated code is nothing more than "missed-optimization" and the gcc bugreport was qualified as that. With -mstringop-strategy=3Dloop, the testcase produces expected code, and the stringop selection in the compiler will be adjusted accordingly also for the very limited selection of stringop algorithms for named AS. Even when the kernel will never use these algorithms for its percpu functionality... > Maybe, but Linus's reluctance and caution is justified IMHO, > and at minimum this feature needs some careful evaluation of > long-time suitability [*] ... I do have a proposal on how to introduce a new feature while minimising risk as much as possible. I must admit that detecting the feature for all released compilers that can handle __seg_gs seems quite risky (I have to curb my enthusiasm somehow ;) ), so perhaps a staged approach with a currently unreleased compiler is more appropriate. Using: +config CC_HAS_NAMED_AS + def_bool CC_IS_GCC && GCC_VERSION >=3D 140000 would enable the new feature only for currently unreleased experimental GCC. This would allow to qualify the compiler and weed out any possible problems, before the compiler is released. Please note, that the patch is written in such a way, that the code reverts to the existing approach for undefined CC_HAS_NAMED_AS. I would also like to point out additional possible improvements that are not in the proposed patch. Using named AS enables the kernel to move one step further to PIE, as noted in the original patch submission [2]. > [*] euphemism for: "I have no idea how to evaluate this risk"... :-/ [1] https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dcommitdiff;h=3Dcfc72af0fbdf [2] https://lore.kernel.org/lkml/20190823224424.15296-1-namit@vmware.com/ Thanks, Uros.