Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1100149lqa; Sun, 28 Apr 2024 19:29:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXj5sb6Dk4MzbKQQoHaiGw8M6zpDsKchVFr8KVS1JpJ1YK3XIxw+8s22lpg6iMb5Xrn0Ooh9RD08ZlKfK0W1WzTaU0M9f48RKgjkEH8/g== X-Google-Smtp-Source: AGHT+IEvOidN83W//KS3TL0PwXTuHW5RsCkND3gigTQ6+K+Ddoo7L6ATO5bl34k7ajWAhHc17Q+9 X-Received: by 2002:a05:6358:78d:b0:186:436a:c686 with SMTP id n13-20020a056358078d00b00186436ac686mr10362667rwj.25.1714357745147; Sun, 28 Apr 2024 19:29:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714357745; cv=pass; d=google.com; s=arc-20160816; b=KriH8ZbigQaukljHgYfizBg1ZPq7JhAzH6rylaQa5MhCw5t/DltFub49UZC+LVovVf gqV7rsRviuLcUnFfZXyH6mJZ93eqffjv3L5lYwInuugZ9tHSBSsiepc2hCXU9Xa86FR+ guJ2hB92H8OFASQQ/nTj8VlfzxzdJDux4q7vf6N89K1vLF1Rz5FlFa0N4rcNwyUBfUTr QBceCvohQtkn0bz2TruvzGxRLpEq6KFkLNyonAIYGNfmCqiSGefDsrdfbcW2S0htEbpq vUyQjbZZzqz9wgwiUbt+tInmQVJm39Vd1hn/SeF9DwUsHeHrKVodu8im9JOybH3+q3cH xnYw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=jT7mAVU8gcg5YtFTPn+gZh0CF87ozRgd/5PRarkdmMI=; fh=CqmnKTkEgnXJpDv8q/TgPCFJZ3ol5WxA2r326AQtS9s=; b=E50byUafzaLurNloMgXstmhNrIZk0+nlDRTPWEe59Ej8I9JI3ir4Gk0Rs/SZCqk9tF ygssEK1IWaPWEa5uCPrvH5QiIYq1oj50Ciwsz0UbsgureXZwQhyO3qP8ELlCYxY/ED+3 PelywZOxN9jLvheSbBJQEbpZFc+MvzvT1p3Lv55WF/VDSOG2PHKyiliMpwLoYfYaPS6W wCk88N2+cpNLYy6Ib1GI4Ckrz3JWHVkF3uf8iXlE3fAOwmTx8XK1yc4P9nbxloVjh7S3 f+Ln6wed9gh/FinHxIMAFym4AeE0a3J0DO2AFFeFgVUloeAt93NEB2Woz3tCwHPxEEER /mqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@antgroup.com header.s=default header.b="i0VpV/Ky"; arc=pass (i=1 spf=pass spfdomain=antgroup.com dkim=pass dkdomain=antgroup.com dmarc=pass fromdomain=antgroup.com); spf=pass (google.com: domain of linux-kernel+bounces-161682-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161682-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id fi30-20020a056a00399e00b006ea9ca4970esi19384167pfb.343.2024.04.28.19.29.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 19:29:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161682-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@antgroup.com header.s=default header.b="i0VpV/Ky"; arc=pass (i=1 spf=pass spfdomain=antgroup.com dkim=pass dkdomain=antgroup.com dmarc=pass fromdomain=antgroup.com); spf=pass (google.com: domain of linux-kernel+bounces-161682-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161682-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E8FC3B20FBF for ; Mon, 29 Apr 2024 02:29:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FE051851; Mon, 29 Apr 2024 02:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="i0VpV/Ky" Received: from out0-212.mail.aliyun.com (out0-212.mail.aliyun.com [140.205.0.212]) (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 3FCED7F; Mon, 29 Apr 2024 02:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.205.0.212 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714357735; cv=none; b=MwgczTHvdh+ZLlNb5wFA5u6Ned2/tFomZQDN3UjzZjirOfBYNFOZlUqkGf+NCYy7op/nJMGUYfR5rHAehaEUoyAkMgpooxRExgjyKbWPh0hbDzyiiClTBuB1Od+tIJjKf1Lmpf1ULXS0nBSdDDuvLOdqU5mnPBxxTijL3SHR36k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714357735; c=relaxed/simple; bh=rgmPIBtv04xS/NJZfML1GPnR64jTHK95wha30aKgRC4=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=aSGm0At9IskOcQstmx1ZV1AGxdeIQCnKHNkhzxlErXgQJyZLFWMYswbeVZLVbdHaAOfY3v8kCvpSqwQme/J13MKAZaJLhOT4uJELY3OeHCxBsTEG8mDR3FWfbEqlU0+nHScPrG1k/B3kbw7w0XrBKFSJ+GcfJBg+FANygltFGI8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=i0VpV/Ky; arc=none smtp.client-ip=140.205.0.212 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1714357723; h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To; bh=jT7mAVU8gcg5YtFTPn+gZh0CF87ozRgd/5PRarkdmMI=; b=i0VpV/KyTRQi8K95bjKOx/1QLAyxIicE2syfgPkD5XOEvDPUcLg7J7cwP8RaexXxHUQCfExiECdSy7/Qp044us0jD5ThWHSAurp760LQW6uUFQNM6MyInLcqf4+a9yWj2+JtA8oXynxs9nUh9K197Egn6gV0rZH2S/tS5eZQSJs= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R601e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047201;MF=zhubojun.zbj@antgroup.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---.XNqNRHq_1714357403; Received: from smtpclient.apple(mailfrom:zhubojun.zbj@antgroup.com fp:SMTPD_---.XNqNRHq_1714357403) by smtp.aliyun-inc.com; Mon, 29 Apr 2024 10:23:24 +0800 Content-Type: text/plain; charset=utf-8 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.100.2.1.4\)) Subject: Re: [RFC PATCH v2 1/1] x86/sgx: Explicitly give up the CPU in EDMM's ioctl() to avoid softlockup From: "Bojun Zhu" In-Reply-To: <30415ed3-a05a-454d-9077-c8674617f291@intel.com> Date: Mon, 29 Apr 2024 10:23:12 +0800 Cc: , , "Jarkko Sakkinen" , , "=?UTF-8?B?Q2hhdHJlLCBSZWluZXR0ZQ==?=" , "=?UTF-8?B?5YiY5Y+MKOi9qeWxuSk=?=" Content-Transfer-Encoding: quoted-printable Message-Id: References: <20240426141823.112366-1-zhubojun.zbj@antgroup.com> <20240426141823.112366-2-zhubojun.zbj@antgroup.com> <30415ed3-a05a-454d-9077-c8674617f291@intel.com> To: Dave Hansen X-Mailer: Apple Mail (2.3774.100.2.1.4) Hi Dave, Appreciate for your review! > On Apr 27, 2024, at 01:06, Dave Hansen wrote: >=20 > On 4/26/24 07:18, Bojun Zhu wrote: >> for (c =3D 0 ; c < modp->length; c +=3D PAGE_SIZE) { >> + if (sgx_check_signal_and_resched()) { >> + if (!c) >> + ret =3D -ERESTARTSYS; >> + >> + goto out; >> + } >=20 > This construct is rather fugly. Let's not perpetuate it, please. Why > not do: >=20 > int ret =3D -ERESTARTSYS; >=20 > ... > for (c =3D 0 ; c < modp->length; c +=3D PAGE_SIZE) { > if (sgx_check_signal_and_resched()) > goto out; >=20 > Then, voila, when c=3D=3D0 on the first run through the loop, you'll = get a > ret=3D-ERESTARTSYS. >=20 Okay, I will refine it later. > But honestly, it seems kinda silly to annotate all these loops with > explicit cond_resched()s. I'd much rather do this once and, for > instance, just wrap the enclave locks: >=20 > - mutex_lock(&encl->lock); > + sgx_lock_enclave(encl); >=20 > and then have the lock function do the rescheds. I assume that > mutex_lock() isn't doing this generically for performance reasons. = But > we don't care in SGX land and can just resched to our heart's content. `mutex_lock(&encl->lock)` appears in everywhere in SGX in-tree driver. But it seems that we only need to additionally invoke `cond_resched()` = for the sgx_enclave_{restrict_permissions | modify_types | remove_pages }=20 and sgx_ioc_add_pages()=E2=80=99s ioctl()s.=20 Shall we replace all the `mutex_lock(&encl->lock) with = `sgx_lock_enclave(encl)`=20 in SGX in-tree driver and then wrap reschedule operation in `sgx_lock_enclave()` ?=20 Regards, Bojun=