All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Arapov <anton@redhat.com>
To: Anton Arapov <anton@redhat.com>, Oleg Nesterov <oleg@redhat.com>,
	Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Josh Stone <jistone@redhat.com>, Frank Eigler <fche@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@elte.hu>,
	Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
	adrian.m.negreanu@intel.com, Torsten.Polle@gmx.de
Subject: [PATCH 2/7] uretprobes: extract fill_page() and trampoline implementation
Date: Fri, 22 Mar 2013 14:08:59 +0100	[thread overview]
Message-ID: <1363957745-6657-3-git-send-email-anton@redhat.com> (raw)
In-Reply-To: <1363957745-6657-1-git-send-email-anton@redhat.com>

  - Split out fill_page() from xol_get_insn_slot().
  - Allocate trampoline page, as the very first one in uprobed
    task xol area, and fill it with breakpoint opcode.
  - Also introduce get_trampoline_vaddr() helper, to wrap the
    trampoline address extraction from area->vaddr. That removes
    confusion and eases the debug experience in case ->vaddr
    notion will be changed.

Signed-off-by: Anton Arapov <anton@redhat.com>
---
 kernel/events/uprobes.c | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 3205a2e..86706d1 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1080,6 +1080,21 @@ void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned lon
 		set_bit(MMF_RECALC_UPROBES, &vma->vm_mm->flags);
 }
 
+static void fill_page(struct page *page, unsigned long offset, uprobe_opcode_t *insn)
+{
+	void *vaddr;
+
+	vaddr = kmap_atomic(page);
+	memcpy(vaddr + offset, insn, MAX_UINSN_BYTES);
+	kunmap_atomic(vaddr);
+
+	/*
+	 * We probably need flush_icache_user_range() but it needs vma.
+	 * This should work on supported architectures too.
+	 */
+	flush_dcache_page(page);
+}
+
 /* Slot allocation for XOL */
 static int xol_add_vma(struct xol_area *area)
 {
@@ -1122,6 +1137,7 @@ static struct xol_area *get_xol_area(void)
 {
 	struct mm_struct *mm = current->mm;
 	struct xol_area *area;
+	uprobe_opcode_t insn = UPROBE_SWBP_INSN;
 
 	area = mm->uprobes_state.xol_area;
 	if (area)
@@ -1139,6 +1155,10 @@ static struct xol_area *get_xol_area(void)
 	if (!area->page)
 		goto free_bitmap;
 
+	/* pre-allocate for return probes */
+	set_bit(0, area->bitmap);
+	fill_page(area->page, 0, &insn);
+
 	init_waitqueue_head(&area->wq);
 	if (!xol_add_vma(area))
 		return area;
@@ -1226,7 +1246,6 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe)
 	struct xol_area *area;
 	unsigned long offset;
 	unsigned long xol_vaddr;
-	void *vaddr;
 
 	area = get_xol_area();
 	if (!area)
@@ -1238,14 +1257,7 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe)
 
 	/* Initialize the slot */
 	offset = xol_vaddr & ~PAGE_MASK;
-	vaddr = kmap_atomic(area->page);
-	memcpy(vaddr + offset, uprobe->arch.insn, MAX_UINSN_BYTES);
-	kunmap_atomic(vaddr);
-	/*
-	 * We probably need flush_icache_user_range() but it needs vma.
-	 * This should work on supported architectures too.
-	 */
-	flush_dcache_page(area->page);
+	fill_page(area->page, offset, uprobe->arch.insn);
 
 	return xol_vaddr;
 }
@@ -1341,6 +1353,11 @@ static struct uprobe_task *get_utask(void)
 	return current->utask;
 }
 
+static unsigned long get_trampoline_vaddr(struct xol_area *area)
+{
+	return area->vaddr;
+}
+
 /* Prepare to single-step probed instruction out of line. */
 static int
 pre_ssout(struct uprobe *uprobe, struct pt_regs *regs, unsigned long bp_vaddr)
