From patchwork Wed Mar 22 17:03:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 73544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2460619wrt; Wed, 22 Mar 2023 10:15:58 -0700 (PDT) X-Google-Smtp-Source: AK7set9Q8HBzGABhIStEWKKKR42w1QF3FH9x+ixLyCkdRIM3ldndAOMafthpJW3QX7vEuiElJRKM X-Received: by 2002:a17:906:2753:b0:908:7fed:f0f with SMTP id a19-20020a170906275300b009087fed0f0fmr8315137ejd.42.1679505358631; Wed, 22 Mar 2023 10:15:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679505358; cv=none; d=google.com; s=arc-20160816; b=MdSg3ot7qoAUyxYgccbp+u4UsJc5fZw5BnASZffVs9op7Rd7sUZ5mij25wfRJuksM9 7A71WuvJmZ4V+mqFWZbSeSpB2tLrabqY/5+AZm1h48P2pKC1a/L6OvHA8q+tF/NqYMFB NGtfIgG7QAHVBY5NXFFqXQ4JAiA3SJ/3W1BxzTdncK+4zoCPL69RIlHLjCqUL3rnSLkB /YRih/TY9SMPKT4vBOft8oUm86JH5yEJ17sFUA6cOo9NZaJTuVujYJxyQD7dPTd+an0+ BmwS7AlNpMGu9DRacBLjUu0+nwAngPOxPZ4H31PMFPmCFJwaEJ1iSMfw9Lr1PtpOLi1a RRvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=oMpc9GjKiKzOfugOngBxJGxql9QSACRvf4WRe2BBm6A=; b=RheMHQVTRaimKzWGJWXlcinAGjOUH5rCpNXddvi+0Ee1tx09atRXtc2pK/nwJclWk4 f06/ssZWQTendtzMpu86WTHXy0FxiK66nUcKpKbNOafJR3BI/u0zN5wVkpUbNz2ZBrCg abUH8gOwcJ/N4d7xHn2YIzh66fz8jcK4fbw/PM3yHPVuDaqaRTNjZvf6jRvJ8ngx7/wZ PvPRbEPGDj7vk2Mjiak2XzscdYtBAzF3ufOTW4+x1EBNQpjhQU6DyXypbwlNXTMZZfFA xVxz01nEqYqtVF95SUFA5t8TSX+Lz0NdXacTSBYiZn8Wkj8IDFaAdmJ75OH7RWKbkgQl kyFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TS6XD55S; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vyTai8vb; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne16-20020a1709077b9000b0093b441fef0fsi3273732ejc.295.2023.03.22.10.15.35; Wed, 22 Mar 2023 10:15:58 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b=TS6XD55S; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vyTai8vb; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231196AbjCVREY (ORCPT + 99 others); Wed, 22 Mar 2023 13:04:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231339AbjCVRDt (ORCPT ); Wed, 22 Mar 2023 13:03:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CD397EF4; Wed, 22 Mar 2023 10:03:24 -0700 (PDT) Date: Wed, 22 Mar 2023 17:03:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1679504584; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oMpc9GjKiKzOfugOngBxJGxql9QSACRvf4WRe2BBm6A=; b=TS6XD55S8eqCToqI2HYTyXG+RtH1536/AxgS+wdhM1sxa63H5PzKrqyZWNXXo0bd3hVUoT KwaDBs9rhznGr1IiQ04/7zEHDjmLBK/l4Sl+JXOPHpnP9g6rv1+H6l6SDUBPkPZ4TOgVnA yMFrSDR9K6m5rwyC9IeqZJVofLrzVRcasQDNjvdfXDpTjzUpTDaj97UyFVsQ7gDgmRCqLg 8b2ayxMMNgJGtDHoWQiffgCzbMJLGbb/J4C6gf0iL0mhKokVfhZrmGPMuNNw3c8ObCU85/ zwfQ+FETIFthrW3tM62CkaSmXh8dPa5gdzbGmNr3LAN+Y/ndbcPJDm+LnWnN/g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1679504584; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oMpc9GjKiKzOfugOngBxJGxql9QSACRvf4WRe2BBm6A=; b=vyTai8vbjRdm3AWvO0Tw3/AgtspWxK0LNutUUvlBV59ryVhov0StvaFNmnwY0fHl21ABdK VAYtGVow+jDsJNDg== From: "tip-bot2 for Kirill A. Shutemov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] selftests/x86/lam: Add test cases for LAM vs thread creation Cc: "Kirill A. Shutemov" , Dave Hansen , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <167950458385.5837.2205725754203915953.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable 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?1761089011000030096?= X-GMAIL-MSGID: =?utf-8?q?1761089011000030096?= The following commit has been merged into the x86/mm branch of tip: Commit-ID: dfd7a1569e25996575a24725b64f73162155bcd6 Gitweb: https://git.kernel.org/tip/dfd7a1569e25996575a24725b64f73162155bcd6 Author: Kirill A. Shutemov AuthorDate: Sun, 12 Mar 2023 14:26:12 +03:00 Committer: Dave Hansen CommitterDate: Thu, 16 Mar 2023 13:08:41 -07:00 selftests/x86/lam: Add test cases for LAM vs thread creation 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 Signed-off-by: Dave Hansen Acked-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/all/20230312112612.31869-18-kirill.shutemov%40linux.intel.com --- 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 a8c9182..eb0e469 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; @@ -849,6 +922,25 @@ static struct testcases inheritance_cases[] = { { .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, .test_func = handle_execve, .msg = "EXECVE: LAM_U57, child process should get disabled LAM mode\n", },