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 83C4CC433FE for ; Fri, 30 Sep 2022 21:44:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD1FE8D0001; Fri, 30 Sep 2022 17:44:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B81756B0073; Fri, 30 Sep 2022 17:44:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A48D98D0001; Fri, 30 Sep 2022 17:44:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9273B6B0072 for ; Fri, 30 Sep 2022 17:44:23 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 647B8AC0E9 for ; Fri, 30 Sep 2022 21:44:23 +0000 (UTC) X-FDA: 79970080806.28.95AACA9 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf23.hostedemail.com (Postfix) with ESMTP id DDCBB140004 for ; Fri, 30 Sep 2022 21:44:22 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 16555B829E1; Fri, 30 Sep 2022 21:44:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 787F2C433D6; Fri, 30 Sep 2022 21:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664574259; bh=hQWzHsnuiI5lL1XcvJK+0kYjG9jtiCejLLU2jWqxGBs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ox2Gq2165KexFYlVsmfZqmB30FcTIWc67xNcdJF4AgfxXojEK73QGDemj6ntyYxi2 dairUb/ZEMLE4+8Ssf7xCnC+Thgx0XueThTys1oOS1o/sLWojun8fi3XhdUmm2YGTk T/d9qHCjvm1Q93ZYq1sH6XfAFUz5TAx6V7KpXN6xiztW9T6mFFSeVAlhGz53l+Pmkw 2WMDeFK9zpsN59ME8ABArazLoWMtC12ng3nEXKp/A2KplOlcxCKDD3a7Z9TavvkS9t 4mTTx4PvuKdiK7UXRtP7gSOs/ubiha2mNk4QEvjtV+SVmU17C+2eoYCdxm7ypccBfZ bbf8DkM2qF0dA== Date: Sat, 1 Oct 2022 00:44:17 +0300 From: Jarkko Sakkinen To: Thomas Tai Cc: tony.luck@intel.com, dave.hansen@linux.intel.com, reinette.chatre@intel.co, naoya.horiguchi@nec.com, linmiaohe@huawei.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/sgx: Add code to inject hwpoison into SGX memory Message-ID: References: <20220927183411.910077-1-thomas.tai@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220927183411.910077-1-thomas.tai@oracle.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664574263; a=rsa-sha256; cv=none; b=OwNkwGMkxMC3ZDTQoZl6qylcGl7BrbC6KRDtvdh3s/nMtIc7yDNdDCp5sCUgcQJlhT3YRJ qMRSukbT/9LaxzL7rqyzvICRQaLSA+ybPLWIOZMzImhP2csS8u5a1ogBRkKxJ+K1IdxJp+ JJ1zs70JMOMFjvx24FKBRGYXpQAUz2I= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Ox2Gq216; spf=pass (imf23.hostedemail.com: domain of jarkko@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=jarkko@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664574263; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UtIhXgw2omUjDYyHal5MoWiQlne+aaEIL7R0NpXCC30=; b=lQS8jCDZ1W1sYWaBHaybTMmGH/wkavsnMXTAM+wlaT85zb1A/td0bx448GV+hykvRZccxq UCqlw3sLJF/eDkgSxBUE/o7Hw1vpsi4QTiCz2AInj3j2FOk/3Sio4gLPg5tL8lDxUPM+Ux pdWNn6BkqYOLgf/8uEaLIATnFOBvSRo= X-Stat-Signature: trcbyt3kkawyyu7gq46n3osuyr6gjeqm X-Rspamd-Queue-Id: DDCBB140004 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Ox2Gq216; spf=pass (imf23.hostedemail.com: domain of jarkko@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=jarkko@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1664574262-349507 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 Tue, Sep 27, 2022 at 02:34:11PM -0400, 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)) > + goto inject; > + > if (!pfn_valid(pfn)) > return -ENXIO; > > -- > 2.31.1 > Hey, this is really useful addition. Thanks for doing this. Reviewed-by: Jarkko Sakkinen BR, Jarkko