Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp909644imm; Wed, 15 Aug 2018 08:10:27 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwE2hp1HPVS8hEojn0ghCzJknilSR/p0v87EMRwAoHM59fb2/BJY+k9Rfno7oPNZRdJJ3a0 X-Received: by 2002:a62:8186:: with SMTP id t128-v6mr28310574pfd.192.1534345827156; Wed, 15 Aug 2018 08:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534345827; cv=none; d=google.com; s=arc-20160816; b=gRrK2PvID4G2SStnIXLdEG+uUbm+PE3ZfRmaVJcGVh9TQnM894d5CttmG9P1feZqwG XvVqsv1azYc8K7J2CrSvlszWiCAmBQ1edkx5thmREKck76hRzGZabAJKIY0z/B8LXDFe GFwNDGyYpZPKQexR0lQ8pnfB0Pg1YhprYer/wIaKN+eAIjZ0xIxJtoIx+/puOEKfIZRR FPEEzZ8DYSi+1eMSnGAUN+imTwnujVMPI28CN6Nl7P2rW0un9jfuBuPaA0aKlvFqXY2P bhVHiFhyEHWZv2cbHM8LGpp7MbHjtDLY0TAfvjasSv0mhXYBSAc/1VOeuU3ECZq9PnM4 lZyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Ok+aaxkbPQLmM8KZgoDxzr2NRgaOTYo4F0JXmz/5ZnU=; b=YAghY0Y/I1YSuP7h7mFgLXIEshS71gScLMvVwj/2KEHNbA8VIZfV5ABgOV+vB1m2db sHqDnoiVvl0sN/sHgd1VYaqFAle3bPSWRAXw512GqHdC+xx/79oZ+qVCGh1bsVtV+Vbq X/HYgdTtGXk0JIvTN9BLM9ZpzIRy4caeUAWkrnA7FpBDimm9byKsotD1mYK5IvJrWccA /ypMlft5uGgne0uTtKk+S7iSZwfRrIpX6+pdMBKoqDjV6Ez0xx9crXl9fuMWOLYEkIr9 8F6sbAVnzxsXyyQTFVwezsQdQcCebEMDcbLpFf71Iaa/o7QRxI4LTDZiwvYBFW0LWqrI y5vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Nw8+ZY/R"; 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 p23-v6si21200301pgd.47.2018.08.15.08.10.12; Wed, 15 Aug 2018 08:10:27 -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="Nw8+ZY/R"; 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 S1730825AbeHOSB1 (ORCPT + 99 others); Wed, 15 Aug 2018 14:01:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:51328 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729528AbeHOSB0 (ORCPT ); Wed, 15 Aug 2018 14:01:26 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7049F208E0; Wed, 15 Aug 2018 15:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1534345733; bh=Ni8RidsLzLP/whU6ki/li3VkX2/A4bocvh6eZlx+Qkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nw8+ZY/RPL4rAz61OKE3gKYwz2KTD1eIw1krRpXADHq8PyUdjHVEpQxhqbQ719OKU xy+PtKmzqQBVP5s/JUOd7nA4Hx1vBzMIzrBp6MqiKyjH+/xqsRCVaQemcsKaQORefu wyGUM3NWFas4pAFujFrc0j4sDz+BKjACyx+feaz8= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Adrian Hunter , Alexander Shishkin , Andy Lutomirski , Dave Hansen , "H . Peter Anvin" , Jiri Olsa , Joerg Roedel , Thomas Gleixner , x86@kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH 35/35] x86: Add entry trampolines to kcore Date: Wed, 15 Aug 2018 12:06:11 -0300 Message-Id: <20180815150611.32080-36-acme@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180815150611.32080-1-acme@kernel.org> References: <20180815150611.32080-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Adrian Hunter Without program headers for PTI entry trampoline pages, the trampoline virtual addresses do not map to anything. Example before: sudo gdb --quiet vmlinux /proc/kcore Reading symbols from vmlinux...done. [New process 1] Core was generated by `BOOT_IMAGE=/boot/vmlinuz-4.16.0 root=UUID=a6096b83-b763-4101-807e-f33daff63233'. #0 0x0000000000000000 in irq_stack_union () (gdb) x /21ib 0xfffffe0000006000 0xfffffe0000006000: Cannot access memory at address 0xfffffe0000006000 (gdb) quit After: sudo gdb --quiet vmlinux /proc/kcore [sudo] password for ahunter: Reading symbols from vmlinux...done. [New process 1] Core was generated by `BOOT_IMAGE=/boot/vmlinuz-4.16.0-fix-4-00005-gd6e65a8b4072 root=UUID=a6096b83-b7'. #0 0x0000000000000000 in irq_stack_union () (gdb) x /21ib 0xfffffe0000006000 0xfffffe0000006000: swapgs 0xfffffe0000006003: mov %rsp,-0x3e12(%rip) # 0xfffffe00000021f8 0xfffffe000000600a: xchg %ax,%ax 0xfffffe000000600c: mov %cr3,%rsp 0xfffffe000000600f: bts $0x3f,%rsp 0xfffffe0000006014: and $0xffffffffffffe7ff,%rsp 0xfffffe000000601b: mov %rsp,%cr3 0xfffffe000000601e: mov -0x3019(%rip),%rsp # 0xfffffe000000300c 0xfffffe0000006025: pushq $0x2b 0xfffffe0000006027: pushq -0x3e35(%rip) # 0xfffffe00000021f8 0xfffffe000000602d: push %r11 0xfffffe000000602f: pushq $0x33 0xfffffe0000006031: push %rcx 0xfffffe0000006032: push %rdi 0xfffffe0000006033: mov $0xffffffff91a00010,%rdi 0xfffffe000000603a: callq 0xfffffe0000006046 0xfffffe000000603f: pause 0xfffffe0000006041: lfence 0xfffffe0000006044: jmp 0xfffffe000000603f 0xfffffe0000006046: mov %rdi,(%rsp) 0xfffffe000000604a: retq (gdb) quit In addition, entry trampolines all map to the same page. Represent that by giving the corresponding program headers in kcore the same offset. This has the benefit that, when perf tools uses /proc/kcore as a source for kernel object code, samples from different CPU trampolines are aggregated together. Note, such aggregation is normal for profiling i.e. people want to profile the object code, not every different virtual address the object code might be mapped to (across different processes for example). Notes by PeterZ: This also adds the KCORE_REMAP functionality. Signed-off-by: Adrian Hunter Acked-by: Andi Kleen Acked-by: Peter Zijlstra (Intel) Cc: Alexander Shishkin Cc: Andy Lutomirski Cc: Dave Hansen Cc: H. Peter Anvin Cc: Jiri Olsa Cc: Joerg Roedel Cc: Thomas Gleixner Cc: x86@kernel.org Link: http://lkml.kernel.org/r/1528289651-4113-4-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- arch/x86/mm/cpu_entry_area.c | 10 ++++++++++ fs/proc/kcore.c | 7 +++++-- include/linux/kcore.h | 13 +++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/cpu_entry_area.c b/arch/x86/mm/cpu_entry_area.c index fab49fd5190f..076ebdce9bd4 100644 --- a/arch/x86/mm/cpu_entry_area.c +++ b/arch/x86/mm/cpu_entry_area.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -14,6 +15,7 @@ static DEFINE_PER_CPU_PAGE_ALIGNED(struct entry_stack_page, entry_stack_storage) #ifdef CONFIG_X86_64 static DEFINE_PER_CPU_PAGE_ALIGNED(char, exception_stacks [(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + DEBUG_STKSZ]); +static DEFINE_PER_CPU(struct kcore_list, kcore_entry_trampoline); #endif struct cpu_entry_area *get_cpu_entry_area(int cpu) @@ -147,6 +149,14 @@ static void __init setup_cpu_entry_area(int cpu) cea_set_pte(&get_cpu_entry_area(cpu)->entry_trampoline, __pa_symbol(_entry_trampoline), PAGE_KERNEL_RX); + /* + * The cpu_entry_area alias addresses are not in the kernel binary + * so they do not show up in /proc/kcore normally. This adds entries + * for them manually. + */ + kclist_add_remap(&per_cpu(kcore_entry_trampoline, cpu), + _entry_trampoline, + &get_cpu_entry_area(cpu)->entry_trampoline, PAGE_SIZE); #endif percpu_setup_debug_store(cpu); } diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index e64ecb9f2720..00282f134336 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -383,8 +383,11 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff) phdr->p_type = PT_LOAD; phdr->p_flags = PF_R|PF_W|PF_X; phdr->p_offset = kc_vaddr_to_offset(m->addr) + dataoff; - phdr->p_vaddr = (size_t)m->addr; - if (m->type == KCORE_RAM || m->type == KCORE_TEXT) + if (m->type == KCORE_REMAP) + phdr->p_vaddr = (size_t)m->vaddr; + else + phdr->p_vaddr = (size_t)m->addr; + if (m->type == KCORE_RAM || m->type == KCORE_TEXT || m->type == KCORE_REMAP) phdr->p_paddr = __pa(m->addr); else phdr->p_paddr = (elf_addr_t)-1; diff --git a/include/linux/kcore.h b/include/linux/kcore.h index 8de55e4b5ee9..bc088ef96358 100644 --- a/include/linux/kcore.h +++ b/include/linux/kcore.h @@ -12,11 +12,13 @@ enum kcore_type { KCORE_VMEMMAP, KCORE_USER, KCORE_OTHER, + KCORE_REMAP, }; struct kcore_list { struct list_head list; unsigned long addr; + unsigned long vaddr; size_t size; int type; }; @@ -36,11 +38,22 @@ struct vmcoredd_node { #ifdef CONFIG_PROC_KCORE extern void kclist_add(struct kcore_list *, void *, size_t, int type); +static inline +void kclist_add_remap(struct kcore_list *m, void *addr, void *vaddr, size_t sz) +{ + m->vaddr = (unsigned long)vaddr; + kclist_add(m, addr, sz, KCORE_REMAP); +} #else static inline void kclist_add(struct kcore_list *new, void *addr, size_t size, int type) { } + +static inline +void kclist_add_remap(struct kcore_list *m, void *addr, void *vaddr, size_t sz) +{ +} #endif #endif /* _LINUX_KCORE_H */ -- 2.14.4