Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp489238pxb; Tue, 15 Feb 2022 19:35:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJx/tMuqEOSLtfRtT0DJrUysZQqQ+lsZdTQ0sBDoTcKhml2eziAhrQwCw12Ef4lfvIFCVeig X-Received: by 2002:a17:906:66cb:b0:6cf:e4f7:9504 with SMTP id k11-20020a17090666cb00b006cfe4f79504mr790965ejp.142.1644982534217; Tue, 15 Feb 2022 19:35:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644982534; cv=none; d=google.com; s=arc-20160816; b=ktUzpGIeXQ0K4otshMxXGEgzFaVjRiqZGsXusDu4WJy1sbeqIv/IHsNPsLMHdRF7ea B1aiaKh3mQeWCj9rHtSp0vNyI9e0wjupk+o+Y9fkYsTXIXvqmCSNEoCqOGuZqzDpRmB/ oSmOiZ2Gm46c1504BNfu8MTNdtyj+P0D903dwoWDVoiCS9OPjGex8s95uo4Mz602uJRi HZwjItorucMV+YtCWEiuMubqV7R7/3QGLjoRpObnWFslLmf+SCEwv0xiQmbcsJWNIeIr NhnlOdSTBC+0xQpYkswAT3Sn69/stSuOOL8ffSeTrR8M+oJ9AB/cjN8s5IsV4wNCgF5G kDlg== 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=GSycWluZZWqMd7iobnE427mbP0AhaCWRVGk9WjPUqDI=; b=IonqLNJu+YKOHNyjKPf9a4F8QSw0as3wH6TBmP02UrtZ1AwU0INFOHYIcrjuhS1whC /Socm+OzUxgtgp8VSe2Haln+svuARxeT4K3+RQgfCwPDfJFJK2rxMM68hAqx86GzrwbF 8IB0hsLKXAXkTssbAjImIOVgOgxnxEEbSU+rp9kKSxBQwKgob7rZSRXFzLBoG06E6x4V 35VsMI6Mui+hma5BFCJCH6BlOUv1bceUcCkIEpJhKrkwga4yxk0SISeXWs1x2/nQcKPT HB5WI+kIPpiLcV2RitHsiDqm2ad3R++pXrDtoLZmFtZ/V4Uw/+KOrvATHqEhiGZ8bIPV uSXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="d9R/K5ji"; 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 dr21si15819338ejc.745.2022.02.15.19.35.08; Tue, 15 Feb 2022 19:35:34 -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="d9R/K5ji"; 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 S244112AbiBOVdi (ORCPT + 99 others); Tue, 15 Feb 2022 16:33:38 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242802AbiBOVdh (ORCPT ); Tue, 15 Feb 2022 16:33:37 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA5D9EC5FF for ; Tue, 15 Feb 2022 13:33:26 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id y17so447282edd.10 for ; Tue, 15 Feb 2022 13:33:26 -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=GSycWluZZWqMd7iobnE427mbP0AhaCWRVGk9WjPUqDI=; b=d9R/K5jisJICbxfnZom2J0LOpS4KfeV/NsU5gaJ4CnIRdXy1mHeW5DBBS4mMiVKV2C NJBeO8aYtcGael71sAhNIcWRmAui2etYm6Ip4mOurKoYCHmo+fZIIGOdeOLRgYsq1sJS 2SJfrfRy0GCV86PMsvhkUZi9u8Z5R1izoVwLwuN+zyIUJGXOIILIiTX0cw0bQPoxqu/c zsXBC78Bhi+sx6ZhYZK1NQdX1fvylS2WKYxXn/VYOjdhmsVHFGTxvUEhpj/bv0r9X0dR ucWgIzWpfWTN3I9Pbumnwy9Z8xbwxmhySE2GSDGLsFTwsMVcWa2IVThTA0NOy6uaEhWl U0nQ== 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=GSycWluZZWqMd7iobnE427mbP0AhaCWRVGk9WjPUqDI=; b=moJ+LvYVBLDTdoswYcdF3lpkkVEE27kGOWSrmeMQv0YlwNB5abEhpX4P/sqOGG3X1c B/1T6vsvzEraoCEzPZJIGFR9I/gDSB8FL3tX8FbKWtetQNO7bDk+2j9DLohqc7h2gqY1 9zLFPDBzd9j1Q4oAUdifzu6sDinvStw1quRr8VgwjC82MBcWFjyqwAjybRQfnxwLzhTV IyCKBIN82hssHtcyLadTvMaRCCibCKOxnZ9FJszQ0Vcdy/olH5tJdRSF2o6Ft7+i76Ym BzQtN+hD1xicHVNL8gDd2ZVZ/8tMXUCpAglZzNoXCzkXfLoTdh22VQZQ+oam9nvfoVBP 6jjw== X-Gm-Message-State: AOAM531uFaJtKU2nmLXJpJ1d6JNC5Ji4WDS7oSo8NZkMjriEe6FkcQdU LhVPTUbjMfO0+13BlANVvYnuqJ1sz9Uq52XwDa30PQ== X-Received: by 2002:a05:6402:2946:: with SMTP id ed6mr904345edb.221.1644960805072; Tue, 15 Feb 2022 13:33:25 -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: Tue, 15 Feb 2022 16:32:48 -0500 Message-ID: Subject: Re: [PATCH stable 5.4,5.10] x86/fpu: Correct pkru/xstate inconsistency To: Greg KH Cc: Dave Hansen , 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=unavailable 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 Tue, Feb 15, 2022 at 2:45 PM Greg KH wrote: > > On Tue, Feb 15, 2022 at 11:22:33AM -0800, Brian Geffon wrote: > > When eagerly switching PKRU in switch_fpu_finish() it checks that > > current is not a kernel thread as kernel threads will never use PKRU. > > It's possible that this_cpu_read_stable() on current_task > > (ie. get_current()) is returning an old cached value. To resolve this > > reference next_p directly rather than relying on current. > > > > As written it's possible when switching from a kernel thread to a > > userspace thread to observe a cached PF_KTHREAD flag and never restore > > the PKRU. And as a result this issue only occurs when switching > > from a kernel thread to a userspace thread, switching from a non kernel > > thread works perfectly fine because all that is considered in that > > situation are the flags from some other non kernel task and the next fpu > > is passed in to switch_fpu_finish(). > > > > This behavior only exists between 5.2 and 5.13 when it was fixed by a > > rewrite decoupling PKRU from xstate, in: > > commit 954436989cc5 ("x86/fpu: Remove PKRU handling from switch_fpu_finish()") > > > > Unfortunately backporting the fix from 5.13 is probably not realistic as > > it's part of a 60+ patch series which rewrites most of the PKRU handling. > > > > Fixes: 0cecca9d03c9 ("x86/fpu: Eager switch PKRU state") > > Signed-off-by: Brian Geffon > > Signed-off-by: Willis Kung > > Tested-by: Willis Kung > > Cc: # v5.4.x > > Cc: # v5.10.x > > --- > > arch/x86/include/asm/fpu/internal.h | 13 ++++++++----- > > arch/x86/kernel/process_32.c | 6 ++---- > > arch/x86/kernel/process_64.c | 6 ++---- > > 3 files changed, 12 insertions(+), 13 deletions(-) > > So this is ONLY for 5.4.y and 5.10.y? I'm really really loath to take > non-upstream changes as 95% of the time (really) it goes wrong. That's correct, this bug was introduced in 5.2 and that code was completely refactored in 5.13 indirectly fixing it. > > 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. > > And finally, what's wrong with 60+ patches to backport to fix a severe > issue? What's preventing that from happening? Did you try it and see > what exactly is involved? It was quite a substantial rewrite of that code with fixes layered on since. > > thanks, > > greg k-h