Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1561539rdb; Sun, 8 Oct 2023 13:52:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnMUi9L6Q5LLXtbUC74EN0C+ccTWOEXAwm+LBvHczYWqxnLjY3gGg+T3ALF5V2Zf1MArCp X-Received: by 2002:a05:620a:2847:b0:775:7fee:7913 with SMTP id h7-20020a05620a284700b007757fee7913mr15966837qkp.16.1696798349967; Sun, 08 Oct 2023 13:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696798349; cv=none; d=google.com; s=arc-20160816; b=ym+HAJDbnCIB2zjf3dHeaG8MINibnP01k68dm/cSfGiUQThTuzlRdofKc2zIMiRRsy 3A5eHFAekUrpeABN6tc7pVjbM0DzPOzSqbVL4aymG1wWcw0WsLF5mLIuESPA6XC7dzd2 Ces8z3sUDDIwBGwo9Dn/t8qbTZMzzpkcF2QITVSr3sS0Vd/QmQY3GTlr7kOHblrBoUdL BmuJTOubXGwMlZLy9F7M5D+DaZdP1krciAAsE7mied1stIjDdr7QBX0t1tcXCK/6CXPg y9F3Bv85jMuTO1Gwf3JSHVgU3mJVNi6oHS0XYN1Zogeeu27pPiLn+Aa/uuzZ3zaCH9Tm UOIA== 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=EtpbtXNTgAw7A9FVCfs/xfeaX4QpnPrPy9XfoZ2+es4=; fh=D/2WpD/FTfktLra+44nV6aoAOzKjvabgolyn1E2WqLA=; b=EwB7NzezkU4C6nwdmNTRr6K0Bk92BmUC1n15q2M3XdzIBsKc2oqbeljsyPKx8lXV9e +rpdA8VEAp/PgV5NDy1p4lka3SRhV8aYXyOkMmim+efSiKMYq3ja/JcJHc4DLg1c/Jtg 3XaolGh+bjXmfsxzjPoec7rydm+kIl/M1zUsUU3vBRG1RYff2br/UMbgJVwRC6R32Odn 1XqHjrFgCgVbl5W49asH2Z1GAPNaLZ9IoZXrexO7c5xFvk/nHosk+QenraCmfr0KIByL JIJUqbH5LKOWzoZEgNjE4sdAqxQ5VxSeOAdbjU2KlUBIY3tlArWPYO9dQU8Dj4vAy+3M CCiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=WPOmpQ0S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id v10-20020a63610a000000b00589fcc39ef1si5492861pgb.365.2023.10.08.13.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 13:52:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=WPOmpQ0S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 1EFD080525BF; Sun, 8 Oct 2023 13:52:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234290AbjJHUs3 (ORCPT + 99 others); Sun, 8 Oct 2023 16:48:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbjJHUs3 (ORCPT ); Sun, 8 Oct 2023 16:48:29 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53C73B3 for ; Sun, 8 Oct 2023 13:48:27 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9b95622c620so714365666b.0 for ; Sun, 08 Oct 2023 13:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1696798105; x=1697402905; 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=EtpbtXNTgAw7A9FVCfs/xfeaX4QpnPrPy9XfoZ2+es4=; b=WPOmpQ0S9yxEyZiLtiYGXneklbJ0Caf69y0jqR681QLCJEr8s+btHyfcgYE0FXXuOv AELHiLj8YlGvXmfWwEEM33Dp3MN/K+K2xSf0yqudT0Duk/Vy/SkWo7kO9KUvP0m2zBAk iwLPL3iGvb6tr4WfGMhgBOtaFb8FV20Sk9qJ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696798105; x=1697402905; 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=EtpbtXNTgAw7A9FVCfs/xfeaX4QpnPrPy9XfoZ2+es4=; b=D2pW2lq8L6TV7gkrIvYd0ymvz7mppzQ1wCX0Pk3usTGpWvdfqGgSeujg9d2EnmXvMn BOI9tpAb6XpliwAeKFBtT50/S6o29KiR569bOMqDp6BKwudDQPszuBQtlhYRCkfY//W1 c0NMFwJnZgJu1YFl0LLkCshgM8Js3nk8lS8i+jz3lJzSfLDAN0x2GSXTsAvUbR+r9eTK wtv35Cb2Qf5/xazrXJPduEpcmFQn/4r93KXN+dCb7+n6okPQN4uI5Zp9Te7geJLc7dWD NRpGz+2nFl1iVvAwZzY+Bn9mE7MQum9Rx7KggKEz/MYc3jho0Z00HO611sj3TwBx4EIQ 1V9w== X-Gm-Message-State: AOJu0Yxziuw5W/zfhOoo7E8v2S7v2+MMXwJirgg/z0jTsb1G0/wHlsB8 74Nfw9scgW6BLHSdrCtLf5Fo23cLjZAk24qg2U6Z3xwq X-Received: by 2002:a17:906:2254:b0:9b9:4509:d575 with SMTP id 20-20020a170906225400b009b94509d575mr12277549ejr.2.1696798105707; Sun, 08 Oct 2023 13:48:25 -0700 (PDT) Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com. [209.85.221.43]) by smtp.gmail.com with ESMTPSA id v2-20020a1709064e8200b009b2c9476726sm5920332eju.21.2023.10.08.13.48.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Oct 2023 13:48:25 -0700 (PDT) Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-307d20548adso3574145f8f.0 for ; Sun, 08 Oct 2023 13:48:24 -0700 (PDT) X-Received: by 2002:adf:e8cc:0:b0:322:da1f:60d9 with SMTP id k12-20020adfe8cc000000b00322da1f60d9mr12676506wrn.47.1696798104195; Sun, 08 Oct 2023 13:48:24 -0700 (PDT) MIME-Version: 1.0 References: <20231004145137.86537-1-ubizjak@gmail.com> <20231004145137.86537-5-ubizjak@gmail.com> In-Reply-To: From: Linus Torvalds Date: Sun, 8 Oct 2023 13:48:06 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 4/4] x86/percpu: Use C for percpu read/write accessors 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=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Sun, 08 Oct 2023 13:52:26 -0700 (PDT) X-Spam-Level: ** On Sun, 8 Oct 2023 at 13:13, Linus Torvalds wrote: > > Your dump does end up being close to a %gs access: Bah. I should have looked closer at the instructions before the oops. Because I think that's exactly the problem here. That's the KASAN checks that have been added, and we have this insane code: > 10: 48 c7 c0 10 73 02 00 mov $0x27310,%rax > 17: 48 ba 00 00 00 00 00 movabs $0xdffffc0000000000,%rdx > 1e: fc ff df > 21: 48 c1 e8 03 shr $0x3,%rax > 25:* 80 3c 10 00 cmpb $0x0,(%rax,%rdx,1) <-- trapping instruction Look how both %rax and %rdx are constants, yet then gcc has generated that crazy "shift a constant value right by three bits, and then use an addressing mode to add it to another constant". And that 0xdffffc0000000000 constant is KASAN_SHADOW_OFFSET. So what I think is going on is trivial - and has nothing to do with ordering. I think gcc is simply doing a KASAN check on a percpu address. Which it shouldn't do, and didn't use to do because we did the access using inline asm. But now that gcc does the accesses as normal (albeit special address space) memory accesses, the KASAN code triggers on them too, and it all goes to hell in a handbasket very quickly. End result: those percpu accessor functions need to disable any KASAN checking or other sanitizer checking. Not on the percpu address, because that's not a "real" address, it's obviously just the offset from the segment register. We have some other cases like that, see __read_once_word_nocheck(). And gcc should probably not have generated such code in the first place, so arguably this is a bug with -fsanitize=kernel-address. How does gcc handle the thread pointers with address sanitizer? Does it convert them into real pointers first, and didn't realize that it can't do it for __seg_gs? Linus