From patchwork Mon Oct 30 18:20:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haitao Huang X-Patchwork-Id: 159838 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2415580vqb; Mon, 30 Oct 2023 11:21:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6Xp8sxDX52Owbu74RkFX5Ru2VawLC5QfLRJKsF+TNkCDFV4b6jOgw/VPfncKhjfAMcPn/ X-Received: by 2002:a05:6a20:da91:b0:17a:2f1:ce1 with SMTP id iy17-20020a056a20da9100b0017a02f10ce1mr11769809pzb.31.1698690104645; Mon, 30 Oct 2023 11:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698690104; cv=none; d=google.com; s=arc-20160816; b=HvW9i+303p51VqxNec863/D9rB1Vi9ykxOYDLhxJN265BI53dOBNbaQ6bCFIn4crqY T7ePJN0z3tN+yyChHoUGB5gP+t22B8t+nOKGaD2UaAueHn1Wy/PKBlY6rlPbrWM4ERMo sZJ1IZHIALDAyUSYrVxp0IS/XNAcdu4Hk4nwwYEmdiXd1FNX3cmBTP/P+6MVMCtSgjNc ZEvxGbfrQkHaFEyZrtiJHWJxkf4AFP3ngxd0RAYbl+SaZLc2v3nNwN4fSU5Z/n6AK/BC /WmefgCEEEtegDhU+armfEkhaAKor2/uTnNJyaixboqkydGL2ahyW5hJETisTmlc99R2 gzWA== 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=fAvwFEpnT51WGj1WZhC61t+ZUkrrIxyKbPugqE1gF9c=; fh=CTa835q0iyfQFiV5yjYPzrfvG/ulw1To85Pi/STRmhA=; b=r4drr2wKMeLoPDN6WrXH1vLBsKogeYKojVgGAGmBGUgmMEbjtB3tL8enKkvzg2J/1q DCEGG6hO0NvNqqFsefLKhATwwgNQGvLXs5oqGwPEUOOeKbyL+RWAgxahD7d4J5RStB/A kCpy4UgH91fk2n70zWJcrt2Aw4bgIstp5yaBtS8rkYAi80xzFokJ+T7dzgWsNE0UcV6y vOmvzKNwbspPe0lfDWvTL1uJtj8LM7EiT/PMztlBCK6l0TmaQknuVHzZ7ZWyrxjQ50I+ fIIo3DY4emNlWvBuOjaVbw6WLrSrnwyTi3aXgRiSIG6o8kC8O+Zjb9U2mOJRCkWwCHVL L+bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nLiGgZCM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id z9-20020a656649000000b00580e32f778csi5146190pgv.506.2023.10.30.11.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 11:21:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nLiGgZCM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id AB37E80AEB0F; Mon, 30 Oct 2023 11:21:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233142AbjJ3SU5 (ORCPT + 32 others); Mon, 30 Oct 2023 14:20:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232084AbjJ3SUg (ORCPT ); Mon, 30 Oct 2023 14:20:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB750F9; Mon, 30 Oct 2023 11:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698690033; x=1730226033; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DcjHPzwKWtx4S8uR0MSwAzSJIgVUMVFldYzeDNnxAeU=; b=nLiGgZCMIfR0uuDBm7McZ61esFs2vx0PnR+DIYTOt44IEgQ/yJ6fgqSd n4vUdgQyI/MDTATd+Di569FtYoJz2K7+Vjv66NxBsFpfh2sZzlq778Oe1 Z/w/FZaF/TffvXIQhpQ7OE8Mmc46VscuhOpByAUfhQ+MViJ+EDNVPppD0 cAKsbfHnz7FoJPG0taUtnlgeQoCSeB4Gu7w35DG1K+VJ6emPSDJUsz+vx J3VAVhhbdiujvs+LhHKarMB8n26pQ+FYL2+Sn0i/+wRjmmKYMno1fPw52 YZE5BR1hjMsFNeO6A163ho3b7lUEXTdpjEyNOFmEwyuTKRZ2EEtiBh3E5 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="367479560" X-IronPort-AV: E=Sophos;i="6.03,263,1694761200"; d="scan'208";a="367479560" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2023 11:20:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="789529514" X-IronPort-AV: E=Sophos;i="6.03,263,1694761200"; d="scan'208";a="789529514" Received: from b4969161e530.jf.intel.com ([10.165.56.46]) by orsmga008.jf.intel.com with ESMTP; 30 Oct 2023 11:20:28 -0700 From: Haitao Huang To: jarkko@kernel.org, dave.hansen@linux.intel.com, tj@kernel.org, mkoutny@suse.com, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, x86@kernel.org, cgroups@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, sohil.mehta@intel.com Cc: zhiquan1.li@intel.com, kristen@linux.intel.com, seanjc@google.com, zhanb@microsoft.com, anakrish@microsoft.com, mikko.ylinen@linux.intel.com, yangjie@microsoft.com, Sean Christopherson , Haitao Huang Subject: [PATCH v6 05/12] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list Date: Mon, 30 Oct 2023 11:20:06 -0700 Message-Id: <20231030182013.40086-6-haitao.huang@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231030182013.40086-1-haitao.huang@linux.intel.com> References: <20231030182013.40086-1-haitao.huang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 30 Oct 2023 11:21:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781205674980946956 X-GMAIL-MSGID: 1781205674980946956 From: Sean Christopherson Introduce a data structure to wrap the existing reclaimable list and its spinlock. Each cgroup later will have one instance of this structure to track EPC pages allocated for processes associated with the same cgroup. Just like the global SGX reclaimer (ksgxd), an EPC cgroup reclaims pages from the reclaimable list in this structure when its usage reaches near its limit. Signed-off-by: Sean Christopherson Co-developed-by: Kristen Carlson Accardi Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V6: - removed introduction to unreclaimables in commit message. V4: - Removed unneeded comments for the spinlock and the non-reclaimables. (Kai, Jarkko) - Revised the commit to add introduction comments for unreclaimables and multiple LRU lists.(Kai) - Reordered the patches: delay all changes for unreclaimables to later, and this one becomes the first change in the SGX subsystem. V3: - Removed the helper functions and revised commit messages. --- arch/x86/kernel/cpu/sgx/sgx.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h index b1786774b8d2..0fbe6a2a159b 100644 --- a/arch/x86/kernel/cpu/sgx/sgx.h +++ b/arch/x86/kernel/cpu/sgx/sgx.h @@ -86,6 +86,21 @@ static inline void *sgx_get_epc_virt_addr(struct sgx_epc_page *page) return section->virt_addr + index * PAGE_SIZE; } +/* + * Contains EPC pages tracked by the global reclaimer (ksgxd) or an EPC + * cgroup. + */ +struct sgx_epc_lru_list { + spinlock_t lock; + struct list_head reclaimable; +}; + +static inline void sgx_lru_init(struct sgx_epc_lru_list *lru) +{ + spin_lock_init(&lru->lock); + INIT_LIST_HEAD(&lru->reclaimable); +} + struct sgx_epc_page *__sgx_alloc_epc_page(void); void sgx_free_epc_page(struct sgx_epc_page *page);