Received: by 10.223.185.116 with SMTP id b49csp1094152wrg; Sat, 3 Mar 2018 15:22:51 -0800 (PST) X-Google-Smtp-Source: AG47ELsAzcta6QHlRY9j6eev+My0BjTuPtq68pYbpEQy5uFrnz9dN9li2ade/O1mV2UGgV6fwi2v X-Received: by 2002:a17:902:7c03:: with SMTP id x3-v6mr1812732pll.94.1520119371196; Sat, 03 Mar 2018 15:22:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520119371; cv=none; d=google.com; s=arc-20160816; b=k0ImoxdQtDPj+QVolEoHogbb/C9ex8wnygctszXz2pVe1gLlmThOYtOT+oR8dbkLHg 6lNtz0f0HTuz05tiQMieb10xst6g43qRIQXXb+3QbqKZNL3HsKCyfKv8rYfF2ugVdJyF 6E2vANVpcseDpyWb/Qb9Kd8ar1ploWlr2ReRp20xKyFfoaOulFuOHF6ox1D3A8rL9WUq 8uZwKGvZlM0jAH5N2CQTWxrCIlXNHujtLqaISN6gRm3bjt3dJy2/ecZS26oq7ZAfYTy+ 8QccTlY+MWNvkXqDf+BN2xAl8KkNusO6vN0YJN93h4ZKTv9qWL/PcRA3yd/DXYBxW4Hv StKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=4OekRN5BIXJ/ljiJXWcmgnsCmQuRMOCo33Ym+GcEtKk=; b=SqrxfigAO/1WGA1AdQ+ksWzkj9Bbes58cmn+D/aNlU97VHMikmse3bkp3t07mfcCOv DMQYY1jh4A+uHR6F5hicc4rPrShXf3wtbPYsHtqszWFSysIjw6o+BqzSSH2I6ad8+dkf aVL9jfEigjifqSOiF3kKqNZDU0t0sjBQZWKBqk2Yq/iXomkqN5U7gIf2inpurBX2WLlz qRcWEFeIAmJQi9Q6nVFRsJFRVJ5b86uSOKJNR3ZX++0auCriIVNH7/jrAqvM9AG+7acN n5UjyOKtQS0czwWBOgkaf/Ph2H1kxz3C684Nvsq++WaNDx8ehVPrFrT71tnNlA3hQx1b eDRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=ZIAEroBm; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n10-v6si6773567plk.255.2018.03.03.15.22.37; Sat, 03 Mar 2018 15:22:51 -0800 (PST) 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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=ZIAEroBm; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934727AbeCCWh4 (ORCPT + 99 others); Sat, 3 Mar 2018 17:37:56 -0500 Received: from mail-co1nam03on0134.outbound.protection.outlook.com ([104.47.40.134]:45128 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932373AbeCCWht (ORCPT ); Sat, 3 Mar 2018 17:37:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=4OekRN5BIXJ/ljiJXWcmgnsCmQuRMOCo33Ym+GcEtKk=; b=ZIAEroBmSIAUfsQ6q9aAxb/PKCxXCv4esfXuRYwnzfh+AIVxubZYvgeRfaL0CJZ0LHPM/tEs58kn3AbbQz0oL+9QZEzR1/+Ho1WI7Hh4RU85DimrHVLmIHMaDbqSDW63tP1JdjlGbhHNBOYvBQiTXbUZayfjUg5HXBAcQmKFrq8= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB1100.namprd21.prod.outlook.com (52.132.149.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.2; Sat, 3 Mar 2018 22:37:46 +0000 Received: from MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0]) by MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0%3]) with mapi id 15.20.0567.006; Sat, 3 Mar 2018 22:37:46 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Josh Poimboeuf , Michael Ellerman , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 211/219] powerpc/modules: Don't try to restore r2 after a sibling call Thread-Topic: [PATCH AUTOSEL for 4.9 211/219] powerpc/modules: Don't try to restore r2 after a sibling call Thread-Index: AQHTsz8piJWHAC6hfE6hnS3sQ8saBQ== Date: Sat, 3 Mar 2018 22:29:59 +0000 Message-ID: <20180303222716.26640-211-alexander.levin@microsoft.com> References: <20180303222716.26640-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222716.26640-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MW2PR2101MB1100;7:NeXIYf5n/sXKSJzH7/vXjRDb8RO5oiQ4UMeuQNMN4900oPa5oEHARtV/iqjTA02MG6chmMbkj4EsQ9eRHX3oHn3rmgs4uXEUg4y52FUmqkbZJmipgwXxPHGJIcObdL1/kbPTUJThV3Nt+zsVE6drHqWeEvbOE2AdCtIIwqfChKBfT3IGxRLUDj8RODovEb59UVQPsmudw4Be4VFX1dMwU0vujZBf7vXUD1mZa70weQP7Vf1BoRySaNC257c4FD9G x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 327beb83-cab9-4e41-a21e-08d581576327 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:MW2PR2101MB1100; x-ms-traffictypediagnostic: MW2PR2101MB1100: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(104084551191319); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(5005006)(8121501046)(10201501046)(3002001)(3231220)(944501244)(52105095)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123560045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:MW2PR2101MB1100;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB1100; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(376002)(39860400002)(396003)(366004)(346002)(199004)(189003)(22452003)(97736004)(7736002)(5250100002)(105586002)(2906002)(6506007)(72206003)(66066001)(59450400001)(4326008)(305945005)(10290500003)(186003)(3280700002)(102836004)(2950100002)(6666003)(2501003)(478600001)(26005)(2900100001)(10090500001)(53936002)(8676002)(25786009)(81166006)(81156014)(54906003)(86362001)(6436002)(106356001)(110136005)(68736007)(36756003)(316002)(6512007)(5660300001)(107886003)(8936002)(1076002)(6486002)(3660700001)(99286004)(76176011)(3846002)(86612001)(14454004)(6116002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB1100;H:MW2PR2101MB1034.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: DwvRIqd/vt/YflSI15qC/dN5sbwuCyvKLy5UZ7DePaAaa2QOxkoW9PFc1jGDGRy4HCUy0SxwvlxmZYtUpUPsNd/Dpn6Vt5r4pD84rtz3Kx2DHrWaX9Ir6cX+lDxva93W3q0w2ON+IgbR11BCmh0dbwH90TMlCPCSMUeuFYIsab4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 327beb83-cab9-4e41-a21e-08d581576327 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:29:59.3539 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB1100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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(-) diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/includ= e/asm/code-patching.h index 2015b072422c..b4ab1f497335 100644 --- a/arch/powerpc/include/asm/code-patching.h +++ b/arch/powerpc/include/asm/code-patching.h @@ -30,6 +30,7 @@ int patch_branch(unsigned int *addr, unsigned long target= , int flags); int patch_instruction(unsigned int *addr, unsigned int instr); =20 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, diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_6= 4.c index 183368e008cf..99407cf12ad5 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -494,7 +494,17 @@ static bool is_early_mcount_callsite(u32 *instruction) restore r2. */ static int restore_r2(u32 *instruction, struct module *me) { - if (is_early_mcount_callsite(instruction - 1)) + u32 *prev_insn =3D 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; =20 if (*instruction !=3D PPC_INST_NOP) { diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patch= ing.c index d5edbeb8eb82..753d591f1b52 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -95,6 +95,11 @@ int instr_is_relative_branch(unsigned int instr) return instr_is_branch_iform(instr) || instr_is_branch_bform(instr); } =20 +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; --=20 2.14.1