From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751111AbdILBKr (ORCPT ); Mon, 11 Sep 2017 21:10:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:56500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750969AbdILBKq (ORCPT ); Mon, 11 Sep 2017 21:10:46 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09B0A21A92 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mhiramat@kernel.org From: Masami Hiramatsu To: Ingo Molnar , "Paul E . McKenney" Cc: Steven Rostedt , Masami Hiramatsu , linux-kernel@vger.kernel.org, Peter Zijlstra , Ananth N Mavinakayanahalli , Thomas Gleixner , "H . Peter Anvin" Subject: [PATCH -tip v2] Enable optprobe on preepmtive kernel Date: Tue, 12 Sep 2017 10:10:12 +0900 Message-Id: <150517861179.26279.7649250983151178165.stgit@devbox> X-Mailer: git-send-email 2.13.5 User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch enables optprobe even with CONFIG_PREEMPT. The previous patch is https://lkml.org/lkml/2017/5/24/464 . With Paul's hack (https://lkml.org/lkml/2017/5/25/435), now synchronize_rcu_tasks() is translated to synchronize_sched() when TASKS_RCU=n. So this patch just replace the synchronize_sched() with synchronize_rcu_tasks() and select TASKS_RCU if PREEMPT=y & OPTPROBES=y. Here is the reason why this change is needed. Since the jump optimized kprobes can replace multiple instructions, there can be tasks which are interrupted on the 2nd (or 3rd) instructions. If the kprobe replaces those instructions by a jump instruction, when those tasks back to the interrupted place, it is a middle of the jump instruction and causes a kernel panic. To avoid such tragedies in advance, kprobe optimizer prepare a detour route using normal kprobe (e.g. int3 breakpoint on x86), and wait for the tasks which is interrrupted on such place by synchronize_sched() when CONFIG_PREEMPT=n. If CONFIG_PREEMPT=y, things be more complicated, because such interrupted thread can be preempted (other thread can be scheduled in interrupt handler.) This means we can not ensure all tasks run in safe zone by synchronize_sched(). However, we have synchronize_rcu_tasks() which can ensure that all preempted tasks back on track and scheduled. kprobes optimizer can wait for those preempted tasks scheduled normally by synchronize_rcu_tasks(). Thank you, --- Masami Hiramatsu (1): kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT arch/Kconfig | 2 +- kernel/kprobes.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) -- Masami Hiramatsu