Received: by 10.213.65.68 with SMTP id h4csp475379imn; Fri, 16 Mar 2018 08:54:05 -0700 (PDT) X-Google-Smtp-Source: AG47ELtqR7Dk9FM9ZbW4PNmqCx/o6bmztHGSpR0/q+oShh3FTGaFmHxwv7MBXFNpEUmY1xXAcQdo X-Received: by 2002:a17:902:20e5:: with SMTP id v34-v6mr2742906plg.66.1521215645355; Fri, 16 Mar 2018 08:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521215645; cv=none; d=google.com; s=arc-20160816; b=DWuCb3YVc+FkL7L/TR4jqDLAAieMFZ1ouV1bXoVkL5Eh3v/ORCAqyeHwhcT2ittS75 bh+OZxwIzHYDiymNodV3cK5vd7m7hDJV97NyKtP+YDKr9bzS15Oa1Ua2VcgYJQ5uNB2m ryPJiQp/SdClsSrH2JoTnH0Jfa2Zxy6PFtCvOcatqpbpJ8iv8GxNJaPkiSDaxFViedi1 +sgCVeu7DJ9XVZP/zCt+E2ZtFBccOwdCwEUQvSJ+aHJfToxdztIkPCYAiqhdsX9MO/MZ cAfwVWrZdr8EqPHZS2P1jyXCUtb+uoc+F8pms5w7wAUYIiCs3zrZPGzI5DPjhdKYqfD+ +14g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=hYrCcHsAuSekIHPgUBop8ma6R9rHSLomomX0f8c6EKs=; b=rfmqeVSQ6XHbn7Lfn5jHcUDTEwo5+Nv/OW7SbeAP+fLZ7WdCcGk4wErfHhGbggoCWP i3ZG6DuyZMw3e/t7P/J49o1i/4DAVSM+ihCFEaayjjUjiRX1VdzqRy+8mKX3FZNBte+c YqWnMj4EG/HxmQH/mDHdeGJarJeOx3vWmbgcPKCX6w2FjjV7M4sVyM8fJvrZ2H6bcxXo 2YUQTWNTn3GDhWN5E7+eOuJ2a4oUnB/QNFCgg5rliusDsLfIfMNg6pQUC43mHlPK7KAf ls0tnHVkhIEg8I3/1iCOpCw7yT4Hoa7jPBFj/AYAbZXqFOHya9klbCv37LCjGdFdv+d9 s72g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si6395788plk.52.2018.03.16.08.53.51; Fri, 16 Mar 2018 08:54:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934430AbeCPPwU (ORCPT + 99 others); Fri, 16 Mar 2018 11:52:20 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45918 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965406AbeCPPoU (ORCPT ); Fri, 16 Mar 2018 11:44:20 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 912C0D13; Fri, 16 Mar 2018 15:44:19 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josh Poimboeuf , "Naveen N. Rao" , Michael Ellerman , Sasha Levin Subject: [PATCH 4.15 112/128] powerpc/modules: Dont try to restore r2 after a sibling call Date: Fri, 16 Mar 2018 16:24:13 +0100 Message-Id: <20180316152342.100812759@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152336.199007505@linuxfoundation.org> References: <20180316152336.199007505@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josh Poimboeuf [ Upstream commit b9eab08d012fa093947b230f9a87257c27fb829b ] When attempting to load a livepatch module, I got the following error: module_64: patch_module: Expect noop after relocate, got 3c820000 The error was triggered by the following code in unregister_netdevice_queue(): 14c: 00 00 00 48 b 14c 14c: R_PPC64_REL24 net_set_todo 150: 00 00 82 3c addis r4,r2,0 GCC didn't insert a nop after the branch to net_set_todo() because it's a sibling call, so it never returns. The nop isn't needed after the branch in that case. Signed-off-by: Josh Poimboeuf Acked-by: Naveen N. Rao Reviewed-and-tested-by: Kamalesh Babulal Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/include/asm/code-patching.h | 1 + arch/powerpc/kernel/module_64.c | 12 +++++++++++- arch/powerpc/lib/code-patching.c | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) --- a/arch/powerpc/include/asm/code-patching.h +++ b/arch/powerpc/include/asm/code-patching.h @@ -33,6 +33,7 @@ int patch_branch(unsigned int *addr, uns int patch_instruction(unsigned int *addr, unsigned int instr); int instr_is_relative_branch(unsigned int instr); +int instr_is_relative_link_branch(unsigned int instr); int instr_is_branch_to_addr(const unsigned int *instr, unsigned long addr); unsigned long branch_target(const unsigned int *instr); unsigned int translate_branch(const unsigned int *dest, --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -487,7 +487,17 @@ static bool is_early_mcount_callsite(u32 restore r2. */ static int restore_r2(u32 *instruction, struct module *me) { - if (is_early_mcount_callsite(instruction - 1)) + u32 *prev_insn = instruction - 1; + + if (is_early_mcount_callsite(prev_insn)) + return 1; + + /* + * Make sure the branch isn't a sibling call. Sibling calls aren't + * "link" branches and they don't return, so they don't need the r2 + * restore afterwards. + */ + if (!instr_is_relative_link_branch(*prev_insn)) return 1; if (*instruction != PPC_INST_NOP) { --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -302,6 +302,11 @@ int instr_is_relative_branch(unsigned in return instr_is_branch_iform(instr) || instr_is_branch_bform(instr); } +int instr_is_relative_link_branch(unsigned int instr) +{ + return instr_is_relative_branch(instr) && (instr & BRANCH_SET_LINK); +} + static unsigned long branch_iform_target(const unsigned int *instr) { signed long imm;