Skip to contentSkip to conversation

perf tools: Urgent fixes

PATCH Applied Adrian Hunter 3 participants 6 messages Sep 24, 2015 – Sep 26, 2015 perf events

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

cover perf tools: Urgent fixes

Hi

Here are a couple of urgent fixes for v4.3.

The "Fix copying of /proc/kcore" problem goes back to v3.13 if you think it is important enough for stable.

Adrian Hunter (2):
perf intel-pt: Remove no_force_psb from documentation perf tools: Fix copying of /proc/kcore

 tools/perf/Documentation/intel-pt.txt | 15 ---------------
 tools/perf/util/symbol-elf.c          | 35 +++++++++++++----------------------
 2 files changed, 13 insertions(+), 37 deletions(-)

Regards
Adrian

author reviewer
#3 lore raw

PATCH 2/2 perf tools: Fix copying of /proc/kcore

A copy of /proc/kcore containing the kernel text can be made to the buildid cache. e.g.

perf buildid-cache -v -k /proc/kcore

To workaround objdump limitations, a copy is also made when annotating against /proc/kcore.

The copying process stops working from libelf about v1.62 onwards (the problem was found with v1.63).

The cause is that a call to gelf_getphdr() in kcore__add_phdr() fails because additional validation has been added to gelf_getphdr().

The use of gelf_getphdr() is a misguided attempt to get default initialization of the Gelf_Phdr structure. That should not be necessary because every member of the Gelf_Phdr structure is subsequently assigned. So just remove the call to gelf_getphdr().

Similarly, a call to gelf_getehdr() in gelf_kcore__init() can be removed also.

---
 tools/perf/util/symbol-elf.c | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)
