From nobody Mon Jun 29 23:57:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90EEFC433F5 for ; Sat, 29 Jan 2022 17:44:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351569AbiA2Roh (ORCPT ); Sat, 29 Jan 2022 12:44:37 -0500 Received: from mga06.intel.com ([134.134.136.31]:54626 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245682AbiA2Roe (ORCPT ); Sat, 29 Jan 2022 12:44:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643478274; x=1675014274; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=hG8h2J7gfBwIVc5hOnYbEWs6O2Ve57mhwXoORMsooLA=; b=ZuIyL5rOZkypLaPOq6RXdPsCxhCFYowbN+jzzHVcYAJWgySLXBZdhfvE djEdpj6RbTTBdBJu/r4TA7MwjCKCR4BBOrR8iIKIUnJsDhpjAYbBEWMyj H5w2uMe/edcLFD9u14fOFweaie1LyvMr4gqbfV+R4tXKs3jzSInt1eQRJ K5ZvaVZ+d0V/NLob17EejBvqBa4SO73NeQLAo7w8w1zAQ7xh0P8Gd9pcI vrflYzcT9OiFBHKbsELwIK6g4x7hCXQG99tAImvI+Pk56EQyVgy2tst0z UlVxfjrSGCEuKAXOdl5Wy+LGwSbA8XZ2pqUHo6T6UBv1aUiEApWRI2utU A==; X-IronPort-AV: E=McAfee;i="6200,9189,10242"; a="308016820" X-IronPort-AV: E=Sophos;i="5.88,327,1635231600"; d="scan'208";a="308016820" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2022 09:44:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,327,1635231600"; d="scan'208";a="675370401" Received: from chang-linux-3.sc.intel.com ([172.25.66.175]) by fmsmga001.fm.intel.com with ESMTP; 29 Jan 2022 09:44:33 -0800 From: "Chang S. Bae" To: linux-kernel@vger.kernel.org, x86@kernel.org, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, mingo@redhat.com Cc: yang.zhong@intel.com, ravi.v.shankar@intel.com, chang.seok.bae@intel.com Subject: [PATCH v4 1/2] x86/arch_prctl: Fix the ARCH_REQ_XCOMP_PERM implementation Date: Sat, 29 Jan 2022 09:36:46 -0800 Message-Id: <20220129173647.27981-2-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220129173647.27981-1-chang.seok.bae@intel.com> References: <20220129173647.27981-1-chang.seok.bae@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Yang Zhong ARCH_REQ_XCOMP_PERM is supposed to add the requested feature to the permission bitmap of thread_group_leader()->fpu. But the code overwrites the bitmap with the requested feature bit only rather than adding it. Fix the code to add the request feature bit to the master bitmask. Fixes: db8268df0983 ("x86/arch_prctl: Add controls for dynamic XSTATE compo= nents") Signed-off-by: Yang Zhong Signed-off-by: Chang S. Bae Cc: Thomas Gleixner Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org --- Changes from v3: * Adjust the change to the mainline (v5.17-rc). Changes from v2: * Fix the authorship. Changes from v1: * Change the mask value only and trim the changelog. --- arch/x86/kernel/fpu/xstate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 02b3ddaf4f75..2d4363e32517 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1636,7 +1636,7 @@ static int __xstate_request_perm(u64 permitted, u64 r= equested, bool guest) =20 perm =3D guest ? &fpu->guest_perm : &fpu->perm; /* Pairs with the READ_ONCE() in xstate_get_group_perm() */ - WRITE_ONCE(perm->__state_perm, requested); + WRITE_ONCE(perm->__state_perm, mask); /* Protected by sighand lock */ perm->__state_size =3D ksize; perm->__user_state_size =3D usize; --=20 2.17.1 From nobody Mon Jun 29 23:57:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28BAFC433EF for ; Sat, 29 Jan 2022 17:44:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352662AbiA2Rok (ORCPT ); Sat, 29 Jan 2022 12:44:40 -0500 Received: from mga06.intel.com ([134.134.136.31]:54627 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349021AbiA2Roe (ORCPT ); Sat, 29 Jan 2022 12:44:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643478274; x=1675014274; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Owt2/avuqAtl47qyDRa69L2r49VRLIBmzHJVHbW63DI=; b=Eq8l1mgmpBjGQGZdDUWC4dJ6conUqJPVO/Lca1/+7cLVZHemH+oBcPkX UMItrGkOOorlaf8Nc7xviLpdBuvQ1W9S9rThBtPQmXNQuU9Nxy/EfW2FG 3RWCTjMU693M1r+8R9gkFxIK6eqLELp7Rpa5yzBUkZkA+9Iu9uxE2fYZL 0GU3+RHD/Q37wU9rXVLqOXvbSpMk1pramWIduJsV53fAedcD3VWx1Q4ye V1up1PEiGE0C8pxUhJmSZMeEIo0ghi4Nvq3cjxuXLjGXwW0fAZcitCfyd 5CwxstTcd+cUVnNDA+bpeo9tTY/S8E8jkbd5TnS1gqC7WSsLHJgCgeoha A==; X-IronPort-AV: E=McAfee;i="6200,9189,10242"; a="308016821" X-IronPort-AV: E=Sophos;i="5.88,327,1635231600"; d="scan'208";a="308016821" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2022 09:44:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,327,1635231600"; d="scan'208";a="675370405" Received: from chang-linux-3.sc.intel.com ([172.25.66.175]) by fmsmga001.fm.intel.com with ESMTP; 29 Jan 2022 09:44:34 -0800 From: "Chang S. Bae" To: linux-kernel@vger.kernel.org, x86@kernel.org, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, mingo@redhat.com Cc: yang.zhong@intel.com, ravi.v.shankar@intel.com, chang.seok.bae@intel.com, linux-kselftest@vger.kernel.org Subject: [PATCH v4 2/2] selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test Date: Sat, 29 Jan 2022 09:36:47 -0800 Message-Id: <20220129173647.27981-3-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220129173647.27981-1-chang.seok.bae@intel.com> References: <20220129173647.27981-1-chang.seok.bae@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Update the arch_prctl test to check the permission bitmap whether the requested feature is added as expected or not. Every non-dynamic feature that is enabled is permitted already for use. TILECFG is not dynamic feature. Ensure the bit is always on from ARCH_GET_XCOMP_PERM. Signed-off-by: Chang S. Bae Cc: Dave Hansen Cc: linux-kselftest@vger.kernel.org Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org --- tools/testing/selftests/x86/amx.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/x86/amx.c b/tools/testing/selftests/x8= 6/amx.c index 3615ef4a48bb..e1e2c8f3356f 100644 --- a/tools/testing/selftests/x86/amx.c +++ b/tools/testing/selftests/x86/amx.c @@ -368,9 +368,16 @@ static void req_xtiledata_perm(void) =20 static void validate_req_xcomp_perm(enum expected_result exp) { - unsigned long bitmask; + unsigned long bitmask, expected_bitmask; long rc; =20 + rc =3D syscall(SYS_arch_prctl, ARCH_GET_XCOMP_PERM, &bitmask); + if (rc) { + fatal_error("prctl(ARCH_GET_XCOMP_PERM) error: %ld", rc); + } else if (!(bitmask & XFEATURE_MASK_XTILECFG)) { + fatal_error("ARCH_GET_XCOMP_PERM returns XFEATURE_XTILECFG off."); + } + rc =3D syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_PERM, XFEATURE_XTILEDATA); if (exp =3D=3D FAIL_EXPECTED) { if (rc) { @@ -383,10 +390,15 @@ static void validate_req_xcomp_perm(enum expected_res= ult exp) fatal_error("ARCH_REQ_XCOMP_PERM saw unexpected failure.\n"); } =20 + expected_bitmask =3D bitmask | XFEATURE_MASK_XTILEDATA; + rc =3D syscall(SYS_arch_prctl, ARCH_GET_XCOMP_PERM, &bitmask); if (rc) { fatal_error("prctl(ARCH_GET_XCOMP_PERM) error: %ld", rc); - } else if (bitmask & XFEATURE_MASK_XTILE) { + } else if (bitmask !=3D expected_bitmask) { + fatal_error("ARCH_REQ_XCOMP_PERM saw a wrong bitmask: %lx, expected: %lx= .\n", + bitmask, expected_bitmask); + } else { printf("\tARCH_REQ_XCOMP_PERM is successful.\n"); } } --=20 2.17.1