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: 13096654 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72C6DC46467 for ; Wed, 11 Jan 2023 13:23:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8A458E0002; Wed, 11 Jan 2023 08:23:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E3A848E0001; Wed, 11 Jan 2023 08:23:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D024C8E0002; Wed, 11 Jan 2023 08:23:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C0A938E0001 for ; Wed, 11 Jan 2023 08:23:51 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8D4648098E for ; Wed, 11 Jan 2023 13:23:51 +0000 (UTC) X-FDA: 80342585862.18.8DA4FA5 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by imf02.hostedemail.com (Postfix) with ESMTP id 0091880016 for ; Wed, 11 Jan 2023 13:23:48 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=PJJWHGvb; spf=none (imf02.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.100) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673443429; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ndhjY0FXUCMFSa32IGE1nAjZD8csY3IWkZ1zvnSeNd0=; b=KpN34oLaiE7BhEUTdnqNFZQJAB0Ms7Kb+pvmYNBX7EALNC76yyx+4JRCtpfrCFiuP/ExHn ejwjOAae+mEc5Itl7D+MG4YnoQCq6gYXrfFqa4agEE41cuH0njZea3dFrRNnWMVMTnXuAL CH8tKiEP1oa/2uISrdGxwH3rdxveDSQ= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=PJJWHGvb; spf=none (imf02.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.100) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673443429; a=rsa-sha256; cv=none; b=juxRnrUM59DTxdqtztqgHhOYW57bUYwH+65dxkPbrtuqP8vh0IGfdzyAACHJpSQ6kRLXqW 3KSg2bX8pyOCtqk4fTU/6S1se1lt1GYNbu5XSecZIbs+7M8R56ox0Rc75Oly6U1q18CLg6 P102EE59oMH+dMMPkVRxQjz+PRDiJHw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673443429; x=1704979429; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nLb+D373AsFdYz+VydkUKZ3nmk+8SeRPO35WqLjs/ys=; b=PJJWHGvbK2KjWGaqA/CdKowGFAOSGfYz2jOMnD1TW5JhFRUzYnuYeN0m CDAOq3D+rMaBXR0GF9PLPLZ73CZfmiXDhg24Q9eaVj4DXaSHflwe47JUx HuPgpVpIVVEFuWGSMLz4N0UClgYYO+lqa2d5Hc0wAyBNuG5/uEfrCv1Oh YnzJhn0uXvaHswOeO0WJFdWeB4Pz0MFMmv433qlsdhgmjLnwkQpKbJimy blgiwRDoLM9Sx3cC1Bozi5yTreItNwBssS6Pz2JGcy9uJ6ZBFTCxatDMS 611z3qxH68Ws3HHgJK68NM5QoOvbvX81LBUhHFQCLJsj3+yp+xn7hndg9 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="387872488" X-IronPort-AV: E=Sophos;i="5.96,317,1665471600"; d="scan'208";a="387872488" 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-Stat-Signature: hykht3z5hhssrk46dzgitwco94dsq4wz X-Rspam-User: X-Rspamd-Queue-Id: 0091880016 X-Rspamd-Server: rspam06 X-HE-Tag: 1673443428-779254 X-HE-Meta: U2FsdGVkX1+Pykb6Kur1u9SB4B0oczm3jgCd5TJWsEtG41y39VYpqVwID2CnnLzkg9e2SkSUxcU+/qgC01PzCZ8f8dziOKJ5qyLUwygj5rWw8HCexHT3ZyhQf+L3WfH5lYZlkEKy6ldg/ErBQUY2VIZGP2gyHsi8+uY/G8M0XHLgA1CtaIuICmyI7Abj2JIRGxdHSHzRmfBv0UgzPSNI0mLOyz+6P6kOiOd+WCC9vcAxgGgrzOKU7HOU0ARKmJsaNSe2wYV+pfJxWdWIHJvdTaN0ApOR2q0Fu+zaw3zHraR1zxaw8EkhULHdgiaCWfuMTT0sXzydZylcorGL7IDVTx98crr9QiU+5lnUEfZNECHJbvxkwSaj2TqVaWVncmszFARtb6nem5yBNdGnZUPwl1r+/mOJQZWDfJqckvBCqQa4QSeYo2MpuXHAA5acxAVSAwwhSVUB6XtsilFB9hUuYX7JmNB7gTkYDR38VfLwa27NQp9RhqQ+zvObN+zCvJY+ndG8Co/F18t5H8YygP6881TJvnrbs9NZHzl1UZo5cTjKZp2absNeGB9/RgVbbwlRqyVjYj5qH8sqt6qN2ZFOMHouuTImHv/JrDUz3f4dsshejXpwAe/4tv0MChHbzIcs7XPwNaoU2bdqRiDaSQjDt5QAUKZrsLUUYrU7dX55s8Hi+0NMlcob507ZaPTWup1AsjK9zre+cCJrDJn4eA7FI0zZiyUJzOjlTDKFG6Yw6CYIyCN8BS16bYlE/PPZ3lF93tOC2Ha300MN/BlMyoa+80swzUR3BryPuF1dhJraR3zmak/VYrNhkUWjlKdtjjSn+7Om1iGTucZC++pntoyqifqMCsvbnZ69g3jGY+42xEi/wSNHG4aDQwGujpyEkFigHkC/By1wm9KVTpHBzy0knQfsL3nBpJNNqawFYP4ovqQ2G35LX5mY8ohu9JptM+wyMycLnRcjIaM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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,