tools/perf/util/symbol-elf.c +13 -22
index f78ea3dc4c08..475d88d0a1c9 100644
@@ -1271,8 +1271,6 @@ out_close:
 static int kcore__init(struct kcore *kcore, char *filename, int elfclass,
 		       bool temp)
 {
-	GElf_Ehdr *ehdr;
-
 	kcore->elfclass = elfclass;
 
 	if (temp)
@@ -1289,9 +1287,7 @@ static int kcore__init(struct kcore *kcore, char *filename, int elfclass,
 	if (!gelf_newehdr(kcore->elf, elfclass))
 		goto out_end;
 
-	ehdr = gelf_getehdr(kcore->elf, &kcore->ehdr);
-	if (!ehdr)
-		goto out_end;
+	memset(&kcore->ehdr, 0, sizeof(GElf_Ehdr));
 
 	return 0;
 
@@ -1348,23 +1344,18 @@ static int kcore__copy_hdr(struct kcore *from, struct kcore *to, size_t count)
 static int kcore__add_phdr(struct kcore *kcore, int idx, off_t offset,
 			   u64 addr, u64 len)
 {
-	GElf_Phdr gphdr;
-	GElf_Phdr *phdr;
-
-	phdr = gelf_getphdr(kcore->elf, idx, &gphdr);
-	if (!phdr)
-		return -1;
-
-	phdr->p_type	= PT_LOAD;
-	phdr->p_flags	= PF_R | PF_W | PF_X;
-	phdr->p_offset	= offset;
-	phdr->p_vaddr	= addr;
-	phdr->p_paddr	= 0;
-	phdr->p_filesz	= len;
-	phdr->p_memsz	= len;
-	phdr->p_align	= page_size;
-
-	if (!gelf_update_phdr(kcore->elf, idx, phdr))
+	GElf_Phdr phdr = {
+		.p_type		= PT_LOAD,
+		.p_flags	= PF_R | PF_W | PF_X,
+		.p_offset	= offset,
+		.p_vaddr	= addr,
+		.p_paddr	= 0,
+		.p_filesz	= len,
+		.p_memsz	= len,
+		.p_align	= page_size,
+	};
+
+	if (!gelf_update_phdr(kcore->elf, idx, &phdr))
 		return -1;
 
 	return 0;
Signature · 1 line
1.9.1
author reviewer
#1 lore raw

PATCH 1/2 perf intel-pt: Remove no_force_psb from documentation

In reply to Adrian Hunter

no_force_psb was dropped as a late change to the kernel driver. Consequently, remove it from the documentation.

---
 tools/perf/Documentation/intel-pt.txt | 15 ---------------
 1 file changed, 15 deletions(-)
tools/perf/Documentation/intel-pt.txt +0 -15
index 4a0501d7a3b4..c94c9de3173e 100644
@@ -364,21 +364,6 @@ cyc_thresh	Specifies how frequently CYC packets are produced - see cyc
 
 		CYC packets are not requested by default.
 
-no_force_psb	This is a driver option and is not in the IA32_RTIT_CTL MSR.
-
-		It stops the driver resetting the byte count to zero whenever
-		enabling the trace (for example on context switches) which in
-		turn results in no PSB being forced.  However some processors
-		will produce a PSB anyway.
-
-		In any case, there is still a PSB when the trace is enabled for
-		the first time.
-
-		no_force_psb can be used to slightly decrease the trace size but
-		may make it harder for the decoder to recover from errors.
-
-		no_force_psb is not selected by default.
-
 
 new snapshot option
 -------------------
Signature · 1 line
1.9.1
maintainer Applied
#5 lore raw
In reply to Adrian Hunter

Em Thu, Sep 24, 2015 at 01:05:20PM +0300, Adrian Hunter escreveu:

Quoted 6 lines

Hi

Here are a couple of urgent fixes for v4.3.

The "Fix copying of /proc/kcore" problem goes back to v3.13 if you think it is important enough for stable.

I added a Cc: [email protected] and your notes to the commit log.

Thanks, applied.

- Arnaldo

#2 lore raw

[tip:perf/urgent] perf intel-pt: Remove no_force_psb from documentation

In reply to Adrian Hunter
perf intel-pt: Remove no_force_psb from documentation
Commit-ID:  597ee40722bf05195f91a41e88e15b79bdab152c
Gitweb:     http://git.kernel.org/tip/597ee40722bf05195f91a41e88e15b79bdab152c
Author:     Adrian Hunter <[email protected]>
AuthorDate: Thu, 24 Sep 2015 13:05:21 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 25 Sep 2015 10:42:38 -0300

perf intel-pt: Remove no_force_psb from documentation

no_force_psb was dropped as a late change to the kernel driver. Consequently, remove it from the documentation.

---
 tools/perf/Documentation/intel-pt.txt | 15 ---------------
 1 file changed, 15 deletions(-)
tools/perf/Documentation/intel-pt.txt +0 -15
index 4a0501d..c94c9de 100644
@@ -364,21 +364,6 @@ cyc_thresh	Specifies how frequently CYC packets are produced - see cyc
 
 		CYC packets are not requested by default.
 
-no_force_psb	This is a driver option and is not in the IA32_RTIT_CTL MSR.
-
-		It stops the driver resetting the byte count to zero whenever
-		enabling the trace (for example on context switches) which in
-		turn results in no PSB being forced.  However some processors
-		will produce a PSB anyway.
-
-		In any case, there is still a PSB when the trace is enabled for
-		the first time.
-
-		no_force_psb can be used to slightly decrease the trace size but
-		may make it harder for the decoder to recover from errors.
-
-		no_force_psb is not selected by default.
-
 
 new snapshot option
 -------------------
#4 lore raw

[tip:perf/urgent] perf tools: Fix copying of /proc/kcore

In reply to Adrian Hunter
perf tools: Fix copying of /proc/kcore
Commit-ID:  b5cabbcbd157a4bf5a92dfc85134999a3b55342d
Gitweb:     http://git.kernel.org/tip/b5cabbcbd157a4bf5a92dfc85134999a3b55342d
Author:     Adrian Hunter <[email protected]>
AuthorDate: Thu, 24 Sep 2015 13:05:22 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 25 Sep 2015 10:45:50 -0300

perf tools: Fix copying of /proc/kcore

A copy of /proc/kcore containing the kernel text can be made to the buildid cache. e.g.

perf buildid-cache -v -k /proc/kcore

To workaround objdump limitations, a copy is also made when annotating against /proc/kcore.

The copying process stops working from libelf about v1.62 onwards (the problem was found with v1.63).

The cause is that a call to gelf_getphdr() in kcore__add_phdr() fails because additional validation has been added to gelf_getphdr().

The use of gelf_getphdr() is a misguided attempt to get default initialization of the Gelf_Phdr structure. That should not be necessary because every member of the Gelf_Phdr structure is subsequently assigned. So just remove the call to gelf_getphdr().

Similarly, a call to gelf_getehdr() in gelf_kcore__init() can be removed also.

Committer notes:

Note to [email protected], from Adrian in the cover letter for this patchkit:

The "Fix copying of /proc/kcore" problem goes back to v3.13 if you think it is important enough for stable.

---
 tools/perf/util/symbol-elf.c | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)
tools/perf/util/symbol-elf.c +13 -22
index f78ea3d..475d88d 100644
@@ -1271,8 +1271,6 @@ out_close:
 static int kcore__init(struct kcore *kcore, char *filename, int elfclass,
 		       bool temp)
 {
-	GElf_Ehdr *ehdr;
-
 	kcore->elfclass = elfclass;
 
 	if (temp)
@@ -1289,9 +1287,7 @@ static int kcore__init(struct kcore *kcore, char *filename, int elfclass,
 	if (!gelf_newehdr(kcore->elf, elfclass))
 		goto out_end;
 
-	ehdr = gelf_getehdr(kcore->elf, &kcore->ehdr);
-	if (!ehdr)
-		goto out_end;
+	memset(&kcore->ehdr, 0, sizeof(GElf_Ehdr));
 
 	return 0;
 
@@ -1348,23 +1344,18 @@ static int kcore__copy_hdr(struct kcore *from, struct kcore *to, size_t count)
 static int kcore__add_phdr(struct kcore *kcore, int idx, off_t offset,
 			   u64 addr, u64 len)
 {
-	GElf_Phdr gphdr;
-	GElf_Phdr *phdr;
-
-	phdr = gelf_getphdr(kcore->elf, idx, &gphdr);
-	if (!phdr)
-		return -1;
-
-	phdr->p_type	= PT_LOAD;
-	phdr->p_flags	= PF_R | PF_W | PF_X;
-	phdr->p_offset	= offset;
-	phdr->p_vaddr	= addr;
-	phdr->p_paddr	= 0;
-	phdr->p_filesz	= len;
-	phdr->p_memsz	= len;
-	phdr->p_align	= page_size;
-
-	if (!gelf_update_phdr(kcore->elf, idx, phdr))
+	GElf_Phdr phdr = {
+		.p_type		= PT_LOAD,
+		.p_flags	= PF_R | PF_W | PF_X,
+		.p_offset	= offset,
+		.p_vaddr	= addr,
+		.p_paddr	= 0,
+		.p_filesz	= len,
+		.p_memsz	= len,
+		.p_align	= page_size,
+	};
+
+	if (!gelf_update_phdr(kcore->elf, idx, &phdr))
 		return -1;
 
 	return 0;