Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759632AbcDERk2 (ORCPT ); Tue, 5 Apr 2016 13:40:28 -0400 Received: from mail-db3on0083.outbound.protection.outlook.com ([157.55.234.83]:59500 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759581AbcDERjw (ORCPT ); Tue, 5 Apr 2016 13:39:52 -0400 Authentication-Results: spf=fail (sender IP is 12.216.194.146) smtp.mailfrom=ezchip.com; mellanox.com; dkim=none (message not signed) header.d=none;mellanox.com; dmarc=fail action=none header.from=mellanox.com; From: Chris Metcalf To: Gilad Ben Yossef , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Andrew Morton , "Rik van Riel" , Tejun Heo , Frederic Weisbecker , Thomas Gleixner , "Paul E. McKenney" , Christoph Lameter , Viresh Kumar , Catalin Marinas , Will Deacon , Andy Lutomirski , Mark Rutland , , CC: Chris Metcalf Subject: [PATCH v12 13/13] arch/arm64: enable task isolation functionality Date: Tue, 5 Apr 2016 13:38:42 -0400 Message-ID: <1459877922-15512-14-git-send-email-cmetcalf@mellanox.com> X-Mailer: git-send-email 2.7.2 In-Reply-To: <1459877922-15512-1-git-send-email-cmetcalf@mellanox.com> References: <1459877922-15512-1-git-send-email-cmetcalf@mellanox.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:12.216.194.146;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(1096002)(36756003)(19580395003)(5001770100001)(19580405001)(107886002)(33646002)(1220700001)(48376002)(47776003)(960300001)(42186005)(5001970100001)(5003940100001)(50466002)(4001430100002)(92566002)(586003)(85426001)(11100500001)(50226001)(104016004)(5008740100001)(6806005)(76176999)(50986999)(4326007)(2950100001)(105606002)(2906002)(229853001)(2201001)(189998001)(106466001)(87936001)(86362001)(921003)(83996005)(2101003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR05MB1531;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;DB3FFO11FD021;1:waS0fi4VFRpt3pK9It2596bQ70T68I9kXvFmqiqbQUfZSoYOdqHmt5ue6unvGmoX44liqpaZ2VoY7Tp580wTQblrc9jIf6o+Av6FtH5GmaUK6LjQGiGgp6BR4CcyUfkR2l688mvGoDSESp8HZLAueLkWKN1BTs8oLPUSu6DzecTDFG4Y3skBOPwJ9QY7aWeTjw/BU7mWZNMbV/N960kcBUXrE6EVmLWcDi4QD0opOiz1NSLoMGOl5SCcowfpbRnUy2+Q2m9PO+R5EdRDNJ9n+lrATUCkkvSW4dnDednG8shl/MPXy/szNE4oRz99JKixLLbxBU6BiSHEhW9d69bDjZsSC0x9/MwBY7AYXlHu/4qq68l88zpJEYMJD6Uoh0Ga22NaR3HNeqhuY0Pna6WieJdg8tI0CrWFnKQRth+1DvQa2pBPBrZwhNqrWLThzggTpy6wbQYJxBLCuWpWSkbqfpr9EEZAC0C/udUQRt0mDUEUHMb34otFvrKxyCLGcNNv2EjVHseQz39bX4BhSHKkb32xRJuujWbUITHsj4DKUkc41P2ha4eMI4AjYKoCBvU7XisVDx4TYRS4KQsDt9KZwELWg4Y0G+wi/qT4jwRVx6TmabTdONDC2fX8XaM8IqHxZ6UVsAYGRgrlfVbG2mXliw== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 319e2804-587b-4bbe-01e8-08d35d79456f X-Microsoft-Exchange-Diagnostics: 1;HE1PR05MB1531;2:J+zt0fqQtmSydYTJkD+EPsGSzDah29YV8bA6ccNeVfnFG0ogBGuCxG7Xea1QN/0QGUC2U0gmTSvM51+lQwe3fZ1Bt1wvqehDOLnFURaZ4YTH7F3rRAzqRJWyRYwIkau4f+n1lM8kv62EnT/My8/ExodCp1/SOWBQdvoYikEsU1OSlweMPaP6E9WD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agnostics: 1;HE1PR05MB1531;20:Ip4ktSYpbD6L+u9iY777651sIxYgve/Y0D4ujN+J5+U//otRWvemGzZIEfhTPZN/R5YqL2thc1RLwokeRxTxwhIAwYorQVskYX5dH9eVRslxdcUVx2888xQQmTesOoav1lxUPndXTWSrejfNOiAGmU9IXbZlEijNLAsDCxZd0sp4sapAruT9HjBs/3R+WnqZ7H7Vpp1+iVb4B3ox1Q+mipxZcnMjljDPu4N8W+Sm0KCn9W3jLSF0CfreDaJrXZpyGua7pAETuu0tgpWhysYMPAfFNBnDhAECJFT5EWYOwx+Z/cVwXd+19ei6A1Qs/lCLhrxZYlfx5GlXh4sAdONmZyaie9ohFAAYTx1RMn+b6leLp5t7hQq9S5eg/Kdc8BnFu5sR9y9tRuGLatBYC1EpB3rKLgEbW9TdBKIN0fVAd4EWpurdpW+mEHxCjkXsXNj9NOxcAr4b2GUfeO2qZgCpUS3U7lrKMkue1sspB2JqYozT8XgdWeg8oonQoLACKZPn X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(13023025)(13024025)(8121501046)(13018025)(13017025)(13015025)(10201501046)(3002001);SRVR:HE1PR05MB1531;BCL:0;PCL:0;RULEID:;SRVR:HE1PR05MB1531; X-Microsoft-Exchange-Diagnostics: 1;HE1PR05MB1531;4:H7bQvCXGTojfC7BRmMRJ2ziz61LqosiwW6OY2MHk6vm2nOniglagdf+60Sv9OVzfEnY/ismT1kdjLBvfLOWRuoEaFupNKNjgOxCyRh1y0pPf52ir3uUxTpeQCtsjPpLCG3nHurZQtEE0REmm2BfQModkHC4CtpPWfjkY0i17Er/yjYF7Sv2W9gySTflBI/KBGxlHjrvS9OBPh4DHC3w1aHDHga0kAx1BK8wujNgGfF85CwVC5XODsiY2Pjt6fInpMFocKsXYMzNhEzIhwwV4pnCj4+el6T1AzpRYHfAECFPL05ozQ39HfVETaYUXza+o3AwlRLsComRuZ2D9A65sBfmeshdbNDvY+qdwsx/cVsuV7sQ3e91ky0qbfWADNz2M0saZVGidQYDvTe6FjkXRrxWmDTizABn0i50W7Vwd8e20RUeAoJsJL1ir49aBW43J6AeZ237FcaltacDTFoAMZQ== X-Forefront-PRVS: 0903DD1D85 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;HE1PR05MB1531;23:fNNDvVbqIj4IaGkGjnvOsqr9bdJZl+UU6p+fnXdYE?= =?us-ascii?Q?BOHBii3i0VsU0F+qM/vL7NHF7uZh1QjYKvwGZugc8zGPYzShU69GpFLDga/z?= =?us-ascii?Q?LqhL/1MCzdI71lAcZ3PvODc+3tmBcfr3iWWtX3Gzjxw0LOtmbZ2powSznIu2?= =?us-ascii?Q?Dsgp5tP4+m5Tr0GuOEq7sZgx7I/l4T4bnkJZvWRXqNJ4Cmq6xeyOHU9DJeIF?= =?us-ascii?Q?2V9XPW36N6qMTILHNktsxNTIMhHWnkDUZlh4TN2Z7PV1pazoi6d0vYwp91gT?= =?us-ascii?Q?/d39EsJSxNxBZXnluKrggzOzn9LCQZkhVQ+j52TQaz/Fs+XUJZ5qSluWdYAN?= =?us-ascii?Q?ml0Drq/2/srmz4L4EVvi+1f4FvO6A2AKSn1HmiRwBb+zmn0nB68fgJ6bDss0?= =?us-ascii?Q?lD+FUdrdzapp3qZX/AZKkZiVW38G0RnTQKiZOAG6mYqadztRk8AIH5muARDr?= =?us-ascii?Q?w1CoPeToyqwMuw8hsdFt4kt0t5pCwkdbnS6fobSB8I9o+g9oRVrL/c7rHLrX?= =?us-ascii?Q?YY4aeUHTHD77PtglU935nb2pd12XDNLPSt2ygDw5RoXVCcLy50S3Nn5n6XDd?= =?us-ascii?Q?lIajYnLLDL6GJxZ7RRvA7WRI7/RAVguKboQZTHpV5aRZr0LgegyQ5k5BdDkt?= =?us-ascii?Q?mOQ7skPIXxcoFBpgefp+TM3Q8hwifW/S3B/guKdGMwSxYv/zk+FTGBK4C+IQ?= =?us-ascii?Q?uNfUIvbugvtjli1a92LK/pWLmU3RCbjuE8Q5wScpNuHjS96wAaaMnlNG3wL4?= =?us-ascii?Q?ntecQfz/mZVFrrVqpBArfm3101oFbD+hVOasMunECIGBd6wXTkIahPT/cKVL?= =?us-ascii?Q?Dg749l5GpWrP4EVWfnGaJGSbYI1h5hyXiZzA73E/RBQ/Wx3HEeyi38A895rC?= =?us-ascii?Q?u3hQk8V4Ajgq3nTPs3jw1xaI98EltKS3+TTsWgUqe4RiEM9e7FhJHrbBBYYM?= =?us-ascii?Q?mdSb5eHLnSqVOL1ViQH1Pig+9C3sbzJ1w7yI3Kn/zqoYS1GvCpwOxc5BVd5Z?= =?us-ascii?Q?HoYAho6Y/kGLy/ImTC9ID2BeQESReqgxSKovvWB1MD2v8xlwp09MhrL3K+5/?= =?us-ascii?Q?BURbLrwsaFOiCDSZ84lnAAfZFwCFsaXUyKb48xnPMbZIwUrrjSizMllBpjGb?= =?us-ascii?Q?7yVmjhbPckCy84O/0hoM2G12hJcx8X+6vED0b7WGlkK+DiDZmMDYeVnk32SD?= =?us-ascii?Q?er/QSLgeWATFI0FJhsnI6FXVs3IIJk6VG2gxSJmDFMNqJdDPsbkDXmaAw=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;HE1PR05MB1531;5:I6KkHl7MEuRd5p21PegwRV9mMFruocT9VuzKQRlxWMu4Gpfzb6SDZSWAWuKQrj1Ce6Pgj4X249xIBfNar9yRlI3QzB84iRuIlnihJY8ShrrN86AYrYmM/6ZZVNtrwabXYal+G5FW3rAX9vo/O7XOpw==;24:d5RfDEucTvF94bhJY5ZgFSrtEtjpXuFLwX11URzAZGwqWIvrqF6uJY4heYnE/Q5DbLkgT9112DWsTyBUPcXAXupW62Cfnf1ZGu3dhaTl41Y= X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2016 17:39:42.2488 (UTC) X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=a652971c-7d2e-4d9b-a6a4-d149256f461b;Ip=[12.216.194.146];Helo=[ld-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR05MB1531 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6779 Lines: 186 In do_notify_resume(), call task_isolation_ready() for TIF_TASK_ISOLATION tasks when we are checking the thread-info flags; and after we've handled the other work, call task_isolation_enter() for such tasks. To ensure we always call task_isolation_enter() when returning to userspace, add _TIF_TASK_ISOLATION to _TIF_WORK_MASK, while leaving the old bitmask value as _TIF_WORK_LOOP_MASK to check while looping. We tweak syscall_trace_enter() slightly to carry the "flags" value from current_thread_info()->flags for each of the tests, rather than doing a volatile read from memory for each one. This avoids a small overhead for each test, and in particular avoids that overhead for TIF_NOHZ when TASK_ISOLATION is not enabled. We instrument the smp_cross_call() routine so that it checks for isolated tasks and generates a suitable warning if we are about to disturb one of them in strict or debug mode. Finally, add an explicit check for STRICT mode in do_mem_abort() to handle the case of page faults. Signed-off-by: Chris Metcalf --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/thread_info.h | 5 ++++- arch/arm64/kernel/ptrace.c | 15 ++++++++++++--- arch/arm64/kernel/signal.c | 10 ++++++++++ arch/arm64/kernel/smp.c | 2 ++ arch/arm64/mm/fault.c | 4 ++++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 4f436220384f..ec033abee9d5 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -57,6 +57,7 @@ config ARM64 select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT select HAVE_ARCH_SECCOMP_FILTER + select HAVE_ARCH_TASK_ISOLATION select HAVE_ARCH_TRACEHOOK select HAVE_BPF_JIT select HAVE_C_RECORDMCOUNT diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index abd64bd1f6d9..bdc6426b9968 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -109,6 +109,7 @@ static inline struct thread_info *current_thread_info(void) #define TIF_NEED_RESCHED 1 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */ #define TIF_FOREIGN_FPSTATE 3 /* CPU's FP state is not current's */ +#define TIF_TASK_ISOLATION 4 #define TIF_NOHZ 7 #define TIF_SYSCALL_TRACE 8 #define TIF_SYSCALL_AUDIT 9 @@ -124,6 +125,7 @@ static inline struct thread_info *current_thread_info(void) #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) #define _TIF_FOREIGN_FPSTATE (1 << TIF_FOREIGN_FPSTATE) +#define _TIF_TASK_ISOLATION (1 << TIF_TASK_ISOLATION) #define _TIF_NOHZ (1 << TIF_NOHZ) #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) @@ -132,7 +134,8 @@ static inline struct thread_info *current_thread_info(void) #define _TIF_32BIT (1 << TIF_32BIT) #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \ - _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE) + _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \ + _TIF_TASK_ISOLATION) #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 3f6cd5c5234f..ae336065733d 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -1246,14 +1247,22 @@ static void tracehook_report_syscall(struct pt_regs *regs, asmlinkage int syscall_trace_enter(struct pt_regs *regs) { - /* Do the secure computing check first; failures should be fast. */ + unsigned long work = ACCESS_ONCE(current_thread_info()->flags); + + /* In isolation mode, we may prevent the syscall from running. */ + if (work & _TIF_TASK_ISOLATION) { + if (task_isolation_syscall(regs->syscallno) == -1) + return -1; + } + + /* Do the secure computing check early; failures should be fast. */ if (secure_computing() == -1) return -1; - if (test_thread_flag(TIF_SYSCALL_TRACE)) + if (work & _TIF_SYSCALL_TRACE) tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER); - if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) + if (work & _TIF_SYSCALL_TRACEPOINT) trace_sys_enter(regs, regs->syscallno); audit_syscall_entry(regs->syscallno, regs->orig_x0, regs->regs[1], diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 404dd67080b9..f9b9b25636ca 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -424,9 +425,18 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, if (thread_flags & _TIF_FOREIGN_FPSTATE) fpsimd_restore_current_state(); + + if (thread_flags & _TIF_TASK_ISOLATION) + task_isolation_enter(); } local_irq_disable(); thread_flags = READ_ONCE(current_thread_info()->flags); + + /* Clear task isolation from cached_flags manually. */ + if ((thread_flags & _TIF_TASK_ISOLATION) && + task_isolation_ready()) + thread_flags &= ~_TIF_TASK_ISOLATION; + } while (thread_flags & _TIF_WORK_MASK); } diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index b2d5f4ee9a1c..83ed6b5baa4d 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -710,6 +711,7 @@ static const char *ipi_types[NR_IPI] __tracepoint_string = { static void smp_cross_call(const struct cpumask *target, unsigned int ipinr) { trace_ipi_raise(target, ipi_types[ipinr]); + task_isolation_debug_cpumask(target); __smp_cross_call(target, ipinr); } diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 95df28bc875f..77f827b02c6d 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -482,6 +483,9 @@ asmlinkage void __exception do_mem_abort(unsigned long addr, unsigned int esr, const struct fault_info *inf = fault_info + (esr & 63); struct siginfo info; + if (user_mode(regs)) + task_isolation_exception("%s at %#lx", inf->name, addr); + if (!inf->fn(addr, esr, regs)) return; -- 2.7.2