Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1463839rwn; Thu, 8 Sep 2022 21:18:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR5EDyvGSxrAaq7xuLqVz9TzhnyW/tsPyu5uoE7l0/9klVNba8B3MR4n+EwCQ8JMDydd0zsX X-Received: by 2002:a17:902:9007:b0:176:9f9d:463 with SMTP id a7-20020a170902900700b001769f9d0463mr11804783plp.32.1662697124302; Thu, 08 Sep 2022 21:18:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662697124; cv=none; d=google.com; s=arc-20160816; b=nocw+Aqx1EXoAyLKA9rr7tuppfTXjWeTQi2A8RxiFkMJNEnftiYUtUPLJqquEE10+x MeMnh6opEZQ5+xEnDhhaYqDS3wnk7/cYNo/Thv62a2aQ84pgQqIIiqlFQwogsUUbDlwI KRBifh1N2MlPp4+sBQ699HMYKPIPpLPPXzvE9rUmt1Y9ORHS1dh1QDyR6DiEYEt531KN ug82LN5SmoDukXY/nIS7TodgfIA4PxSIuyPFpVsINLpab35nBv/pgz3QnGUFEjfBguWW czLXkgdtiwzKtJODIX1XIGXEWl6wdrGRwQhZb5alxw7mRnlqKx5lsPKEtG2bwQk588R+ ufqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=z/iHf7R0on3IvVO3o7saTuw3Kge8Fnyu+sffm6VRYMc=; b=FABCIOdnosChdd2oId/IUd/sWTIN9fEXgeu8cEAaVGWu79z/Uy8UsxB8ZMSvPYl7JN TxIYc34AhaPRzCPxHvX/ltGH3jqhwfLO3bi/36ACtCLKPTYPNYGf+KXY+o33kJ/91Wpo JM4s3I2f3qi6jkmLdVA+USXbauLVNCRjXwxhfVu0952yShQCCKBoIbjcQOXmDLpsSWJk M7nFwndmtTzKYda6PMpsAdwMyyDhvjmxExx7ACi3wgkRk6b/9GFef2qR4AF4JaLJsq3d uMHuGJFRfTyADP5uzCf0wTIsKcRX22Q7m58lMTzuRUahq6fcZSNCHgkTrnxtl7jMctnH DMcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TKjmeoR2; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k9-20020a170902c40900b00177ef72831dsi843314plk.398.2022.09.08.21.18.31; Thu, 08 Sep 2022 21:18:44 -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=@kernel.org header.s=k20201202 header.b=TKjmeoR2; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229660AbiIIEBt (ORCPT + 99 others); Fri, 9 Sep 2022 00:01:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbiIIEBp (ORCPT ); Fri, 9 Sep 2022 00:01:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7837D074A; Thu, 8 Sep 2022 21:01:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3A80161E35; Fri, 9 Sep 2022 04:01:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16162C433C1; Fri, 9 Sep 2022 04:01:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662696103; bh=9PLi232bcOnEaVbw2xQNicyLAvrsStubFpd3g24HjS8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TKjmeoR2dbaaPj+sb57Jx3PPxOKZQnISq6tuHl3KURjplc474Wsl+FG1myLQNQq7k vn+heCFNH8b+vdX1bDyNTmOZoG5Q2kzAxb8+kjed/itQsRlOg5iJE10lanYcUjyqkb RMtXLmRMhhz3BWiUmEJQMe/mCAK7mYZnjk4BjrxbzSuXlCDyhTnd5/AF8bGcFewTI3 kNhgzS/EOHbxrAzMUnhPkxFCaFUmzWtDJqgjMF8kfpYEC4LSHh7fgDvqgjIsJ38cvm gpCbQ+FqkQTsgzcmPaFmWnD7aEZMLRtiYwMADhEpdeoldiF33ZuM1rFE1OpGy9oiHm gA5QrYY6nRKdg== Date: Fri, 9 Sep 2022 07:01:36 +0300 From: Jarkko Sakkinen To: Reinette Chatre Cc: linux-sgx@vger.kernel.org, Haitao Huang , Vijay Dhanraj , Dave Hansen , Shuah Khan , "open list:KERNEL SELFTEST FRAMEWORK" , open list Subject: Re: [PATCH v2 1/5] selftests/sgx: Retry the ioctl()'s returned with EAGAIN Message-ID: References: <20220905020411.17290-1-jarkko@kernel.org> <20220905020411.17290-2-jarkko@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Thu, Sep 08, 2022 at 05:06:58PM -0700, Reinette Chatre wrote: > Hi Jarkko, > > On 9/8/2022 4:19 PM, Jarkko Sakkinen wrote: > > On Thu, Sep 08, 2022 at 03:43:06PM -0700, Reinette Chatre wrote: > >> Hi Jarkko and Haitao, > >> > >> On 9/4/2022 7:04 PM, Jarkko Sakkinen wrote: > >>> From: Haitao Huang > >>> > >>> For EMODT and EREMOVE ioctl()'s with a large range, kernel > >>> may not finish in one shot and return EAGAIN error code > >>> and count of bytes of EPC pages on that operations are > >>> finished successfully. > >>> > >>> Change the unclobbered_vdso_oversubscribed_remove test > >>> to rerun the ioctl()'s in a loop, updating offset and length > >>> using the byte count returned in each iteration. > >>> > >>> Fixes: 6507cce561b4 ("selftests/sgx: Page removal stress test") > >> > >> Should this patch be moved to the "critical fixes for v6.0" series? > > > > I think not because it does not risk stability of the > > kernel itself. It's "nice to have" but not mandatory. > > ok, thank you for considering it. > > ... > > >>> @@ -453,16 +454,30 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900) > >>> modt_ioc.offset = heap->offset; > >>> modt_ioc.length = heap->size; > >>> modt_ioc.page_type = SGX_PAGE_TYPE_TRIM; > >>> - > >>> + count = 0; > >>> TH_LOG("Changing type of %zd bytes to trimmed may take a while ...", > >>> heap->size); > >>> - ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc); > >>> - errno_save = ret == -1 ? errno : 0; > >>> + do { > >>> + ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc); > >>> + > >>> + errno_save = ret == -1 ? errno : 0; > >>> + if (errno_save != EAGAIN) > >>> + break; > >>> + > >>> + EXPECT_EQ(modt_ioc.result, 0); > >> > >> If this check triggers then there is something seriously wrong and in that case > >> it may also be that this loop may be unable to terminate or the error condition would > >> keep appearing until the loop terminates (which may be many iterations). Considering > >> the severity and risk I do think that ASSERT_EQ() would be more appropriate, > >> similar to how ASSERT_EQ() is used in patch 5/5. > >> > >> Apart from that I think that this looks good. > >> > >> Thank you very much for adding this. > >> > >> Reinette > > > > Hmm... I could along the lines: > > > > /* > > * Get time since Epoch is milliseconds. > > */ > > unsigned long get_time(void) > > { > > struct timeval start; > > > > gettimeofday(&start, NULL); > > > > return (unsigneg long)start.tv_sec * 1000L + (unsigned long)start.tv_usec / 1000L; > > } > > > > and > > > > #define IOCTL_RETRY_TIMEOUT 100 > > > > In the test function: > > > > unsigned long start_time; > > > > /* ... */ > > > > start_time = get_time(); > > do { > > EXPECT_LT(get_time() - start_time(), IOCTL_RETRY_TIMEOUT); > > > > /* ... */ > > } > > > > /* ... */ > > > > What do you think? > > I do think that your proposal can be considered for an additional check in this > test but the way I understand it it does not address my feedback. > > In this patch the flow is: > > do { > ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc); > > errno_save = ret == -1 ? errno : 0; > if (errno_save != EAGAIN) > break; > > EXPECT_EQ(modt_ioc.result, 0); > ... > } while ... > > > If this EXPECT_EQ() check fails then it means that errno_save is EAGAIN > and modt_ioc.result != 0. This should never happen because in the kernel > (sgx_enclave_modify_types()) the only time modt_ioc.result can be set is > when the ioctl() returns EFAULT. > > In my opinion this check should be changed to: > ASSERT_EQ(modt_ioc.result, 0); Right, I missed this. It should be definitely ASSERT_EQ((). BR, Jarkko