From patchwork Thu Sep 6 10:22:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 10590411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BA61112B for ; Thu, 6 Sep 2018 10:23:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 440D02A4D4 for ; Thu, 6 Sep 2018 10:23:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 379D42A511; Thu, 6 Sep 2018 10:23:33 +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,RCVD_IN_DNSWL_NONE autolearn=ham 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 A20B62A4D4 for ; Thu, 6 Sep 2018 10:23:32 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=UzIf60HfoSWg+f8ll1vONlOjJscRi4KMlYhKTeDAxJo=; b=l731C3UbRTVkWL y36LCtsl6l/wJgWC6lXjz57AFOzrKw0mtK376IklBuVmGm9PKNgXeOkKnF5vFkiTlXY1QrvgmVP6t 4geRJjej26RHx+wY+cpcbLztIVAhZUO3CCU35acsp4TdUZbRcp2QVAHUd9+hX0Oh7yMqY0j8L8xMP WwgbNhQ7LVcPhly6wJKFb50LhjylUcqRqC8vqcq90GzbeBLoHpHdtQXwx6wn5ibXa+PHqdgZBZF3D qljK97k17yXlKjjuLRIQCUN7kPqfAkFwqvXYrYi9X7CoEWurahdrdgLDJYzKTBmZM7SkdJq+RCAlq l5js8Kf1mY/Q95JZCqxg==; 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 1fxrRd-0003ue-RL; Thu, 06 Sep 2018 10:23:25 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fxrQy-0003QD-BR for linux-arm-kernel@lists.infradead.org; Thu, 06 Sep 2018 10:22:46 +0000 Received: by mail-pf1-x443.google.com with SMTP id j26-v6so5052929pfi.10 for ; Thu, 06 Sep 2018 03:22:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pVdxn+3vt6uBmQntezzi5p84CFfWT4Wz9Qc3XWM/P2I=; b=Uj6dYugECbTFq5bCh3KlVp6wUAaK9VN33+FUNZKjKrLFk0NpeMV5Lcu75PkkmH1jO5 nLHUDZx/staukoocEtTAJUjcckmJeRl4CvPLs4oXCp6/FUGn7OH1wYR4+uzp6o9AjyCR FctxgoOrh4o2G8xQZHhJ40VMP95rpyBzgQ0Ae4qjUKqxjCg37nsI06S8+rEgajqxDPzC Vtgaz/aeD6xe8R2SnByWGBcHZpOOedfc3191FEkP2g3hov+z5gcj+U1udj5J/kkuZKzz QfsXN2Y9816Tw2c1hioE2jqPEcNzXWIMXCxfIbNHtCcInRbnqXaRat0sFNo0P5o266uy bHMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=pVdxn+3vt6uBmQntezzi5p84CFfWT4Wz9Qc3XWM/P2I=; b=jpITUseAGJ+2Nu5QNv5h7bIAt2SgXIeAvQnK4BOgWo/YtFFakaQg/dJwVYk0jXYagJ Ir/ppCwzZIPHz3E/RLdVENhrsYWStBQYo3/R9D7Yqa1TA00TIzAVaZK8kFj7zWBcKI6f H1YbWDOidIuYKKkph6iDzdlnJhiUkU5zFqyQkCxytndrSQ7J1VpLOBq0cAkxQgZxWFsc 3BXxZ95JEEyqKp0zH+rF/YGwCFqvQjO8no2Bt7zoeC3sdxKYPfX1snHzXx4PLPOVPonC GehJF5Nr+Tqco/FCNw26nQXICjB/sEckjfQCpJLlUxzxQMpu0tBQgal0tnK+FIkoOOzp DvJg== X-Gm-Message-State: APzg51DWdje7T69FD/7NokYy4Mh1DI77R8QLTPnn/ozuii5maoHbx36K lw9yGaRQNlxBMdJpyTXrDhc= X-Google-Smtp-Source: ANB0VdZWf0siBKdhWrhJ6Bz9HLbQzzJb49Z79wPC47qfzbXzfKczofzbxQDk7scN0TgV6IMQAAPShQ== X-Received: by 2002:a63:1c1b:: with SMTP id c27-v6mr2097691pgc.48.1536229352570; Thu, 06 Sep 2018 03:22:32 -0700 (PDT) Received: from bbox-2.seo.corp.google.com ([2401:fa00:d:10:affa:813f:5380:6613]) by smtp.gmail.com with ESMTPSA id h82-v6sm7909555pfa.173.2018.09.06.03.22.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 03:22:31 -0700 (PDT) From: Minchan Kim To: Andrew Morton , linux@armlinux.org.uk Subject: [RFC 1/3] arm: mm: reordering memory type table Date: Thu, 6 Sep 2018 19:22:10 +0900 Message-Id: <20180906102212.218294-2-minchan@kernel.org> X-Mailer: git-send-email 2.19.0.rc1.350.ge57e33dbd1-goog In-Reply-To: <20180906102212.218294-1-minchan@kernel.org> References: <20180906102212.218294-1-minchan@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180906_032244_520922_275EFC45 X-CRM114-Status: GOOD ( 12.04 ) 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: steve.capper@linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, Minchan Kim , android-treble-mediatek-ext@partner.android.com, kernel-team@android.com, linux-arm-kernel@lists.infradead.org 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 To use bit 5th in page table, we need a room for that and it seems we don't need 4 bits for the memory type with ARMv6+. If so, let's reorder bits to make bit 5 free. We will use the bit for L_PTE_SPECIAL in next patch. Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Steve Capper Signed-off-by: Minchan Kim --- arch/arm/include/asm/pgtable-2level.h | 13 +++++++++++-- arch/arm/mm/proc-macros.S | 16 ++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h index 92fd2c8a9af0..91b99fadcba1 100644 --- a/arch/arm/include/asm/pgtable-2level.h +++ b/arch/arm/include/asm/pgtable-2level.h @@ -164,14 +164,23 @@ #define L_PTE_MT_BUFFERABLE (_AT(pteval_t, 0x01) << 2) /* 0001 */ #define L_PTE_MT_WRITETHROUGH (_AT(pteval_t, 0x02) << 2) /* 0010 */ #define L_PTE_MT_WRITEBACK (_AT(pteval_t, 0x03) << 2) /* 0011 */ +#define L_PTE_MT_DEV_SHARED (_AT(pteval_t, 0x04) << 2) /* 0100 */ #define L_PTE_MT_MINICACHE (_AT(pteval_t, 0x06) << 2) /* 0110 (sa1100, xscale) */ #define L_PTE_MT_WRITEALLOC (_AT(pteval_t, 0x07) << 2) /* 0111 */ -#define L_PTE_MT_DEV_SHARED (_AT(pteval_t, 0x04) << 2) /* 0100 */ -#define L_PTE_MT_DEV_NONSHARED (_AT(pteval_t, 0x0c) << 2) /* 1100 */ +#if defined(CONFIG_CPU_V7) || defined(CONFIG_CPU_V7M) || \ + defined (CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) +#define L_PTE_MT_DEV_WC L_PTE_MT_BUFFERABLE +#define L_PTE_MT_DEV_CACHED L_PTE_MT_WRITEBACK +#define L_PTE_MT_DEV_NONSHARED L_PTE_MT_MINICACHE +#define L_PTE_MT_VECTORS (_AT(pteval_t, 0x05) << 2) /* 0101 */ +#define L_PTE_MT_MASK (_AT(pteval_t, 0x07) << 2) +#else #define L_PTE_MT_DEV_WC (_AT(pteval_t, 0x09) << 2) /* 1001 */ #define L_PTE_MT_DEV_CACHED (_AT(pteval_t, 0x0b) << 2) /* 1011 */ +#define L_PTE_MT_DEV_NONSHARED (_AT(pteval_t, 0x0c) << 2) /* 1100 */ #define L_PTE_MT_VECTORS (_AT(pteval_t, 0x0f) << 2) /* 1111 */ #define L_PTE_MT_MASK (_AT(pteval_t, 0x0f) << 2) +#endif #ifndef __ASSEMBLY__ diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S index 81d0efb055c6..f896a30653fa 100644 --- a/arch/arm/mm/proc-macros.S +++ b/arch/arm/mm/proc-macros.S @@ -134,21 +134,21 @@ .macro armv6_mt_table pfx \pfx\()_mt_table: .long 0x00 @ L_PTE_MT_UNCACHED - .long PTE_EXT_TEX(1) @ L_PTE_MT_BUFFERABLE + .long PTE_EXT_TEX(1) @ L_PTE_MT_BUFFERABLE(L_PTE_MT_DEV_WC) .long PTE_CACHEABLE @ L_PTE_MT_WRITETHROUGH - .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEBACK + .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEBACK(L_PTE_MT_DEV_CACHED) .long PTE_BUFFERABLE @ L_PTE_MT_DEV_SHARED - .long 0x00 @ unused - .long 0x00 @ L_PTE_MT_MINICACHE (not present) + .long PTE_CACHEABLE | PTE_BUFFERABLE | PTE_EXT_APX @ L_PTE_MT_VECTORS + .long PTE_EXT_TEX(2) @ L_PTE_MT_DEV_NONSHARED .long PTE_EXT_TEX(1) | PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEALLOC .long 0x00 @ unused - .long PTE_EXT_TEX(1) @ L_PTE_MT_DEV_WC .long 0x00 @ unused - .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_DEV_CACHED - .long PTE_EXT_TEX(2) @ L_PTE_MT_DEV_NONSHARED .long 0x00 @ unused .long 0x00 @ unused - .long PTE_CACHEABLE | PTE_BUFFERABLE | PTE_EXT_APX @ L_PTE_MT_VECTORS + .long 0x00 @ unused + .long 0x00 @ unused + .long 0x00 @ unused + .long 0x00 @ unused .endm .macro armv6_set_pte_ext pfx From patchwork Thu Sep 6 10:22:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 10590413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C53636CB for ; Thu, 6 Sep 2018 10:24:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D6FA2A4D4 for ; Thu, 6 Sep 2018 10:24:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 919FD2A511; Thu, 6 Sep 2018 10:24: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,RCVD_IN_DNSWL_NONE autolearn=ham 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 EC1242A4D4 for ; Thu, 6 Sep 2018 10:24: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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=opMAu3D03cX884YEwx/CAJX3joX8gOmVtVtuEAfsrfY=; b=rayNTZ+bVHY69g XmNm196/evM3diO5UP5R7lR/mkmy4fNKdcbOVpSC3yCBC9pTFVJ5KYiNU7nWwFhMweDblIvEFkP2D SGolEybaUIGkc2PZPy34T0tZ6McJ6hGLsY19UQ1i/CYCiA+1JlwhfyUos2U9TtnRf3vaAyFPotudq 518OCIqRvN6TRp0d1Q5x8CKsOx9zmoW6WVZrGHvriRYwGMfBhw85PXnJ6NVLYgmb6XVpeXRdAp7jy NMTeNpqc10ZvldEadn22YGBg7Yg/AHbtlbzZZ4vs2G8GrKOa3lrFhLLeqQXvzRMDbUY6hiIm4Ea+X DqRoE3TZO3A52Q6vhXDA==; 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 1fxrSX-0004JC-Vo; Thu, 06 Sep 2018 10:24:22 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fxrR1-0003VI-8p for linux-arm-kernel@lists.infradead.org; Thu, 06 Sep 2018 10:22:49 +0000 Received: by mail-pf1-x444.google.com with SMTP id h69-v6so5065842pfd.4 for ; Thu, 06 Sep 2018 03:22:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=03bIWVCZcpSISui3/Ik6Fa/F3kqV26SZAxPeXglLQxw=; b=NBcQdLcQbCwTjKKcDm4+2ANdOnkvxrj/B55QkCps1JMGAWFtbwKnC9Mn0PwKBI1uT1 +lS5EaejJvxLJz642JYK4CObkRmb6SF6lIyy+CTcwKjasQFVa2Xzg7xT2Ymt+TcpAydN PEipe99YTRKgBlJk0bbv+SAf2b7RsiNEC+ZscCFIQdcJNkL+5x2L15qyDLiHHDFamJo/ NxGMlY+vFwlSPKocOLqM4HgJA1S3Nh51epauyPxAA6HFa92CEKOrvKtzxqx2Ft0nn092 Kabt4Ggf/BEU/2n8iJb92Ho9WZH5/U1JCv2wNTxD+5pMi7+hGWc9J8+ARCvivLQRneCx zCJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=03bIWVCZcpSISui3/Ik6Fa/F3kqV26SZAxPeXglLQxw=; b=Ee9ThUv2DEQ3NnH5UOItY+tjStyOqGkucPcQe5qObghytnXLls5mhx9GocW0CrmMAL RfWju/KzFtoswSVamPxsbiy3EqqWqJvigbC+PbO0tMEXn2JOmh1Exkk3i8Fj57UKHZvM o8xoya5p4tBOEcxIqE7fGwJ3gpFYBTSRWZzgEAr26J0+cMqR09PY4BNSABsXtUXBB+l2 MgfmF/C7Y30GGjtAvBS0C/3duLQ/uecQTIB7GN6ocbb+qk5e/RiYrpes829CYPYzKvjS VBe5z+KFg8O9H4k3JAavdI+gxb1uJiORSN+onxuvSvLCTITXvE46mDw/ryU6NFlcswpv cwpg== X-Gm-Message-State: APzg51CyrtLNqsPxM/XotYgq4TWWtC+4DGWfvkm+yLRHttLf5+av2FQZ JGmvqeCCL23e+dv64UVTN3M= X-Google-Smtp-Source: ANB0Vda6zKJ0Ab0QpfofnQ53HKeh/Ng6YwnIDsM0nEbgCyhMULUtAydQ8B1URWQPjF3h6GHswl7BSw== X-Received: by 2002:a63:e54b:: with SMTP id z11-v6mr1973207pgj.328.1536229356519; Thu, 06 Sep 2018 03:22:36 -0700 (PDT) Received: from bbox-2.seo.corp.google.com ([2401:fa00:d:10:affa:813f:5380:6613]) by smtp.gmail.com with ESMTPSA id h82-v6sm7909555pfa.173.2018.09.06.03.22.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 03:22:35 -0700 (PDT) From: Minchan Kim To: Andrew Morton , linux@armlinux.org.uk Subject: [RFC 2/3] arm: mm: introduce L_PTE_SPECIAL Date: Thu, 6 Sep 2018 19:22:11 +0900 Message-Id: <20180906102212.218294-3-minchan@kernel.org> X-Mailer: git-send-email 2.19.0.rc1.350.ge57e33dbd1-goog In-Reply-To: <20180906102212.218294-1-minchan@kernel.org> References: <20180906102212.218294-1-minchan@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180906_032247_364720_29C66442 X-CRM114-Status: GOOD ( 13.55 ) 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: steve.capper@linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, Minchan Kim , android-treble-mediatek-ext@partner.android.com, kernel-team@android.com, linux-arm-kernel@lists.infradead.org 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 This patch introduces L_PTE_SPECIAL and pte functions for supporting get_user_pages_fast. Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Steve Capper Signed-off-by: Minchan Kim --- arch/arm/Kconfig | 2 +- arch/arm/include/asm/pgtable-2level.h | 3 +-- arch/arm/include/asm/pgtable-3level.h | 6 ------ arch/arm/include/asm/pgtable.h | 13 +++++++++++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index e8cd55a5b04c..5d4489a019c4 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -10,7 +10,7 @@ config ARM select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_KCOV select ARCH_HAS_MEMBARRIER_SYNC_CORE - select ARCH_HAS_PTE_SPECIAL if ARM_LPAE + select ARCH_HAS_PTE_SPECIAL if (ARM_LPAE || CPU_V7 || CPU_V7M || CPU_V6 || CPUV6K) select ARCH_HAS_PHYS_TO_DMA select ARCH_HAS_SET_MEMORY select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h index 91b99fadcba1..82386a2b84e7 100644 --- a/arch/arm/include/asm/pgtable-2level.h +++ b/arch/arm/include/asm/pgtable-2level.h @@ -120,6 +120,7 @@ #define L_PTE_VALID (_AT(pteval_t, 1) << 0) /* Valid */ #define L_PTE_PRESENT (_AT(pteval_t, 1) << 0) #define L_PTE_YOUNG (_AT(pteval_t, 1) << 1) +#define L_PTE_SPECIAL (_AT(pteval_t, 1) << 5) #define L_PTE_DIRTY (_AT(pteval_t, 1) << 6) #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) #define L_PTE_USER (_AT(pteval_t, 1) << 8) @@ -222,8 +223,6 @@ static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr) #define pmd_addr_end(addr,end) (end) #define set_pte_ext(ptep,pte,ext) cpu_set_pte_ext(ptep,pte,ext) -#define pte_special(pte) (0) -static inline pte_t pte_mkspecial(pte_t pte) { return pte; } /* * We don't have huge page support for short descriptors, for the moment diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h index 6d50a11d7793..b6f52e16b478 100644 --- a/arch/arm/include/asm/pgtable-3level.h +++ b/arch/arm/include/asm/pgtable-3level.h @@ -213,12 +213,6 @@ static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr) #define pmd_present(pmd) (pmd_isset((pmd), L_PMD_SECT_VALID)) #define pmd_young(pmd) (pmd_isset((pmd), PMD_SECT_AF)) -#define pte_special(pte) (pte_isset((pte), L_PTE_SPECIAL)) -static inline pte_t pte_mkspecial(pte_t pte) -{ - pte_val(pte) |= L_PTE_SPECIAL; - return pte; -} #define pmd_write(pmd) (pmd_isclear((pmd), L_PMD_SECT_RDONLY)) #define pmd_dirty(pmd) (pmd_isset((pmd), L_PMD_SECT_DIRTY)) diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index a757401129f9..6cc7ce0e423e 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -228,6 +228,11 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd) #define pte_dirty(pte) (pte_isset((pte), L_PTE_DIRTY)) #define pte_young(pte) (pte_isset((pte), L_PTE_YOUNG)) #define pte_exec(pte) (pte_isclear((pte), L_PTE_XN)) +#ifdef CONFIG_ARCH_HAS_PTE_SPECIAL +#define pte_special(pte) (pte_isset((pte), L_PTE_SPECIAL)) +#else +#define pte_special(pte) (0) +#endif #define pte_valid_user(pte) \ (pte_valid(pte) && pte_isset((pte), L_PTE_USER) && pte_young(pte)) @@ -318,6 +323,14 @@ static inline pte_t pte_mknexec(pte_t pte) return set_pte_bit(pte, __pgprot(L_PTE_XN)); } +#ifdef CONFIG_ARCH_HAS_PTE_SPECIAL +static inline pte_t pte_mkspecial(pte_t pte) +{ + return set_pte_bit(pte, __pgprot(L_PTE_SPECIAL)); +} +#else +static inline pte_t pte_mkspecial(pte_t pte) { return pte; } +#endif static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) { const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | From patchwork Thu Sep 6 10:22:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 10590415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F504112B for ; Thu, 6 Sep 2018 10:25:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39D942A4EB for ; Thu, 6 Sep 2018 10:25:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CFA72A524; Thu, 6 Sep 2018 10:25:15 +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,RCVD_IN_DNSWL_NONE autolearn=ham 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 6E0DD2A4EB for ; Thu, 6 Sep 2018 10:25:14 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=GL57v9SVhu2oyqXh6euhmlKVBCyNVaqgkXwLT2n44UA=; b=qmc60rd3Am+ohu ES4Om4//czXlyI3QAC6ZxZsyWvptco7uhYc4JyFZUXSNnRzxpkbXwpAISKndT9s1Ty/uulVBzQ0y5 Vl+SZRFyxfKcrFqWqM65ue7OT1w80jAh1GxA6GFvvvr/KR2Cp3oWQfCL3W9sOk39WdjlvvpPsoCYG 0TtMPNoo59NVOAOjbXFATvIqECBnJ9GHxl1cMaLo2569OLJMO94nFML9+wXmv+IeQfXHV6ctY3zX1 ReJSr5nshRkUwD4iDCdQinuVZJHfAO1ehWOiaUgAbLTrCPddP6htQ6nHoxOJXhYKAk4hE1Hkh9jp5 iE9P35joWYghNt0X0P2Q==; 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 1fxrTF-0004cI-Jr; Thu, 06 Sep 2018 10:25:05 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fxrR5-0003Vx-CM for linux-arm-kernel@lists.infradead.org; Thu, 06 Sep 2018 10:22:53 +0000 Received: by mail-pl1-x642.google.com with SMTP id g2-v6so3811657plo.2 for ; Thu, 06 Sep 2018 03:22:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sCOjJCIPjuifYDa+05zHL+WPmPDOj/NAolPV8GEjiP4=; b=TOIsaVYJTHzrvs7ufNK+zs1lnHPddRhNS9vMssgDAOZvHX9Qht4OlYinQLaohyH6RD mU56zOj/ZYEC1IQIpnrH99T4gFbXZapBet5DD5vY3ZB/YlL1bxwJgJntD6xrBZKp/mdU H41EoRJPm1NL3yzWkuyRVW+HXGwVAcOt5eR1/Q6h7uZpmeLQOKl7Nr/JoWQIq8KNZsh8 b8cCqOLDwPUGep4h2RXQyIfN2DkCIS9TCkT5d2Ok6WRLN6i7kbWqP5LGOaOXw4/Akt59 Ih6dfjq+OB0kqAWyn8O8InWGb2EkdiWfIJTsea5hyzH10O2AYQYRC155TtRMj4SlLvNp RLRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=sCOjJCIPjuifYDa+05zHL+WPmPDOj/NAolPV8GEjiP4=; b=IK0ZSMvYLnMsR4qk2rF7lwXZtKpFeiUa5dSWjjtg/1LQuJCt03oUPAMfchFzW1f1Dm +7eLqCYW4IV/3rKaz5xlp2izViqJAqXy7MLtXMVbxZAZCueaLZNNFx7CgnZfNj0p47yH prMD86C7rlzBY3Dg88jXYsM0aJU4fS7o213i6SSOQ1pf0fIYQlZEVgEo4P6Las7okXHO 3nRplYsIB6/qFWDI5oXu9AVpNaIOx2RGIKPzeF9TVuv26Z+I5clmfUKoL3VuKCN/bkVr C2u6A7V1QUcQegua9H2bxgclYMQSJ6yVpAwr+azy3HRtE9O2ZVfa+RL+ilVM6SEYqiUG TtQQ== X-Gm-Message-State: APzg51BNIA2i8J+dUTbKpI2XBbxE3W/2r6HXXYXhdcpU9/hda31raI1c zXnp3CgBx3vLtni+4ST1kk4= X-Google-Smtp-Source: ANB0Vdac3TqOVzfOTkd+mkLosV6H0nHL5sc7hGEcZLAJ54ZFX4GvaOM8fol92aWpVHkgP9/KImB+fQ== X-Received: by 2002:a17:902:46a4:: with SMTP id p33-v6mr1947964pld.205.1536229360600; Thu, 06 Sep 2018 03:22:40 -0700 (PDT) Received: from bbox-2.seo.corp.google.com ([2401:fa00:d:10:affa:813f:5380:6613]) by smtp.gmail.com with ESMTPSA id h82-v6sm7909555pfa.173.2018.09.06.03.22.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 03:22:39 -0700 (PDT) From: Minchan Kim To: Andrew Morton , linux@armlinux.org.uk Subject: [RFC 3/3] arm: mm: support get_user_pages_fast Date: Thu, 6 Sep 2018 19:22:12 +0900 Message-Id: <20180906102212.218294-4-minchan@kernel.org> X-Mailer: git-send-email 2.19.0.rc1.350.ge57e33dbd1-goog In-Reply-To: <20180906102212.218294-1-minchan@kernel.org> References: <20180906102212.218294-1-minchan@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180906_032251_476555_358E5014 X-CRM114-Status: GOOD ( 17.90 ) 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: steve.capper@linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, Minchan Kim , android-treble-mediatek-ext@partner.android.com, kernel-team@android.com, linux-arm-kernel@lists.infradead.org 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 Recently, there was a report get_user_pages_fast helps app launching speed due to reducing uninterruptible sleep time because we don't need to contend for mmap_sem, I believe. With get_user_pages_fast, that uniterruptible sleep time is reduced about 5~10% by testing. Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Steve Capper Signed-off-by: Minchan Kim --- arch/arm/mm/Makefile | 6 ++ arch/arm/mm/gup.c | 221 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 arch/arm/mm/gup.c diff --git a/arch/arm/mm/Makefile b/arch/arm/mm/Makefile index 7cb1699fbfc4..f55f96d56843 100644 --- a/arch/arm/mm/Makefile +++ b/arch/arm/mm/Makefile @@ -13,6 +13,12 @@ obj-y += nommu.o obj-$(CONFIG_ARM_MPU) += pmsa-v7.o pmsa-v8.o endif +ifneq ($(CONFIG_ARM_LPAE),y) +ifeq ($(CONFIG_ARCH_HAS_PTE_SPECIAL),y) +obj-$(CONFIG_MMU) += gup.o +endif +endif + obj-$(CONFIG_ARM_PTDUMP_CORE) += dump.o obj-$(CONFIG_ARM_PTDUMP_DEBUGFS) += ptdump_debugfs.o obj-$(CONFIG_MODULES) += proc-syms.o diff --git a/arch/arm/mm/gup.c b/arch/arm/mm/gup.c new file mode 100644 index 000000000000..44e12fb7430e --- /dev/null +++ b/arch/arm/mm/gup.c @@ -0,0 +1,221 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + +static inline pte_t gup_get_pte(pte_t *ptep) +{ + return READ_ONCE(*ptep); +} + +static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, + int write, struct page **pages, int *nr) +{ + int ret = 0; + pte_t *ptep, *ptem; + + ptem = ptep = pte_offset_map(&pmd, addr); + do { + pte_t pte = gup_get_pte(ptep); + struct page *page; + + if (!pte_access_permitted(pte, write)) + goto pte_unmap; + + if (pte_special(pte)) + goto pte_unmap; + + VM_BUG_ON(!pfn_valid(pte_pfn(pte))); + page = pte_page(pte); + + if (!page_cache_get_speculative(page)) + goto pte_unmap; + + if (unlikely(pte_val(pte) != pte_val(*ptep))) { + put_page(page); + goto pte_unmap; + } + + SetPageReferenced(page); + pages[*nr] = page; + (*nr)++; + + } while (ptep++, addr += PAGE_SIZE, addr != end); + + ret = 1; + +pte_unmap: + pte_unmap(ptem); + return ret; +} + +static int gup_pmd_range(pud_t pud, unsigned long addr, unsigned long end, + int write, struct page **pages, int *nr) +{ + unsigned long next; + pmd_t *pmdp; + + pmdp = pmd_offset(&pud, addr); + do { + pmd_t pmd = READ_ONCE(*pmdp); + + next = pmd_addr_end(addr, end); + if (!pmd_present(pmd)) + return 0; + else if (!gup_pte_range(pmd, addr, next, write, pages, nr)) + return 0; + } while (pmdp++, addr = next, addr != end); + + return 1; +} + +static int gup_pud_range(p4d_t *p4dp, unsigned long addr, unsigned long end, + int write, struct page **pages, int *nr) +{ + unsigned long next; + pud_t *pudp; + + pudp = pud_offset(p4dp, addr); + do { + pud_t pud = READ_ONCE(*pudp); + + next = pud_addr_end(addr, end); + if (pud_none(pud)) + return 0; + else if (!gup_pmd_range(pud, addr, next, write, pages, nr)) + return 0; + } while (pudp++, addr = next, addr != end); + + return 1; +} + +static int gup_p4d_range(pgd_t *pgdp, unsigned long addr, unsigned long end, + int write, struct page **pages, int *nr) +{ + unsigned long next; + p4d_t *p4dp; + + p4dp = p4d_offset(pgdp, addr); + do { + next = p4d_addr_end(addr, end); + if (p4d_none(*p4dp)) { + return 0; + } else if (!gup_pud_range(p4dp, addr, next, write, pages, nr)) + return 0; + } while (p4dp++, addr = next, addr != end); + + return 1; +} + + +static void gup_pgd_range(unsigned long addr, unsigned long end, + int write, struct page **pages, int *nr) +{ + unsigned long next; + pgd_t *pgdp; + + pgdp = pgd_offset(current->mm, addr); + do { + next = pgd_addr_end(addr, end); + if (pgd_none(*pgdp)) + return; + else if (!gup_p4d_range(pgdp, addr, next, write, pages, nr)) + break; + } while (pgdp++, addr = next, addr != end); +} + +bool gup_fast_permitted(unsigned long start, int nr_pages, int write) +{ + unsigned long len, end; + + len = (unsigned long) nr_pages << PAGE_SHIFT; + end = start + len; + return end >= start; +} + +/* + * Like get_user_pages_fast() except its IRQ-safe in that it won't fall + * back to the regular GUP. + */ +int __get_user_pages_fast(unsigned long start, int nr_pages, int write, + struct page **pages) +{ + unsigned long addr, len, end; + unsigned long flags; + int nr = 0; + + start &= PAGE_MASK; + addr = start; + len = (unsigned long) nr_pages << PAGE_SHIFT; + end = start + len; + + if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ, + (void __user *)start, len))) + return 0; + + /* + * Disable interrupts. We use the nested form as we can already have + * interrupts disabled by get_futex_key. + * + * With interrupts disabled, we block page table pages from being + * freed from under us. See mmu_gather_tlb in asm-generic/tlb.h + * for more details. + * + * We do not adopt an rcu_read_lock(.) here as we also want to + * block IPIs that come from THPs splitting. + */ + + if (gup_fast_permitted(start, nr_pages, write)) { + local_irq_save(flags); + gup_pgd_range(addr, end, write, pages, &nr); + local_irq_restore(flags); + } + + return nr; +} + +int get_user_pages_fast(unsigned long start, int nr_pages, int write, + struct page **pages) +{ + unsigned long addr, len, end; + int nr = 0, ret = 0; + + start &= PAGE_MASK; + addr = start; + len = (unsigned long) nr_pages << PAGE_SHIFT; + end = start + len; + + if (nr_pages <= 0) + return 0; + + if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ, + (void __user *)start, len))) + return -EFAULT; + + if (gup_fast_permitted(start, nr_pages, write)) { + local_irq_disable(); + gup_pgd_range(addr, end, write, pages, &nr); + local_irq_enable(); + ret = nr; + } + + if (nr < nr_pages) { + /* Try to get the remaining pages with get_user_pages */ + start += nr << PAGE_SHIFT; + pages += nr; + + ret = get_user_pages_unlocked(start, nr_pages - nr, pages, + write ? FOLL_WRITE : 0); + + /* Have to be a bit careful with return values */ + if (nr > 0) { + if (ret < 0) + ret = nr; + else + ret += nr; + } + } + + return ret; +}