-- 
1.8.1.4


  parent reply	other threads:[~2013-03-22 13:10 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-22 13:08 [PATCH 0/7] uretprobes: return probes implementation Anton Arapov
2013-03-22 13:08 ` [PATCH 1/7] uretprobes: preparation patch Anton Arapov
2013-03-23 17:42   ` Oleg Nesterov
2013-03-22 13:08 ` Anton Arapov [this message]
2013-03-24 14:41   ` [PATCH 2/7] uretprobes: extract fill_page() and trampoline implementation Oleg Nesterov
2013-03-24 18:20     ` [PATCH 0/5] kmap cleanups for uretprobes (Was: extract fill_page() and trampoline implementation) Oleg Nesterov
2013-03-24 18:21       ` [PATCH 1/5] uprobes: Turn copy_opcode() into copy_from_page() Oleg Nesterov
2013-03-25 10:30         ` Anton Arapov
2013-03-26 11:59         ` Srikar Dronamraju
2013-03-24 18:21       ` [PATCH 2/5] uprobes: Change __copy_insn() to use copy_from_page() Oleg Nesterov
2013-03-25 10:31         ` Anton Arapov
2013-03-26 12:00         ` Srikar Dronamraju
2013-03-24 18:21       ` [PATCH 3/5] uprobes: Kill the unnecesary filp != NULL check in __copy_insn() Oleg Nesterov
2013-03-25 10:31         ` Anton Arapov
2013-03-26 12:00         ` Srikar Dronamraju
2013-03-24 18:21       ` [PATCH 4/5] uprobes: Introduce copy_to_page() Oleg Nesterov
2013-03-25 10:31         ` Anton Arapov
2013-03-26 12:02         ` Srikar Dronamraju
2013-03-24 18:21       ` [PATCH 5/5] uprobes: Change write_opcode() to use copy_*page() Oleg Nesterov
2013-03-25 10:31         ` Anton Arapov
2013-03-26 11:59         ` Srikar Dronamraju
2013-03-25 10:30       ` [PATCH 0/5] kmap cleanups for uretprobes (Was: extract fill_page() and trampoline implementation) Anton Arapov
2013-03-25 11:58     ` [PATCH 2/7] uretprobes: extract fill_page() and trampoline implementation Oleg Nesterov
2013-03-22 13:09 ` [PATCH 3/7] uretprobes/x86: hijack return address Anton Arapov
2013-03-24 14:59   ` Oleg Nesterov
2013-03-22 13:09 ` [PATCH 4/7] uretprobes: return probe entry, prepare_uretprobe() Anton Arapov
2013-03-22 15:02   ` Oleg Nesterov
2013-03-26 12:26     ` Anton Arapov
2013-03-26 14:34       ` Oleg Nesterov
2013-03-23 17:46   ` Oleg Nesterov
2013-03-24 15:26   ` Oleg Nesterov
2013-03-25 15:51     ` Anton Arapov
2013-03-26  8:45     ` Anton Arapov
2013-03-26  8:50       ` Anton Arapov
2013-03-22 13:09 ` [PATCH 5/7] uretprobes: return probe exit, invoke handlers Anton Arapov
2013-03-24 16:28   ` Oleg Nesterov
2013-03-25 12:31     ` Oleg Nesterov
2013-03-25 15:49     ` Anton Arapov
2013-03-25 16:38       ` Oleg Nesterov
2013-03-26  8:36         ` Anton Arapov
2013-03-22 13:09 ` [PATCH 6/7] uretprobes: limit the depth of return probe nestedness Anton Arapov
2013-03-24 16:54   ` Oleg Nesterov
2013-03-22 13:09 ` [PATCH 7/7] uretprobes: implemented, thus remove -ENOSYS Anton Arapov
2013-03-22 13:13   ` Anton Arapov
2013-03-22 13:09 ` [PATCH 7/7] uretprobes: remove -ENOSYS as return probes implemented Anton Arapov
2013-03-22 15:10 ` [PATCH 0/7] uretprobes: return probes implementation Oleg Nesterov
2013-03-22 21:40   ` Josh Stone
2013-03-23  6:43     ` Anton Arapov
2013-03-23 18:04       ` Oleg Nesterov
2013-03-23 17:56     ` Oleg Nesterov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1363957745-6657-3-git-send-email-anton@redhat.com \
    --to=anton@redhat.com \
    --cc=Torsten.Polle@gmx.de \
    --cc=adrian.m.negreanu@intel.com \
    --cc=ananth@in.ibm.com \
    --cc=fche@redhat.com \
    --cc=jistone@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=srikar@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.