Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp503849pxb; Thu, 17 Feb 2022 08:32:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzQT6+OBMeJrPbB+aZ0i44LYF2BlJ5Sk1fpEL7J03rbeEI0578lOAlwJrxw4V6MGg2KalM/ X-Received: by 2002:a17:906:81d5:b0:6cf:1fb9:3440 with SMTP id e21-20020a17090681d500b006cf1fb93440mr2941175ejx.351.1645115558644; Thu, 17 Feb 2022 08:32:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645115558; cv=none; d=google.com; s=arc-20160816; b=l2awHgpviXFhmIWvXviKNaCttMr5tnuVd0rD/mcxnScwewA3N2WrJKYVe7gCh/WhMb DFgduvP13OQfhw5UFI/OPeRVVa3H5NONsNRc7TQVeLU0E8HlYLonAGDMwvFH8f75mMXt 6MGTszrHuV5sc/5bKacCpu9myGKhIuR13T1Kpay9cB2Rcj8gL4nJEziktNISpd60ABBA lTYNIh7nd3kFCPVBTaARgOlHsQfzaREv0JIsxdRu0M8bgF70A79e7AeevvPR4kGxkLmu whn0AmUT1MAumcoN6aaauBvVE1D/vfEQhdj1k3UkqLRGJwg5g/SNK3nQR9T6cu5PqKsg J/TQ== 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=B0M/IeDIZGDcjbJ+9jtwyMZRbiHqmRKaJeE0g2p7LE4=; b=o7L+1BVAQY3U45WuFyrlgv+T2cHrYZYRpalkclGlKlgd+wHsaLYLsOmojBPawTz3Uu FnTY77KQG5WcfXivF3zFWqCtHQwLl580XOkG1a8LIIMuIGBK4iDzL7FJCYzP0FEZfpCv tSRe7MRmPObNcotLw3cgIFWz3ndnzOX0FwQsQU0lkm3iG6oPuA7lUoDiZnjnXM16l0NH uNnsOsuVUzQm4afMNv8A2UjZh4nNfZlIwJMP6W4F4Ssj1v/C2Uy1TTlfXifWVFMIVg6u DMyL6F9Qjwod8hxKxi/fw/kvO8y1X3h+wZPNxTY4W6kOwP8VvE/3JqgoaAjyohLvPHPa Tfmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="EcO/f6Ht"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h14si2018971edj.425.2022.02.17.08.32.15; Thu, 17 Feb 2022 08:32:38 -0800 (PST) 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=@google.com header.s=20210112 header.b="EcO/f6Ht"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240848AbiBQNcI (ORCPT + 99 others); Thu, 17 Feb 2022 08:32:08 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240966AbiBQNcF (ORCPT ); Thu, 17 Feb 2022 08:32:05 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE614ECB0C for ; Thu, 17 Feb 2022 05:31:50 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id z22so9667397edd.1 for ; Thu, 17 Feb 2022 05:31:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=B0M/IeDIZGDcjbJ+9jtwyMZRbiHqmRKaJeE0g2p7LE4=; b=EcO/f6Ht5+dpl6IvTJTBMSv3SiVfR0UbSXtnhj76Rm8qfUeUWKPvAkaw/yX3GVPcs4 VkU/hBPdgZxB448qYxGahx6hEj2NnLDW5/8WRTE50C6q6pDcanFpnv0Sn8iHqQhouK2U 8/QJuyK0Pv9MSmWICgutOvhlLrDv2++0a9EIPsKFss6wpT9YPqVAzfRDK4pEp39DIfBe guhZsQxb2H8l56cLwclMKHaerODFXqdEoInf2OQZFwggBDthun7OJg4H6UQjrNQyGXEQ cxJG+bfK96XlCfJ4nZDusI7G3GtmGsm4NL2m8CdHG/s+vhvF8RjwApKeWa3gidQW3iYd qezw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=B0M/IeDIZGDcjbJ+9jtwyMZRbiHqmRKaJeE0g2p7LE4=; b=Qxz8alxDoldo/k6AW1rWer+lj0Xc7Xq/nUnDomA7U+Gu4mwdTJt8sHYVEWg3KEvXvF 8Ap6IAt6evPzgKQxakNjtC8laDVPX0USvBEPgwRFmFTYFozGj6VJcCwFLvzSF4ZlCNbh fmd99vcGCoooWJCpJA2q2uTHQJX+xZnXZRRPSBrnz6aws7KD/ooQ2CCBoqtBUyjtjcr5 xGniF58eKnuvXHyECkm7yHna6uIhbbLZJ6jkCrZjFJ7XJaPneO152yG0V0bn5b0tEKB9 aCNoXvKsmv//PgVYAlQKfxk3T5cRwiL31HRI5XeFkVMm+8Aln/m3Kg08DF7U7yxOvVwP gE0w== X-Gm-Message-State: AOAM530gn3IdxuiPJCMOxOvemQSn76xNrMiJIDyWT4PBuLkjpDsXupg6 6CUPq6XhLaqjlutMax9gRRIfvP34MsZhTLAZKkEC7g== X-Received: by 2002:aa7:d8cb:0:b0:406:3135:51c7 with SMTP id k11-20020aa7d8cb000000b00406313551c7mr2504206eds.233.1645104709080; Thu, 17 Feb 2022 05:31:49 -0800 (PST) MIME-Version: 1.0 References: <543efc25-9b99-53cd-e305-d8b4d917b64b@intel.com> <20220215192233.8717-1-bgeffon@google.com> In-Reply-To: From: Brian Geffon Date: Thu, 17 Feb 2022 08:31:12 -0500 Message-ID: Subject: Re: [PATCH stable 5.4,5.10] x86/fpu: Correct pkru/xstate inconsistency To: Dave Hansen Cc: Greg KH , Thomas Gleixner , Willis Kung , Guenter Roeck , Borislav Petkov , Andy Lutomirski , "# v4 . 10+" , "the arch/x86 maintainers" , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Wed, Feb 16, 2022 at 10:16 AM Dave Hansen wrote: > > On 2/16/22 02:05, Greg KH wrote: > >>> How was this tested, and what do the maintainers of this subsystem > >>> think? And will you be around to fix the bugs in this when they are > >>> found? > >> This has been trivial to reproduce, I've used a small repro which I've > >> put here: https://gist.github.com/bgaff/9f8cbfc8dd22e60f9492e4f0aff8f04f > >> , I also was able to reproduce this using the protection_keys self > >> tests on a 11th Gen Core i5-1135G7. I'm happy to commit to addressing > >> any bugs that may appear. I'll see what the maintainers say, but there > >> is also a smaller fix that just involves using this_cpu_read() in > >> switch_fpu_finish() for this specific issue, although that approach > >> isn't as clean. > > Can you add the test to the in-kernel tests so that we make sure it is > > fixed and never comes back? > > It would be great if Brian could confirm this. But, I'm 99% sure that > this can be reproduced in the vm/protection_keys.c selftest, if you run > it for long enough. Hi Dave, Yes, this is reproduced by the protection keys selfs tests. If your kernel was compiled in a way which caches current_task when read via this_cpu_read_stable(), then when switching from a kernel thread to a user thread you will observe this behavior, so the only situation where it's timing related is waiting for that switch from a kernel to user thread. If your kernel is compiled in a way which does not cache the value of current_task then you will never observe this behavior. My understanding is that this is perfectly valid for the compiler to produce that code. > > The symptom here is corruption of the PKRU register. I created *lots* > of bugs like this during protection keys development so the selftest > keeps a shadow copy of the register to specifically watch for corruption. > > It's _plausible_ that no one ever ran the pkey selftests with a > clang-compiled kernel for long enough to hit this issue. For ChromeOS we use clang and when I tested a vanilla 5.10 kernel _built with clang_ it also reproduced, so I suspect you're right that the self tests just haven't been run against clang built kernels all that often. How would you and Greg KH like to proceed with this? I'm happy to help however I can. Brian