Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3110339ybi; Thu, 18 Jul 2019 21:13:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqAML67sG9UVtwxiobW7NT0qCEn1W9aiF5zDri3mDJJGzPxlGQ6BpnThmaIJ5kOQIXROm6 X-Received: by 2002:a17:902:4e25:: with SMTP id f34mr54021506ple.305.1563509604246; Thu, 18 Jul 2019 21:13:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563509604; cv=none; d=google.com; s=arc-20160816; b=neazFjF3y9ZbA/N3Sd7W+h3KoD7Rkty4wNQA3K/F02Sp6r5CXj/+uwfoa6/Rei69mI CPZtaoI5oN85pPyYNEgSadQkHNh7sTlIjvYM1mJXDyqzzoiVCRIlxGTfA07zksXpJs0A 2LhQ7KguH/UtRckXdSVEdY1lNd7amcvyOCt7O3q/KREmTWQKJxuA7E4vt9SvTExeJGCS 9L9IyqaDecdbL0YpBjJJXA8DSlHgzPkhbOKY2iwGEscbjUfghJcA5owgbdFGiH09u/bB A/Whcv7Hb/BgTCyOaVCUPBvSwTiUNQeCs2XfQG+D0BDCzGisHSKyYTTCnCPyNHvTd3tN PMgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=c3LUFr5ElROzHnC0rgmNZc1p1awSaDKB1MP4yLilKbY=; b=rvN9H3Ch2qMa6rQ7T4+8XHPXgPcTGL+fDZdD9a8AOuze5b4kBgr+lKMD8Y1cr4md7d AjA2fricEXD1mTi4q60pr7ZH1KwUG5da57fQZ+Zwj+QHhn/bhbzSStpQL+1F4/JsVSMy /SThsdScLUJDcImwsy6Q5DBb8of0KERx1Wa/Qc1EpSQZD5qZNbZTJeAbAHVszhmCKLO5 yLfx132oNNDgye1Q3iwemo/koxhkEPZI9AC1JTcdXl5DbAWEBlmOSxUXOhqOExse7c/F q+B36ubjn+8lsFpDpO7yNV7S9R3xP4i8ORScOUweGRroyLC035ytOCTz3nLQEESiIcwX aVow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="YFE/de4z"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f89si1216510pje.50.2019.07.18.21.13.08; Thu, 18 Jul 2019 21:13:24 -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; dkim=pass header.i=@kernel.org header.s=default header.b="YFE/de4z"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388747AbfGSEMQ (ORCPT + 99 others); Fri, 19 Jul 2019 00:12:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:47364 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732409AbfGSEMK (ORCPT ); Fri, 19 Jul 2019 00:12:10 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 37669218B6; Fri, 19 Jul 2019 04:12:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509529; bh=/EQ1w8gR6g3qcNT8caFVXf3PCM05WaMi9SnkxpZmX7c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YFE/de4zofwDUoB0zcdxKVT4Bhh5di9BPp6CeM38Z5yZ7lA2e3pHt64hvfhEdRc5+ 1CeKO+YnGQjPwurXEce7sfXICkyS22KAMf3Stt6oV/PuRodDBw45EslIKhs1kjZSFH hl9QLIwPSbIdCL1poNDcY2HZq/pUuDqfxXpGmkgs= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Naveen N. Rao" , Steven Rostedt , Satheesh Rajendran , Michael Ellerman , Sasha Levin Subject: [PATCH AUTOSEL 4.14 32/60] recordmcount: Fix spurious mcount entries on powerpc Date: Fri, 19 Jul 2019 00:10:41 -0400 Message-Id: <20190719041109.18262-32-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719041109.18262-1-sashal@kernel.org> References: <20190719041109.18262-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Naveen N. Rao" [ Upstream commit 80e5302e4bc85a6b685b7668c36c6487b5f90e9a ] An impending change to enable HAVE_C_RECORDMCOUNT on powerpc leads to warnings such as the following: # modprobe kprobe_example ftrace-powerpc: Not expected bl: opcode is 3c4c0001 WARNING: CPU: 0 PID: 227 at kernel/trace/ftrace.c:2001 ftrace_bug+0x90/0x318 Modules linked in: CPU: 0 PID: 227 Comm: modprobe Not tainted 5.2.0-rc6-00678-g1c329100b942 #2 NIP: c000000000264318 LR: c00000000025d694 CTR: c000000000f5cd30 REGS: c000000001f2b7b0 TRAP: 0700 Not tainted (5.2.0-rc6-00678-g1c329100b942) MSR: 900000010282b033 CR: 28228222 XER: 00000000 CFAR: c0000000002642fc IRQMASK: 0 NIP [c000000000264318] ftrace_bug+0x90/0x318 LR [c00000000025d694] ftrace_process_locs+0x4f4/0x5e0 Call Trace: [c000000001f2ba40] [0000000000000004] 0x4 (unreliable) [c000000001f2bad0] [c00000000025d694] ftrace_process_locs+0x4f4/0x5e0 [c000000001f2bb90] [c00000000020ff10] load_module+0x25b0/0x30c0 [c000000001f2bd00] [c000000000210cb0] sys_finit_module+0xc0/0x130 [c000000001f2be20] [c00000000000bda4] system_call+0x5c/0x70 Instruction dump: 419e0018 2f83ffff 419e00bc 2f83ffea 409e00cc 4800001c 0fe00000 3c62ff96 39000001 39400000 386386d0 480000c4 <0fe00000> 3ce20003 39000001 3c62ff96 ---[ end trace 4c438d5cebf78381 ]--- ftrace failed to modify [] 0xc0080000012a0008 actual: 01:00:4c:3c Initializing ftrace call sites ftrace record flags: 2000000 (0) expected tramp: c00000000006af4c Looking at the relocation records in __mcount_loc shows a few spurious entries: RELOCATION RECORDS FOR [__mcount_loc]: OFFSET TYPE VALUE 0000000000000000 R_PPC64_ADDR64 .text.unlikely+0x0000000000000008 0000000000000008 R_PPC64_ADDR64 .text.unlikely+0x0000000000000014 0000000000000010 R_PPC64_ADDR64 .text.unlikely+0x0000000000000060 0000000000000018 R_PPC64_ADDR64 .text.unlikely+0x00000000000000b4 0000000000000020 R_PPC64_ADDR64 .init.text+0x0000000000000008 0000000000000028 R_PPC64_ADDR64 .init.text+0x0000000000000014 The first entry in each section is incorrect. Looking at the relocation records, the spurious entries correspond to the R_PPC64_ENTRY records: RELOCATION RECORDS FOR [.text.unlikely]: OFFSET TYPE VALUE 0000000000000000 R_PPC64_REL64 .TOC.-0x0000000000000008 0000000000000008 R_PPC64_ENTRY *ABS* 0000000000000014 R_PPC64_REL24 _mcount The problem is that we are not validating the return value from get_mcountsym() in sift_rel_mcount(). With this entry, mcountsym is 0, but Elf_r_sym(relp) also ends up being 0. Fix this by ensuring mcountsym is valid before processing the entry. Signed-off-by: Naveen N. Rao Acked-by: Steven Rostedt (VMware) Tested-by: Satheesh Rajendran Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- scripts/recordmcount.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h index b9897e2be404..04151ede8043 100644 --- a/scripts/recordmcount.h +++ b/scripts/recordmcount.h @@ -326,7 +326,8 @@ static uint_t *sift_rel_mcount(uint_t *mlocp, if (!mcountsym) mcountsym = get_mcountsym(sym0, relp, str0); - if (mcountsym == Elf_r_sym(relp) && !is_fake_mcount(relp)) { + if (mcountsym && mcountsym == Elf_r_sym(relp) && + !is_fake_mcount(relp)) { uint_t const addend = _w(_w(relp->r_offset) - recval + mcount_adjust); mrelp->r_offset = _w(offbase -- 2.20.1