Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp903764oof; Tue, 25 Sep 2018 06:13:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV62VVAipmfYTlUytzcihxsF1Jk64JzxGJ5TA/W4qomEYhQLpmmsfCgcEfZEQ5L6vB1hAVYV5 X-Received: by 2002:a63:6a42:: with SMTP id f63-v6mr1122224pgc.48.1537881239675; Tue, 25 Sep 2018 06:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537881239; cv=none; d=google.com; s=arc-20160816; b=InuxUtUTU60TXgO9KVe1YcIu/9laXHLdDw6t8iMRu8avsrSBmrtHAVeob+8V28XLnd zMaYNVKXkIoy6cV/IRx70HDCvZEsBG/vXMioodwPAjE4AfmvHvfF6Q40uMoBCtfSM2lU VFlG/mMOgnntMziQ9FmTCzwziaZtEZ9FLweg50EzRhtDY59Xzd0zwZeRFxJRlDDXtdfI KDiIM2JNUMw8ItqyiA5kSaUyIpBjV6YtC6Hugd5IUQuihWtMSgEf4hGK4hwtOo6fX7f6 jPv1yG6gyCyeRqVSBLG0PdfbsvR195f3SrpjtpkKX8qEwVwmMGaHhW5sTS1q3nyHods1 7Cvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=Q2+vhbz15ShUpt9fKUO3kmFkN2nBGk6HTp7HeoCrNV0=; b=m/p3TQim99nKsPzaZif66+7e1lidhYmyYct5pnmbXuTVROta8a4+sIoGj5qX3Uwwd9 yaVqbBFoS8xT3aJTiYeXPmGQFFDG/sF6iz96vI61efdgCQdPqGWPDdOjsBiInl/FPA/d 9VBV53z6EnMXgz8/e1X9NUtzTsurEOvPypQI3tJe1K3MLEqmr0GpeqLPbdhoa1cYP6jQ CamvcAABsqfWMoP9Ps1u4JUFWayAN30O5toUVG3K/mE31UBhDBmW4rP81jtjQ5RmOlI/ v7O39GxZjz7tykWEwG3Bk50vZAPt9RXg2U0XVr5y48F2FjDX9ceIkpSHqbwJhWaH4yEr qiCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id a7-v6si2447595pga.322.2018.09.25.06.13.42; Tue, 25 Sep 2018 06:13:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729336AbeIYTUY (ORCPT + 99 others); Tue, 25 Sep 2018 15:20:24 -0400 Received: from mga02.intel.com ([134.134.136.20]:39145 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729112AbeIYTUW (ORCPT ); Tue, 25 Sep 2018 15:20:22 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2018 06:12:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,302,1534834800"; d="scan'208";a="93546815" Received: from thomasvo-mobl2.ger.corp.intel.com (HELO localhost) ([10.252.53.212]) by orsmga001.jf.intel.com with ESMTP; 25 Sep 2018 06:10:41 -0700 From: Jarkko Sakkinen To: x86@kernel.org, platform-driver-x86@vger.kernel.org Cc: dave.hansen@intel.com, sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, serge.ayoun@intel.com, shay.katz-zamir@intel.com, linux-sgx@vger.kernel.org, andriy.shevchenko@linux.intel.com, Dave Hansen , Jarkko Sakkinen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , linux-kernel@vger.kernel.org (open list:X86 MM) Subject: [PATCH v14 09/19] x86/mm: x86/sgx: Signal SEGV_SGXERR for #PFs w/ PF_SGX Date: Tue, 25 Sep 2018 16:06:46 +0300 Message-Id: <20180925130845.9962-10-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180925130845.9962-1-jarkko.sakkinen@linux.intel.com> References: <20180925130845.9962-1-jarkko.sakkinen@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Signal SIGSEGV(SEGV_SGXERR) for all faults with PF_SGX set in the error code. The PF_SGX bit is set if and only if the #PF is detected by the Enclave Page Cache Map (EPCM), which is consulted only after an access walks the kernel's page tables, i.e.: a. the access was allowed by the kernel b. the kernel's tables have become less restrictive than the EPCM c. the kernel cannot fixup the cause of the fault Noteably, (b) implies that either the kernel has botched the EPC mappings or the EPCM has been invalidated due to a power event. In either case, userspace needs to be alerted so that it can take appropriate action, e.g. restart the enclave. This is reinforced by (c) as the kernel doesn't really have any other reasonable option, e.g. we could kill the task or panic, but neither is warranted. Signed-off-by: Sean Christopherson Cc: Dave Hansen Signed-off-by: Jarkko Sakkinen --- arch/x86/mm/fault.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 85d20516b2f3..3fb2b2838d6c 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -960,10 +960,13 @@ static noinline void bad_area_access_error(struct pt_regs *regs, unsigned long error_code, unsigned long address, struct vm_area_struct *vma) { + int si_code = SEGV_ACCERR; + if (bad_area_access_from_pkeys(error_code, vma)) - __bad_area(regs, error_code, address, vma, SEGV_PKUERR); - else - __bad_area(regs, error_code, address, vma, SEGV_ACCERR); + si_code = SEGV_PKUERR; + else if (unlikely(error_code & X86_PF_SGX)) + si_code = SEGV_SGXERR; + __bad_area(regs, error_code, address, vma, si_code); } static void @@ -1153,6 +1156,17 @@ access_error(unsigned long error_code, struct vm_area_struct *vma) if (error_code & X86_PF_PK) return 1; + /* + * Access is blocked by the Enclave Page Cache Map (EPCM), + * i.e. the access is allowed by the PTE but not the EPCM. + * This usually happens when the EPCM is yanked out from + * under us, e.g. by hardware after a suspend/resume cycle. + * In any case, there is nothing that can be done by the + * kernel to resolve the fault (short of killing the task). + */ + if (unlikely(error_code & X86_PF_SGX)) + return 1; + /* * Make sure to check the VMA so that we do not perform * faults just to hit a X86_PF_PK as soon as we fill in a -- 2.17.1