From patchwork Sun Mar 8 03:44:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250974 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=J/pFjUIx; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=Kiz2qXZn; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48ZnL14fBvz9sSK for ; Sun, 8 Mar 2020 14:44:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726353AbgCHDon (ORCPT ); Sat, 7 Mar 2020 22:44:43 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:40790 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726259AbgCHDom (ORCPT ); Sat, 7 Mar 2020 22:44:42 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283fbk1011848; Sat, 7 Mar 2020 19:44:15 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=mOmcxhcHfdvs2/ffWTPRYKAh6MJbVx4NXz+n9OW7E6A=; b=J/pFjUIxxIZrdncw+in5uedPYv1Zy9oC9zlPa+r40DIeGWM8KZ4WTxUGEWk3FtvinapR aUVQeCgGgvwucKje6c5QBBP0rvil8jKdNVwMxtUlbzhBUn5iXjS1CAEbAjWr6mjtu7jO HY+YpTyDBHSPTaAPo9kA2uneKtPc3f4kzgvsJpGnhu0khfMGub5EvFIR6G+m5+U8/Cf7 NemBtfDR4ezvm40vBxnOtEwqS3HR0/QyleKCMoBd6BOmaKNTTpLYSf3CRo6mOgScIqn0 aljJgGkbqh8silJSUjcIMjb2OxGTWHvN5rr+4ui20DbxUayFAI/GtUhg5qBer+mCm9K8 Kw== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 2ymc0sj1e1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:44:15 -0800 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:44:12 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.102) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:44:12 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kqw0QOMZJuRqzCIIDZt5iygL+7Jcsh1mzV+obWsZEM6fmV9Ol8wKO6EHSbwtRepb24/hKjrbrMT2W7w5DM6vngPbU+XcnDFkT2kD5SBo0fab0Lq82gbIbnLnJPlljV6BoS6C0CVm9BGAngcK9PK5PtZmCSFQh9DJWdRX9gtQI6fXC2QxTDr8p9uvtkjoJQkP2gr5K1cV2w/UYoeS04Tq4jOmheBuUrmwxrv/C2YxQPR9msDEPJKdNbUGTQkx0XmDL3ehjdEV/C83gXV9KKEQ6qp5R/6hVFF3pHIXNkYKkwL6LDwXOp8n41ZmA2vqK3ZDfe5QK3LOfQdBSHrccObiFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mOmcxhcHfdvs2/ffWTPRYKAh6MJbVx4NXz+n9OW7E6A=; b=kYj5sUX0e4idCLBW5O6ExKsALxWDl0mZfln5k7O7Eu3CGCXQ78zJr4N0Jcd4YGNGGs+Xb2hWXmZx1it8oaCLcFoxVznWLwpko+XqZQFWapkdAfwkInMW+IpmegrUtqoXz/ijDwtz+Gh1PU8r3XP5luYv6YXBL5CQ59nNu3Z6yeKOWN9xmPF7uW+9FPd0MdOdl42IOQybACt6RlGAwDxxYDofTlyQYCyf2gTxmUe3q0r/ZtPg9qB+h0pGV0sIk0+qRgExaWN85G06UAq6nb/SxUS0heDS2rnqr+S8mbRXgRKjzMWVV98kIqcqM3a6kceQUvc2Gs1BmY3Yfj7LzaPymg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mOmcxhcHfdvs2/ffWTPRYKAh6MJbVx4NXz+n9OW7E6A=; b=Kiz2qXZnpzsVJ1vcKIEtXnmxIN2LmAJ7SQWe6RCiNezFn7XNNaW+gPr966Aujog+pL9WDdGlJQxctco9ZpVfd6REICf5g+tDl9HUIj3grIA18PJ6J/c9OLgVHS+TvsSkK++PINhKhRcbBk0HPi09NO3Jf8EZq/2V7IY42g7lfJ0= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2920.namprd18.prod.outlook.com (2603:10b6:a03:10b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.14; Sun, 8 Mar 2020 03:44:11 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:44:11 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 01/12] task_isolation: vmstat: add quiet_vmstat_sync function Thread-Topic: [PATCH v2 01/12] task_isolation: vmstat: add quiet_vmstat_sync function Thread-Index: AQHV9PvUoI+q+Qtq5kW5lYF66zseNQ== Date: Sun, 8 Mar 2020 03:44:11 +0000 Message-ID: <3118206b99e862d4c163eefd086af14dd12fe305.camel@marvell.com> References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5d1224fc-89a5-442e-bda2-08d7c312f6db x-ms-traffictypediagnostic: BYAPR18MB2920: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1186; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(136003)(396003)(39850400004)(376002)(346002)(366004)(199004)(189003)(316002)(66946007)(5660300002)(6512007)(478600001)(8936002)(71200400001)(2906002)(6486002)(66556008)(66476007)(76116006)(6506007)(91956017)(64756008)(66446008)(36756003)(54906003)(4326008)(2616005)(186003)(110136005)(8676002)(26005)(81166006)(81156014)(86362001)(7416002); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2920; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: LCevfyd3TjO59jIN9PP1YJOR99nlqERfDWpOJlXWY8oPyYugKX+jB4Bk7nBnfFdFzRm/+W8p+7rjrehCbKQATyJNz2XBhdI26ArNcnSLHvqNyGpuNRel6NBW1f5Q2Tl4r7HgdRIKRG5aGwZALhO6iwplnmS61cPpH1y8OxQwdccsX+E7lvoihxHgi+5XpxMtDrDfK3F2Uxrbte0g7VPPDBxY2QQrznkahFPMYinQVlPPO+sFv+qmPAYRY9hqFHDaKdDiq9dw5+5KW1Cygdd7Ze+3bl9c7vrVSKS/CRb5uy66yXRQepZwGrN9A4W537gOCTx0bV8C01ijSBmk+JkXXw3JVovVLvn5ENqX51+dEYRPsSMCi8EKCdUArnPFYb4HF1ux9kmz0KY25LuSn9omsTgZyiUOeseQWrFP7ZO1QYAyaAB1P8PYJw0sT+y4spTP x-ms-exchange-antispam-messagedata: 49h2ZUw5oVc8dq9Nq1GSF3wGOCqyiaL3QCbh9CtMm0vuauL+urIaxaHwwPAjefKwAUw07f6ejnEt/mLjflzKNP7L4/Qd24HISokvazlw2bzaQdV5of4JiC66izy4kSfQM3Z/Lpcr57L+6tGlbIl92w== Content-ID: <34D5BF63C3F7774795D2B302FE3EC1E3@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 5d1224fc-89a5-442e-bda2-08d7c312f6db X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:44:11.3448 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: U8+wW6UiKHPmk+1ZkPKeDK3YiFcdKcvJYKSJ43o5xYUUK8vflOm6VrlSajQrIfb9KIVzcCmDxlKr1CdEVUDSdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2920 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Chris Metcalf In commit f01f17d3705b ("mm, vmstat: make quiet_vmstat lighter") the quiet_vmstat() function became asynchronous, in the sense that the vmstat work was still scheduled to run on the core when the function returned. For task isolation, we need a synchronous version of the function that guarantees that the vmstat worker will not run on the core on return from the function. Add a quiet_vmstat_sync() function with that semantic. Signed-off-by: Chris Metcalf Signed-off-by: Alex Belits --- include/linux/vmstat.h | 2 ++ mm/vmstat.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 292485f3d24d..2bc5e85f2514 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -270,6 +270,7 @@ extern void __dec_zone_state(struct zone *, enum zone_stat_item); extern void __dec_node_state(struct pglist_data *, enum node_stat_item); void quiet_vmstat(void); +void quiet_vmstat_sync(void); void cpu_vm_stats_fold(int cpu); void refresh_zone_stat_thresholds(void); @@ -372,6 +373,7 @@ static inline void __dec_node_page_state(struct page *page, static inline void refresh_zone_stat_thresholds(void) { } static inline void cpu_vm_stats_fold(int cpu) { } static inline void quiet_vmstat(void) { } +static inline void quiet_vmstat_sync(void) { } static inline void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset) { } diff --git a/mm/vmstat.c b/mm/vmstat.c index 78d53378db99..1fa0b2d04afa 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1870,6 +1870,15 @@ void quiet_vmstat(void) refresh_cpu_vm_stats(false); } +/* + * Synchronously quiet vmstat so the work is guaranteed not to run on return. + */ +void quiet_vmstat_sync(void) +{ + cancel_delayed_work_sync(this_cpu_ptr(&vmstat_work)); + refresh_cpu_vm_stats(false); +} + /* * Shepherd worker thread that checks the * differentials of processors that have their worker From patchwork Sun Mar 8 03:46:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250975 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=flxrLBa2; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=atlvKHHH; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48ZnNH5TpYz9sSL for ; Sun, 8 Mar 2020 14:46:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726303AbgCHDqx (ORCPT ); Sat, 7 Mar 2020 22:46:53 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:24666 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726116AbgCHDqx (ORCPT ); Sat, 7 Mar 2020 22:46:53 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283fYMH006247; Sat, 7 Mar 2020 19:46:10 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=3zRBZywEQlwY12ZkVBkV2O6spn9XfENf40p27pJFgsE=; b=flxrLBa2lSLz3b7rVYBwYdQFXPpnIve6rQ6ycea9sTG2CX3z91Xjcbl8FxqXzxQPzzJH woSA6H+KmRK7Ke2lMljU0EIlED3niCNh/KHT1TvH75AwRNZxTAblQQXFkBD33/ly4eCj bC0D+eFWlxww/ChwY9AoGRSMut81+rsd80eLFKsoKXAPbHwgHr6zsx6iGeXMq4TwsZvF U/9ocFbXI6XCproDO4yOXpHwquDyBgOODDrwktV65sQsAiWtehVw0nKqR/s6/iM5vssc H7n7Q5hX0oUjyiv/9RNV/04u0+U3IcGPjD1+VZx70WpxmQ9BAyvUzcPoBlsFTi6KyqNh Mw== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 2ym9uwauxt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:46:09 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:46:08 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.107) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:46:08 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f7SztssoDwbVn+IPYnqSV/zeBbIEgIc/8TrdhxFz3FpWY9WCwL950P6zrIYdL5mxLfeCKi9xIdBVoJuY8Qi/u1lbZiKxxBa3yXmKIOFmQkPuPSK2BGAEdMMboRs6QAsjAWcflEn/WOssnJtCfHuI7ukKV9Nau9b8qYz0YcVSzZYiBzxQti/kbxQWFcgDg5XxnDs3D3PQ0ra8bVZkmEcaDKtOuBEsc4iniY8tr3Ioie+M6RTQwc5k5rC5e7R/FlPBgrU2x4D0O/vEieVREf6//SLKZGz1ZcocASPSa3AdkCQci779It6iKbeucPLCmj+l0OzqnYzj2W5+7jwN+3JK0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3zRBZywEQlwY12ZkVBkV2O6spn9XfENf40p27pJFgsE=; b=XZnuF4CEn/8M4p+rlJlDl3QaTj4E9IloO2VY6/taw50YY8MHM24xYvU4EELygQ5COns8kQp/qiz/cYjXZBhSR7Jf8AuKTb/20bDiUz8tKUJ5fibmb+6silrq6YMMnfxKM5nAolcuckZ6mlSNjQ4ODWtUYsQvK5O2rCmPwd4+T5nODSuutMB0VAio6EaHDx7J4CYFFXopKjblcQxgZW+k9pmFHBHBULtSO7ji0j6+OWuKI4GXJd7vv8iW1HScGSLzZffxOSBBihwcwiBMNTP2stpdczLgeTQDThfhSBcjSFGJeVxNsOEdpJi58gdi4CdXh9mDAaTVh16K7fL2FoKAQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3zRBZywEQlwY12ZkVBkV2O6spn9XfENf40p27pJFgsE=; b=atlvKHHH5l1ITNHjhhKbaYhZnJP8/ILb7J/uJYl6NVKuSmQRMJ6fIwcpK1MYKbor3JADr9jZYyBuCRIIRXrXU+PUmh+ZyQ+rkfkzt2ZpZjEuZLrmHQ0yvxaFx1kj7zmi0q7wJKcAmJCkaYaguvRnZ3VCSmCsyLJ4Yos2CsI9JuU= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2920.namprd18.prod.outlook.com (2603:10b6:a03:10b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.14; Sun, 8 Mar 2020 03:46:07 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:46:07 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 02/12] task_isolation: vmstat: add vmstat_idle function Thread-Topic: [PATCH v2 02/12] task_isolation: vmstat: add vmstat_idle function Thread-Index: AQHV9PwZGuit9HuXRU+77sdJLQQteg== Date: Sun, 8 Mar 2020 03:46:07 +0000 Message-ID: <3443bdf4ff557331c39a99b133defee56452be48.camel@marvell.com> References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4ecca648-818e-4a2f-3bea-08d7c3133c1b x-ms-traffictypediagnostic: BYAPR18MB2920: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4502; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(136003)(396003)(39850400004)(376002)(346002)(366004)(199004)(189003)(316002)(66946007)(5660300002)(6512007)(478600001)(8936002)(71200400001)(2906002)(6486002)(66556008)(66476007)(76116006)(6506007)(91956017)(64756008)(66446008)(36756003)(54906003)(4326008)(2616005)(186003)(110136005)(8676002)(26005)(81166006)(81156014)(86362001)(7416002); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2920; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: K1w9NNQLSIZEVeuLwjLXHmyPgxXu6iAwZEAz/weEU0znNRgUcfvjMwgEMM1+kpx3lOiMf1LLhAd1jWJ07uykEKgLagewGDDDMsajyvDwI+TiIh9Bi24tOOHju9OGOMZaRctCg8iU9MWyTdSPHY3LgqpJGRMpPO8vCCVAc6T8fUkYVs+31mk9zLRPUqiU/gSQMc8Nmdb5ItbJ3COx7PgLle36C6fpmO5UPo1AARIJtB/2WiLYaydcnulzA4QBaBE7QexjyK0BaXXVJR+mdatJMm0RdU3v8r/0HX7rrU0eE7j0r3oeXCox3GOfeFNoCwiDG1OMMqQTXOvJ2IhaQuMqLRmAA8nhGjP+MKV2jboWXNvFo96+f3KilaeM9GsSh8mWFUhvMwhzlSDNkQwCP74zslEeccB4wZeGiInA1uscJVNKQRM04RrQUN8XB6bBttbF x-ms-exchange-antispam-messagedata: OHEcJGmt41CWcun0s7cQbSTV28EEdejWEH0FpXvuR8uy9aA5YrCbjBhyRIKACaXrb8av2QbW828CjUjoUKRzTwWo1iGXhVMcBk71xvm/30zMayitQEV9fYoZE7XxnudozjkwEDSiXjMSgw+g1BmkXg== Content-ID: <31B867DD531EED43ABA359B8014CD8B7@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 4ecca648-818e-4a2f-3bea-08d7c3133c1b X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:46:07.5137 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: OSE0VXI9N6Pxe2NZ3UMhSPuxeK0lKS3PND98sFxxqba3DAPTWcipf2lUr93WpfSVvIpxN+W8QFcCbMUCAtr4jg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2920 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Chris Metcalf This function checks to see if a vmstat worker is not running, and the vmstat diffs don't require an update. The function is called from the task-isolation code to see if we need to actually do some work to quiet vmstat. Signed-off-by: Chris Metcalf Signed-off-by: Alex Belits --- include/linux/vmstat.h | 2 ++ mm/vmstat.c | 10 ++++++++++ 2 files changed, 12 insertions(+) * differentials of processors that have their worker diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 2bc5e85f2514..66d9ae32cf07 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -271,6 +271,7 @@ extern void __dec_node_state(struct pglist_data *, enum node_stat_item); void quiet_vmstat(void); void quiet_vmstat_sync(void); +bool vmstat_idle(void); void cpu_vm_stats_fold(int cpu); void refresh_zone_stat_thresholds(void); @@ -374,6 +375,7 @@ static inline void refresh_zone_stat_thresholds(void) { } static inline void cpu_vm_stats_fold(int cpu) { } static inline void quiet_vmstat(void) { } static inline void quiet_vmstat_sync(void) { } +static inline bool vmstat_idle(void) { return true; } static inline void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset) { } diff --git a/mm/vmstat.c b/mm/vmstat.c index 1fa0b2d04afa..5c4aec651062 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1879,6 +1879,16 @@ void quiet_vmstat_sync(void) refresh_cpu_vm_stats(false); } +/* + * Report on whether vmstat processing is quiesced on the core currently: + * no vmstat worker running and no vmstat updates to perform. + */ +bool vmstat_idle(void) +{ + return !delayed_work_pending(this_cpu_ptr(&vmstat_work)) && + !need_update(smp_processor_id()); +} + /* * Shepherd worker thread that checks the From patchwork Sun Mar 8 03:47:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250976 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=fuLCASPB; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=HrBNwBvU; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48ZnPb1Yxfz9sSM for ; Sun, 8 Mar 2020 14:48:03 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726346AbgCHDsA (ORCPT ); Sat, 7 Mar 2020 22:48:00 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:50270 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726116AbgCHDr7 (ORCPT ); Sat, 7 Mar 2020 22:47:59 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283kgeP010472; Sat, 7 Mar 2020 19:47:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=//FmOczEWgkGYUmePhPUIERaj4n3oxFfYqv74bQpsog=; b=fuLCASPBDQNNdRK4E9rU4oh+ZYopzF0C779+V+cJ/yPkM1PcH1W2BZyBTMxUd56GntD2 jI+nVJdbrkheEItfPk2VWN76URwTUBRKo9KDGvyzgyr+Sn7Zb3ukJ7HG7up7IDcmQ7cX navAInm8X6JBPhVrYxPgULhbVaf54vFi6pCSxgJAiC4J0r0aBaO2nThbDCAE30h95Stk 1F7Pom20j7+HiyLE8L7j6xbhWf2PGoEF8DvXtIv1RMqJqYgqQEOBhe5dg2zHtto4MMFE 7yESZd2Z/mI3sPXcE06Ayj0UZUE+ZlzOK3PBkvR0jIHOX7lBNvrqROjbsZ9vXXvE9Lu9 /A== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 2ym9uwav15-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:47:13 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:47:12 -0800 Received: from SC-EXCH04.marvell.com (10.93.176.84) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:47:11 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.102) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:47:11 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DoiE2kWVSmnvkVrol2AT8cZ+5d6e/vkC8QpaV8beiSy0oc4645ZZX5tEqeKfhvkiwxFcr431v3WRwRc5oNJxhKFJ9HcN/1MswpQK/o6PQP2hwg6NdmZ7zKeCaiubpOJEb6Qdnd0fgGPDWdzOYsaOr7f2xRvD5AkI9GFdICU7cq7oslWpclEn0BCu5xT4U8Ba/07ldFtmH6a4uTQCEGGbBlGm/56loMm7sXFGSFUbxvrMdtCJcXeF+PXIxc6qnd2n/lgu0GsY+kkJuljTN4nfzcU530FC1AM4LjvTdxlx34DjX8h8hMUz/4vRu0FMtXlCEKDpXFOqlocQ2cdIpvUzXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=//FmOczEWgkGYUmePhPUIERaj4n3oxFfYqv74bQpsog=; b=niE9nqpF+SGraSUNox0FlEpVLwcc6va9Op2OVwS7kj5uVChK5nGuUFcReOjMbCEbWqzmA1qGG4T4gAMOJaK7uGiJH3uPGGNQE3+utIqRgD0wAX82UN1u5xBScnLSMLs+FkFPPhieL2Ea9e8xPtuPk6IcsBnEto/YGiBIjtV7w9nl8Vk2NXeCeWqQkkcc5jQpklod27xqIHMrPANKROr7bBNWOF9pFSTWuGW57vaNTZU/GTq3ST8SnUbs7o9DbH4t5Zr9/+Tytu6d3oidiCUA90Gh9Er5U/V7azIbHji6DyPefnGfSxaCmOcO/Gz75/kZmLxvr6MVyHVyWnMAGHf6fQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=//FmOczEWgkGYUmePhPUIERaj4n3oxFfYqv74bQpsog=; b=HrBNwBvUQx1vPyxc9WZUVW/a14RSbtcOC/WB8kqH6BWKseM3KIGzRMqnE3+NMAEuPfT+M/lyaVm0tCEjCzPRGh8/4yPW0m5vInbKxDNl2PGqjnwNl5qQQVFHe4kbwoMXOTCeF7RZizksmJHDPqiiDLCblJiGycKq5OfMWbO0zHU= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2920.namprd18.prod.outlook.com (2603:10b6:a03:10b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.14; Sun, 8 Mar 2020 03:47:09 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:47:09 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 03/12] task_isolation: userspace hard isolation from kernel Thread-Topic: [PATCH v2 03/12] task_isolation: userspace hard isolation from kernel Thread-Index: AQHV9Pw+p8WFE2eefk2Rf0eNEw4Adw== Date: Sun, 8 Mar 2020 03:47:08 +0000 Message-ID: <105f17f25e90a9a58299a7ed644bdd0f36434c87.camel@marvell.com> References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0296d72d-cb49-482e-30e9-08d7c31360e6 x-ms-traffictypediagnostic: BYAPR18MB2920: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(136003)(396003)(39850400004)(376002)(346002)(366004)(199004)(189003)(316002)(66946007)(5660300002)(6512007)(30864003)(478600001)(8936002)(71200400001)(2906002)(6486002)(66556008)(66476007)(76116006)(6506007)(91956017)(64756008)(66446008)(36756003)(54906003)(4326008)(2616005)(186003)(110136005)(8676002)(26005)(81166006)(81156014)(86362001)(7416002)(21314003)(579004)(559001); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2920; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: X1sj4YgHvePNMAfh/S3vcE8Ijjwtv2BsursbIsiAtQ3EJ+nX6Qrm/75FCDnFxVwDLAAtOowXWklmW2lPyd+MefBl1DvQiI4xkQ2zIWx1PiGUHAjxnjWJhzgqclPl/4HNMjdPlnNO1XbkVeNY6Vd1T3IUFE/Oy+r6pgy09PlkzOpJpDhV4jXlHyExaUUdrYVekWhANB9odmcXauDBCy06pIXitlwcVMyq3NJoaPgxNvSDJ6q8HSfYP7SxWdneCQEIPGxt81lAPlRt7pjcUlhesGeAp7WnBT4e7i18aHtu4A/WgsoZP0LpQRdvZAl9Ixtx/eRkcxsd0VX1R1WaFwmSRGxmHgDQyTx4BUODJeK4o4D9+SgG5BCdaQqbAYTuJGoGGaXvlltPvmp7Ew8a9H3FT1TB1fdVb/X/Xx+1ipLB/K2zJofGYSqnijbSoE+7QC4ZaCbvOQpybZZ42NahA1l/+qVQYfqLSSehKe8u22LT6FrVho/NvygJsv4LL3/px/hn x-ms-exchange-antispam-messagedata: qkYGMFQsG4os70GgHJwG2r37KQL/rjm2UhhEQDGQ6sPZETmXGTFrRNaEGAMVjXKYfkRdA0FITnBU2w58kkjp7V2J/M4ZJkt4zpkAICWCW2BgT/JWepgwnNYvqC76nMNzO/rvgT6wODSpmY0RnJqABw== Content-ID: <86098B5433923643954377077B047068@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 0296d72d-cb49-482e-30e9-08d7c31360e6 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:47:09.2268 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: a4TBQkCJcH+fRsxY20H8EX/JYhaGJ9dd/NrTls+SfkSjeM0FD7I0TDUoLZXEApD1NIEIbBjhMqAC2ie7a/9ygg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2920 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The existing nohz_full mode is designed as a "soft" isolation mode that makes tradeoffs to minimize userspace interruptions while still attempting to avoid overheads in the kernel entry/exit path, to provide 100% kernel semantics, etc. However, some applications require a "hard" commitment from the kernel to avoid interruptions, in particular userspace device driver style applications, such as high-speed networking code. This change introduces a framework to allow applications to elect to have the "hard" semantics as needed, specifying prctl(PR_TASK_ISOLATION, PR_TASK_ISOLATION_ENABLE) to do so. The kernel must be built with the new TASK_ISOLATION Kconfig flag to enable this mode, and the kernel booted with an appropriate "isolcpus=nohz,domain,CPULIST" boot argument to enable nohz_full and isolcpus. The "task_isolation" state is then indicated by setting a new task struct field, task_isolation_flag, to the value passed by prctl(), and also setting a TIF_TASK_ISOLATION bit in the thread_info flags. When the kernel is returning to userspace from the prctl() call and sees TIF_TASK_ISOLATION set, it calls the new task_isolation_start() routine to arrange for the task to avoid being interrupted in the future. With interrupts disabled, task_isolation_start() ensures that kernel subsystems that might cause a future interrupt are quiesced. If it doesn't succeed, it adjusts the syscall return value to indicate that fact, and userspace can retry as desired. In addition to stopping the scheduler tick, the code takes any actions that might avoid a future interrupt to the core, such as a worker thread being scheduled that could be quiesced now (e.g. the vmstat worker) or a future IPI to the core to clean up some state that could be cleaned up now (e.g. the mm lru per-cpu cache). Once the task has returned to userspace after issuing the prctl(), if it enters the kernel again via system call, page fault, or any other exception or irq, the kernel will kill it with SIGKILL. In addition to sending a signal, the code supports a kernel command-line "task_isolation_debug" flag which causes a stack backtrace to be generated whenever a task loses isolation. To allow the state to be entered and exited, the syscall checking test ignores the prctl(PR_TASK_ISOLATION) syscall so that we can clear the bit again later, and ignores exit/exit_group to allow exiting the task without a pointless signal being delivered. The prctl() API allows for specifying a signal number to use instead of the default SIGKILL, to allow for catching the notification signal; for example, in a production environment, it might be helpful to log information to the application logging mechanism before exiting. Or, the signal handler might choose to reset the program counter back to the code segment intended to be run isolated via prctl() to continue execution. In a number of cases we can tell on a remote cpu that we are going to be interrupting the cpu, e.g. via an IPI or a TLB flush. In that case we generate the diagnostic (and optional stack dump) on the remote core to be able to deliver better diagnostics. If the interrupt is not something caught by Linux (e.g. a hypervisor interrupt) we can also request a reschedule IPI to be sent to the remote core so it can be sure to generate a signal to notify the process. Separate patches that follow provide these changes for x86, arm, and arm64. Signed-off-by: Alex Belits --- .../admin-guide/kernel-parameters.txt | 6 + include/linux/hrtimer.h | 4 + include/linux/isolation.h | 229 ++++++ include/linux/sched.h | 4 + include/linux/tick.h | 3 + include/uapi/linux/prctl.h | 6 + init/Kconfig | 28 + kernel/Makefile | 2 + kernel/context_tracking.c | 2 + kernel/isolation.c | 774 ++++++++++++++++++ kernel/signal.c | 2 + kernel/sys.c | 6 + kernel/time/hrtimer.c | 27 + kernel/time/tick-sched.c | 18 + 14 files changed, 1111 insertions(+) create mode 100644 include/linux/isolation.h create mode 100644 kernel/isolation.c diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index c07815d230bc..e4a2d6e37645 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4808,6 +4808,12 @@ neutralize any effect of /proc/sys/kernel/sysrq. Useful for debugging. + task_isolation_debug [KNL] + In kernels built with CONFIG_TASK_ISOLATION, this + setting will generate console backtraces to + accompany the diagnostics generated about + interrupting tasks running with task isolation. + tcpmhash_entries= [KNL,NET] Set the number of tcp_metrics_hash slots. Default value is 8192 or 16384 depending on total diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index 15c8ac313678..e81252eb4f92 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -528,6 +528,10 @@ extern void __init hrtimers_init(void); /* Show pending timers: */ extern void sysrq_timer_list_show(void); +#ifdef CONFIG_TASK_ISOLATION +extern void kick_hrtimer(void); +#endif + int hrtimers_prepare_cpu(unsigned int cpu); #ifdef CONFIG_HOTPLUG_CPU int hrtimers_dead_cpu(unsigned int cpu); diff --git a/include/linux/isolation.h b/include/linux/isolation.h new file mode 100644 index 000000000000..6bd71c67f10f --- /dev/null +++ b/include/linux/isolation.h @@ -0,0 +1,229 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Task isolation support + * + * Authors: + * Chris Metcalf + * Alex Belits + * Yuri Norov + */ +#ifndef _LINUX_ISOLATION_H +#define _LINUX_ISOLATION_H + +#include +#include +#include +#include +#include + +struct task_struct; + +#ifdef CONFIG_TASK_ISOLATION + +int task_isolation_message(int cpu, int level, bool supp, const char *fmt, ...); + +#define pr_task_isol_emerg(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_EMERG, false, fmt, ##__VA_ARGS__) +#define pr_task_isol_alert(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_ALERT, false, fmt, ##__VA_ARGS__) +#define pr_task_isol_crit(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_CRIT, false, fmt, ##__VA_ARGS__) +#define pr_task_isol_err(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_ERR, false, fmt, ##__VA_ARGS__) +#define pr_task_isol_warn(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_WARNING, false, fmt, ##__VA_ARGS__) +#define pr_task_isol_notice(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_NOTICE, false, fmt, ##__VA_ARGS__) +#define pr_task_isol_info(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_INFO, false, fmt, ##__VA_ARGS__) +#define pr_task_isol_debug(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_DEBUG, false, fmt, ##__VA_ARGS__) + +#define pr_task_isol_emerg_supp(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_EMERG, true, fmt, ##__VA_ARGS__) +#define pr_task_isol_alert_supp(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_ALERT, true, fmt, ##__VA_ARGS__) +#define pr_task_isol_crit_supp(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_CRIT, true, fmt, ##__VA_ARGS__) +#define pr_task_isol_err_supp(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_ERR, true, fmt, ##__VA_ARGS__) +#define pr_task_isol_warn_supp(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_WARNING, true, fmt, ##__VA_ARGS__) +#define pr_task_isol_notice_supp(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_NOTICE, true, fmt, ##__VA_ARGS__) +#define pr_task_isol_info_supp(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_INFO, true, fmt, ##__VA_ARGS__) +#define pr_task_isol_debug_supp(cpu, fmt, ...) \ + task_isolation_message(cpu, LOGLEVEL_DEBUG, true, fmt, ##__VA_ARGS__) +DECLARE_PER_CPU(unsigned long, tsk_thread_flags_copy); +extern cpumask_var_t task_isolation_map; + +/** + * task_isolation_request() - prctl hook to request task isolation + * @flags: Flags from PR_TASK_ISOLATION_xxx. + * + * This is called from the generic prctl() code for PR_TASK_ISOLATION. + * + * Return: Returns 0 when task isolation enabled, otherwise a negative + * errno. + */ +extern int task_isolation_request(unsigned int flags); +extern void task_isolation_cpu_cleanup(void); +/** + * task_isolation_start() - attempt to actually start task isolation + * + * This function should be invoked as the last thing prior to returning to + * user space if TIF_TASK_ISOLATION is set in the thread_info flags. It + * will attempt to quiesce the core and enter task-isolation mode. If it + * fails, it will reset the system call return value to an error code that + * indicates the failure mode. + */ +extern void task_isolation_start(void); + +/** + * is_isolation_cpu() - check if CPU is intended for running isolated tasks. + * @cpu: CPU to check. + */ +static inline bool is_isolation_cpu(int cpu) +{ + return task_isolation_map != NULL && + cpumask_test_cpu(cpu, task_isolation_map); +} + +/** + * task_isolation_on_cpu() - check if the cpu is running isolated task + * @cpu: CPU to check. + */ +extern int task_isolation_on_cpu(int cpu); +extern void task_isolation_check_run_cleanup(void); + +/** + * task_isolation_cpumask() - set CPUs currently running isolated tasks + * @mask: Mask to modify. + */ +extern void task_isolation_cpumask(struct cpumask *mask); + +/** + * task_isolation_clear_cpumask() - clear CPUs currently running isolated tasks + * @mask: Mask to modify. + */ +extern void task_isolation_clear_cpumask(struct cpumask *mask); + +/** + * task_isolation_syscall() - report a syscall from an isolated task + * @nr: The syscall number. + * + * This routine should be invoked at syscall entry if TIF_TASK_ISOLATION is + * set in the thread_info flags. It checks for valid syscalls, + * specifically prctl() with PR_TASK_ISOLATION, exit(), and exit_group(). + * For any other syscall it will raise a signal and return failure. + * + * Return: 0 for acceptable syscalls, -1 for all others. + */ +extern int task_isolation_syscall(int nr); + +/** + * _task_isolation_interrupt() - report an interrupt of an isolated task + * @fmt: A format string describing the interrupt + * @...: Format arguments, if any. + * + * This routine should be invoked at any exception or IRQ if + * TIF_TASK_ISOLATION is set in the thread_info flags. It is not necessary + * to invoke it if the exception will generate a signal anyway (e.g. a bad + * page fault), and in that case it is preferable not to invoke it but just + * rely on the standard Linux signal. The macro task_isolation_syscall() + * wraps the TIF_TASK_ISOLATION flag test to simplify the caller code. + */ +extern void _task_isolation_interrupt(const char *fmt, ...); +#define task_isolation_interrupt(fmt, ...) \ + do { \ + if (current_thread_info()->flags & _TIF_TASK_ISOLATION) \ + _task_isolation_interrupt(fmt, ## __VA_ARGS__); \ + } while (0) + +/** + * task_isolation_remote() - report a remote interrupt of an isolated task + * @cpu: The remote cpu that is about to be interrupted. + * @fmt: A format string describing the interrupt + * @...: Format arguments, if any. + * + * This routine should be invoked any time a remote IPI or other type of + * interrupt is being delivered to another cpu. The function will check to + * see if the target core is running a task-isolation task, and generate a + * diagnostic on the console if so; in addition, we tag the task so it + * doesn't generate another diagnostic when the interrupt actually arrives. + * Generating a diagnostic remotely yields a clearer indication of what + * happened then just reporting only when the remote core is interrupted. + * + */ +extern void task_isolation_remote(int cpu, const char *fmt, ...); + +/** + * task_isolation_remote_cpumask() - report interruption of multiple cpus + * @mask: The set of remotes cpus that are about to be interrupted. + * @fmt: A format string describing the interrupt + * @...: Format arguments, if any. + * + * This is the cpumask variant of _task_isolation_remote(). We + * generate a single-line diagnostic message even if multiple remote + * task-isolation cpus are being interrupted. + */ +extern void task_isolation_remote_cpumask(const struct cpumask *mask, + const char *fmt, ...); + +/** + * _task_isolation_signal() - disable task isolation when signal is pending + * @task: The task for which to disable isolation. + * + * This function generates a diagnostic and disables task isolation; it + * should be called if TIF_TASK_ISOLATION is set when notifying a task of a + * pending signal. The task_isolation_interrupt() function normally + * generates a diagnostic for events that just interrupt a task without + * generating a signal; here we need to hook the paths that correspond to + * interrupts that do generate a signal. The macro task_isolation_signal() + * wraps the TIF_TASK_ISOLATION flag test to simplify the caller code. + */ +extern void _task_isolation_signal(struct task_struct *task); +#define task_isolation_signal(task) \ + do { \ + if (task_thread_info(task)->flags & _TIF_TASK_ISOLATION) \ + _task_isolation_signal(task); \ + } while (0) + +/** + * task_isolation_user_exit() - debug all user_exit calls + * + * By default, we don't generate an exception in the low-level user_exit() + * code, because programs lose the ability to disable task isolation: the + * user_exit() hook will cause a signal prior to task_isolation_syscall() + * disabling task isolation. In addition, it means that we lose all the + * diagnostic info otherwise available from task_isolation_interrupt() hooks + * later in the interrupt-handling process. But you may enable it here for + * a special kernel build if you are having undiagnosed userspace jitter. + */ +static inline void task_isolation_user_exit(void) +{ +#ifdef DEBUG_TASK_ISOLATION + task_isolation_interrupt("user_exit"); +#endif +} + +#else /* !CONFIG_TASK_ISOLATION */ +static inline int task_isolation_request(unsigned int flags) { return -EINVAL; } +static inline void task_isolation_start(void) { } +static inline bool is_isolation_cpu(int cpu) { return 0; } +static inline int task_isolation_on_cpu(int cpu) { return 0; } +static inline void task_isolation_cpumask(struct cpumask *mask) { } +static inline void task_isolation_clear_cpumask(struct cpumask *mask) { } +static inline void task_isolation_cpu_cleanup(void) { } +static inline void task_isolation_check_run_cleanup(void) { } +static inline int task_isolation_syscall(int nr) { return 0; } +static inline void task_isolation_interrupt(const char *fmt, ...) { } +static inline void task_isolation_remote(int cpu, const char *fmt, ...) { } +static inline void task_isolation_remote_cpumask(const struct cpumask *mask, + const char *fmt, ...) { } +static inline void task_isolation_signal(struct task_struct *task) { } +static inline void task_isolation_user_exit(void) { } +#endif + +#endif /* _LINUX_ISOLATION_H */ diff --git a/include/linux/sched.h b/include/linux/sched.h index 04278493bf15..52fdb32aa3b9 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1280,6 +1280,10 @@ struct task_struct { unsigned long lowest_stack; unsigned long prev_lowest_stack; #endif +#ifdef CONFIG_TASK_ISOLATION + unsigned short task_isolation_flags; /* prctl */ + unsigned short task_isolation_state; +#endif /* * New fields for task_struct should be added above here, so that diff --git a/include/linux/tick.h b/include/linux/tick.h index 7340613c7eff..27c7c033d5a8 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -268,6 +268,9 @@ static inline void tick_dep_clear_signal(struct signal_struct *signal, extern void tick_nohz_full_kick_cpu(int cpu); extern void __tick_nohz_task_switch(void); extern void __init tick_nohz_full_setup(cpumask_var_t cpumask); +#ifdef CONFIG_TASK_ISOLATION +extern int try_stop_full_tick(void); +#endif #else static inline bool tick_nohz_full_enabled(void) { return false; } static inline bool tick_nohz_full_cpu(int cpu) { return false; } diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index 07b4f8131e36..f4848ed2a069 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -238,4 +238,10 @@ struct prctl_mm_map { #define PR_SET_IO_FLUSHER 57 #define PR_GET_IO_FLUSHER 58 +/* Enable task_isolation mode for TASK_ISOLATION kernels. */ +#define PR_TASK_ISOLATION 48 +# define PR_TASK_ISOLATION_ENABLE (1 << 0) +# define PR_TASK_ISOLATION_SET_SIG(sig) (((sig) & 0x7f) << 8) +# define PR_TASK_ISOLATION_GET_SIG(bits) (((bits) >> 8) & 0x7f) + #endif /* _LINUX_PRCTL_H */ diff --git a/init/Kconfig b/init/Kconfig index 20a6ac33761c..ecdf567f6bd4 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -576,6 +576,34 @@ config CPU_ISOLATION source "kernel/rcu/Kconfig" +config HAVE_ARCH_TASK_ISOLATION + bool + +config TASK_ISOLATION + bool "Provide hard CPU isolation from the kernel on demand" + depends on NO_HZ_FULL && HAVE_ARCH_TASK_ISOLATION + help + + Allow userspace processes that place themselves on cores with + nohz_full and isolcpus enabled, and run prctl(PR_TASK_ISOLATION), + to "isolate" themselves from the kernel. Prior to returning to + userspace, isolated tasks will arrange that no future kernel + activity will interrupt the task while the task is running in + userspace. Attempting to re-enter the kernel while in this mode + will cause the task to be terminated with a signal; you must + explicitly use prctl() to disable task isolation before resuming + normal use of the kernel. + + This "hard" isolation from the kernel is required for userspace + tasks that are running hard real-time tasks in userspace, such as + a high-speed network driver in userspace. Without this option, but + with NO_HZ_FULL enabled, the kernel will make a best-faith, "soft" + effort to shield a single userspace process from interrupts, but + makes no guarantees. + + You should say "N" unless you are intending to run a + high-performance userspace driver or similar task. + config BUILD_BIN2C bool default n diff --git a/kernel/Makefile b/kernel/Makefile index 4cb4130ced32..2f2ae91f90d5 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -122,6 +122,8 @@ obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o KASAN_SANITIZE_stackleak.o := n KCOV_INSTRUMENT_stackleak.o := n +obj-$(CONFIG_TASK_ISOLATION) += isolation.o + $(obj)/configs.o: $(obj)/config_data.gz targets += config_data.gz diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c index 0296b4bda8f1..e9206736f219 100644 --- a/kernel/context_tracking.c +++ b/kernel/context_tracking.c @@ -21,6 +21,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -157,6 +158,7 @@ void __context_tracking_exit(enum ctx_state state) if (state == CONTEXT_USER) { vtime_user_exit(current); trace_user_exit(0); + task_isolation_user_exit(); } } __this_cpu_write(context_tracking.state, CONTEXT_KERNEL); diff --git a/kernel/isolation.c b/kernel/isolation.c new file mode 100644 index 000000000000..ae29732c376c --- /dev/null +++ b/kernel/isolation.c @@ -0,0 +1,774 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * linux/kernel/isolation.c + * + * Implementation of task isolation. + * + * Authors: + * Chris Metcalf + * Alex Belits + * Yuri Norov + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * These values are stored in task_isolation_state. + * Note that STATE_NORMAL + TIF_TASK_ISOLATION means we are still + * returning from sys_prctl() to userspace. + */ +enum { + STATE_NORMAL = 0, /* Not isolated */ + STATE_ISOLATED = 1 /* In userspace, isolated */ +}; + +/* + * This variable contains thread flags copied at the moment + * when schedule() switched to the task on a given CPU, + * or 0 if no task is running. + */ +DEFINE_PER_CPU(unsigned long, tsk_thread_flags_cache); + +/* + * Counter for isolation state on a given CPU, increments when entering + * isolation and decrements when exiting isolation (before or after the + * cleanup). Multiple simultaneously running procedures entering or + * exiting isolation are prevented by checking the result of + * incrementing or decrementing this variable. This variable is both + * incremented and decremented by CPU that caused isolation entering or + * exit. + * + * This is necessary because multiple isolation-breaking events may happen + * at once (or one as the result of the other), however isolation exit + * may only happen once to transition from isolated to non-isolated state. + * Therefore, if decrementing this counter results in a value less than 0, + * isolation exit procedure can't be started -- it already happened, or is + * in progress, or isolation is not entered yet. + */ +DEFINE_PER_CPU(atomic_t, isol_counter); + +/* + * Description of the last two tasks that ran isolated on a given CPU. + * This is intended only for messages about isolation breaking. We + * don't want any references to actual task while accessing this from + * CPU that caused isolation breaking -- we know nothing about timing + * and don't want to use locking or RCU. + */ +struct isol_task_desc { + atomic_t curr_index; + atomic_t curr_index_wr; + bool warned[2]; + pid_t pid[2]; + pid_t tgid[2]; + char comm[2][TASK_COMM_LEN]; +}; +static DEFINE_PER_CPU(struct isol_task_desc, isol_task_descs); + +/* + * Counter for isolation exiting procedures (from request to the start of + * cleanup) being attempted at once on a CPU. Normally incrementing of + * this counter is performed from the CPU that caused isolation breaking, + * however decrementing is done from the cleanup procedure, delegated to + * the CPU that is exiting isolation, not from the CPU that caused isolation + * breaking. + * + * If incrementing this counter while starting isolation exit procedure + * results in a value greater than 0, isolation exiting is already in + * progress, and cleanup did not start yet. This means, counter should be + * decremented back, and isolation exit that is already in progress, should + * be allowed to complete. Otherwise, a new isolation exit procedure should + * be started. + */ +DEFINE_PER_CPU(atomic_t, isol_exit_counter); + +/* + * Descriptor for isolation-breaking SMP calls + */ +DEFINE_PER_CPU(call_single_data_t, isol_break_csd); + +cpumask_var_t task_isolation_map; +cpumask_var_t task_isolation_cleanup_map; +static DEFINE_SPINLOCK(task_isolation_cleanup_lock); + +/* We can run on cpus that are isolated from the scheduler and are nohz_full. */ +static int __init task_isolation_init(void) +{ + alloc_bootmem_cpumask_var(&task_isolation_cleanup_map); + if (alloc_cpumask_var(&task_isolation_map, GFP_KERNEL)) + /* + * At this point task isolation should match + * nohz_full. This may change in the future. + */ + cpumask_copy(task_isolation_map, tick_nohz_full_mask); + return 0; +} +core_initcall(task_isolation_init) + +/* Enable stack backtraces of any interrupts of task_isolation cores. */ +static bool task_isolation_debug; +static int __init task_isolation_debug_func(char *str) +{ + task_isolation_debug = true; + return 1; +} +__setup("task_isolation_debug", task_isolation_debug_func); + +/* + * Record name, pid and group pid of the task entering isolation on + * the current CPU. + */ +static void record_curr_isolated_task(void) +{ + int ind; + int cpu = smp_processor_id(); + struct isol_task_desc *desc = &per_cpu(isol_task_descs, cpu); + struct task_struct *task = current; + + /* Finish everything before recording current task */ + smp_mb(); + ind = atomic_inc_return(&desc->curr_index_wr) & 1; + desc->comm[ind][sizeof(task->comm) - 1] = '\0'; + memcpy(desc->comm[ind], task->comm, sizeof(task->comm) - 1); + desc->pid[ind] = task->pid; + desc->tgid[ind] = task->tgid; + desc->warned[ind] = false; + /* Write everything, to be seen by other CPUs */ + smp_mb(); + atomic_inc(&desc->curr_index); + /* Everyone will see the new record from this point */ + smp_mb(); +} + +/* + * Print message prefixed with the description of the current (or + * last) isolated task on a given CPU. Intended for isolation breaking + * messages that include target task for the user's convenience. + * + * Messages produced with this function may have obsolete task + * information if isolated tasks managed to exit, start and enter + * isolation multiple times, or multiple tasks tried to enter + * isolation on the same CPU at once. For those unusual cases it would + * contain a valid description of the cause for isolation breaking and + * target CPU number, just not the correct description of which task + * ended up losing isolation. + */ +int task_isolation_message(int cpu, int level, bool supp, const char *fmt, ...) +{ + struct isol_task_desc *desc; + struct task_struct *task; + va_list args; + char buf_prefix[TASK_COMM_LEN + 20 + 3 * 20]; + char buf[200]; + int curr_cpu, ind_counter, ind_counter_old, ind; + + curr_cpu = get_cpu(); + desc = &per_cpu(isol_task_descs, cpu); + ind_counter = atomic_read(&desc->curr_index); + + if (curr_cpu == cpu) { + /* + * Message is for the current CPU so current + * task_struct should be used instead of cached + * information. + * + * Like in other diagnostic messages, if issued from + * interrupt context, current will be the interrupted + * task. Unlike other diagnostic messages, this is + * always relevant because the message is about + * interrupting a task. + */ + ind = ind_counter & 1; + if (supp && desc->warned[ind]) { + /* + * If supp is true, skip the message if the + * same task was mentioned in the message + * originated on remote CPU, and it did not + * re-enter isolated state since then (warned + * is true). Only local messages following + * remote messages, likely about the same + * isolation breaking event, are skipped to + * avoid duplication. If remote cause is + * immediately followed by a local one before + * isolation is broken, local cause is skipped + * from messages. + */ + put_cpu(); + return 0; + } + task = current; + snprintf(buf_prefix, sizeof(buf_prefix), + "isolation %s/%d/%d (cpu %d)", + task->comm, task->tgid, task->pid, cpu); + put_cpu(); + } else { + /* + * Message is for remote CPU, use cached information. + */ + put_cpu(); + /* + * Make sure, index remained unchanged while data was + * copied. If it changed, data that was copied may be + * inconsistent because two updates in a sequence could + * overwrite the data while it was being read. + */ + do { + /* Make sure we are reading up to date values */ + smp_mb(); + ind = ind_counter & 1; + snprintf(buf_prefix, sizeof(buf_prefix), + "isolation %s/%d/%d (cpu %d)", + desc->comm[ind], desc->tgid[ind], + desc->pid[ind], cpu); + desc->warned[ind] = true; + ind_counter_old = ind_counter; + /* Record the warned flag, then re-read descriptor */ + smp_mb(); + ind_counter = atomic_read(&desc->curr_index); + /* + * If the counter changed, something was updated, so + * repeat everything to get the current data + */ + } while (ind_counter != ind_counter_old); + } + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + switch (level) { + case LOGLEVEL_EMERG: + pr_emerg("%s: %s", buf_prefix, buf); + break; + case LOGLEVEL_ALERT: + pr_alert("%s: %s", buf_prefix, buf); + break; + case LOGLEVEL_CRIT: + pr_crit("%s: %s", buf_prefix, buf); + break; + case LOGLEVEL_ERR: + pr_err("%s: %s", buf_prefix, buf); + break; + case LOGLEVEL_WARNING: + pr_warn("%s: %s", buf_prefix, buf); + break; + case LOGLEVEL_NOTICE: + pr_notice("%s: %s", buf_prefix, buf); + break; + case LOGLEVEL_INFO: + pr_info("%s: %s", buf_prefix, buf); + break; + case LOGLEVEL_DEBUG: + pr_debug("%s: %s", buf_prefix, buf); + break; + default: + /* No message without a valid level */ + return 0; + } + return 1; +} + +/* + * Dump stack if need be. This can be helpful even from the final exit + * to usermode code since stack traces sometimes carry information about + * what put you into the kernel, e.g. an interrupt number encoded in + * the initial entry stack frame that is still visible at exit time. + */ +static void debug_dump_stack(void) +{ + if (task_isolation_debug) + dump_stack(); +} + +/* + * Set the flags word but don't try to actually start task isolation yet. + * We will start it when entering user space in task_isolation_start(). + */ +int task_isolation_request(unsigned int flags) +{ + struct task_struct *task = current; + + /* + * The task isolation flags should always be cleared just by + * virtue of having entered the kernel. + */ + WARN_ON_ONCE(test_tsk_thread_flag(task, TIF_TASK_ISOLATION)); + WARN_ON_ONCE(task->task_isolation_flags != 0); + WARN_ON_ONCE(task->task_isolation_state != STATE_NORMAL); + + task->task_isolation_flags = flags; + if (!(task->task_isolation_flags & PR_TASK_ISOLATION_ENABLE)) + return 0; + + /* We are trying to enable task isolation. */ + set_tsk_thread_flag(task, TIF_TASK_ISOLATION); + + /* + * Shut down the vmstat worker so we're not interrupted later. + * We have to try to do this here (with interrupts enabled) since + * we are canceling delayed work and will call flush_work() + * (which enables interrupts) and possibly schedule(). + */ + quiet_vmstat_sync(); + + /* We return 0 here but we may change that in task_isolation_start(). */ + return 0; +} + +/* + * Perform actions that should be done immediately on exit from isolation. + */ +static void fast_task_isolation_cpu_cleanup(void *info) +{ + atomic_dec(&per_cpu(isol_exit_counter, smp_processor_id())); + /* At this point breaking isolation from other CPUs is possible again */ + + /* + * This task is no longer isolated (and if by any chance this + * is the wrong task, it's already not isolated) + */ + current->task_isolation_flags = 0; + clear_tsk_thread_flag(current, TIF_TASK_ISOLATION); + + /* Run the rest of cleanup later */ + set_tsk_thread_flag(current, TIF_NOTIFY_RESUME); + + /* Copy flags with task isolation disabled */ + this_cpu_write(tsk_thread_flags_cache, + READ_ONCE(task_thread_info(current)->flags)); +} + +/* Disable task isolation for the specified task. */ +static void stop_isolation(struct task_struct *p) +{ + int cpu, this_cpu; + unsigned long flags; + + this_cpu = get_cpu(); + cpu = task_cpu(p); + if (atomic_inc_return(&per_cpu(isol_exit_counter, cpu)) > 1) { + /* Already exiting isolation */ + atomic_dec(&per_cpu(isol_exit_counter, cpu)); + put_cpu(); + return; + } + + if (p == current) { + p->task_isolation_state = STATE_NORMAL; + fast_task_isolation_cpu_cleanup(NULL); + task_isolation_cpu_cleanup(); + if (atomic_dec_return(&per_cpu(isol_counter, cpu)) < 0) { + /* Is not isolated already */ + atomic_inc(&per_cpu(isol_counter, cpu)); + } + put_cpu(); + } else { + if (atomic_dec_return(&per_cpu(isol_counter, cpu)) < 0) { + /* Is not isolated already */ + atomic_inc(&per_cpu(isol_counter, cpu)); + atomic_dec(&per_cpu(isol_exit_counter, cpu)); + put_cpu(); + return; + } + /* + * Schedule "slow" cleanup. This relies on + * TIF_NOTIFY_RESUME being set + */ + spin_lock_irqsave(&task_isolation_cleanup_lock, flags); + cpumask_set_cpu(cpu, task_isolation_cleanup_map); + spin_unlock_irqrestore(&task_isolation_cleanup_lock, flags); + /* + * Setting flags is delegated to the CPU where + * isolated task is running + * isol_exit_counter will be decremented from there as well. + */ + per_cpu(isol_break_csd, cpu).func = + fast_task_isolation_cpu_cleanup; + per_cpu(isol_break_csd, cpu).info = NULL; + per_cpu(isol_break_csd, cpu).flags = 0; + smp_call_function_single_async(cpu, + &per_cpu(isol_break_csd, cpu)); + put_cpu(); + } +} + +/* + * This code runs with interrupts disabled just before the return to + * userspace, after a prctl() has requested enabling task isolation. + * We take whatever steps are needed to avoid being interrupted later: + * drain the lru pages, stop the scheduler tick, etc. More + * functionality may be added here later to avoid other types of + * interrupts from other kernel subsystems. + * + * If we can't enable task isolation, we update the syscall return + * value with an appropriate error. + */ +void task_isolation_start(void) +{ + int error; + + /* + * We should only be called in STATE_NORMAL (isolation disabled), + * on our way out of the kernel from the prctl() that turned it on. + * If we are exiting from the kernel in another state, it means we + * made it back into the kernel without disabling task isolation, + * and we should investigate how (and in any case disable task + * isolation at this point). We are clearly not on the path back + * from the prctl() so we don't touch the syscall return value. + */ + if (WARN_ON_ONCE(current->task_isolation_state != STATE_NORMAL)) { + /* Increment counter, this will allow isolation breaking */ + if (atomic_inc_return(&per_cpu(isol_counter, + smp_processor_id())) > 1) { + atomic_dec(&per_cpu(isol_counter, smp_processor_id())); + } + atomic_inc(&per_cpu(isol_counter, smp_processor_id())); + stop_isolation(current); + return; + } + + /* + * Must be affinitized to a single core with task isolation possible. + * In principle this could be remotely modified between the prctl() + * and the return to userspace, so we have to check it here. + */ + if (current->nr_cpus_allowed != 1 || + !is_isolation_cpu(smp_processor_id())) { + error = -EINVAL; + goto error; + } + + /* If the vmstat delayed work is not canceled, we have to try again. */ + if (!vmstat_idle()) { + error = -EAGAIN; + goto error; + } + + /* Try to stop the dynamic tick. */ + error = try_stop_full_tick(); + if (error) + goto error; + + /* Drain the pagevecs to avoid unnecessary IPI flushes later. */ + lru_add_drain(); + + /* Increment counter, this will allow isolation breaking */ + if (atomic_inc_return(&per_cpu(isol_counter, + smp_processor_id())) > 1) { + atomic_dec(&per_cpu(isol_counter, smp_processor_id())); + } + + /* Record isolated task IDs and name */ + record_curr_isolated_task(); + + /* Copy flags with task isolation enabled */ + this_cpu_write(tsk_thread_flags_cache, + READ_ONCE(task_thread_info(current)->flags)); + + current->task_isolation_state = STATE_ISOLATED; + return; + +error: + /* Increment counter, this will allow isolation breaking */ + if (atomic_inc_return(&per_cpu(isol_counter, + smp_processor_id())) > 1) { + atomic_dec(&per_cpu(isol_counter, smp_processor_id())); + } + stop_isolation(current); + syscall_set_return_value(current, current_pt_regs(), error, 0); +} + +/* Stop task isolation on the remote task and send it a signal. */ +static void send_isolation_signal(struct task_struct *task) +{ + int flags = task->task_isolation_flags; + kernel_siginfo_t info = { + .si_signo = PR_TASK_ISOLATION_GET_SIG(flags) ?: SIGKILL, + }; + + stop_isolation(task); + send_sig_info(info.si_signo, &info, task); +} + +/* Only a few syscalls are valid once we are in task isolation mode. */ +static bool is_acceptable_syscall(int syscall) +{ + /* No need to incur an isolation signal if we are just exiting. */ + if (syscall == __NR_exit || syscall == __NR_exit_group) + return true; + + /* Check to see if it's the prctl for isolation. */ + if (syscall == __NR_prctl) { + unsigned long arg[SYSCALL_MAX_ARGS]; + + syscall_get_arguments(current, current_pt_regs(), arg); + if (arg[0] == PR_TASK_ISOLATION) + return true; + } + + return false; +} + +/* + * This routine is called from syscall entry, prevents most syscalls + * from executing, and if needed raises a signal to notify the process. + * + * Note that we have to stop isolation before we even print a message + * here, since otherwise we might end up reporting an interrupt due to + * kicking the printk handling code, rather than reporting the true + * cause of interrupt here. + * + * The message is not suppressed by previous remotely triggered + * messages. + */ +int task_isolation_syscall(int syscall) +{ + struct task_struct *task = current; + + if (is_acceptable_syscall(syscall)) { + stop_isolation(task); + return 0; + } + + send_isolation_signal(task); + + pr_task_isol_warn(smp_processor_id(), + "task_isolation lost due to syscall %d\n", + syscall); + debug_dump_stack(); + + syscall_set_return_value(task, current_pt_regs(), -ERESTARTNOINTR, -1); + return -1; +} + +/* + * This routine is called from any exception or irq that doesn't + * otherwise trigger a signal to the user process (e.g. page fault). + * + * Messages will be suppressed if there is already a reported remote + * cause for isolation breaking, so we don't generate multiple + * confusingly similar messages about the same event. + */ +void _task_isolation_interrupt(const char *fmt, ...) +{ + struct task_struct *task = current; + va_list args; + char buf[100]; + + /* RCU should have been enabled prior to this point. */ + RCU_LOCKDEP_WARN(!rcu_is_watching(), "kernel entry without RCU"); + + /* Are we exiting isolation already? */ + if (atomic_read(&per_cpu(isol_exit_counter, smp_processor_id())) != 0) { + task->task_isolation_state = STATE_NORMAL; + return; + } + /* + * Avoid reporting interrupts that happen after we have prctl'ed + * to enable isolation, but before we have returned to userspace. + */ + if (task->task_isolation_state == STATE_NORMAL) + return; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + /* Handle NMIs minimally, since we can't send a signal. */ + if (in_nmi()) { + pr_task_isol_err(smp_processor_id(), + "isolation: in NMI; not delivering signal\n"); + } else { + send_isolation_signal(task); + } + + if (pr_task_isol_warn_supp(smp_processor_id(), + "task_isolation lost due to %s\n", buf)) + debug_dump_stack(); +} + +/* + * Called before we wake up a task that has a signal to process. + * Needs to be done to handle interrupts that trigger signals, which + * we don't catch with task_isolation_interrupt() hooks. + * + * This message is also suppressed if there was already a remotely + * caused message about the same isolation breaking event. + */ +void _task_isolation_signal(struct task_struct *task) +{ + struct isol_task_desc *desc; + int ind, cpu; + bool do_warn = (task->task_isolation_state == STATE_ISOLATED); + + cpu = task_cpu(task); + desc = &per_cpu(isol_task_descs, cpu); + ind = atomic_read(&desc->curr_index) & 1; + if (desc->warned[ind]) + do_warn = false; + + stop_isolation(task); + + if (do_warn) { + pr_warn("isolation: %s/%d/%d (cpu %d): task_isolation lost due to signal\n", + task->comm, task->tgid, task->pid, cpu); + debug_dump_stack(); + } +} + +/* + * Generate a stack backtrace if we are going to interrupt another task + * isolation process. + */ +void task_isolation_remote(int cpu, const char *fmt, ...) +{ + struct task_struct *curr_task; + va_list args; + char buf[200]; + + if (!is_isolation_cpu(cpu) || !task_isolation_on_cpu(cpu)) + return; + + curr_task = current; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + if (pr_task_isol_warn(cpu, + "task_isolation lost due to %s by %s/%d/%d on cpu %d\n", + buf, + curr_task->comm, curr_task->tgid, + curr_task->pid, smp_processor_id())) + debug_dump_stack(); +} + +/* + * Generate a stack backtrace if any of the cpus in "mask" are running + * task isolation processes. + */ +void task_isolation_remote_cpumask(const struct cpumask *mask, + const char *fmt, ...) +{ + struct task_struct *curr_task; + cpumask_var_t warn_mask; + va_list args; + char buf[200]; + int cpu, first_cpu; + + if (task_isolation_map == NULL || + !zalloc_cpumask_var(&warn_mask, GFP_KERNEL)) + return; + + first_cpu = -1; + for_each_cpu_and(cpu, mask, task_isolation_map) { + if (task_isolation_on_cpu(cpu)) { + if (first_cpu < 0) + first_cpu = cpu; + else + cpumask_set_cpu(cpu, warn_mask); + } + } + + if (first_cpu < 0) + goto done; + + curr_task = current; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + if (cpumask_weight(warn_mask) == 0) + pr_task_isol_warn(first_cpu, + "task_isolation lost due to %s by %s/%d/%d on cpu %d\n", + buf, curr_task->comm, curr_task->tgid, + curr_task->pid, smp_processor_id()); + else + pr_task_isol_warn(first_cpu, + " and cpus %*pbl: task_isolation lost due to %s by %s/%d/%d on cpu %d\n", + cpumask_pr_args(warn_mask), + buf, curr_task->comm, curr_task->tgid, + curr_task->pid, smp_processor_id()); + debug_dump_stack(); + +done: + free_cpumask_var(warn_mask); +} + +/* + * Check if given CPU is running isolated task. + */ +int task_isolation_on_cpu(int cpu) +{ + return test_bit(TIF_TASK_ISOLATION, + &per_cpu(tsk_thread_flags_cache, cpu)); +} + +/* + * Set CPUs currently running isolated tasks in CPU mask. + */ +void task_isolation_cpumask(struct cpumask *mask) +{ + int cpu; + + if (task_isolation_map == NULL) + return; + + for_each_cpu(cpu, task_isolation_map) + if (task_isolation_on_cpu(cpu)) + cpumask_set_cpu(cpu, mask); +} + +/* + * Clear CPUs currently running isolated tasks in CPU mask. + */ +void task_isolation_clear_cpumask(struct cpumask *mask) +{ + int cpu; + + if (task_isolation_map == NULL) + return; + + for_each_cpu(cpu, task_isolation_map) + if (task_isolation_on_cpu(cpu)) + cpumask_clear_cpu(cpu, mask); +} + +/* + * Cleanup procedure. The call to this procedure may be delayed. + */ +void task_isolation_cpu_cleanup(void) +{ + kick_hrtimer(); +} + +/* + * Check if cleanup is scheduled on the current CPU, and if so, run it. + * Intended to be called from notify_resume() or another such callback + * on the target CPU. + */ +void task_isolation_check_run_cleanup(void) +{ + int cpu; + unsigned long flags; + + spin_lock_irqsave(&task_isolation_cleanup_lock, flags); + + cpu = smp_processor_id(); + + if (cpumask_test_cpu(cpu, task_isolation_cleanup_map)) { + cpumask_clear_cpu(cpu, task_isolation_cleanup_map); + spin_unlock_irqrestore(&task_isolation_cleanup_lock, flags); + task_isolation_cpu_cleanup(); + } else + spin_unlock_irqrestore(&task_isolation_cleanup_lock, flags); +} diff --git a/kernel/signal.c b/kernel/signal.c index 5b2396350dd1..1df57e38c361 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -46,6 +46,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -758,6 +759,7 @@ static int dequeue_synchronous_signal(kernel_siginfo_t *info) */ void signal_wake_up_state(struct task_struct *t, unsigned int state) { + task_isolation_signal(t); set_tsk_thread_flag(t, TIF_SIGPENDING); /* * TASK_WAKEKILL also means wake it up in the stopped/traced/killable diff --git a/kernel/sys.c b/kernel/sys.c index f9bc5c303e3f..0a4059a8c4f9 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -2513,6 +2514,11 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, error = (current->flags & PR_IO_FLUSHER) == PR_IO_FLUSHER; break; + case PR_TASK_ISOLATION: + if (arg3 || arg4 || arg5) + return -EINVAL; + error = task_isolation_request(arg2); + break; default: error = -EINVAL; break; diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 3a609e7344f3..5bb98f39bde6 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -721,6 +722,19 @@ static void retrigger_next_event(void *arg) raw_spin_unlock(&base->lock); } +#ifdef CONFIG_TASK_ISOLATION +void kick_hrtimer(void) +{ + unsigned long flags; + + preempt_disable(); + local_irq_save(flags); + retrigger_next_event(NULL); + local_irq_restore(flags); + preempt_enable(); +} +#endif + /* * Switch to high resolution mode */ @@ -868,8 +882,21 @@ static void hrtimer_reprogram(struct hrtimer *timer, bool reprogram) void clock_was_set(void) { #ifdef CONFIG_HIGH_RES_TIMERS +#ifdef CONFIG_TASK_ISOLATION + struct cpumask mask; + + cpumask_clear(&mask); + task_isolation_cpumask(&mask); + cpumask_complement(&mask, &mask); + /* + * Retrigger the CPU local events everywhere except CPUs + * running isolated tasks. + */ + on_each_cpu_mask(&mask, retrigger_next_event, NULL, 1); +#else /* Retrigger the CPU local events everywhere */ on_each_cpu(retrigger_next_event, NULL, 1); +#endif #endif timerfd_clock_was_set(); } diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index a792d21cac64..1d4dec9d3ee7 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -882,6 +882,24 @@ static void tick_nohz_full_update_tick(struct tick_sched *ts) #endif } +#ifdef CONFIG_TASK_ISOLATION +int try_stop_full_tick(void) +{ + int cpu = smp_processor_id(); + struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); + + /* For an unstable clock, we should return a permanent error code. */ + if (atomic_read(&tick_dep_mask) & TICK_DEP_MASK_CLOCK_UNSTABLE) + return -EINVAL; + + if (!can_stop_full_tick(cpu, ts)) + return -EAGAIN; + + tick_nohz_stop_sched_tick(ts, cpu); + return 0; +} +#endif + static bool can_stop_idle_tick(int cpu, struct tick_sched *ts) { /* From patchwork Sun Mar 8 03:48:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250977 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=YmBPyq3l; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=e18sUEzx; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48ZnQQ637sz9sSK for ; Sun, 8 Mar 2020 14:48:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726397AbgCHDso (ORCPT ); Sat, 7 Mar 2020 22:48:44 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:9712 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726174AbgCHDsn (ORCPT ); Sat, 7 Mar 2020 22:48:43 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283kgI4010475; Sat, 7 Mar 2020 19:48:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=MTd/dMc3M0TGfoAmo6csx6t6wKErRI+/1qrvWpMK/To=; b=YmBPyq3lkG3u4A9Wl7RSe3LsPgm/kuYeeiUEnx3lqSRSiJTLhM7edjX1KJp1CSMWKZtC FPeottYl70VaeBr/H6xb+Cg28foTPFbPA/46xxNk6C/+Tr9pBNNE6BnHP1YnFOwOt/qh eBN4hWc/aWSJKgw28ztaTFn7bYLZKTbUE9b9kVU2HtqmuErHxBYSscKVio+FdFSBAu4F EB+GW6NieyCmMFouZa14MVYgzWV8UiF824+P+OYBleTQR71X4ckIAGz+RP831Kf4LmCb v3nQAa6f/2gE6cAA6ggk3CKkp7y8n73RLxDAUoks+2WGQ5IL6sw6k7l3baR4W6ovxPvk rA== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 2ym9uwav3g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:48:16 -0800 Received: from SC-EXCH04.marvell.com (10.93.176.84) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:48:15 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.106) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:48:15 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B/gOjvsslRmZJBFfiRKGh7DjndRoqRlB+/ICRJk1aDHR2qmdg8VgneXC+RnWXdCmf0HCopzoQaqbCJHPnE8v4KUXSsBOuu1s2nArTO7OCAqTA6CVOtkxFuPjmXWdMWu6tG/Au9vPA/aiUydfR+zFOGbTJn2EFQNPTqiN6L4pC/4dBLsIx+TYlU6oyW6ALLV1856kp7z3uNntlpC5FmD3CauR4Nc8W8k5u0v+Jb9k79Jelx37jSTQHRQ3+0deXCJLA2nOk/GVLyc2d4bEXllKfMCJanNUtUjPABC7tyVoqctosUsr+p9VZooxIVgsJJ2aPYsWspAwnym9Et181RMUew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MTd/dMc3M0TGfoAmo6csx6t6wKErRI+/1qrvWpMK/To=; b=HkIE5+jusNLl+6mijlNi6OBKEPUoJDIGU40nnHwdtsrHqdPweXyFfxymlF0azm4nNGLvSzRKg3fRhtffUqBTyBqVABgRtP/lcGh4fqAEBdoBE5LzCUhSFgtsfhfOEWdX7hU5nBxuZfeIhy1GxXzGmOhNhMMRY4M0SgRwmhpbXkhYf4sF0wYsiVs4DmPP/Of/VjBrhTojCJWllef6HicCFKFipMeKcn9XDhyISdvTbQuLfRE8iggJc8GCGZncYijlM94cvn3kVVUwsfMUimQUCeBcLT+aWs9+Tp2RBGK+5xNHwHwZdNMTHNL+q5UZcvfm2becBD+3fIPhtHAUTsgjdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MTd/dMc3M0TGfoAmo6csx6t6wKErRI+/1qrvWpMK/To=; b=e18sUEzxzjfq+QWTFmPOtGEPJM56CcvcHxadtxW/r155rf7FmowrohVX4cDfoPGlbsu2DirEEXojju8GXq89ETSJMctRLSad7VcwhYNz/65XL16AZlV1CbH8L8X3K7NJjYKSHMe6dMAYhnYBK9+9RIJRnRSGPDLlKXJ6gVBUGFY= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2920.namprd18.prod.outlook.com (2603:10b6:a03:10b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.14; Sun, 8 Mar 2020 03:48:14 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:48:14 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 04/12] task_isolation: Add task isolation hooks to arch-independent code Thread-Topic: [PATCH v2 04/12] task_isolation: Add task isolation hooks to arch-independent code Thread-Index: AQHV9Pxl8pkDGPPGIkW3Dq3VcQpODQ== Date: Sun, 8 Mar 2020 03:48:14 +0000 Message-ID: References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 565d896e-70f9-4fde-1f8d-08d7c31387b2 x-ms-traffictypediagnostic: BYAPR18MB2920: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:418; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(136003)(396003)(39850400004)(376002)(346002)(366004)(199004)(189003)(316002)(66946007)(5660300002)(6512007)(478600001)(8936002)(71200400001)(2906002)(6486002)(66556008)(66476007)(76116006)(6506007)(91956017)(64756008)(66446008)(36756003)(54906003)(4326008)(2616005)(186003)(110136005)(8676002)(26005)(81166006)(81156014)(86362001)(7416002); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2920; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: OkM/3l9kPUecBiRT5oxINp6rtJUGFNZEXHa8kJYJ10ueYs2Jn7d4hzRxkhmR/vKb1pwK7eL9b4M9YX67M3hEmIRwYg8XDWUHx1IIHlLpO2+JhJl5WQIvMLUJx4ENURZ17/jdDDxKlas62AFaPU0dDTAUaQ28R1+53WXsEDy3i1Vpf5OrHJk5XVdz2kk1by8J/qyhg/s/ksT/ubSdcNXibhlhj7LCJO41S3puRceo7uvU2zd5M0UFDvaa6jjH2I3vVpQidV48+yjco1FgwWsx9Alo/cYSwz0S1S575MvLLDnBdvsbZ70teI5MKpxtIObaA/lvwv2EJmDW9C7TZolodvqFXiyOuyZuS8ltVZbmy6sEV4r6+qFdnD+TRWOXERrok09RatRPVcuYw4v8G1evcej8LSmWg31vFaIs5HQq3puCAigiFlwTOoMFQqmJeDXl x-ms-exchange-antispam-messagedata: D/Mtrvz8zNxD/2FLhKjp2lbDImRlRFwHr5HKlls6uK1ox4GEYCHHQB5xc9RP0f4zA/AntWfdwQPmJR9KDUXZXY88uJxaIPtVwvaVEyr6JTVSdTBxKHu/dB9rthxWljw6UV9AYgJE4WW0ap09RooX6A== Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 565d896e-70f9-4fde-1f8d-08d7c31387b2 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:48:14.3297 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: LeF9Wx7kepNpZhtJi4NJAXZjrDgaPECbwR9g3ImxeYzwuc7uHyeKVwsom+5FoLwnX0gxTB04db5DPqx4ZHaK7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2920 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Chris Metcalf This commit adds task isolation hooks as follows: - __handle_domain_irq() generates an isolation warning for the local task - irq_work_queue_on() generates an isolation warning for the remote task being interrupted for irq_work - generic_exec_single() generates a remote isolation warning for the remote cpu being IPI'd - smp_call_function_many() generates a remote isolation warning for the set of remote cpus being IPI'd Calls to task_isolation_remote() or task_isolation_interrupt() can be placed in the platform-independent code like this when doing so results in fewer lines of code changes, as for example is true of the users of the arch_send_call_function_*() APIs. Or, they can be placed in the per-architecture code when there are many callers, as for example is true of the smp_send_reschedule() call. A further cleanup might be to create an intermediate layer, so that for example smp_send_reschedule() is a single generic function that just calls arch_smp_send_reschedule(), allowing generic code to be called every time smp_send_reschedule() is invoked. But for now, we just update either callers or callees as makes most sense. Signed-off-by: Chris Metcalf [abelits@marvell.com: adapted for kernel 5.6] Signed-off-by: Alex Belits --- kernel/irq/irqdesc.c | 9 +++++++++ kernel/irq_work.c | 5 ++++- kernel/smp.c | 6 +++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 98a5f10d1900..e2b81d035fa1 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "internals.h" @@ -670,6 +671,10 @@ int __handle_domain_irq(struct irq_domain *domain, unsigned int hwirq, irq = irq_find_mapping(domain, hwirq); #endif + task_isolation_interrupt((irq == hwirq) ? + "irq %d (%s)" : "irq %d (%s hwirq %d)", + irq, domain ? domain->name : "", hwirq); + /* * Some hardware gives randomly wrong interrupts. Rather * than crashing, do something sensible. @@ -711,6 +716,10 @@ int handle_domain_nmi(struct irq_domain *domain, unsigned int hwirq, irq = irq_find_mapping(domain, hwirq); + task_isolation_interrupt((irq == hwirq) ? + "NMI irq %d (%s)" : "NMI irq %d (%s hwirq %d)", + irq, domain ? domain->name : "", hwirq); + /* * ack_bad_irq is not NMI-safe, just report * an invalid interrupt. diff --git a/kernel/irq_work.c b/kernel/irq_work.c index 828cc30774bc..8fd4ece43dd8 100644 --- a/kernel/irq_work.c +++ b/kernel/irq_work.c @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -102,8 +103,10 @@ bool irq_work_queue_on(struct irq_work *work, int cpu) if (cpu != smp_processor_id()) { /* Arch remote IPI send/receive backend aren't NMI safe */ WARN_ON_ONCE(in_nmi()); - if (llist_add(&work->llnode, &per_cpu(raised_list, cpu))) + if (llist_add(&work->llnode, &per_cpu(raised_list, cpu))) { + task_isolation_remote(cpu, "irq_work"); arch_send_call_function_single_ipi(cpu); + } } else { __irq_work_queue_local(work); } diff --git a/kernel/smp.c b/kernel/smp.c index d0ada39eb4d4..3a8bcbdd4ce6 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "smpboot.h" @@ -176,8 +177,10 @@ static int generic_exec_single(int cpu, call_single_data_t *csd, * locking and barrier primitives. Generic code isn't really * equipped to do the right thing... */ - if (llist_add(&csd->llist, &per_cpu(call_single_queue, cpu))) + if (llist_add(&csd->llist, &per_cpu(call_single_queue, cpu))) { + task_isolation_remote(cpu, "IPI function"); arch_send_call_function_single_ipi(cpu); + } return 0; } @@ -466,6 +469,7 @@ static void smp_call_function_many_cond(const struct cpumask *mask, } /* Send a message to all CPUs in the map */ + task_isolation_remote_cpumask(cfd->cpumask_ipi, "IPI function"); arch_send_call_function_ipi_mask(cfd->cpumask_ipi); if (wait) { From patchwork Sun Mar 8 03:49:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250978 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=MLnoaCZy; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=SpiFOsbb; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48ZnSC0Prnz9sSJ for ; Sun, 8 Mar 2020 14:50:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726300AbgCHDuP (ORCPT ); Sat, 7 Mar 2020 22:50:15 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:64270 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726174AbgCHDuP (ORCPT ); Sat, 7 Mar 2020 22:50:15 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283kiT2016084; Sat, 7 Mar 2020 19:49:19 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=4c8Apfmk2kumwoQaqUicAng6ThoU4i/OF2i1qdPGql8=; b=MLnoaCZyw5YGL7gy+FPGL0t0hge3+joOq0MTXkz+S7l+U//qZ7SmTHBB0MWVI5JWX8R9 pAvi9ny3in8kZBy1qZJPeXm5/cVwDvNMJzJ1UTZeJVcn8oEGj4rutHHEhzmR9MjBsGwi fbnIt6GYOnq282DHOgOcE7E+FSo/dFkZVSAVaVI7fmW/wf4K5k7fO7l+mwETZ57kWKKB 5x99lngIveysfTNfSOUz+GMrC6LeBkJKTzWjuCrgwqCpW9am94mJZ+0gboeUeajVtolj Af/hanMkqikqwIc8/T1tPoV7urNbzgdzctJ8SxrPkksaJCZErvVLh0twwaMogP8GW325 bg== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2ymc0sj1qf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:49:18 -0800 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:49:16 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.103) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:49:16 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XHGQFuCrDmpE0RqgOSpYj2tPVuFiaLyiEknHakwU/HLPSNBj97th05iQFZuvEPu9C+ArLaEV6zkyQU/Upa3w6tOLlojagp16jBegW4oqB2NwOH3DZFjeJBXty3Rk+5FayaffsN5XlkUugyeUgCvwV73s/9mr1o1dHILywDWHer82xwwU6abZs6MCsIc70l+w8qd065t0Bm5Ajafzr+G3SfNDqanguo0c1TPCKbg3iIgScIrWQXcLOxcOkWGX0dyuHS2BOHszDPorQSB/8Pw2IBKVdTsDzfGh1gK/BMqAUVDR8khtEnfCRKTCFZMyFOCxYdGEYXQaEaeuWHBA3IRXjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4c8Apfmk2kumwoQaqUicAng6ThoU4i/OF2i1qdPGql8=; b=A24ZPFzb989w8WlWzZsMgSkWJcqFhEu2NhNKy/wMpsEdZ9BE7tX6+j5Edd5005tEGkiV79Yyfo/JeXJ2BuNIQ/pADpCocruKHjkmXnjQh0nHbKgyfGfaftADjzfF6+C35sG0N4sT2HVtVA/02GBJn49FQaQamHafBWdubvgfBDwgGYX/CxmfP/p1NMMzQEUqowso5gsMi9O1lER7nGk7p1hYfeOygFOXEJLULttsyvnIkwAmhP2nKV+KCrrANrcBhzsWAD/oG5zMYmwR/f9t5rQyN1eRRPdzCy42o9px8vn3bj8k6O2r+6RsQgNIODOtP3KXe5KF/Lc30uQ1nFV68Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4c8Apfmk2kumwoQaqUicAng6ThoU4i/OF2i1qdPGql8=; b=SpiFOsbbfGEIxCoTceXlf1BdTBkbbuMpP7Ao1j92Zl7oZ61Lin7Jv3ayhU764EPfLwWi6wu8grPwvn3I+/w7XQqYEbWtH1vfM2Y3ZtXj/k3kxS/cLx6zRBuJVIdRaD7ELaJIfQOL0CaEnSLYlqXU4rv9GnIgrVdP2O/J5pi8fhI= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2920.namprd18.prod.outlook.com (2603:10b6:a03:10b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.14; Sun, 8 Mar 2020 03:49:15 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:49:15 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 05/12] task_isolation: arch/x86: enable task isolation functionality Thread-Topic: [PATCH v2 05/12] task_isolation: arch/x86: enable task isolation functionality Thread-Index: AQHV9PyJVxq1ibIggkG2K9HIzhIQ0A== Date: Sun, 8 Mar 2020 03:49:15 +0000 Message-ID: <1ddd1aeb9798a85e25debd8cc57a3059eda512d9.camel@marvell.com> References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 55476e7c-4eef-4f52-c27f-08d7c313ac40 x-ms-traffictypediagnostic: BYAPR18MB2920: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(136003)(396003)(39850400004)(376002)(346002)(366004)(199004)(189003)(316002)(66946007)(5660300002)(6512007)(478600001)(8936002)(71200400001)(2906002)(6486002)(66556008)(66476007)(76116006)(6506007)(91956017)(64756008)(66446008)(36756003)(54906003)(4326008)(2616005)(186003)(110136005)(8676002)(26005)(81166006)(81156014)(86362001)(7416002); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2920; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: cAw28saCt0D1kbdqlz1HVT7xcZeGIivdovrKrPxPfLwR/hI8Duf8JNCOQBxKYKUR9KdcLdrumBmgWkLlp7eCI1UyIzFb9y43NP/e88MAp3vfu+clT1HWVkYzGCC9CvNIApUX4nzj3vIRL7aNUdqrNJpSbDmepqyw3ek1l2eQv0YZ6SM4m7RXMWmys9CeOC9zOxEZ3072J2Sk5pbRacbhysYX5bdodAY0g0AkqnoKBRMD45Zv6FqqVyWlmZiPlWS40JgTBmsjpgmLH9CJxbwOQgLIyxI6xoQENd5Miqir1U+jKIrhfkSV+SqTe2RAY3WN+CGLX6vB99Hy5Es/3AKe5F1eeBaBVBazXDsovcuG06Dp0eGp+RzMdghTz03zE2xZxnEfqTUmSzYuNK3MiQ+aTKPpSd/jrHAZgG1X+pvm/ePZCEa2C4eBTlFFSlwNUTnZ x-ms-exchange-antispam-messagedata: fgy8Sy4MfzfdIFXb7bNVbM5TE0/R/V5h9jwkpNpENhCQDVmCDrzTp95rU1Y+OL00Lu+hQNyia910sx5lI88Gs3ei0AcQHo9tJm2J+yPkIseB7qrNK2DS2Xe+Hn+Cs0ew+L6f9f0VEy30GgfQ5NP5kA== Content-ID: <24669D11BC4CA740BBBEB5BC8FC0A3CD@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 55476e7c-4eef-4f52-c27f-08d7c313ac40 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:49:15.3647 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: E4Wv0uc2TzA32BQVJri1tg9A+qR4a8w5BDh340GJKNyQV3AJWYdOPmc7Qi1huqhVZZtE3VMnUhVq1zfnM/NTIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2920 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Chris Metcalf In prepare_exit_to_usermode(), run cleanup for tasks exited from isolation and call task_isolation_start() for tasks with TIF_TASK_ISOLATION. In syscall_trace_enter_phase1(), add the necessary support for reporting syscalls for task-isolation processes. Add task_isolation_remote() calls for the kernel exception types that do not result in signals, namely non-signalling page faults. Signed-off-by: Chris Metcalf [abelits@marvell.com: adapted for kernel 5.6] Signed-off-by: Alex Belits --- arch/x86/Kconfig | 1 + arch/x86/entry/common.c | 15 +++++++++++++++ arch/x86/include/asm/apic.h | 3 +++ arch/x86/include/asm/thread_info.h | 4 +++- arch/x86/kernel/apic/ipi.c | 2 ++ arch/x86/mm/fault.c | 4 ++++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index beea77046f9b..9ea6d3e6e77d 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -144,6 +144,7 @@ config X86 select HAVE_ARCH_COMPAT_MMAP_BASES if MMU && COMPAT select HAVE_ARCH_PREL32_RELOCATIONS select HAVE_ARCH_SECCOMP_FILTER + select HAVE_ARCH_TASK_ISOLATION select HAVE_ARCH_THREAD_STRUCT_WHITELIST select HAVE_ARCH_STACKLEAK select HAVE_ARCH_TRACEHOOK diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 9747876980b5..ba8cd75dc7cf 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -86,6 +87,15 @@ static long syscall_trace_enter(struct pt_regs *regs) return -1L; } + /* + * In task isolation mode, we may prevent the syscall from + * running, and if so we also deliver a signal to the process. + */ + if (work & _TIF_TASK_ISOLATION) { + if (task_isolation_syscall(regs->orig_ax) == -1) + return -1L; + work &= ~_TIF_TASK_ISOLATION; + } #ifdef CONFIG_SECCOMP /* * Do seccomp after ptrace, to catch any tracer changes. @@ -189,6 +199,8 @@ __visible inline void prepare_exit_to_usermode(struct pt_regs *regs) lockdep_assert_irqs_disabled(); lockdep_sys_exit(); + task_isolation_check_run_cleanup(); + cached_flags = READ_ONCE(ti->flags); if (unlikely(cached_flags & EXIT_TO_USERMODE_LOOP_FLAGS)) @@ -204,6 +216,9 @@ __visible inline void prepare_exit_to_usermode(struct pt_regs *regs) if (unlikely(cached_flags & _TIF_NEED_FPU_LOAD)) switch_fpu_return(); + if (cached_flags & _TIF_TASK_ISOLATION) + task_isolation_start(); + #ifdef CONFIG_COMPAT /* * Compat syscalls set TS_COMPAT. Make sure we clear it before diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index 19e94af9cc5d..71149abbb0a0 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -3,6 +3,7 @@ #define _ASM_X86_APIC_H #include +#include #include #include @@ -524,6 +525,7 @@ extern void irq_exit(void); static inline void entering_irq(void) { + task_isolation_interrupt("irq"); irq_enter(); kvm_set_cpu_l1tf_flush_l1d(); } @@ -536,6 +538,7 @@ static inline void entering_ack_irq(void) static inline void ipi_entering_ack_irq(void) { + task_isolation_interrupt("ack irq"); irq_enter(); ack_APIC_irq(); kvm_set_cpu_l1tf_flush_l1d(); diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index cf4327986e98..60d107f784ee 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h @@ -92,6 +92,7 @@ struct thread_info { #define TIF_NOCPUID 15 /* CPUID is not accessible in userland */ #define TIF_NOTSC 16 /* TSC is not accessible in userland */ #define TIF_IA32 17 /* IA32 compatibility process */ +#define TIF_TASK_ISOLATION 18 /* task isolation enabled for task */ #define TIF_NOHZ 19 /* in adaptive nohz mode */ #define TIF_MEMDIE 20 /* is terminating due to OOM killer */ #define TIF_POLLING_NRFLAG 21 /* idle is polling for TIF_NEED_RESCHED */ @@ -122,6 +123,7 @@ struct thread_info { #define _TIF_NOCPUID (1 << TIF_NOCPUID) #define _TIF_NOTSC (1 << TIF_NOTSC) #define _TIF_IA32 (1 << TIF_IA32) +#define _TIF_TASK_ISOLATION (1 << TIF_TASK_ISOLATION) #define _TIF_NOHZ (1 << TIF_NOHZ) #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) #define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP) @@ -140,7 +142,7 @@ struct thread_info { #define _TIF_WORK_SYSCALL_ENTRY \ (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \ - _TIF_NOHZ) + _TIF_NOHZ | _TIF_TASK_ISOLATION) /* flags to check in __switch_to() */ #define _TIF_WORK_CTXSW_BASE \ diff --git a/arch/x86/kernel/apic/ipi.c b/arch/x86/kernel/apic/ipi.c index 6ca0f91372fd..b4dfaad6a440 100644 --- a/arch/x86/kernel/apic/ipi.c +++ b/arch/x86/kernel/apic/ipi.c @@ -2,6 +2,7 @@ #include #include +#include #include "local.h" @@ -67,6 +68,7 @@ void native_smp_send_reschedule(int cpu) WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n", cpu); return; } + task_isolation_remote(cpu, "reschedule IPI"); apic->send_IPI(cpu, RESCHEDULE_VECTOR); } diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index fa4ea09593ab..2175a8655a7d 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -18,6 +18,7 @@ #include /* faulthandler_disabled() */ #include /* efi_recover_from_page_fault()*/ #include +#include /* task_isolation_interrupt */ #include /* boot_cpu_has, ... */ #include /* dotraplinkage, ... */ @@ -1483,6 +1484,9 @@ void do_user_addr_fault(struct pt_regs *regs, perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, address); } + /* No signal was generated, but notify task-isolation tasks. */ + task_isolation_interrupt("page fault at %#lx", address); + check_v8086_mode(regs, address, tsk); } NOKPROBE_SYMBOL(do_user_addr_fault); From patchwork Sun Mar 8 03:50:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250979 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=EfPq7fOb; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=r0NP050V; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48ZnTc086Tz9sNg for ; Sun, 8 Mar 2020 14:51:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726303AbgCHDv3 (ORCPT ); Sat, 7 Mar 2020 22:51:29 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:31740 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726174AbgCHDv3 (ORCPT ); Sat, 7 Mar 2020 22:51:29 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283kvjj010537; Sat, 7 Mar 2020 19:51:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=O+bhqr4/bcv5yvmoUmApccrZL//vCN8BtdiyigeXwLc=; b=EfPq7fObGNuDgMpWG1C/PTN+yoKKiboFj/H3V3EAlQpvbE/875uTsmYaIPijVzCOPXOK +gZR3YrEs9vSfjPpLVgtqXkbqhLa+Ntv0ZOwuRtT7tZE1lNPY5Iye7UWxSrmDzzkuS2h MEzm9OhjJjRaf54JnvB061W5BQW0wP4F+JaMkgO6IWWN1ghkikeHV5P/4tPFxfS4h0/d eFXVlb9UjOyfFMt67RXK1Ssv8ajix6OL/Sp5ocqyLEMsSO8WJPB+x4hNgo6+nLMZ1aAf pejPUljI5n7PGY30yzUZeOcGhaCj9JEY33DaUtPjsrqo23QMEQ/cERBmq/Ln9cKW2iPS yQ== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 2ym9uwav83-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:51:01 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:51:00 -0800 Received: from SC-EXCH04.marvell.com (10.93.176.84) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:50:59 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.107) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:50:59 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nGxIzGGeFxL1lnxSIWI+WAdo2swHErC80zJ1tCmz3xyaSuF3XA62dI7UYG8JeMDTkzIMc0mQZjKs/mjvkXy1+i1sbzZj35pjVv82hs1W1p/t5mL+vyVofDBWpEBtsUYJIrv/69sPzkMZyCcbkgeiLm0sVO0e+zRFIPVTIsh8H1iX0fPiSMWOnBThBgHygvh95DXKYb2TV4A8A30Z1nxhADwL+hDvgqGDHIkjHlOCcsU0YyBIlYvx897Py7GQxkwRBrSwQlCDRHjgHvIKSjAIk6zOGYeO3wYVctCNav+XGISmk23sKkU3PA2HHhY9gpXKVM9/+RVEBAj4PxDDE7aSAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O+bhqr4/bcv5yvmoUmApccrZL//vCN8BtdiyigeXwLc=; b=bQX3YLwRYV/lVslA7cTMjjwE8ritYtA/dCBAYagkwHxKyctGrDc8GQqgUJcRnET+hKGVVS9063jJ6uegWXuij7lzA1wH333IWd/w4a2BlYZeyWYjkDDjCZFEPB6/G5fm9xy1CF7md0/WNN71So39zIcTyWp18tB+sFuLPpUWt62ia1VguWE31I10ylTDhe0wxF1opHePRzbuR3YF4M/RQxoVp6UhRXZfEwiN/EqCZKCnJjGNMn1dyVWfjxwsPlPOj86EDaPw6Gju5iuc8HRmne0FSO3E2StzC54pneUmwcYPNKgKAuZN2s+3aI1OK4QIWh1U82363bm7D6Xw52NcXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O+bhqr4/bcv5yvmoUmApccrZL//vCN8BtdiyigeXwLc=; b=r0NP050VazPRHLwbfAD4rZKDVGUQ7NiurSPluBYYAESBm4NZGi6t2xZOFE2tKrKekm71swtehXwbTFYbQA0CS2uuoWlqvZL2m8f3JgjXr4+qji7GWpGkXa0Rk+MGEe2lV7SupTBzsxv0XLeatRpRAezXF9qAtAzCIuKj7bno+YA= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2920.namprd18.prod.outlook.com (2603:10b6:a03:10b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.14; Sun, 8 Mar 2020 03:50:58 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:50:58 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 06/12] task_isolation: arch/arm64: enable task isolation functionality Thread-Topic: [PATCH v2 06/12] task_isolation: arch/arm64: enable task isolation functionality Thread-Index: AQHV9PzGqYwRhIb41UmglY+oy7CR8w== Date: Sun, 8 Mar 2020 03:50:58 +0000 Message-ID: References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 707ff5f4-e4bc-4c19-b080-08d7c313e959 x-ms-traffictypediagnostic: BYAPR18MB2920: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(376002)(366004)(346002)(39850400004)(396003)(136003)(189003)(199004)(4326008)(2616005)(110136005)(186003)(36756003)(54906003)(81156014)(81166006)(86362001)(7416002)(8676002)(26005)(2906002)(6486002)(71200400001)(8936002)(66946007)(5660300002)(6512007)(316002)(478600001)(91956017)(6506007)(66446008)(64756008)(66556008)(66476007)(76116006); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2920; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: fKVz9Sj1r1ln5LNarZpj69qeq/HB2JfmnhFroEhw4CtGLY1iWvsufQr47dQUqTNRdZvX0xCTuSp5vDhXQxkEe7g+sl9wHu6BG/j0Hf9flvp4LamWTpG5Sqjp78RVhA+ycv2Ac942YGRW/MGZB9mwPf1h916c2GVBBjITNrmU0nMjcPUk+Hrl9aF1gcsHR95Nk0tO4QTfH7007Mdnjrg0Ss1c3Ss4EejC3L5gq73etYj0Wa4gWf/4VivCCh679H1+MUHznd9PAQWcAcKxEVJy49w0cG88NsH7ZijCLqFnUPEmX/+GnxVvRECkqf+4aO4jICoJxwuZTRau4k0aSQJDx8G+dFLYuFsNs1OMjEyDLxQWVq8EGJFA+DE0sk0B6Gz+d9ADuBGbDHdakTJIigQRfSXEdBl6+tvCGudzP+qMFxXGShPGKtRoNCNhAXkIFB8r x-ms-exchange-antispam-messagedata: wHcYKq3xpR8QXOC1WJtPOg946YjvsMsDSvx/9tzt2O4wo01xX4IObDJ49ZnkQ+Ldq/R/5Lqwm2jgE7HudrRYhJ9T+vOZitqCDjNBPrfOFGkW16bIeo4vyJeP3PVWgjPMlmIuCwIj4hwRXPKMFvKu2A== Content-ID: <5488B4749FDB154F978D946B283098A9@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 707ff5f4-e4bc-4c19-b080-08d7c313e959 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:50:58.1079 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: pM1zl+1OZoAlmP+Hv/ncqceWwhI7Z8qUCK61WE9oxuQg2rVDi9ZqXQ/V4LqlKGEHY6OPLDtbpspx6ocdHhjDyw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2920 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Chris Metcalf In do_notify_resume(), call task_isolation_start() for TIF_TASK_ISOLATION tasks. Add _TIF_TASK_ISOLATION to _TIF_WORK_MASK, and define a local NOTIFY_RESUME_LOOP_FLAGS to check in the loop, since we don't clear _TIF_TASK_ISOLATION in the loop. We instrument the smp_send_reschedule() routine so that it checks for isolated tasks and generates a suitable warning if needed. Finally, report on page faults in task-isolation processes in do_page_faults(). Signed-off-by: Chris Metcalf [abelits@marvell.com: simplified to match kernel 5.6] Signed-off-by: Alex Belits --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/thread_info.h | 5 ++++- arch/arm64/kernel/ptrace.c | 10 ++++++++++ arch/arm64/kernel/signal.c | 13 ++++++++++++- arch/arm64/kernel/smp.c | 7 +++++++ arch/arm64/mm/fault.c | 5 +++++ 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 0b30e884e088..93b6aabc8be9 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -129,6 +129,7 @@ config ARM64 select HAVE_ARCH_PREL32_RELOCATIONS select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_STACKLEAK + select HAVE_ARCH_TASK_ISOLATION select HAVE_ARCH_THREAD_STRUCT_WHITELIST select HAVE_ARCH_TRACEHOOK select HAVE_ARCH_TRANSPARENT_HUGEPAGE diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index f0cec4160136..7563098eb5b2 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -63,6 +63,7 @@ void arch_release_task_struct(struct task_struct *tsk); #define TIF_FOREIGN_FPSTATE 3 /* CPU's FP state is not current's */ #define TIF_UPROBE 4 /* uprobe breakpoint or singlestep */ #define TIF_FSCHECK 5 /* Check FS is USER_DS on return */ +#define TIF_TASK_ISOLATION 6 #define TIF_NOHZ 7 #define TIF_SYSCALL_TRACE 8 /* syscall trace active */ #define TIF_SYSCALL_AUDIT 9 /* syscall auditing */ @@ -83,6 +84,7 @@ void arch_release_task_struct(struct task_struct *tsk); #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) @@ -96,7 +98,8 @@ void arch_release_task_struct(struct task_struct *tsk); #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \ _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \ - _TIF_UPROBE | _TIF_FSCHECK) + _TIF_UPROBE | _TIF_FSCHECK | \ + _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 cd6e5fa48b9c..b35b9b0c594c 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -1836,6 +1837,15 @@ int syscall_trace_enter(struct pt_regs *regs) return -1; } + /* + * In task isolation mode, we may prevent the syscall from + * running, and if so we also deliver a signal to the process. + */ + if (test_thread_flag(TIF_TASK_ISOLATION)) { + if (task_isolation_syscall(regs->syscallno) == -1) + return -1; + } + /* Do the secure computing after ptrace; failures should be fast. */ if (secure_computing() == -1) return -1; diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 339882db5a91..d488c91a4877 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -898,6 +899,11 @@ static void do_signal(struct pt_regs *regs) restore_saved_sigmask(); } +#define NOTIFY_RESUME_LOOP_FLAGS \ + (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \ + _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \ + _TIF_UPROBE | _TIF_FSCHECK) + asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags) { @@ -908,6 +914,8 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, */ trace_hardirqs_off(); + task_isolation_check_run_cleanup(); + do { /* Check valid user FS if needed */ addr_limit_user_check(); @@ -938,7 +946,10 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, local_daif_mask(); thread_flags = READ_ONCE(current_thread_info()->flags); - } while (thread_flags & _TIF_WORK_MASK); + } while (thread_flags & NOTIFY_RESUME_LOOP_FLAGS); + + if (thread_flags & _TIF_TASK_ISOLATION) + task_isolation_start(); } unsigned long __ro_after_init signal_minsigstksz; diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index d4ed9a19d8fe..00f0f77adea0 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -818,6 +819,7 @@ void arch_send_call_function_single_ipi(int cpu) #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL void arch_send_wakeup_ipi_mask(const struct cpumask *mask) { + task_isolation_remote_cpumask(mask, "wakeup IPI"); smp_cross_call(mask, IPI_WAKEUP); } #endif @@ -886,6 +888,9 @@ void handle_IPI(int ipinr, struct pt_regs *regs) __inc_irq_stat(cpu, ipi_irqs[ipinr]); } + task_isolation_interrupt("IPI type %d (%s)", ipinr, + ipinr < NR_IPI ? ipi_types[ipinr] : "unknown"); + switch (ipinr) { case IPI_RESCHEDULE: scheduler_ipi(); @@ -948,12 +953,14 @@ void handle_IPI(int ipinr, struct pt_regs *regs) void smp_send_reschedule(int cpu) { + task_isolation_remote(cpu, "reschedule IPI"); smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE); } #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST void tick_broadcast(const struct cpumask *mask) { + task_isolation_remote_cpumask(mask, "timer IPI"); smp_cross_call(mask, IPI_TIMER); } #endif diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 85566d32958f..fc4b42c81c4f 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -543,6 +544,10 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, */ if (likely(!(fault & (VM_FAULT_ERROR | VM_FAULT_BADMAP | VM_FAULT_BADACCESS)))) { + /* No signal was generated, but notify task-isolation tasks. */ + if (user_mode(regs)) + task_isolation_interrupt("page fault at %#lx", addr); + /* * Major/minor page fault accounting is only done * once. If we go through a retry, it is extremely From patchwork Sun Mar 8 03:52:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250980 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=eC2uXGxC; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=nvJ5ZSo/; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48ZnWC0GWYz9sNg for ; Sun, 8 Mar 2020 14:52:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726300AbgCHDwv (ORCPT ); Sat, 7 Mar 2020 22:52:51 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:64156 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726138AbgCHDwv (ORCPT ); Sat, 7 Mar 2020 22:52:51 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283l0Ch010565; Sat, 7 Mar 2020 19:52:20 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=MTgWmjDqBAQ16SXK7Xqo80CSSZHLL5odf6Rput0yktE=; b=eC2uXGxCFZoV0dYMWXP1qQlBD40o3RyHCUrjIK84OXJe4nK6m1k/U+o+qKdnw32T1Zr9 Ocv3N3DI3b+Ai4nU9WuAD8EcbT2j/tjX2LknQgFo0qWCJmoAM3UuIgGe2PkZe3yl++Hs e4ny9L4roB18R7r7lvc6YOBYKftJE3Kk1jRz0KUxsRwt7PYPqY2miqz5u0KY19xzfJ3L Givv+v6vXKJbNGSRJF5HHTU+4prRrbexVKaRcXwlJ5Oml9UsUM/uVkMTugvD1vnjHBrS vRIHko8SLmoZGFFIm/x60p3Wzpr2Bj7jCz7iVgzCYLBL89ZX0hunwJASYdn8DI0YlDd3 MQ== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 2ym9uwavaa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:52:20 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:52:18 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.173) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:52:18 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m+mXdxEKAdG+5In9jHxcWkdFx7s+tu/GioDDSsamcxP2gncQw3RIqyRohlx2ngfTuL6eZCxiFnBd6Y1pWERhR2T+qUT6mlGkGb+G1nOoHgLPLujbJyz+DhrEEKHuzGmPp7JOUVuGf853Lt9zP0r/ofRzif/7T0sqoCZRi/YhH910wRic1HcZu3XHNdqTgCZDk1Qxf1jZIIRDiwevAbcncd98ofQOtKib+EJuQS8pEs5oSpip4pvcBqqdiEJVvoWObPay/ZzTd3YDhqgksN7V4Uxj8+k7xOhKJzw+LPoQbFFfT4z79XMer9TSnHCa8PaklVggjqtD8I3nQ5TRbjU7qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MTgWmjDqBAQ16SXK7Xqo80CSSZHLL5odf6Rput0yktE=; b=WZ7vNWHqpQUDYdzmqE+269MI5YDTyzZUzNWO8jHDwMQp/LDNg2pfxMpVdU7YOWnLR+zWqCH5xMhD8MlO972F2QKhbB5mpFi30tKb45xRJFj+5i3uMw3Dl4b5rkWJ8QpdhHrLE5HcGi5iu8AK3KaMxWkDz1DE6Lj2GH8aTDfWlQBGNxdKkRFPCkFdlDwFgIsJFA573F3exoEK220vGjem8vSs0O9x9Hu8lpC9T9I/r50XWMU3sOLLmZwmKtwmXGoN+ja2LG99+OssWZlSnZIj0SnVUmvdqMdWxkfkShWdsIyOr8H1Fo9vaZSrNf/CVFAVP4XR6pC/dAmDQRQcNlQbRg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MTgWmjDqBAQ16SXK7Xqo80CSSZHLL5odf6Rput0yktE=; b=nvJ5ZSo/9D/VdwVTgxHxoFqs9eJyq2rNI3AwRMSnZ6me2R0ogNa2/wTRbA+iGPkLQlWXdfc6BzlJGZ8Dkq5dp8RcqDPWk0guZWDMB3wMyxPBvzkAqN2YQSMvU1U8a1PhiXtozTx3VTyJVNNn4EHrL3GBrBZY33eaozGSEciAWMk= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2661.namprd18.prod.outlook.com (2603:10b6:a03:136::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Sun, 8 Mar 2020 03:52:16 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:52:16 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 07/12] task_isolation: arch/arm: enable task isolation functionality Thread-Topic: [PATCH v2 07/12] task_isolation: arch/arm: enable task isolation functionality Thread-Index: AQHV9Pz1/BmyVtfMrEiERiaNilF2mQ== Date: Sun, 8 Mar 2020 03:52:16 +0000 Message-ID: <8b86f8e92208d56cdfd1a680aa53001d27eab994.camel@marvell.com> References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 09a35ce6-9ba8-48c6-a719-08d7c31417db x-ms-traffictypediagnostic: BYAPR18MB2661: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(376002)(346002)(39850400004)(136003)(366004)(396003)(189003)(199004)(5660300002)(186003)(26005)(66946007)(66446008)(66476007)(64756008)(66556008)(6486002)(6506007)(6512007)(91956017)(478600001)(76116006)(7416002)(4326008)(2906002)(86362001)(36756003)(71200400001)(2616005)(8936002)(81156014)(8676002)(81166006)(54906003)(110136005)(316002); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2661; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: s+0sV43imQGrl8KTQ53uM1z74M8xw9GJ6yXgpFGPdGdVMa7bGG36czs6+6ShynJm0Nn0htoFGN4O8JY57MUi8Fv4PjbCtnoYDyWoSwgCXVi8j5uMNwHQAo1RZ2mRWmjblJxs1nA7vo2xAr3LdrMxnlTh5edxr/KpOkbnfniSrPAl+rsJ8P85h3G8Dc9IriWlnQ1t1wOUjxbuQIelzFIdfSc+BmCgekLN0RyhVGuoNzOY/GEogvwY5M9utCEmOgyOQdayt7nLsSdsGLxF+0qqZ072vaXPQ5PdobQBHNr7vQ3KggxUc8mchGx8N/LlX2jNc4GPB9cfCUDsCpEQoFR8vsKO5PtiLYl10MBiNv0aCR0/M1kSdK3f886VHUqDQkbMN7gfOTeNWldfwwLNIa5VRapUvGKxEUkNl99v9sDCF5Lx4o5xe5gL0c+HYc+9MuZJ x-ms-exchange-antispam-messagedata: k0f58bPzKTJoHeaLtoEYg237ZIpwDc1kEWLpys/yZ49d4Faml2aqLu73+PzoaVJcAvMMoxuRhyEQiTWYl30lt3JitzOPWxolphHEmp9excQZvfydJ2iyHJbu2nJ1UfnbtI68sKd99mMtbz1eeXOspg== Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 09a35ce6-9ba8-48c6-a719-08d7c31417db X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:52:16.0909 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Oj6Qy/gC8SeKe0LroFqDkRH3vVN7XIoLqPlE+oKCm/LxATsmK50+U3gnzpAZ6XrAaoPQ2kw8bNF3y4mOiomrbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2661 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Francis Giraldeau This patch is a port of the task isolation functionality to the arm 32-bit architecture. The task isolation needs an additional thread flag that requires to change the entry assembly code to accept a bitfield larger than one byte. The constants _TIF_SYSCALL_WORK and _TIF_WORK_MASK are now defined in the literal pool. The rest of the patch is straightforward and reflects what is done on other architectures. To avoid problems with the tst instruction in the v7m build, we renumber TIF_SECCOMP to bit 8 and let TIF_TASK_ISOLATION use bit 7. Signed-off-by: Francis Giraldeau Signed-off-by: Chris Metcalf [with modifications] [abelits@marvell.com: modified for kernel 5.6, added isolation cleanup] Signed-off-by: Alex Belits --- arch/arm/Kconfig | 1 + arch/arm/include/asm/thread_info.h | 10 +++++++--- arch/arm/kernel/entry-common.S | 15 ++++++++++----- arch/arm/kernel/ptrace.c | 10 ++++++++++ arch/arm/kernel/signal.c | 13 ++++++++++++- arch/arm/kernel/smp.c | 4 ++++ arch/arm/mm/fault.c | 8 +++++++- 7 files changed, 51 insertions(+), 10 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 97864aabc2a6..1a66e6c6807c 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -67,6 +67,7 @@ config ARM select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU select HAVE_ARCH_MMAP_RND_BITS if MMU select HAVE_ARCH_SECCOMP_FILTER if AEABI && !OABI_COMPAT + select HAVE_ARCH_TASK_ISOLATION select HAVE_ARCH_THREAD_STRUCT_WHITELIST select HAVE_ARCH_TRACEHOOK select HAVE_ARM_SMCCC if CPU_V7 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h index 0d0d5178e2c3..ec3c2084c391 100644 --- a/arch/arm/include/asm/thread_info.h +++ b/arch/arm/include/asm/thread_info.h @@ -139,7 +139,8 @@ extern int vfp_restore_user_hwstate(struct user_vfp *, #define TIF_SYSCALL_TRACE 4 /* syscall trace active */ #define TIF_SYSCALL_AUDIT 5 /* syscall auditing active */ #define TIF_SYSCALL_TRACEPOINT 6 /* syscall tracepoint instrumentation */ -#define TIF_SECCOMP 7 /* seccomp syscall filtering active */ +#define TIF_TASK_ISOLATION 7 /* task isolation active */ +#define TIF_SECCOMP 8 /* seccomp syscall filtering active */ #define TIF_NOHZ 12 /* in adaptive nohz mode */ #define TIF_USING_IWMMXT 17 @@ -153,18 +154,21 @@ extern int vfp_restore_user_hwstate(struct user_vfp *, #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) +#define _TIF_TASK_ISOLATION (1 << TIF_TASK_ISOLATION) #define _TIF_SECCOMP (1 << TIF_SECCOMP) #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT) /* Checks for any syscall work in entry-common.S */ #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP) + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ + _TIF_TASK_ISOLATION) /* * Change these and you break ASM code in entry-common.S */ #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \ - _TIF_NOTIFY_RESUME | _TIF_UPROBE) + _TIF_NOTIFY_RESUME | _TIF_UPROBE | \ + _TIF_TASK_ISOLATION) #endif /* __KERNEL__ */ #endif /* __ASM_ARM_THREAD_INFO_H */ diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 271cb8a1eba1..6ceb5cb808a9 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -53,7 +53,8 @@ __ret_fast_syscall: cmp r2, #TASK_SIZE blne addr_limit_check_failed ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing - tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK + ldr r2, =_TIF_SYSCALL_WORK | _TIF_WORK_MASK + tst r1, r2 bne fast_work_pending @@ -90,7 +91,8 @@ __ret_fast_syscall: cmp r2, #TASK_SIZE blne addr_limit_check_failed ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing - tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK + ldr r2, =_TIF_SYSCALL_WORK | _TIF_WORK_MASK + tst r1, r2 beq no_work_pending UNWIND(.fnend ) ENDPROC(ret_fast_syscall) @@ -98,7 +100,8 @@ ENDPROC(ret_fast_syscall) /* Slower path - fall through to work_pending */ #endif - tst r1, #_TIF_SYSCALL_WORK + ldr r2, =_TIF_SYSCALL_WORK + tst r1, r2 bne __sys_trace_return_nosave slow_work_pending: mov r0, sp @ 'regs' @@ -131,7 +134,8 @@ ENTRY(ret_to_user_from_irq) cmp r2, #TASK_SIZE blne addr_limit_check_failed ldr r1, [tsk, #TI_FLAGS] - tst r1, #_TIF_WORK_MASK + ldr r2, =_TIF_WORK_MASK + tst r1, r2 bne slow_work_pending no_work_pending: asm_trace_hardirqs_on save = 0 @@ -251,7 +255,8 @@ local_restart: ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing stmdb sp!, {r4, r5} @ push fifth and sixth args - tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls? + ldr r11, =_TIF_SYSCALL_WORK @ are we tracing syscalls? + tst r10, r11 bne __sys_trace invoke_syscall tbl, scno, r10, __ret_fast_syscall diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c index b606cded90cd..a69b0bfd71ae 100644 --- a/arch/arm/kernel/ptrace.c +++ b/arch/arm/kernel/ptrace.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -921,6 +922,15 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno) if (test_thread_flag(TIF_SYSCALL_TRACE)) tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER); + /* + * In task isolation mode, we may prevent the syscall from + * running, and if so we also deliver a signal to the process. + */ + if (test_thread_flag(TIF_TASK_ISOLATION)) { + if (task_isolation_syscall(scno) == -1) + return -1; + } + /* Do seccomp after ptrace; syscall may have changed. */ #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER if (secure_computing() == -1) diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index ab2568996ddb..29ccef8403cd 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -639,6 +640,9 @@ static int do_signal(struct pt_regs *regs, int syscall) return 0; } +#define WORK_PENDING_LOOP_FLAGS (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \ + _TIF_NOTIFY_RESUME | _TIF_UPROBE) + asmlinkage int do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall) { @@ -648,6 +652,9 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall) * Update the trace code with the current status. */ trace_hardirqs_off(); + + task_isolation_check_run_cleanup(); + do { if (likely(thread_flags & _TIF_NEED_RESCHED)) { schedule(); @@ -676,7 +683,11 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall) } local_irq_disable(); thread_flags = current_thread_info()->flags; - } while (thread_flags & _TIF_WORK_MASK); + } while (thread_flags & WORK_PENDING_LOOP_FLAGS); + + if (thread_flags & _TIF_TASK_ISOLATION) + task_isolation_start(); + return 0; } diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 46e1be9e57a8..95f19b980776 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -560,6 +561,7 @@ void arch_send_call_function_ipi_mask(const struct cpumask *mask) void arch_send_wakeup_ipi_mask(const struct cpumask *mask) { + task_isolation_remote_cpumask(mask, "wakeup IPI"); smp_cross_call(mask, IPI_WAKEUP); } @@ -579,6 +581,7 @@ void arch_irq_work_raise(void) #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST void tick_broadcast(const struct cpumask *mask) { + task_isolation_remote_cpumask(mask, "timer IPI"); smp_cross_call(mask, IPI_TIMER); } #endif @@ -702,6 +705,7 @@ void handle_IPI(int ipinr, struct pt_regs *regs) void smp_send_reschedule(int cpu) { + task_isolation_remote(cpu, "reschedule IPI"); smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE); } diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index bd0f4821f7e1..acd11a69c4e4 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -332,8 +333,13 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) /* * Handle the "normal" case first - VM_FAULT_MAJOR */ - if (likely(!(fault & (VM_FAULT_ERROR | VM_FAULT_BADMAP | VM_FAULT_BADACCESS)))) + if (likely(!(fault & (VM_FAULT_ERROR | VM_FAULT_BADMAP | + VM_FAULT_BADACCESS)))) { + /* No signal was generated, but notify task-isolation tasks. */ + if (user_mode(regs)) + task_isolation_interrupt("page fault at %#lx", addr); return 0; + } /* * If we are in kernel mode at this point, we From patchwork Sun Mar 8 03:53:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250981 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=c+cPXSlv; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=m0s/rxSs; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48ZnXZ5BcHz9sSK for ; Sun, 8 Mar 2020 14:54:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726307AbgCHDyF (ORCPT ); Sat, 7 Mar 2020 22:54:05 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:55008 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726138AbgCHDyF (ORCPT ); Sat, 7 Mar 2020 22:54:05 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283l1im010585; Sat, 7 Mar 2020 19:53:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=VshAxQlrpDGqLX3Ub9gD9awNJkWKsqMZMcz/QPzm4d0=; b=c+cPXSlvmKl0zbzWE2DqoQrEsqoCQjZ6/cG75qffbYZy7RpRSw8SiajIDjEUCJVDsqQ+ hRIB46QGdBppsChhFAeTOZ9Jzivh+Gcp+qPwPO8JA/dQvVl+pGWRcaMxtS4yaH+5BCTO mOed1WDuYofkvEYwhMvsqD/hWPbwzH+YfDehzL7IBJOUNl6v5Uxmn6JqNcmbdmGKuVTV rqmBj23ll9nmUukWG6L8drJJOvNykxG/ctewH1kM13DPT1Dn/WrPwjSMmipTLzJstBF7 snxpejZty5ZRxPum9ojoFHaDQ6F+xJHxqIU/3EUHqL5u30SUlCWsd/urbimf3lfn2MGf FQ== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0a-0016f401.pphosted.com with ESMTP id 2ym9uwavc6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:53:38 -0800 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:53:37 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.177) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:53:37 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iId1pAbZNQ8JgSQg06mNPFAsZmhu7RvxI6UwFck/+zGUNaOJisQ1tvcxSXt1oJp360cPo04cXn1vUxZSIC1QLJG3k2bPgwah9enZmLuPwKJ+CYHat3YEMwmb7ol31aPCT8nFeMZ31nKf8++yTF12icmyRLOUFcAFlUqc4o6ifA5c9i+JV4BscOF5dRfnDt1oVlPWuqpJWDv0HXs6U5xKt0atdvLvl7ABxmHFeeqYUhBPIQlknHmB9rYdE4Tr8M6uh5tfmH3u3ZnfJfzgiexkDLWDi7HiPH3rNJzHZDMZ+WOvjWfzOUGbxXg6POLPT2dCKp6mcucwClll0MupCnuePA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VshAxQlrpDGqLX3Ub9gD9awNJkWKsqMZMcz/QPzm4d0=; b=GvBCODgI6XaMsttxXL48Ygdc571+f3VuvpQV0Na4io1ySgDkwKGansBL5tB3yrROg+xKj3oPDM2emCOi/XXW/s6ZUYH+6hxsIEh0zb+8TXbX22nvkBRy6cJfHjV/wGN6brd+ghYDH9hGGqpVtubkhpuDys/9Rc7cIGl0MdoZDFJa5rcTk5rDc+CqId7K0OEFxfs/g6P5F1Ogv2WiwfyAfN5Z23A83r/kHHAYwE768HLwx6vitZ6nNXXvY2UPmodD2EndTZNeXebuxeMZlZdNV+EYmOSk3un9bwjfc0WmFdIlaFsXbMQh8feFWnSsiBR4PkYWPwqA8GK6WTWYsZb1ng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VshAxQlrpDGqLX3Ub9gD9awNJkWKsqMZMcz/QPzm4d0=; b=m0s/rxSsSgxsdO4SdB6qtiBowW+sMpUAlNTQBFQL3mAKbqhrI5qApQoOMUwQfxysaUe5zSRnkarnuXgNTvWufSuywapH+KSeiVv8F2DbeBG15g0/ZARj4Iw73IEBaOJVC6JkX8ifBdovHYYeSluxVn+TNSc9c9sX2iIZIyiKhqc= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2661.namprd18.prod.outlook.com (2603:10b6:a03:136::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Sun, 8 Mar 2020 03:53:35 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:53:35 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 08/12] task_isolation: don't interrupt CPUs with tick_nohz_full_kick_cpu() Thread-Topic: [PATCH v2 08/12] task_isolation: don't interrupt CPUs with tick_nohz_full_kick_cpu() Thread-Index: AQHV9P0k4GMnIbRPmkShfBNP7hpH9A== Date: Sun, 8 Mar 2020 03:53:35 +0000 Message-ID: <0b4615be96008d1031efd3ed309437c05d564019.camel@marvell.com> References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0e45a13b-7eaa-444d-32e0-08d7c3144730 x-ms-traffictypediagnostic: BYAPR18MB2661: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4502; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(376002)(346002)(39850400004)(136003)(366004)(396003)(189003)(199004)(5660300002)(186003)(26005)(66946007)(66446008)(66476007)(64756008)(66556008)(6486002)(6506007)(6512007)(91956017)(478600001)(76116006)(7416002)(4326008)(2906002)(86362001)(36756003)(4744005)(71200400001)(2616005)(8936002)(81156014)(8676002)(81166006)(54906003)(110136005)(316002); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2661; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: w9bPIUUzRiYavzQsGz27feKKQf8amrol5kYqO7iXcCaEp8nzSy1wJS3UM6lmsNKetDMCHDMxfksjTTHV+JqDDeeVF9iyV20xul+ZVXK6WXkamgAlQ0+cWFqIxoDZEhmHXWBfBkBtiCC1XtXsn0rZGcmG8W9+XthgjRby9V0kDV1BrCwjfBZI9aMLTsDUWwCDWqWSJNO7xEHN3cI9GdardtUE/2nIBkiDStouejbC6aIGa+8fgQISTS4Nycq1FtiXQeGw6zMCPpRnUZwwmpMG8dZPM9hh1KYvH4Ni/2rlPVqHK7paDSHn3M3hMKcf3tkFSNiX3PCsWFx0AjeKlopfzA1FJbdFcxN9RccNRn7pYQVxFaMrQK9QRnEmu6d9VAHNfcJ/Lso7q1flujlkcbqWoGCfb28l1Wk6jQONikJtedVMVGx5icynODpZWFm6bI0b x-ms-exchange-antispam-messagedata: wyFtbJwbo6uu250MoBQgzm7ZNyMUyGQO2/miTojm5/qyvw0WKKMRBHvmyOacwPPdqHRInbiCNY4K8slZeUaN1624bOfG6jpax/sC/Y1XGp319fM8pDRyNspFPiMfq82wcrsWLWiwTuhsIHWvfwwJvg== Content-ID: <12BFA578C199064E880E6064C4B51C83@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 0e45a13b-7eaa-444d-32e0-08d7c3144730 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:53:35.5828 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: niHMUmcgY/fF4N9xHpXroHTwFYtzu4p3oiRGrstz1DZ7DXcdet+XUAxR0dX5qMW6MyQERa6y8/fum4Mdq6j+ig== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2661 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Yuri Norov For nohz_full CPUs the desirable behavior is to receive interrupts generated by tick_nohz_full_kick_cpu(). But for hard isolation it's obviously not desirable because it breaks isolation. This patch adds check for it. Signed-off-by: Yuri Norov [abelits@marvell.com: updated, only exclude CPUs running isolated tasks] Signed-off-by: Alex Belits --- kernel/time/tick-sched.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 1d4dec9d3ee7..fe4503ba1316 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -262,7 +263,7 @@ static void tick_nohz_full_kick(void) */ void tick_nohz_full_kick_cpu(int cpu) { - if (!tick_nohz_full_cpu(cpu)) + if (!tick_nohz_full_cpu(cpu) || task_isolation_on_cpu(cpu)) return; irq_work_queue_on(&per_cpu(nohz_full_kick_work, cpu), cpu); From patchwork Sun Mar 8 03:54:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250982 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=aDxLXv6j; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=HonBtHpC; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48ZnYk3brPz9sSM for ; Sun, 8 Mar 2020 14:55:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726346AbgCHDzE (ORCPT ); Sat, 7 Mar 2020 22:55:04 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:16808 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726138AbgCHDzD (ORCPT ); Sat, 7 Mar 2020 22:55:03 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283l0kG016589; Sat, 7 Mar 2020 19:54:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=7uwLq7YtkP35e1XF36deYTJy3st9hj5NfCBESg1sgqA=; b=aDxLXv6jI2gtvd/E1CpsJwgnEpZaHfpAJnR9ORoS2Gs7YV3/1xZ94C8gvMp4xVvoOSdt xaSgkd4gotoviYJ8MZxkZJ+qptO4A1qi0Z7hNu2EbWdfUt+g8gl2+A2T32nNnji1hjKM RYyEknKxGClj0qEcRqYNx3A2uoBlMuLaT98R5yi6uFY/NWuqdYDWTyJoGjnmYhTnIu9q POYx683Ut18A1jUUpFlZgAk3AMuKOOaw6bIa0hRNu6j3b9IfkefFvoNWLH2cTZUcoYQZ K6rD6oBSFa7Sm4kUBafHBcqrLsJ1uVhSnXs3JoPzw4eKIgx1jeDbFPcIxibPHDMcqcsb PA== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2ymc0sj233-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:54:36 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:54:34 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:54:34 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.175) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:54:33 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HetgxSTp4X6Sqaw2DfwlN+Xwc9peVZpEa2t1sTNnDOcp8ConfBdoYn/N7DRT8lHqfv7AE7/DMRddIrpRXG40vQCIcovAMnjHIbd9X5wCh5lo2TBl5k63hU/eFVrNKd6PNGydYHRAbdc867TK9v1VeWZeHmss6f8Eqv0bOVY6VFWhDOoVf/fzWoi+I1YKHmJE93UWtI9pOak6rz25fPW8b5QNUmmUW9NOrJb/tsShswKiWEjyVN5uP+VEywOtP7e+FNB7m5tQcMZBWedBP3lAcoZdz/G5qTXuxOhgWvSq0Pv165iveJMmzS5EuV8jMlqWa5iUrEgKCfhJ/wqv8c3l0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7uwLq7YtkP35e1XF36deYTJy3st9hj5NfCBESg1sgqA=; b=jVLv76X1loXtmQAAJnDcXNYIM8buuIvT/0mwwdNvGJnszTSsi4BaZzUOnMPWpy9yyzndMXJuAvifjmQ+JQhYDfldRPEBUZ3p57WJxxU+KxDIetyu+uv0EWN4+zxkc48O9CuyvQ9PhvYp5aUM2TKUgkocsU40P0L7lUiDiywX5G81nJB2pj4CZhgX89Ce/rtIRxjTzLDBIeprlal3XqhG9I/eREtDkyxuaRpkutGcSHXz7ke1/Cpd6Ei80Ru2dg3zGaXQvp//3thA535NWjXIuEOtJzf5kA6+XkFSxaLNMICgvmnZYevbzr9xoDeS6bQokzdFuUNnm4Mp5ruxiBp7Cg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7uwLq7YtkP35e1XF36deYTJy3st9hj5NfCBESg1sgqA=; b=HonBtHpCd+MEDbXxHLzfnezKlEffOrxfNnXwidTRJDhVb3C+eI9OGND+YeCQVRCJZxQl52AI5SflfM8zBe+iXugtKNGD6W8tMyqEvCEVIyZrYf3/4JLs/Nza9/5QFL1ElH7NJi7wy2auYbt9cQN9prc6kjrej36wsNOmGKoR238= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2661.namprd18.prod.outlook.com (2603:10b6:a03:136::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Sun, 8 Mar 2020 03:54:32 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:54:32 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 09/12] task_isolation: net: don't flush backlog on CPUs running isolated tasks Thread-Topic: [PATCH v2 09/12] task_isolation: net: don't flush backlog on CPUs running isolated tasks Thread-Index: AQHV9P1GBrz1yVmd6UuxuMn6UClzgQ== Date: Sun, 8 Mar 2020 03:54:32 +0000 Message-ID: <541d4f371541b5085fb3519ae749d9ed8f056aeb.camel@marvell.com> References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b8999706-7442-4b2b-fb53-08d7c3146949 x-ms-traffictypediagnostic: BYAPR18MB2661: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6108; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(376002)(346002)(39850400004)(136003)(366004)(396003)(189003)(199004)(5660300002)(186003)(26005)(66946007)(66446008)(66476007)(64756008)(66556008)(6486002)(6506007)(6512007)(91956017)(478600001)(76116006)(7416002)(4326008)(2906002)(86362001)(36756003)(71200400001)(2616005)(8936002)(81156014)(8676002)(81166006)(54906003)(110136005)(316002); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2661; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Mu1sfgly1DrRSKkw/cBHFMYr5+Sj9Cs/L8HaKefOEMP9NODpmYnSXPnNr9zOyknnpKbuHufMJPWvvZnbUe8KLU7gMJF2aMJluGzuiswdA5NiAwArTN1Xcu6r7CC5ssnEikql9JNwZ8ggL7XfvgqjdSbg8TSrQeU+JB/bY36rhnUWZUC27QnHR0x+bhwr8BUuo7epsnRjX9EQfs/o6NhoHLJHMQz7mt7idFKyOiMv7WGN5LxCVSoFQdl9uCc5GT692VPLou8wgTa4ZKBdaBJzBOD9F6OADP43HUG0+2sCuZKiQWL0P011L6rUGEO6g4ytqhS0sMM7uG9SnvClT8vvDMe5A7QyjkRPcia63VttgKILQXxCLs4rubPVoOshGkEYZexO2F6c1ES/Y/VdUXMf10ShVSLyv1Uwo6/gNRFfprwI7oVLC7YiA4TGcM7/Hsrj x-ms-exchange-antispam-messagedata: q94X6Ph4bEe5bpb0ppead4Gq6gMyET0mUaUi6WoVc2IrPfj0KG5dbTrsHg8n9bfFArFdyGK291beOMAJGYwgM9ASKQAeUB7lNS4t9Xpfhgzt18dmqHMK5D7SQlSTYW0xKtZ4oirDAIxjOpYDdkY9/Q== Content-ID: <4C9919D0E1E70145A8395AD0A6D070D1@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: b8999706-7442-4b2b-fb53-08d7c3146949 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:54:32.7683 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: SlInwuUat97o68Y0AEahB/x+4LwoTzZ8iRUjYnb4eGWUnVPcHWkYKdSrh3FATmpe+D6BpK1rUVeDHyB790oTCA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2661 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Yuri Norov If CPU runs isolated task, there's no any backlog on it, and so we don't need to flush it. Currently flush_all_backlogs() enqueues corresponding work on all CPUs including ones that run isolated tasks. It leads to breaking task isolation for nothing. In this patch, backlog flushing is enqueued only on non-isolated CPUs. Signed-off-by: Yuri Norov [abelits@marvell.com: use safe task_isolation_on_cpu() implementation] Signed-off-by: Alex Belits --- net/core/dev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index c6c985fe7b1b..6d32abb1f06d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -74,6 +74,7 @@ #include #include #include +#include #include #include #include @@ -5518,9 +5519,12 @@ static void flush_all_backlogs(void) get_online_cpus(); - for_each_online_cpu(cpu) + for_each_online_cpu(cpu) { + if (task_isolation_on_cpu(cpu)) + continue; queue_work_on(cpu, system_highpri_wq, per_cpu_ptr(&flush_works, cpu)); + } for_each_online_cpu(cpu) flush_work(per_cpu_ptr(&flush_works, cpu)); From patchwork Sun Mar 8 03:55:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250983 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=VIk+Zcpd; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=WQNpW3dB; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48ZnZp4M5Rz9sSJ for ; Sun, 8 Mar 2020 14:56:02 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726322AbgCHDz7 (ORCPT ); Sat, 7 Mar 2020 22:55:59 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:10400 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726174AbgCHDz7 (ORCPT ); Sat, 7 Mar 2020 22:55:59 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283tAWQ026854; Sat, 7 Mar 2020 19:55:28 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=qdZ/vn3bHhysvv1QtgEvgFqxPoO4vvTNif9CUS4Xkc0=; b=VIk+Zcpd1gDYm0XqfFQZ5IBBnJM0hWXHHYohUrogszsIMO4TLDaUhg6/xnUJvqUWv4th hMM+vGNE1q7osuShuvY68DQIGu+akgOEoOZ/yXs/JemcvkZU1JPdEYE3tYkxP9ei42AB sg36SxNYsKM+9qp5AriIbLxVudrrzogM0NM2CR2/GMr4Zt45+/+19Y/K6R2BLrlz4u0Y 2F3hzIuA/gogdimuFdyBAWKgks4K/6l/CYfy6ZJmKPtH+qPkhMskOGOfjXYnrIo4FnJt JgNGc4A9Kklur/fe/xJgplg+ehzcGIoCMs2Hz2bpsOdEUw+Ik31X9s0LyzhW4cCYldE2 uQ== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 2ymc0sj24f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:55:28 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:55:26 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.170) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:55:26 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F6uupuh5/ZHrMp4BWEpqaiolF77uAduM43m9N8lIXxVf+liFwZBfz8ONf0LG79LH2ETcL3tm6ti/TZccWU4a/H7j6fP1wjuEdsBtpReL43F4GSLe3tOUwTJ3mHLzmMIq9bgcZFUM89R0xMHMy8a/vtJFLKsjC0Cw+wt9fE0aOOX+liJTSmyCOMF9LepRf4pJhUD/+LwrKBPhxYQ9Dsl50aVg3eHveEh+8Z/cWhbz8cQdQxKQja8yx6bA3yMWIdC6vrNpD4kqJyFWLcPYH1e6izaYfSTAINcrifl5VwoY3a1FJBbcdIDO2VGT+8dSnw45GrBpdN2Vd5f/iLhfQPiBWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qdZ/vn3bHhysvv1QtgEvgFqxPoO4vvTNif9CUS4Xkc0=; b=XwCuE06Xn12upIYN8GHo5z/qd9b5aZ0guJLKTJ0O3znmgBS4yb0CTm3dnzbo6HwqOud4TaVf9DeWLETiZqcV8Mmyt4dkN3nZuZgte3HBoH0NuJdtsUmqvthK+gd0+0u1vpZg9iQZxDpkYqsm7UUKplO1cr7WKLkx1riDAyz/aXbJJOGAQdGc2+jWf5Fa/UW9ZpaFz5eA9ZqzvF9TuNXo7ZeGYqxq442AAlIxG5goWrQxae3RPeG9Z2r3EY4KFtO+fu1AOQ0X1e5rUq+fy21fsE80OVZhppxqJ2yPtqPGhzNTDLmDWFe4AK8RttqnW3GWqC29xpxQ1SctmaJXShWvwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qdZ/vn3bHhysvv1QtgEvgFqxPoO4vvTNif9CUS4Xkc0=; b=WQNpW3dBMEj4T/4XY9zYZzjAX/djRBfZ5spBckvNdYi3UOY5/TwLdQ9xzFNVQy1uRCrGc8981m57HxDCvvwo8PohBn8P6wq/vck8f/CbwGrNl2Mv07CSs++Hp5yXk588TJYP8O+n5ZnPKpyT1YigC8TXhOacciAeMdNAQ8pHhgU= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2661.namprd18.prod.outlook.com (2603:10b6:a03:136::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Sun, 8 Mar 2020 03:55:25 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:55:25 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 10/12] task_isolation: ringbuffer: don't interrupt CPUs running isolated tasks on buffer resize Thread-Topic: [PATCH v2 10/12] task_isolation: ringbuffer: don't interrupt CPUs running isolated tasks on buffer resize Thread-Index: AQHV9P1lnq03GLPAlkGSNgjYIgfZQg== Date: Sun, 8 Mar 2020 03:55:24 +0000 Message-ID: <5add46d3bfbdac3fb42dcef6b6e4ea0e39abe11f.camel@marvell.com> References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3b52a88a-a37f-456f-a47a-08d7c3148868 x-ms-traffictypediagnostic: BYAPR18MB2661: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(366004)(136003)(39850400004)(346002)(376002)(189003)(199004)(36756003)(71200400001)(4326008)(86362001)(2906002)(54906003)(110136005)(316002)(2616005)(8936002)(81156014)(8676002)(81166006)(26005)(186003)(66446008)(66476007)(64756008)(66556008)(66946007)(5660300002)(76116006)(478600001)(7416002)(91956017)(6486002)(6512007)(6506007); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2661; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: pHI0fRpVX5NZyPb4d79CwPjPYOflsOWaMl9oUuul1CUZRwJD681Zsh91Qmz2pA8jiH+Oz4Du/2BIx3iEjSlv/nOShfM4/VZftY7h9yFzETiDm2Z1gO51YVu+upITaoyGmuQLj+1lLnubjnhaKWbO1W0FfKeV2JuW0lyEMFumpigXXfCueL0H4x8R9XA6M8i82MtVLMpN4p+Zk2TXquT2NH0W5d5EHmLWACoqKBlxoqA2ZMSSSAIyWdycA9fWNY+jVsInFEWreqk10iP7yyHHiSiQ4YD2JV4Dzc5l4N0hxo273z1hwdHkMdQXDZLVeV83gis9k/epAcHigHahT9hoIzEoPykZYXdvyjofGIG4fNR88LeGUYD6TMwlgShInoT4mtCuSQ68YU7GFeb+oZOEpqz8pi1XepbjfbqaLArTXc17nhG/V0A06t43v19Ec07K x-ms-exchange-antispam-messagedata: 5/B5jPgGH3F5LXyL2WktlHPLgZc6r0RTrmWS3rftadfeDmO4hZNN9FJNFbWZTUF/W8BhSDiUcaRf3DMmCE5zCucaJXTqcaSDfmrPKPQuntgcOQbwEmMun/RQGbuNy+nZ2hnseVzGeO8euJK1i03JtQ== Content-ID: <3896D0563E38F142822135338FAF4CA2@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 3b52a88a-a37f-456f-a47a-08d7c3148868 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:55:24.9437 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Cs/xat34kBHw6Q5eVwXhdA9GSVSZ8BbChTP1sBeYuLW3FP/OaamY5jusSKEaxVjIJTEMJ+vKHMxjONYaiTP7pA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2661 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Yuri Norov CPUs running isolated tasks are in userspace, so they don't have to perform ring buffer updates immediately. If ring_buffer_resize() schedules the update on those CPUs, isolation is broken. To prevent that, updates for CPUs running isolated tasks are performed locally, like for offline CPUs. A race condition between this update and isolation breaking is avoided at the cost of disabling per_cpu buffer writing for the time of update when it coincides with isolation breaking. Signed-off-by: Yuri Norov [abelits@marvell.com: updated to prevent race with isolation breaking] Signed-off-by: Alex Belits --- kernel/trace/ring_buffer.c | 62 ++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 61f0e92ace99..593effe40183 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -1701,6 +1702,37 @@ static void update_pages_handler(struct work_struct *work) complete(&cpu_buffer->update_done); } +static bool update_if_isolated(struct ring_buffer_per_cpu *cpu_buffer, + int cpu) +{ + bool rv = false; + + if (task_isolation_on_cpu(cpu)) { + /* + * CPU is running isolated task. Since it may lose + * isolation and re-enter kernel simultaneously with + * this update, disable recording until it's done. + */ + atomic_inc(&cpu_buffer->record_disabled); + /* Make sure, update is done, and isolation state is current */ + smp_mb(); + if (task_isolation_on_cpu(cpu)) { + /* + * If CPU is still running isolated task, we + * can be sure that breaking isolation will + * happen while recording is disabled, and CPU + * will not touch this buffer until the update + * is done. + */ + rb_update_pages(cpu_buffer); + cpu_buffer->nr_pages_to_update = 0; + rv = true; + } + atomic_dec(&cpu_buffer->record_disabled); + } + return rv; +} + /** * ring_buffer_resize - resize the ring buffer * @buffer: the buffer to resize. @@ -1784,13 +1816,22 @@ int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size, if (!cpu_buffer->nr_pages_to_update) continue; - /* Can't run something on an offline CPU. */ + /* + * Can't run something on an offline CPU. + * + * CPUs running isolated tasks don't have to + * update ring buffers until they exit + * isolation because they are in + * userspace. Use the procedure that prevents + * race condition with isolation breaking. + */ if (!cpu_online(cpu)) { rb_update_pages(cpu_buffer); cpu_buffer->nr_pages_to_update = 0; } else { - schedule_work_on(cpu, - &cpu_buffer->update_pages_work); + if (!update_if_isolated(cpu_buffer, cpu)) + schedule_work_on(cpu, + &cpu_buffer->update_pages_work); } } @@ -1829,13 +1870,22 @@ int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size, get_online_cpus(); - /* Can't run something on an offline CPU. */ + /* + * Can't run something on an offline CPU. + * + * CPUs running isolated tasks don't have to update + * ring buffers until they exit isolation because they + * are in userspace. Use the procedure that prevents + * race condition with isolation breaking. + */ if (!cpu_online(cpu_id)) rb_update_pages(cpu_buffer); else { - schedule_work_on(cpu_id, + if (!update_if_isolated(cpu_buffer, cpu_id)) + schedule_work_on(cpu_id, &cpu_buffer->update_pages_work); - wait_for_completion(&cpu_buffer->update_done); + wait_for_completion(&cpu_buffer->update_done); + } } cpu_buffer->nr_pages_to_update = 0; From patchwork Sun Mar 8 03:56:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250984 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=aFvTt9Pn; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=pmEJI+xU; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48Znbs4XPxz9sSM for ; Sun, 8 Mar 2020 14:56:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726402AbgCHD4z (ORCPT ); Sat, 7 Mar 2020 22:56:55 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:18590 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726252AbgCHD4z (ORCPT ); Sat, 7 Mar 2020 22:56:55 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283tEk9026867; Sat, 7 Mar 2020 19:56:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=k0vIAxn3AIo8QaLwrLyG1NeeznnzsFDK5s3ERyd1KbI=; b=aFvTt9PnrOt4CA+9grRuozihx+Edpge8qvwgkKdt7boAqF4jwXl7QFppT70mVn3KWl0w aI6St/VPFT3FLpCr1mdgqgF11Pm1leV9USQYwFR4FXhuP0gFywCeZIPMLHBmASpc2ZJ6 E8Edcq1SUf5WwqyXjRVEUvkV/fTlUhZaDvp9oPSHWJYCKE4DQYL3bFXfQHng2q8vquYy mY2Lu6meN2bzxMIuhkdcze/5/2efZqqDt7tZUPDiSIcHpsCMdlDtKHz8mFAuZM2ROCbU lU/egrWBQQPpf6j9c9xLiLYSy1cURbs0BvmUdZ+P4ZfPfsLpyuXfgVqVLlVsiXdKXNMx Sg== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 2ymc0sj26d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:56:17 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:56:15 -0800 Received: from SC-EXCH02.marvell.com (10.93.176.82) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:56:15 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.170) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:56:14 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k4aqvJs3k/zx959CzOLGJyWBlXOUgSzeJuZcvp0bAJKgGqsDFlx9IxXUcaATVcR9yJAcuePtTAyCxxGxVdcNV927Cve1EEXwD6KaD0pel11iGxwSxcQt1sRe1r5rR3tDMtvoKUdK/yCNajmjcn91SiOPIJJpCymoN3t7ZVCKMdACcO1StohqqxZvlo8Mb0MZ9yTQiM2DTIfBkLefcEo8I4up/pqTUOkJYpJsPW81DqN9ANINup+/2eGmxmtJXo0Kr7dkamokAzIgOT4LONzXAj99/vv3wYjYRN8j+dUIAvgjif+OWdTtpay8z72Oi5rfqvuRHdMEfWD+VvWXd0OyCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k0vIAxn3AIo8QaLwrLyG1NeeznnzsFDK5s3ERyd1KbI=; b=HS3ObJ8ZbpNXp9EYD0JEkv7dp493rnYxxBHUZv/9dgwLERUnlkkWqoTqzpBRbEN5TMf/67DWpMESRundXKllesnpMFgjM0EDW5N7FxU2te4bYwjk/nwQiUxXDJsUgc7gaGG8fuRpg7CS6lU5InEnnf88rFVyVNVym91EwgkPJ30gd4AJ+3LyAmP/c0bBQwf0vcVnbx6XPixwKAmRkR7I0fya0lIlqOib7RyzV0gisA52i/RTB+d4GSi7br5sGqku7AM+rtRWtkQPUYM6UVeRWihb2HiAcQ4erasIu8DImDzAyl3pIOsEv43nZMJXuUZPUqjtSzLr5GWiPQK/Ys1SHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k0vIAxn3AIo8QaLwrLyG1NeeznnzsFDK5s3ERyd1KbI=; b=pmEJI+xUk88noa5FnL40505PiOwBfKIg+eRAK15as6D7MAa1+d8ksIyqWyTV0a7c/5dPSv/B/3TvQBOATj0YvGCe3DyH2Tk0QY4fCx7EROF4EzVTH6AO83MANRgbtUknc1geZ+/Wp8JnRUcsRU5W62qvV+4e9oUMl5wysRgsUjM= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2661.namprd18.prod.outlook.com (2603:10b6:a03:136::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Sun, 8 Mar 2020 03:56:13 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:56:13 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 11/12] task_isolation: kick_all_cpus_sync: don't kick isolated cpus Thread-Topic: [PATCH v2 11/12] task_isolation: kick_all_cpus_sync: don't kick isolated cpus Thread-Index: AQHV9P2C8Ps2pU+gnk+87Km1UNmHNA== Date: Sun, 8 Mar 2020 03:56:13 +0000 Message-ID: References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e28157aa-2ca2-4fb6-7ad0-08d7c314a567 x-ms-traffictypediagnostic: BYAPR18MB2661: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:873; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(366004)(136003)(39850400004)(346002)(376002)(189003)(199004)(36756003)(4744005)(71200400001)(4326008)(86362001)(2906002)(54906003)(110136005)(316002)(2616005)(8936002)(81156014)(8676002)(81166006)(26005)(186003)(66446008)(66476007)(64756008)(66556008)(66946007)(5660300002)(76116006)(478600001)(7416002)(91956017)(6486002)(6512007)(6506007); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2661; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: BOWGO4LhwRBTMLm5/CQrGqZJPeajT1OFva3gjwLbus+yIY7/6Uo0jBdstk0NOSdUxVZLvfGcZTEQyQEyZ9IV7FlRr9gazC3JxVZzGKiwmv5LgOflqy7eZPc/i5ecqpqvlbEC5eqFP4FfTehtDHaOqpDt4KouKq8csYldMD9oHpVGKu6MG2LzTsugsF9pvwTF/vxl1NeaM2R6igPJKLixSmpm3LBE4OPiuuYwag59YCyKkuZjsAfilEpQxDfcw1SZm6wDhCsmyXQ4vgIU0lpaq9SgcHIKngqUjchxaqLzuuriyNMZmjs/4HtSmY92WJnkMFuBde/QVXSdcO01CikxYAcQtuC+FK28TCmIoUB34HTF3IQewZBdwpdpZ7EPUneiGufMdaMqUlmUwAQwDlE35kaA/mxMzM3FGJ+uU8/Oti+tqg2K3aQMGlPmd534nD4Z x-ms-exchange-antispam-messagedata: ANR7TG8upBWlsjUwlwjj5USQwR0UNR4FGVu+5hrvI4z/CboyKMRlQuLwMRaHKbdC7ii/28Hv02CHJMevElORSo2fnnJtIp69fkDnC+cRj+AUWD9/AKFKS310XCJMEfWHSiY9KFoo54LLU/bPwPXCrw== Content-ID: <0CF0F9A752365D499FA079925E0AB4FC@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: e28157aa-2ca2-4fb6-7ad0-08d7c314a567 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:56:13.6429 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: IB/79jGHa0db6moNctxQP7N15aQ1TpSxdMtMT2QoLICroCaO8nusVbywKuGgsf3+Ffbby1eX2XhklmNF0dYGPw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2661 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Yuri Norov Make sure that kick_all_cpus_sync() does not call CPUs that are running isolated tasks. Signed-off-by: Yuri Norov [abelits@marvell.com: use safe task_isolation_cpumask() implementation] Signed-off-by: Alex Belits --- kernel/smp.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kernel/smp.c b/kernel/smp.c index 3a8bcbdd4ce6..d9b4b2fedfed 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -731,9 +731,21 @@ static void do_nothing(void *unused) */ void kick_all_cpus_sync(void) { + struct cpumask mask; + /* Make sure the change is visible before we kick the cpus */ smp_mb(); - smp_call_function(do_nothing, NULL, 1); + + preempt_disable(); +#ifdef CONFIG_TASK_ISOLATION + cpumask_clear(&mask); + task_isolation_cpumask(&mask); + cpumask_complement(&mask, &mask); +#else + cpumask_setall(&mask); +#endif + smp_call_function_many(&mask, do_nothing, NULL, 1); + preempt_enable(); } EXPORT_SYMBOL_GPL(kick_all_cpus_sync); From patchwork Sun Mar 8 03:57:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 1250985 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0818 header.b=JsaUY8b3; dkim=pass (1024-bit key; unprotected) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-marvell-onmicrosoft-com header.b=N2SARFl4; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48Zncs3gp0z9sSJ for ; Sun, 8 Mar 2020 14:57:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726323AbgCHD5q (ORCPT ); Sat, 7 Mar 2020 22:57:46 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:49860 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726252AbgCHD5q (ORCPT ); Sat, 7 Mar 2020 22:57:46 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0283tG4F026879; Sat, 7 Mar 2020 19:57:18 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=pfpt0818; bh=QqX6DBmhSYAp+Ek6zwjJxp8jOQpdgd0MftEbnabeMYM=; b=JsaUY8b31R5i0N1Y+geKkqlDDi1bdwiHrO1ZP0DG5QsF9ihK603GNXzn0QYenhtpgNER fnMwiUcg9nFj36XBmBtlQ1hCsPgXllKQ/4q9w7KDh8a0/tT2hgyMhBJs2kZs5wGqYRMb G7ydK0MoANebQsd3fUpFM9jpw5PiZ3pV8iP7V3IKiOgb4AW8bj1IJPafG6Uyh1EX2tFm gZ0xgn6eNVk1/l7wNAaflT2QSdVGixbjM3KQJ7cEX3up6XxDiuXLpiAB5gKc/XETxyWu HMBaXNYR/66hWyRJAY4Xu07OsfEJcwvVoYAIGyv2zO/x+ExDvgL7h3ll37hxdNizoW6D HQ== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0b-0016f401.pphosted.com with ESMTP id 2ymc0sj27q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 07 Mar 2020 19:57:17 -0800 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 7 Mar 2020 19:57:15 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.168) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Sat, 7 Mar 2020 19:57:15 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oZYAQbMFcqkdvnAxzMJyDTRbLYPvaa72/eIK02veLLWl7UMB7tQqgnYdJKr06H3PvS7HjXZBm4nA8p1BW8/RFAJoBRSRPkYsDihmnlNpIdv4ThGrTRl5YuFCJEP7KFlI85r41twqq7Zrq6nfWrv7sJ6Gsi8/BDcqv3XDSx9He0YAXGHjhDRMMOrgeYBSlUzgLGKy4g6kiF1DKzkBiIVFnkNCbL0ZTNT6BytIYbQxC44Ftx/k7Qc+a8iaPdg8mHF2dqNscAryeysBWxKrHEOPp6LoBfB5l3obu14gJeuW6YubXkgboFaOzRaOcujbafvODl4iaydnSdEgeJPxET2uRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QqX6DBmhSYAp+Ek6zwjJxp8jOQpdgd0MftEbnabeMYM=; b=k+l5HzOcjsTf+3KXJNqUu7LTXUyrvsbQyVf/uVgFhNO+zt1331p9Z8X18MZDPafnOHMdCd4YLgjAqMcOfcquG14+3qA279U3cxIEaE60gboAXc6v7oVFhuBkZzbyWR+PTArrl+etg5TWAh8CY5tkDX3lgeT3ZbU6xsDobc421aWy54SUjgXQTsLK35aGY6Lacfozf2pjJN0J23yIkmtqEH1yUn0m795xMVYzHOqWen6//P5AtcC3wTZb+l0gZCUNh2som4ug4giyZuIxy/00Vyvu5seelYxTOv4Vya1e4z8WZe7LSeJhN+t0LugTCwGThtxlGPC+7yiNX9FeCkZZog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QqX6DBmhSYAp+Ek6zwjJxp8jOQpdgd0MftEbnabeMYM=; b=N2SARFl4R5vCYvZD/rUsNXxrB2Vw55V8v49/1z1KTIAxjyXcfQnGDopJPWfgXGdIyNp41fmFvPPsO/11n+yzSQ5Vy9kWqlJB5t//CU+Ca77ucU/PYfAg8x3NoB/MrL1U396xc8b1oeQfNjQ6K9oOIDfL8HNIIctQbcWcW507SfQ= Received: from BYAPR18MB2535.namprd18.prod.outlook.com (2603:10b6:a03:137::17) by BYAPR18MB2661.namprd18.prod.outlook.com (2603:10b6:a03:136::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Sun, 8 Mar 2020 03:57:14 +0000 Received: from BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23]) by BYAPR18MB2535.namprd18.prod.outlook.com ([fe80::8cd1:1741:8d2d:1c23%7]) with mapi id 15.20.2793.013; Sun, 8 Mar 2020 03:57:14 +0000 From: Alex Belits To: "frederic@kernel.org" , "rostedt@goodmis.org" CC: "mingo@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , Prasun Kapoor , "tglx@linutronix.de" , "linux-api@vger.kernel.org" , "catalin.marinas@arm.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "linux-arch@vger.kernel.org" , "will@kernel.org" Subject: [PATCH v2 12/12] task_isolation: CONFIG_TASK_ISOLATION prevents distribution of jobs to non-housekeeping CPUs Thread-Topic: [PATCH v2 12/12] task_isolation: CONFIG_TASK_ISOLATION prevents distribution of jobs to non-housekeeping CPUs Thread-Index: AQHV9P2m7r4Cq5RXm0W7iV9iTkwGPQ== Date: Sun, 8 Mar 2020 03:57:13 +0000 Message-ID: References: <4473787e1b6bc3cc226067e8d122092a678b63de.camel@marvell.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [199.233.58.128] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c65de317-9996-4ed4-0e16-08d7c314c94b x-ms-traffictypediagnostic: BYAPR18MB2661: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3968; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(366004)(136003)(39850400004)(346002)(376002)(189003)(199004)(36756003)(71200400001)(4326008)(86362001)(2906002)(54906003)(110136005)(316002)(2616005)(8936002)(81156014)(8676002)(81166006)(26005)(186003)(66446008)(66476007)(64756008)(66556008)(66946007)(5660300002)(76116006)(478600001)(7416002)(91956017)(6486002)(6512007)(6506007); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR18MB2661; H:BYAPR18MB2535.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: tRZx4B7zRm9z98p2OXHivqF9ZInmk414dMbNffTE/DXcuyUkQTkw+gK1zbwd0xNupoU+3q3h7wu4tL0uXszyJinoa4AdEHYhQleNyrF+ZxYowTMIrPNE0Z7+CDGvxrXeoCtylaJNTjUpKPVjIWKYWPJYYrTunJILbZNA7eZz+iyoIg2hWrxKMixxLqyR7ICImkiu4Rqol20ZimxK0/nZnyg1n15GXX3N95Xp5qdQ+c2uWRj1NQVJud37Tq2tLSgV8Z6/7+2QgFl/cVG6KxeQQJIJW7a5QI7a5gFdaKnYFuAgoFf0cXj3ratu6hGWhLyXed1vjVQQ/J9lotQBvf5EmgTimqbkY0SsM6ykjzVvcUm4Rik7Tdf5gr9ZQ5ItMquKhQ4cEyozdCR50A7tJKCogavCShDVddIOT9WHOdj6p4kO1lcevfeaWxwvcisMYJva x-ms-exchange-antispam-messagedata: cIHdX12WV4njsZ177EM5HXuuJ5nDEYUQBQJdZBEla0Kv82ZEYekqnUJXBG1Sp7YOi0D+YTsWHoZspCAorhGeLw/jJw1+zmyrtPGf5aA/9DpmKqcoGJ9taXzYd+6oSNss3mYjTlABk0un38L02iTquQ== Content-ID: <6F7A0CBA8D79BD4490A8227E3C795C60@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: c65de317-9996-4ed4-0e16-08d7c314c94b X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2020 03:57:13.8426 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: tX4HOFXBeJWiRn+m0XzX1SFEyk+4E3R+pri5OJCT3S+BlObkx+2obpb06WVw7z6VixS6PYWTLAAXSzLzSwE+zA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2661 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-07_09:2020-03-06,2020-03-07 signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There are various mechanisms that select CPUs for jobs other than regular workqueue selection. CPU isolation normally does not prevent those jobs from running on isolated CPUs. When task isolation is enabled those jobs should be limited to housekeeping CPUs. Signed-off-by: Alex Belits --- drivers/pci/pci-driver.c | 9 +++++++ lib/cpumask.c | 53 +++++++++++++++++++++++++--------------- net/core/net-sysfs.c | 9 +++++++ 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 0454ca0e4e3f..cb872cdd1782 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -332,6 +333,9 @@ static bool pci_physfn_is_probed(struct pci_dev *dev) static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev, const struct pci_device_id *id) { +#ifdef CONFIG_TASK_ISOLATION + int hk_flags = HK_FLAG_DOMAIN | HK_FLAG_WQ; +#endif int error, node, cpu; struct drv_dev_and_id ddi = { drv, dev, id }; @@ -353,7 +357,12 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev, pci_physfn_is_probed(dev)) cpu = nr_cpu_ids; else +#ifdef CONFIG_TASK_ISOLATION + cpu = cpumask_any_and(cpumask_of_node(node), + housekeeping_cpumask(hk_flags)); +#else cpu = cpumask_any_and(cpumask_of_node(node), cpu_online_mask); +#endif if (cpu < nr_cpu_ids) error = work_on_cpu(cpu, local_pci_probe, &ddi); diff --git a/lib/cpumask.c b/lib/cpumask.c index 0cb672eb107c..dcbc30a47600 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -6,6 +6,7 @@ #include #include #include +#include /** * cpumask_next - get the next cpu in a cpumask @@ -205,28 +206,40 @@ void __init free_bootmem_cpumask_var(cpumask_var_t mask) */ unsigned int cpumask_local_spread(unsigned int i, int node) { - int cpu; + const struct cpumask *mask; + int cpu, m, n; + +#ifdef CONFIG_TASK_ISOLATION + mask = housekeeping_cpumask(HK_FLAG_DOMAIN); + m = cpumask_weight(mask); +#else + mask = cpu_online_mask; + m = num_online_cpus(); +#endif /* Wrap: we always want a cpu. */ - i %= num_online_cpus(); - - if (node == NUMA_NO_NODE) { - for_each_cpu(cpu, cpu_online_mask) - if (i-- == 0) - return cpu; - } else { - /* NUMA first. */ - for_each_cpu_and(cpu, cpumask_of_node(node), cpu_online_mask) - if (i-- == 0) - return cpu; - - for_each_cpu(cpu, cpu_online_mask) { - /* Skip NUMA nodes, done above. */ - if (cpumask_test_cpu(cpu, cpumask_of_node(node))) - continue; - - if (i-- == 0) - return cpu; + n = i % m; + + while (m-- > 0) { + if (node == NUMA_NO_NODE) { + for_each_cpu(cpu, mask) + if (n-- == 0) + return cpu; + } else { + /* NUMA first. */ + for_each_cpu_and(cpu, cpumask_of_node(node), mask) + if (n-- == 0) + return cpu; + + for_each_cpu(cpu, mask) { + /* Skip NUMA nodes, done above. */ + if (cpumask_test_cpu(cpu, + cpumask_of_node(node))) + continue; + + if (n-- == 0) + return cpu; + } } } BUG(); diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 4c826b8bf9b1..253758f102d9 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -725,6 +726,14 @@ static ssize_t store_rps_map(struct netdev_rx_queue *queue, return err; } +#ifdef CONFIG_TASK_ISOLATION + cpumask_and(mask, mask, housekeeping_cpumask(HK_FLAG_DOMAIN)); + if (cpumask_weight(mask) == 0) { + free_cpumask_var(mask); + return -EINVAL; + } +#endif + map = kzalloc(max_t(unsigned int, RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES), GFP_KERNEL);