Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5562972pxv; Wed, 28 Jul 2021 13:49:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDvxJ8znmvAluaL1hkz0dabBTeR6qQgIs9xPmxKQLW4nyraiuNYFiFJCMCWs6Cmq3kcsqp X-Received: by 2002:a05:6638:58e:: with SMTP id a14mr1398764jar.81.1627505365005; Wed, 28 Jul 2021 13:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627505364; cv=none; d=google.com; s=arc-20160816; b=O/fZMpDYTGAuGRjMEVtmrHnyjdVO86o15owk6oRmI43cLaLDtfq6Bp6hpZHcq1Lk33 LM5r7lOv3NRpjl0F3ngi5Hww37uRR09aqHP6TDGjGtNit/gSgCLM+4k7GGndBidu8MnB U26Udbo7AkX+dKo4kCBjR33q4T8EcRTwlCGD6MT08pwCRw0hAhyDUpH7PSdtX2N8Wfqi /2uOkUle5/JHBTmajGA4jEvxAEQFb1L4sqeRXgSwRvylF4MWTgzc/rD6/slT0041ROnD U9StQsNmD0S2rnln72n8RwvzzZsyPJWsyFfal+ugl0eZc3l3Nmj74v7Le9AvkPQSjl8m 0reQ== 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=8i4mR1h4pfbdAGSvTmOyDkfNMxss+FMU8vYTUp9m3yU=; b=pDEapiBsZMPypp5yL5CnFknWva9LCvgsr755bVuoIQNi5gbzH+JeU55y+ZTsn7OwBf 6qN1RjiiSW/qRMtzJhc3hI8BWY0l2kQwFZVTAL/ajw38FOGYI/MYmP7OzAXn8FfDdHQ/ BmFIoonGi/VA3PA/HNiLbLmGuotOBmmG7NL6HUqZ1S+skeZb0kukm9IfOLSyceIEW7EL X1Fiv8Du68WqR3luTo7OEz15dD2SS27aBNzT1PVmJ+PTGUzMjaSW8hVe0Yl/IsfnPfYc +c3jXOQ8knt914xAeMayO7ScWN2X9/1fij1tq0EO8reqQS+A1iQ2jybMlUhzPioIFcCQ 6aUA== 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 y7si907453jae.125.2021.07.28.13.49.13; Wed, 28 Jul 2021 13:49:24 -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 S231903AbhG1UrP (ORCPT + 99 others); Wed, 28 Jul 2021 16:47:15 -0400 Received: from mga01.intel.com ([192.55.52.88]:60186 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231637AbhG1UrE (ORCPT ); Wed, 28 Jul 2021 16:47:04 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10059"; a="234634460" X-IronPort-AV: E=Sophos;i="5.84,276,1620716400"; d="scan'208";a="234634460" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2021 13:47:01 -0700 X-IronPort-AV: E=Sophos;i="5.84,276,1620716400"; d="scan'208";a="506679874" Received: from agluck-desk2.sc.intel.com ([10.3.52.146]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2021 13:47:01 -0700 From: Tony Luck To: Sean Christopherson , Jarkko Sakkinen , Dave Hansen Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Tony Luck Subject: [PATCH v3 2/7] x86/sgx: Add infrastructure to identify SGX EPC pages Date: Wed, 28 Jul 2021 13:46:48 -0700 Message-Id: <20210728204653.1509010-3-tony.luck@intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210728204653.1509010-1-tony.luck@intel.com> References: <20210719182009.1409895-1-tony.luck@intel.com> <20210728204653.1509010-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 X86 machine check architecture reports a physical address when there is a memory error. Handling that error requires a method to determine whether the physical address reported is in any of the areas reserved for EPC pages by BIOS. Add an end_phys_addr field to the sgx_epc_section structure and a new function sgx_paddr_to_page() that searches all such structures and returns the struct sgx_epc_page pointer if the address is an EPC page. This function is only intended for use within SGX code. Export a function sgx_is_epc_page() that simply reports whether an address is an EPC page for use elsewhere in the kernel. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/sgx/main.c | 24 ++++++++++++++++++++++++ arch/x86/kernel/cpu/sgx/sgx.h | 1 + 2 files changed, 25 insertions(+) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 17d09186a6c2..ce40c010c9cb 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -649,6 +649,7 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, } section->phys_addr = phys_addr; + section->end_phys_addr = phys_addr + size - 1; for (i = 0; i < nr_pages; i++) { section->pages[i].section = index; @@ -660,6 +661,29 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, return true; } +static struct sgx_epc_page *sgx_paddr_to_page(u64 paddr) +{ + struct sgx_epc_section *section; + int i; + + for (i = 0; i < ARRAY_SIZE(sgx_epc_sections); i++) { + section = &sgx_epc_sections[i]; + + if (paddr < section->phys_addr || paddr > section->end_phys_addr) + continue; + + return §ion->pages[PFN_DOWN(paddr - section->phys_addr)]; + } + + return NULL; +} + +bool sgx_is_epc_page(u64 paddr) +{ + return !!sgx_paddr_to_page(paddr); +} +EXPORT_SYMBOL_GPL(sgx_is_epc_page); + /** * A section metric is concatenated in a way that @low bits 12-31 define the * bits 12-31 of the metric and @high bits 0-19 define the bits 32-51 of the diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h index 4e1a410b8a62..226b081a4d05 100644 --- a/arch/x86/kernel/cpu/sgx/sgx.h +++ b/arch/x86/kernel/cpu/sgx/sgx.h @@ -50,6 +50,7 @@ struct sgx_numa_node { */ struct sgx_epc_section { unsigned long phys_addr; + unsigned long end_phys_addr; void *virt_addr; struct sgx_epc_page *pages; struct sgx_numa_node *node; -- 2.29.2