{"id":811889,"url":"http://patchwork.ozlabs.org/api/patches/811889/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/1504910713-7094-31-git-send-email-linuxram@us.ibm.com/","project":{"id":2,"url":"http://patchwork.ozlabs.org/api/projects/2/?format=json","name":"Linux PPC development","link_name":"linuxppc-dev","list_id":"linuxppc-dev.lists.ozlabs.org","list_email":"linuxppc-dev@lists.ozlabs.org","web_url":"https://github.com/linuxppc/wiki/wiki","scm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git","webscm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/","list_archive_url":"https://lore.kernel.org/linuxppc-dev/","list_archive_url_format":"https://lore.kernel.org/linuxppc-dev/{}/","commit_url_format":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id={}"},"msgid":"<1504910713-7094-31-git-send-email-linuxram@us.ibm.com>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/1504910713-7094-31-git-send-email-linuxram@us.ibm.com/","date":"2017-09-08T22:45:10","name":"[22/25] powerpc: capture the violated protection key on fault","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":false,"hash":"ae376860f6dc9559cbed844ca5632664c9481fb4","submitter":{"id":2667,"url":"http://patchwork.ozlabs.org/api/people/2667/?format=json","name":"Ram Pai","email":"linuxram@us.ibm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/1504910713-7094-31-git-send-email-linuxram@us.ibm.com/mbox/","series":[{"id":2303,"url":"http://patchwork.ozlabs.org/api/series/2303/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=2303","date":"2017-09-08T22:44:40","name":"powerpc: Free up RPAGE_RSV bits","version":1,"mbox":"http://patchwork.ozlabs.org/series/2303/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811889/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811889/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>","X-Original-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xpv6j2Znyz9sRY\n\tfor <patchwork-incoming@ozlabs.org>;\n\tSat,  9 Sep 2017 09:44:13 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xpv6j1NjMzDrKx\n\tfor <patchwork-incoming@ozlabs.org>;\n\tSat,  9 Sep 2017 09:44:13 +1000 (AEST)","from mail-qt0-x243.google.com (mail-qt0-x243.google.com\n\t[IPv6:2607:f8b0:400d:c0d::243])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3xpss63SFGzDrcy\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tSat,  9 Sep 2017 08:47:22 +1000 (AEST)","by mail-qt0-x243.google.com with SMTP id 7so2357460qtz.3\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tFri, 08 Sep 2017 15:47:22 -0700 (PDT)","from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net.\n\t[50.39.103.96]) by smtp.gmail.com with ESMTPSA id\n\tx124sm2033726qka.85.2017.09.08.15.47.18\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tFri, 08 Sep 2017 15:47:20 -0700 (PDT)"],"Authentication-Results":["ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"JE70y0hq\"; dkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"JE70y0hq\"; dkim-atps=neutral","ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gmail.com\n\t(client-ip=2607:f8b0:400d:c0d::243; helo=mail-qt0-x243.google.com;\n\tenvelope-from=ram.n.pai@gmail.com; receiver=<UNKNOWN>)","lists.ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"JE70y0hq\"; dkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=sender:from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=tjoLRWV8/gE2726EvKR5SxiBU56PhidBO43op8+yP5A=;\n\tb=JE70y0hqEy9A3+WqagR3RMdMqjeG+nKquToryqO/cHp3eUL7C7vTjn918bti9fEIKS\n\tW07N9Hn9G7MazzmV5B3JZawCIcK7qhPmGIJFId9a3HOFtyZ9mhX4toY7JbOCFstk+kPM\n\tG+6N/XonHOgXXJrMEiOYvGvT7Bo6GZN6YKidyiMNG23x1uNxN1xe1NL5J0Ojewbgn0wx\n\tuYplL+BdprkINa+cj7PN72LKQHqtt3eBiyaTTpP1JXcFMtSkMRvgixyut16aqTdK0DGg\n\tNVxee5g/3duHi9pL3NZj7puSukKkFHwGBiYUivxlnNheBwLbOdhZvgFYKoZgOksoZdau\n\tZzYQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:sender:from:to:cc:subject:date:message-id\n\t:in-reply-to:references;\n\tbh=tjoLRWV8/gE2726EvKR5SxiBU56PhidBO43op8+yP5A=;\n\tb=Y38b5+FHFGWC4Xw33rXR8HaGL4vlkWUMWgJu6FxMpn9Vrejr5JAdmV2S47QUUj+y6g\n\tQgJgTWGmS8nrAT07Zbap9vmUaistsyPvxYL3DHCkCoyXEBK9V19T7VdEQYEgKxhlCE9j\n\tpe1QW0Xo96zPZ8Lhrs1OMhxbzL8ZjToeHe8ddzJK27uC58G+XwLTEXz/I5SKqdqOTZyS\n\tC/vNKrrUyXp9oHNjDXzRoB7eHkoLDEVaTyCr34GrkjUD/POCGoie99aIcAx4wUnVRY6R\n\tjmewWwETx/Kh5m4kAJlZG5239SUzYUHeOgB33FBHnI3PbOc0YRN7evw7AbI6OHE9ZTGt\n\tmvWA==","X-Gm-Message-State":"AHPjjUhJs2oKpSlTVKI4YJ3ksk5VOGAo2D0g0xb+RC3orcL9bhQoBxmT\n\trPAacr+2VqCNHg==","X-Google-Smtp-Source":"AOwi7QA24Bd69kye+iVe8x9bMN7Yp0td1YZgkg01cI8J/QOiJ1F2acNIyDAC0TrWhYt4aVsRT6NjcA==","X-Received":"by 10.200.49.170 with SMTP id h39mr6156346qte.162.1504910840623; \n\tFri, 08 Sep 2017 15:47:20 -0700 (PDT)","From":"Ram Pai <linuxram@us.ibm.com>","To":"mpe@ellerman.id.au,\n\tlinuxppc-dev@lists.ozlabs.org","Subject":"[PATCH 22/25] powerpc: capture the violated protection key on fault","Date":"Fri,  8 Sep 2017 15:45:10 -0700","Message-Id":"<1504910713-7094-31-git-send-email-linuxram@us.ibm.com>","X-Mailer":"git-send-email 1.7.1","In-Reply-To":"<1504910713-7094-1-git-send-email-linuxram@us.ibm.com>","References":"<1504910713-7094-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\n\t<linuxppc-dev.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>","Cc":"ebiederm@xmission.com, linuxram@us.ibm.com, mhocko@kernel.org,\n\tpaulus@samba.org, aneesh.kumar@linux.vnet.ibm.com,\n\tbauerman@linux.vnet.ibm.com, khandual@linux.vnet.ibm.com","Errors-To":"linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org","Sender":"\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>"},"content":"Capture the protection key that got violated in paca.\nThis value will be later used to inform the signal\nhandler.\n\nSigned-off-by: Ram Pai <linuxram@us.ibm.com>\n---\n arch/powerpc/include/asm/paca.h   |    3 +++\n arch/powerpc/kernel/asm-offsets.c |    5 +++++\n arch/powerpc/mm/fault.c           |   11 ++++++++++-\n 3 files changed, 18 insertions(+), 1 deletions(-)","diff":"diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h\nindex 04b60af..51c89c1 100644\n--- a/arch/powerpc/include/asm/paca.h\n+++ b/arch/powerpc/include/asm/paca.h\n@@ -97,6 +97,9 @@ struct paca_struct {\n \tstruct dtl_entry *dispatch_log_end;\n #endif /* CONFIG_PPC_STD_MMU_64 */\n \tu64 dscr_default;\t\t/* per-CPU default DSCR */\n+#ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS\n+\tu16 paca_pkey;                  /* exception causing pkey */\n+#endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */\n \n #ifdef CONFIG_PPC_STD_MMU_64\n \t/*\ndiff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c\nindex 8cfb20e..361f0d4 100644\n--- a/arch/powerpc/kernel/asm-offsets.c\n+++ b/arch/powerpc/kernel/asm-offsets.c\n@@ -241,6 +241,11 @@ int main(void)\n \tOFFSET(PACAHWCPUID, paca_struct, hw_cpu_id);\n \tOFFSET(PACAKEXECSTATE, paca_struct, kexec_state);\n \tOFFSET(PACA_DSCR_DEFAULT, paca_struct, dscr_default);\n+\n+#ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS\n+\tOFFSET(PACA_PKEY, paca_struct, paca_pkey);\n+#endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */\n+\n \tOFFSET(ACCOUNT_STARTTIME, paca_struct, accounting.starttime);\n \tOFFSET(ACCOUNT_STARTTIME_USER, paca_struct, accounting.starttime_user);\n \tOFFSET(ACCOUNT_USER_TIME, paca_struct, accounting.utime);\ndiff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c\nindex a16bc43..ad31f6e 100644\n--- a/arch/powerpc/mm/fault.c\n+++ b/arch/powerpc/mm/fault.c\n@@ -153,6 +153,7 @@ static int bad_page_fault_exception(struct pt_regs *regs, unsigned long address,\n \n #ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS\n \tif (si_code & DSISR_KEYFAULT) {\n+\t\tget_paca()->paca_pkey = get_pte_pkey(current->mm, address);\n \t\tsig = SIGSEGV;\n \t\tcode = SEGV_PKUERR;\n \t}\n@@ -509,8 +510,16 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address,\n \n #ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS\n \tif (!arch_vma_access_permitted(vma, flags & FAULT_FLAG_WRITE,\n-\t\t\tis_exec, 0))\n+\t\t\tis_exec, 0)) {\n+\t\t/*\n+\t\t * The pgd-pdt...pmd-pte tree may not  have  been fully setup.\n+\t\t * Hence we cannot walk the tree to locate the pte, to locate\n+\t\t * the key. Hence lets use vma_pkey() to get the key; instead\n+\t\t * of get_pte_pkey().\n+\t\t */\n+\t\tget_paca()->paca_pkey = vma_pkey(vma);\n \t\treturn __bad_area(regs, address, SEGV_PKUERR);\n+\t}\n #endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */\n \n \n","prefixes":["22/25"]}