From nobody Mon Sep 15 18:11:26 2025 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 52490C46467 for ; Wed, 11 Jan 2023 13:24:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233315AbjAKNXw (ORCPT ); Wed, 11 Jan 2023 08:23:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231453AbjAKNXt (ORCPT ); Wed, 11 Jan 2023 08:23:49 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D1925EF for ; Wed, 11 Jan 2023 05:23:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673443428; x=1704979428; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nLb+D373AsFdYz+VydkUKZ3nmk+8SeRPO35WqLjs/ys=; b=Z2Oc/SBLrngL79WzeX4pwnFfH0hBLpwUtZbbtFRNYVlTMm4Mupx7SjdX P4kpUonlgMEIcjxyz51OZg3q0S3xJBp/i0XWObctZQYKAfJH6l3ftZLM6 cT6Q78p/h8CyX/lwfKat8NSl5f6t7IIV5ULMXJgEJ2au/2tOWA/luKelj tBoADmj5TOv2fmjrIB56OVENR1mcUA0JgQxk5owN0wmJCHFQrf3t6LNS6 LgvVeShJBtX3LO4VWtGkpqL7HJBHC5+o9/unPSbCLI1e5QfQS5GtzXqBc Iokn6j0r5rGiIIkpwSU0h677BOnkqcYGvwl5Z58mPC48ifhz9gbqtLVw+ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="387872486" X-IronPort-AV: E=Sophos;i="5.96,317,1665471600"; d="scan'208";a="387872486" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2023 05:23:47 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="687927402" X-IronPort-AV: E=Sophos;i="5.96,317,1665471600"; d="scan'208";a="687927402" Received: from bachaue1-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.37.250]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2023 05:23:42 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id B6579109D31; Wed, 11 Jan 2023 15:37:41 +0300 (+03) From: "Kirill A. Shutemov" To: Dave Hansen , Andy Lutomirski , Peter Zijlstra Cc: x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Taras Madan , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , Bharata B Rao , Jacob Pan , Ashok Raj , Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv14 17/17] selftests/x86/lam: Add test cases for LAM vs thread creation Date: Wed, 11 Jan 2023 15:37:36 +0300 Message-Id: <20230111123736.20025-18-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20230111123736.20025-1-kirill.shutemov@linux.intel.com> References: <20230111123736.20025-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" LAM enabling is only allowed when the process has single thread. LAM mode is inherited into child thread. Trying to enable LAM after spawning a thread has to fail. Signed-off-by: Kirill A. Shutemov --- tools/testing/selftests/x86/lam.c | 92 +++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x8= 6/lam.c index a8c91829b616..eb0e46905bf9 100644 --- a/tools/testing/selftests/x86/lam.c +++ b/tools/testing/selftests/x86/lam.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE #include #include #include @@ -12,6 +13,7 @@ #include #include #include +#include =20 #include #include @@ -50,6 +52,8 @@ =20 #define PAGE_SIZE (4 << 10) =20 +#define STACK_SIZE 65536 + #define barrier() ({ \ __asm__ __volatile__("" : : : "memory"); \ }) @@ -731,6 +735,75 @@ static int handle_inheritance(struct testcases *test) return 0; } =20 +static int thread_fn_get_lam(void *arg) +{ + return get_lam(); +} + +static int thread_fn_set_lam(void *arg) +{ + struct testcases *test =3D arg; + + return set_lam(test->lam); +} + +static int handle_thread(struct testcases *test) +{ + char stack[STACK_SIZE]; + int ret, child_ret; + int lam =3D 0; + pid_t pid; + + /* Set LAM mode in parent process */ + if (!test->later) { + lam =3D test->lam; + if (set_lam(lam) !=3D 0) + return 1; + } + + pid =3D clone(thread_fn_get_lam, stack + STACK_SIZE, + SIGCHLD | CLONE_FILES | CLONE_FS | CLONE_VM, NULL); + if (pid < 0) { + perror("Clone failed."); + return 1; + } + + waitpid(pid, &child_ret, 0); + ret =3D WEXITSTATUS(child_ret); + + if (lam !=3D ret) + return 1; + + if (test->later) { + if (set_lam(test->lam) !=3D 0) + return 1; + } + + return 0; +} + +static int handle_thread_enable(struct testcases *test) +{ + char stack[STACK_SIZE]; + int ret, child_ret; + int lam =3D test->lam; + pid_t pid; + + pid =3D clone(thread_fn_set_lam, stack + STACK_SIZE, + SIGCHLD | CLONE_FILES | CLONE_FS | CLONE_VM, test); + if (pid < 0) { + perror("Clone failed."); + return 1; + } + + waitpid(pid, &child_ret, 0); + ret =3D WEXITSTATUS(child_ret); + + if (lam !=3D ret) + return 1; + + return 0; +} static void run_test(struct testcases *test, int count) { int i, ret =3D 0; @@ -846,6 +919,25 @@ static struct testcases inheritance_cases[] =3D { .test_func =3D handle_inheritance, .msg =3D "FORK: LAM_U57, child process should get LAM mode same as paren= t\n", }, + { + .expected =3D 0, + .lam =3D LAM_U57_BITS, + .test_func =3D handle_thread, + .msg =3D "THREAD: LAM_U57, child thread should get LAM mode same as pare= nt\n", + }, + { + .expected =3D 1, + .lam =3D LAM_U57_BITS, + .test_func =3D handle_thread_enable, + .msg =3D "THREAD: [NEGATIVE] Enable LAM in child.\n", + }, + { + .expected =3D 1, + .later =3D 1, + .lam =3D LAM_U57_BITS, + .test_func =3D handle_thread, + .msg =3D "THREAD: [NEGATIVE] Enable LAM in parent after thread created.\= n", + }, { .expected =3D 0, .lam =3D LAM_U57_BITS, --=20 2.38.2