Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2601166rwb; Fri, 2 Dec 2022 12:06:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf5LJf53AINMpilZmew5xrosb93R9c32/hWGqdkjglvXPKGs955czuHPmxDJG0Chu/u/TWxb X-Received: by 2002:a17:906:6d03:b0:78d:9d0b:a9f6 with SMTP id m3-20020a1709066d0300b0078d9d0ba9f6mr14747256ejr.661.1670011616934; Fri, 02 Dec 2022 12:06:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670011616; cv=none; d=google.com; s=arc-20160816; b=d2C0vbAcIOr01Ju2kvONI6ElPXDQ/2Tv+I2spmgyx3V0mgr9dBjpCHPjggrkLSMMdF yjYf2Fow4/UiIwo5bqvTd8zd0GDXs+bjhslTa7KP6EOYSnQ3Im4Mm7YEa7+Nkfx9/sY0 NMpvMF/ksWhjKJE+fK1O+ys+D896bAD0Jz7Tp61d4yX61Ojw3+4cxa4gkf8LpdwqBKaq mLfc+4OlcZZYJAKG+T9UPpRedhDgfQrZd4Ss+eEp/k7dILvsBIpKJ1ikSC1yW03wDHPg Cgf21il9o9pnb+fcW30nWHPFPzILH8rTYjfEOMjRUb6mifczADB37Uy5uzCfQIbizwxt WvDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1rZRYnxGuVgoAOvKoWbYKl/U6ds7FSlrzSuH4+JNyng=; b=pto8HgwHLqst9htY0uNEHuY6gfb7k8MQsSjfgzbLZBNx7N8lpt518aDq7JrWOM39So kni2BciddY4MZNG+shLBmQNKOKsDg/3KqBRqeIj5RqTbh4llKInp/DQFki3FcjO6HYbK LbVMpNPoqjZ/8+1/v8tjSgKh641lATVbkBBXWRxbF0ZBSRZZJc4bUSVdvT1/LPdd63uv h0d86ob7xDK6dFhCTEIB0JkCixFbT46iDXo0MRqAGviojmaPutDEAuoVpCRp7RUq5JPF qWXuSwjt8OklkYQMBanzE5IIfumFrjak7SlVyeSGokt25umIMmZo0CU8ioz3SdQ+R5Ue IlgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fjwrwjP9; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o9-20020a170906974900b007c0b22a5328si4795476ejy.385.2022.12.02.12.06.37; Fri, 02 Dec 2022 12:06:56 -0800 (PST) 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=@intel.com header.s=Intel header.b=fjwrwjP9; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234361AbiLBShL (ORCPT + 82 others); Fri, 2 Dec 2022 13:37:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234541AbiLBShH (ORCPT ); Fri, 2 Dec 2022 13:37:07 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC423EDD4D; Fri, 2 Dec 2022 10:37:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670006226; x=1701542226; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qv8PoJW739IycS7cP6BKN7byFcsUeUj+E5iETGUdTaY=; b=fjwrwjP9y+xUEsMd6ZeGhn8XC348NLasrXvwxkfJICVBO3ZSoij9vVmd 6n287W0Zzn8E3fNXrvfyuK9LQn5YK/Qs11plq4giEMXVX8lTMYiFuwfEs QEpOUFuhTtLoQvWK6EQSi6TctCfuSeG0vO1EmjwEJ8QsD7FEviR89DLlT sIuJDFUD/uH85zJcrDOXw8cvjUFZOfqxGXtl7TpDw8vU07t6dbq5tKTs0 wXuvF00RoE3LxhWuD1HrUFBI3Yys/YJIUztwpoEiqJzp58mPhX8LVReCW EcFU/FwdhO5Xmlp4DIidrt4HPrm3/R3nttsrRQZIYLD/oAQqq9k4gb+w+ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="314724475" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="314724475" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 10:37:06 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="713717343" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="713717343" Received: from kcaskeyx-mobl1.amr.corp.intel.com (HELO kcaccard-desk.amr.corp.intel.com) ([10.251.1.207]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 10:37:03 -0800 From: Kristen Carlson Accardi To: jarkko@kernel.org, dave.hansen@linux.intel.com, tj@kernel.org, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, cgroups@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Cc: zhiquan1.li@intel.com, Kristen Carlson Accardi , Sean Christopherson Subject: [PATCH v2 01/18] x86/sgx: Call cond_resched() at the end of sgx_reclaim_pages() Date: Fri, 2 Dec 2022 10:36:37 -0800 Message-Id: <20221202183655.3767674-2-kristen@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221202183655.3767674-1-kristen@linux.intel.com> References: <20221202183655.3767674-1-kristen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 From: Sean Christopherson In order to avoid repetition of cond_resched() in ksgxd() and sgx_alloc_epc_page(), move the invocation of post-reclaim cond_resched() inside sgx_reclaim_pages(). Except in the case of sgx_reclaim_direct(), sgx_reclaim_pages() is always called in a loop and is always followed by a call to cond_resched(). This will hold true for the EPC cgroup as well, which adds even more calls to sgx_reclaim_pages() and thus cond_resched(). Calls to sgx_reclaim_direct() may be performance sensitive. Allow sgx_reclaim_direct() to avoid the cond_resched() call by moving the original sgx_reclaim_pages() call to __sgx_reclaim_pages() and then have sgx_reclaim_pages() become a wrapper around that call with a cond_resched(). Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Cc: Sean Christopherson --- arch/x86/kernel/cpu/sgx/main.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 160c8dbee0ab..ffce6fc70a1f 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -287,7 +287,7 @@ static void sgx_reclaimer_write(struct sgx_epc_page *epc_page, * problematic as it would increase the lock contention too much, which would * halt forward progress. */ -static void sgx_reclaim_pages(void) +static void __sgx_reclaim_pages(void) { struct sgx_epc_page *chunk[SGX_NR_TO_SCAN]; struct sgx_backing backing[SGX_NR_TO_SCAN]; @@ -369,6 +369,12 @@ static void sgx_reclaim_pages(void) } } +static void sgx_reclaim_pages(void) +{ + __sgx_reclaim_pages(); + cond_resched(); +} + static bool sgx_should_reclaim(unsigned long watermark) { return atomic_long_read(&sgx_nr_free_pages) < watermark && @@ -378,12 +384,14 @@ static bool sgx_should_reclaim(unsigned long watermark) /* * sgx_reclaim_direct() should be called (without enclave's mutex held) * in locations where SGX memory resources might be low and might be - * needed in order to make forward progress. + * needed in order to make forward progress. This call to + * __sgx_reclaim_pages() avoids the cond_resched() in sgx_reclaim_pages() + * to improve performance. */ void sgx_reclaim_direct(void) { if (sgx_should_reclaim(SGX_NR_LOW_PAGES)) - sgx_reclaim_pages(); + __sgx_reclaim_pages(); } static int ksgxd(void *p) @@ -410,8 +418,6 @@ static int ksgxd(void *p) if (sgx_should_reclaim(SGX_NR_HIGH_PAGES)) sgx_reclaim_pages(); - - cond_resched(); } return 0; @@ -582,7 +588,6 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) } sgx_reclaim_pages(); - cond_resched(); } if (sgx_should_reclaim(SGX_NR_LOW_PAGES)) -- 2.38.1