Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3982053imj; Tue, 12 Feb 2019 07:55:21 -0800 (PST) X-Google-Smtp-Source: AHgI3IbsGTqglXPqaa8mXbS671kq/X4E1//QXAx1U80xgNzfgzRxbFxmxr3XMdcdi8/CeoyOeYJi X-Received: by 2002:a62:35c7:: with SMTP id c190mr4743057pfa.76.1549986921127; Tue, 12 Feb 2019 07:55:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549986921; cv=none; d=google.com; s=arc-20160816; b=ofAEg2n2goHOZoB6PU0786lH4HTy2WJZHblhakY5Cw+l9WjVix4OjH9W97rFkA4Eqp KsqrC3FRcF3/urdwZsdRLNcWOjgrVoqTqj+/9pV5ZEe9VRQHbPFO6K6+ByB5SC3+tiyW DzlCMQzUB/gazoPh0Qzi/apPJkeecvVcTGfqCjy3jVuTPXaP0cALvSRisJnLw23ikPQ+ WwJGJcxA9TSN4NKoX9CC8ohvYt53yzVF8WsOMOH08fDI51W5oOEGZOgcDBK+UL5h+04V teMbEKIQ05r3nNLPRcyBNi2Ou2qM5bQEheqx4nTKjLJ1SIZFj02Q7r3ErjCbgyG0nJJW CIqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:in-reply-to:mime-version :user-agent:date:message-id:organization:from:references:cc:to :subject:dkim-signature; bh=byLhuTWcAJtsD+8gN5cbHsUplgXHJ5TjR9BbBHliQDY=; b=uHdAo+Xg+Isq8bP8r/YuOXXHD2ZzZ2qg3DTC469jw2m2bI52PlDjRF+NhBNYCzR/fi 8p00ZdfgEFFgkrcK6/DZcsZabLCvQ4nrmspsdONxKb7/OR5/RA5ejIQbScOaLlO9KixT kSAEoVlh3ELbzXCCOkHAUND9XPPaAxyS+bl4z1ruBj28tYCdu/0FCH7IjzHW4KCcxuu4 QA/6o71cfl72wzM3xMGLvYCAZNL0rLHEjB0G7VfDV82S3ebq9eCQuAK/b/cEnvuiBg18 dzE2lITKF3hx8crwww7grElBKB/iXJ4h7hE6cMloRwlea01o7bFd+wrntMEwrqQLW55Q E+Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=wcoAN6Vm; 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 a12si12404141pgk.291.2019.02.12.07.55.04; Tue, 12 Feb 2019 07:55:21 -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=wcoAN6Vm; 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 S1730675AbfBLPyw (ORCPT + 99 others); Tue, 12 Feb 2019 10:54:52 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:54106 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728347AbfBLPyv (ORCPT ); Tue, 12 Feb 2019 10:54:51 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1CFn7Hi093071; Tue, 12 Feb 2019 15:52:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type; s=corp-2018-07-02; bh=byLhuTWcAJtsD+8gN5cbHsUplgXHJ5TjR9BbBHliQDY=; b=wcoAN6Vmo2y18k2tcw0tBVfKea4IGHuY3FK8HEZhfNhCzsfckC6V94Vzr+ZewIt+MpGQ nc8gIJANFXP/n4+kExJYa2Kr6jpsc4vf1RVR/MD0VWtruSTKmhvvXhwJ5+bUlQUT91zh S2YaKMEyuY9lPBRgjlqZIR12LUsNtv9yO9AB1NYgK5JstyppWaIws+o6YUMZX9dsCm96 ZoFWqbNRQmg7bAPK9TWF1VzpWsrHGVt6bbS8pnXi7S6ze7xhW38YenwqrwdOPvoHwZPG J+iTsqlWY6dszf7Te/iANEQg7brXIVZMcQCG5NjzoW7oItcRRXwAG9MHWJxAENRorMJB Wg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2qhrekcry6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Feb 2019 15:52:57 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x1CFquPt031138 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Feb 2019 15:52:56 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x1CFqsMl011172; Tue, 12 Feb 2019 15:52:55 GMT Received: from [192.168.1.16] (/24.9.64.241) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 12 Feb 2019 07:52:54 -0800 Subject: Re: [RFC PATCH v7 05/16] arm64/mm: Add support for XPFO To: Konrad Rzeszutek Wilk 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 References: <89f03091af87f5ab27bd6cafb032236d5bd81d65.1547153058.git.khalid.aziz@oracle.com> <20190123142410.GC19289@Konrads-MacBook-Pro.local> From: Khalid Aziz Organization: Oracle Corp Message-ID: <4dfba458-1bf6-25ff-df4c-b96a1221cd95@oracle.com> Date: Tue, 12 Feb 2019 08:52:51 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190123142410.GC19289@Konrads-MacBook-Pro.local> Content-Type: multipart/mixed; boundary="------------E60D98927E4F6B22818A3147" Content-Language: en-US X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9165 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902120112 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. --------------E60D98927E4F6B22818A3147 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 1/23/19 7:24 AM, Konrad Rzeszutek Wilk wrote: > 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. >> =20 >> 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 +=3D n >> =20 >> obj-$(CONFIG_KASAN) +=3D kasan_init.o >> KASAN_SANITIZE_kasan_init.o :=3D n >> + >> +obj-$(CONFIG_XPFO) +=3D 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 modi= fy it >> + * under the terms of the GNU General Public License version 2 as pub= lished by >> + * the Free Software Foundation. >> + */ >> + >> +#include >> +#include >> + >> +#include >> + >> +/* >> + * Lookup the page table entry for a virtual address and return a poi= nter 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 =3D pgd_offset_k(addr); >> + if (pgd_none(*pgd)) >> + return NULL; >> + >> + pud =3D pud_offset(pgd, addr); >> + if (pud_none(*pud)) >> + return NULL; >> + >> + pmd =3D 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 =3D lookup_address((unsigned long)kaddr); >> + >> + set_pte(pte, pfn_pte(page_to_pfn(page), prot)); >=20 > Thought on the other hand.. what if the page is PMD? Do you really want= > to do this? >=20 > What if 'pte' is NULL? >> +} >> + >> +inline void xpfo_flush_kernel_tlb(struct page *page, int order) >> +{ >> + unsigned long kaddr =3D (unsigned long)page_address(page); >> + unsigned long size =3D PAGE_SIZE; >> + >> + flush_tlb_kernel_range(kaddr, kaddr + (1 << order) * size); >=20 > Ditto here. You are assuming it is PTE, but it may be PMD or such. > Or worts - the lookup_address could be NULL. >=20 >> +} >> --=20 >> 2.17.1 >> Hi Konrad, This makes sense. x86 version of set_kpte() checks pte for NULL and also checks if the page is PMD. Now what you said about adding level to lookup_address() for arm makes more sense. Can someone with knowledge of arm64 mmu make recommendations here? Thanks, Khalid --------------E60D98927E4F6B22818A3147 Content-Type: application/pgp-keys; name="pEpkey.asc" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pEpkey.asc" -----BEGIN PGP PUBLIC KEY BLOCK----- mQGNBFwdSxMBDACs4wtsihnZ9TVeZBZYPzcj1sl7hz41PYvHKAq8FfBOl4yC6ghp U0FDo3h8R7ze0VG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