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: 10845309 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 2B9361515 for ; Fri, 8 Mar 2019 18:41:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 131652FC23 for ; Fri, 8 Mar 2019 18:41:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 066952FDE4; Fri, 8 Mar 2019 18:41:00 +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 6410F2FC23 for ; Fri, 8 Mar 2019 18:40:58 +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=SYgdteB8wkiXaJiMQi5t5mOqH1JZtz6ppZjYejsgdmk=; b=ig09jnoeC0Fqgw C28DF8zAY6tqpUMbLZDrZGUhzTjB70yqiJ3E/xvLYBgRGYKdgAtdb0ebWl1w+DANHQRSCL0p9badg +mVfTRRWItTAPJguI8nVH2weO/8+mqzwFIIXSaIXjx2sJNBi6uxmmsaqVR+BRHASdKoMFt6bVreyx iKLzJAVVviRvNALmL3TnczKmsEnCCDk/2RRCZd4zmT8hq304Yio40ndQQIrw7wfaDEGVnoL7eNJiI cAVTonBPRqTzWhGSIjijnLrEzygnPha3fcJQ7u9kYJxlPjI7aWaEma7LdKFhKj7mlNM9wjqk1KIGo CaZHLOKp/MA+E5k+8lTA==; 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 1h2KQR-0003r7-SV; Fri, 08 Mar 2019 18:40:55 +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 1h2KQO-0003oy-Vv for linux-riscv@lists.infradead.org; Fri, 08 Mar 2019 18:40:54 +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=2TMRCRkZlWDb5DgG3a/IFQ4jS6pMxwpHwOa3rVRdYik=; b=PH1OO1UD3Fb1R7NF9DyXhmOSs9reXKttMA+9FEktBQcKZZRJiUq+M1IXkzpi5fvTeOH7XtMVb4XxiCPmA+bazhVmYqSXmWuc4pZ9aKU70oqmYOU1mVzcwJIeyOWzWE4bYQDOrmLRuBfYb2+U7cTxq3NQ9pvHQIrFfsZkZoqCZ8E= 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:49 +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:49 +0000 From: Gary Guo Subject: [PATCH v2 1/4] riscv: move flush_icache_{all,mm} to cacheflush.c Thread-Topic: [PATCH v2 1/4] riscv: move flush_icache_{all, mm} to cacheflush.c Thread-Index: AQHU1d5uSE1MyRE3LEG58+Wg47x8VA== Date: Fri, 8 Mar 2019 18:40:41 +0000 Message-ID: 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: 18241572-58b6-49f3-e73a-08d6a3f5909d 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:DbickJHXsMc8vStxKBB2aE6bIoj9Gwy8SsKR3H2?= =?iso-8859-1?q?dHhtSzlb2w8fehT?= =?iso-8859-1?q?08KDG1LVGm/PbzpSOE79yF3yvankpHBVa8piRkqS2HfgVkCd92zISJoqGGXD?= =?iso-8859-1?q?BsXrGjPV1NFtCIY5qSBNrV70PcAGPFA/Au528SZLIv8AFGTl/B9Yg3FWT/+t?= =?iso-8859-1?q?wns/JGz/ibRenfvaBqkSUhEujpWSb67W2L+J4fMSF0+c9rPi4+F0uFu5APOe?= =?iso-8859-1?q?45zWzFWayvMVPM/XHWXNrfp+CiLtt/Og1iyG4Cv3fBbqTZpRaUykbfdpqBH1?= =?iso-8859-1?q?QqrPTv4vD4tqAq/qDn084Eel7AvBaO9ZKJ5cZY2mgtuiPJ1HmvxSA3C66WfT?= =?iso-8859-1?q?AQOwJ3aUjO/x+M7B3w+A3FHjBEelC2II4PquUujyhFpa8+4w7EltHC2Ih57+?= =?iso-8859-1?q?1skXz3eWKiYG5mcf5Oi6FH0gCfWPJu6870uqdbmw2o4vD1//OY8DsAHXelT7?= =?iso-8859-1?q?sgdApfgARrAqSVDHtGS5v5+OzGwoIxxxAWNLCoxraFAi+lpmTIy6GwrH9Cdz?= =?iso-8859-1?q?4fU9QKvwIEh4Xzxmko0M0OQJ6NCJHyxl+VLVUB38ZMlCy5lWtN5JczHESYCd?= =?iso-8859-1?q?2YXL9SryfHeaKAZi8MUBiar/EZV2Zbvr/lnwWtn/jxwsSpwPHkz9P2hPfNVd?= =?iso-8859-1?q?SUo8ZCXSxNXVtIVU5RX687DSHagANDRy4tl2CxreKCIaET1Pwdyeavzd3rYv?= =?iso-8859-1?q?wmfpbfFHBG1LoRhfuSVkRgnK38ZGOq+7hZ3Icz3bmZa0jGfPuyEB5zxjMFyF?= =?iso-8859-1?q?8Z7U2EHDnV5upkx50cLoEsvMokaWlI9gjiPHkkFpsETqqOumhrl6KheTj41M?= =?iso-8859-1?q?wjRGjA9S+NhwdnSXiZZiymL9o6xkV9s0I3v/9kCv93Y3Yslu/Vwous32qMJi?= =?iso-8859-1?q?qmk52jvZgZcQqAngziOpUJCRIjhM+SmgPn2d1+oOAPk1oKN3ssZn5X5XNQGT?= =?iso-8859-1?q?HCUM35j9X/s37tkmEUZO/ej16LYt/P7FnDfDYhrYVt/A4GCd5gCKr059bxNd?= =?iso-8859-1?q?8pXaB0ufOLivDP/iMOj7g/niRz6s4nPlJUyNT/qxXH2gtEAXveV+Hle9lm6Q?= =?iso-8859-1?q?bsywjCOFTPKcfKM3XSwZa/sSBzlGojUgK/BiR4WUI/c3Ujb36G3TjmMHMGeL?= =?iso-8859-1?q?98tV1HOPm+QROVKPxGFzE7JCCsH5mqcWGKYkf0/ZiK3up7POfPCYFdCIWNvZ?= =?iso-8859-1?q?d8bqcGymnmal2SauO2aE6tpZVEfYRTUXa5P8g1lIAm+gtEsU1aj3CjMDOMV1?= =?iso-8859-1?q?YfSDGot9Co9QzykvoojwhTUOMXTpQpCzZ3rz7t2C42Mxp0Tw=3D=3D?= 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)(142933001); 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: kKIyMCCX3wuFHOeYj2Jo6X7pCK+bNcTY5e2n09q1ZG43m673YquUHVFacYjbZl7NKgZQ0p3F0AHmO3GxXuylyiIdRXfMoRtwh65WuckvZTjs1+Pmwn1nxZNx5gy1USRHCPLfsfmT0vChmTzbbFA1rEAk11WtyCw/xQT00BE6NBmjA5DM0PgKfhhsH/4I3W7veT0dYz8Ii3mnQpRK/oHrlwFKKCpxYWgmxCLJNRhsxBOTmyCw7Ho9tEXUarqyTXOyqC+HzVI/jeMq1hA1PgkOMpYjt0+iNueB6OnGtFtfrhhLZ2rDQb8Xl1SKMof97L3VIwsWafySKTww4oMobW989U5adl2lLlRDL2g2SeADOitbS/9POeIYjQSEWa71iDY3ChlPA6WZdwzkmX+TJmnOlDR3aLLJ9NHpOoZHLsnFBQQ= MIME-Version: 1.0 X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 18241572-58b6-49f3-e73a-08d6a3f5909d X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2019 18:40:41.1868 (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_104053_025745_334A94A1 X-CRM114-Status: GOOD ( 15.42 ) 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 Currently, flush_icache_all is macro-expanded into a SBI call, yet no asm/sbi.h is included in asm/cacheflush.h. This could be moved to mm/cacheflush.c instead (SBI call will dominate performance-wise and there is no worry to not have it inlined. Currently, flush_icache_mm stays in kernel/smp.c, which looks like a hack to prevent it from being compiled when CONFIG_SMP=n. It should also be in mm/cacheflush.c. Signed-off-by: Gary Guo --- arch/riscv/include/asm/cacheflush.h | 2 +- arch/riscv/kernel/smp.c | 49 ----------------------- arch/riscv/mm/cacheflush.c | 61 +++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 50 deletions(-) diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h index 8f13074413a7..1f4ba68ab9aa 100644 --- a/arch/riscv/include/asm/cacheflush.h +++ b/arch/riscv/include/asm/cacheflush.h @@ -47,7 +47,7 @@ static inline void flush_dcache_page(struct page *page) #else /* CONFIG_SMP */ -#define flush_icache_all() sbi_remote_fence_i(NULL) +void flush_icache_all(void); void flush_icache_mm(struct mm_struct *mm, bool local); #endif /* CONFIG_SMP */ diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index 57b1383e5ef7..f066344aaf42 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -162,52 +162,3 @@ void smp_send_reschedule(int cpu) send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE); } -/* - * Performs an icache flush for the given MM context. 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. - */ -void flush_icache_mm(struct mm_struct *mm, bool local) -{ - unsigned int cpu; - cpumask_t others, hmask, *mask; - - preempt_disable(); - - /* Mark every hart's icache as needing a flush for this MM. */ - mask = &mm->context.icache_stale_mask; - cpumask_setall(mask); - /* Flush this hart's I$ now, and mark it as flushed. */ - cpu = smp_processor_id(); - cpumask_clear_cpu(cpu, mask); - local_flush_icache_all(); - - /* - * Flush the I$ of other harts concurrently executing, and mark them as - * flushed. - */ - cpumask_andnot(&others, mm_cpumask(mm), cpumask_of(cpu)); - local |= cpumask_empty(&others); - if (mm != current->active_mm || !local) { - cpumask_clear(&hmask); - riscv_cpuid_to_hartid_mask(&others, &hmask); - sbi_remote_fence_i(hmask.bits); - } else { - /* - * It's assumed that at least one strongly ordered operation is - * performed on this hart between setting a hart's cpumask bit - * and scheduling this MM context on that hart. Sending an SBI - * remote message will do this, but in the case where no - * messages are sent we still need to order this hart's writes - * with flush_icache_deferred(). - */ - smp_mb(); - } - - preempt_enable(); -} diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index 498c0a0814fe..497b7d07af0c 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -14,6 +14,67 @@ #include #include +#ifdef CONFIG_SMP + +#include + +void flush_icache_all(void) +{ + sbi_remote_fence_i(NULL); +} + +/* + * Performs an icache flush for the given MM context. 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. + */ +void flush_icache_mm(struct mm_struct *mm, bool local) +{ + unsigned int cpu; + cpumask_t others, hmask, *mask; + + preempt_disable(); + + /* Mark every hart's icache as needing a flush for this MM. */ + mask = &mm->context.icache_stale_mask; + cpumask_setall(mask); + /* Flush this hart's I$ now, and mark it as flushed. */ + cpu = smp_processor_id(); + cpumask_clear_cpu(cpu, mask); + local_flush_icache_all(); + + /* + * Flush the I$ of other harts concurrently executing, and mark them as + * flushed. + */ + cpumask_andnot(&others, mm_cpumask(mm), cpumask_of(cpu)); + local |= cpumask_empty(&others); + if (mm != current->active_mm || !local) { + cpumask_clear(&hmask); + riscv_cpuid_to_hartid_mask(&others, &hmask); + sbi_remote_fence_i(hmask.bits); + } else { + /* + * It's assumed that at least one strongly ordered operation is + * performed on this hart between setting a hart's cpumask bit + * and scheduling this MM context on that hart. Sending an SBI + * remote message will do this, but in the case where no + * messages are sent we still need to order this hart's writes + * with flush_icache_deferred(). + */ + smp_mb(); + } + + preempt_enable(); +} + +#endif /* CONFIG_SMP */ + void flush_icache_pte(pte_t pte) { struct page *page = pte_page(pte); 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); +} + 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: 10845313 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 B032E14E1 for ; Fri, 8 Mar 2019 18:41:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A16B2FC23 for ; Fri, 8 Mar 2019 18:41:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E2B62FDE4; Fri, 8 Mar 2019 18:41:02 +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 2FC792FC23 for ; Fri, 8 Mar 2019 18:41:02 +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=fdiZekw2Au2SmSabFnh60eocFlGSmhjqygZjmsFMScU=; b=BrB2foAYPsSZsf w/nv0BQi5P/GVKFxeP6kvapbNsQu+sVOx+0JQbVBX3gr2afeEITJ1jS/BQV+m/9MGjXgHOkqa262r PhKzpJkNxpqJv9JSuu8vd2jSji9KkTLAFohEB2b3gJ3bXfsob/Bg9UubrKDWhpgP3PoYzoVgyGscn yCe5HsLMc87bkSYjXsjXcdzeeksVHfvHwLweal4axy/o80/ZoonILdfQT0RKL1iv771C06OojJpX9 /5/OpcQL2dvlC2H/wBPAMeOEONadNZzx3LPhJ1Rzk3rcTEWNbdkFNNW9qh2x9qrEKIOoRw08AARpr LBReTCnXXer0c2ZWKUjQ==; 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 1h2KQW-0003wu-IU; Fri, 08 Mar 2019 18:41:00 +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 1h2KQT-0003oy-6J for linux-riscv@lists.infradead.org; Fri, 08 Mar 2019 18:40:58 +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=Zj/uHTSPRMiIS73g46NB5MYWGGCzJXJJvWiKMnQXqts=; b=v5sUBMiwewO5cutV0wwXmViU26mkHVTwqEpQmdVBW8qd9TEo2BsgM+CwSPlG4ep6/L4ZP/COuM/FPZXYuT6rrIEgo3OIpXJaRnr/l9B6js5gxpaezvQf3Aa/JjG7BoXi72ayh5BLu3XpSnr9dHPVzawlyKqOu07qhON/6bsLI0o= 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 3/4] riscv: fix sbi_remote_sfence_vma{,_asid}. Thread-Topic: [PATCH v2 3/4] riscv: fix sbi_remote_sfence_vma{,_asid}. Thread-Index: AQHU1d5u4xRTm7jXMEGRowDv8gG2sQ== Date: Fri, 8 Mar 2019 18:40:41 +0000 Message-ID: <9daacfb1af0b5429c384b00953018102cff4b8e6.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: d14a50b3-1607-4024-e772-08d6a3f59136 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:zt94KkrlqLeo+/y5S3Taj749Op3jei8PCnbN1KJ?= =?iso-8859-1?q?Od1mT5xmSe/8eZ4?= =?iso-8859-1?q?UDRt6ZNEDqJYJwlJV/aGzy/VPBQ8Ojs1cIUGG1sLv6fVN6yItnZJ2sTxgbou?= =?iso-8859-1?q?gnh3gBmpSW7in0E0l58yavw9OGi8ASzodnmHTbV2orGO8HgS3WxoUFDv7H+n?= =?iso-8859-1?q?digvL6Cp/SgoczgGsTpWy+VOTXOshBoE4YPOOyOihcSrewzIyFOXyd/ejhZ1?= =?iso-8859-1?q?nKrumJd2tuZ34euoPqM5VXF3szMltzUsiElT1ORohPdRuJCMmwI+SaYsH8Ig?= =?iso-8859-1?q?T0RNWh4bsKezP2Xb93yY4+3TSWp8cE4OICsJfN9MpHN3WNoJdLM5YWLQeK5p?= =?iso-8859-1?q?cRsN/bgvJnYfcndQIB9TcHJ1ogtyUd1CSF7W0UC5+1L5UvK8JYKbHQEi3Jvz?= =?iso-8859-1?q?IsXRi4prmdOZ9LZCKTB7u1ASKb5OQS8B+c1oIKmM6k3ph7lX4KlOqqyXh13n?= =?iso-8859-1?q?Cp2YWDPN0g51HRQdIBuFSGy/fRWal60yp1GgLpnP7s5LNiQuXnaSpnwsA5AX?= =?iso-8859-1?q?/zca7YLAbWtgIIqRigf1tCDso8BjSz9ma5vthEAHNgI1fmmYbZBAqT9vtHkP?= =?iso-8859-1?q?RgyfC8S8WgQuwGz5YTeNwlvCz4EoEQkxp7xr/FF//rGIRKrg5S7RJSYbaC4i?= =?iso-8859-1?q?9NbGjTErSimWZ2UWDxL3DFp1jsiHwYBhi7dLm1+CmeYff6sP5xL8O2rEJlnD?= =?iso-8859-1?q?Ezo4BXm2is1VhJ57J6euEe9MYtSnOc3mLOWtzVmrdMROiKKhlu+ej20Hm+Qd?= =?iso-8859-1?q?2Ym/B3TDerAh3lnvO6HeBTm40PHgao9tscYqc+poiayxwp2BODLU4CuZUYHw?= =?iso-8859-1?q?INKVJgJScS6cM77cu9N90ZoZ9z56A3tpReAQz+H6bOXPAgE9W0LF93MQYB8A?= =?iso-8859-1?q?wzZJjDCgmwWXGLwqZGB3DuUyUTjIjnUfazP2t9pCeztb9oky3XOYFnoYWxLM?= =?iso-8859-1?q?4cHnDJBFLb7UHIjalf6drVrBr0UaabKzkdQ5q0jjzGWbeROh1bkhxlIPdyYF?= =?iso-8859-1?q?IGhIzHoEkLfG1qPyQi+ykDkLWOoSX+MutqDuh8ZRHzBIlBdys3PLu717Fyxh?= =?iso-8859-1?q?OEYI2wnxu5NKC2gxZJr1ydGA1sWjgVBC4xtmwY9e2rbgipMtfOAWBe+CXjYY?= =?iso-8859-1?q?J+ikfdHJ7v2P2EhPgDJ8POMNjVVGJ7vm2Pfz8iRzG8oXF0hvxi9H7h0iPVdR?= =?iso-8859-1?q?A31j6+qmmEMAZwOglyGHbO2xyQRNetMMTqFGyxkKO6OTDBMDOv1yhlGH5HLc?= =?iso-8859-1?q?tzK50=3D?= 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)(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: +o3CJ4aXM45AjWOaV4rDW61+duoHuElUuoVaPCPCgQ5S2L2L494BC5BjMzZAG0MyR1r6+hin6SFGr3r8u348p4WmI7SR9wR7Qky8CH+UKATh92enWvYXsPegJjN6fP7SubHWh6cxJmk4Nfpd4utUsRlnsLNB8XdbBC400TsGdnoyZCXr7ctigzbUjj925QjwqLwHT8GyNhIHo/rw6RCXOQl4EanSdT1ApjsPt9ahPbwDMC4/Y4JFe1PYQqm7hgaPCND7A5QhF6zaWrlwpkxqn6B8MlRHmaCxPsX1auhseGtTUOYMvVRL9smxd8Hq/for02A9BSx0bgCKlQ4DuZerPtBCURo/szu9stVX62l0hGYy7PKJXktQa9RTJPVx+SNAMhYaasrniCnhVM4qz4nXomDe9XYERKdKUMITm+DQlZE= MIME-Version: 1.0 X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: d14a50b3-1607-4024-e772-08d6a3f59136 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2019 18:40:41.9834 (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_104057_525908_02391B29 X-CRM114-Status: UNSURE ( 9.38 ) X-CRM114-Notice: Please train this message. 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 Currently sbi_remote_sfence_vma{,_asid} does not pass their arguments to SBI at all, which is semantically incorrect. Neither BBL nor OpenSBI is using these arguments at the moment, and they just do a global flush instead. However we still need to provide correct arguments. Signed-off-by: Gary Guo --- arch/riscv/include/asm/sbi.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index b6bb10b92fe2..19f231615510 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -26,22 +26,27 @@ #define SBI_REMOTE_SFENCE_VMA_ASID 7 #define SBI_SHUTDOWN 8 -#define SBI_CALL(which, arg0, arg1, arg2) ({ \ +#define SBI_CALL(which, arg0, arg1, arg2, arg3) ({ \ register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \ register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); \ register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); \ + register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); \ register uintptr_t a7 asm ("a7") = (uintptr_t)(which); \ asm volatile ("ecall" \ : "+r" (a0) \ - : "r" (a1), "r" (a2), "r" (a7) \ + : "r" (a1), "r" (a2), "r" (a3), "r" (a7) \ : "memory"); \ a0; \ }) /* Lazy implementations until SBI is finalized */ -#define SBI_CALL_0(which) SBI_CALL(which, 0, 0, 0) -#define SBI_CALL_1(which, arg0) SBI_CALL(which, arg0, 0, 0) -#define SBI_CALL_2(which, arg0, arg1) SBI_CALL(which, arg0, arg1, 0) +#define SBI_CALL_0(which) SBI_CALL(which, 0, 0, 0, 0) +#define SBI_CALL_1(which, arg0) SBI_CALL(which, arg0, 0, 0, 0) +#define SBI_CALL_2(which, arg0, arg1) SBI_CALL(which, arg0, arg1, 0, 0) +#define SBI_CALL_3(which, arg0, arg1, arg2) \ + SBI_CALL(which, arg0, arg1, arg2, 0) +#define SBI_CALL_4(which, arg0, arg1, arg2, arg3) \ + SBI_CALL(which, arg0, arg1, arg2, arg3) static inline void sbi_console_putchar(int ch) { @@ -86,7 +91,7 @@ static inline void sbi_remote_sfence_vma(const unsigned long *hart_mask, unsigned long start, unsigned long size) { - SBI_CALL_1(SBI_REMOTE_SFENCE_VMA, hart_mask); + SBI_CALL_3(SBI_REMOTE_SFENCE_VMA, hart_mask, start, size); } static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, @@ -94,7 +99,7 @@ static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, unsigned long size, unsigned long asid) { - SBI_CALL_1(SBI_REMOTE_SFENCE_VMA_ASID, hart_mask); + SBI_CALL_4(SBI_REMOTE_SFENCE_VMA_ASID, hart_mask, start, size, asid); } #endif From patchwork Fri Mar 8 18:40:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Guo X-Patchwork-Id: 10845315 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 325C01515 for ; Fri, 8 Mar 2019 18:41:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 163C82FC23 for ; Fri, 8 Mar 2019 18:41:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A4CC2FDE4; Fri, 8 Mar 2019 18:41:05 +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 E65E42FC23 for ; Fri, 8 Mar 2019 18:41:03 +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=f9xmqWxEiHmo0kOSYEZkeZi3PrY++Wr1E/sRCc07LsY=; b=nqjhOA1O7eEE0D 6w+q6+WPJacVg7lFeROgIIAiEwpCOqEXw+u8Sli8OuNaBOkFYykkFIZ2MSgdxpGICN2rs8gEdedA8 RAZgXD/lUluqqN4rrdRDxOXkaqupmqubRsTwCUgT7MWo4+7LW7O3cEOazkK/i4YdJ0mYsEjl1Lbch kUXQCwniyZulr38mY4knL5NoE3NOTO9qXOoLfq9NM27/4PeIV+/qqbN9sOiJ0tXHm/STkgx5f5vnc cWlBtt79aoxkTBRjBRQlUn8qTIRkbtstS7Ps3NP0FRP1cIV5tkycDSye0sGDpDGJqFar1jsH1IvL3 lzA87DHu5z9SpW91Ov1A==; 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 1h2KQY-0003z1-A9; Fri, 08 Mar 2019 18:41:02 +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 1h2KQV-0003oy-8F for linux-riscv@lists.infradead.org; Fri, 08 Mar 2019 18:41:01 +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=n/MJ1YOTuHIAgKL+4cRGmx1/4hwT8DJhkkwexhlK5s4=; b=FLGpSe37vu1gqyTp3Ho4efDiXii6jr9Dr0yHUnd+Ol8/kDYMUarIuacQVoQzc5DyUn5KpitV6ZDFn29+eSQQzKHr3LYYb5bH7mcUYNCEsqTc/9rTmpCXIqUhxT3mOU+XbomRPgHnvf86ps5hfAHepwGhJe6YQPhmBefQkk+Vj1s= 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:52 +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:52 +0000 From: Gary Guo Subject: [PATCH v2 4/4] riscv: rewrite tlb flush for performance Thread-Topic: [PATCH v2 4/4] riscv: rewrite tlb flush for performance Thread-Index: AQHU1d5vRDLalg67e0mBr2jahRUw7Q== Date: Fri, 8 Mar 2019 18:40:42 +0000 Message-ID: <33588efb3909a4d699a952f93c26ea2f3c8bfdc4.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: 702cd5c2-633c-4e81-f6db-08d6a3f59161 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:HqbDz5rjNj6Ri898lEzB9DyIodjKzrh6PGCMrVa?= =?iso-8859-1?q?2PCNTmTtKFc6VKC?= =?iso-8859-1?q?0fT524FCjhSTMVicZEOAn7377kB1Z+saPSKtobAWC37vl67ZD0SbdP+pyP0Q?= =?iso-8859-1?q?p1s8pg81O1/nYFcugpxICZQ/DQSnSb/fxayS1bJx3O3oKjanAub5XoLr76Dp?= =?iso-8859-1?q?bPsO5fbR1kav2EhCcAC9Uayjjxwm8TfNmQ3KQB7qkxw8fI0JkTY73f2ZiY9E?= =?iso-8859-1?q?5bIG6tQPTY1XsaIBu1c5V2PyqX3xaPhXMyY8MjT3l4b22E+G4HcB8XqndK3L?= =?iso-8859-1?q?swHpKNyJ0/RMrdeTNASQTM/CjSeNQnLka3waAzXghIlyrRuib0vQCH3HDEAk?= =?iso-8859-1?q?/d7FtqXuTrIv/WT29rXuqhqtn18C1yfNLLmMHIerkkcp5zVdZOjYrU1QbEV5?= =?iso-8859-1?q?p/5L+3UgokPiDtMZY5oTVro5nioTpruHlyLiIvzYdmQVPC0gzaXMbp8u+DDm?= =?iso-8859-1?q?M/MA2Btvf824DO3VUA79w1B3XaRa+kYWBD+42KV47VpyVyMZXZFkDNVxRJCP?= =?iso-8859-1?q?BJx/tmWFZwTEqjKLcVtjvEJbshIDT1OdSoq3J8VCcVLWmdQoNI46/lWE802A?= =?iso-8859-1?q?47FBK0BVRwHqJ0keqbDO1tHB9dgGHaQ2pZ4kvJGh/Lv+IeuYqs1dtvGTzoCF?= =?iso-8859-1?q?wq3JIUrrAL7BV4lKQEk5jUyTcSkJgy6Zv5G+5nXFeD+lycCgVL2GjZ7AEEKQ?= =?iso-8859-1?q?uOuL4SUk9WM9Hgqn1MxkBAYMReIiVp8qbFqiQ3InV8zdhjKAoa6YhEgvLTFV?= =?iso-8859-1?q?rNmKCaQhYt3Zi6uaEzkigOewyxTMLYhpp8UzDGcecMYutp/T4FOqD77T2E1+?= =?iso-8859-1?q?uHH7yDMF1+Tev0VrruYwFJ9j6FgWYYs1+okFf5W4mzQFGmXNBTRzpbCUl1sl?= =?iso-8859-1?q?E6lLe+LVZbq2ykkFcTifmDQtjAXEj/RqBZvogsfrvUy22LIQNQwnL4D+axFT?= =?iso-8859-1?q?LCkJgtgYH8OaxA2HodQaep+ouQtU8QE6mCP35sm3OZbrKLjaNDzF3/FWr8TU?= =?iso-8859-1?q?J6NIN+BDbaHb122tvR1+ub+FQmTLK89hnkFPtf0XuBIYwIflWjZ9NmMkkxO/?= =?iso-8859-1?q?IzyijG9fqcx886/jVJSTL7aYgwnoKwDYPiGO8wQjFMVkPcCs2bPd56iiD4Rf?= =?iso-8859-1?q?1SWKZuX5kAvmhhHXihq+cVfgb3/v/5lI/5MHqpvdVuBdJNFdbY6sw4/RI8A5?= =?iso-8859-1?q?FOyhHlz2ayr4nOj6XCNs2Ja0XTlENNIlhz0WejHQEZvoj+YN0EjoPAHHOtvF?= =?iso-8859-1?q?PdG27KjMmDOMz5gR7qBh34s8demh6Pm2W5ckEMnFKDbYg8RvUUmWuLnFZoGD?= =?iso-8859-1?q?5q9Imqmpk=3D?= 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)(30864003)(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)(2004002); 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: 8VuDR24P5IjpOuF7Tjwp49Kd8CRmJLwdytBflW2dLdB/B6kPTZcjGI0k4mgHo/y4Puj4P/QykTH6+o6l9s+zcUFGdaXmchyq7kN2PHxBTRdzam0zDQEyKxgie+sTvhDZbpvWElX324Ut0XNWTFsSMPO0kZkjkgAnkyTq7+7KX8hMYrUglumbke+GAcbyrcjIADH23EiMl5QFipQ8aKRPw5jqjk+dRzjQnE5o3TrbcyqqO6OjyUeoL+uLRFsU3+uPtnNuG+dK9+6hZEprnzaUKRpRPz163xMAT8lDDM955jrzIx76JxnH/6LLwuZ0hOO+8ktP2LQdC6+SrfE6TxhDZBIhIM4IlU3rRMK+1TToIT99fA0zVBW39Q6J8ocZQjOlzpydJzpDnvxARh/whVQ0stUwnybjRktegYRVlBZ5O+M= MIME-Version: 1.0 X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 702cd5c2-633c-4e81-f6db-08d6a3f59161 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2019 18:40:42.3196 (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_104059_314033_616543F7 X-CRM114-Status: GOOD ( 21.36 ) 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 This patch rewrites the logic related to TLB flushing, both to cleanup the code and to improve performance. We now use sfence.vma variant with specified ASID and virtual address whenever possible. Even though only ASID 0 is used, it still improves performance by preventing global mappings from being flushed from TLB. This patch also includes a IPI-based remote TLB shootdown, which is useful at this stage for testing because BBL/OpenSBI ignores operands of sbi_remote_sfence_vma_asid and always perform a global TLB flush. The SBI-based remote TLB shootdown can still be opt-in using boot cmdline "tlbi_method=sbi". Signed-off-by: Gary Guo --- arch/riscv/include/asm/pgtable.h | 2 +- arch/riscv/include/asm/tlbflush.h | 73 ++++------ arch/riscv/mm/Makefile | 1 + arch/riscv/mm/context.c | 8 +- arch/riscv/mm/tlbflush.c | 216 ++++++++++++++++++++++++++++++ 5 files changed, 252 insertions(+), 48 deletions(-) create mode 100644 arch/riscv/mm/tlbflush.c diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 16301966d65b..47a8616b9de0 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -279,7 +279,7 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, * Relying on flush_tlb_fix_spurious_fault would suffice, but * the extra traps reduce performance. So, eagerly SFENCE.VMA. */ - local_flush_tlb_page(address); + local_flush_tlb_page(vma, address); } #define __HAVE_ARCH_PTE_SAME diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index 54fee0cadb1e..d6c247ce17f3 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -1,22 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (C) 2009 Chen Liqin * Copyright (C) 2012 Regents of the University of California - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * Copyright (C) 2019 Gary Guo, University of Cambridge */ #ifndef _ASM_RISCV_TLBFLUSH_H #define _ASM_RISCV_TLBFLUSH_H #include -#include /* * Flush entire local TLB. 'sfence.vma' implicitly fences with the instruction @@ -27,53 +19,42 @@ static inline void local_flush_tlb_all(void) __asm__ __volatile__ ("sfence.vma" : : : "memory"); } -/* Flush one page from local TLB */ -static inline void local_flush_tlb_page(unsigned long addr) +static inline void local_flush_tlb_mm(struct mm_struct *mm) { - __asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory"); + /* Flush ASID 0 so that global mappings are not affected */ + __asm__ __volatile__ ("sfence.vma x0, %0" : : "r" (0) : "memory"); } -#ifndef CONFIG_SMP - -#define flush_tlb_all() local_flush_tlb_all() -#define flush_tlb_page(vma, addr) local_flush_tlb_page(addr) - -static inline void flush_tlb_range(struct vm_area_struct *vma, - unsigned long start, unsigned long end) +static inline void local_flush_tlb_page(struct vm_area_struct *vma, + unsigned long addr) { - local_flush_tlb_all(); + __asm__ __volatile__ ("sfence.vma %0, %1" + : : "r" (addr), "r" (0) + : "memory"); } -#define flush_tlb_mm(mm) flush_tlb_all() +void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, + unsigned long end); +void local_flush_tlb_kernel_range(unsigned long start, unsigned long end); -#else /* CONFIG_SMP */ - -#include +#ifdef CONFIG_SMP -static inline void remote_sfence_vma(struct cpumask *cmask, unsigned long start, - unsigned long size) -{ - struct cpumask hmask; +void flush_tlb_all(void); +void flush_tlb_mm(struct mm_struct *mm); +void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr); +void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, + unsigned long end); +void flush_tlb_kernel_range(unsigned long start, unsigned long end); - cpumask_clear(&hmask); - riscv_cpuid_to_hartid_mask(cmask, &hmask); - sbi_remote_sfence_vma(hmask.bits, start, size); -} +#else /* CONFIG_SMP */ -#define flush_tlb_all() sbi_remote_sfence_vma(NULL, 0, -1) -#define flush_tlb_page(vma, addr) flush_tlb_range(vma, addr, 0) -#define flush_tlb_range(vma, start, end) \ - remote_sfence_vma(mm_cpumask((vma)->vm_mm), start, (end) - (start)) -#define flush_tlb_mm(mm) \ - remote_sfence_vma(mm_cpumask(mm), 0, -1) +#define flush_tlb_all() local_flush_tlb_all() +#define flush_tlb_mm(mm) local_flush_tlb_mm(mm) +#define flush_tlb_page(vma, addr) local_flush_tlb_page(vma, addr) +#define flush_tlb_range(vma, start, end) local_flush_tlb_range(vma, start, end) +#define flush_tlb_kernel_range(start, end) \ + local_flush_tlb_kernel_range(start, end) #endif /* CONFIG_SMP */ -/* Flush a range of kernel pages */ -static inline void flush_tlb_kernel_range(unsigned long start, - unsigned long end) -{ - flush_tlb_all(); -} - #endif /* _ASM_RISCV_TLBFLUSH_H */ diff --git a/arch/riscv/mm/Makefile b/arch/riscv/mm/Makefile index d75b035786d6..53b68fd3cb45 100644 --- a/arch/riscv/mm/Makefile +++ b/arch/riscv/mm/Makefile @@ -4,3 +4,4 @@ obj-y += extable.o obj-y += ioremap.o obj-y += cacheflush.o obj-y += context.o +obj-y += tlbflush.o diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c index fbb1cfe80267..0f787bcd3a7a 100644 --- a/arch/riscv/mm/context.c +++ b/arch/riscv/mm/context.c @@ -64,7 +64,13 @@ void switch_mm(struct mm_struct *prev, struct mm_struct *next, * privileged ISA 1.10 yet. */ csr_write(sptbr, virt_to_pfn(next->pgd) | SATP_MODE); - local_flush_tlb_all(); + + /* + * sfence.vma after SATP write. We call it on MM context instead of + * calling local_flush_tlb_all to prevent global mappings from being + * affected. + */ + local_flush_tlb_mm(next); flush_icache_deferred(next); } diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c new file mode 100644 index 000000000000..b4b35e825495 --- /dev/null +++ b/arch/riscv/mm/tlbflush.c @@ -0,0 +1,216 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2019 Gary Guo, University of Cambridge + */ + +#include +#include + +#define SFENCE_VMA_FLUSH_ALL ((unsigned long) -1) + +/* + * This controls the maximum amount of page-level sfence.vma that the kernel + * can issue when the kernel needs to flush a range from the TLB. If the size + * of range goes beyond this threshold, a full sfence.vma is issued. + * + * Increase this number can negatively impact performance on implemntations + * where sfence.vma's address operand is ignored and always perform a global + * TLB flush. On the other hand, implementations with page-level TLB flush + * support can benefit from a larger number. + */ +static unsigned long tlbi_range_threshold = PAGE_SIZE; + +static int __init setup_tlbi_max_ops(char *str) +{ + int value = 0; + + get_option(&str, &value); + + /* + * This value cannot be greater or equal to PTRS_PER_PTE, as we need + * to full flush for any non-leaf page table change. The value has also + * be at least 1. + */ + if (value >= PTRS_PER_PTE || value < 1) + return 0; + + tlbi_range_threshold = value * PAGE_SIZE; + return 1; +} +__setup("tlbi_max_ops=", setup_tlbi_max_ops); + +void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, + unsigned long end) +{ + if (end - start > tlbi_range_threshold) { + local_flush_tlb_mm(vma->vm_mm); + return; + } + + while (start < end) { + __asm__ __volatile__ ("sfence.vma %0, %1" + : : "r" (start), "r" (0) + : "memory"); + start += PAGE_SIZE; + } +} + +void local_flush_tlb_kernel_range(unsigned long start, unsigned long end) +{ + if (end - start > tlbi_range_threshold) { + local_flush_tlb_all(); + return; + } + + while (start < end) { + __asm__ __volatile__ ("sfence.vma %0" + : : "r" (start) + : "memory"); + start += PAGE_SIZE; + } +} + +#ifdef CONFIG_SMP + +/* + * BBL/OpenSBI are currently ignoring ASID and address range provided + * by SBI call argument, and do a full TLB flush instead. This may + * negatively impact performance on implementations with page-level + * sfence.vma support. + * + * We provide an IPI-based remote shootdown implementation to improve + * performance on implementations with page-level sfence.vma, and also to + * allow testing of these implementations. + * + * This parameter allows the approach (IPI/SBI) to be specified using boot + * cmdline. + */ +static bool tlbi_ipi = true; + +static int __init setup_tlbi_method(char *str) +{ + if (strcmp(str, "ipi") == 0) + tlbi_ipi = true; + else if (strcmp(str, "sbi") == 0) + tlbi_ipi = false; + else + return 0; + + return 1; +} +__setup("tlbi_method=", setup_tlbi_method); + + +struct tlbi { + unsigned long start; + unsigned long size; + unsigned long asid; +}; + +static void ipi_remote_sfence_vma(void *info) +{ + struct tlbi *data = info; + unsigned long start = data->start; + unsigned long size = data->size; + unsigned long i; + + for (i = 0; i < size; i += PAGE_SIZE) { + __asm__ __volatile__ ("sfence.vma %0" + : : "r" (start + i) + : "memory"); + } +} + +static void ipi_remote_sfence_vma_asid(void *info) +{ + struct tlbi *data = info; + unsigned long asid = data->asid; + unsigned long start = data->start; + unsigned long size = data->size; + unsigned long i; + + /* Flush entire MM context */ + if (size == SFENCE_VMA_FLUSH_ALL) { + __asm__ __volatile__ ("sfence.vma x0, %0" + : : "r" (asid) + : "memory"); + return; + } + + for (i = 0; i < size; i += PAGE_SIZE) { + __asm__ __volatile__ ("sfence.vma %0, %1" + : : "r" (start + i), "r" (asid) + : "memory"); + } +} + +static void remote_sfence_vma(unsigned long start, unsigned long size) +{ + if (tlbi_ipi) { + struct tlbi info = { + .start = start, + .size = size, + }; + on_each_cpu(ipi_remote_sfence_vma, &info, 1); + } else + sbi_remote_sfence_vma(NULL, start, size); +} + +static void remote_sfence_vma_asid(cpumask_t *mask, unsigned long start, + unsigned long size, unsigned long asid) +{ + if (tlbi_ipi) { + struct tlbi info = { + .start = start, + .size = size, + .asid = asid, + }; + on_each_cpu_mask(mask, ipi_remote_sfence_vma_asid, &info, 1); + } else { + cpumask_t hmask; + + cpumask_clear(&hmask); + riscv_cpuid_to_hartid_mask(mask, &hmask); + sbi_remote_sfence_vma_asid(hmask.bits, start, size, asid); + } +} + + +void flush_tlb_all(void) +{ + sbi_remote_sfence_vma(NULL, 0, SFENCE_VMA_FLUSH_ALL); +} + +void flush_tlb_mm(struct mm_struct *mm) +{ + remote_sfence_vma_asid(mm_cpumask(mm), 0, SFENCE_VMA_FLUSH_ALL, 0); +} + +void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr) +{ + remote_sfence_vma_asid(mm_cpumask(vma->vm_mm), addr, PAGE_SIZE, 0); +} + + +void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, + unsigned long end) +{ + if (end - start > tlbi_range_threshold) { + flush_tlb_mm(vma->vm_mm); + return; + } + + remote_sfence_vma_asid(mm_cpumask(vma->vm_mm), start, end - start, 0); +} + +void flush_tlb_kernel_range(unsigned long start, unsigned long end) +{ + if (end - start > tlbi_range_threshold) { + flush_tlb_all(); + return; + } + + remote_sfence_vma(start, end - start); +} + +#endif /* CONFIG_SMP */