Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6a7d607 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds
Browse files

ptrace/x86: simplify the "disable" logic in ptrace_write_dr7()



ptrace_write_dr7() looks unnecessarily overcomplicated.  We can factor
out ptrace_modify_breakpoint() and do not do "continue" twice, just we
need to pass the proper "disabled" argument to
ptrace_modify_breakpoint().

Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Acked-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: Michael Neuling <mikey@neuling.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Prasad <prasad@linux.vnet.ibm.com>
Cc: Russell King <linux@arm.linux.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7c8df286
Loading
Loading
Loading
Loading
+15 −25
Original line number Original line Diff line number Diff line
@@ -637,9 +637,7 @@ static int ptrace_write_dr7(struct task_struct *tsk, unsigned long data)
	struct thread_struct *thread = &(tsk->thread);
	struct thread_struct *thread = &(tsk->thread);
	unsigned long old_dr7;
	unsigned long old_dr7;
	int i, orig_ret = 0, rc = 0;
	int i, orig_ret = 0, rc = 0;
	int enabled, second_pass = 0;
	int second_pass = 0;
	unsigned len, type;
	struct perf_event *bp;


	data &= ~DR_CONTROL_RESERVED;
	data &= ~DR_CONTROL_RESERVED;
	old_dr7 = ptrace_get_dr7(thread->ptrace_bps);
	old_dr7 = ptrace_get_dr7(thread->ptrace_bps);
@@ -649,30 +647,22 @@ static int ptrace_write_dr7(struct task_struct *tsk, unsigned long data)
	 * appropriate changes to each.
	 * appropriate changes to each.
	 */
	 */
	for (i = 0; i < HBP_NUM; i++) {
	for (i = 0; i < HBP_NUM; i++) {
		enabled = decode_dr7(data, i, &len, &type);
		unsigned len, type;
		bp = thread->ptrace_bps[i];
		bool disabled = !decode_dr7(data, i, &len, &type);
		struct perf_event *bp = thread->ptrace_bps[i];


		if (!enabled) {
		if (disabled) {
			if (bp) {
			/*
			/*
				 * Don't unregister the breakpoints right-away,
			 * Don't unregister the breakpoints right-away, unless
				 * unless all register_user_hw_breakpoint()
			 * all register_user_hw_breakpoint() requests have
				 * requests have succeeded. This prevents
			 * succeeded. This prevents any window of opportunity
				 * any window of opportunity for debug
			 * for debug register grabbing by other users.
				 * register grabbing by other users.
			 */
			 */
				if (!second_pass)
			if (!bp || !second_pass)
					continue;

				rc = ptrace_modify_breakpoint(bp, len, type,
							      tsk, 1);
				if (rc)
					break;
			}
				continue;
				continue;
		}
		}


		rc = ptrace_modify_breakpoint(bp, len, type, tsk, 0);
		rc = ptrace_modify_breakpoint(bp, len, type, tsk, disabled);
		if (rc)
		if (rc)
			break;
			break;
	}
	}