Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6790435rwr; Tue, 25 Apr 2023 04:00:42 -0700 (PDT) X-Google-Smtp-Source: AKy350a7+7ncYeQWtw84x9gl/dBSdBJXSLexhGYB0eM8oWD9cZE008X7MNwjril2KB/ChoVzjUm5 X-Received: by 2002:a05:6a00:1788:b0:63d:3f74:9df7 with SMTP id s8-20020a056a00178800b0063d3f749df7mr23888713pfg.34.1682420441946; Tue, 25 Apr 2023 04:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682420441; cv=none; d=google.com; s=arc-20160816; b=nh7r5LVNB8PWU/wVhxKAkC3XEqClBo0MBS/gv5ru5mCBKh8kEwbhStg0QT9cYtBp1o pIsesrif9nLjuQa2QPYZpG/DmdXn2tvhU/eoT8TYNtC+vHBZ8T3h37xPGhlNpsBXLIIz G64zQC0xBM3ipV7NE102j2w4xi6EMBESz1u7iEbqimSVHI+5nOjYgcGdEFoaOrAK2w6c ajBQUZLw4whTxWJ5aoks86/H6B+p01DGre702Mdkj0JQIOlveIa1Ah37CSMrd8js5sgJ bfDeXQ0gRuO1TvQ2kEkKSCgoPhPXB779MNOxqDAcxm2lmLZh0VeTJ/k0WVz3ZhfYp9wc R+Lw== 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=b0JHWtYitmYVTIJ2+ge4uzqOjTVMwrngSNO6Xtd2pjU=; b=FRFEhNtHFwM9atIx8RKNP4F+wKe9pxkDH4t6jNvUP0QKeZIPJJrrUPmvh2SMkz94FX 3wbPOCFqtp8hujh+J+blAQA5QVG2ZZwTDXYjGV1g8LdLfBU1ZIiwFp41zVDJprC6I4x4 tHNfYWlTu02D9svAC0X89XeEi6o6G6+VhMVWgcHSCzzsd76lf5vVteOwMFbMeWejOpEC DB5BOxO5WwvME7nAiHPDS35ml/zqZZiJlBEHUVAXDiMm8qq/If/mEfmNfVJYUVw9LHCg LQUFRieI2fXRAOxSzHG4+ucTaPboa9Pm0yhkSEkg2bFTPxSvOIme9owInjKkpivB7eSW Og6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NR2WE+Pg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bk13-20020a056a02028d00b005192652814bsi13340299pgb.541.2023.04.25.04.00.29; Tue, 25 Apr 2023 04:00:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NR2WE+Pg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233842AbjDYK7B (ORCPT + 99 others); Tue, 25 Apr 2023 06:59:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233290AbjDYK7A (ORCPT ); Tue, 25 Apr 2023 06:59:00 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D840E49EA; Tue, 25 Apr 2023 03:58:57 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-246fa478d45so5083110a91.3; Tue, 25 Apr 2023 03:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682420337; x=1685012337; 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=b0JHWtYitmYVTIJ2+ge4uzqOjTVMwrngSNO6Xtd2pjU=; b=NR2WE+PgVRsWds0vo3wWvFtwGWABl8CrGItfKViXFhxsyUrBL04N2S1PfkqPdJ4LzQ JMMcQhwSiJpZgUPGMTBbIefeNfDHW5eErS7Lns22Z58bi3BvLFRPO1Fs0oYJp/vjzZT7 l/aLkHxy0BV1OmBS3/ZugkuCMGUU6dSmaNG9DD3eN1sbDYCZfEhebaktBnf9xnX+J8ks l94ijmRjnxW+X0k5/QT75NHMuWJxQ/Y1zSaRiBFHWzbpwd4AjdZu6e4vfwce4ApmhKpn MAvbcqnrMtyJ42eG0Yr1klG/IXpJW6ouZK8m6oOpU8z9Pl0Xqt8Hg75CBu/MQVNAVEjH smQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682420337; x=1685012337; 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=b0JHWtYitmYVTIJ2+ge4uzqOjTVMwrngSNO6Xtd2pjU=; b=hKDa67+Z1u95df1QC1u/aC3mR05v6dd3eiQoJW4EYxpya9yW5LSp1asWPIfS2jyUih aOYCGRHQLYvtb/QDiGCxo55NyuLICm45DtiU1m0Jbolik/6ByDagPwAhxrtGZv+NAc4h n/ROE3OR2EGnIYERe9yAaeCkjqO7/ODHniMwAw7I6z8teACDopYv4TBO9nezGHDzeWC7 cECn6fyumbKLOGU0IS9ju+abef/N1i0ZfSXPf/NndqVUColHAvm2fJaGXaNu4rfld25n qvkCSqIS25Up6urm9K/XLLGulB7251ElKKbliEgUNj/5EbGX/7m1RsjkNXhgQige0k4+ /vrw== X-Gm-Message-State: AAQBX9fuTxtjymi7hoOVrobLaEwb32D/fZ8D5Wo1SGOP+3Xkccu/bsL8 VbPZN5el39oSv4OPFAzpFGNbu1VpkKxT+4L8xww= X-Received: by 2002:a17:90a:950e:b0:24b:2ef6:64d5 with SMTP id t14-20020a17090a950e00b0024b2ef664d5mr16225496pjo.47.1682420337231; Tue, 25 Apr 2023 03:58:57 -0700 (PDT) MIME-Version: 1.0 References: <87fs8pzalj.fsf@mail.concordia> <20230424151351.GP19790@gate.crashing.org> <20230425101324.GD1331236@hirez.programming.kicks-ass.net> In-Reply-To: <20230425101324.GD1331236@hirez.programming.kicks-ass.net> From: Zhouyi Zhou Date: Tue, 25 Apr 2023 18:58:46 +0800 Message-ID: Subject: Re: BUG : PowerPC RCU: torture test failed with __stack_chk_fail To: Peter Zijlstra Cc: Joel Fernandes , Boqun Feng , Segher Boessenkool , Michael Ellerman , linuxppc-dev , rcu , linux-kernel , lance@osuosl.org, "Paul E. McKenney" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NORMAL_HTTP_TO_IP, NUMERIC_HTTP_ADDR,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 hi On Tue, Apr 25, 2023 at 6:13=E2=80=AFPM Peter Zijlstra wrote: > > On Mon, Apr 24, 2023 at 02:55:11PM -0400, Joel Fernandes wrote: > > This is amazing debugging Boqun, like a boss! One comment below: > > > > > > > Or something simple I haven't thought of? :) > > > > > > > > At what points can r13 change? Only when some particular functions= are > > > > called? > > > > > > > > > > r13 is the local paca: > > > > > > register struct paca_struct *local_paca asm("r13"); > > > > > > , which is a pointer to percpu data. > > > > > > So if a task schedule from one CPU to anotehr CPU, the value gets > > > changed. > > > > It appears the whole issue, per your analysis, is that the stack > > checking code in gcc should not cache or alias r13, and must read its > > most up-to-date value during stack checking, as its value may have > > changed during a migration to a new CPU. > > > > Did I get that right? > > > > IMO, even without a reproducer, gcc on PPC should just not do that, > > that feels terribly broken for the kernel. I wonder what clang does, > > I'll go poke around with compilerexplorer after lunch. > > > > Adding +Peter Zijlstra as well to join the party as I have a feeling > > he'll be interested. ;-) > > I'm a little confused; the way I understand the whole stack protector > thing to work is that we push a canary on the stack at call and on > return check it is still valid. Since in general tasks randomly migrate, > the per-cpu validation canary should be the same on all CPUs. > > Additionally, the 'new' __srcu_read_{,un}lock_nmisafe() functions use > raw_cpu_ptr() to get 'a' percpu sdp, preferably that of the local cpu, > but no guarantees. > > Both cases use r13 (paca) in a racy manner, and in both cases it should > be safe. New test results today: both gcc build from git (git clone git://gcc.gnu.org/git/gcc.git) and Ubuntu 22.04 gcc-12.1.0 are immune from the above issue. We can see the assembly code on http://140.211.169.189/0425/srcu_gp_start_if_needed-gcc-12.txt while Both native gcc on PPC vm (gcc version 9.4.0), and gcc cross compiler on my x86 laptop (gcc version 10.4.0) will reproduce the bug.