Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1027500rdb; Sun, 1 Oct 2023 16:55:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsvjeMgn6o3ZL5OTHjdrSiqQEs7ei7Xac14QCpMyFuAZEVMRY5S0fvS9BGwWkJLDxvxT3E X-Received: by 2002:a05:6830:6b0c:b0:6c4:da36:f949 with SMTP id db12-20020a0568306b0c00b006c4da36f949mr10356266otb.8.1696204555511; Sun, 01 Oct 2023 16:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696204555; cv=none; d=google.com; s=arc-20160816; b=rGsKHFiy1Q+WsgUA+A5BNikDye/BIpkw2C5eBWAh6QiOwQ1owhULUh6EIVmptAAWJZ mPdx49TtZg2YjiHmttyYaXwscYPd82rOnunqRGVS5KLJCUgF+DCBtBKiGprJRnGy3CPN hlhRYyB3RbEw/bkd/Pf/NHH5I9mB72jWltF3NZHV6honABjUZ15ffZ6sUScfRTUU6XzT ZQ5+wfXwidzlijRsFeI/crYCGPZOPSNq3tLRGGg1Faxft/+6mH8Ed+lijqAfiNCz3aB/ jTmrRFnwXuLo3yemtpfN5nxAhUjlNH0BAbdxPZPt3xRIsftrD/l9IHgySFIvFjnKyn2R o+eQ== 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=LlRFgA8ATQ35N96xDGhtrDBHITpZIgMVFViB4ahY4i0=; fh=QteByd+ihGknb5LPfDEqmcfmyroyknGG+az1Jv2i3kM=; b=Go5GEd2sLn6tfjY5okUw2qmSgQH7nEjvDmEQy9BCcR2Nq2JUE9FmvB9WfYNgyS6bUq SvS83B5zkivIp/Z3tJucmFDc+I+yJwdl5LteoQl6oAgShUGQRNqh24MVSP6gQcRyPLtE oDxHhZyTjXobLipXOifiLTESWYu7GW/a8WsBAN29HG23IHil+MRyWLSzR0myMKrm+wWH JNw1Y16QDbJhDexyZeoM9DRBTRBknUGUGA3AcmnU5i+SbD+k8l0bM8r/VzRSCPuyFJFq lYYyc595pQljT4FebEsDtbtqv8dZTok+LWhABv26V7VtYMK1QBPm48jnCwxOty8myobI azdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ai3n08pq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i67-20020a639d46000000b00584c5117901si15287304pgd.59.2023.10.01.16.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 16:55:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ai3n08pq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 23550802C7D5; Sun, 1 Oct 2023 14:59:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235419AbjJAVsQ (ORCPT + 99 others); Sun, 1 Oct 2023 17:48:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235414AbjJAVsP (ORCPT ); Sun, 1 Oct 2023 17:48:15 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C55EFCE for ; Sun, 1 Oct 2023 14:48:11 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-53808d5b774so2584124a12.3 for ; Sun, 01 Oct 2023 14:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696196890; x=1696801690; 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=LlRFgA8ATQ35N96xDGhtrDBHITpZIgMVFViB4ahY4i0=; b=ai3n08pqnr6yiYaKjvL2YzTPzfBC108fctZRrBsaWQ8KopHPxbP3cqN5vJHa1ljt9/ UI5IhG9UeVC7x8W4WXuglX6D5wUj8GomrbyVgz8MnntPJHFwF1wJZ9rUwE1pgVBmDINQ ckxYTqotEAkkW2pE9oIOFIkpKHwmLDR7qMne++xoIqRd5oOvWe/yupXn67UnnssgWVJf MbKwhNlxiVnYlbzF8Hh3LRMVj2y4ftrTxmFCubMg+FXy55cL43MaD2X9BnrHtPRwZeyj hm8h98352oOGlhRKyUtyHS6H6MnnZAbcWFKcO4mFxxwU7FWF55RD+0z1P9lKHpWTEyh6 ytRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696196890; x=1696801690; 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=LlRFgA8ATQ35N96xDGhtrDBHITpZIgMVFViB4ahY4i0=; b=Ds7yYo+AD/xJ9phpbX9jIuST8jvp/+KWFR+cmeaijXDrjiyQOGK26X/AjCigR1noIE 6itKmQeY+iXoj1Ftet2why60WMs2X9MnZuAGUts2JBMLj5WiQmvvOqlzrWmY3MwM74mZ gP90YUtk10+HaAiwIyh3ZXlTBkPyCSW8V5O/WtTWyQ/a4D0HZwtuyUDD99rGQLSePusU QKAZ/XdR7ZSSSgTta1IA8FQz05APh8eVYj4zpieCKFKjEqXMbXWS2iPkyrDss0ugrwel 6alAVEGX0uPxglImqvyz9jyqouig6etSHx97kMMHqXOvd/xPagy7MfAnQQvEXB6Wgy1Q 2xyg== X-Gm-Message-State: AOJu0YyGQX4Fzr5W9y688Br1/0ghTo/0/ER1z4ia+rE4UsmGMp5yYbkA nHH6FFISEZiW73q1U/49hoCgNw6yFdC9j+zCcWE= X-Received: by 2002:aa7:c488:0:b0:533:20ab:5d84 with SMTP id m8-20020aa7c488000000b0053320ab5d84mr7801093edq.30.1696196890011; Sun, 01 Oct 2023 14:48:10 -0700 (PDT) MIME-Version: 1.0 References: <20231001131620.112484-1-ubizjak@gmail.com> In-Reply-To: From: Uros Bizjak Date: Sun, 1 Oct 2023 23:47:58 +0200 Message-ID: Subject: Re: [RFC PATCH 0/4] x86/percpu: Use segment qualifiers To: Linus Torvalds 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" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Sun, 01 Oct 2023 14:59:48 -0700 (PDT) On Sun, Oct 1, 2023 at 10:21=E2=80=AFPM Linus Torvalds wrote: > > 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 +=3D -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 =3D 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. Huh, this testcase triggers known issue with IVopts. I opened PR111657, but the issue with IVopts is already reported in PR79649 [2]. > 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". [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111657 [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D79649 Uros.