From patchwork Wed Jan 11 12:37:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 41981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3318028wrt; Wed, 11 Jan 2023 05:25:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXs1p2p+mIVQp/oDjYgLhDPczf+65gcOCX8PXCXceqwKymzAnf1PHYy922gEWW2tZPDpjG5M X-Received: by 2002:a17:90a:acf:b0:226:ddf6:b7da with SMTP id r15-20020a17090a0acf00b00226ddf6b7damr19212201pje.41.1673443540815; Wed, 11 Jan 2023 05:25:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673443540; cv=none; d=google.com; s=arc-20160816; b=CO9GpfEVgToZ4pmFiaRLjYDKFwdMkMAYvKM6PMfxNMjvv2EQ6KLOB5uC5Q5U7kYOB0 kHfSuSqAxvIIgMajjZ/T73VimmwMEWBaee1txNRVp676WWbM4DuJOh3GDJ9+zg+inVza VA9gW5DK/Wm9Db3SKZBvMPhtRU+Ns+yGKSCD/lCrpyVUP3gBZtFKtkwmM/ZypVoNYL8O vU9vSRGhASpC3lSnKhmUPApI8IrullmaG1zf0PNlIJ7V7CZUEPfXMTs9RaJWKKAT2o5m mjkGwTarMzNrB27bY+Osf/5tzoxbIsheWkIqpIRMagPFyWtQHFFoj1DUxctvObLY3KtR cphQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lb13-20020a17090b4a4d00b00228ea30ff29si1165321pjb.23.2023.01.11.05.25.27; Wed, 11 Jan 2023 05:25:40 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754732734052674050?= X-GMAIL-MSGID: =?utf-8?q?1754732734052674050?= 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,