From patchwork Tue May 22 23:50:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 10419771 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 D177B601E8 for ; Tue, 22 May 2018 23:58:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B07FF28C87 for ; Tue, 22 May 2018 23:58:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E18428DD6; Tue, 22 May 2018 23:58:48 +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 303D428C87 for ; Tue, 22 May 2018 23:58:47 +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: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:In-Reply-To: References:List-Owner; bh=T1WwFWTDIgi9gTSZg+PusKkC3k8DHRi+M3KjGBUG5/E=; b=oVy A+ru+z0Fmo6PnNn5s8gWmWAkJuV2w2o9ygWDPMKWKCHACHZZxTlzFoLNT/MfkqepoKY0qnZwTsfi+ D0Fn7Em7WdfwXxlwCHJIZvnyz3++PQ+oJnmzsGU+trmbqvTGUksQNS8DvXnfpO9YkOaJ6nTKcR2C0 9rDVuDFgDydd60uj0VQXfYEiSu9SCY7QgLqKaHNM+S6+5ghMMB0gCh8H+DLUEC8dooCY8Mu2MQxYa 3FN/jQ/JnoCryTy6fOhVd872qR1WZgyfkftL3S6t6sN2k5ZuO2b4EMXGv4WQ9kcjvRZ0ZpnYr2Yle Le/CFrwch3TXGrJduP5G0yJIr0utCRQ==; 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 1fLHAo-0002Rx-IW; Tue, 22 May 2018 23:58:34 +0000 Received: from mail-oi0-f68.google.com ([209.85.218.68]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLHAk-0002RS-AA for linux-arm-kernel@lists.infradead.org; Tue, 22 May 2018 23:58:32 +0000 Received: by mail-oi0-f68.google.com with SMTP id v2-v6so17880188oif.3 for ; Tue, 22 May 2018 16:58:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=z/L+eBidMXWGcDCiH06VXkfGqQN2oqcQpEamNB+pKcw=; b=rZxM2NbwkgnMKSuvuCUwRZyTMC0cUKoiPJrmbYywFYib2mApbdzibmHLxAqSFsWsjQ ihZO5k9krxkft+1EemTNJmwXwN/pjlxHhHNsucfVLpStCi+p88W3l631t1/63+RZaKRS sHY6pWbnIDKmlEvv9ViqrSd35jU0s1DK3H2n4tKwE9e7zndh14pHnQctzCXsxuGRH5UO FHX5+fHZytKNTDy6CU+uZ8GDLwENYwFlBdbPcCH+DOT+F1HxHuvhJfnaUpz8FmfvLKMo Qr1o2Zofb7VoKZS9n9BZKmpdMhGeOCEGJiKHwfc+bo9MQpK5GzlB63JHJJv3RvmCzp9t hxvA== X-Gm-Message-State: ALKqPwdcsu+tofJD6aXhfFDALtNzj8tisRNuse5yF3X7PQEyBgbMjtlw 3XD4cbzwYKNWA9ls6ZVjVR8twQ== X-Google-Smtp-Source: AB8JxZpVUcfmWo6jFvz9IKnBznak2ufRlys5av1nhrWtFZlhTxFBbcoo21dJs6ykwEWLDMKFW+d2fQ== X-Received: by 2002:aca:a803:: with SMTP id r3-v6mr324360oie.200.1527033077502; Tue, 22 May 2018 16:51:17 -0700 (PDT) Received: from labbott-redhat.redhat.com ([2601:602:9802:a8dc::d2dd]) by smtp.gmail.com with ESMTPSA id o9-v6sm14721631otd.18.2018.05.22.16.51.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 May 2018 16:51:16 -0700 (PDT) From: Laura Abbott To: Catalin Marinas , Will Deacon , Ard Biesheuvel Subject: [PATCH] arm64: Make sure permission updates happen for pmd/pud Date: Tue, 22 May 2018 16:50:49 -0700 Message-Id: <20180522235049.23400-1-labbott@redhat.com> X-Mailer: git-send-email 2.17.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180522_165830_348143_30866555 X-CRM114-Status: GOOD ( 14.14 ) 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: Peter Robinson , Laura Abbott , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Kees Cook 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 Commit 15122ee2c515 ("arm64: Enforce BBM for huge IO/VMAP mappings") disallowed block mappings for ioremap since that code does not honor break-before-make. The same APIs are also used for permission updating though and the extra checks prevent the permission updates from happening, even though this should be permitted. This results in read-only permissions not being fully applied. Visibly, this can occasionaly be seen as a failure on the built in rodata test when the test data ends up in a section or as an odd RW gap on the page table dump. Fix this by keeping the check for the top level p*d_set_huge APIs but using separate functions for the update APIs. Reported-by: Peter Robinson Fixes: 15122ee2c515 ("arm64: Enforce BBM for huge IO/VMAP mappings") Signed-off-by: Laura Abbott --- arch/arm64/mm/mmu.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 2dbb2c9f1ec1..57517ad86910 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -66,6 +66,9 @@ static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss; static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss __maybe_unused; static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss __maybe_unused; +static void __pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot); +static void __pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot); + pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, unsigned long size, pgprot_t vma_prot) { @@ -200,7 +203,7 @@ static void init_pmd(pud_t *pudp, unsigned long addr, unsigned long end, /* try section mapping first */ if (((addr | next | phys) & ~SECTION_MASK) == 0 && (flags & NO_BLOCK_MAPPINGS) == 0) { - pmd_set_huge(pmdp, phys, prot); + __pmd_set_huge(pmdp, phys, prot); /* * After the PMD entry has been populated once, we @@ -299,7 +302,7 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, */ if (use_1G_block(addr, next, phys) && (flags & NO_BLOCK_MAPPINGS) == 0) { - pud_set_huge(pudp, phys, prot); + __pud_set_huge(pudp, phys, prot); /* * After the PUD entry has been populated once, we @@ -929,31 +932,40 @@ int __init arch_ioremap_pmd_supported(void) return 1; } -int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot) +void __pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot) { pgprot_t sect_prot = __pgprot(PUD_TYPE_SECT | pgprot_val(mk_sect_prot(prot))); + BUG_ON(phys & ~PUD_MASK); + set_pud(pudp, pfn_pud(__phys_to_pfn(phys), sect_prot)); +} + +int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot) +{ /* ioremap_page_range doesn't honour BBM */ if (pud_present(READ_ONCE(*pudp))) return 0; - BUG_ON(phys & ~PUD_MASK); - set_pud(pudp, pfn_pud(__phys_to_pfn(phys), sect_prot)); + __pud_set_huge(pudp, phys, prot); return 1; } -int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot) +static void __pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot) { pgprot_t sect_prot = __pgprot(PMD_TYPE_SECT | pgprot_val(mk_sect_prot(prot))); + BUG_ON(phys & ~PMD_MASK); + set_pmd(pmdp, pfn_pmd(__phys_to_pfn(phys), sect_prot)); +} +int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot) +{ /* ioremap_page_range doesn't honour BBM */ if (pmd_present(READ_ONCE(*pmdp))) return 0; - BUG_ON(phys & ~PMD_MASK); - set_pmd(pmdp, pfn_pmd(__phys_to_pfn(phys), sect_prot)); + __pmd_set_huge(pmdp, phys, prot); return 1; }