From patchwork Tue Sep 12 15:07:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1833092 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RlRmC4NP0z1yh0 for ; Wed, 13 Sep 2023 01:08:11 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qg4zg-00024a-RJ; Tue, 12 Sep 2023 15:08:01 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qg4zd-00024F-BM for kernel-team@lists.ubuntu.com; Tue, 12 Sep 2023 15:07:57 +0000 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 0679B3F185 for ; Tue, 12 Sep 2023 15:07:57 +0000 (UTC) Received: by mail-io1-f70.google.com with SMTP id ca18e2360f4ac-778d823038bso405064739f.3 for ; Tue, 12 Sep 2023 08:07:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694531275; x=1695136075; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fv8YZ6VqVJNGz3NgXLqOdxAtb8VzjEZVj7barI3Kkro=; b=dmARJVRYl/1e0WRaIXKb9ZCJHMT0avttTmrNnfYtswTJrp1Vne8Ljjw0vvcBSFMr8k AUDFpM0sybADvRvjkrXq6i6ajySedNsmQ8cXug+S7ZqmnfmgUXDki4xId+dwXj678Y1J yyk2RojjegUCnvqMySjqy7/LtGbZEDASn7/emsGUzVXhQL6hPjG4UNSopAA8Cyo/qjeL qun/jywq3v3o4i1y/QD47+72noi64+YIVMxgT+DDVSo5cQIOe8q+j2K+CSOTJben2ICU M2lpVJ2XlR28Y2NFEmIN2VnVPoFqZhZJPV6aUMlVmqIzfibSzVuRS18bIuUUojhxlTKO Bkwg== X-Gm-Message-State: AOJu0Ywr5/GC4reV47CgKJmusTw06qOtn4NwUKJcRtylRk20KTSGMvnx cg8b5Pwny2jORkFUWnkacyHOQ9kMCVgh/Zjb9AWlV8tn8704PZBCW4ABfmas4eyjp68kCu3NyZd 2WDq9kVnCuv7R6TXlssTHq1kzieLE3kTfWXTg+aZOVWA3hS8D+Q== X-Received: by 2002:a5e:c816:0:b0:783:3899:e1d0 with SMTP id y22-20020a5ec816000000b007833899e1d0mr66836iol.6.1694531275629; Tue, 12 Sep 2023 08:07:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGbFKRuWOFIwFK2fXhxrHVv/S76GiYLyWVHVNM+XRb2ez3vGD6Ljbk04S3FwGZWMqdKQdPkA== X-Received: by 2002:a5e:c816:0:b0:783:3899:e1d0 with SMTP id y22-20020a5ec816000000b007833899e1d0mr66816iol.6.1694531275382; Tue, 12 Sep 2023 08:07:55 -0700 (PDT) Received: from smtp.gmail.com (174-045-099-030.res.spectrum.com. [174.45.99.30]) by smtp.gmail.com with ESMTPSA id d24-20020a5d9518000000b007836e9ff198sm2876939iom.55.2023.09.12.08.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 08:07:54 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH] x86/fpu: Set X86_FEATURE_OSXSAVE feature after enabling OSXSAVE in CR4 Date: Tue, 12 Sep 2023 09:07:50 -0600 Message-Id: <20230912150750.386513-2-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912150750.386513-1-tim.gardner@canonical.com> References: <20230912150750.386513-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Feng Tang BugLink: https://bugs.launchpad.net/bugs/2034745 0-Day found a 34.6% regression in stress-ng's 'af-alg' test case, and bisected it to commit b81fac906a8f ("x86/fpu: Move FPU initialization into arch_cpu_finalize_init()"), which optimizes the FPU init order, and moves the CR4_OSXSAVE enabling into a later place: arch_cpu_finalize_init identify_boot_cpu identify_cpu generic_identify get_cpu_cap --> setup cpu capability ... fpu__init_cpu fpu__init_cpu_xstate cr4_set_bits(X86_CR4_OSXSAVE); As the FPU is not yet initialized the CPU capability setup fails to set X86_FEATURE_OSXSAVE. Many security module like 'camellia_aesni_avx_x86_64' depend on this feature and therefore fail to load, causing the regression. Cure this by setting X86_FEATURE_OSXSAVE feature right after OSXSAVE enabling. [ tglx: Moved it into the actual BSP FPU initialization code and added a comment ] Fixes: b81fac906a8f ("x86/fpu: Move FPU initialization into arch_cpu_finalize_init()") Reported-by: kernel test robot Signed-off-by: Feng Tang Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Link: https://lore.kernel.org/lkml/202307192135.203ac24e-oliver.sang@intel.com Link: https://lore.kernel.org/lkml/20230823065747.92257-1-feng.tang@intel.com (cherry picked from commit 2c66ca3949dc701da7f4c9407f2140ae425683a5) Signed-off-by: Tim Gardner --- arch/x86/kernel/fpu/xstate.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index fc1ab0116f4e..358c97d203bc 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -963,6 +963,13 @@ void __init fpu__init_system_xstate(unsigned int legacy_size) goto out_disable; } + /* + * CPU capabilities initialization runs before FPU init. So + * X86_FEATURE_OSXSAVE is not set. Now that XSAVE is completely + * functional, set the feature bit so depending code works. + */ + setup_force_cpu_cap(X86_FEATURE_OSXSAVE); + print_xstate_offset_size(); pr_info("x86/fpu: Enabled xstate features 0x%llx, context size is %d bytes, using '%s' format.\n", fpu_kernel_cfg.max_features,