Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp969616rdb; Sun, 1 Oct 2023 13:31:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMT7RxALGMv9zREgFZVRxtA7aY2JPcmbJDx0YbTErdFt0xiFFr4NUM8IR+TmGB+y7aJvvU X-Received: by 2002:a05:6808:1910:b0:3ae:170f:a39b with SMTP id bf16-20020a056808191000b003ae170fa39bmr15139234oib.17.1696192263119; Sun, 01 Oct 2023 13:31:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696192263; cv=none; d=google.com; s=arc-20160816; b=kS1MDwtZ+vzLHLDiNO0A38Tgjt7+lbacu+qApdxEVwIFp+fwDGn2xgGMq7KaU5gSxB mT6eEcyD06b7fujl6zvmQNqaPUPphVtnFtWdxK2uFziJXT9FDMy9AhFbDV1hATKUPmQd sYv5007TVFx+FJ18TISTDt2vrbW28DjtBlpUlujE4B2G71EUEoz1atoGpZRICT3BpQRz YY0QJ/zSZSIu+piqtcnDchcQXb76h+U+m8dDUT9wjYIpQpO4ka4XCmk3UDP/YXBhJNg3 ix+Djrdg6wbpPFU5TBBg00wUXHer4WGerIbBghfop/+JOP8ppz2eKL167ZlA0oVwvvpm lb+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=u1n+ZWsHXBr8FhnGB0kWER6c5yvJ+Tmgd0dVGu15OJg=; fh=D/2WpD/FTfktLra+44nV6aoAOzKjvabgolyn1E2WqLA=; b=Qo9m/xDQyslCkDj8MhM+ofOi2y4dBR8xHleSwjOtz4Rfiqui9maePdMdFnDlbxDDtp G6MdXBSrgV8ILaAN56Gh2Hnse2bsrBuQgjDsaLUYcx5s/DnFSwtpvVUkJAkcf4qyIMQ8 DCYVv7y3ksyrTY63tTk+wGVbe2+V77RIUjcIqC1avaiPA3NlJvslps6lR0pxX+ukbly2 m5b2iINnOUfyIGr/bhX1iB4I17HaXuzO0Tr4g8lu36lKakXggoqYWQKmB53M4ctQr+S9 8HmNPGShShH2WJMEJF7jxZ9JQPy7TwNvdWHOGmAk+al2VePneMayy13I3RZot762A3Hl nRgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="WXCVxI/w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id o13-20020a170903210d00b001c0953d0055si9905589ple.262.2023.10.01.13.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 13:31:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="WXCVxI/w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id E263780DBAC3; Sun, 1 Oct 2023 13:22:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235375AbjJAUVo (ORCPT + 99 others); Sun, 1 Oct 2023 16:21:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235346AbjJAUVm (ORCPT ); Sun, 1 Oct 2023 16:21:42 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 285A3A7 for ; Sun, 1 Oct 2023 13:21:39 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-99c136ee106so2184713466b.1 for ; Sun, 01 Oct 2023 13:21:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1696191697; x=1696796497; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=u1n+ZWsHXBr8FhnGB0kWER6c5yvJ+Tmgd0dVGu15OJg=; b=WXCVxI/wBzliWVLUw0z6FjGmBfcUXdBKvf9l1NbAzk+sxqiE9GtZGfATXONdFYtAGa pBvOR+ZZwRIElxeT0GvtHkRQGCAMELllUeo64Frr0zlzIpZuv5t15oLUI0TrYIj5UTzR d3fI7WxZ2Q403IjeKRFs9BGUZPeZXF8KAWj58= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696191697; x=1696796497; h=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=u1n+ZWsHXBr8FhnGB0kWER6c5yvJ+Tmgd0dVGu15OJg=; b=NU5nYIoEH2vDw2rSMzID4e010/bBPQPFQadtwMveaTC356ilmHRDzYT6xiqWCKkOic p4X/lpFtpVLsv1QuEb9oLaH0UlYtuSkGvRxVaOOX0mxhg0oOIr4OPPd8o/FCfrJxiirQ fv5yhnWSId+KaRnSS8hkup/z9/m2xsM2tkww4wqJV2nlBynz3FWJXDm2EySzWaxZOTVI kTSyzQdf8hfKAsbdf7tMXuyrcDrwri8jXpWA312JHgjs+dJDvWVvi2cxyrgoTdXIQ64/ Fv7tr/r+CgPVf0VlVnb4Pr3liXwLCEqbLwXMMC3uM75ihu/GvH3ETlklUl24bqYRvJkX x2ww== X-Gm-Message-State: AOJu0YwBWbjrKZvpPhZ9bhmoTrjFNcnvQZ/sCn1iMSIIfmYRfcs8hvVH 4+8KH5tmHR2sJ2DTsGIbW3h+g3inepHHo5rN9rIEgw== X-Received: by 2002:a17:906:328b:b0:9ae:658f:a80a with SMTP id 11-20020a170906328b00b009ae658fa80amr8357288ejw.48.1696191697356; Sun, 01 Oct 2023 13:21:37 -0700 (PDT) Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com. [209.85.208.44]) by smtp.gmail.com with ESMTPSA id lf23-20020a170906ae5700b00991d54db2acsm15834780ejb.44.2023.10.01.13.21.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 01 Oct 2023 13:21:36 -0700 (PDT) Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-533d9925094so17466346a12.2 for ; Sun, 01 Oct 2023 13:21:36 -0700 (PDT) X-Received: by 2002:a05:6402:1257:b0:530:77e6:849f with SMTP id l23-20020a056402125700b0053077e6849fmr8682600edw.27.1696191696452; Sun, 01 Oct 2023 13:21:36 -0700 (PDT) MIME-Version: 1.0 References: <20231001131620.112484-1-ubizjak@gmail.com> In-Reply-To: From: Linus Torvalds Date: Sun, 1 Oct 2023 13:21:16 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 0/4] x86/percpu: Use segment qualifiers To: Uros Bizjak Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Andy Lutomirski , Ingo Molnar , Nadav Amit , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Peter Zijlstra , Thomas Gleixner , Borislav Petkov , Josh Poimboeuf Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 agentk.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 (agentk.vger.email [0.0.0.0]); Sun, 01 Oct 2023 13:22:19 -0700 (PDT) On Sun, 1 Oct 2023 at 12:53, Uros Bizjak wrote: > > Regarding x86 target specific code, the same functionality used for > explicit address space is used internally to handle __thread > qualifier. Ok, that's interesting, in that __thread is certainly widely used so it will have seen testing. > Even *if* there are some issues with aliasing, the kernel > is immune to them due to > > KBUILD_CFLAGS += -fno-strict-aliasing It's not aliasing I'd worry about. It's correctness. And indeed, the *very* first thing I tried shows that this is all very very buggy in gcc. What did I try? A simple memory copy with a structure assignment. Try to compile this: #include struct a { long arr[30]; }; __seg_fs struct a m; void foo(struct a *dst) { *dst = m; } using the kernel compiler options (it's the "don't use sse/avx" ones that matter): gcc -mno-avx -mno-sse -O2 -S t.c and look at the end result. It's complete and utter sh*t: foo: xorl %eax, %eax cmpq $240, %rax jnb .L5 .L2: movzbl %fs:m(%rax), %edx movb %dl, (%rdi,%rax) addq $1, %rax cmpq $240, %rax jb .L2 .L5: ret to the point that I can only go "WTF"? I mean, it's not just that it does the copy one byte at a time. It literally compares %rax to $240 just after it has cleared it. I look at that code, and I go "a five-year old with a crayon could have done better". In other words, no, we're not using this thing that generates that kind of garbage. Somebody needs to open a bugzilla entry for this kind of code generation. 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 ready for prime-time. If literally the *first* thing I thought to test was this broken, what 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 support tested". The answer is "not at all". Linus