From patchwork Wed Jun 5 20:32:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Schnelle X-Patchwork-Id: 10977799 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 128781515 for ; Wed, 5 Jun 2019 20:32:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00E3D28421 for ; Wed, 5 Jun 2019 20:32:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E92DD289FB; Wed, 5 Jun 2019 20:32: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CB0C28421 for ; Wed, 5 Jun 2019 20:32:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726543AbfFEUc0 (ORCPT ); Wed, 5 Jun 2019 16:32:26 -0400 Received: from smtp.duncanthrax.net ([89.31.1.170]:57192 "EHLO smtp.duncanthrax.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726527AbfFEUc0 (ORCPT ); Wed, 5 Jun 2019 16:32:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=duncanthrax.net; s=dkim; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=DkSDqDpsMdGGavYvzoKFcsAqjPo7XeGtb6IBNsHEjGI=; b=nnSpg6ljkl8gllaIHPd5+9WK37 0wL1OkfZwwdfOqQ5ge0cdzJckLyVoRAZibsR6c+btnfRGKvZvyvMvBbaekiOdRizHeDLmmOXWING9 g6qJwNDXaK8AsTc2OKvnHT4cNpCfhc6EWI9jJrEO0hFrF9J+xbK1qsyFnBr13uC76Q0Y=; Received: from [134.3.44.134] (helo=t470p.stackframe.org) by smtp.eurescom.eu with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1hYca8-0004ei-Q0; Wed, 05 Jun 2019 22:32:24 +0200 From: Sven Schnelle To: deller@gmx.de Cc: linux-parisc@vger.kernel.org, Sven Schnelle Subject: [PATCH v3 2/6] parisc: add spinlock to patch function Date: Wed, 5 Jun 2019 22:32:18 +0200 Message-Id: <20190605203222.6194-3-svens@stackframe.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190605203222.6194-1-svens@stackframe.org> References: <20190605203222.6194-1-svens@stackframe.org> MIME-Version: 1.0 Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If multiple CPUs are patching code we need the spinlock to protect against parallel fixmap maps/unmap calls. Signed-off-by: Sven Schnelle --- arch/parisc/kernel/patch.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/arch/parisc/kernel/patch.c b/arch/parisc/kernel/patch.c index 70e9997a3f80..80a0ab372802 100644 --- a/arch/parisc/kernel/patch.c +++ b/arch/parisc/kernel/patch.c @@ -23,7 +23,9 @@ struct patch { static DEFINE_RAW_SPINLOCK(patch_lock); -static void __kprobes *patch_map(void *addr, int fixmap, int *need_unmap) +static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags, + int *need_unmap) +{ unsigned long uintaddr = (uintptr_t) addr; bool module = !core_kernel_text(uintaddr); struct page *page; @@ -38,19 +40,29 @@ static void __kprobes *patch_map(void *addr, int fixmap, int *need_unmap) *need_unmap = 1; set_fixmap(fixmap, page_to_phys(page)); + if (flags) + raw_spin_lock_irqsave(&patch_lock, *flags); + else + __acquire(&patch_lock); return (void *) (__fix_to_virt(fixmap) + (uintaddr & ~PAGE_MASK)); } -static void __kprobes patch_unmap(int fixmap) +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); } void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len) { unsigned long start = (unsigned long)addr; unsigned long end = (unsigned long)addr + len; + unsigned long flags; u32 *p, *fixmap; int mapped; @@ -58,7 +70,7 @@ void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len) flush_kernel_vmap_range(addr, len); flush_icache_range(start, end); - p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &mapped); + p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &flags, &mapped); while (len >= 4) { *p++ = *insn++; @@ -72,14 +84,15 @@ void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len) flush_kernel_vmap_range((void *)fixmap, (p-fixmap) * sizeof(*p)); if (mapped) - patch_unmap(FIX_TEXT_POKE0); - p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &mapped); + patch_unmap(FIX_TEXT_POKE0, &flags); + p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &flags, + &mapped); } } flush_kernel_vmap_range((void *)fixmap, (p-fixmap) * sizeof(*p)); if (mapped) - patch_unmap(FIX_TEXT_POKE0); + patch_unmap(FIX_TEXT_POKE0, &flags); flush_icache_range(start, end); }