From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90A3AC433EF for ; Wed, 13 Apr 2022 16:53:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235569AbiDMQ4G (ORCPT ); Wed, 13 Apr 2022 12:56:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbiDMQ4F (ORCPT ); Wed, 13 Apr 2022 12:56:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6C5D68301 for ; Wed, 13 Apr 2022 09:53:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4D70D61E71 for ; Wed, 13 Apr 2022 16:53:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B77CBC385A3; Wed, 13 Apr 2022 16:53:41 +0000 (UTC) Date: Wed, 13 Apr 2022 17:53:38 +0100 From: Catalin Marinas To: Guanghui Feng Cc: will@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, baolin.wang@linux.alibaba.com Subject: Re: [PATCH RFC v1] arm64: mm: change mem_map to use block/section mapping with crashkernel Message-ID: References: <1649754476-8713-1-git-send-email-guanghuifeng@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1649754476-8713-1-git-send-email-guanghuifeng@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 12, 2022 at 05:07:56PM +0800, Guanghui Feng wrote: > There are many changes and discussions: > commit 031495635b46 > commit 1a8e1cef7603 > commit 8424ecdde7df > commit 0a30c53573b0 > commit 2687275a5843 > > When using DMA/DMA32 zone and crashkernel, disable rodata full and kfence, > mem_map will use non block/section mapping(for crashkernel requires to shrink > the region in page granularity). But it will degrade performance when doing > larging continuous mem access in kernel(memcpy/memmove, etc). > > This patch firstly do block/section mapping at mem_map, reserve crashkernel > memory. And then walking pagetable to split block/section mapping > to non block/section mapping [only] for crashkernel mem. We will accelerate > mem access about 10-20% performance improvement, and reduce the cpu dTLB miss > conspicuously on some platform with this optimization. Do you actually have some real world use-cases where this improvement matters? I don't deny that large memcpy over the kernel linear map may be slightly faster but where does this really matter? > +static void init_crashkernel_pmd(pud_t *pudp, unsigned long addr, > + unsigned long end, phys_addr_t phys, > + pgprot_t prot, > + phys_addr_t (*pgtable_alloc)(int), int flags) > +{ > + phys_addr_t map_offset; > + unsigned long next; > + pmd_t *pmdp; > + pmdval_t pmdval; > + > + pmdp = pmd_offset(pudp, addr); > + do { > + next = pmd_addr_end(addr, end); > + if (!pmd_none(*pmdp) && pmd_sect(*pmdp)) { > + phys_addr_t pte_phys = pgtable_alloc(PAGE_SHIFT); > + pmd_clear(pmdp); > + pmdval = PMD_TYPE_TABLE | PMD_TABLE_UXN; > + if (flags & NO_EXEC_MAPPINGS) > + pmdval |= PMD_TABLE_PXN; > + __pmd_populate(pmdp, pte_phys, pmdval); > + flush_tlb_kernel_range(addr, addr + PAGE_SIZE); The architecture requires us to do a break-before-make here, so pmd_clear(), TLBI, __pmd_populate() - in this order. And that's where it gets tricky, if the kernel happens to access this pmd range while it is unmapped, you'd get a translation fault. -- Catalin From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1EB01C433F5 for ; Wed, 13 Apr 2022 16:54:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9bQKOhCtoD1iWRUpGHpm2AAk/3HLWjbZYq0Ur6kr194=; b=zQmb+QBZUJBW82 MWUWfLL/j7ZuVwKbH2kExB1Mlyd7q1vLsAXRgSKXvXhGlnF11lu+dJsX0aV7LktfDZA4/tiYKE7p0 qvQjgFeDQ1cglIJ6Ynt6rfTOwNRGNOiYTBYlFQci1JZmJS34dsi9nWvnAYvd3THJmWa/S7Qn3bJO4 F1WfqQbEuufbIFGh/qviQDrlExYN27RXGNCoTOHOwTEn3OvsKB+3YteXPhxp+WGxs7ZCjKoc8Ttd6 2LHMUKeT8qvbHQ14ZWdOqwe30cyxPo7h3iET7hIUv7BD1Amxw9/v0w6Q2wHquu8TVv74hpYs32jPV 5/xaPb+WCpap6HrjoUgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1negFY-001pTP-KR; Wed, 13 Apr 2022 16:53:48 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1negFU-001pSX-W2 for linux-arm-kernel@lists.infradead.org; Wed, 13 Apr 2022 16:53:46 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4A5C361E0D; Wed, 13 Apr 2022 16:53:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B77CBC385A3; Wed, 13 Apr 2022 16:53:41 +0000 (UTC) Date: Wed, 13 Apr 2022 17:53:38 +0100 From: Catalin Marinas To: Guanghui Feng Cc: will@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, baolin.wang@linux.alibaba.com Subject: Re: [PATCH RFC v1] arm64: mm: change mem_map to use block/section mapping with crashkernel Message-ID: References: <1649754476-8713-1-git-send-email-guanghuifeng@linux.alibaba.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1649754476-8713-1-git-send-email-guanghuifeng@linux.alibaba.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220413_095345_108021_C51BDDA8 X-CRM114-Status: GOOD ( 17.61 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Apr 12, 2022 at 05:07:56PM +0800, Guanghui Feng wrote: > There are many changes and discussions: > commit 031495635b46 > commit 1a8e1cef7603 > commit 8424ecdde7df > commit 0a30c53573b0 > commit 2687275a5843 > > When using DMA/DMA32 zone and crashkernel, disable rodata full and kfence, > mem_map will use non block/section mapping(for crashkernel requires to shrink > the region in page granularity). But it will degrade performance when doing > larging continuous mem access in kernel(memcpy/memmove, etc). > > This patch firstly do block/section mapping at mem_map, reserve crashkernel > memory. And then walking pagetable to split block/section mapping > to non block/section mapping [only] for crashkernel mem. We will accelerate > mem access about 10-20% performance improvement, and reduce the cpu dTLB miss > conspicuously on some platform with this optimization. Do you actually have some real world use-cases where this improvement matters? I don't deny that large memcpy over the kernel linear map may be slightly faster but where does this really matter? > +static void init_crashkernel_pmd(pud_t *pudp, unsigned long addr, > + unsigned long end, phys_addr_t phys, > + pgprot_t prot, > + phys_addr_t (*pgtable_alloc)(int), int flags) > +{ > + phys_addr_t map_offset; > + unsigned long next; > + pmd_t *pmdp; > + pmdval_t pmdval; > + > + pmdp = pmd_offset(pudp, addr); > + do { > + next = pmd_addr_end(addr, end); > + if (!pmd_none(*pmdp) && pmd_sect(*pmdp)) { > + phys_addr_t pte_phys = pgtable_alloc(PAGE_SHIFT); > + pmd_clear(pmdp); > + pmdval = PMD_TYPE_TABLE | PMD_TABLE_UXN; > + if (flags & NO_EXEC_MAPPINGS) > + pmdval |= PMD_TABLE_PXN; > + __pmd_populate(pmdp, pte_phys, pmdval); > + flush_tlb_kernel_range(addr, addr + PAGE_SIZE); The architecture requires us to do a break-before-make here, so pmd_clear(), TLBI, __pmd_populate() - in this order. And that's where it gets tricky, if the kernel happens to access this pmd range while it is unmapped, you'd get a translation fault. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel