Received: by 10.223.164.200 with SMTP id h8csp920888wrb; Mon, 6 Nov 2017 01:00:06 -0800 (PST) X-Google-Smtp-Source: ABhQp+RGUP9ouvDaxibohUcbHp2eXEAJmGssgRRNSsRtkdGCZmHRMCt5aa/IeoYhvgmMTVD5+AZ1 X-Received: by 10.84.215.9 with SMTP id k9mr13740845pli.284.1509958805989; Mon, 06 Nov 2017 01:00:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509958805; cv=none; d=google.com; s=arc-20160816; b=SQEzvTMYnmG8N48xrClygtWp3g/pdGbNGPqB28gY3wQuYNAa0v50znS+R4lZ2r4TOQ RSsmqZOBRCZQPNDWdIqH3fafeQT5cu3ZP8a1kxXKOzBiAK7+mzPeCmW/70W5dRbnAsHt Me9pXfYNr3H/IPBz6oaU3/43Tw3qPOFbHcLlxb4MIKpC9w56OsvxHCtknTatVk6PFUId 4XjgT1Ur9bXfk6pb8ldBEbEarUG+J59v/O7VyR6tFIK9SPTZbVqAPx88LDVuypiiQMQK EJkCt1QSJ7uXgDejuNysKAaRYOyXu/QngawpPoZo5lJSscVTCSL9qdrjvXp/j2gC165O /2uA== 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=2j0y8uaRjiFJXofm1DBPRR/i/L2x/DaClDZkcDlzTTI=; b=CjQZwXFeUWm7aK+BcqgDbgLQAktZVRkkbFoJYXAR0yLMK4T7RxHt9kvBvo3xxOLXJ3 e4QdlhoHju31+zqLNzRC5hw1PldVYQDRJCwRF44ejZJkGSILK0ik6KGuX4oBvOloZoLS SdCCHN33VXe0KKN7/3xIKy/QVefF5sDx/Z+JHkDEnTeVKzS/BK79eKwHbkvwXE+hX5k+ pdvhhnm0nxb6cT3JIHz4n7QF8v7cL+PQboWojltVxHpkTDiO1K5TlUSdjTR8YgMUrXoT V0bZb23jD+C11XbrVpi3wjRYae/3VoWi+WcBLu0Ul+zSynUIDsYkEX+bSqp5jq6+ZHI5 mXJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=DI13gDLp; 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 z14si10836781plh.282.2017.11.06.00.59.51; Mon, 06 Nov 2017 01:00:05 -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=DI13gDLp; 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 S1752330AbdKFI7Q (ORCPT + 98 others); Mon, 6 Nov 2017 03:59:16 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:55310 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752306AbdKFI7M (ORCPT ); Mon, 6 Nov 2017 03:59:12 -0500 Received: by mail-qt0-f195.google.com with SMTP id v41so9977636qtv.12; Mon, 06 Nov 2017 00:59:12 -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=2j0y8uaRjiFJXofm1DBPRR/i/L2x/DaClDZkcDlzTTI=; b=DI13gDLpFXLUBaqmK9p47hONif2h3v9Gp+jJndGZlNy/sdTSOKx14EUxhtbe36H4Yt n53Ni67lCSGKOf3BHdV9DOVXC/639riVekxtA2GxY9dqhf/utdt1bNgnatBBIU9v/QbJ cqthZqUmWVW0qGL4ebeJcjuaD5hHDVlVRg5Ie/Ct/TYkYVkULLwWf3oVofJ8/Vvr4bqf L84YeOrnwD25EuJA1JOAcPqj8eCNiR+gPLyXiEUDWSv6KBHpZMvwfYxhv6sBI+FTpHE3 uFmjhoRDaigoOxq6h1DdIZhI43KJlVEgkh9uF9s9kTKcBt3/ynMV0nz16v8oGgQr0glh WwcA== 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=2j0y8uaRjiFJXofm1DBPRR/i/L2x/DaClDZkcDlzTTI=; b=AjmS4+nU5ha41awJp0digmkXFEb1X0913Sro4/9FJKLw9oWZVK8ROIk9ZKaP7fncQG 2llCWPb96cAoVxlcyUjoca5kb+DWl3j70n8EnsARYc4ymuV8QFYl5plFUPcRRbz6B/Ez htQzWIeHIHOWt5GrgPqYQRet8HEnhvwjrdvuoqLm22oreoi6QhIlXqEEIwAWmFN2R3bE 2APuLn4e8ICNLYqeMnVAZCarorOZNe/5gNJFAKkdrj1Z4Q/YVihOi0a2Sf1cdUos4bTs dhcBYxO2EnYEttd75n0QXPAvpPYPKWcNQqyc2SdfFH4ev7e6mb/d1oaRdAGrAjvVTLWl 7+2w== X-Gm-Message-State: AMCzsaUj5lSO76LpkVDAnWi0hiWbWbV7/aPnYWwIAlYeaaGeCN3HL7DS sQFjfzKHOxKJYJjCXNEHDJs= X-Received: by 10.200.36.150 with SMTP id s22mr22121167qts.237.1509958751868; Mon, 06 Nov 2017 00:59:11 -0800 (PST) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id r26sm8001094qki.42.2017.11.06.00.59.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:59:11 -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 v9 19/51] powerpc: Handle exceptions caused by pkey violation Date: Mon, 6 Nov 2017 00:57:11 -0800 Message-Id: <1509958663-18737-20-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> References: <1509958663-18737-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 --- arch/powerpc/mm/fault.c | 32 +++++++++++++++++++++++++++----- 1 files changed, 27 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index 4797d08..dfcd0e4 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -145,6 +145,24 @@ static noinline int bad_area(struct pt_regs *regs, unsigned long address) return __bad_area(regs, address, SEGV_MAPERR); } +static int bad_page_fault_exception(struct pt_regs *regs, unsigned long address, + int si_code) +{ + int sig = SIGBUS; + int code = BUS_OBJERR; + +#ifdef CONFIG_PPC_MEM_KEYS + if (si_code & DSISR_KEYFAULT) { + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); + sig = SIGSEGV; + code = SEGV_PKUERR; + } +#endif /* CONFIG_PPC_MEM_KEYS */ + + _exception(sig, regs, code, address); + return 0; +} + static int do_sigbus(struct pt_regs *regs, unsigned long address, unsigned int fault) { @@ -391,11 +409,9 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address, return 0; if (unlikely(page_fault_is_bad(error_code))) { - if (is_user) { - _exception(SIGBUS, regs, BUS_OBJERR, address); - return 0; - } - return SIGBUS; + if (!is_user) + return SIGBUS; + return bad_page_fault_exception(regs, address, error_code); } /* Additional sanity check(s) */ @@ -498,6 +514,12 @@ 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 (unlikely(fault & VM_FAULT_SIGSEGV)) + return __bad_area(regs, address, SEGV_PKUERR); +#endif /* CONFIG_PPC_MEM_KEYS */ + major |= fault & VM_FAULT_MAJOR; /* -- 1.7.1 From 1583307760926008874@xxx Mon Nov 06 09:19:06 +0000 2017 X-GM-THRID: 1583278151262820801 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread