Received: by 10.213.65.68 with SMTP id h4csp499383imn; Fri, 16 Mar 2018 09:36:09 -0700 (PDT) X-Google-Smtp-Source: AG47ELtL6q07hjBua7cIl0gmWJuNu0umgG7WUXBd2p+pPWO13K7uj/CuL4YNGkBi4FTOabFpxG6p X-Received: by 2002:a17:902:2884:: with SMTP id f4-v6mr2775042plb.153.1521218169915; Fri, 16 Mar 2018 09:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521218169; cv=none; d=google.com; s=arc-20160816; b=LUZY33RPck0iuYLmIjTga+KR5zjzlAOasuNLJg/aP+dMAF2VkN9IG2ATSx2lNFiogm V2DoS8z7VCoHDpq8XO+22/i0CMgyiVIepZamQWpRVXUX7DaJxhEDReIDyXYeSWOCe4Rb hEvBpYI9jM7/t7sXIEVDbpFxEyRCfoEeoEIvtKiQRK9+x7wRHo0oFTO19ALwImYeh9R8 RK7lka2HUSmBJsIRj78W3zeclLIlUg/mwikwXipZzwXXCAoj0xL9YTKjrYPNNUt2uKUE t7LvP+5RGzddOGEeBUg83Rus9+efW8uEvJCOi6EEXfhwHHaoOc/z7plli9H0SSps6gCJ jyzQ== 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=6TW5MAXvNYXwelzG6rgACMqpjrGkLbgeh69SckMcyuo=; b=gLs56QVl9VZs/d4nPwCbrOPiI1bg0EAeC4U3uiddXvNdcScIQXQsSGXEghhs+knuv0 Of+7+CaECoIQIzigxKzSBlTpv5kOkSxvJwQ4xf3mD8peLY3X94LRJmN7Tak/nhKUer4D 9JUSFCEFphK8PGGjgO78z4k+0cjIPivSqwwpQyA04B0+9L74NcbEURY7RC9ARm8tgAIj zQRX6a5urNB48zTKs/r85mRT5QU+TnNqzodeVKLhfPN9J2MHWK2tzbm71mlIQ7D1feY1 AIVHCmhod1vVbSAb94vm3QcqpAtepcGbj8rH33USLSt5FCFOk5O0VtUh/cNLUaqFDA10 PscA== 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 m5si5120792pgv.487.2018.03.16.09.35.55; Fri, 16 Mar 2018 09:36:09 -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 S1754471AbeCPPiN (ORCPT + 99 others); Fri, 16 Mar 2018 11:38:13 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42154 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750749AbeCPPiJ (ORCPT ); Fri, 16 Mar 2018 11:38:09 -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 C02FB1225; Fri, 16 Mar 2018 15:38:08 +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.14 093/109] powerpc/modules: Dont try to restore r2 after a sibling call Date: Fri, 16 Mar 2018 16:24:02 +0100 Message-Id: <20180316152334.964491242@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152329.844663293@linuxfoundation.org> References: <20180316152329.844663293@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.14-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 @@ -486,7 +486,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;