Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4166969pxv; Mon, 19 Jul 2021 19:04:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqDFcMPsj7tavryaCybqlq98SuPWIAsNyywAKvPqtTSCSA8fmTZcF+17agnMp7dqK9MHBH X-Received: by 2002:a02:c95a:: with SMTP id u26mr24718273jao.49.1626746655177; Mon, 19 Jul 2021 19:04:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626746655; cv=none; d=google.com; s=arc-20160816; b=GpIaov2AS7qxx7htaFYCu4+YHwbqqoB6QuNEq7iVBvci/Ig298k/HbCKO7I7BYVK1N 3zrSVcoOLB56mFyMkK15J7PIRaQkZsOB4rJKcKWm9Zw2vdo141cVBEX6eNABpIw2J84A isoIAHQNrpgrQAFKfhsp1+af8erGNoN/t8f3Rh/d5UiD6fQj7S2HM82Q2c8c0XLj5KxC KXEVjLMXyOjDJafyKI7boG1ncGdztGGUmVrKhwOkHh6sQwOua0d0PCZTzQn/mLEnsOjM GK2NMk0J/nRtKslHgsx3NsHpWSX1nj4Zsly7x3Em8czgawX/bs2A6y/eUvBfIVwpFgzg p7Zg== 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; bh=sdXaQRz69LQ1RJVfEeuwnlqOyBYWrSAofVRjXjNQ19Y=; b=lcA7DCI+vkx2ilqBaVjsTuBN2/ndkvkWXu+DQG0B5WK61PRJSLObK8snDnj7zoSRa3 mxWOagnOpHldr5BIgoXHdT8tI5oLG22NY9zeIXNAHI/HPoneGqtRfiHLHzz1Yi3vQ+DK PBNjewkXuKxNq4Mu2ym4asqRnOYmfybm34tdzDn5yVtgoU+NgIlPTtlk9xFgX2Vqy2ZN vLznuHX5bkyuTdeQ6ISGOEGILum2i3bF66XV18DrSjKatyQSYYPdTBbiPzQkbl9PQB9a T6ekrdLFA25kbf/5zeXMB1LuQtP9EZkWbC8KnkFOQbDABolxQaB3+22dQJXT+vUSjcnB VIlw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o2si10509099ilo.2.2021.07.19.19.04.03; Mon, 19 Jul 2021 19:04:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381137AbhGSRv7 (ORCPT + 99 others); Mon, 19 Jul 2021 13:51:59 -0400 Received: from mga03.intel.com ([134.134.136.65]:51676 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382631AbhGSRjg (ORCPT ); Mon, 19 Jul 2021 13:39:36 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10050"; a="211166999" X-IronPort-AV: E=Sophos;i="5.84,252,1620716400"; d="scan'208";a="211166999" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jul 2021 11:20:15 -0700 X-IronPort-AV: E=Sophos;i="5.84,252,1620716400"; d="scan'208";a="509462733" Received: from agluck-desk2.sc.intel.com ([10.3.52.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jul 2021 11:20:15 -0700 From: Tony Luck To: Sean Christopherson , Jarkko Sakkinen , Dave Hansen Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Tony Luck Subject: [PATCH v2 1/6] x86/sgx: Provide indication of life-cycle of EPC pages Date: Mon, 19 Jul 2021 11:20:04 -0700 Message-Id: <20210719182009.1409895-2-tony.luck@intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210719182009.1409895-1-tony.luck@intel.com> References: <20210708181423.1312359-1-tony.luck@intel.com> <20210719182009.1409895-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SGX EPC pages go through the following life cycle: DIRTY ---> FREE ---> IN-USE --\ ^ | \-----------------/ Recovery action for poison for a DIRTY or FREE page is simple. Just make sure never to allocate the page. IN-USE pages need some extra handling. It would be good to use the sgx_epc_page->owner field as an indicator of where an EPC page is currently in that cycle (owner != NULL means the EPC page is IN-USE). But there is one caller, sgx_alloc_va_page(), that calls with NULL. Make the following changes: 1) Change the type of "owner" to "void *" (it can have other types besides "struct sgx_encl_page *). 2) Update sgx_alloc_va_page() to pass in a dummy non-NULL value in this case. 3) Add a check to sgx_free_epc_page() to prevent calling with NULL. 4) Reset owner to NULL in sgx_free_epc_page(). Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/sgx/encl.c | 2 +- arch/x86/kernel/cpu/sgx/main.c | 6 ++++++ arch/x86/kernel/cpu/sgx/sgx.h | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c index 001808e3901c..ca328d56d230 100644 --- a/arch/x86/kernel/cpu/sgx/encl.c +++ b/arch/x86/kernel/cpu/sgx/encl.c @@ -679,7 +679,7 @@ struct sgx_epc_page *sgx_alloc_va_page(void) struct sgx_epc_page *epc_page; int ret; - epc_page = sgx_alloc_epc_page(NULL, true); + epc_page = sgx_alloc_epc_page("Not NULL!", true); if (IS_ERR(epc_page)) return ERR_CAST(epc_page); diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 63d3de02bbcc..d61bc1f635a1 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -578,6 +578,11 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) { struct sgx_epc_page *page; + if (!owner) { + WARN_ON_ONCE(1); + return NULL; + } + for ( ; ; ) { page = __sgx_alloc_epc_page(); if (!IS_ERR(page)) { @@ -624,6 +629,7 @@ void sgx_free_epc_page(struct sgx_epc_page *page) spin_lock(&node->lock); + page->owner = NULL; list_add_tail(&page->list, &node->free_page_list); sgx_nr_free_pages++; diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h index 4628acec0009..4e1a410b8a62 100644 --- a/arch/x86/kernel/cpu/sgx/sgx.h +++ b/arch/x86/kernel/cpu/sgx/sgx.h @@ -29,7 +29,7 @@ struct sgx_epc_page { unsigned int section; unsigned int flags; - struct sgx_encl_page *owner; + void *owner; struct list_head list; }; -- 2.29.2