From mboxrd@z Thu Jan 1 00:00:00 1970 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 B0299C04A95 for ; Wed, 28 Sep 2022 07:59:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF11E8E0131; Wed, 28 Sep 2022 03:59:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA0308E0120; Wed, 28 Sep 2022 03:59:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D68128E0131; Wed, 28 Sep 2022 03:59:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C2BE98E0120 for ; Wed, 28 Sep 2022 03:59:56 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6EC0C160DEA for ; Wed, 28 Sep 2022 07:59:56 +0000 (UTC) X-FDA: 79960745592.30.6BFA8BA Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf23.hostedemail.com (Postfix) with ESMTP id 0945E14000A for ; Wed, 28 Sep 2022 07:59:54 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4McpkQ4YbQzHptq; Wed, 28 Sep 2022 15:57:34 +0800 (CST) Received: from [10.174.151.185] (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 28 Sep 2022 15:59:51 +0800 Subject: Re: [PATCH] x86/sgx: Add code to inject hwpoison into SGX memory To: Thomas Tai References: <20220927183411.910077-1-thomas.tai@oracle.com> From: Miaohe Lin CC: , , , , , , , Message-ID: Date: Wed, 28 Sep 2022 15:59:50 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20220927183411.910077-1-thomas.tai@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664351995; a=rsa-sha256; cv=none; b=T+19DfYx21md5SdHbLEIlwNt+qqvsmgBQ+Qn+ZAbj6LJ9RtynlVNHKiqMMLDtNcOlTmDUZ XkqyFln9rzzYGHV8S9riMw5jJ+3q7FSihfnUBgM7KROY+ikSea+X1hzBYcT+qV82vFCYLw uI0ZwfeKN4uj2Wh6cYkbm21wbYm4yR4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664351995; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0KYM+jckgy5MxqeU208eaLnBsH7i/2GmWZ9RT3adp9s=; b=B+RZPm1V1+zt8IhEXrqv2CY+B2K2Rp0rLYHZHw04TeCL4TfrQR0mulzX+muCGInDvXkt3D ZVluX+2DCiDGJ6geEqRaIk7YMx3axS0+POgrIMGgNO6Tovna/nBhfv/jOoPoYmcPBc9yRP 8Jkn2OlPpvzaYX7hViPF1oq5fw9dCoA= X-Rspamd-Server: rspam10 X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Stat-Signature: 7zu4pptnw8k8ctxh5j3mi8z74iz4hwqy X-Rspamd-Queue-Id: 0945E14000A X-HE-Tag: 1664351994-108542 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: On 2022/9/28 2:34, Thomas Tai wrote: > 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 > --- > 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)) Maybe it's better to add a comment above. Anyway, this patch looks good to me. Thanks. Reviewed-by: Miaohe Lin Thanks, Miaohe Lin