Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1575371rdb; Sun, 8 Oct 2023 14:42:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHw7lCJz2UEzQo0H4qMGZ54fwEBBBPHTCeuVFjTmLpKmviO3kdQXuhrK3HVerCyqBGrnBAx X-Received: by 2002:a05:6358:722:b0:14b:9537:b18e with SMTP id e34-20020a056358072200b0014b9537b18emr14095592rwj.7.1696801327114; Sun, 08 Oct 2023 14:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696801327; cv=none; d=google.com; s=arc-20160816; b=kXT0defiM8AreFIiW2/2iDIWxXiR9u0rQf6tNrubvryugdd9eNG8rd7mo3aTnvJzqT fSqJR2qbdqDk/Fgp4d6571Y6fS/iWWWRTQAZiHcdt+WZA4DBprv0ZLmuLrZFDXhYXb80 3wCGH0yQTUPxpq8P3WMWkURz5G5UOOQbZEFusw806CcHR5KpskPLvNeMf/OmPeckHQAo APPh8aPC4Ij3TNoVgYwfIYBU5V77Q0ic7JjM/By5zI5pfdEgpiQqzKzlk0oRGzdif3V5 COa7SHLMDybGtjgC+MTK6VyeK9/EsIkmgn7Z96rSbQUJTBa5AohntsNjk47P2laIUyvu CKSw== 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=e3K46u8zfExXHmFTfWuyAKJzhx6jk+xJTytgfR+yIjo=; fh=QteByd+ihGknb5LPfDEqmcfmyroyknGG+az1Jv2i3kM=; b=ziCMITJihSPGTFqXd5BULL6NfxwSRUeGM7SDjcNKZiJ/C8Uxn73Z/rzQNbpC90uPT5 AT9vKXqpZfkw2ZGdXLWHqx/0YLVaxa+7s5blYc6Htz5Ood1luPnBAlU7IiE8KLxPBW4q CTmsH3e/J+7b3sny3bCAcy+saQ26uIQBCPtZ0g6n2i+xeoILwL7vvYbQUqgLHc13yQzp Xv4r/5+EiEDEKOIXvH/DaLehC+sAYBWUcBjcfO0fQoTpySZTB42wYU50V2yLENpgfToy KG6j04hsK6UH5F3clO9cvLyVpfrPF6ZfagQ2NkvLTn1v8/v2yNMvRLGdzMOiEUTUOC+j 2kvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XpOW50MF; 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 pg15-20020a17090b1e0f00b0026305080a6fsi8845915pjb.63.2023.10.08.14.42.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 14:42:07 -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=XpOW50MF; 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 B5FD2806236E; Sun, 8 Oct 2023 14:42:04 -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 S1344638AbjJHVlz (ORCPT + 99 others); Sun, 8 Oct 2023 17:41:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbjJHVlz (ORCPT ); Sun, 8 Oct 2023 17:41:55 -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 74A159D for ; Sun, 8 Oct 2023 14:41:53 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5362bcc7026so6934918a12.1 for ; Sun, 08 Oct 2023 14:41:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696801312; x=1697406112; 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=e3K46u8zfExXHmFTfWuyAKJzhx6jk+xJTytgfR+yIjo=; b=XpOW50MFUDY07srGFNRQqq9kLTxSdT+ZX9sk69hGV/h+QQpETK2g21NeiYsGJjP41P 0qkfA1XaNtgllkK8PfpSSuab8R3w2jgSGVeoXMJbv0q1J3E5gxnAdfXrqj1H3DYSKedd ikC1k/Cewb3toWVNjJ8t860qMwTcCuupb5Ajnuclb+2pY3etSDnEx+6R89XeP6zQ9pJj 0kfe6Y/gqlbcvuylj2Ak9tCT0Z4rioayVlXF1r4TwjAB7hpP+pyoHhsAU8A6VVpU3jkM XuMUm7wrGsAIbVMOhSO4oK+CMvd7J0I6ODB9z8fBysNsxoXGEiEywEmPmj0LrNtmun0c 9Hyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696801312; x=1697406112; 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=e3K46u8zfExXHmFTfWuyAKJzhx6jk+xJTytgfR+yIjo=; b=i8nzmEQdY/mUUat7JajNcSgu2U/NSoEbpTMYoVzvVM2eZlgMpCga6w+anrORp/YerZ 1q+Ewih02poK/2ERsTSLOqSqNgrydspCq2BawgkZlERK/Gup626yRdweNHksrljLTtCn fTRDo7D7Fqcka1JuY2X0uiwi0EEDJVbrd67aoHtkrvUNED3JiSJLSPx8YeNN8JstQyMx rRFEhhwyG9Mwj1zzHV7yRYxoDiiNHc0ouwQ45OoOT+KF6tQ9GYO1u8Oe/WvInWxocBy2 REHUax4uE9X7Hv8ZikhraMlkpEJoaZslGBimwUpIclcbkFIf1+E6WL1is/mvCx2AvxU8 g3hA== X-Gm-Message-State: AOJu0Yy2JlG+qdu0T191bvUr91JAfhqFJvOLYPf5+Ha4UP71NFOyFYgo yYGWtQxL/G1urtR9FaeLUpNex+qUu3VS2IzTT04= X-Received: by 2002:aa7:da99:0:b0:52c:164:efe5 with SMTP id q25-20020aa7da99000000b0052c0164efe5mr11480003eds.39.1696801311680; Sun, 08 Oct 2023 14:41:51 -0700 (PDT) MIME-Version: 1.0 References: <20231004145137.86537-1-ubizjak@gmail.com> <20231004145137.86537-5-ubizjak@gmail.com> In-Reply-To: From: Uros Bizjak Date: Sun, 8 Oct 2023 23:41:39 +0200 Message-ID: Subject: Re: [PATCH 4/4] x86/percpu: Use C for percpu read/write accessors 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: multipart/mixed; boundary="0000000000007005cf06073b57cd" X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 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]); Sun, 08 Oct 2023 14:42:04 -0700 (PDT) X-Spam-Level: ** --0000000000007005cf06073b57cd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Oct 8, 2023 at 10:48=E2=80=AFPM Linus Torvalds wrote: > > 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 inst= ruction > > 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". Hm, the compiler knows perfectly well how to make compound addresses, but all this KASAN stuff is a bit special. > And that 0xdffffc0000000000 constant is KASAN_SHADOW_OFFSET. > > So what I think is going on is trivial - and has nothing to do with order= ing. > > 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. Yes, I can confirm that. The failing .config from Linux Kernel Test project works perfectly well after KASAN has been switched off. So, the patch to fix the issue could be as simple as the one attached to the message. > 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=3Dkernel-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? I don't know this part of the compiler well, but it should not touch non-default namespaces. I'll file a bug report there. Thanks, Uros. --0000000000007005cf06073b57cd Content-Type: text/plain; charset="US-ASCII"; name="p.diff.txt" Content-Disposition: attachment; filename="p.diff.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lnhzjzd30 ZGlmZiAtLWdpdCBhL2FyY2gveDg2L0tjb25maWcgYi9hcmNoL3g4Ni9LY29uZmlnCmluZGV4IGVj YjI1Njk1NDM1MS4uMWVkZjRhNWI5M2NhIDEwMDY0NAotLS0gYS9hcmNoL3g4Ni9LY29uZmlnCisr KyBiL2FyY2gveDg2L0tjb25maWcKQEAgLTIzOTMsNyArMjM5Myw3IEBAIGNvbmZpZyBDQ19IQVNf TkFNRURfQVMKIAogY29uZmlnIFVTRV9YODZfU0VHX1NVUFBPUlQKIAlkZWZfYm9vbCB5Ci0JZGVw ZW5kcyBvbiBDQ19IQVNfTkFNRURfQVMgJiYgU01QCisJZGVwZW5kcyBvbiBDQ19IQVNfTkFNRURf QVMgJiYgU01QICYmICFLQVNBTgogCiBjb25maWcgQ0NfSEFTX1NMUwogCWRlZl9ib29sICQoY2Mt b3B0aW9uLC1taGFyZGVuLXNscz1hbGwpCg== --0000000000007005cf06073b57cd--