From patchwork Tue Mar 29 18:54:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John David Anglin X-Patchwork-Id: 12795204 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2744BC433F5 for ; Tue, 29 Mar 2022 18:54:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239585AbiC2S4a (ORCPT ); Tue, 29 Mar 2022 14:56:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237828AbiC2S43 (ORCPT ); Tue, 29 Mar 2022 14:56:29 -0400 Received: from cmx-torrgo002.bell.net (mta-tor-005.bell.net [209.71.212.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 95F5622E953 for ; Tue, 29 Mar 2022 11:54:45 -0700 (PDT) X-RG-CM-BuS: 0 X-RG-CM-SC: 0 X-RG-CM: Clean X-Originating-IP: [70.50.7.94] X-RG-Env-Sender: dave.anglin@bell.net X-RG-Rigid: 6243254D0005D102 X-CM-Envelope: MS4xfBllL5ENdj3dX0GR9RQ383zqxCETF66gPrNeYcPx+XCDfQLXlS5VH2mOXkAndvArpuIVVChsaWwv0eAk1/L/PnJCuL8iBVsIMyxeFYUNGGy/OHRD9H9x 2ZKL83gHj2OGxthEZMGJcRstSSpyXQraYVUx0L+B3LEHUNBEoFvLl1o8HLoZ0Yej5asK8yC9ICyC3o0MMzGsbgUDf06BqWFHZDBKo0vz7KEc1GG0kQ/bymPd UVCsA0DtDmpJbCi6ybvWkmnUsZ0eb2N1xoohR6mJcwPAAJkY084vx4gvwhd4oqCfAGD4AEbeLFHL71KMMWo1Nl76pkz5I1KKGbRy5iBrcvjL5Q9gWoDZrjso 96PRyzc6HUH42mZ5w255f5/UchIyMsFQrkyK7O8FLnk9jYHv44CUxxzfJEysFOuufAeBtWHVXgJJXSYY1nBluZQKMME/sd2g0w8OiNeXt+TVO2/GmOAjHT6u BGfGrvZssdgSoBHGWvhXYq4NJeJVEEs1oJfg/hIY8asKx2dO0MIxj8dD9dJ7n1q1n8z+zwIzrYXeV78w00FvPilpCqdHQLsjwPG5uJOWJTQf3yW0s90LtQIG v+cy/p3qsf5qV+Sf0X8aRYHPr2YUsSAQKZij256bcJ7D+w== X-CM-Analysis: v=2.4 cv=G99/r/o5 c=1 sm=1 tr=0 ts=624355ed a=9k1bCY7nR7m1ZFzoCuQ56g==:117 a=9k1bCY7nR7m1ZFzoCuQ56g==:17 a=o8Y5sQTvuykA:10 a=FBHGMhGWAAAA:8 a=Fe-wxvhmr2ytpZrFxScA:9 a=CjuIK1q_8ugA:10 a=LX2NGLxKwRSNBg788TcA:9 a=FfaGCDsud1wA:10 a=9gvnlMMaQFpL9xblJ6ne:22 Received: from mx3210.localdomain (70.50.7.94) by cmx-torrgo002.bell.net (5.8.807) (authenticated as dave.anglin@bell.net) id 6243254D0005D102; Tue, 29 Mar 2022 14:54:37 -0400 Received: by mx3210.localdomain (Postfix, from userid 1000) id 1D431220115; Tue, 29 Mar 2022 18:54:36 +0000 (UTC) Date: Tue, 29 Mar 2022 18:54:36 +0000 From: John David Anglin To: linux-parisc@vger.kernel.org Cc: Helge Deller , Deller , James Bottomley Subject: [PATCH] parisc: Fix patch code locking and flushing Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org This change fixes the following: 1) The flags variable is not initialized. Always use raw_spin_lock_irqsave and raw_spin_unlock_irqrestore to serialize patching. 2) flush_kernel_vmap_range is primarily intended for DMA flushes. Since __patch_text_multiple is often called with interrupts disabled, it is better to directly call flush_kernel_dcache_range_asm and flush_kernel_icache_range_asm. This avoids an extra call. 3) The final call to flush_icache_range is unnecessary. Signed-off-by: John David Anglin diff --git a/arch/parisc/kernel/patch.c b/arch/parisc/kernel/patch.c index 80a0ab372802..e59574f65e64 100644 --- a/arch/parisc/kernel/patch.c +++ b/arch/parisc/kernel/patch.c @@ -40,10 +40,7 @@ static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags, *need_unmap = 1; set_fixmap(fixmap, page_to_phys(page)); - if (flags) - raw_spin_lock_irqsave(&patch_lock, *flags); - else - __acquire(&patch_lock); + raw_spin_lock_irqsave(&patch_lock, *flags); return (void *) (__fix_to_virt(fixmap) + (uintaddr & ~PAGE_MASK)); } @@ -52,10 +49,7 @@ static void __kprobes patch_unmap(int fixmap, unsigned long *flags) { clear_fixmap(fixmap); - if (flags) - raw_spin_unlock_irqrestore(&patch_lock, *flags); - else - __release(&patch_lock); + raw_spin_unlock_irqrestore(&patch_lock, *flags); } void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len) @@ -67,8 +61,9 @@ void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len) int mapped; /* Make sure we don't have any aliases in cache */ - flush_kernel_vmap_range(addr, len); - flush_icache_range(start, end); + flush_kernel_dcache_range_asm(start, end); + flush_kernel_icache_range_asm(start, end); + flush_tlb_kernel_range(start, end); p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &flags, &mapped); @@ -81,8 +76,10 @@ void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len) * We're crossing a page boundary, so * need to remap */ - flush_kernel_vmap_range((void *)fixmap, - (p-fixmap) * sizeof(*p)); + flush_kernel_dcache_range_asm((unsigned long)fixmap, + (unsigned long)p); + flush_tlb_kernel_range((unsigned long)fixmap, + (unsigned long)p); if (mapped) patch_unmap(FIX_TEXT_POKE0, &flags); p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &flags, @@ -90,10 +87,10 @@ void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len) } } - flush_kernel_vmap_range((void *)fixmap, (p-fixmap) * sizeof(*p)); + flush_kernel_dcache_range_asm((unsigned long)fixmap, (unsigned long)p); + flush_tlb_kernel_range((unsigned long)fixmap, (unsigned long)p); if (mapped) patch_unmap(FIX_TEXT_POKE0, &flags); - flush_icache_range(start, end); } void __kprobes __patch_text(void *addr, u32 insn)