Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1257321rwn; Thu, 8 Sep 2022 16:26:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Qr4AdV9f+s3b6GIMLptw/p1gaW/mKqjeyS5e23zwBdD/7B/e/Trlk9xhJ/HX3ho67XTcv X-Received: by 2002:a63:e205:0:b0:435:c80:ecd0 with SMTP id q5-20020a63e205000000b004350c80ecd0mr7012768pgh.174.1662679614898; Thu, 08 Sep 2022 16:26:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662679614; cv=none; d=google.com; s=arc-20160816; b=vFRJVgqGAFebTRiflDS7smr1ucumFtAcTwi7uW7IlY9NCwcb78F8qiPgHa2fSRgBxH AWyiM4248Ay1cy2hPC3hajZPfzcQcQzYLUp1kya8UuB/4me107kbCGAQv22Ju9JkiVvQ PwDk9v8/0mFVgE/QXhpggrE5d6WkEmuCjGJqPuCOGeQCAPpS40pi1jjW3SdIWsF2aTNy imqMo8WsELyAorxqKeX5otrV7X9jvVW4eTJ5PgF/nwqgMjEIUgy6tqoKUwlLPL4RS6VI 5vnY+V0DKYH42n0haKiRkq69+zfKFnekBdg4N6kC6tHrCMSCE3+oBTXU3RPWng/TBvFc 2Xiw== 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=dVBLP6AdEMMQr4HTeLQUv42hEvNyBcHdKC9uoidpx3A=; b=kvG2rYscAFGqVAv0rZtbCgmAeUeXwDk3DNt8d6XMQWJ7UTbgLXx0vrDHdkHMN1sfts 9PfNdCRSpiqSUBTMS0dohnM5UVjbaOs5ZEUBWHkHcM2t2u5e/3K19n9srrQfi+I39JQG 5NDQFa+kWuzbD3t6giyVXvCA/cjsjwIqqx5rRSaM2XaQhF04Ne8DklUKrPWkHPsz2F2m S/edFYJKazZc4p8/tdWRHIrHkP20LAYBouG7sj9RI4gzu2z+OuxgrFG/0Up/95KzAr7P a++b5jkwKO424v9Ltc9hEcn0p9NgqMVPb/Mz9EcYouJPHZ3EtBBnzFjcrTi/vhxmG5MF pTtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BCev5ieZ; 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 jd1-20020a170903260100b0016efb38cf39si212021plb.141.2022.09.08.16.26.43; Thu, 08 Sep 2022 16:26:54 -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=BCev5ieZ; 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 S230001AbiIHXTs (ORCPT + 99 others); Thu, 8 Sep 2022 19:19:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbiIHXTq (ORCPT ); Thu, 8 Sep 2022 19:19:46 -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 8255D22298; Thu, 8 Sep 2022 16:19: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 0DA9E61E2C; Thu, 8 Sep 2022 23:19:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1F44C433C1; Thu, 8 Sep 2022 23:19:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662679183; bh=iOyyWbAaz1hh5SNuHyuGAi6HyRZtoAMjl33qrdVB8kY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BCev5ieZ7COM056f56yk/NxR7hauUKJYz4b3Ci3rbhk/jRE8V6Jw8pC4lYio8iVc0 3FI41qWJQIcojQ6rAiYdFrNf/515IGYeTLD8D7kASVLTSQz+kE7aLvKcSSPzabUXZo PkVolO1I+hOsAyNo+BrHTZcemvWQapeQrISaVnwGZMMdAUufxyf/6pkx7oI6jgHhXo maZwzIaVUETjmvjPt1ks84Ax0QuA4WNl9O/SNHR2VZmQCK/seM31upXfHw7F5AUMpi QajG2XVQsqFkLceKgLrSwwyKo0Zc0DiHIPfUderNTU9oX9fNHaSJ+aIpkXsPyY7OhJ jnPgTzfq0OqeA== Date: Fri, 9 Sep 2022 02:19: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 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. > > > Signed-off-by: Haitao Huang > > Tested-by: Jarkko Sakkinen > > Signed-off-by: Jarkko Sakkinen > > --- > > v3: > > * Added a fixes tag. The bug is in v6.0 patches. > > * Added my tested-by (the bug reproduced in my NUC often). > > v2: > > * Changed branching in EAGAIN condition so that else branch > > is not required. > > * Addressed Reinette's feedback: > > --- > > tools/testing/selftests/sgx/main.c | 42 ++++++++++++++++++++++++------ > > 1 file changed, 34 insertions(+), 8 deletions(-) > > > > diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c > > index 9820b3809c69..59cca806eda1 100644 > > --- a/tools/testing/selftests/sgx/main.c > > +++ b/tools/testing/selftests/sgx/main.c > > @@ -390,6 +390,7 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900) > > struct encl_segment *heap; > > unsigned long total_mem; > > int ret, errno_save; > > + unsigned long count; > > unsigned long addr; > > unsigned long i; > > > > @@ -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? BR, Jarkko