Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2571928rwb; Fri, 2 Dec 2022 11:38:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf5UfBLF9n1FALgQ/veQLiBvq0WVwsCXWf/RqttpthK1hO/CEhG2slvUmvBJmkJgAAU3qoT7 X-Received: by 2002:a63:5d45:0:b0:476:dd29:75a8 with SMTP id o5-20020a635d45000000b00476dd2975a8mr45826561pgm.547.1670009886177; Fri, 02 Dec 2022 11:38:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670009886; cv=none; d=google.com; s=arc-20160816; b=xPPIp7PKhLwuqqgmXANUw7KNMohu8HtlaqHf4Os2BMSfvGuoAr99MwSE7agt+UrpMy CjQd7Ubb1AB+/qyu7w4N9e6TtQ6qpAgI4/f4IUxnTrEtGbz1umvg+12ryd3l+6+Khcft j+IATRlLgOUfTNjVOAcuuJD++jFbq7cTTQDPfJRhAXebOskmkS7HRI9FJm90qGcmNon5 MiikPkLM2noLHQpLMMq8EPni9fvjmYgK/T8jn3HfeR6BczdJ0/2PX4C8ccZo4mmb3uNm Ii8C3sa9TbxURSdXdi2FT/gx+uv7wOsq9mxoRxJzdorXAKj3Z6DSym2qIMpMiN4+oXgQ bLDA== 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=hLAJ7Gg1rSbTxQmdH7VvXNSZor1QA1TjBf5mEOK+8o8=; b=OMFfkq54ss3Vky0/+kNtg/syF0olP5wXsZkflau9M0igwwAq/xZN/7POYZXRBTVWWj hW9dYu+nGyStt6CS0aDMVsjLPL81fR4gpmzvEY3w0O3CW0f/jUy+k5LD80PUzsTiCD5A tQ86/ea4CADMOz6x3hIG78LacxyEYuZ8okCcNAoQp+0trfjBMZEWgCd7Q+iNFfl6I/uW UlHHamWBFd+9GBqc0LFpocwDRcQcogUdEWIZK981vck98JQH+2S1tlJj06budhDACuvD m+BMb0S7vdrAc43Px0hULwvQ7AcaHR7fCOEQRAS7Nafeuko3SSRVXN+3LQ43iZerXW84 i6ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fxbfFMvt; 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 pj8-20020a17090b4f4800b00218792fa2b3si11783751pjb.160.2022.12.02.11.37.53; Fri, 02 Dec 2022 11:38:06 -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=fxbfFMvt; 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 S234516AbiLBShQ (ORCPT + 82 others); Fri, 2 Dec 2022 13:37:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234473AbiLBShJ (ORCPT ); Fri, 2 Dec 2022 13:37:09 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3830EDD4D; Fri, 2 Dec 2022 10:37:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670006228; x=1701542228; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ba88DeV8/njUEzN15e2sj/am8fPP9lPmiVElJCF0C+U=; b=fxbfFMvt9WUMNgypsz/7z/fJyPXW7QBFRkSLf/tQhaARtEdM4IrD/8hP rRPgwIgZsHixQn6kYqx4h+0TbhqPyKUblU5u/muAaTwDKmaVUR9Y4yWST bNGurGrB4V4GoaerfRDi9BEbLH+l8nU6zzlhX+06jbXHQbD2bS9HThx7j 6lhVhslfHoMONlzVYZU/FIqBd20Hm3kLNFtWsMcg0T57kTIbhqQpt5IkP dmRrnGN02g4xvrWocP/y2wIkMD5bcir8aklDkLgC2Z7ny7OQsBMLWtEov kKn4iOOUss1toSYrL08roAsXU9llKBnUkBUZuZuE2WR1/M5kcLCcTSXrL g==; X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="314724495" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="314724495" 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:08 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="713717366" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="713717366" 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:06 -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 02/18] x86/sgx: Store struct sgx_encl when allocating new VA pages Date: Fri, 2 Dec 2022 10:36:38 -0800 Message-Id: <20221202183655.3767674-3-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 When allocating new Version Array (VA) pages, pass the struct sgx_encl of the enclave that is allocating the page. sgx_alloc_epc_page() will store this value in the encl_owner field of the struct sgx_epc_page. In a later patch, VA pages will be placed in an unreclaimable queue, and then when the cgroup max limit is reached and there are no more reclaimable pages and the enclave must be oom killed, all the VA pages associated with that enclave can be uncharged and freed. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Cc: Sean Christopherson --- arch/x86/kernel/cpu/sgx/encl.c | 5 +++-- arch/x86/kernel/cpu/sgx/encl.h | 2 +- arch/x86/kernel/cpu/sgx/ioctl.c | 2 +- arch/x86/kernel/cpu/sgx/sgx.h | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c index f40d64206ded..4eaf9d21e71b 100644 --- a/arch/x86/kernel/cpu/sgx/encl.c +++ b/arch/x86/kernel/cpu/sgx/encl.c @@ -1193,6 +1193,7 @@ void sgx_zap_enclave_ptes(struct sgx_encl *encl, unsigned long addr) /** * sgx_alloc_va_page() - Allocate a Version Array (VA) page + * @encl: The enclave that this page is allocated to. * @reclaim: Reclaim EPC pages directly if none available. Enclave * mutex should not be held if this is set. * @@ -1202,12 +1203,12 @@ void sgx_zap_enclave_ptes(struct sgx_encl *encl, unsigned long addr) * a VA page, * -errno otherwise */ -struct sgx_epc_page *sgx_alloc_va_page(bool reclaim) +struct sgx_epc_page *sgx_alloc_va_page(struct sgx_encl *encl, bool reclaim) { struct sgx_epc_page *epc_page; int ret; - epc_page = sgx_alloc_epc_page(NULL, reclaim); + epc_page = sgx_alloc_epc_page(encl, reclaim); if (IS_ERR(epc_page)) return ERR_CAST(epc_page); diff --git a/arch/x86/kernel/cpu/sgx/encl.h b/arch/x86/kernel/cpu/sgx/encl.h index f94ff14c9486..831d63f80f5a 100644 --- a/arch/x86/kernel/cpu/sgx/encl.h +++ b/arch/x86/kernel/cpu/sgx/encl.h @@ -116,7 +116,7 @@ struct sgx_encl_page *sgx_encl_page_alloc(struct sgx_encl *encl, unsigned long offset, u64 secinfo_flags); void sgx_zap_enclave_ptes(struct sgx_encl *encl, unsigned long addr); -struct sgx_epc_page *sgx_alloc_va_page(bool reclaim); +struct sgx_epc_page *sgx_alloc_va_page(struct sgx_encl *encl, bool reclaim); unsigned int sgx_alloc_va_slot(struct sgx_va_page *va_page); void sgx_free_va_slot(struct sgx_va_page *va_page, unsigned int offset); bool sgx_va_page_full(struct sgx_va_page *va_page); diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c index ebe79d60619f..9a1bb3c3211a 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -30,7 +30,7 @@ struct sgx_va_page *sgx_encl_grow(struct sgx_encl *encl, bool reclaim) if (!va_page) return ERR_PTR(-ENOMEM); - va_page->epc_page = sgx_alloc_va_page(reclaim); + va_page->epc_page = sgx_alloc_va_page(encl, reclaim); if (IS_ERR(va_page->epc_page)) { err = ERR_CAST(va_page->epc_page); kfree(va_page); diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h index d16a8baa28d4..39cb15a8abcb 100644 --- a/arch/x86/kernel/cpu/sgx/sgx.h +++ b/arch/x86/kernel/cpu/sgx/sgx.h @@ -39,6 +39,7 @@ struct sgx_epc_page { struct sgx_encl_page *encl_owner; /* Use when SGX_EPC_PAGE_KVM_GUEST set in ->flags: */ void __user *vepc_vaddr; + struct sgx_encl *encl; }; struct list_head list; }; -- 2.38.1