From patchwork Thu Jul 5 14:08:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Punit Agrawal X-Patchwork-Id: 10509417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 76DA8600F5 for ; Thu, 5 Jul 2018 14:10:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6488129137 for ; Thu, 5 Jul 2018 14:10:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62A002912D; Thu, 5 Jul 2018 14:10:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EE942290F7 for ; Thu, 5 Jul 2018 14:10:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=6quwfs19+WZJdlX8V0BXJfptxwbq3xdvX3UhW42EMQo=; b=l/tYWns5JSUIJnZvOZLu4qj4WI qq4yyC+1ECP7UKQaRflrBmsw1fEaUSNecOOyVqMXuy7URDZ1sekCDOKoI6D21x3M4xew0GOyaAcFv 6P9Ta2bCJ9Vc2uADMf6AyFxG2KEjV1A3oB8CaascikMiGfGjrioKUArSjxCcgD7SXUmqoRXgigIYm UrCbzwRr1TPUtQGvfCkdCDEiTpZowzrMkMHqPn5fuBi7dmoYmZb8MF7wpI24vXmVfBWIQ85Mn60Pm C9LUOR3EOq9XfCGYQVT1sLnd3NdmbdhrfMtnk0hd05COvrxorUu9QT9mggCxu1qACDo7lnCkhmIxp 1lGwmj4A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fb4xj-0002Ky-9h; Thu, 05 Jul 2018 14:10:23 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fb4xS-0001oE-I4 for linux-arm-kernel@bombadil.infradead.org; Thu, 05 Jul 2018 14:10:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=5hFlXDpuE2pWUpA1GAZTmR7qMkvJll1VYQrarAXwsM8=; b=GbWBfn1LESC++XIsGqY2VVkht BI2AmNfiRD4CG2F2wUHYR0ZEHo5sBr8b6kwW9r6xqhxE4I1iaHGI9vXET2yrpENwCaFj2OSSTTSNB ezLiTk2bia3CnxpCi8qGN77thfoBiPmngb9D1OU5THyRxvEzVf9Kkt91bXNpa1wGi6qTskY0LKDt5 Xp8lZNZiBMCg8fYPXXPuAkAuznKdp+orZ+fb9pQOOlojpOHll7rRX/5hnx4IhQFKWiKNHbP6mdV2O Ic5X1cvr/Lu24BndYLUntcsQIbwvaLldwUdhsuQtf7YjSptPvKnTLc4EbngmN5RIqAXUu0cwtlWUg sN0Vd+gfw==; Received: from foss.arm.com ([217.140.101.70]) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fb4xM-00088h-IF for linux-arm-kernel@lists.infradead.org; Thu, 05 Jul 2018 14:10:04 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 940F780D; Thu, 5 Jul 2018 07:09:43 -0700 (PDT) Received: from localhost (e105922-lin.cambridge.arm.com [10.1.206.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 157F33F5BA; Thu, 5 Jul 2018 07:09:42 -0700 (PDT) From: Punit Agrawal To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v4 4/7] KVM: arm64: Support PUD hugepage in stage2_is_exec() Date: Thu, 5 Jul 2018 15:08:47 +0100 Message-Id: <20180705140850.5801-5-punit.agrawal@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180705140850.5801-1-punit.agrawal@arm.com> References: <20180705140850.5801-1-punit.agrawal@arm.com> X-ARM-No-Footer: FoSSMail X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180705_101000_874026_CCF7F631 X-CRM114-Status: GOOD ( 16.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, marc.zyngier@arm.com, Catalin Marinas , Punit Agrawal , Will Deacon , christoffer.dall@arm.com, linux-kernel@vger.kernel.org, Russell King , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In preparation for creating PUD hugepages at stage 2, add support for detecting execute permissions on PUD page table entries. Faults due to lack of execute permissions on page table entries is used to perform i-cache invalidation on first execute. Provide trivial implementations of arm32 helpers to allow sharing of code. Signed-off-by: Punit Agrawal Cc: Christoffer Dall Cc: Marc Zyngier Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon --- arch/arm/include/asm/kvm_mmu.h | 6 ++++++ arch/arm64/include/asm/kvm_mmu.h | 5 +++++ arch/arm64/include/asm/pgtable-hwdef.h | 2 ++ virt/kvm/arm/mmu.c | 10 +++++++++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index c23722f75d5c..d05c8986e495 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -96,6 +96,12 @@ static inline bool kvm_s2pud_readonly(pud_t *pud) } +static inline bool kvm_s2pud_exec(pud_t *pud) +{ + BUG(); + return false; +} + static inline void kvm_set_pmd(pmd_t *pmd, pmd_t new_pmd) { *pmd = new_pmd; diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 84051930ddfe..15bc1be8f82f 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -249,6 +249,11 @@ static inline bool kvm_s2pud_readonly(pud_t *pudp) return kvm_s2pte_readonly((pte_t *)pudp); } +static inline bool kvm_s2pud_exec(pud_t *pudp) +{ + return !(READ_ONCE(pud_val(*pudp)) & PUD_S2_XN); +} + static inline bool kvm_page_empty(void *ptr) { struct page *ptr_page = virt_to_page(ptr); diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index fd208eac9f2a..10ae592b78b8 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -193,6 +193,8 @@ #define PMD_S2_RDWR (_AT(pmdval_t, 3) << 6) /* HAP[2:1] */ #define PMD_S2_XN (_AT(pmdval_t, 2) << 53) /* XN[1:0] */ +#define PUD_S2_XN (_AT(pudval_t, 2) << 53) /* XN[1:0] */ + /* * Memory Attribute override for Stage-2 (MemAttr[3:0]) */ diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index db04b18218c1..ccdea0edabb3 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1040,10 +1040,18 @@ static int stage2_set_pmd_huge(struct kvm *kvm, struct kvm_mmu_memory_cache static bool stage2_is_exec(struct kvm *kvm, phys_addr_t addr) { + pud_t *pudp; pmd_t *pmdp; pte_t *ptep; - pmdp = stage2_get_pmd(kvm, NULL, addr); + pudp = stage2_get_pud(kvm, NULL, addr); + if (!pudp || pud_none(*pudp) || !pud_present(*pudp)) + return false; + + if (pud_huge(*pudp)) + return kvm_s2pud_exec(pudp); + + pmdp = stage2_pmd_offset(pudp, addr); if (!pmdp || pmd_none(*pmdp) || !pmd_present(*pmdp)) return false;