From patchwork Sun Jul 16 03:56:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 789029 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x9Dp15WBmz9s4s for ; Sun, 16 Jul 2017 15:03:05 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Pguhbdlw"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3x9Dp144QSzDqpR for ; Sun, 16 Jul 2017 15:03:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Pguhbdlw"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-qk0-x243.google.com (mail-qk0-x243.google.com [IPv6:2607:f8b0:400d:c09::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3x9CNb1RKczDqmV for ; Sun, 16 Jul 2017 13:59:27 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Pguhbdlw"; dkim-atps=neutral Received: by mail-qk0-x243.google.com with SMTP id a66so16022788qkb.0 for ; Sat, 15 Jul 2017 20:59:27 -0700 (PDT) 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=QUjqSkW2xXyAsVPQHgdW/Rduko9cJBsIdEAlptpOw/w=; b=PguhbdlwHtJvkas0ionbdOsDcMvXfdwjgjNxmOciYavWfg7CsqKiwQY59dLBTzGaRh +plx00KGUTFadCLXJUfI9nFrTz/Av4dhB3OIF8+fCBIc/OmaWlX6DLVenMIv2ZV7xVwd FJBr1+4tVjsIQKlRaCTPCw8obCuB0U4i231cPvAaDKFaQaVjQbYZC1pLhBHrYiJQUveD mndUCLFzlHtSd/uTGwc0X/tUYGR2Ixwtu4tCsPeZUa5xBLazIvIq2oCWshEGy76KQmNk PzAllW70NxGc8RJmSdQu7i6TJjKm4SZK7nFvnvmQfJyLjmZwN6fIFOA6DNR/TozQBFYq YaqA== 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=QUjqSkW2xXyAsVPQHgdW/Rduko9cJBsIdEAlptpOw/w=; b=P/I2zkDwH+fhKRGNAkm41dovEnCLGVyuBNZWpXCZZQ1F597oHM9Fnw6YkC9yhtl09F NsimbZ8014wcOUkM+gcArVMHJRYPoyrBFnrjApVHj5wOpCMPmzbyEyckkEcWRNMHHA7N IcPjSFDV9E1CbZvH2nE7ZucL0sERON2RN/dOfmCnpcHEBUGxO1HloO+uEWApgmf62A0M dIh7uviqrYvdB5lP/PogJRXypJVLeUtNZB5yypfseoWf/jXrzFFG3dKaeUQeXkeor2O3 yO/+IySwqtoW1e122r7WgnRmFyZPp0ef4v3SIhesTRN3XMR0+hkHY9Y8KTJQG7u0DeTL 3Nag== X-Gm-Message-State: AIVw111dW83Dw0dh7AjFwKH/E3gPoOMn+KB7JQ+cuxyD+LSOmOifVmPl A0z2NX9lozcZEFtUFOs= X-Received: by 10.233.216.1 with SMTP id u1mr19261014qkf.10.1500177565220; Sat, 15 Jul 2017 20:59:25 -0700 (PDT) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id q46sm2290345qtc.54.2017.07.15.20.59.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Jul 2017 20:59:24 -0700 (PDT) From: Ram Pai To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC v6 34/62] powerpc: capture the violated protection key on fault Date: Sat, 15 Jul 2017 20:56:36 -0700 Message-Id: <1500177424-13695-35-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1500177424-13695-1-git-send-email-linuxram@us.ibm.com> References: <1500177424-13695-1-git-send-email-linuxram@us.ibm.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: arnd@arndb.de, corbet@lwn.net, linuxram@us.ibm.com, mhocko@kernel.org, dave.hansen@intel.com, mingo@redhat.com, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, akpm@linux-foundation.org, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Capture the protection key that got violated in paca. This value will be later used to inform the signal handler. Signed-off-by: Ram Pai --- arch/powerpc/include/asm/paca.h | 1 + arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/mm/fault.c | 8 ++++++++ 3 files changed, 10 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h index c8bd1fc..0c06188 100644 --- a/arch/powerpc/include/asm/paca.h +++ b/arch/powerpc/include/asm/paca.h @@ -94,6 +94,7 @@ struct paca_struct { u64 dscr_default; /* per-CPU default DSCR */ #ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS u64 paca_amr; /* value of amr at exception */ + u16 paca_pkey; /* exception causing pkey */ #endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */ #ifdef CONFIG_PPC_STD_MMU_64 diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index 17f5d8a..7dff862 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -244,6 +244,7 @@ int main(void) #ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS OFFSET(PACA_AMR, paca_struct, paca_amr); + OFFSET(PACA_PKEY, paca_struct, paca_pkey); #endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */ OFFSET(ACCOUNT_STARTTIME, paca_struct, accounting.starttime); diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index a6710f5..6423277 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -265,6 +265,7 @@ int do_page_fault(struct pt_regs *regs, unsigned long address, if (error_code & DSISR_KEYFAULT) { code = SEGV_PKUERR; get_paca()->paca_amr = read_amr(); + get_paca()->paca_pkey = get_pte_pkey(current->mm, address); goto bad_area_nosemaphore; } #endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */ @@ -453,6 +454,13 @@ int do_page_fault(struct pt_regs *regs, unsigned long address, if (!arch_vma_access_permitted(vma, flags & FAULT_FLAG_WRITE, is_exec, 0)) { get_paca()->paca_amr = read_amr(); + /* + * The pgd-pdt...pmd-pte tree may not have been fully setup. + * Hence we cannot walk the tree to locate the pte, to locate + * the key. Hence lets call vma_pkey() to get the key here + * instead of get_pte_pkey(). + */ + get_paca()->paca_pkey = vma_pkey(vma); code = SEGV_PKUERR; goto bad_area; }