From patchwork Tue Nov 10 18:09:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikos Nikoleris X-Patchwork-Id: 11894999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 868F8C388F7 for ; Tue, 10 Nov 2020 18:09:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48F8120797 for ; Tue, 10 Nov 2020 18:09:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730468AbgKJSJx (ORCPT ); Tue, 10 Nov 2020 13:09:53 -0500 Received: from foss.arm.com ([217.140.110.172]:59518 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726152AbgKJSJx (ORCPT ); Tue, 10 Nov 2020 13:09:53 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AA620139F; Tue, 10 Nov 2020 10:09:52 -0800 (PST) Received: from camtx2.cambridge.arm.com (camtx2.cambridge.arm.com [10.1.7.22]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 841D03F7BB; Tue, 10 Nov 2020 10:09:51 -0800 (PST) From: Nikos Nikoleris To: kvm@vger.kernel.org Cc: mark.rutland@arm.com, jade.alglave@arm.com, luc.maranget@inria.fr, andre.przywara@arm.com, alexandru.elisei@arm.com, drjones@redhat.com, Luc Maranget Subject: [kvm-unit-tests PATCH v3 1/2] arm: Add mmu_get_pte() to the MMU API Date: Tue, 10 Nov 2020 18:09:23 +0000 Message-Id: <20201110180924.95106-2-nikos.nikoleris@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201110180924.95106-1-nikos.nikoleris@arm.com> References: <20201110180924.95106-1-nikos.nikoleris@arm.com> X-ARM-No-Footer: FoSSMail Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Luc Maranget Add the mmu_get_pte() function that allows a test to get a pointer to the PTE for a valid virtual address. Return NULL if the MMU is off. Signed-off-by: Nikos Nikoleris Signed-off-by: Luc Maranget Co-Developed-by: Nikos Nikoleris Reviewed-by: Andrew Jones Reviewed-by: Alexandru Elisei --- lib/arm/asm/mmu-api.h | 1 + lib/arm/mmu.c | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/arm/asm/mmu-api.h b/lib/arm/asm/mmu-api.h index 2bbe1fa..3d04d03 100644 --- a/lib/arm/asm/mmu-api.h +++ b/lib/arm/asm/mmu-api.h @@ -22,5 +22,6 @@ extern void mmu_set_range_sect(pgd_t *pgtable, uintptr_t virt_offset, extern void mmu_set_range_ptes(pgd_t *pgtable, uintptr_t virt_offset, phys_addr_t phys_start, phys_addr_t phys_end, pgprot_t prot); +extern pteval_t *mmu_get_pte(pgd_t *pgtable, uintptr_t vaddr); extern void mmu_clear_user(pgd_t *pgtable, unsigned long vaddr); #endif diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c index d937f20..a1862a5 100644 --- a/lib/arm/mmu.c +++ b/lib/arm/mmu.c @@ -212,7 +212,13 @@ unsigned long __phys_to_virt(phys_addr_t addr) return addr; } -void mmu_clear_user(pgd_t *pgtable, unsigned long vaddr) +/* + * NOTE: The Arm architecture might require the use of a + * break-before-make sequence before making changes to a PTE and + * certain conditions are met (see Arm ARM D5-2669 for AArch64 and + * B3-1378 for AArch32 for more details). + */ +pteval_t *mmu_get_pte(pgd_t *pgtable, uintptr_t vaddr) { pgd_t *pgd; pud_t *pud; @@ -220,7 +226,7 @@ void mmu_clear_user(pgd_t *pgtable, unsigned long vaddr) pte_t *pte; if (!mmu_enabled()) - return; + return NULL; pgd = pgd_offset(pgtable, vaddr); assert(pgd_valid(*pgd)); @@ -229,17 +235,21 @@ void mmu_clear_user(pgd_t *pgtable, unsigned long vaddr) pmd = pmd_offset(pud, vaddr); assert(pmd_valid(*pmd)); - if (pmd_huge(*pmd)) { - pmd_t entry = __pmd(pmd_val(*pmd) & ~PMD_SECT_USER); - WRITE_ONCE(*pmd, entry); - goto out_flush_tlb; - } + if (pmd_huge(*pmd)) + return &pmd_val(*pmd); pte = pte_offset(pmd, vaddr); assert(pte_valid(*pte)); - pte_t entry = __pte(pte_val(*pte) & ~PTE_USER); - WRITE_ONCE(*pte, entry); -out_flush_tlb: - flush_tlb_page(vaddr); + return &pte_val(*pte); +} + +void mmu_clear_user(pgd_t *pgtable, unsigned long vaddr) +{ + pteval_t *p_pte = mmu_get_pte(pgtable, vaddr); + if (p_pte) { + pteval_t entry = *p_pte & ~PTE_USER; + WRITE_ONCE(*p_pte, entry); + flush_tlb_page(vaddr); + } } From patchwork Tue Nov 10 18:09:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikos Nikoleris X-Patchwork-Id: 11895001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E11CC4741F for ; Tue, 10 Nov 2020 18:10:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2809C20797 for ; Tue, 10 Nov 2020 18:10:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730786AbgKJSJ7 (ORCPT ); Tue, 10 Nov 2020 13:09:59 -0500 Received: from foss.arm.com ([217.140.110.172]:59528 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730705AbgKJSJ7 (ORCPT ); Tue, 10 Nov 2020 13:09:59 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 98F721063; Tue, 10 Nov 2020 10:09:58 -0800 (PST) Received: from camtx2.cambridge.arm.com (camtx2.cambridge.arm.com [10.1.7.22]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 993E83F7BB; Tue, 10 Nov 2020 10:09:57 -0800 (PST) From: Nikos Nikoleris To: kvm@vger.kernel.org Cc: mark.rutland@arm.com, jade.alglave@arm.com, luc.maranget@inria.fr, andre.przywara@arm.com, alexandru.elisei@arm.com, drjones@redhat.com Subject: [kvm-unit-tests PATCH v3 2/2] arm: Add support for the DEVICE_nGRE and NORMAL_WT memory types Date: Tue, 10 Nov 2020 18:09:24 +0000 Message-Id: <20201110180924.95106-3-nikos.nikoleris@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201110180924.95106-1-nikos.nikoleris@arm.com> References: <20201110180924.95106-1-nikos.nikoleris@arm.com> X-ARM-No-Footer: FoSSMail Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Nikos Nikoleris Reviewed-by: Andrew Jones Reviewed-by: Alexandru Elisei --- lib/arm64/asm/pgtable-hwdef.h | 2 ++ arm/cstart64.S | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/arm64/asm/pgtable-hwdef.h b/lib/arm64/asm/pgtable-hwdef.h index c31bc11..48a1d1a 100644 --- a/lib/arm64/asm/pgtable-hwdef.h +++ b/lib/arm64/asm/pgtable-hwdef.h @@ -153,5 +153,7 @@ #define MT_DEVICE_GRE 2 #define MT_NORMAL_NC 3 /* writecombine */ #define MT_NORMAL 4 +#define MT_NORMAL_WT 5 +#define MT_DEVICE_nGRE 6 #endif /* _ASMARM64_PGTABLE_HWDEF_H_ */ diff --git a/arm/cstart64.S b/arm/cstart64.S index 6610779..0428014 100644 --- a/arm/cstart64.S +++ b/arm/cstart64.S @@ -154,6 +154,8 @@ halt: * DEVICE_GRE 010 00001100 * NORMAL_NC 011 01000100 * NORMAL 100 11111111 + * NORMAL_WT 101 10111011 + * DEVICE_nGRE 110 00001000 */ #define MAIR(attr, mt) ((attr) << ((mt) * 8)) @@ -184,7 +186,9 @@ asm_mmu_enable: MAIR(0x04, MT_DEVICE_nGnRE) | \ MAIR(0x0c, MT_DEVICE_GRE) | \ MAIR(0x44, MT_NORMAL_NC) | \ - MAIR(0xff, MT_NORMAL) + MAIR(0xff, MT_NORMAL) | \ + MAIR(0xbb, MT_NORMAL_WT) | \ + MAIR(0x08, MT_DEVICE_nGRE) msr mair_el1, x1 /* TTBR0 */