From patchwork Sat Apr 10 09:56:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 12195555 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=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 B68E2C433ED for ; Sat, 10 Apr 2021 10:00:38 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 55C9861001 for ; Sat, 10 Apr 2021 10:00:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55C9861001 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=66k47o0H/P9/dE4VyqRVZHLcT5BgzDdnr5R2qWw8Z2Q=; b=EAx8pUYhgRrP2nc7+5k8PQ/gR 9gu9aZsJOOC5IN4KKJ/ZsP8HfkihzGw8VzYNMNDp6XN09POd0b7PYM8+qBFWKGBpA1DGnYMKL7J+N cMC7koRvpcTFRAXg+qnRhOTQevnKQE443ey/QD7qbrNhfWW7P0wy1R2QGudRQy/u2DNYTgbCWYbWI RTKVMqLRej7yqG1mQBxvfjjt2TPPd2JQcmsa6ggWgNMxSlbNLhDQoTvbCyfbKtbEndfKxnX4ZywCF 8J6OGG3IJvKAO4EiAD1W1Vz2FeQdBonU9giKZOMX24Y1diqMmCVMRhOuycWrAo00ox4dQywPvUcjC O5u2JaAwQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lVANv-002bdU-Ui; Sat, 10 Apr 2021 09:58:36 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lVAN1-002bRK-Gf for linux-arm-kernel@desiato.infradead.org; Sat, 10 Apr 2021 09:57:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=ebzxZEiBIG4H4lXdCyPtungiZLvBTkaali2R4+XSI1E=; b=HmV5xQrRf8JXSf7qsnZjG+41+S eQB5zPKK/Df3nAD3bNutZSbR+6WRzNrDwSQmSt4BN2G0hGIeUheNVVJeAZVbpm7VcKc5fH9u/3C6W zbahSze8CGOYvZAV5wyLkpdvOBk8P/etQVsSRwYNiSpmoFd0gMfIH3DzpFT1NRr1r4U/sPqYDBhx6 7qSv+2WpZGywZuDG8VGVDug0BcMpJYaB5iAODZu4gmvQIW3PX5XxSVjx1QISJQ2MZ2lckZWdkV8XP gRYYTUjYZHyqgEmiStPgcSffn+Mw7yCc4eCQnzFJKFG1YtkjyJAIxa/nOVVeeoi3cH3qO2S56iw7A JdzWm7Kg==; Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lVAMy-0051Zn-VE for linux-arm-kernel@lists.infradead.org; Sat, 10 Apr 2021 09:57:38 +0000 Received: by mail-pj1-x102b.google.com with SMTP id ot17-20020a17090b3b51b0290109c9ac3c34so6187178pjb.4 for ; Sat, 10 Apr 2021 02:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ebzxZEiBIG4H4lXdCyPtungiZLvBTkaali2R4+XSI1E=; b=Fh+13w75g3g8mU6JGXclOI+3G/txBOJkK3A3GlhwlmVzSqj6wQwJDtPZ3gCsWnmoMV 2xi9vxd5A1XIEdSB5n5Ekpva6ge3w9lo6SYuxAXlPMdYWowrx6aKVxDEhJGCrM8fsFSK QK7tg+MbPv3dfmpwmNsp4xjb+OqdqBtOQzdbmmIy1vhrnEhGFcSwdfnHTFDo8ImNZZSO SNAzbBYBX595POok74qhtjscAIPZrlBv3LZzVGhGS1KatTwbBgBHz5ftYCXGhEXajQY0 duMs8NgGxx6Mhijl3QbLsGGErAkkTwEgH8nu3Hd/YFg9jzwnhLtDYdJx2emrZaV1MCN2 yfwA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=ebzxZEiBIG4H4lXdCyPtungiZLvBTkaali2R4+XSI1E=; b=GwaU3VTsDOElbdcaieo33PQhg3tEtN4pqVXVhfNt4FK594P6FUmR9wGHch3wPcBbM8 acaebe7vl149dxuUbw3RIoIfdobpctOGUxvOI56vX5gYc1MSwvBuLqwcxIX7oHdvyJHm LbVaCkZraX1xDxEVMhTw55qAVcxYTtLOXjwLMpkh3wX8Ir4CwQeBBZycDAgqT/AEN91i /VhwboWQNMoiZu/jr0lfuyMIATH6zhkiAyoOsiKXXltkTEbq/Jm0xlQkRfx+edECEFTi g7B7EITnWGEJwHU3xnNU5VIR+wnJnS0isxuJVju6F4LN7NpKwTcDwMHbTdXDIvcBtCUs 0tMw== X-Gm-Message-State: AOAM5306epbYz3qdtqrMVqSCbrCPQNoYf/OyrmZ3lo26DSL/cy16f38W VqvJMSlaecEISF7kIR40+CD/9QRm69Vc X-Google-Smtp-Source: ABdhPJxnr7uMB5MKBnBuAWtsS2Acp+r7BDqCchInppccITVVYuezEPXRijon5dR7ErDjn6WhtOepug== X-Received: by 2002:a17:903:22c2:b029:ea:b40b:7f88 with SMTP id y2-20020a17090322c2b02900eab40b7f88mr4322891plg.61.1618048656036; Sat, 10 Apr 2021 02:57:36 -0700 (PDT) Received: from x1pad.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m14sm3836322pfh.89.2021.04.10.02.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Apr 2021 02:57:35 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org Cc: Pingfan Liu , Catalin Marinas , Will Deacon , Marc Zyngier , Kristina Martsenko , James Morse , Steven Price , Jonathan Cameron , Pavel Tatashin , Anshuman Khandual , Atish Patra , Mike Rapoport , Logan Gunthorpe , Mark Brown Subject: [RFC 5/8] arm64/mm: make trans_pgd_idmap_page() use create_idmap() Date: Sat, 10 Apr 2021 17:56:51 +0800 Message-Id: <20210410095654.24102-6-kernelfans@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210410095654.24102-1-kernelfans@gmail.com> References: <20210410095654.24102-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210410_025737_025489_E7B4BA18 X-CRM114-Status: GOOD ( 14.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org At present, trans_pgd_idmap_page() has its own logic to set up idmap. To make code simple, it can reuse create_idmap(). Signed-off-by: Pingfan Liu Cc: Catalin Marinas Cc: Will Deacon Cc: Marc Zyngier Cc: Kristina Martsenko Cc: James Morse Cc: Steven Price Cc: Jonathan Cameron Cc: Pavel Tatashin Cc: Anshuman Khandual Cc: Atish Patra Cc: Mike Rapoport Cc: Logan Gunthorpe Cc: Mark Brown To: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/pgalloc.h | 9 +++++ arch/arm64/mm/trans_pgd.c | 59 +++++++++++++++----------------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h index 6e9f1e218300..f848a0300228 100644 --- a/arch/arm64/include/asm/pgalloc.h +++ b/arch/arm64/include/asm/pgalloc.h @@ -93,6 +93,15 @@ extern void __create_pgd_mapping_extend(pgd_t *pgdir, void *info, int flags); +extern int idmap_extend_pgtable; + +extern void create_idmap(pgd_t *pgdir, phys_addr_t phys, + phys_addr_t size, + pgprot_t prot, + pgtable_alloc allocator, + void *info, + int flags); + #define NO_BLOCK_MAPPINGS BIT(0) #define NO_CONT_MAPPINGS BIT(1) #define NO_FIXMAP BIT(2) diff --git a/arch/arm64/mm/trans_pgd.c b/arch/arm64/mm/trans_pgd.c index 527f0a39c3da..004ccbadd647 100644 --- a/arch/arm64/mm/trans_pgd.c +++ b/arch/arm64/mm/trans_pgd.c @@ -274,6 +274,14 @@ int trans_pgd_map_page(struct trans_pgd_info *info, pgd_t *trans_pgd, return 0; } +static unsigned long allocator_trans_alloc(unsigned long unused, void *info) +{ + unsigned long *p; + + p = trans_alloc(info); + return (unsigned long)p; +} + /* * The page we want to idmap may be outside the range covered by VA_BITS that * can be built using the kernel's p?d_populate() helpers. As a one off, for a @@ -287,38 +295,25 @@ int trans_pgd_map_page(struct trans_pgd_info *info, pgd_t *trans_pgd, int trans_pgd_idmap_page(struct trans_pgd_info *info, phys_addr_t *trans_ttbr0, unsigned long *t0sz, void *page) { - phys_addr_t dst_addr = virt_to_phys(page); - unsigned long pfn = __phys_to_pfn(dst_addr); - int max_msb = (dst_addr & GENMASK(52, 48)) ? 51 : 47; - int bits_mapped = PAGE_SHIFT - 4; - unsigned long level_mask, prev_level_entry, *levels[4]; - int this_level, index, level_lsb, level_msb; - - dst_addr &= PAGE_MASK; - prev_level_entry = pte_val(pfn_pte(pfn, PAGE_KERNEL_EXEC)); - - for (this_level = 3; this_level >= 0; this_level--) { - levels[this_level] = trans_alloc(info); - if (!levels[this_level]) - return -ENOMEM; - - level_lsb = ARM64_HW_PGTABLE_LEVEL_SHIFT(this_level); - level_msb = min(level_lsb + bits_mapped, max_msb); - level_mask = GENMASK_ULL(level_msb, level_lsb); - - index = (dst_addr & level_mask) >> level_lsb; - *(levels[this_level] + index) = prev_level_entry; - - pfn = virt_to_pfn(levels[this_level]); - prev_level_entry = pte_val(pfn_pte(pfn, - __pgprot(PMD_TYPE_TABLE))); - - if (level_msb == max_msb) - break; - } - - *trans_ttbr0 = phys_to_ttbr(__pfn_to_phys(pfn)); - *t0sz = TCR_T0SZ(max_msb + 1); + pgd_t * pgdir = trans_alloc(info); + int flags = NO_FIXMAP; + unsigned long base, step, level, va_bits; + +#ifdef CONFIG_ARM64_64K_PAGES + base = 16; + step = 13; +#elif CONFIG_ARM64_4K_PAGES + base = 12; + step = 9; +#endif + create_idmap(pgdir, virt_to_phys(page), PAGE_SIZE, PAGE_KERNEL_EXEC, + allocator_trans_alloc, info, flags); + + *trans_ttbr0 = phys_to_ttbr(__virt_to_phys(pgdir)); + level = CONFIG_PGTABLE_LEVELS + idmap_extend_pgtable ? 1 : 0; + va_bits = base + step * level; + va_bits = min(va_bits, vabits_actual); + *t0sz = 64 - va_bits; return 0; }