Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp830238imu; Wed, 23 Jan 2019 06:28:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN6J9uvZnGHDATzzSrnLCqkRxZUbPGC4RaY1xVpKasDRHv/fT4P+zCi5yyDILJBlSw0V+cnb X-Received: by 2002:a63:70c:: with SMTP id 12mr2085194pgh.352.1548253689656; Wed, 23 Jan 2019 06:28:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548253689; cv=none; d=google.com; s=arc-20160816; b=wu3cBGPC+Y4sOHg/Fc2I4t3EdlzWZ7hughqS+OI0yAD0G7L71N9ALVUsgxRQOiRPLv 1f056hnV+EYSEY2wueVXb6/5z80HZpgPS0HIuwc7da4EdeFGgK2tYO4HWyEgYhPjaoGG wkLxbeD1Ddl7gsU+BOke7RU4uB9YsEQn5IirYl5WE5QxCFaeB3a9F3mBvlWppgxaGgHE WxBkvilyiHpCFZvhYzABqOsemkADc4Z70RiAxaljaumRKa6lsohMC/xD7EaOwn/jpMeU VsWd/OtiM33I6731pHgoWfwE1wMB3dtOg1ls4wioM85UMEmesoLkoBV/f6CDogJB2jY9 erSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=3/BHDXBDjwaMslYodL58H902nHYtHgdrjeSHAL9Rim4=; b=zKbkdBm6MJZ4t8cgkTMkCSasRNSl+N+ez9xPntJcPcuF/zoLNcioBbpPgOOBIC2cQw tadDaTTyoRXz0U3UOrqmLK14lEOcZRUByx4Bq0FKtjmPeg4GHXn5C6UeqipKNy1jq+Y+ jx/shiV7mHGaqxkpn+ds5GKanDK4srXtVlBL83ClGe1VdpHW/gB+0Lg6sM3DSEOi0exD a5EUCQ+FJXXCDCQdqctbFhrIF4K6wicC202zt5Bmq02ta+kUhUR4DrnyArqLVveJnL4o r3f7mP4ScRoLBqiLpqdjBxfWQcHPmi6ikTYGkhAdvdlCa7yXcfAQQDshBp4IZEkdUkN+ VYGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=tQ50ZO0m; 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 h68si18508723plb.375.2019.01.23.06.27.54; Wed, 23 Jan 2019 06:28:09 -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=tQ50ZO0m; 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 S1727146AbfAWO0I (ORCPT + 99 others); Wed, 23 Jan 2019 09:26:08 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:36432 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726818AbfAWO0I (ORCPT ); Wed, 23 Jan 2019 09:26:08 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0NEO5Bj058309; Wed, 23 Jan 2019 14:25:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=3/BHDXBDjwaMslYodL58H902nHYtHgdrjeSHAL9Rim4=; b=tQ50ZO0mMFU/r47bPEQw09c+k8zRY002JWSjxdoFz6jjfI2kVAe4dtv/Oa9NMJ3LNuJA gfKMxVe0/l67rEURRsAA7nMGmQFg1affh+xbZs1Z23E/FsDe3lrb59pgZsu4deTnt2x3 H9lMuiHBKZWm1uU3k+oWUfumK5HLfchyj6ZsuFCp66e/DEygmkvc0ieRfH8CnPMn9J68 IPWyPOeb2tvs2g7AXVFOu2uilgkqGXcwul1xpzCXlzYIWnWqx8nMf+RAogbiTzZ6OrqH qoXHgRb8QtRllcVjNZb/Wyi21NztmuUommixCTz9WTbS2KsdYXkY+ojtTyEjKnrWzKN4 EQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2q3sdej9fe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Jan 2019 14:25:15 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0NEP9f5017026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Jan 2019 14:25:09 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x0NEP6wA014770; Wed, 23 Jan 2019 14:25:06 GMT Received: from Konrads-MacBook-Pro.local (/75.104.64.133) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 23 Jan 2019 06:25:05 -0800 Date: Wed, 23 Jan 2019 09:24:13 -0500 From: Konrad Rzeszutek Wilk To: Khalid Aziz Cc: juergh@gmail.com, tycho@tycho.ws, jsteckli@amazon.de, ak@linux.intel.com, torvalds@linux-foundation.org, liran.alon@oracle.com, keescook@google.com, 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 Subject: Re: [RFC PATCH v7 05/16] arm64/mm: Add support for XPFO Message-ID: <20190123142410.GC19289@Konrads-MacBook-Pro.local> References: <89f03091af87f5ab27bd6cafb032236d5bd81d65.1547153058.git.khalid.aziz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <89f03091af87f5ab27bd6cafb032236d5bd81d65.1547153058.git.khalid.aziz@oracle.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9144 signatures=668682 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-1901230108 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 10, 2019 at 02:09:37PM -0700, Khalid Aziz wrote: > 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)); Thought on the other hand.. what if the page is PMD? Do you really want to do this? What if 'pte' is NULL? > +} > + > +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); Ditto here. You are assuming it is PTE, but it may be PMD or such. Or worts - the lookup_address could be NULL. > +} > -- > 2.17.1 >