From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC31DC43461 for ; Wed, 9 Sep 2020 09:56:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70B59207DE for ; Wed, 9 Sep 2020 09:56:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="DkXPn3vV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727113AbgIIJ4Q (ORCPT ); Wed, 9 Sep 2020 05:56:16 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:36694 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725864AbgIIJ4M (ORCPT ); Wed, 9 Sep 2020 05:56:12 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0899sdcc105246; Wed, 9 Sep 2020 09:56:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : in-reply-to : references : date : message-id : mime-version : content-type; s=corp-2020-01-29; bh=cWr4fsJ3cUouor9+S1PGF/0q4IMawHo7uuemCdRxs/g=; b=DkXPn3vVdRTFXrgmr3DHGN0t/F6QJosjDkNHJVTqSCsx1qvxtOc61BJQIXeANEZwykC+ iwSWsey9bD91GWQ2Hgo6e3N9O5hzDUDxRT37DwIbxzml8hoQGLGCuw3tFWeUOOxJFTdE ZBhKjGIhlBly2WXhcPq9HcvRrAgCoQmKe6SbdVu6MXXW0Jomkf3KayyjNtxqTZ5zzInv 8ORaQZlE+sRoenhiujgXqKhc0Fj8OKaXGdIGbb2o5EvruUochLYH0M0gKNbk7dZp90rr 5MPKMmhpjAVTKYngb6bM25b4UgYzqABTpO6BtJ93DHVxKuDFrZeoMX9oz8N9wPngmN+Q 6Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 33c2mm0qed-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 09 Sep 2020 09:56:03 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0899oMKu001988; Wed, 9 Sep 2020 09:56:03 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 33cmkxg1dq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Sep 2020 09:56:03 +0000 Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0899u1Ru006571; Wed, 9 Sep 2020 09:56:01 GMT Received: from starbug-mbp.localdomain (/79.97.215.145) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 09 Sep 2020 02:56:01 -0700 Received: by starbug-mbp.localdomain (Postfix, from userid 501) id 25942142B311; Wed, 9 Sep 2020 10:55:58 +0100 (IST) From: Darren Kenny To: Jarkko Sakkinen , linux-sgx@vger.kernel.org Cc: Jarkko Sakkinen , Sean Christopherson , Borislav Petkov Subject: Re: [PATCH] x86/sgx: Roof the number of pages process in SGX_IOC_ENCLAVE_ADD_PAGES In-Reply-To: <20200908190042.24895-1-jarkko.sakkinen@linux.intel.com> References: <20200908190042.24895-1-jarkko.sakkinen@linux.intel.com> Date: Wed, 09 Sep 2020 10:55:58 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9738 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009090087 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9738 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 priorityscore=1501 phishscore=0 adultscore=0 bulkscore=0 clxscore=1011 mlxlogscore=999 malwarescore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009090088 Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org On Tuesday, 2020-09-08 at 22:00:42 +03, Jarkko Sakkinen wrote: > Remove 'count' from struct sgx_enclave_add_pages and return number of > pages processed as a positive return as there is no reasonable use for > -EINTR for the caller. Then, roof the processing with a fixed constant > and break out the loop also when this value is surpassed. > > Link: https://lore.kernel.org/linux-sgx/20200626153400.GE27151@zn.tnic/ > Cc: Sean Christopherson > Cc: Borislav Petkov > Signed-off-by: Jarkko Sakkinen > --- > arch/x86/include/uapi/asm/sgx.h | 2 -- > arch/x86/kernel/cpu/sgx/ioctl.c | 10 ++++------ > arch/x86/kernel/cpu/sgx/sgx.h | 1 + > 3 files changed, 5 insertions(+), 8 deletions(-) > > diff --git a/arch/x86/include/uapi/asm/sgx.h b/arch/x86/include/uapi/asm/sgx.h > index b3d5ccf5b976..1564d7f88597 100644 > --- a/arch/x86/include/uapi/asm/sgx.h > +++ b/arch/x86/include/uapi/asm/sgx.h > @@ -45,7 +45,6 @@ struct sgx_enclave_create { > * @length: length of the data (multiple of the page size) > * @secinfo: address for the SECINFO data > * @flags: page control flags > - * @count: number of bytes added (multiple of the page size) > */ > struct sgx_enclave_add_pages { > __u64 src; > @@ -53,7 +52,6 @@ struct sgx_enclave_add_pages { > __u64 length; > __u64 secinfo; > __u64 flags; > - __u64 count; > }; > > /** > diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c > index 6c3c6177b690..0ae00fa9b589 100644 > --- a/arch/x86/kernel/cpu/sgx/ioctl.c > +++ b/arch/x86/kernel/cpu/sgx/ioctl.c > @@ -490,7 +490,7 @@ static int sgx_encl_add_page(struct sgx_encl *encl, unsigned long src, > * caller. > * > * Return: > - * 0 on success, > + * length of the data processed on success, > * -EACCES if an executable source page is located in a noexec partition, > * -EIO if either ENCLS[EADD] or ENCLS[EEXTEND] fails > * -errno otherwise > @@ -530,8 +530,8 @@ static long sgx_ioc_enclave_add_pages(struct sgx_encl *encl, void __user *arg) > return -EINVAL; > > for (c = 0 ; c < addp.length; c += PAGE_SIZE) { > - if (signal_pending(current)) { > - ret = -EINTR; > + if (c == SGX_MAX_ADD_PAGES_LENGTH || signal_pending(current)) { I know that SGX_MAX_ADD_PAGES_LENGTH may be a multiple of PAGE_SIZE, but to be sure that nothing breaks here in the future, I think it would be better to use '>=' as the comparison rather than just '=='. Also, the indentation seems off here w.r.t. using TABs when the break below is using spaces - would be good to have them the same at least. Thanks, Darren. > + ret = c; > break; > } > > @@ -544,12 +544,10 @@ static long sgx_ioc_enclave_add_pages(struct sgx_encl *encl, void __user *arg) > break; > } > > - addp.count = c; > - > if (copy_to_user(arg, &addp, sizeof(addp))) > return -EFAULT; > > - return ret; > + return c; > } > > static int __sgx_get_key_hash(struct crypto_shash *tfm, const void *modulus, > diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h > index 1a6ca5f734e5..94b29f378ea2 100644 > --- a/arch/x86/kernel/cpu/sgx/sgx.h > +++ b/arch/x86/kernel/cpu/sgx/sgx.h > @@ -37,6 +37,7 @@ struct sgx_epc_section { > #define SGX_EPC_SECTION_MASK GENMASK(7, 0) > #define SGX_MAX_EPC_SECTIONS (SGX_EPC_SECTION_MASK + 1) > #define SGX_EPC_PAGE_RECLAIMABLE BIT(8) > +#define SGX_MAX_ADD_PAGES_LENGTH 0x100000 > #define SGX_NR_TO_SCAN 16 > #define SGX_NR_LOW_PAGES 32 > #define SGX_NR_HIGH_PAGES 64 > -- > 2.25.1