From patchwork Tue Sep 27 18:34:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Tai X-Patchwork-Id: 12991091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A7C8C07E9D for ; Tue, 27 Sep 2022 18:35:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB1698E00F7; Tue, 27 Sep 2022 14:35:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C61828E00C1; Tue, 27 Sep 2022 14:35:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B02428E00F7; Tue, 27 Sep 2022 14:35:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9D6AF8E00C1 for ; Tue, 27 Sep 2022 14:35:58 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 32CCE1606C1 for ; Tue, 27 Sep 2022 18:35:58 +0000 (UTC) X-FDA: 79958719596.09.A35E610 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf01.hostedemail.com (Postfix) with ESMTP id C00C040007 for ; Tue, 27 Sep 2022 18:35:56 +0000 (UTC) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28RIPubj019800; Tue, 27 Sep 2022 18:33:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2022-7-12; bh=Zv5+rHipBcgS8FwB2WOhjPJORx2DH06MRLcvr4/hF0E=; b=DwVrq7ZebKRhWYU6TaungOD27I7jubkrDn+eCpCG6As4cfElfRLD4itoBNecKqEMq65x iIKoNIYbPM0Pn6wEy6RZiqRbgb861hjxwDXjw7+vmOExaMIu29oWW2cfILBvw5Th7zeU PsSCK+cDNxQ4gDQ7beQJxROXwQiFdy4X3d5ZlYvIa9BB6oy9At8wEQdslSPa7hfkQbGb HceC+2kveoTxYWypk9SmhkPWjvRNIbi6jwtVjFGOO/+myabTuFAQeNNw2SbQZ6iFveAi 3MWa9jgH1PuyW2gsd/0/N66R3GthKJr+BRayuS2UYpTpEdkTte5A00tB3v+liq0vgyA1 Nw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3jssrwfpwh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Sep 2022 18:33:41 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 28RH5Jp8001468; Tue, 27 Sep 2022 18:33:40 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3jtpv0skn2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Sep 2022 18:33:40 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 28RIXe8E032462; Tue, 27 Sep 2022 18:33:40 GMT Received: from brm-x62-20.us.oracle.com (brm-x62-20.us.oracle.com [10.80.150.35]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3jtpv0skmp-1; Tue, 27 Sep 2022 18:33:40 +0000 From: Thomas Tai To: tony.luck@intel.com, dave.hansen@linux.intel.com, jarkko@kernel.org, reinette.chatre@intel.co, naoya.horiguchi@nec.com, linmiaohe@huawei.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, thomas.tai@oracle.com Subject: [PATCH] x86/sgx: Add code to inject hwpoison into SGX memory Date: Tue, 27 Sep 2022 14:34:11 -0400 Message-Id: <20220927183411.910077-1-thomas.tai@oracle.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-27_09,2022-09-27_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209270115 X-Proofpoint-ORIG-GUID: OFIMB3-3QhE5kdQqiQ5rWyj2L9ETlZ9_ X-Proofpoint-GUID: OFIMB3-3QhE5kdQqiQ5rWyj2L9ETlZ9_ ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664303756; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=Zv5+rHipBcgS8FwB2WOhjPJORx2DH06MRLcvr4/hF0E=; b=uL1ZFivR0Y1RRHOOzSxN+/qJPZtCIeTKho8JJocLMMeZ3vsMx8zFuQ0uCjo4ysbwRAddpK fn7u3yuT5mghP6hvNqx19/RyD+gIAbg9v1gEjAuVZUuweAiUqpeDL8tduiWnS31ZUXUkig UwDYxGojLmMRH1cr369f6/vAfnsdJZM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=DwVrq7Ze; spf=pass (imf01.hostedemail.com: domain of thomas.tai@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=thomas.tai@oracle.com; dmarc=pass (policy=none) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664303756; a=rsa-sha256; cv=none; b=iaFJl3g/Ng9+EPLZvmcwPm8liSOKB3dY5tEskgibrq55HoirUCaCC5GVvHmwGv6SVJ6x8T jMf4Ev+Lri6YATs23sn4tlezn1ApdbBGTTm/LpdxE/QthNo3O7f3EboxVi0/p8+gxIfUHa GjXqrOz1uuErs+YHGA8egPb0v8jp0RA= X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C00C040007 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=DwVrq7Ze; spf=pass (imf01.hostedemail.com: domain of thomas.tai@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=thomas.tai@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Stat-Signature: qcmqr5jkx1ne1759segesiyjcyt5km37 X-Rspam-User: X-HE-Tag: 1664303756-12050 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Inspired by commit c6acb1e7bf46 (x86/sgx: Add hook to error injection address validation), add a similar code in hwpoison_inject function to check if the address is located in SGX Memory. The error will then be handled by the arch_memory_failure function in the SGX driver. Signed-off-by: Thomas Tai Reviewed-by: Tony Luck Reviewed-by: Miaohe Lin Reviewed-by: Jarkko Sakkinen --- Documentation/mm/hwpoison.rst | 44 +++++++++++++++++++++++++++++++++++ mm/hwpoison-inject.c | 3 +++ 2 files changed, 47 insertions(+) diff --git a/Documentation/mm/hwpoison.rst b/Documentation/mm/hwpoison.rst index b9d5253c1305..8a542aca4744 100644 --- a/Documentation/mm/hwpoison.rst +++ b/Documentation/mm/hwpoison.rst @@ -162,6 +162,50 @@ Testing Some portable hwpoison test programs in mce-test, see below. +* Special notes for injection into SGX enclaves + + 1) Determine physical address of enclave page + + dmesg | grep "sgx: EPC" + + sgx: EPC section 0x8000c00000-0x807f7fffff + sgx: EPC section 0x10000c00000-0x1007fffffff + + 2) Convert the EPC address to page frame number. + + For 4K page size, the page frame number for 0x8000c00000 is + 0x8000c00000 / 0x1000 = 0x8000c00. + + 3) Trace memory_failure + + echo nop > /sys/kernel/tracing/current_tracer + echo *memory_failure > /sys/kernel/tracing/set_ftrace_filter + echo function > /sys/kernel/tracing/current_tracer + + 4) Inject a memory error + + modprobe hwpoison-inject + echo "0x8000c00" > /sys/kernel/debug/hwpoison/corrupt-pfn + + 5) Check the trace output + + cat /sys/kernel/tracing/trace + + # tracer: function + # + # entries-in-buffer/entries-written: 2/2 #P:128 + # + # _-----=> irqs-off + # / _----=> need-resched + # | / _---=> hardirq/softirq + # || / _--=> preempt-depth + # ||| / _-=> migrate-disable + # |||| / delay + # TASK-PID CPU# ||||| TIMESTAMP FUNCTION + # | | | ||||| | | + bash-12167 [002] ..... 113.136808: memory_failure<-simple_attr_write + bash-12167 [002] ..... 113.136810: arch_memory_failure<-memory_failure + References ========== diff --git a/mm/hwpoison-inject.c b/mm/hwpoison-inject.c index 65e242b5a432..8134dc983699 100644 --- a/mm/hwpoison-inject.c +++ b/mm/hwpoison-inject.c @@ -21,6 +21,9 @@ static int hwpoison_inject(void *data, u64 val) if (!capable(CAP_SYS_ADMIN)) return -EPERM; + if (arch_is_platform_page(pfn << PAGE_SHIFT)) + goto inject; + if (!pfn_valid(pfn)) return -ENXIO;