From patchwork Thu Apr 19 10:58:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 133746 Delivered-To: patch@linaro.org Received: by 10.46.66.142 with SMTP id h14csp490294ljf; Thu, 19 Apr 2018 03:59:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx49/ggkUq75dzJfzzPKrgZBQuuIYJ4eEYwV2r7OFCHvhSCRWXylpvo4pLnRCYD1QduE4xOZ2 X-Received: by 10.98.130.140 with SMTP id w134mr5430645pfd.127.1524135545064; Thu, 19 Apr 2018 03:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524135545; cv=none; d=google.com; s=arc-20160816; b=YNM9nIFbGX4ZRK2GO+TYQE6DZBkri4SGOJaqU/bsEtPcggN/Fyz4sj+GIEPO93BaMt gOFs3t4ZMz8zD/rZfOkchhshFIS2qSxAEleVFqcKMLNE+hORuOgRMjkYpovLT+owqh1g UGAiRrcpldnmMs3YmzuIZhOaCBqdNx9SNr72PIsd1ZuG9MXgNYNMm61LPIKMcObXCGGB p8sO5Wq3oPxGNbVjuhHOL8CEfsa81chkpB/R0flFw/BVDYJHPwCQtPHdoYND4LWMh5JS iXkO1fqB+qw9bvWYttsTGURZL1Ar4IjldNf1h00A6Di5oOa8BzD5wHnaGbExRaP3Fz3y LuWQ== 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:arc-authentication-results; bh=Ext4jsrBr2VQNgd6x2/yd2rFNvaUdpNuFf0lIC+7nk4=; b=hQwfvAQdNTGjM6RVrWMNbu7adFC8FHg2N2uRQNBgw9G1nmeUgstM+LeXuuSYdg7Am/ lp12hBQxZOS7vobWcSFYr8ZRnEfqMoZNy7Zd3wUNFNAS1BPqZ2lEj1GDpPajw0JjKFFZ kHARzP7Tkr9/TDyQDgE77ZoF72UvHP8v640g5CwpSpbcoM0g8F1WMTMEM2kO9FP+JhPu QQeZsm8+2M1+2lZW1LXyUR5gY1ZZp9YXuJJ1707VQSG+8x3aUrcML3LAjohBcrqJ4xs2 tOu//9jOLzAxN7TubNX2cOPyFHK7mQAjCxl0kgpcMctgQWIBHEGyVwcw1pBtMLWLbsxO kVzg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z6-v6si3101456pln.339.2018.04.19.03.59.04; Thu, 19 Apr 2018 03:59:05 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752618AbeDSK7A (ORCPT + 29 others); Thu, 19 Apr 2018 06:59:00 -0400 Received: from foss.arm.com ([217.140.101.70]:35828 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751228AbeDSK65 (ORCPT ); Thu, 19 Apr 2018 06:58:57 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9994815AD; Thu, 19 Apr 2018 03:58:57 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 652AA3F59D; Thu, 19 Apr 2018 03:58:55 -0700 (PDT) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Ralf Baechle , James Hogan , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "David S. Miller" , Ingo Molnar , Peter Zijlstra , Steven Rostedt , Oleg Nesterov , linux-arch@vger.kernel.org Subject: [RFC PATCH 1/6] thread_info: Add update_thread_flag() helpers Date: Thu, 19 Apr 2018 11:58:43 +0100 Message-Id: <1524135528-28561-2-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524135528-28561-1-git-send-email-Dave.Martin@arm.com> References: <1524135528-28561-1-git-send-email-Dave.Martin@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are a number of bits of code sprinkled around the kernel to set a thread flag if a certain condition is true, and clear it otherwise. To help make those call sites terser and less cumbersome, this patch adds a new family of thread flag manipulators update*_thread_flag([...,] flag, cond) which do the equivalent of: if (cond) set*_thread_flag([...,] flag); else clear*_thread_flag([...,] flag); Signed-off-by: Dave Martin Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Oleg Nesterov --- Note, this patch assumes C99 _Bool semantics where casting a value to _Bool is true is and only if the value compares != 0. This would not be true if bool where a typedef of unsigned char for example. It appears that the kernel has always used the C99 semantics for bool and relies on them elsewhere, so I don't believe this patch introduces a new dependency. --- include/linux/sched.h | 6 ++++++ include/linux/thread_info.h | 11 +++++++++++ include/trace/syscall.h | 6 ++---- kernel/ptrace.c | 13 +++++-------- 4 files changed, 24 insertions(+), 12 deletions(-) -- 2.1.4 Acked-by: Will Deacon diff --git a/include/linux/sched.h b/include/linux/sched.h index b3d697f..c2c3051 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1578,6 +1578,12 @@ static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag) clear_ti_thread_flag(task_thread_info(tsk), flag); } +static inline void update_tsk_thread_flag(struct task_struct *tsk, int flag, + bool value) +{ + update_ti_thread_flag(task_thread_info(tsk), flag, value); +} + static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag) { return test_and_set_ti_thread_flag(task_thread_info(tsk), flag); diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h index 34f053a..efd5ec4 100644 --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -64,6 +64,15 @@ static inline void clear_ti_thread_flag(struct thread_info *ti, int flag) clear_bit(flag, (unsigned long *)&ti->flags); } +static inline void update_ti_thread_flag(struct thread_info *ti, int flag, + bool value) +{ + if (value) + set_ti_thread_flag(ti, flag); + else + clear_ti_thread_flag(ti, flag); +} + static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag) { return test_and_set_bit(flag, (unsigned long *)&ti->flags); @@ -83,6 +92,8 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag) set_ti_thread_flag(current_thread_info(), flag) #define clear_thread_flag(flag) \ clear_ti_thread_flag(current_thread_info(), flag) +#define update_thread_flag(flag, value) \ + update_ti_thread_flag(current_thread_info(), flag, value) #define test_and_set_thread_flag(flag) \ test_and_set_ti_thread_flag(current_thread_info(), flag) #define test_and_clear_thread_flag(flag) \ diff --git a/include/trace/syscall.h b/include/trace/syscall.h index dc8ac27..dcc9bdf 100644 --- a/include/trace/syscall.h +++ b/include/trace/syscall.h @@ -37,10 +37,8 @@ struct syscall_metadata { #if defined(CONFIG_TRACEPOINTS) && defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS) static inline void syscall_tracepoint_update(struct task_struct *p) { - if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) - set_tsk_thread_flag(p, TIF_SYSCALL_TRACEPOINT); - else - clear_tsk_thread_flag(p, TIF_SYSCALL_TRACEPOINT); + update_tsk_thread_flag(p, TIF_SYSCALL_TRACEPOINT, + test_thread_flag(TIF_SYSCALL_TRACEPOINT)); } #else static inline void syscall_tracepoint_update(struct task_struct *p) diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 21fec73..7a2bd8d 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -785,16 +785,13 @@ static int ptrace_resume(struct task_struct *child, long request, if (!valid_signal(data)) return -EIO; - if (request == PTRACE_SYSCALL) - set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); - else - clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); + update_tsk_thread_flag(child, TIF_SYSCALL_TRACE, + request == PTRACE_SYSCALL); #ifdef TIF_SYSCALL_EMU - if (request == PTRACE_SYSEMU || request == PTRACE_SYSEMU_SINGLESTEP) - set_tsk_thread_flag(child, TIF_SYSCALL_EMU); - else - clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); + update_tsk_thread_flag(child, TIF_SYSCALL_EMU, + request == PTRACE_SYSEMU || + request == PTRACE_SYSEMU_SINGLESTEP); #endif if (is_singleblock(request)) {