From patchwork Fri Mar 8 18:40:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Guo X-Patchwork-Id: 10845311 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 A393F1515 for ; Fri, 8 Mar 2019 18:41:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C29B2FC23 for ; Fri, 8 Mar 2019 18:41:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FB902FDE4; Fri, 8 Mar 2019 18:41:01 +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=-4.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,MISSING_HEADERS,RCVD_IN_DNSWL_MED 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 E75D02FC23 for ; Fri, 8 Mar 2019 18:41:00 +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:In-Reply-To:References: Message-ID:Date:Subject:From:Reply-To:To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SNMGKk15nHUCs0lpfUSW8nxYSU33+1csVezXgv/cAKc=; b=pi3/978NXJMYoI BeM1HFGbpVMxCQ/r+pegxCfqlZ/86t/iyrnjhlFf86dcFpGPqSsleCIC7szn9b9Lrs10LRmtsicdP gIsuwiQPpZ8eYTKfccCE5Nd/qiX3JEJrY/L2OUVtPg4Dlz6aD+90mG7EKQNObmU6N61qpOnSQPX5j n4TUvjw4OUfECvKakDEzYHxAuGL9beUOUB9WNTrkByYMeKSCjuo8peDDABlwlfig3wI2lJg714Tu4 E0y1VWN0USPQUKYmYHYaVywd+bfsWn+hhtJXFdwQfD5vVE67IzjNXpZBj43oAxWznxbc+YIO4YXbP sVBVhlAdV0IP/OIMlRcg==; 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 1h2KQT-0003tY-Ux; Fri, 08 Mar 2019 18:40:57 +0000 Received: from mail-eopbgr100132.outbound.protection.outlook.com ([40.107.10.132] helo=GBR01-LO2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h2KQQ-0003oy-Ry for linux-riscv@lists.infradead.org; Fri, 08 Mar 2019 18:40:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U12VmDqp5PDY/bRQP1bMyCfddobhmO3WImVlkJZ+iZI=; b=U8qS5C47Fx5zxcghiJkTD1X/DYYIRG0JZEHjckTulUSBop4j2yxV/MMx3pCs6C7HYh9HbacuRYa9bF7qR5kMOZxaIQlI8Jwe03E3PxHVkEiZdysuYmhjViupqhO85tFqmfuW0a2OJdqHpzRLfbipnBG/i16QnF5OHtxJGTMNp6Q= Received: from LO2P265MB0847.GBRP265.PROD.OUTLOOK.COM (20.176.139.20) by LO2P265MB1277.GBRP265.PROD.OUTLOOK.COM (20.176.140.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1665.19; Fri, 8 Mar 2019 18:40:51 +0000 Received: from LO2P265MB0847.GBRP265.PROD.OUTLOOK.COM ([fe80::ed34:1290:4306:3157]) by LO2P265MB0847.GBRP265.PROD.OUTLOOK.COM ([fe80::ed34:1290:4306:3157%3]) with mapi id 15.20.1686.019; Fri, 8 Mar 2019 18:40:51 +0000 From: Gary Guo Subject: [PATCH v2 2/4] riscv: move switch_mm to its own file Thread-Topic: [PATCH v2 2/4] riscv: move switch_mm to its own file Thread-Index: AQHU1d5u/gidJsJ6yUi8SNURjy5IQQ== Date: Fri, 8 Mar 2019 18:40:41 +0000 Message-ID: <3f92dd8a80ffb952b2725245821a11417c2d3506.1552069700.git.gary@garyguo.net> References: In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0170.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::14) To LO2P265MB0847.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8c::20) x-mailer: git-send-email 2.17.1 authentication-results: spf=none (sender IP is ) smtp.mailfrom=gary@garyguo.net; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [2001:630:212:238:3697:f6ff:fe55:55b1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7429fb76-6739-41bc-a7b5-08d6a3f590e7 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(7021145)(8989299)(4534185)(7022145)(4603075)(4627221)(201702281549075)(8990200)(7048125)(7024125)(7027125)(7023125)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:LO2P265MB1277; x-ms-traffictypediagnostic: LO2P265MB1277: x-microsoft-exchange-diagnostics: =?iso-8859-1?Q?1; LO2P265MB1277; 23:tShi0xtrA0l3r/1NdB0FVyTLxweh2wfmbXhL/9z?= =?iso-8859-1?q?mcfG9P8zu+Jdtsh?= =?iso-8859-1?q?LIR4xs+sVOE0/obXR4chOodnKDsujjeaIBm4v/5X53m6jzh/pXbbu8bwHShg?= =?iso-8859-1?q?zGFbKRrm1EcTpGRcG6yBotJbnA7b74OugWJj66Ibqc86bVCrai1HoyomT+/M?= =?iso-8859-1?q?ZkwW46rCKow4BpPkO/mXE3EIcCFgvtvuujssysC898PwGFFQxv6WoHV8m3uO?= =?iso-8859-1?q?TSarhUrPZqxrRxa4fzycShaCeuk2NqD9AsCNgwJkvuZji2e/uXfl31RW6tvs?= =?iso-8859-1?q?mCVcGW9V/Q1iJtII5pagNr9OYD3z0nOS5LSVVSsWUxVN/lbJt3PqE+/oqgZ1?= =?iso-8859-1?q?fKvTKN//3MAs8Jz0OAV1sM2roxJ8cFH5aB+7PLlJa2RmyoWfZbTn3FTh8neY?= =?iso-8859-1?q?499oaEgmSAndSQW2ldzoVfFdr30xgDQ2kUGlQQyufqJtxZ4CbgT7hH18RRuH?= =?iso-8859-1?q?xMw0YySHyQiKkKdAZtxsVQeyEtJCN4tQR+riMd3Z/v8uAHGw878o7aUgu04S?= =?iso-8859-1?q?TPG4hCTIzTT6I91otfnx0c8L7fcz09D9SC8UOO9easaqcDM3wNwV0/uGbgFN?= =?iso-8859-1?q?zmEx58K44UP8xEL8wwWdBxirqfTwYGqqMrJ/0WnXAf1eIBxg41DCsjh2JlU1?= =?iso-8859-1?q?5zb4jfK1vTwHaTEeqMC0MYh45j+VU2epmax3h610EzNqgWDjfJ3w9GW1o/EN?= =?iso-8859-1?q?UJA0iw+lb6a/UjpYC+9Fakc2ckAPHN2zf+s+VVQxuvmK2xzLUsMyea+e5xcs?= =?iso-8859-1?q?tn/17KCV5900Eya0AYhDVS9OZBcf9XFqd0Ni1Pmh2ytKFPFgZ7vgVJNCbasH?= =?iso-8859-1?q?efsAlDiavIGEvx8+/Cg6b9Fu0olcdrK0q0lp5Tqh8ffCxJc0FHIyj0ysvjft?= =?iso-8859-1?q?y2xDF5h/F6aNMicGwvSXTbKQV+/liNgwSUVM7p19zhhE3I5G2frCTOVdGVHM?= =?iso-8859-1?q?CPhmJANzacUKsHTyEiHgdbmepmnl4MKLS4CYs+CpAU/pUh/gZ814aN62x0CV?= =?iso-8859-1?q?KofYxqAoQ339cO27HDNzyqYIRrJmO2VjEMAeXjQ7VJOzD9RhG7SYBrPZS0q+?= =?iso-8859-1?q?0Vahskj9sZqZYm/xpc56Q34o/Ay3a5LTmKUHQYvapqKVz51ND5JMSXg7pHvM?= =?iso-8859-1?q?P9mrU1kDZyk84IN15zXpzBmxHc7UO0oe1OYXksipprYNoJyXieGc688CfGJ6?= =?iso-8859-1?q?uweDeG0jd8Ba8tpWjs0qHR6E1xg94hD71Lja4inWMMZxZbf4yrmOt3OLSvC8?= =?iso-8859-1?q?ez8C0wHD01fPcG5pM+R0WVmmPl?= x-microsoft-antispam-prvs: x-forefront-prvs: 0970508454 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(136003)(39830400003)(396003)(376002)(346002)(199004)(189003)(81166006)(8676002)(2616005)(305945005)(446003)(186003)(76176011)(97736004)(508600001)(1671002)(2906002)(68736007)(59246006)(14454004)(7736002)(6116002)(71200400001)(6506007)(102836004)(256004)(386003)(6666004)(36756003)(8936002)(14444005)(81156014)(118296001)(486006)(99286004)(86362001)(6486002)(476003)(5660300002)(50226002)(71190400001)(54906003)(53936002)(25786009)(105586002)(316002)(4326008)(6512007)(52116002)(6436002)(109986005)(46003)(107886003)(11346002)(106356001); DIR:OUT; SFP:1102; SCL:1; SRVR:LO2P265MB1277; H:LO2P265MB0847.GBRP265.PROD.OUTLOOK.COM; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: garyguo.net does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: RAygcVqx1CtvGku11vqdw4nPhKREc7x+VbdDVls3AI4dojsi8yDEIM1oZHzMxztXP2qlpyd/kpil9kHF5FPKl/r0JQUinqC7qc5L0SqWJckJgIuqiMkEvXyRz0Ovla8Po/+l5XAHJwya+dugfkJwzF6Wc51wz4NsUbXuv09L/ndcEOiyEGRcGzNpPmgE6gJn+2/GoCDkTWxWtE3Ki10gZWGMhr/Z0M9igBR7zI/u/J/XCiZ5+lFPKNADVuNh9I4HN//fSJ1hgiPH7hTkso+seJK2alF7aulF2+kJaofEoHAjGLsXjNrEYick73AvrV6Fe0q+RktazmvQhFsRXnCGBpKP+Y3lgIPG+DOKyyHWjLcUTGb2cji+sNVxfh27bPgqPMVXAY3ghJCkA87bXlhHqqg7nskOIBw5xzk+KGRGAtU= MIME-Version: 1.0 X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 7429fb76-6739-41bc-a7b5-08d6a3f590e7 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2019 18:40:41.7132 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO2P265MB1277 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190308_104055_009984_93251ACB X-CRM114-Status: GOOD ( 18.10 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Palmer Dabbelt , Anup Patel , Christoph Hellwig , Atish Patra , Albert Ou , Gary Guo , "linux-riscv@lists.infradead.org" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Gary Guo switch_mm is an expensive operations that has two users. flush_icache_deferred is only called within switch_mm and can be moved together. The function is expected to be more complicated when ASID support is added, so clean up eagerly. By moving them to a separate file we also removes some excessive dependency of tlbflush.h and cacheflush.h. Signed-off-by: Gary Guo --- arch/riscv/include/asm/mmu_context.h | 59 +---------------------- arch/riscv/mm/Makefile | 1 + arch/riscv/mm/context.c | 71 ++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 57 deletions(-) create mode 100644 arch/riscv/mm/context.c diff --git a/arch/riscv/include/asm/mmu_context.h b/arch/riscv/include/asm/mmu_context.h index 336d60ec5698..bf4f097a9051 100644 --- a/arch/riscv/include/asm/mmu_context.h +++ b/arch/riscv/include/asm/mmu_context.h @@ -20,8 +20,6 @@ #include #include -#include -#include static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *task) @@ -39,61 +37,8 @@ static inline void destroy_context(struct mm_struct *mm) { } -/* - * When necessary, performs a deferred icache flush for the given MM context, - * on the local CPU. RISC-V has no direct mechanism for instruction cache - * shoot downs, so instead we send an IPI that informs the remote harts they - * need to flush their local instruction caches. To avoid pathologically slow - * behavior in a common case (a bunch of single-hart processes on a many-hart - * machine, ie 'make -j') we avoid the IPIs for harts that are not currently - * executing a MM context and instead schedule a deferred local instruction - * cache flush to be performed before execution resumes on each hart. This - * actually performs that local instruction cache flush, which implicitly only - * refers to the current hart. - */ -static inline void flush_icache_deferred(struct mm_struct *mm) -{ -#ifdef CONFIG_SMP - unsigned int cpu = smp_processor_id(); - cpumask_t *mask = &mm->context.icache_stale_mask; - - if (cpumask_test_cpu(cpu, mask)) { - cpumask_clear_cpu(cpu, mask); - /* - * Ensure the remote hart's writes are visible to this hart. - * This pairs with a barrier in flush_icache_mm. - */ - smp_mb(); - local_flush_icache_all(); - } -#endif -} - -static inline void switch_mm(struct mm_struct *prev, - struct mm_struct *next, struct task_struct *task) -{ - if (likely(prev != next)) { - /* - * Mark the current MM context as inactive, and the next as - * active. This is at least used by the icache flushing - * routines in order to determine who should - */ - unsigned int cpu = smp_processor_id(); - - cpumask_clear_cpu(cpu, mm_cpumask(prev)); - cpumask_set_cpu(cpu, mm_cpumask(next)); - - /* - * Use the old spbtr name instead of using the current satp - * name to support binutils 2.29 which doesn't know about the - * privileged ISA 1.10 yet. - */ - csr_write(sptbr, virt_to_pfn(next->pgd) | SATP_MODE); - local_flush_tlb_all(); - - flush_icache_deferred(next); - } -} +void switch_mm(struct mm_struct *prev, struct mm_struct *next, + struct task_struct *task); static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next) diff --git a/arch/riscv/mm/Makefile b/arch/riscv/mm/Makefile index eb22ab49b3e0..d75b035786d6 100644 --- a/arch/riscv/mm/Makefile +++ b/arch/riscv/mm/Makefile @@ -3,3 +3,4 @@ obj-y += fault.o obj-y += extable.o obj-y += ioremap.o obj-y += cacheflush.o +obj-y += context.o diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c new file mode 100644 index 000000000000..fbb1cfe80267 --- /dev/null +++ b/arch/riscv/mm/context.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2012 Regents of the University of California + * Copyright (C) 2017 SiFive + */ + +#include + +#include +#include + +/* + * When necessary, performs a deferred icache flush for the given MM context, + * on the local CPU. RISC-V has no direct mechanism for instruction cache + * shoot downs, so instead we send an IPI that informs the remote harts they + * need to flush their local instruction caches. To avoid pathologically slow + * behavior in a common case (a bunch of single-hart processes on a many-hart + * machine, ie 'make -j') we avoid the IPIs for harts that are not currently + * executing a MM context and instead schedule a deferred local instruction + * cache flush to be performed before execution resumes on each hart. This + * actually performs that local instruction cache flush, which implicitly only + * refers to the current hart. + */ +static inline void flush_icache_deferred(struct mm_struct *mm) +{ +#ifdef CONFIG_SMP + unsigned int cpu = smp_processor_id(); + cpumask_t *mask = &mm->context.icache_stale_mask; + + if (cpumask_test_cpu(cpu, mask)) { + cpumask_clear_cpu(cpu, mask); + /* + * Ensure the remote hart's writes are visible to this hart. + * This pairs with a barrier in flush_icache_mm. + */ + smp_mb(); + local_flush_icache_all(); + } + +#endif +} + +void switch_mm(struct mm_struct *prev, struct mm_struct *next, + struct task_struct *task) +{ + unsigned int cpu; + + if (unlikely(prev == next)) + return; + + /* + * Mark the current MM context as inactive, and the next as + * active. This is at least used by the icache flushing + * routines in order to determine who should be flushed. + */ + cpu = smp_processor_id(); + + cpumask_clear_cpu(cpu, mm_cpumask(prev)); + cpumask_set_cpu(cpu, mm_cpumask(next)); + + /* + * Use the old spbtr name instead of using the current satp + * name to support binutils 2.29 which doesn't know about the + * privileged ISA 1.10 yet. + */ + csr_write(sptbr, virt_to_pfn(next->pgd) | SATP_MODE); + local_flush_tlb_all(); + + flush_icache_deferred(next); +} +