Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4682imu; Thu, 10 Jan 2019 15:50:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN6DbqJMvy7pym3GOjx4VWEMJr32bRsRK4hoAqa+3awlSx+nEcfg5jiiMh7wCtMgaYIAlKwt X-Received: by 2002:a63:f658:: with SMTP id u24mr11345596pgj.267.1547164256252; Thu, 10 Jan 2019 15:50:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547164256; cv=none; d=google.com; s=arc-20160816; b=PsfOqUBy+HyV05uxrjfABrP4slHqcjDH44w5ffYCj8R6VxVStX4TQQ9gdIcvYwXHVN 2RiHjagHJGVDVNKso/kkIf24QvG/2SQEyVJpTfH9MQ63+siwM1p8OM9B9pzYfm05oIJt iGlynBviYOW2a4CWKZSEcLuiNaqxq/86xI4hwBv4fz2G/KE/vxqxeLJ1bnyDkEKvp7C7 jrtfF3uUDDnfuTeYkY64kK0mUhYgthT6mi26opHZlLe1ustX6J+sR1tXWBPuKlj2eVhV cLn6t7O0xOfegHwzKmWP7bse43fv0NKLVMRlwAiBy/XvZe9MPc3do7THduZZeZvyNWFf kWrg== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=gX2mJdtpePxKA35+8CzrSsJglZdMj3Uyq1TNFTJ+UG8=; b=e6IklVW1IChNS2WIQiBw9mL6Do8SFvTl/og6nErtnUUeupoCrNNnHJi7icoerbkRAr frH9AlInSJWKrbz55M42hDvIvCasdj0/Xp7GAqXM+mZb7Zy3WflfF/QMns17fDObYlmG uiQ2mKLZRCjvv8Oxuez5okkYT4CW2Sey/n72xk0UOq2aPA2RGoQQPrJ/vnVAGoI1G1J6 eIaXAxiqq57pD5PcJhOC8bnKAnRnWzTmzeRzEbK3RBLW9Rkt5Zr43RRfL+jWUQb1HoGz QnZVURsdaEZPe9SGNmJJK4hATm/X0VDgFXvRQe7ETTiKY/SbEY1iXrGInxSCYnv09mWD Obgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Ibd0cQL6; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si10197124pfb.166.2019.01.10.15.50.40; Thu, 10 Jan 2019 15:50:56 -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=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Ibd0cQL6; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731178AbfAJVLf (ORCPT + 99 others); Thu, 10 Jan 2019 16:11:35 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:57260 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731131AbfAJVLX (ORCPT ); Thu, 10 Jan 2019 16:11:23 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0AL9URC041621; Thu, 10 Jan 2019 21:10:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2018-07-02; bh=gX2mJdtpePxKA35+8CzrSsJglZdMj3Uyq1TNFTJ+UG8=; b=Ibd0cQL66/Pb0nDbJsIMNJzyd8kKLoFMvwVPnDYSaUhVHgEfhyU47vuyhyoAQ9k2SP6C StEUBOQgSCvzTnn9h+UDKXfgtPFCWhtlMR0JzkADh9ihDe3FPhKazazVcoo14jbU7XQl K1EjNugwd2s1+zetkMhkcq/FsEe9Yd8W/GJLHPv+EMsOmp07GsbYVXK9615cjbazxiSP XJw0vyBfi7NQZ2wuGAFgjtITMe9DL6AW5g4qS9JAx9bFXnfwm4leU+XamB68ZTlkf+J6 e3SXq2H+Jlus4XUj2W07lFbgFkTlaBZXXkGQsWherXkWrPFagTorX6CU6WYs040aVs5A Fg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2ptm0uhnuh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Jan 2019 21:10:28 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0ALAMv8008733 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Jan 2019 21:10:23 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x0ALAM90022955; Thu, 10 Jan 2019 21:10:22 GMT Received: from concerto.internal (/24.9.64.241) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 10 Jan 2019 13:10:22 -0800 From: Khalid Aziz To: juergh@gmail.com, tycho@tycho.ws, jsteckli@amazon.de, ak@linux.intel.com, torvalds@linux-foundation.org, liran.alon@oracle.com, keescook@google.com, konrad.wilk@oracle.com Cc: Juerg Haefliger , deepa.srinivasan@oracle.com, chris.hyser@oracle.com, tyhicks@canonical.com, dwmw@amazon.co.uk, andrew.cooper3@citrix.com, jcm@redhat.com, boris.ostrovsky@oracle.com, kanth.ghatraju@oracle.com, joao.m.martins@oracle.com, jmattson@google.com, pradeep.vincent@oracle.com, john.haxby@oracle.com, tglx@linutronix.de, kirill.shutemov@linux.intel.com, hch@lst.de, steven.sistare@oracle.com, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Tycho Andersen , Khalid Aziz Subject: [RFC PATCH v7 05/16] arm64/mm: Add support for XPFO Date: Thu, 10 Jan 2019 14:09:37 -0700 Message-Id: <89f03091af87f5ab27bd6cafb032236d5bd81d65.1547153058.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9132 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901100164 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juerg Haefliger Enable support for eXclusive Page Frame Ownership (XPFO) for arm64 and provide a hook for updating a single kernel page table entry (which is required by the generic XPFO code). v6: use flush_tlb_kernel_range() instead of __flush_tlb_one() CC: linux-arm-kernel@lists.infradead.org Signed-off-by: Juerg Haefliger Signed-off-by: Tycho Andersen Signed-off-by: Khalid Aziz --- arch/arm64/Kconfig | 1 + arch/arm64/mm/Makefile | 2 ++ arch/arm64/mm/xpfo.c | 58 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 arch/arm64/mm/xpfo.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index ea2ab0330e3a..f0a9c0007d23 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -171,6 +171,7 @@ config ARM64 select SWIOTLB select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK + select ARCH_SUPPORTS_XPFO help ARM 64-bit (AArch64) Linux support. diff --git a/arch/arm64/mm/Makefile b/arch/arm64/mm/Makefile index 849c1df3d214..cca3808d9776 100644 --- a/arch/arm64/mm/Makefile +++ b/arch/arm64/mm/Makefile @@ -12,3 +12,5 @@ KASAN_SANITIZE_physaddr.o += n obj-$(CONFIG_KASAN) += kasan_init.o KASAN_SANITIZE_kasan_init.o := n + +obj-$(CONFIG_XPFO) += xpfo.o diff --git a/arch/arm64/mm/xpfo.c b/arch/arm64/mm/xpfo.c new file mode 100644 index 000000000000..678e2be848eb --- /dev/null +++ b/arch/arm64/mm/xpfo.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2017 Hewlett Packard Enterprise Development, L.P. + * Copyright (C) 2016 Brown University. All rights reserved. + * + * Authors: + * Juerg Haefliger + * Vasileios P. Kemerlis + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include +#include + +#include + +/* + * Lookup the page table entry for a virtual address and return a pointer to + * the entry. Based on x86 tree. + */ +static pte_t *lookup_address(unsigned long addr) +{ + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + + pgd = pgd_offset_k(addr); + if (pgd_none(*pgd)) + return NULL; + + pud = pud_offset(pgd, addr); + if (pud_none(*pud)) + return NULL; + + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + return NULL; + + return pte_offset_kernel(pmd, addr); +} + +/* Update a single kernel page table entry */ +inline void set_kpte(void *kaddr, struct page *page, pgprot_t prot) +{ + pte_t *pte = lookup_address((unsigned long)kaddr); + + set_pte(pte, pfn_pte(page_to_pfn(page), prot)); +} + +inline void xpfo_flush_kernel_tlb(struct page *page, int order) +{ + unsigned long kaddr = (unsigned long)page_address(page); + unsigned long size = PAGE_SIZE; + + flush_tlb_kernel_range(kaddr, kaddr + (1 << order) * size); +} -- 2.17.1