Received: by 10.223.176.46 with SMTP id f43csp306824wra; Thu, 18 Jan 2018 17:54:23 -0800 (PST) X-Google-Smtp-Source: ACJfBosFst8hV5ADphCfj3LfwoR+e03G0KcqnOzqPoAgAQJj28T0TCO0yWoiF0g/cbOTAvKiA5aG X-Received: by 10.99.126.89 with SMTP id o25mr37776283pgn.161.1516326863637; Thu, 18 Jan 2018 17:54:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516326863; cv=none; d=google.com; s=arc-20160816; b=UayGne6f3baIzxqCrxFCvahvuZCutz8oaLsr4/a+NzsuGwjMW0Z2C91Hroza5hmXcZ IKievtm8lcah/RAx5a9W0tZynCGSLnC356ANGMcLftpcpjd/NuJUbKzM4xacc9SfckKf 63D0MJMylGaII74UXZGt2/ytpOuidN3y7BA1MHxUF4OcSwRLajEF/VwPICRcJKFgxeJa sJsGOtpE5HKjh2QHMg89bDhFmT4MkMI1FsLLGXXXCmDPKGVkuE3VlT9wHtJ/gU4aFtj6 W90bAaGszEhHXuDqS+Jawi1TZkKHGcJC+YkjSDFAPZV0eieQpx3EwFps8A8jJbs2SEYD XjnQ== 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:dkim-signature:arc-authentication-results; bh=jEFr+/ItQprjvRbosCMEviNuJ+iENrbFOe79xZZDJ7A=; b=WFTmz0wNvcualW6/JueJZUjak/RGMmmuzEo71XawODvlkiLvyl4jUFQEhtj9x6rLF+ y9LGkj8PxSm76aDPv7UImeolRwpqdpTErUM0kc2fFd6IxtNnA7UUQwbaQcwZleecNc0B DQRTnUeapCaKWFgXjMCCxxOGDwoACuQFQV6vNenYgqyO0Hip5e5pTby+U7pBvhM1c+cs 7Jb+IdU+0RvEb3isAnqOEibV5BLzEx9Idz8KJ7v6mqFRvMLl+W36OTEjHvniZUk5iLtR 3axKpQRbsmQSlEOBWeNpzA0zcM/XGOK2HYxquWB1qqduonuABAoZH3gORPns+8efXbbo n2AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=se4l5zai; 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r29si8219681pfj.115.2018.01.18.17.54.10; Thu, 18 Jan 2018 17:54:23 -0800 (PST) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=se4l5zai; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932907AbeASBxq (ORCPT + 99 others); Thu, 18 Jan 2018 20:53:46 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:44028 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755740AbeASBwk (ORCPT ); Thu, 18 Jan 2018 20:52:40 -0500 Received: by mail-qt0-f193.google.com with SMTP id s3so422701qtb.10; Thu, 18 Jan 2018 17:52:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=jEFr+/ItQprjvRbosCMEviNuJ+iENrbFOe79xZZDJ7A=; b=se4l5zaipkRSkLO8D+eJe+ThLKHw2LY8ug8qyfsIyPtRnWOc8VKGyT2ok2dxpelLbu tVrvZqz1TtswdrOu31FzYkgD+M9Psqxzyox6r6/u75Na7fvjkWsAloaw2nAnkIMZBCOp J3KOql1fubvy9ghiVQ3CbwkRYwtteWKu5Fx05o+QsmsJy26gsI3YKgM2r35TjNGWqrMb O2MGuv6OkRAyVjMjLWxcTNHolzLXX1tl8Y+TU5Vm4YmHD07zTDjnqX7pA1WkV00xq/zQ LXVffIHMfDAEa8vwwaKJ9/H8Lo4dyZB6YsKCILwNnFSIamL8FtwOyllLZS0l88LTXin/ xvFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=jEFr+/ItQprjvRbosCMEviNuJ+iENrbFOe79xZZDJ7A=; b=NeVWkObHoYrRMQ1AXKEbaWEAVV9i3IbBp3Ev7fX1byfahHQhDT1SNBTAZivs+1BFN7 JgxaLmS1JLp3xqOxRt5S8YA6PmT/PrmiNEhGumzJIdcUzSktAWKlYQp1dwkz0f1Viffk ET+BrL8gj1wC+7jhERe3Ht9u1rNQ7RdTE1m27mDIvfAWlYPPPBvMib1gcOifLD1N8wIP 6HCSZ4N3pr2B0vqCg8qZ5BG8/7GGFeTpvi7RgKqeERpHo5c0BplX+6k1aQAtQhGAXJcj wuoQoqG8zp54Bg0q6DcfTGOKldD00N3MBe3kyA72kjC1rZdT7if5MfiY0ZSaWdnP1SIj Py/Q== X-Gm-Message-State: AKwxytd3hl0/o4t3ajNPppXuBk/gggvObHtS4G3V0NE060GnzhsF78y8 uI/5aeaEmuM970BRSJzrqBY= X-Received: by 10.237.52.226 with SMTP id x89mr21715821qtd.114.1516326757906; Thu, 18 Jan 2018 17:52:37 -0800 (PST) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id c127sm5483161qke.78.2018.01.18.17.52.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 17:52:37 -0800 (PST) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org, corbet@lwn.net, arnd@arndb.de Cc: linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, linuxram@us.ibm.com Subject: [PATCH v10 19/27] powerpc: Handle exceptions caused by pkey violation Date: Thu, 18 Jan 2018 17:50:40 -0800 Message-Id: <1516326648-22775-20-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1516326648-22775-1-git-send-email-linuxram@us.ibm.com> References: <1516326648-22775-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Handle Data and Instruction exceptions caused by memory protection-key. The CPU will detect the key fault if the HPTE is already programmed with the key. However if the HPTE is not hashed, a key fault will not be detected by the hardware. The software will detect pkey violation in such a case. Signed-off-by: Ram Pai Signed-off-by: Thiago Jung Bauermann --- arch/powerpc/include/asm/reg.h | 1 - arch/powerpc/kernel/exceptions-64s.S | 2 +- arch/powerpc/mm/fault.c | 22 ++++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h index b779f3c..ffc9990 100644 --- a/arch/powerpc/include/asm/reg.h +++ b/arch/powerpc/include/asm/reg.h @@ -312,7 +312,6 @@ DSISR_BAD_EXT_CTRL) #define DSISR_BAD_FAULT_64S (DSISR_BAD_FAULT_32S | \ DSISR_ATTR_CONFLICT | \ - DSISR_KEYFAULT | \ DSISR_UNSUPP_MMU | \ DSISR_PRTABLE_FAULT | \ DSISR_ICSWX_NO_CT | \ diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S index e441b46..804e804 100644 --- a/arch/powerpc/kernel/exceptions-64s.S +++ b/arch/powerpc/kernel/exceptions-64s.S @@ -1521,7 +1521,7 @@ USE_TEXT_SECTION() .balign IFETCH_ALIGN_BYTES do_hash_page: #ifdef CONFIG_PPC_BOOK3S_64 - lis r0,(DSISR_BAD_FAULT_64S|DSISR_DABRMATCH)@h + lis r0,(DSISR_BAD_FAULT_64S | DSISR_DABRMATCH | DSISR_KEYFAULT)@h ori r0,r0,DSISR_BAD_FAULT_64S@l and. r0,r4,r0 /* weird error? */ bne- handle_page_fault /* if not, try to insert a HPTE */ diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index 4797d08..943a91e 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -427,6 +427,11 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address, perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); + if (error_code & DSISR_KEYFAULT) { + _exception(SIGSEGV, regs, SEGV_PKUERR, address); + return 0; + } + /* * We want to do this outside mmap_sem, because reading code around nip * can result in fault, which will cause a deadlock when called with @@ -498,6 +503,23 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address, * the fault. */ fault = handle_mm_fault(vma, address, flags); + +#ifdef CONFIG_PPC_MEM_KEYS + /* + * if the HPTE is not hashed, hardware will not detect + * a key fault. Lets check if we failed because of a + * software detected key fault. + */ + if (unlikely(fault & VM_FAULT_SIGSEGV) && + !arch_vma_access_permitted(vma, flags & FAULT_FLAG_WRITE, + is_exec, 0)) { + int pkey = vma_pkey(vma); + + if (likely(pkey)) + return __bad_area(regs, address, SEGV_PKUERR); + } +#endif /* CONFIG_PPC_MEM_KEYS */ + major |= fault & VM_FAULT_MAJOR; /* -- 1.7.1