From patchwork Sat Sep 23 03:06:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haitao Huang X-Patchwork-Id: 143919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp209559vqu; Sat, 23 Sep 2023 07:30:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzh5CfLlc0SYwQZ1hLARRXJeiQTSmiBZcNIaCsziOKle1MBL8pQPiYwbnFo2df4sltKsod X-Received: by 2002:a05:6358:9320:b0:13a:4120:ce2e with SMTP id x32-20020a056358932000b0013a4120ce2emr2952383rwa.20.1695479416108; Sat, 23 Sep 2023 07:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695479416; cv=none; d=google.com; s=arc-20160816; b=BY5mL1JeA5mpd+pF0ge0FEGtoqR2dE3g7KH8YcDWp1+Q6uKbizjwEHrRu+GjzJtcjb R3c1+1lb/Jd8waZ3kQN7ySKEYmbYJfFmQRY2GFHe2ydsa/grY5HW31gYGeCB9p3MJQ9D M75zOHhKXj+eX0ndrLIQ3rpHXAKrGzorp3BaHbNvwkGZOvNtg3eWIcwh/640a2K7+c6I 6TzRveccJx5B2dTA/aR/ycTZOQMBZDuWCpBA4ISeJkS+Lz1rScUwYFsQ86gq5lYxaTFH pA6UmobT4LODOthfOMqo9wsKrXQQIsryvoafdtZS0QjW+OE1odhI0bhVmZD0n5GimwTa XaJw== 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=izbdcrGLbqCNLEY8Fiam4brrWR+nP2g4UE9Ir99aJrY=; fh=j8PE345l5Ydlo3KwK7JeWnjqRgjiq4AteUoOZeOwa0I=; b=P3ftq5UZfuZUv2FD1mlQQhP0ZWxe6rwVhY62tUfXIGtiVdFTWMka1jVtx0jZ5ZgWek lw83viP2vcaK3jZ/oBNhgfWfjJUokiSVixXtZbXY6t+FjmTVdLot6gbzBvXI1fOva7Sa iJlb8lXBj62rwltz+YHIFeGQ2MsLZraq9VyzIkdKMGjjfUQLB/6jAIgCZqqZbxM50SGc iT0XwV3QzR1gugkdcAOd/aqzuA5LyBzZ1cdBPMauHY7A4dOLug/dYLlc+DkapiHrqkq9 WFU/G/snfaKrP6H+aHyBtQVVFT0BAQ8qQawv/jiyX7JUvJu/rCeMNRwf0rby0Su4wEms GFGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NQAKpaPC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id w2-20020a637b02000000b00573fb2f7537si6114551pgc.586.2023.09.23.07.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 07:30:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NQAKpaPC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 36534823911E; Fri, 22 Sep 2023 20:08:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231164AbjIWDHt (ORCPT + 28 others); Fri, 22 Sep 2023 23:07:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229897AbjIWDHM (ORCPT ); Fri, 22 Sep 2023 23:07:12 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BF361AC; Fri, 22 Sep 2023 20:07:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695438426; x=1726974426; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6rGwrEe4Ukw7FcCDvhuspXyNUODXLObGeH1s03Sjd5k=; b=NQAKpaPCKs6WV2O14ecofFZZ9esdSnu0asaZdOVT+XQageN1ztqicilL rzAY1Oc6Dj3M1jWLYOwxjOf003wyh9gJpnluU4FkJiYW5BPqxk9+TVxpI Uyukf/dregEBk1zKYgAO1z//YfiwxErw/Si3OBB/C9mBM64Ht/Yernpur HDErU2BNxrok2XAhulmiKK7Y8dL+xGUCwVSG9gEJOn2GMNzgdjvswrEU1 avvk1vtjlIOzvXABdLE2yrt07Jhu8RPC0f8CwtJyO4cZ7swcDqY33gc2m 3ohVt24lWqYDZrkNv/JFTWdTwaoeU47on21VzB/EkYFlGnQpnRv1CQCLX A==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="447466795" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="447466795" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 20:07:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="891048558" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="891048558" Received: from b4969161e530.jf.intel.com ([10.165.56.46]) by fmsmga001.fm.intel.com with ESMTP; 22 Sep 2023 20:06:09 -0700 From: Haitao Huang To: jarkko@kernel.org, dave.hansen@linux.intel.com, tj@kernel.org, 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 Subject: [PATCH v5 10/18] x86/sgx: Add EPC page flags to identify owner types Date: Fri, 22 Sep 2023 20:06:49 -0700 Message-Id: <20230923030657.16148-11-haitao.huang@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230923030657.16148-1-haitao.huang@linux.intel.com> References: <20230923030657.16148-1-haitao.huang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=2.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 22 Sep 2023 20:08:40 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777839024018853974 X-GMAIL-MSGID: 1777839024018853974 From: Sean Christopherson Two types of owners of struct sgx_epc_page, 'sgx_encl' for VA pages and 'sgx_encl_page' can be stored in the previously introduced union field. OOM support for cgroups requires that the owner needs to be identified when selecting pages from the unreclaimable list. Address this by adding flags for the owner type. 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 --- V4: - Updates for patch reordering. - Rename SGX_EPC_OWNER_ENCL_PAGE to SGX_EPC_OWNER_PAGE. (Jarkko) - Commit message changes. (Jarkko) --- arch/x86/kernel/cpu/sgx/encl.c | 9 +++++---- arch/x86/kernel/cpu/sgx/ioctl.c | 6 ++++-- arch/x86/kernel/cpu/sgx/sgx.h | 6 ++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c index ec3402d41b63..da1657813fce 100644 --- a/arch/x86/kernel/cpu/sgx/encl.c +++ b/arch/x86/kernel/cpu/sgx/encl.c @@ -248,6 +248,7 @@ static struct sgx_epc_page *sgx_encl_load_secs(struct sgx_encl *encl) epc_page = sgx_encl_eldu(&encl->secs, NULL); if (!IS_ERR(epc_page)) sgx_record_epc_page(epc_page, + SGX_EPC_OWNER_PAGE | SGX_EPC_PAGE_UNRECLAIMABLE); } @@ -276,7 +277,7 @@ static struct sgx_encl_page *__sgx_encl_load_page(struct sgx_encl *encl, return ERR_CAST(epc_page); encl->secs_child_cnt++; - sgx_record_epc_page(epc_page, SGX_EPC_PAGE_RECLAIMABLE); + sgx_record_epc_page(epc_page, SGX_EPC_OWNER_PAGE | SGX_EPC_PAGE_RECLAIMABLE); return entry; } @@ -402,7 +403,7 @@ static vm_fault_t sgx_encl_eaug_page(struct vm_area_struct *vma, encl_page->type = SGX_PAGE_TYPE_REG; encl->secs_child_cnt++; - sgx_record_epc_page(epc_page, SGX_EPC_PAGE_RECLAIMABLE); + sgx_record_epc_page(epc_page, SGX_EPC_OWNER_PAGE | SGX_EPC_PAGE_RECLAIMABLE); phys_addr = sgx_get_epc_phys_addr(epc_page); /* @@ -1261,8 +1262,8 @@ struct sgx_epc_page *sgx_alloc_va_page(struct sgx_encl *encl, bool reclaim) sgx_encl_free_epc_page(epc_page); return ERR_PTR(-EFAULT); } - sgx_record_epc_page(epc_page, - SGX_EPC_PAGE_UNRECLAIMABLE); + sgx_record_epc_page(epc_page, SGX_EPC_OWNER_ENCL | + SGX_EPC_PAGE_UNRECLAIMABLE); return epc_page; } diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c index 164256ea18d0..cd338e93acc1 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -114,6 +114,7 @@ static int sgx_encl_create(struct sgx_encl *encl, struct sgx_secs *secs) encl->attributes_mask = SGX_ATTR_UNPRIV_MASK; sgx_record_epc_page(encl->secs.epc_page, + SGX_EPC_OWNER_PAGE | SGX_EPC_PAGE_UNRECLAIMABLE); /* Set only after completion, as encl->lock has not been taken. */ @@ -325,7 +326,7 @@ static int sgx_encl_add_page(struct sgx_encl *encl, unsigned long src, goto err_out; } - sgx_record_epc_page(epc_page, SGX_EPC_PAGE_RECLAIMABLE); + sgx_record_epc_page(epc_page, SGX_EPC_OWNER_PAGE | SGX_EPC_PAGE_RECLAIMABLE); mutex_unlock(&encl->lock); mmap_read_unlock(current->mm); return ret; @@ -979,7 +980,8 @@ static long sgx_enclave_modify_types(struct sgx_encl *encl, mutex_lock(&encl->lock); - sgx_record_epc_page(entry->epc_page, SGX_EPC_PAGE_RECLAIMABLE); + sgx_record_epc_page(entry->epc_page, + SGX_EPC_OWNER_PAGE | SGX_EPC_PAGE_RECLAIMABLE); } /* Change EPC type */ diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h index 5110dd433b80..51aba1cd1937 100644 --- a/arch/x86/kernel/cpu/sgx/sgx.h +++ b/arch/x86/kernel/cpu/sgx/sgx.h @@ -64,6 +64,12 @@ enum sgx_epc_page_state { #define SGX_EPC_PAGE_STATE_MASK GENMASK(2, 0) +/* flag for pages owned by a sgx_encl_page */ +#define SGX_EPC_OWNER_PAGE BIT(3) + +/* flag for pages owned by a sgx_encl struct */ +#define SGX_EPC_OWNER_ENCL BIT(4) + struct sgx_epc_page { unsigned int section; u16 flags;