Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp395471lqb; Tue, 4 Jun 2024 15:00:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWnlb9LBCqft5F8V5E1rgXVSbUkVr/M/R/erOyfTbhyo2lwJaH9mL3/0Ha3uM04iJ4gJ56RvOl+0ClBhStp79ADTbXMbOcDJCYfE/JSdw== X-Google-Smtp-Source: AGHT+IFBxyFNnJSdvvfqKU6dcIjNodjpzjKiTTDtDKABSxcuPoCdZsBtxzWu2vKACxDxiVg1Uqh8 X-Received: by 2002:a17:90a:b297:b0:2c1:948b:6f2c with SMTP id 98e67ed59e1d1-2c27db5ce10mr842227a91.39.1717538450469; Tue, 04 Jun 2024 15:00:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717538450; cv=pass; d=google.com; s=arc-20160816; b=UXnBw5S1ZltC3K2OHMbXiZ29I1+lvWljgcURn0hUyhbHV4YIjcvtyWYZams865A2q6 ASzhTP/2KIdfnMzKvh9SgDnt879LkJerppwGpGnFcE3ZCWnAi2ObOeAapw+mCc2peFYg 7HbqkUlnrSGJsCTanh2llwdyQ7haj7aIna2I326Gh32VrOsusy+lktn5EDDFm1edAmzI TQO8+TtThJnRDY2Oc6Qt87azLf4RDBCGf6Q2s7zw5uTUcGGcbJjIro1kEqy2E0n0WJP0 8D50efMCEURgWJVbjPoUxNqD1LPxuNTp6oqsgBvcGHEHYj5o3kNyCzey+fvpO+kjuz+7 +5qw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=dkT/bMJjzG4XhPFTehWSHHJ3jYB/YtLavjG1o/X1/lA=; fh=O/HDNTaprEU6+2NekXFHdrqtcw+UHBBY93oZGoG+mUs=; b=IWowKhntp9haYLmMR45pYJMgufRkDaOLZrmhbOhF2tJSVhvJl88D68Pz02Wiz/8jEG 8LAzwPKEnkpxcUEcwYyMJe3RVsCGpzrF/HJ7YWQLOMLlLTeZ3GtqvjsNmKs5enIyV7d/ yEkuNK923eH4+RRze4UPeqyjXpm1S9R9Qz6TdNPhY6s3n7RuF5AVvWe2ZC5Ms0d00SVH 02LH1eb3y/3GYP0TNa1afdsl9h8D8mD3sTCQRir+UtLRidEJPBCq89GYMuIkEavFf1bo GdRzvn3Y2PDQHjYJY++wq5I5QC/flvRfV73fwcdmwbTWfWva/cV5pPMv4w8wSYtcIT2Z f74A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U50dsZ7k; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-201430-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201430-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c2806aef37si12743a91.161.2024.06.04.15.00.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 15:00:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201430-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U50dsZ7k; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-201430-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201430-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CE5CA2870E3 for ; Tue, 4 Jun 2024 22:00:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75F8913A41A; Tue, 4 Jun 2024 22:00:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U50dsZ7k" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91DE3320C; Tue, 4 Jun 2024 22:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717538441; cv=none; b=ok3902EVtwQso5aQEjbW8toDNWQAe4mfQM7v124ra1jg8aUhwhWUSTRWQFefoTboWOnqRRQ9aMm7tcpbXjHCL9ZVUant7oA7bFqo1PfkHjz2otppUWJhHQmzF2PX0sDXUY84XxkYKSOKouYipCUgxo/y/+QFtEFbNW0AkBE2sN4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717538441; c=relaxed/simple; bh=NQTkQHeOY2E4PqUwFkIfMHALr0nDPHYLaa8Ap72Ep8Y=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=NAoP1ZJrIugPni22ukBS+64DWBwhE0WRpq/rTx8GPD/tNj/LmVl5T/zidsmKKnqAFSxT71Ty7ui8193Npi2eiKGNnHUGUqH4cNNGHyUPv01nKMCQj16AZ7Y+5oz2hofAngq93LnUMlAXJGYdVGZAD/TiojdA03qf7EA8U53tlQo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U50dsZ7k; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEBADC2BBFC; Tue, 4 Jun 2024 22:00:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717538441; bh=NQTkQHeOY2E4PqUwFkIfMHALr0nDPHYLaa8Ap72Ep8Y=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=U50dsZ7kNEoV6ry+gD9c+oSDIESJkBhMtrEG0ihzGUQzRWSAj1ZPQ0GqHscmPTzjA vWPuT8/Q1HYBzltMWxDReryIfS5+6YjwjkqtmzH4wLlJV1u+OiUzuXQsBTRUsngZU+ X0m0HFeSox3lHiC6YyXmxHNh8LA/cJ9T+eKyXm/aDiNh78NR1tiVgmAUY70ddzDdrb ncv4P7an+gJZmV44yNBFygxQxtstaNiR9A+ekpCFIf7ur/BE+AgUSI1E77g9w8SbZ0 NB89P+x3jWqgzQTJF+akXLo7a+rxJO9QQY0fZwk9Jsk+udi9f4RrbqqYEzsgHPP/eN 5z+9SXd2keR2w== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 05 Jun 2024 01:00:34 +0300 Message-Id: Cc: , , , , , , , Subject: Re: [PATCH v14 14/14] selftests/sgx: Add scripts for EPC cgroup testing From: "Jarkko Sakkinen" To: "Haitao Huang" , , , , , , , , , , , , , , X-Mailer: aerc 0.17.0 References: <20240531222630.4634-1-haitao.huang@linux.intel.com> <20240531222630.4634-15-haitao.huang@linux.intel.com> In-Reply-To: <20240531222630.4634-15-haitao.huang@linux.intel.com> On Sat Jun 1, 2024 at 1:26 AM EEST, Haitao Huang wrote: > With different cgroups, the script starts one or multiple concurrent SGX > selftests (test_sgx), each to run the unclobbered_vdso_oversubscribed > test case, which loads an enclave of EPC size equal to the EPC capacity > available on the platform. The script checks results against the > expectation set for each cgroup and reports success or failure. > > The script creates 3 different cgroups at the beginning with following > expectations: > > 1) small - intentionally small enough to fail the test loading an > enclave of size equal to the capacity. > 2) large - large enough to run up to 4 concurrent tests but fail some if > more than 4 concurrent tests are run. The script starts 4 expecting at > least one test to pass, and then starts 5 expecting at least one test > to fail. > 3) larger - limit is the same as the capacity, large enough to run lots o= f > concurrent tests. The script starts 8 of them and expects all pass. > Then it reruns the same test with one process randomly killed and > usage checked to be zero after all processes exit. > > The script also includes a test with low mem_cg limit and large sgx_epc > limit to verify that the RAM used for per-cgroup reclamation is charged > to a proper mem_cg. For this test, it turns off swapping before start, > and turns swapping back on afterwards. > > Add README to document how to run the tests. > > Signed-off-by: Haitao Huang > Reviewed-by: Jarkko Sakkinen > Tested-by: Jarkko Sakkinen Reorg: void sgx_cgroup_init(void) { struct workqueue_struct *wq; /* eagerly allocate the workqueue: */ wq =3D alloc_workqueue("sgx_cg_wq", wq_unbound | wq_freezable, wq_unbound_= max_active); if (!wq) { pr_warn("sgx_cg_wq creation failed\n"); return; } misc_cg_set_ops(MISC_CG_RES_SGX_EPC, &sgx_cgroup_ops); sgx_cgroup_misc_init(misc_cg_root(), &sgx_cg_root); /* Depending on misc state, keep or destory the workqueue: */ if (cgroup_subsys_enabled(misc_cgrp_subsys)) sgx_cg_wq =3D wq; else destroy_workqueue(wq); } BTW, why two previous operations are performed if subsystem is not enabled? I.e. why not instead: void sgx_cgroup_init(void) { struct workqueue_struct *wq; /* Eagerly allocate the workqueue: */ wq =3D alloc_workqueue("sgx_cg_wq", wq_unbound | wq_freezable, wq_unbound_= max_active); if (!wq) { pr_warn("sgx_cg_wq creation failed\n"); return; } if (!cgroup_subsys_enabled(misc_cgrp_subsys)) { destroy_workqueue(wq); return; } misc_cg_set_ops(MISC_CG_RES_SGX_EPC, &sgx_cgroup_ops); sgx_cgroup_misc_init(misc_cg_root(), &sgx_cg_root); sgx_cg_wq =3D wq; } Finally, why this does not have __init? And neither sgx_cgroup_misc_init(). The names for these are also somewhat confusing, maybe something like: * __sgx_cgroups_misc_init() * sgx_cgroups_misc_init() And both with __init. I just made a trivial checkpatch run as a final check, and spotted the warning on BUG_ON(), and noticed that this can't be right as it is but please comment and correct where I might have gotten something wrong. With "--strict" flag I also catched these: CHECK: spinlock_t definition without comment #1308: FILE: arch/x86/kernel/cpu/sgx/sgx.h:122: + spinlock_t lock; CHECK: multiple assignments should be avoided #444: FILE: kernel/cgroup/misc.c:450: + parent_cg =3D cg =3D &root_cg; BR, Jarkko