Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp674064pxv; Thu, 8 Jul 2021 11:16:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnX97SZPiETtPpJN7030KCYv6MYxhc/OSCrmH6CMLiHdVQQAnLAY0Fsp6hLawJbf6fH5zb X-Received: by 2002:a05:6e02:43:: with SMTP id i3mr23372058ilr.172.1625768179581; Thu, 08 Jul 2021 11:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625768179; cv=none; d=google.com; s=arc-20160816; b=mf66/PwwC+Jw8xvC1GYcCADVyd1JCUTYHOZH476Jj/TQHf500Dgee0RyoFqPXadUBy SDIqgOdOd4rYWC+SYfZ/47kuT+6HM14dOLw4/oaXStMHhQh2Osoy3uq6dVYYHtSZ1KfF zK8I9VMm7c3VZaiwDi6vo8N8DgtHRoQ1HjKGCqhX9Cemzsolop/Ilh2z2OxQ/+nZR6Qp YTsuJSisHtbPl/K2yDyE+BSvLWxyckdBujaaweM3n3Ca+nRZ9cL+VzTjvM3lK08PGFeU 3Mz+Ws722NSLB8uYKZbQAq6SLb50qhrp2G7MlDj2Txf6gcczhDF7eFK6cDNs3nuYyXIY IuMA== 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=w5OT4JiY61OoNEOmXGTTzoA+Hn+PwTtYMuYfL2UoflU=; b=wxxb+AKWJitLvWfQThcfv+fzU7+zaUvDrTtGMWy6YeH9wDglF6jt56tyNuZ8OwUjTJ tsyfpRVwX9D2nfTStvh8CdiNgSHEq35w/f4jr7WEkXe9pnLRRQa5kBe3DUQBGrQkU1U9 qojVIKo8toq/inEifNK2F6KuteTNjEwGRi7ES10hUrE8Twj5ryT9tpbVFLb4VgSS+Xyi SGe9vQhfXKpFiRe3RsuWADiqw6etOBRwboJxbkVG54uOxkWQv3gghl7qmksrMj+To0yj AMkzEDNwTVFIqVwY1OrHK32hZ7URyO8JPHYehyeb7GthAqSKbOv7rZnAwyVQTNPpqoe9 EnlQ== 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 d12si2986503ioi.82.2021.07.08.11.16.07; Thu, 08 Jul 2021 11:16:19 -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 S230211AbhGHSRZ (ORCPT + 99 others); Thu, 8 Jul 2021 14:17:25 -0400 Received: from mga01.intel.com ([192.55.52.88]:2094 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230115AbhGHSRS (ORCPT ); Thu, 8 Jul 2021 14:17:18 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10039"; a="231327151" X-IronPort-AV: E=Sophos;i="5.84,224,1620716400"; d="scan'208";a="231327151" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2021 11:14:35 -0700 X-IronPort-AV: E=Sophos;i="5.84,224,1620716400"; d="scan'208";a="482637388" Received: from agluck-desk2.sc.intel.com ([10.3.52.146]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2021 11:14:35 -0700 From: Tony Luck To: tony.luck@intel.com Cc: Jarkko Sakkinen , Dave Hansen , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] x86/sgx: Add hook to error injection address validation Date: Thu, 8 Jul 2021 11:14:23 -0700 Message-Id: <20210708181423.1312359-5-tony.luck@intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210708181423.1312359-1-tony.luck@intel.com> References: <20210708181423.1312359-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 reserved memory does not appear in the standard address maps. Add hook to call into the SGX code to check if an address is located in SGX memory. There are other challenges in injecting errors into SGX. Update the documentation with a sequence of operations to inject. Signed-off-by: Tony Luck --- .../firmware-guide/acpi/apei/einj.rst | 19 +++++++++++++++++++ drivers/acpi/apei/einj.c | 3 ++- include/linux/mm.h | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Documentation/firmware-guide/acpi/apei/einj.rst b/Documentation/firmware-guide/acpi/apei/einj.rst index c042176e1707..55e2331a6438 100644 --- a/Documentation/firmware-guide/acpi/apei/einj.rst +++ b/Documentation/firmware-guide/acpi/apei/einj.rst @@ -181,5 +181,24 @@ You should see something like this in dmesg:: [22715.834759] EDAC sbridge MC3: PROCESSOR 0:306e7 TIME 1422553404 SOCKET 0 APIC 0 [22716.616173] EDAC MC3: 1 CE memory read error on CPU_SrcID#0_Channel#0_DIMM#0 (channel:0 slot:0 page:0x12345 offset:0x0 grain:32 syndrome:0x0 - area:DRAM err_code:0001:0090 socket:0 channel_mask:1 rank:0) +Special notes for injection into SGX enclaves: + +There may be a separate BIOS setup option to enable SGX injection. + +The injection process consists of setting some special memory controller +trigger that will inject the error on the next write to the target +address. But the h/w prevents any software outside of an SGX enclave +from accessing enclave pages (even BIOS SMM mode). + +The following sequence can be used: + 1) Determine physical address of enclave page + 2) Use "notrigger=1" mode to inject (this will setup + the injection address, but will not actually inject) + 3) Enter the enclave + 4) Store data to the virtual address matching physical address from step 1 + 5) Execute CLFLUSH for that virtual address + 6) Spin delay for 250ms + 7) Read from the virtual address. This will trigger the error + For more information about EINJ, please refer to ACPI specification version 4.0, section 17.5 and ACPI 5.0, section 18.6. diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c index 328e8aeece6c..fb634219e232 100644 --- a/drivers/acpi/apei/einj.c +++ b/drivers/acpi/apei/einj.c @@ -544,7 +544,8 @@ static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, ((region_intersects(base_addr, size, IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE) != REGION_INTERSECTS) && (region_intersects(base_addr, size, IORESOURCE_MEM, IORES_DESC_PERSISTENT_MEMORY) - != REGION_INTERSECTS))) + != REGION_INTERSECTS) && + !sgx_is_epc_page(base_addr))) return -EINVAL; inject: diff --git a/include/linux/mm.h b/include/linux/mm.h index 1b9d0912942a..47eb960516cf 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3253,11 +3253,17 @@ static inline int seal_check_future_write(int seals, struct vm_area_struct *vma) #ifdef CONFIG_X86_SGX int sgx_memory_failure(unsigned long pfn, int flags); +bool sgx_is_epc_page(u64 paddr); #else static inline int sgx_memory_failure(unsigned long pfn, int flags) { return -ENXIO; } + +static inline bool sgx_is_epc_page(u64 paddr) +{ + return false; +} #endif #endif /* __KERNEL__ */ -- 2.29.2