Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9484365rwl; Wed, 11 Jan 2023 06:20:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXteS3cDcyRiWPTf42T1hADv66dVFvvgOgsk0KBNYvPisxIavx9YM9vepGtUBb72WOcBS5vG X-Received: by 2002:a17:903:181:b0:193:3154:5c86 with SMTP id z1-20020a170903018100b0019331545c86mr15537760plg.21.1673446803047; Wed, 11 Jan 2023 06:20:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673446803; cv=none; d=google.com; s=arc-20160816; b=AYDP1eGHgHczNxyrg82HWrvFBiUwXRnRshrwdGDyiRd2ZVxvokU+uPAmO6pHU2iCqX uJn+G4YLUAengud/aHg1sL9Tz/ECezFuI61ZHEf2KETZrsRAi2PMDOasod7vJF/EoNgx sASf7LKv7CDSVo/fx/HVrpctFcSlE/zOo/yG9q135vHobkpZgLNryHalIuM5a5QUmlJ0 V2orJTQJRd3t2qXDPclSHrdY1mcjK4wF/ou+Ac6S3SeWXim4PViC+j7KrP5G0N+ERFO/ iQqK71Reb7ILd2p8DtvQKDzonMaQRfDzC2aa1mW/Hg3ZS88rkrg9KRJ/VSo+vnOgfLGT Nmbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ndhjY0FXUCMFSa32IGE1nAjZD8csY3IWkZ1zvnSeNd0=; b=G8NSQmBNY1E2n9DNrusRpewVhHPs3M6x3HV3nqBlKM+7xhBFIQSMy4ynivo37tUIO3 PCz0z3XSq42qg58Co/pNqu6NARAK5VqLWnBJaQxkxn7rqKq14HHg4KHg+a/6b5L3oMOW 4CooNzyLCyp/MFOGaJ/EcdDJc/GaqyMOckdnU4QmmlpxGj0quEUa9ly8PopfDfIVb9D4 U1bVnKIZP5TyNnOYUWGbeDl95Ndq2CfyMqc7gzbD5T0Gf8nfvaHpBUt9zlhWH8Nb1+iZ ihGPIFy09xEjSfk6LguKgC2lzEvxqP4a3ddJZRjGiFRmI6xiyE/3hl4YLVVUMZft10Qj JSQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Z2Oc/SBL"; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n14-20020a170902e54e00b00189e752b2f8si15200853plf.328.2023.01.11.06.19.55; Wed, 11 Jan 2023 06:20:03 -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=@intel.com header.s=Intel header.b="Z2Oc/SBL"; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233245AbjAKNXv (ORCPT + 53 others); Wed, 11 Jan 2023 08:23:51 -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: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 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/x86/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 #include #include @@ -50,6 +52,8 @@ #define PAGE_SIZE (4 << 10) +#define STACK_SIZE 65536 + #define barrier() ({ \ __asm__ __volatile__("" : : : "memory"); \ }) @@ -731,6 +735,75 @@ static int handle_inheritance(struct testcases *test) return 0; } +static int thread_fn_get_lam(void *arg) +{ + return get_lam(); +} + +static int thread_fn_set_lam(void *arg) +{ + struct testcases *test = arg; + + return set_lam(test->lam); +} + +static int handle_thread(struct testcases *test) +{ + char stack[STACK_SIZE]; + int ret, child_ret; + int lam = 0; + pid_t pid; + + /* Set LAM mode in parent process */ + if (!test->later) { + lam = test->lam; + if (set_lam(lam) != 0) + return 1; + } + + pid = 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 = WEXITSTATUS(child_ret); + + if (lam != ret) + return 1; + + if (test->later) { + if (set_lam(test->lam) != 0) + return 1; + } + + return 0; +} + +static int handle_thread_enable(struct testcases *test) +{ + char stack[STACK_SIZE]; + int ret, child_ret; + int lam = test->lam; + pid_t pid; + + pid = 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 = WEXITSTATUS(child_ret); + + if (lam != ret) + return 1; + + return 0; +} static void run_test(struct testcases *test, int count) { int i, ret = 0; @@ -846,6 +919,25 @@ static struct testcases inheritance_cases[] = { .test_func = handle_inheritance, .msg = "FORK: LAM_U57, child process should get LAM mode same as parent\n", }, + { + .expected = 0, + .lam = LAM_U57_BITS, + .test_func = handle_thread, + .msg = "THREAD: LAM_U57, child thread should get LAM mode same as parent\n", + }, + { + .expected = 1, + .lam = LAM_U57_BITS, + .test_func = handle_thread_enable, + .msg = "THREAD: [NEGATIVE] Enable LAM in child.\n", + }, + { + .expected = 1, + .later = 1, + .lam = LAM_U57_BITS, + .test_func = handle_thread, + .msg = "THREAD: [NEGATIVE] Enable LAM in parent after thread created.\n", + }, { .expected = 0, .lam = LAM_U57_BITS, -- 2.38.2