From patchwork Mon Nov 23 17:56:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 330981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 337C0C2D0E4 for ; Mon, 23 Nov 2020 17:57:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB28320758 for ; Mon, 23 Nov 2020 17:57:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="UtsY8Dp+"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="JfB6qWKf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390443AbgKWR44 (ORCPT ); Mon, 23 Nov 2020 12:56:56 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:35254 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731340AbgKWR44 (ORCPT ); Mon, 23 Nov 2020 12:56:56 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0ANHtsnM032585; Mon, 23 Nov 2020 09:56:04 -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=pfpt0220; bh=ayKeG63TgdBGMWt1elUzDKUGrj2crvvsQ9p3cwwH5ak=; b=UtsY8Dp+ZO5f3OPsimL93Lnbcl/uYS3ZHxxB+QElzOfKFS3ZIuUZ/L2d2LTe4fDAtg5J vhezygtr+i9EtfGmgeRNCyNmM6ZlfoBsFpKGCNYiqdZOPEb5ByOmYAhjpZM4kKsLbD92 4MduIC9+HFcShFrE2Cugc6juHkvlNJfjdIlbkfXiwVXISjAKz5Il82OY/q5R8+i9G3M9 23uRfc0Rmz2mWkUGVKTlXBZxczl13TQnytwP7uucLfVTM/zuZ67rs3F7ZaNxdbMPgr5a Inx5V8jW/e53TABa7FaImsnagxwwUipFoIpGPEa8XnHHkUsfN6JqpsxUoYtqVmqZhLBm ag== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0a-0016f401.pphosted.com with ESMTP id 34y14u6ttk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 23 Nov 2020 09:56:04 -0800 Received: from SC-EXCH04.marvell.com (10.93.176.84) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 09:56:03 -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; Mon, 23 Nov 2020 09:56:03 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.108) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Mon, 23 Nov 2020 09:56:03 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i7tm1+76zAtj/vIyFCxE6yQMb4CsarawXzIRT+03KQrO1+nLAuJsQXgCi/xi4tdbcO4aVYrQDCQ1CDwekiXDgVPu/9WhOA5bjlC+TfGjEkDEdtX6QQ084fDspzd3UKMPZotbufJV6pKZeY9lCGEfmyu3aE6lDcdfC1j7KrIQEiF6CKYRf6SHyt/X5oNeIWF3I7fbhBbITxiTkvHFWWJhexpjm79BlQ++mUmShaPI0DnxMncm8jS5egMdI7jTrw3wKlp3OfJs7pHfPmohCyEomXyssa8T2HyiPkCwO9k5oJkoXPLAE2VLX1+JKr/3InShC0jTMT3jVZwFtylbwSshGA== 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=ayKeG63TgdBGMWt1elUzDKUGrj2crvvsQ9p3cwwH5ak=; b=hpxf1M3GjHDdDuLj9bHAXoL2xob1XEKAPPSF/4zEmKSIVPQDbJ6aKVJAxZmiRPf2aZQRgueqvUWae7ttvuz2Ou/UW2skYSnKkHbGhuMac3ihhIphnK3gfkw0L6rHnsrRFkwUQLywqasqajphJiXeiXpGXDQKX0knpWr3JsQT3LAmEXhh2DyuB3d5YkZaCQAPsrXqCBbS39/TyTnvzEqswv8o3rrvF67+fTelBEXkWl9VQNxsw3uDM1swI2lydxLy3rc7QmsjQLwUOOZsbismS0/+/OQUoocKCzf5xlzPsbVIeVLptytUrjrvlVl4yx4q2gTWulBQmWDWAU5SfjZuYw== 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=ayKeG63TgdBGMWt1elUzDKUGrj2crvvsQ9p3cwwH5ak=; b=JfB6qWKfMc6J0mdkxZTBVtjb+x2w17wkRHQ447xS0o35X2TgD+OVWylAGNVL3UhTUL7rrrJD7y1RhRSN03Vkr79+BHfLPa3uinWiYAvWGekLVYYZgdkX7iLFzzSchJa+DzfCoarA3285JCMSG0a4PGWhMc6IgwE2inj9CjJeT1s= Received: from MW2PR18MB2267.namprd18.prod.outlook.com (2603:10b6:907:3::11) by CO6PR18MB3954.namprd18.prod.outlook.com (2603:10b6:5:34d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.22; Mon, 23 Nov 2020 17:56:01 +0000 Received: from MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703]) by MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703%4]) with mapi id 15.20.3564.039; Mon, 23 Nov 2020 17:56:01 +0000 From: Alex Belits To: "nitesh@redhat.com" , "frederic@kernel.org" CC: Prasun Kapoor , "linux-api@vger.kernel.org" , "davem@davemloft.net" , "trix@redhat.com" , "mingo@kernel.org" , "catalin.marinas@arm.com" , "rostedt@goodmis.org" , "linux-kernel@vger.kernel.org" , "peterx@redhat.com" , "tglx@linutronix.de" , "linux-arch@vger.kernel.org" , "mtosatti@redhat.com" , "will@kernel.org" , "peterz@infradead.org" , "leon@sidebranch.com" , "linux-arm-kernel@lists.infradead.org" , "pauld@redhat.com" , "netdev@vger.kernel.org" Subject: [PATCH v5 1/9] task_isolation: vmstat: add quiet_vmstat_sync function Thread-Topic: [PATCH v5 1/9] task_isolation: vmstat: add quiet_vmstat_sync function Thread-Index: AQHWwcHncFFYB7yySUCSwy4M4/wQUg== Date: Mon, 23 Nov 2020 17:56:01 +0000 Message-ID: <0e07e5bf6f65dc89d263683c81b4a19bcc6d4b60.camel@marvell.com> References: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> In-Reply-To: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=marvell.com; x-originating-ip: [173.228.7.197] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a177c911-2bea-4778-33e1-08d88fd90a1e x-ms-traffictypediagnostic: CO6PR18MB3954: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1186; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: WeR3fWHdBhlNYuHhjuoI2gi6gCZ1erUXqY612gVYWmlJAUbLJcP5Syi3n76eWrPiKkOJ4T0jsyzT5k9cd5Lbs14RE85Qe/HICzSxs2JSNylUZfp0/NVXm8YnF0Ab7pqgbQbgfgMKxAc+YgTWwrVH6vDUizKHJToEeuLi39dYONBnmhTstAYHeHPu99p2N1R2hGf/XH6gAH4q/kYGeAMJ4Chx57TzHAnZNFo1YVKbGydhGtvHBFduiqEkY8pCqcsu4zyY/WUqxB26HCE3SzFbMyO6AWRz36cnCpSHWxouxTktgDo6pHUn88X13oyK1HbTPTr1MtPGt7ddJQkKcc7Xew== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW2PR18MB2267.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(136003)(376002)(366004)(396003)(39860400002)(2906002)(6506007)(6512007)(64756008)(8676002)(66476007)(66446008)(66556008)(7416002)(6486002)(4326008)(8936002)(71200400001)(26005)(36756003)(2616005)(478600001)(54906003)(66946007)(86362001)(5660300002)(316002)(76116006)(91956017)(186003)(110136005); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: T01+YFQyVT/f4ttncxpIuAGD2LawA0m61uid3Ji7jj8UhXXgHMhTxTJaDlOE+H06q/w/MsZwILZdj63WbPQ5B5uqKEhN+9wkl2RtUmI5R6uTi3TuTpvyFdKVgrU9SJ4O5XRJdagSilhVg28lF8lZbHCMqYlwz0FrOoDqiITE2JL3dPcDu/Riu6thizwNb0WAsRwR9TKhiiz9KEUAfPemKM86iP+AogeDFWkm1LXf6uOoNKA4GMEFsu+CJn/zI0Tcn60WgHCpXUZFFdF641F2YazWpwB+FRVCFKeTDkPO5O04fNh4icIvyimczk1R9CQWbujmx2wobg3N9kLXJnh04IVNW8NOOgBYsW7aKWQQ622hAEacgLMYtKrh0D5EEYvvYslM2VwYWaT89WSiX6ARnORFpXlJv+ciL8EwX9RviZLJmyr2n/4sUD9DiG58mMItgcHpTy/5/Q64rb676jamlsns6KQ0Fd7AzUUKrWWsdkDRlA0VOyRvCrWt6ZchaWWHUTts/b26MrIMLziD/+prPfdfu/g7nuN48RyEfHZH0BRPntaee4RoqNYOr5GcOluXZ6xVkOdYzlof756NTPhDUFUekMp0qRoRHC6f34YDphN4w2Bs6TjTS1noJaJv/dX/G/Od5HYA+bt2BLfxLtaSrlMorD6DbhvzT2V1ZiPgv9+UgoMD3AVEU0wIoI9QLNwmiughGy8frXjL0wNUOZEInbfOoR9Um5bSDZ++9x/555LjxD45gQOjYGzWBJMNXr4JcAlozDNqBIfzKSNQ088rtL7BvUU7rVBzMQEjPj6SBkS8bWjE4E8inZvSM6IJ4iEh0TVusSkzz6b1xWjkz9weFMo1UUHfiN+8bsztac7ICWs+MJ9e58Ayp8Mahzjatsz0aVk7VWQYhY4YRGl+frrA9A== Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW2PR18MB2267.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a177c911-2bea-4778-33e1-08d88fd90a1e X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Nov 2020 17:56:01.1572 (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: 4DTxq/F1OHacfwsrXoBCqTINPgRqURp+6GALpX5cvtQz/qE6fu3iqt+sZjtaUSSKeGQIy+YsqJROt7RkU/ELiQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR18MB3954 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-23_17:2020-11-23,2020-11-23 signatures=0 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(+) -- 2.20.1 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 322dcbfcc933..300ce6648923 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -284,6 +284,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); @@ -391,6 +392,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 698bc0bc18d1..43999caf47a4 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1936,6 +1936,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 Mon Nov 23 17:56:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 330980 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88838C64E69 for ; Mon, 23 Nov 2020 17:57:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3EE112076E for ; Mon, 23 Nov 2020 17:57:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="McX3ZCTl"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="GqU8KpzX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390486AbgKWR5I (ORCPT ); Mon, 23 Nov 2020 12:57:08 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:4366 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390464AbgKWR5H (ORCPT ); Mon, 23 Nov 2020 12:57:07 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0ANHteWq032523; Mon, 23 Nov 2020 09:56:25 -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=pfpt0220; bh=q+mezuTzgLgTkL4t+dz/4pR2SMeorDqyG2uWP3LYDUw=; b=McX3ZCTlxlzhcdoZkRTWVg8gNbqWQK31s8fM34jMFigGk58PoZahNP2psKPBXUTTcnuf bFOrrbBmHpshSRNuH71cBKBRQB8y+QdUPxefEq+W7RHOzw+G3sgeQUkdPC6kPIBiyjc+ U+YscLg5ye+AAZ+mrhi8xKfuQE17mnFG+rzeMDJnJORng3R1ojxoJdyaNGu6tJfQeoug M9A7gMqq6Pquya5cVAIeCQfqc7kLT16M52shBUKTXQgfVqpK/MtZ+BcEl85ew/ShSJmW tDexlEsDgJXt+6A71+vjmMKFVpXfxSVoLaHLReJRgm5U3PRWlAldpIrxMaM6ALfzXhV6 lw== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 34y14u6tut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 23 Nov 2020 09:56:24 -0800 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 09:56:23 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.104) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Mon, 23 Nov 2020 09:56:23 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Av2cxbm7/wyadtuE+JqKotc5Uz+C8Y10+ZXqQLxa/1x1AOHGz3BEwulrwKwq1ACKy80pGMssVIfWNA3j7INX+NLrqx7KtgqfuC3C+iPctz5P1ggzfxhlYn+F0J+F92FAn6MNQogg64oLeuKBig53HrHt/I3YVhf3orTaHOPrDtwaDQLxWPl6gi1vb7/QmXVVRpZQFIjYUNn7TR/1xs/6IEx8EJFvPuhf68d1H/KE83jpY4vxoVSaUTOLGQCUvG+xiZOZahf5U5lYZ2Z4g8S9yozAxSkEVRaoRXFlxkQjjUPHEI3fHOA+uWgAx34NKqeLL6MXIeBvXc6p65mjIGHYcQ== 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=q+mezuTzgLgTkL4t+dz/4pR2SMeorDqyG2uWP3LYDUw=; b=KI5IhuLt4jOrlf/v49l5cCx0eo3lW3TKN2bmA85jFO2jz+l4CNlj9ZU53DqhMxNFcAnuDPTdo+FOmKqfPN880tqD8Mu9pD/7RNfdn64dGxfciegWgxxd+3VvP+1dFxvd7XvPhbmFG2sgLjwtCUX1NeAfIWUtoO0NG+eYwTCqUBIAEyDhn+iCAWyfVe+++woX2jUqsH7PvvaaK4niL64de/tTElialzrSZY6DzQz051yBPh42DfprSzgjflCbncLI40mEydUO3nPHnVgppnPFrqpeLj9qk6VtNxMoUNj5ISuqh/sQa7zEsi8+1hX1fpbl0YCVFcQde1sJUCX8E2kACw== 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=q+mezuTzgLgTkL4t+dz/4pR2SMeorDqyG2uWP3LYDUw=; b=GqU8KpzX2DQuRBDK9d/fQfHt38Yw1ASW0+IXSAk0ro2SWJGQgFgQX+RmL3HhVKoZxcpuQ9VJqicRWk57lVWBOpsJcs0o/dLWgk1jULO+wvQp89kxp9rLIZbAI51hgIRKcXEBWMDpZEVJMQBe4o5NLs2WkP1aUME6JQWrrMPae74= Received: from MW2PR18MB2267.namprd18.prod.outlook.com (2603:10b6:907:3::11) by CO6PR18MB3954.namprd18.prod.outlook.com (2603:10b6:5:34d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.22; Mon, 23 Nov 2020 17:56:22 +0000 Received: from MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703]) by MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703%4]) with mapi id 15.20.3564.039; Mon, 23 Nov 2020 17:56:22 +0000 From: Alex Belits To: "nitesh@redhat.com" , "frederic@kernel.org" CC: Prasun Kapoor , "linux-api@vger.kernel.org" , "davem@davemloft.net" , "trix@redhat.com" , "mingo@kernel.org" , "catalin.marinas@arm.com" , "rostedt@goodmis.org" , "linux-kernel@vger.kernel.org" , "peterx@redhat.com" , "tglx@linutronix.de" , "linux-arch@vger.kernel.org" , "mtosatti@redhat.com" , "will@kernel.org" , "peterz@infradead.org" , "leon@sidebranch.com" , "linux-arm-kernel@lists.infradead.org" , "pauld@redhat.com" , "netdev@vger.kernel.org" Subject: [PATCH v5 2/9] task_isolation: vmstat: add vmstat_idle function Thread-Topic: [PATCH v5 2/9] task_isolation: vmstat: add vmstat_idle function Thread-Index: AQHWwcH0WzY0i0qVVUKJ5jpW2camEQ== Date: Mon, 23 Nov 2020 17:56:22 +0000 Message-ID: <6ac7143e5038614e3950636456cef67b5bc0c9e4.camel@marvell.com> References: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> In-Reply-To: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=marvell.com; x-originating-ip: [173.228.7.197] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bb56586a-20f3-4f14-8455-08d88fd916fa x-ms-traffictypediagnostic: CO6PR18MB3954: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4502; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: iC46aZQXsW84tTGGPEAR0wY7aGRsc9zS5hS8jZCvYC2GH5EVLqFFPWuYE/hcGY9RTGDMgXBfvok6NTB0RHC6O+LRojFyoVvjeNTiCDgJiKtekJ9jJa3jZsIoXkbBMbiBRrB1VWfasgpv4YGCuBhFuXc5yjjyWEpT1KQ3KoLC11sEboDt/UrJiSV+we3zmxeW1gQkbGocL8thw/V1DQPSVkdr/ZU4RgCR5ir2uEz5KI/N4Vru0AuhpwDGc0O9JBNyf3LmwxL93AFgpSBr+CB5n4Ch056rfPuEbLNv26sWZXV5WCk/wIIJif2+mE7dm99lyBilc34r9Fr1nFJH+xYRwQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW2PR18MB2267.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(136003)(376002)(366004)(396003)(39860400002)(2906002)(6506007)(6512007)(64756008)(8676002)(66476007)(66446008)(66556008)(7416002)(6486002)(4326008)(8936002)(71200400001)(26005)(36756003)(2616005)(478600001)(54906003)(66946007)(86362001)(5660300002)(316002)(76116006)(83380400001)(91956017)(186003)(110136005); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: fTcOVmxDyvg2KsMbgTCkSVkpAVbzlpUDLEcHZeN3Uv9oRChomFWyPtxPi6/p2KWPPMi1RTOZ+nuq8/9kKkEBWaxv/+0DIZdW7LsJQ6g2j3wpCzMmJTmyvlyMVqPrARKAh2Kq9zk4G0TCxKak03YGu0ZdgGSfdNl2eaFo8xWDpuamz4ipIbNt5XEL0rqwkY1BO+7Ix8/jAXjbe3XUYX/Fdr0F1PclSo9Ec/RKIW6k1aL5ePU9zCn4ipjza+vmUttK2URprw35kTFObuA5anGiCLlENwHUQcjPRLu4ATjRIWxu0Wcywbyq8emXk/4hovV06Mw4FWrnCdLVs/0CchH5U9Gvcfu9dtRKgjzM3r4AhhUoYAvbWYNZH3NSTVstcHlCQU21XaqtEpBw9WAi94GGgzV8ry47xKE+mSWJ8dhjogq1OsAdzhhiKEFocIAfwvTLF/Pc7ctUKBY/zoOqeEdT3b67W3m+4gSbmaBAxtosgFDywZeEKl0D8b4O54WmbJ6ZvKzxIusJdrwPLtCX9acBTGwpWWdHvIUJUXIWnJx8FL4oXAhxiYGGFVLztQNLMqwYUCaOk8ZtPMg6HC60NyR/5Vb/nyxxUgTxlemWVzymrPMLNm3X/GeS6278z8rdV0bGAvtdvKD12T4dzvLTNEaibGEmtvqOIRuwftUezfev9TKewwkMxBPi1FHetAbNNBzPZbJ399n7+DxJuS5svGFuAERKNeCXtfaASymyOpxiH8S33w3suv/GwRfPQDYV85qBg23xhK/7sB1yj/A0P7LfLxKtTy1+wuyiYhB311SPLRA2Zgrtnau+hOAs8xApU6gM7fOz62zgoHeLW6WNpbSyvn6BSiTn/2T5UdmvQfgtWCieoZ+wTeo3ilZ8a8RDKcz9NzXFMX/+w76OnRUK2dcjnA== Content-ID: <9E079E53BC0AE046828BEDFA6A41E3AA@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW2PR18MB2267.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: bb56586a-20f3-4f14-8455-08d88fd916fa X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Nov 2020 17:56:22.7008 (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: vTaf1fFIh1Wzq5+NwrpSPp83djATvtNv+yydeGSuAqletBkNda1I76fl/mCHqSdwABqny/m/YS+3d6Caypf6pA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR18MB3954 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-23_17:2020-11-23,2020-11-23 signatures=0 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(+) -- 2.20.1 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 300ce6648923..24392a957cfc 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -285,6 +285,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); @@ -393,6 +394,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 43999caf47a4..5b0ad7ed65f7 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1945,6 +1945,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 * differentials of processors that have their worker From patchwork Mon Nov 23 17:56:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 331970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC0C6C63697 for ; Mon, 23 Nov 2020 17:57:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 288E5205CB for ; Mon, 23 Nov 2020 17:57:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="aeZYU5qN"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="mjxvVrk1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390493AbgKWR54 (ORCPT ); Mon, 23 Nov 2020 12:57:56 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:48386 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731411AbgKWR5z (ORCPT ); Mon, 23 Nov 2020 12:57:55 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0ANHsit1021505; Mon, 23 Nov 2020 09:56:59 -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=pfpt0220; bh=tHoReLszDAI3jmxrNXdt2HKxSY04a9TR7emfXGJgwVg=; b=aeZYU5qNVtHqaRZEblgxmftWskIHmcZ29KKSfut1zlIx1ZVolBdqwcv1LsSlhZqsig/2 LTg6bo2XrF38Pd0HvS+R6E22RrMBIEVbCTwSovb28Z5a2HTHik/L8ziBnPZyf7a4Jfjg KPGLusgooemggFl15AYlIYBCHMCD8uggccFIh6psldDubrRJ6xlieLNMxxjzxrriGoiU rJ1ry2qZn2T+M+dnxA7eHHcRL0+H4CDZlsuZhe7XsLG7WHf7jGBmC41zf4XR/JpFRxyQ 2Rx3JSSfttL6DChGoqANxBbfgqwddZc2gxZwav5P7mFaxtRzVrmi/1XA9tFXpTPCHdEf Ew== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 34y39r6df5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 23 Nov 2020 09:56:58 -0800 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 09:56:56 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.173) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Mon, 23 Nov 2020 09:56:56 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hRznavdMedllgthbkewSXmpD3tRHdFKjWYTrelp6vWzeq/wi/7NO2JqlIQ2NHMHLPjI7QizhTbNKIvPkIYmXpq0RqwnMesbGh/twvJiJESmFn8kn0/ye2NyVMzSto0rLsKE1ne3upCmfZDHe3iNHhXWxVJQO8DMHLVZpoGuzF479cBroF0kMkUKF7XVs0jS2Hl/76GAJ06AF59XwoPKb9J9csTRCFnqJStByFZzeL9ie5QQqlPGiJEbZ0IlU7ox0wWpbcQEh/NQJ2vSSBO3WSCtd7rpU+oi3/09PTomOoR5am9NPWdL3MGQDokldrrV/JwB/bWKWliw4Et948s/DoA== 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=tHoReLszDAI3jmxrNXdt2HKxSY04a9TR7emfXGJgwVg=; b=I0ESK90kiz1VcdqOrIr5lMyujfxCQ4WhoRwd8swGEOLXTsnIUofrE18Ly9nlGHw2DJbnxAS7hH3nAeswsoFbPGF8XKpsvfmH4ptFMCGrzAcUdDp3YI2SB8lYQvahMjttzgQPakjyB4iVq+NhSsYlP6hQOeqrv3V4cizNziAPCYPlNEwi2wn4GRf9svrgx6JKnNchL1srmwJCNdUHHjI2X2u6OXMJCbO90s6uPweTcXToegp4wfB/+ZhqZxNmVHyARQGTGTgb/G53kdX4Ggdic4NjDCm7p+kOIvHQBNM9ZplJxSlHzBFQt/2kFJuOVHtB0k8jWnRkOROhnDoqgij8Fw== 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=tHoReLszDAI3jmxrNXdt2HKxSY04a9TR7emfXGJgwVg=; b=mjxvVrk1/TaFzhe6yXJIzOsFOJkp6AIb/FLReWkSswt9b1rVr6A+ZqlmyWjJx0V37cBKlNzva0HWuTH80isMo6EnLRQZdmEJUFZBAVT0wksy6RhEa1jVEJUDasdUDfpFLN4dA7rcRNvkGaYEuBNmqIACXW7JEw2pQL2J1EPFjJo= Received: from MW2PR18MB2267.namprd18.prod.outlook.com (2603:10b6:907:3::11) by MW3PR18MB3530.namprd18.prod.outlook.com (2603:10b6:303:55::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.22; Mon, 23 Nov 2020 17:56:53 +0000 Received: from MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703]) by MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703%4]) with mapi id 15.20.3564.039; Mon, 23 Nov 2020 17:56:53 +0000 From: Alex Belits To: "nitesh@redhat.com" , "frederic@kernel.org" CC: Prasun Kapoor , "linux-api@vger.kernel.org" , "davem@davemloft.net" , "trix@redhat.com" , "mingo@kernel.org" , "catalin.marinas@arm.com" , "rostedt@goodmis.org" , "linux-kernel@vger.kernel.org" , "peterx@redhat.com" , "tglx@linutronix.de" , "linux-arch@vger.kernel.org" , "mtosatti@redhat.com" , "will@kernel.org" , "peterz@infradead.org" , "leon@sidebranch.com" , "linux-arm-kernel@lists.infradead.org" , "pauld@redhat.com" , "netdev@vger.kernel.org" Subject: [PATCH v5 3/9] task_isolation: userspace hard isolation from kernel Thread-Topic: [PATCH v5 3/9] task_isolation: userspace hard isolation from kernel Thread-Index: AQHWwcIGq3rxbUiOxUqcMTxtbX7+zg== Date: Mon, 23 Nov 2020 17:56:53 +0000 Message-ID: <5d882681867ed43636e22d265d61afbbac1b5a62.camel@marvell.com> References: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> In-Reply-To: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=marvell.com; x-originating-ip: [173.228.7.197] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ba117b05-d7e9-49f1-fe10-08d88fd92924 x-ms-traffictypediagnostic: MW3PR18MB3530: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: WJqQ2c9jHsGcO9UOsg1dYA3ZiI7Yog7kccYYsQnogCn7BFS1RMUJaoDDpjZDzDncee51i1hamv1wZ6VZyBbatib4fVg9EN+84lgRlT3NGZRjayJa9my/qwtgDqbyZZe1VwLf+q7NXn3SYLFCjfVvUoTd5+gRlmcXk/vfuklofXZF/nKeRHkL3iQQeQJYlCvb2VQkBMWstHDLjOB34gd/oGjJ8vTTT7sHmHuyNGOjRdi/xi6JmACwGog+cesGtlongEp2dLkqmWlXCHl5OfFgLUAXUDlu2ihi/zjdY/gtpYHCFA537s7GYlNyskg/H6Xd/qhRcpuEo8pU6t0m9o1ZFoCrXYtdgwqvAETgFqWEAQPsimmyjTuFQ3k+ooNcMXs0 x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW2PR18MB2267.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(346002)(376002)(39860400002)(136003)(396003)(2906002)(2616005)(71200400001)(5660300002)(6512007)(83380400001)(110136005)(26005)(54906003)(6486002)(186003)(6506007)(36756003)(66946007)(8676002)(316002)(478600001)(8936002)(86362001)(30864003)(7416002)(66476007)(66556008)(64756008)(66446008)(91956017)(76116006)(4326008)(21314003)(559001)(579004); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: AHbBNo0lsI/gROTs2xbV1vanGr8iu4Lv4FDuKRoDnL23USYPr/csy2vAMwaOz9P2jSasmXrLEDKv3J5dGIrBIv9FhqpHfqvVYAkfBcmuWvbL6YK4UomXo+qQmQJyCQNut48jMU42bxRqziLEeEgQFeYZ/3b8Uw0oSflQaXYVUp1fhcoXqrqQm7KdqusgwD/NYA0pUPkwnOeaHrcZrn0jcESdFV7Z3OoaNuTQtopzYgs6PKeUgUbbqSImhOZbx4HIv3I4O7CkTGuJHjw7hNDW4pMnRwWNlT9/8kV1SZ5q7pmXSzoyhhNXSnvOk7mjIgJ+/H8KMKcOPJr6rdC9D5rNoXe2+CLUD7Lw8QOXpP1JMArG6eyJilEAeJ2n+DmxupxAH7AReDGexwz1Amo8PHlpf5yofuaKtGqrRL0PQhXn4/uTp1263oLekJBu1Djqn2f/z36TimxA9UK59nacibpRdkrJe6XQ0ocQ0HIjk6Bx6Ut9kUiqR2WP9tZkKvIGb38Q+FK9iU2aqRljLUu7Fo17+gir3XDfWyDrAHd3S9gGNCr9Yoqnwj4RHjhawqSyCjAFww0VVZOeNhNea7JKwiL7E0YjSsBRAL6H5QaWi+Hb4wM5P0aIOUDnCnnVwjxzHu1cjUdyW82uFPsQUIyyAo6VVFeaMgM82i81CChsUtHpLFWZzzuhMTZjBAomWt2lDh/wLUvC653BUZEtnTS8U73AvUwsDLIuwklpa9dB/dPy6NJyFyhRXennwHmjxqDhN/jbnUo4tDHC2Ri6HHqov4M6J2zhEFfmrl+1BokXaY/s7MKg/2vwZH790nhfY86IkwlFm2pRtlmTG7y0qZCv8vUNO3BBeFopbf/Q+Q29k9N4GYJsxvsqiBMweQaBSKOYVP8/ATaix/Y1kVDpVHElxWowNA== Content-ID: <00891653461773498D363F8473253E3D@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW2PR18MB2267.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba117b05-d7e9-49f1-fe10-08d88fd92924 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Nov 2020 17:56:53.1751 (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: SHeDtkcgZnaw457HgA/jnFpYByfMYbIggmAkuPNSZSD/KPl8/zj1K4hKIqiJfedHu+fPj/aCbJuJyqaSntJlJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR18MB3530 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-23_17:2020-11-23,2020-11-23 signatures=0 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, 0, 0, 0) 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). The last stage of enabling task isolation happens in task_isolation_exit_to_user_mode() that runs last before returning to userspace and changes ll_isol_flags (see later) to prevent other CPUs from interfering with isolated task. 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 send it a signal to indicate isolation loss. 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. Isolation also disables CPU state synchronization mechanisms that are. normally done by IPI. In the future, more synchronization mechanisms, such as TLB flushes, may be disabled for isolated tasks. This requires careful handling of kernel entry from isolated task -- remote synchronization requests must be re-enabled and synchronization procedure triggered, before anything other than low-level kernel entry code is called. Same applies to exiting from kernel to userspace after isolation is enabled. For this purpose, per-CPU low-level flags ll_isol_flags are used to indicate isolation state, and task_isolation_kernel_enter() is used to safely clear them early in kernel entry. CPU mask corresponding to isolation bit in ll_isol_flags is visible to userspace as /sys/devices/system/cpu/isolation_running, and can be used for monitoring. Signed-off-by: Chris Metcalf Signed-off-by: Alex Belits --- .../admin-guide/kernel-parameters.txt | 6 + drivers/base/cpu.c | 23 + include/linux/hrtimer.h | 4 + include/linux/isolation.h | 326 ++++++++ include/linux/sched.h | 5 + include/linux/tick.h | 3 + include/uapi/linux/prctl.h | 6 + init/Kconfig | 27 + kernel/Makefile | 2 + kernel/isolation.c | 714 ++++++++++++++++++ kernel/signal.c | 2 + kernel/sys.c | 6 + kernel/time/hrtimer.c | 27 + kernel/time/tick-sched.c | 18 + 14 files changed, 1169 insertions(+) create mode 100644 include/linux/isolation.h create mode 100644 kernel/isolation.c -- 2.20.1 diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 44fde25bb221..4b28f2022c98 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -5250,6 +5250,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/drivers/base/cpu.c b/drivers/base/cpu.c index 8f1d6569564c..afa6163203c7 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -284,6 +284,26 @@ static ssize_t print_cpus_isolated(struct device *dev, } static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL); +#ifdef CONFIG_TASK_ISOLATION +static ssize_t isolation_running_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int n; + cpumask_var_t isolation_running; + + if (!zalloc_cpumask_var(&isolation_running, GFP_KERNEL)) + return -ENOMEM; + + task_isolation_cpumask(isolation_running); + n = sprintf(buf, "%*pbl\n", cpumask_pr_args(isolation_running)); + + free_cpumask_var(isolation_running); + + return n; +} +static DEVICE_ATTR_RO(isolation_running); +#endif + #ifdef CONFIG_NO_HZ_FULL static ssize_t print_cpus_nohz_full(struct device *dev, struct device_attribute *attr, char *buf) @@ -471,6 +491,9 @@ static struct attribute *cpu_root_attrs[] = { #ifdef CONFIG_NO_HZ_FULL &dev_attr_nohz_full.attr, #endif +#ifdef CONFIG_TASK_ISOLATION + &dev_attr_isolation_running.attr, +#endif #ifdef CONFIG_GENERIC_CPU_AUTOPROBE &dev_attr_modalias.attr, #endif diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index 107cedd7019a..9a6c9ce95080 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -529,6 +529,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..eb6c99bd2db4 --- /dev/null +++ b/include/linux/isolation.h @@ -0,0 +1,326 @@ +/* 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 +#include +#include + +struct task_struct; + +#ifdef CONFIG_TASK_ISOLATION + +/* + * Logging + */ +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__) + +#define BIT_LL_TASK_ISOLATION (0) +#define BIT_LL_TASK_ISOLATION_BROKEN (1) +#define BIT_LL_TASK_ISOLATION_REQUEST (2) +#define FLAG_LL_TASK_ISOLATION (1 << BIT_LL_TASK_ISOLATION) +#define FLAG_LL_TASK_ISOLATION_BROKEN (1 << BIT_LL_TASK_ISOLATION_BROKEN) +#define FLAG_LL_TASK_ISOLATION_REQUEST (1 << BIT_LL_TASK_ISOLATION_REQUEST) + +DECLARE_PER_CPU(unsigned long, ll_isol_flags); +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); + +/** + * task_isolation_kernel_enter() - clear low-level task isolation flag + * + * This should be called immediately after entering kernel. It must + * be inline, and suitable for running after leaving isolated + * userspace in a "stale" state when synchronization is required + * before the CPU can safely enter the rest of the kernel. + */ +static __always_inline void task_isolation_kernel_enter(void) +{ + unsigned long flags; + + /* + * This function runs on a CPU that ran isolated task. + * + * We don't want this CPU running code from the rest of kernel + * until other CPUs know that it is no longer isolated. When + * CPU is running isolated task until this point anything that + * causes an interrupt on this CPU must end up calling this + * before touching the rest of kernel. That is, this function + * or fast_task_isolation_cpu_cleanup() or stop_isolation() + * calling it. If any interrupt, including scheduling timer, + * arrives, it will still end up here early after entering + * kernel. From this point interrupts are disabled until all + * CPUs will see that this CPU is no longer running isolated + * task. + * + * See also fast_task_isolation_cpu_cleanup(). + */ + if ((this_cpu_read(ll_isol_flags) & FLAG_LL_TASK_ISOLATION) == 0) + return; + + raw_local_irq_save(flags); + + /* Change low-level flags to indicate broken isolation */ + this_cpu_write(ll_isol_flags, FLAG_LL_TASK_ISOLATION_BROKEN); + + /* + * If something happened that requires a barrier that would + * otherwise be called from remote CPUs by CPU kick procedure, + * this barrier runs instead of it. After this barrier, CPU + * kick procedure would see the updated ll_isol_flags, so it + * will run its own IPI to trigger a barrier. + */ + smp_mb(); + /* + * Synchronize instructions -- this CPU was not kicked while + * in isolated mode, so it might require synchronization. + * There might be an IPI if kick procedure happened and + * ll_isol_flags was already updated while it assembled a CPU + * mask. However if this did not happen, synchronize everything + * here. + */ + instr_sync(); + raw_local_irq_restore(flags); +} + +/** + * task_isolation_exit_to_user_mode() - set low-level task isolation flag + * if task isolation is requested + * + * This should be called immediately before exiting kernel. It must + * be inline, and the state of CPI may become "stale" between setting + * the flag and returning to the userspace. + */ +static __always_inline void task_isolation_exit_to_user_mode(void) +{ + unsigned long flags; + + /* Check if this task is entering isolation */ + if ((this_cpu_read(ll_isol_flags) & FLAG_LL_TASK_ISOLATION_REQUEST) + == 0) + return; + raw_local_irq_save(flags); + + /* Set low-level flags */ + this_cpu_write(ll_isol_flags, FLAG_LL_TASK_ISOLATION); + /* + * After this barrier the rest of the system stops using IPIs + * to synchronize this CPU state. Since only exit to userspace + * follows, this is safe. Synchronization will happen again in + * task_isolation_enter() when this CPU will enter kernel. + */ + smp_mb(); + /* + * From this point this is recognized as isolated by + * other CPUs + */ + raw_local_irq_restore(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. + */ +static inline int task_isolation_on_cpu(int cpu) +{ + return test_bit(BIT_LL_TASK_ISOLATION, &per_cpu(ll_isol_flags, cpu)); +} + +/** + * 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_before_pending_work_check() - check for isolation breaking + * + * This routine is called from the code responsible for exiting to user mode, + * before the point when thread flags are checked for pending work. + * That function must be called if the current task is isolated, because + * TIF_TASK_ISOLATION must trigger a call to it. + */ +void task_isolation_before_pending_work_check(void); + +/** + * _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) + +#else /* !CONFIG_TASK_ISOLATION */ +static inline int task_isolation_request(unsigned int flags) { return -EINVAL; } +static inline void task_isolation_kernel_enter(void) {} +static inline void task_isolation_exit_to_user_mode(void) {} +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 int task_isolation_syscall(int nr) { return 0; } +static inline void task_isolation_before_pending_work_check(void) { } +static inline void task_isolation_signal(struct task_struct *task) { } +#endif + +#endif /* _LINUX_ISOLATION_H */ diff --git a/include/linux/sched.h b/include/linux/sched.h index 063cd120b459..5d8b17aa544b 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1316,6 +1316,11 @@ struct task_struct { unsigned long prev_lowest_stack; #endif +#ifdef CONFIG_TASK_ISOLATION + unsigned short task_isolation_flags; /* prctl */ + unsigned short task_isolation_state; +#endif + #ifdef CONFIG_X86_MCE void __user *mce_vaddr; __u64 mce_kflags; 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 7f0827705c9a..bf72afb0364f 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -247,4 +247,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 c9446911cf41..f708580fb56d 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -648,6 +648,33 @@ 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 af601b9bda0e..8a8a361dc1a5 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -133,6 +133,8 @@ KCOV_INSTRUMENT_stackleak.o := n obj-$(CONFIG_SCF_TORTURE_TEST) += scftorture.o +obj-$(CONFIG_TASK_ISOLATION) += isolation.o + $(obj)/configs.o: $(obj)/config_data.gz targets += config_data.gz diff --git a/kernel/isolation.c b/kernel/isolation.c new file mode 100644 index 000000000000..127b2a1cb0cb --- /dev/null +++ b/kernel/isolation.c @@ -0,0 +1,714 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * 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 */ +}; + +/* + * Low-level isolation flags. + * Those flags are used by low-level isolation set/clear/check routines. + * Those flags should be set last before return to userspace and cleared + * first upon kernel entry, and synchronized to allow isolation breaking + * detection before touching potentially unsynchronized parts of kernel. + * Isolated task does not receive synchronization events of any kind, so + * at the time of the first entry into kernel it might not be ready to + * run most of the kernel code. However to perform synchronization + * properly, kernel entry code should also enable synchronization events + * at the same time. This presents a problem because more kernel code + * should run to determine the cause of isolation breaking, signals may + * have to be generated, etc. So some flag clearing and synchronization + * should happen in "low-level" entry code but processing of isolation + * breaking should happen in "high-level" code. Low-level isolation flags + * should be set in that low-level code, possibly long before the cause + * of isolation breaking is known. Symmetrically, entering isolation + * should disable synchronization events before returning to userspace + * but after all potentially volatile code is finished. + */ +DEFINE_PER_CPU(unsigned long, ll_isol_flags); + +/* + * 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(); + /* Barrier to synchronize with recording isolated task information */ + smp_rmb(); + 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) +{ + unsigned long flags; + + /* + * This function runs on a CPU that ran isolated task. + * It should be called either directly when isolation breaking is + * being processed, or using IPI from another CPU when it intends + * to break isolation on the given CPU. + * + * We don't want this CPU running code from the rest of kernel + * until other CPUs know that it is no longer isolated. Any + * entry into kernel will call task_isolation_kernel_enter() + * before calling this, so this will be already done by + * setting per-cpu flags and synchronizing in that function. + * + * For development purposes it makes sense to check if it was + * done, because there is a possibility that some entry points + * were left unguarded. That would be clearly a bug because it + * will mean that regular kernel code is running with no + * synchronization. + */ + local_irq_save(flags); + atomic_dec(&per_cpu(isol_exit_counter, smp_processor_id())); + /* Barrier to sync with requesting a task isolation breaking */ + smp_mb__after_atomic(); + /* + * At this point breaking isolation will be treated as a + * separate isolation-breaking event, however interrupts won't + * arrive until local_irq_restore() + */ + + /* + * Check for the above mentioned entry without a call to + * task_isolation_kernel_enter() + */ + if ((this_cpu_read(ll_isol_flags) & FLAG_LL_TASK_ISOLATION)) { + /* + * If it did happen, call the function here, to + * prevent further problems from running in + * un-synchronized state + */ + task_isolation_kernel_enter(); + /* Report the problem */ + pr_task_isol_emerg(smp_processor_id(), + "Isolation breaking was not detected on kernel entry\n"); + } + /* + * 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); + + local_irq_restore(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(); + put_cpu(); + } else { + /* + * 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. This, however, may still not + * have the intended result, so the rest of the system takes into account + * the possibility of receiving an interrupt and isolation breaking later. + * + * If we can't enable task isolation, we update the syscall return + * value with an appropriate error. + * + * This, however, does not enable isolation yet, as far as low-level + * flags are concerned. So if interrupts will be enabled, it's still + * possible for the task to be interrupted. The call to + * task_isolation_exit_to_user_mode() should finally enable task + * isolation after this function set FLAG_LL_TASK_ISOLATION_REQUEST. + */ +void task_isolation_start(void) +{ + int error; + unsigned long flags; + + /* + * 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)) { + stop_isolation(current); + /* Report the problem */ + pr_task_isol_emerg(smp_processor_id(), + "Isolation start requested while not in the normal state\n"); + 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(); + + local_irq_save(flags); + + /* Record isolated task IDs and name */ + record_curr_isolated_task(); + + current->task_isolation_state = STATE_ISOLATED; + this_cpu_write(ll_isol_flags, FLAG_LL_TASK_ISOLATION_REQUEST); + /* Barrier to synchronize with reading of flags */ + smp_mb(); + local_irq_restore(flags); + return; + +error: + 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, + }; + + if ((flags & PR_TASK_ISOLATION_ENABLE) == 0) + return; + + 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; + + /* + * Check if by any chance syscall is being processed from + * isolated state without a call to + * task_isolation_kernel_enter() happening on entry + */ + if ((this_cpu_read(ll_isol_flags) & FLAG_LL_TASK_ISOLATION)) { + /* + * If it did happen, call the function here, to + * prevent further problems from running in + * un-synchronized state + */ + task_isolation_kernel_enter(); + /* Report the problem */ + pr_task_isol_emerg(smp_processor_id(), + "Isolation breaking was not detected on syscall\n"); + } + /* + * Clear low-level isolation flags to avoid triggering + * a signal on return to userspace + */ + this_cpu_write(ll_isol_flags, 0); + + 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 the code responsible for exiting to user mode, + * before the point when thread flags are checked for pending work. + * That function must be called if the current task is isolated, because + * TIF_TASK_ISOLATION must trigger a call to it. + */ +void task_isolation_before_pending_work_check(void) +{ + int cpu; + unsigned long flags; + + /* Handle isolation breaking */ + if ((current->task_isolation_state != STATE_NORMAL) + && ((this_cpu_read(ll_isol_flags) & FLAG_LL_TASK_ISOLATION_BROKEN) + != 0)) { + /* + * Clear low-level isolation flags to avoid triggering + * a signal again + */ + this_cpu_write(ll_isol_flags, 0); + /* Send signal to notify about isolation breaking */ + send_isolation_signal(current); + /* Produce generic message about lost isolation */ + pr_task_isol_warn(smp_processor_id(), "task_isolation lost\n"); + debug_dump_stack(); + } + + /* + * If this CPU is in the map of CPUs with cleanup pending, + * remove it from the map and call cleanup + */ + 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); +} + +/* + * 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(); + } +} + +/* + * Set CPUs currently running isolated tasks in CPU mask. + */ +void task_isolation_cpumask(struct cpumask *mask) +{ + int cpu; + + if (task_isolation_map == NULL) + return; + + /* Barrier to synchronize with writing task isolation flags */ + smp_rmb(); + 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; + + /* Barrier to synchronize with writing task isolation flags */ + smp_rmb(); + 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(); +} diff --git a/kernel/signal.c b/kernel/signal.c index ef8f2a28d37c..252886e6aa76 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -46,6 +46,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -759,6 +760,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 a730c03ee607..0da007ce8666 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -2530,6 +2531,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 387b4bef7dd1..27fedddc2729 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -720,6 +721,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 */ @@ -867,8 +881,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 81632cd5e3b7..a213952541db 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -896,6 +896,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 Mon Nov 23 17:57:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 330979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B18ABC63798 for ; Mon, 23 Nov 2020 17:58:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A85B206B2 for ; Mon, 23 Nov 2020 17:58:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="REg4e9yY"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="g/uVQalq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390508AbgKWR6G (ORCPT ); Mon, 23 Nov 2020 12:58:06 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:52444 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728717AbgKWR6F (ORCPT ); Mon, 23 Nov 2020 12:58:05 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0ANHskg9021571; Mon, 23 Nov 2020 09:57:23 -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=pfpt0220; bh=HNSnwq3BAnQ302ZnxuEdNJkN9rfi2avd1wcD5vME7g4=; b=REg4e9yY7m/V6+LX58L7Y7C/O9qP2m+xXsASAzMGZbTHIOa6IldIXv7z9+T+1Fsm+6f9 OF77iXnM2fyYt6OQGewpFf3MbCxDqNbXyBX/5a8eVvCWdzKa24SHVIkkH3AU+ySKMkle Jjhq01zggIafG7l+UW3ZrlT9Apdf1whZTk1/FHCorPGMGXvx7YIC2/WimdyqjRPZ82jk WDtOobR5R3XPTjq2sXzB1ZbfyZoMzUk/xrwLPW9//hQnXK+3Gl/Fi76J7Z5fWSQPBLRB oJciCjL731eHZ4F6FdRZmAJ7i01bCIit1R+0EKvUDa1eE2nPmNsCDOyEG8lDgHnd2AgX 1w== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 34y39r6dgs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 23 Nov 2020 09:57:23 -0800 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 09:57:21 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.173) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Mon, 23 Nov 2020 09:57:21 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KSS4jWIynv3ow4UseirWsqRyNxouPFXHoa7DXf3yM8PPgYE9JffeMlx0hqNxKz+4JLUNnyY7wPRgTsrh6/CvOADC0+sQk7CIFZPJaGpyUG+ar3Vy0hhEvyEUDnmNgG9wTTUNeTZmadplD/idZc/J1+FIa7YbKSpQfLLJHutGxJDAqff7FNx+EbhDtdF23h45mq6qap7mhuZ3jT35dxbBB1FfnLlzbRPNaIcXyop1Jg9VcjW+h88cveBKw6VMvema2ZJnOLHTXVZJvTwV8AnBORSH4ARA806PTfapkFDua82l14QquSl4z6/7qw8HcrtaS0yF+/MeA1xRX8cDgwyqMg== 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=HNSnwq3BAnQ302ZnxuEdNJkN9rfi2avd1wcD5vME7g4=; b=fzD3V63KyW2P7NOPh6rUoXP7i7RU7PFCsnbDulr4Ax4UnXNTBujn9PiaMvMpu/k4qf2i2XwWyFpADQzIsmoUZADSLr5GJNAC6lTpsSPpfSWdBDDj+uZM09BW/KWbuukqiNdHn66Rt8g/XddJrDdyOn+ecmcOC04/T2PmwbR87tIpGXI4+PWQ6dLb14PGiR/hwfoAM73Myg5Z/T9FPaR51kcO77E1KOOTRJIx4uHxEkWB7+Dka5c1Imv8MBBhbsvNT6DBXVNgRvpLh2IPIXf9lB/tltZFjSgy3C52Pu+iY0OxeLMKA+i4ElBnEEIFEc60dSo96GYCaVVepdDi+jGhig== 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=HNSnwq3BAnQ302ZnxuEdNJkN9rfi2avd1wcD5vME7g4=; b=g/uVQalqr4vxFXRd8dMYyGA0jb7c4EjXi99MHsUwlndQtvvfIHnzgL4x6MTGRC+oeOYfFSq3gVGw2f18PIdA5IFk4bS7STB32CdZ8+EeSWlklIoYlHjq1m+0+6AQPb+7xEFa7Kj9lswBevWEJffIaRScOMPdJInetRWp7iNchc0= Received: from MW2PR18MB2267.namprd18.prod.outlook.com (2603:10b6:907:3::11) by MW3PR18MB3530.namprd18.prod.outlook.com (2603:10b6:303:55::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.22; Mon, 23 Nov 2020 17:57:20 +0000 Received: from MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703]) by MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703%4]) with mapi id 15.20.3564.039; Mon, 23 Nov 2020 17:57:18 +0000 From: Alex Belits To: "nitesh@redhat.com" , "frederic@kernel.org" CC: Prasun Kapoor , "linux-api@vger.kernel.org" , "davem@davemloft.net" , "trix@redhat.com" , "mingo@kernel.org" , "catalin.marinas@arm.com" , "rostedt@goodmis.org" , "linux-kernel@vger.kernel.org" , "peterx@redhat.com" , "tglx@linutronix.de" , "linux-arch@vger.kernel.org" , "mtosatti@redhat.com" , "will@kernel.org" , "peterz@infradead.org" , "leon@sidebranch.com" , "linux-arm-kernel@lists.infradead.org" , "pauld@redhat.com" , "netdev@vger.kernel.org" Subject: [PATCH v5 4/9] task_isolation: Add task isolation hooks to arch-independent code Thread-Topic: [PATCH v5 4/9] task_isolation: Add task isolation hooks to arch-independent code Thread-Index: AQHWwcIVoVPtc0KJ9ES4lz5Mtce9+Q== Date: Mon, 23 Nov 2020 17:57:18 +0000 Message-ID: References: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> In-Reply-To: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=marvell.com; x-originating-ip: [173.228.7.197] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bbf22c39-c559-4e26-479c-08d88fd93806 x-ms-traffictypediagnostic: MW3PR18MB3530: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: r5zHGgBN6rk0BYC8zo5dgzzvLoF6x6wCmgBpkLF7VKl4BDS0EvnHeY0Yjn8jXmg+R2I28oatFpz4BEPhzGjPS04dgmhECmoyWNS7zxzvBtX5tqvUv/KRqQZDOUVQxt43aRJAlfs3KYbd/FfS7nqJa2kfk9MqX6Us4FCYROFbqDt0tdh7wRvGy/JpOEaLvIdB6GG88sNJfZp2Y2yIML+28TLV0ZrDDUUyr4965XuW86ZvT1XUCHtCRZjAnc8hIxuNjLBObu7oiYMqAEzdBTQrlfy9nQGLs3139VEydqPg3ky5yAIWu5yuaJtPj0oA/c0RoZ+AjcOALx5I5IB9R8sZag== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW2PR18MB2267.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(346002)(376002)(39860400002)(136003)(396003)(2906002)(2616005)(71200400001)(5660300002)(6512007)(83380400001)(110136005)(26005)(54906003)(6486002)(186003)(6506007)(36756003)(66946007)(8676002)(316002)(478600001)(8936002)(86362001)(7416002)(66476007)(66556008)(64756008)(66446008)(91956017)(76116006)(4326008); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: eoKw0E7BgzlSVvx+l62a0GeA2uPmmXiNpCSZEeGT+FblCpTJS61eyeUDW3eFJW6O5nVi3TL/pUu+3luz0WSh58PlNX3FTbMi2kywvLslTwS0qTlPSSWWim1Z2S2EDeQ+QSC3hx+iIiEzmwXwptf4zngmzdCuFD3UMysZ6BFWUlqyAQ1O/qt3u4otp/jpDTVdSNueli7PXo3rEDNlhfWi5WUFno0MYoM1QFih0yiXOa0e3Q0qVnDcmXsQhAzHQteYulP5djF2s2VP9XgLGipTgzZfXsAqS8JrWAqx0gTVZiISp9U2mAo0GYStMrF5uGq7WOIxtk4APs+qYEBf2O6LafRTAfXIa0lv/AtGAJk2E6iqkvtgVHnYVY5GU8MVhXIOFhWKzlgSeTRIQ61U8gLdwwjNwpnOzE9KQcqAllm3JyVbkpzxGrl4WX/MOnb65uxaEqQMn6iO+zbC8FjQtxPEEVN/CEAoY9UCjUhvyIfdBKx0vg9Vjr59tYi3Gk7+HX1FXCqgZwBOXUd6HTTJ4CCiWxttkS0oLOZq45azwj2NTpVBljNEqb9WyNPuJZRmQpMZq+uV9jsX+Q/savjTuoYf+x6AeRggTz77/nVyBveah2BRyhTQ2hmhGd0NRyz9h7e9H6r8AUtPjScl2L77zdbki80xzBs5Erbw+FbEA4v8g3vMOm5fWIXLE7pTyTSR8fUE/xIInh3oyHX3+rkKA6bTB4kuWyoLrk9GyZ1AisGsatdXABsOW5vHk20TUEagqM/CZQUs4nE7dXBof7WC1rYBPFT51QRlaL6Jx5f9xvnN3fYnQ9RAiHiHE4Po1nvEZdYhHa17qugGI8NaukchxZGJezoT373kcyC3qTx8bfYntGm03PmXdWsuN8/GHDCa68qLVsgX39OMcE12dsH38u7idQ== Content-ID: <2303373E2A551D43B55A2519D2C99F04@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW2PR18MB2267.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: bbf22c39-c559-4e26-479c-08d88fd93806 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Nov 2020 17:57:18.1527 (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: +tEO1zdHbjRS2TOLmUbfG8U44gAaeEPhM8mfi1Zgu5QbLk4yr8Hute1HKD1uNngjar5U7NnVPPi01K9eVWP/xg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR18MB3530 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-23_17:2020-11-23,2020-11-23 signatures=0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Kernel entry and exit functions for task isolation are added to context tracking and common entry points. Common handling of pending work on exit to userspace now processes isolation breaking, cleanup and start. Signed-off-by: Chris Metcalf [abelits@marvell.com: adapted for kernel 5.10] Signed-off-by: Alex Belits --- include/linux/hardirq.h | 2 ++ include/linux/sched.h | 2 ++ kernel/context_tracking.c | 5 +++++ kernel/entry/common.c | 10 +++++++++- kernel/irq/irqdesc.c | 5 +++++ 5 files changed, 23 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/include/linux/hardirq.h b/include/linux/hardirq.h index 754f67ac4326..b9e604ae6a0d 100644 --- a/include/linux/hardirq.h +++ b/include/linux/hardirq.h @@ -7,6 +7,7 @@ #include #include #include +#include #include extern void synchronize_irq(unsigned int irq); @@ -115,6 +116,7 @@ extern void rcu_nmi_exit(void); do { \ lockdep_off(); \ arch_nmi_enter(); \ + task_isolation_kernel_enter(); \ printk_nmi_enter(); \ BUG_ON(in_nmi() == NMI_MASK); \ __preempt_count_add(NMI_OFFSET + HARDIRQ_OFFSET); \ diff --git a/include/linux/sched.h b/include/linux/sched.h index 5d8b17aa544b..51c2d774250b 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -34,6 +34,7 @@ #include #include #include +#include /* task_struct member predeclarations (sorted alphabetically): */ struct audit_context; @@ -1762,6 +1763,7 @@ extern char *__get_task_comm(char *to, size_t len, struct task_struct *tsk); #ifdef CONFIG_SMP static __always_inline void scheduler_ipi(void) { + task_isolation_kernel_enter(); /* * Fold TIF_NEED_RESCHED into the preempt_count; anybody setting * TIF_NEED_RESCHED remotely (for the first time) will also send diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c index 36a98c48aedc..379a48fd0e65 100644 --- a/kernel/context_tracking.c +++ b/kernel/context_tracking.c @@ -21,6 +21,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -100,6 +101,8 @@ void noinstr __context_tracking_enter(enum ctx_state state) __this_cpu_write(context_tracking.state, state); } context_tracking_recursion_exit(); + + task_isolation_exit_to_user_mode(); } EXPORT_SYMBOL_GPL(__context_tracking_enter); @@ -148,6 +151,8 @@ void noinstr __context_tracking_exit(enum ctx_state state) if (!context_tracking_recursion_enter()) return; + task_isolation_kernel_enter(); + if (__this_cpu_read(context_tracking.state) == state) { if (__this_cpu_read(context_tracking.active)) { /* diff --git a/kernel/entry/common.c b/kernel/entry/common.c index e9e2df3f3f9e..10a520894105 100644 --- a/kernel/entry/common.c +++ b/kernel/entry/common.c @@ -4,6 +4,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -183,13 +184,20 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs, static void exit_to_user_mode_prepare(struct pt_regs *regs) { - unsigned long ti_work = READ_ONCE(current_thread_info()->flags); + unsigned long ti_work; lockdep_assert_irqs_disabled(); + task_isolation_before_pending_work_check(); + + ti_work = READ_ONCE(current_thread_info()->flags); + if (unlikely(ti_work & EXIT_TO_USER_MODE_WORK)) ti_work = exit_to_user_mode_loop(regs, ti_work); + if (unlikely(ti_work & _TIF_TASK_ISOLATION)) + task_isolation_start(); + arch_exit_to_user_mode_prepare(regs, ti_work); /* Ensure that the address limit is intact and no locks are held */ diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 1a7723604399..b8f0a7574f55 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "internals.h" @@ -669,6 +670,8 @@ int __handle_domain_irq(struct irq_domain *domain, unsigned int hwirq, unsigned int irq = hwirq; int ret = 0; + task_isolation_kernel_enter(); + irq_enter(); #ifdef CONFIG_IRQ_DOMAIN @@ -710,6 +713,8 @@ int handle_domain_nmi(struct irq_domain *domain, unsigned int hwirq, unsigned int irq; int ret = 0; + task_isolation_kernel_enter(); + /* * NMI context needs to be setup earlier in order to deal with tracing. */ From patchwork Mon Nov 23 17:57:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 331969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C360DC64E7A for ; Mon, 23 Nov 2020 17:58:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 607E0206B2 for ; Mon, 23 Nov 2020 17:58:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="i6R4a19b"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="mlLJQs0L" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390527AbgKWR62 (ORCPT ); Mon, 23 Nov 2020 12:58:28 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:57330 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390442AbgKWR61 (ORCPT ); Mon, 23 Nov 2020 12:58:27 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0ANHtsnQ032585; Mon, 23 Nov 2020 09:57:45 -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=pfpt0220; bh=ZsVGrf96RQZC2gJ3j4omQY4A3uR1ZqJF3Li3cBFxpiA=; b=i6R4a19bSrjS23VdfN6af2/g2McSsGsc3qY7nC4vg5UGxoMU4GpoFqytEG042dNueq8o NiX3EkYiPIzUtiKrzUwH4DMD/Q4afnlrRqknzZDZ/g65gQ4Wy2cSatmkOqqJr4b8uR8t WUPqtQ3XMwN7CJECNbR6CNqh6ncffxdBUOzvXaO7Gh7dFXLL6a1oN9zMIWhDi74UiVYf Sg37NpXecW/kfWUkYWeHDXhB//LEKz3P41yy4cvZr2AevgAcp5yNfg60wLCsI/pp01/H IK9fj1OClJ8LAivXIyZGodH8CqRDWTSGnwvtYaxsRmeSGXmFaYQwjTeSQ7zhKNEMOXE5 LA== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 34y14u6tyw-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 23 Nov 2020 09:57:45 -0800 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 09:57:44 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.177) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Mon, 23 Nov 2020 09:57:44 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RBfML/BzAdDDVOmR5W2tEL1SVOMADQUrOgAheS7eTVNm6q0TA5Szp54pdPAFb8HSad4EIB49opeYX2XO7jRVsAqT9IKZUhp19QQX6oUiTKKUMjwoZ3VeH4eBQiJd62fmDt6YEFRdjj2anQteMTUFSwKafF1Mnq0UB4FJZKOQe2HgsQzqN7Tb2DEQ2emgXOawRwsITQ6ssPAuuBDTzyY/C1JtHDIswKZrvRTr3yorVvsosA6BdpIZsTuvUgkypkkIGMC4Wye10OOwTLyHyPk39Pr56n/DLf2l1HhkdQJJKs+m/e7yhsq48HSpeJmEF0XJir21dIpLnbGPR6R/lsGuVw== 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=ZsVGrf96RQZC2gJ3j4omQY4A3uR1ZqJF3Li3cBFxpiA=; b=DL5G5XNvZHqdUwdflqrgOUwv5Xk8ymgSVZie7d1kpduQBbeAisD5si5lwONkcheYOEl+jNzSa5IaiytAZmyBYh9q2sj0Adqn2pzisXb+MzNlERTWwdR8yD8aMhtjJpwihwG0QWCRIn/gpJe89xvkWmmznSqvAlMs4y0Jbbu4Dld2lrTEZ/XjsWyHPt0XUrfV8OsI6VQYtb+aEwUZPwAL9BsxNgxQOPhpqkW1SmMKh35XUKJ+P+1ZHfAno2q9uGZW6IVX59oXZHC2gMxkEZVUjRVyrVKv4dCXVL2coIy9Oy9Z41aiEeePFoVVaiX2X1Kv6PRIx3mOEV6GwEG4DvrrXA== 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=ZsVGrf96RQZC2gJ3j4omQY4A3uR1ZqJF3Li3cBFxpiA=; b=mlLJQs0LTu88LU1d6eaIFip4Uph09Bss7YakCaz+5szVeOBHamw4GSFJbKfJhkaP99GYb9zRpYKkGEmZmbt7MWtzvfraaNFp6Cr7+IAGKPaj3SpirCoDeibdahhX+/gKairHFVEEJlZ8LiDB8a+phHGW1XMm98EN/SorsgxnBJo= Received: from MW2PR18MB2267.namprd18.prod.outlook.com (2603:10b6:907:3::11) by MW3PR18MB3530.namprd18.prod.outlook.com (2603:10b6:303:55::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.22; Mon, 23 Nov 2020 17:57:43 +0000 Received: from MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703]) by MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703%4]) with mapi id 15.20.3564.039; Mon, 23 Nov 2020 17:57:43 +0000 From: Alex Belits To: "nitesh@redhat.com" , "frederic@kernel.org" CC: Prasun Kapoor , "linux-api@vger.kernel.org" , "davem@davemloft.net" , "trix@redhat.com" , "mingo@kernel.org" , "catalin.marinas@arm.com" , "rostedt@goodmis.org" , "linux-kernel@vger.kernel.org" , "peterx@redhat.com" , "tglx@linutronix.de" , "linux-arch@vger.kernel.org" , "mtosatti@redhat.com" , "will@kernel.org" , "peterz@infradead.org" , "leon@sidebranch.com" , "linux-arm-kernel@lists.infradead.org" , "pauld@redhat.com" , "netdev@vger.kernel.org" Subject: [PATCH v5 5/9] task_isolation: Add driver-specific hooks Thread-Topic: [PATCH v5 5/9] task_isolation: Add driver-specific hooks Thread-Index: AQHWwcIjLJ3XhCtZ4UCn5Rp0YgDpdQ== Date: Mon, 23 Nov 2020 17:57:42 +0000 Message-ID: <6e15fde56203f89ebab0565dc22177f42063ae7c.camel@marvell.com> References: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> In-Reply-To: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=marvell.com; x-originating-ip: [173.228.7.197] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 97615725-7978-467b-5bf9-08d88fd946b9 x-ms-traffictypediagnostic: MW3PR18MB3530: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1265; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: IqZH+V28Y+39eM63y9yPGzz58EwE1gqJMAPAihDdMV7ILV4T4+pzHmR0tS+HNiv6aqA9GwVX0wBnUD+YHAvsXN7hv/hw+SA5XxJUunvShzgI99+GYQNftOzGceodwpR6CksoCGr4zST4em4tMK/KlFYN7R/j99VxkuiCnbmzbCcDOJaWzehRZ6fSChF+55rI33+CW8vHdSC4EHcx0TYz25CkLmxDqCjOhUUhhySuM0AFbKqckcIPcV8kkArIdBkoPnSaLawPYKNqKuoOzvpVyHkia9URj1ICHcC/pcIy3zbeIjEgvmuC9pjuck1XpOXU x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW2PR18MB2267.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(346002)(376002)(39860400002)(136003)(396003)(2906002)(2616005)(71200400001)(5660300002)(6512007)(83380400001)(110136005)(26005)(54906003)(6486002)(186003)(6506007)(36756003)(66946007)(8676002)(316002)(478600001)(8936002)(86362001)(7416002)(66476007)(66556008)(64756008)(66446008)(91956017)(76116006)(4326008); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: 3elDcvQibqAkHgBF6TTWWiEMZfiJIQh6SlSwvFJUJvI1GmLahDjkrPiw3MmeT/igzsrsOVfjJHSV3DZul9ixvWLuPoYJMAGlmk5OgtQVru/IxlqRajyuneW+BgVR4C2k/m2+qx4V9CUCg9eS/xwXcqMuLc4y3kLQNzeeWgtx/JrcFQzFNJRFqMySxLP2O5jV8MUB+0xSrdUOwYH9o7jHopJhJEq8v+mFpZPmlcI/SM9Kzzn5Kt6jfiGzm3yYlDfBoKjZPeMXQR/JlD1pArCKpmKgbC+VdgNFQguH5S21vn4dR/NO9ra4rhlCWz/Jqm5VQTkRhJyYuhl1ROc3vISJEKAAHKvoyo8yF479i1Jk0gMwvF1FaWDZvPJb8vHNcC52lwaDGTFnL6qkWWL0N94dwTZ2k6t4+wGJ//CClapiCpoWo3qjIixlskvoId1rMsJgxw0LFnRVOn11+YOZudxg6ti3pQ2qNIKvtToMYKfEeihGS09sUeeFGndPzbHD5i9a5IqX1oefWGzsj1F6la2OfL7qv6aT98ULKdyVGnsAeLl913qrlP9S6M9InTjsVC7aau6ox+D2GAJu6Y6WYVdvUwrvKs4gL0r2MxumNBG7vPS8/VzOP6+63yoXY3O5qtwbTdJUzdeIT1suyIS6i8jt4zERWtT3MN0FEEtwDm7aIxToRcUtwwkOP7jwS5QuHEzF+2qnlOWyICAodsDaOoFRCCP4oo8Frt+k2trzn4cE/brnxeMNi9HrLm/fdjux0ouKLdxdsPf18sr9Hcwqa3eDpDfPddQ3fLMqwbmnI0Y3Wfe9aJbE+txiB1qGP37Bw3Kdnz+DMayuhQTN+LA4hzc7stYijx2MW+54gKBFbuO6knXL8pEUi+MLwmyoXj8+VlpWMI07EU02p/TbdSkL0Lp38w== Content-ID: <5C8C0415A4BFAA41923B78D82E3BB917@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW2PR18MB2267.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97615725-7978-467b-5bf9-08d88fd946b9 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Nov 2020 17:57:42.8194 (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: v3ZMSJ2xPJtEQVOxFlqQA2TE/pwZdjx3y2XIbX6I5lX35cPIbrw5NDTk1/7A1q/obJS9ypZsbucQK8VGQrglQQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR18MB3530 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-23_17:2020-11-23,2020-11-23 signatures=0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Some drivers don't call functions that call task_isolation_kernel_enter() in interrupt handlers. Call it directly. Signed-off-by: Alex Belits --- drivers/irqchip/irq-armada-370-xp.c | 6 ++++++ drivers/irqchip/irq-gic-v3.c | 3 +++ drivers/irqchip/irq-gic.c | 3 +++ drivers/s390/cio/cio.c | 3 +++ 4 files changed, 15 insertions(+) -- 2.20.1 diff --git a/drivers/irqchip/irq-armada-370-xp.c b/drivers/irqchip/irq-armada-370-xp.c index d7eb2e93db8f..4ac7babe1abe 100644 --- a/drivers/irqchip/irq-armada-370-xp.c +++ b/drivers/irqchip/irq-armada-370-xp.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -572,6 +573,7 @@ static const struct irq_domain_ops armada_370_xp_mpic_irq_ops = { static void armada_370_xp_handle_msi_irq(struct pt_regs *regs, bool is_chained) { u32 msimask, msinr; + int isol_entered = 0; msimask = readl_relaxed(per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS) @@ -588,6 +590,10 @@ static void armada_370_xp_handle_msi_irq(struct pt_regs *regs, bool is_chained) continue; if (is_chained) { + if (!isol_entered) { + task_isolation_kernel_enter(); + isol_entered = 1; + } irq = irq_find_mapping(armada_370_xp_msi_inner_domain, msinr - PCI_MSI_DOORBELL_START); generic_handle_irq(irq); diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index 16fecc0febe8..ded26dd4da0f 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -646,6 +647,8 @@ static asmlinkage void __exception_irq_entry gic_handle_irq(struct pt_regs *regs { u32 irqnr; + task_isolation_kernel_enter(); + irqnr = gic_read_iar(); if (gic_supports_nmi() && diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c index 6053245a4754..bb482b4ae218 100644 --- a/drivers/irqchip/irq-gic.c +++ b/drivers/irqchip/irq-gic.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -337,6 +338,8 @@ static void __exception_irq_entry gic_handle_irq(struct pt_regs *regs) struct gic_chip_data *gic = &gic_data[0]; void __iomem *cpu_base = gic_data_cpu_base(gic); + task_isolation_kernel_enter(); + do { irqstat = readl_relaxed(cpu_base + GIC_CPU_INTACK); irqnr = irqstat & GICC_IAR_INT_ID_MASK; diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c index 6d716db2a46a..beab88881b6d 100644 --- a/drivers/s390/cio/cio.c +++ b/drivers/s390/cio/cio.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -584,6 +585,8 @@ void cio_tsch(struct subchannel *sch) struct irb *irb; int irq_context; + task_isolation_kernel_enter(); + irb = this_cpu_ptr(&cio_irb); /* Store interrupt response block to lowcore. */ if (tsch(sch->schid, irb) != 0) From patchwork Mon Nov 23 17:58:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 330978 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D720C63798 for ; Mon, 23 Nov 2020 17:59:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3023420758 for ; Mon, 23 Nov 2020 17:59:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="c2IbUq2W"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="MYTLPTPv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390541AbgKWR65 (ORCPT ); Mon, 23 Nov 2020 12:58:57 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:16822 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726817AbgKWR64 (ORCPT ); Mon, 23 Nov 2020 12:58:56 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0ANHtYXr032333; Mon, 23 Nov 2020 09:58:09 -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=pfpt0220; bh=+5zfWOoo9C8mJq2CA6DN/odbo41v8z2mssdpSRAZiuk=; b=c2IbUq2WCM2FVrMQ71tRDjNaAcePiuU/t6rgwoJUqCHk/tZiYouBDsrlG48Sp9NOG5+D kRfWfZWud9qY68ilR/kTvBRcVZwsaMupn4ZtttDeLNx2CT7yaMFBeI7c/WcGmm8XySgF uycBfyXp1p/JmAtFQEvmWvI58XBoypK0YPzqmzwjNLa0Cem6zh6b4oowG9HsYx4Flkc6 p4dZxRzxfbYFqrniYIlMvtHe9kbJM68fVkYxdcHFXfkKFYQYzM007PPqhZvO0A5x5I+V zOiigwft+nM0ak2S/DQUVFe0gPQQx6XAjuA/7m6fFGIjZ1BqSTWndxi0q0nQQO1DRaAk zw== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0a-0016f401.pphosted.com with ESMTP id 34y14u6u1m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 23 Nov 2020 09:58:09 -0800 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 09:58:07 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.172) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Mon, 23 Nov 2020 09:58:08 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kakNQczypO3n5WuKKrocEGsTUIcvN6v68w3+NYc2kmRZxQMmVzDpllvqf56khMNOHYjwcPZ1Me3zmzS7J1yjJG3jkK5VmUI0RM67G+hpxXfkoXB4OmbvFNC/iQKO++GdaKy8ADI8phcs/AcfU7xhHAiPlbdgN/h/EydSczL/f2a7GnTrLupRY1UWYJVzuvasKW8fJFSUda7h2iGS4OqmABBIHAshovJSAKW+SpABeKc/r+PRgLKRG8EDZazMj/NN3PvedYke5dbmc3uy+QTW+ZKnlP3epDLxbxvsWKcFFxR01Kp6bvXw3HHcsynFVIAXGPAvpBqLTbea5yTsLAQPEw== 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=+5zfWOoo9C8mJq2CA6DN/odbo41v8z2mssdpSRAZiuk=; b=W/stWnds9YsnhaEvRzARLe/nRZsKrR9+N/WjcDoBdDxkuoy37xVnB/+GrsqFQEVhGUvm0S2O07XJpTiYVV1lXYQZ0fbXEPHCrkLQeIeywzaxqC3zkiWdhAZtwwQpthpJY/ic2rCiUeKPCzF4cs8QFmG5D8Ul1aoDhyfeOYzVjRxms2shmEld2YzbpW8+sO73GS4C4h4lxCpaLvTwV2zCCkcEp2Loj8hnqS5jeOGumAmsPyDymV/Y8XtKYQ1gD3drbiQObOOUonwXYCoigQjXIOcNwGlV75d16rH5VXmHFR/oJSApwIoG1lBmtwkrPC0uJIQ2Ydo2ynUs8uKJVlPWkg== 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=+5zfWOoo9C8mJq2CA6DN/odbo41v8z2mssdpSRAZiuk=; b=MYTLPTPvPhcHwdLaBkO9jiXcv5pzQDZqajOqWHyIpNLofmIFyHUXdY2dxHtWV++nSDbmn+DRCdAw/I3rlVXOF47OdsWsU+RKZoeKsDlORo4rvZvZqZzd9Mx486DPQ+ZiWFcOTbjJE+nghW0uQt/Gz4dDNvmpvvgOSLDsp6zBvyE= Received: from MW2PR18MB2267.namprd18.prod.outlook.com (2603:10b6:907:3::11) by MW3PR18MB3530.namprd18.prod.outlook.com (2603:10b6:303:55::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.22; Mon, 23 Nov 2020 17:58:06 +0000 Received: from MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703]) by MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703%4]) with mapi id 15.20.3564.039; Mon, 23 Nov 2020 17:58:06 +0000 From: Alex Belits To: "nitesh@redhat.com" , "frederic@kernel.org" CC: Prasun Kapoor , "linux-api@vger.kernel.org" , "davem@davemloft.net" , "trix@redhat.com" , "mingo@kernel.org" , "catalin.marinas@arm.com" , "rostedt@goodmis.org" , "linux-kernel@vger.kernel.org" , "peterx@redhat.com" , "tglx@linutronix.de" , "linux-arch@vger.kernel.org" , "mtosatti@redhat.com" , "will@kernel.org" , "peterz@infradead.org" , "leon@sidebranch.com" , "linux-arm-kernel@lists.infradead.org" , "pauld@redhat.com" , "netdev@vger.kernel.org" Subject: [PATCH v5 6/9] task_isolation: arch/arm64: enable task isolation functionality Thread-Topic: [PATCH v5 6/9] task_isolation: arch/arm64: enable task isolation functionality Thread-Index: AQHWwcIyUgmIaBCwmkq+zZ19oo0twQ== Date: Mon, 23 Nov 2020 17:58:06 +0000 Message-ID: <91496c0cf8d24717a2641fc4d02063f3f10dc733.camel@marvell.com> References: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> In-Reply-To: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=marvell.com; x-originating-ip: [173.228.7.197] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: badb8142-3f0b-4ab7-4572-08d88fd954eb x-ms-traffictypediagnostic: MW3PR18MB3530: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: y7cpnyqMXnf/qIeNvze+DmXHo+E++Mwy4et/kpZmEc7KqSuoAbtMtnemN6shMt0awQJelgKO86j2pWjYTGQnoel0U6VUfwN45NDxCk6vMxrs78VVVpldHGAYBWp/LS4aQf0GHLxhB4TF/qlXatqaXVBujn9ZDYt7vH+vQlZ7E/h8KhBT+tdk2fboFuv9Ber5gI9Ocesof1DckxO46Jk4E8a17di8eeEQOklm2/gBCyTkRKDRmHLic3193oNjBfdeUkZColF56WBYingjMi/Y08cxx+UdPNjdfcxplbVxx4LfDN1f3pG3P6bG0nu+hTU/ x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW2PR18MB2267.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(346002)(376002)(39860400002)(136003)(396003)(2906002)(2616005)(71200400001)(5660300002)(6512007)(83380400001)(110136005)(26005)(54906003)(6486002)(186003)(6506007)(36756003)(66946007)(8676002)(316002)(478600001)(8936002)(86362001)(7416002)(66476007)(66556008)(64756008)(66446008)(91956017)(76116006)(4326008); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: ndd38rUCP6CTRl+l53zcuDt4JXCMljHr99x1wbZo8l6GkMPxSmcqkYmJqrqeRGYZy8HMJtWsB/BNsr6ydi0mUNZh8CsMJzLEmzcSyMHQJYuuoswtligrKTfCxtqXEHO4vPK5qJIE1voLGF4FkbdL4OF01iX0ykRaEZUSKlQhcAHDd67ZBAa1/Q6pU3pHBWAzJ3JkaNwzBUxNoB0RXAbDJu9y1uMxu04SfjK2W94p5IhPGgxPtncwkQgE1jb5gikZD74t6+yJTAeHs70JsmbRRuTYZjmUTdqAvt5Vt7KqIfQ9082KC/s6iwdsbw11WO2qFWhBNa3Ge6Mbd5TCCZkUm9lKajR5C4m2dA1l/XhtOwwsMHx3CGUlTPAjok3IUAhOK/SGjxO6dn1zL9IfL/RvfpbCezNOPZtmeBRsfIAgTAvQ9pZm/5dnx/Bi5Oh4VaR36bQSLceXtU9k5/tQRVZh9CB/GqMyVk26uIibdtXId0YBOaqjArEqHA5H19tCUZjJXbCOw76LqJ8dSn4KMRXzzI2XUQluJZO5flpHz/WNwB93aZNPTXA3MwFQwW3ZD6aii3W+SuLnXQIwRTvXXGn9UZAS/n/z7UsfkK5tJk0+lHU2WvUw6YzYW5odgjukmMceAuuc8oosrFTjgFvRA8fGPRJoWMd4JptZj1DJD+Qf34tzvAHnZnJ+sRWeqILSQjFDD2NstpRTZkKliLCDU9SRle6dDBDz40RoOkk9DiEtrkZMqqqhpKS9iqh53GjIMQWcEG+89BmdAhoimrwZdt9IVWByeElNAYt3VZRydTLTtchrCNIirmnzgkZwXPERe68nh/vdc4OiSf8QC2axalR1hJbBWbIBM43s1cs+R40yUnfW55ghW/iSZa8Ewku69X68mSDK2xGbJxeutxWFTzZxBQ== Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW2PR18MB2267.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: badb8142-3f0b-4ab7-4572-08d88fd954eb X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Nov 2020 17:58:06.6176 (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: lgCYBa3/FtYA4udOMnenVmYAaoGIDmO9d1541TkqzFnTqqVdNnrFta1BpM5Y6Ebna0Oui74RYW3bWrHo+zUHLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR18MB3530 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-23_17:2020-11-23,2020-11-23 signatures=0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In do_notify_resume(), call task_isolation_before_pending_work_check() first, to report isolation breaking, then after handling all pending work, call task_isolation_start() for TIF_TASK_ISOLATION tasks. Add _TIF_TASK_ISOLATION to _TIF_WORK_MASK, and _TIF_SYSCALL_WORK, define local NOTIFY_RESUME_LOOP_FLAGS to check in the loop, since we don't clear _TIF_TASK_ISOLATION in the loop. Early kernel entry code calls task_isolation_kernel_enter(). In particular: Vectors: el1_sync -> el1_sync_handler() -> task_isolation_kernel_enter() el1_irq -> asm_nmi_enter(), handle_arch_irq() el1_error -> do_serror() el0_sync -> el0_sync_handler() el0_irq -> handle_arch_irq() el0_error -> do_serror() el0_sync_compat -> el0_sync_compat_handler() el0_irq_compat -> handle_arch_irq() el0_error_compat -> do_serror() SDEI entry: __sdei_asm_handler -> __sdei_handler() -> nmi_enter() Functions called from there: asm_nmi_enter() -> nmi_enter() -> task_isolation_kernel_enter() asm_nmi_exit() -> nmi_exit() -> task_isolation_kernel_return() Handlers: do_serror() -> nmi_enter() -> task_isolation_kernel_enter() or task_isolation_kernel_enter() el1_sync_handler() -> task_isolation_kernel_enter() el0_sync_handler() -> task_isolation_kernel_enter() el0_sync_compat_handler() -> task_isolation_kernel_enter() handle_arch_irq() is irqchip-specific, most call handle_domain_irq() There is a separate patch for irqchips that do not follow this rule. handle_domain_irq() -> task_isolation_kernel_enter() do_handle_IPI() -> task_isolation_kernel_enter() (may be redundant) nmi_enter() -> task_isolation_kernel_enter() Signed-off-by: Chris Metcalf [abelits@marvell.com: simplified to match kernel 5.10] Signed-off-by: Alex Belits --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/barrier.h | 1 + arch/arm64/include/asm/thread_info.h | 7 +++++-- arch/arm64/kernel/entry-common.c | 7 +++++++ arch/arm64/kernel/ptrace.c | 10 ++++++++++ arch/arm64/kernel/signal.c | 13 ++++++++++++- arch/arm64/kernel/smp.c | 3 +++ 7 files changed, 39 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 1515f6f153a0..fc958d8d8945 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -141,6 +141,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/barrier.h b/arch/arm64/include/asm/barrier.h index c3009b0e5239..ad5a6dd380cf 100644 --- a/arch/arm64/include/asm/barrier.h +++ b/arch/arm64/include/asm/barrier.h @@ -49,6 +49,7 @@ #define dma_rmb() dmb(oshld) #define dma_wmb() dmb(oshst) +#define instr_sync() isb() /* * Generate a mask for array_index__nospec() that is ~0UL when 0 <= idx < sz * and 0 otherwise. diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index 1fbab854a51b..3321c69c46fe 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -68,6 +68,7 @@ void arch_release_task_struct(struct task_struct *tsk); #define TIF_UPROBE 4 /* uprobe breakpoint or singlestep */ #define TIF_FSCHECK 5 /* Check FS is USER_DS on return */ #define TIF_MTE_ASYNC_FAULT 6 /* MTE Asynchronous Tag Check Fault */ +#define TIF_TASK_ISOLATION 7 /* task isolation enabled for task */ #define TIF_SYSCALL_TRACE 8 /* syscall trace active */ #define TIF_SYSCALL_AUDIT 9 /* syscall auditing */ #define TIF_SYSCALL_TRACEPOINT 10 /* syscall tracepoint for ftrace */ @@ -87,6 +88,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_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) @@ -101,11 +103,12 @@ 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_MTE_ASYNC_FAULT) + _TIF_UPROBE | _TIF_FSCHECK | \ + _TIF_MTE_ASYNC_FAULT | _TIF_TASK_ISOLATION) #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ - _TIF_SYSCALL_EMU) + _TIF_SYSCALL_EMU | _TIF_TASK_ISOLATION) #ifdef CONFIG_SHADOW_CALL_STACK #define INIT_SCS \ diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index 43d4c329775f..8152760de683 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -77,6 +78,8 @@ asmlinkage void notrace el1_sync_handler(struct pt_regs *regs) { unsigned long esr = read_sysreg(esr_el1); + task_isolation_kernel_enter(); + switch (ESR_ELx_EC(esr)) { case ESR_ELx_EC_DABT_CUR: case ESR_ELx_EC_IABT_CUR: @@ -249,6 +252,8 @@ asmlinkage void notrace el0_sync_handler(struct pt_regs *regs) { unsigned long esr = read_sysreg(esr_el1); + task_isolation_kernel_enter(); + switch (ESR_ELx_EC(esr)) { case ESR_ELx_EC_SVC64: el0_svc(regs); @@ -321,6 +326,8 @@ asmlinkage void notrace el0_sync_compat_handler(struct pt_regs *regs) { unsigned long esr = read_sysreg(esr_el1); + task_isolation_kernel_enter(); + switch (ESR_ELx_EC(esr)) { case ESR_ELx_EC_SVC32: el0_svc_compat(regs); diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index f49b349e16a3..2941f2b16796 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -1803,6 +1804,15 @@ int syscall_trace_enter(struct pt_regs *regs) return NO_SYSCALL; } + /* + * 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 NO_SYSCALL; + } + /* Do the secure computing after ptrace; failures should be fast. */ if (secure_computing() == -1) return NO_SYSCALL; diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index a8184cad8890..e3a82b75e39d 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -911,6 +912,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 | \ + _TIF_MTE_ASYNC_FAULT) + asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags) { @@ -921,6 +927,8 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, */ trace_hardirqs_off(); + task_isolation_before_pending_work_check(); + do { /* Check valid user FS if needed */ addr_limit_user_check(); @@ -956,7 +964,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 18e9727d3f64..4401eac4710c 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -890,6 +891,8 @@ static void do_handle_IPI(int ipinr) { unsigned int cpu = smp_processor_id(); + task_isolation_kernel_enter(); + if ((unsigned)ipinr < NR_IPI) trace_ipi_entry_rcuidle(ipi_types[ipinr]); From patchwork Mon Nov 23 17:58:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 330977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 531C1C64E69 for ; Mon, 23 Nov 2020 17:59:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06ACF2075A for ; Mon, 23 Nov 2020 17:59:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="BbhyOL8b"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="lOcVajST" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390556AbgKWR7C (ORCPT ); Mon, 23 Nov 2020 12:59:02 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:19450 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726817AbgKWR7A (ORCPT ); Mon, 23 Nov 2020 12:59:00 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0ANHsiJi021464; Mon, 23 Nov 2020 09:58:27 -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=pfpt0220; bh=XdATJSpoCgQBdRF9UUyxPd2r0o++/lQNfaFSdjxtaio=; b=BbhyOL8bI+qLInsoDEBV4Gh2RhZE6I8nG5iic6BNhBrnGPfKcxlQe2+321PeHialYBFJ kUSmTq57XTlmMVdpUX2l/efei25QJjeueQb/zL5GD8SCtmnu3cpwHXYeQxndVtBxTb52 eGtKS8fCDh0q1nZ/41pn0OdZKUEXcSsMMl4QC4gaAvW2auanEBxTBntAaS0KfCb/Fk9p h0TZsRflp4CGw6qCbt0r16DL6P7dAUO8TzURXtNddraB9JIgf6n/1uDVLCYiC47Snfpy uUwsUi4KntTr4tJtDDKwU5cVU/bS7AfS55pdEB+DnaJzuaENul09lbsmSgVikOAXQCtK 5A== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 34y39r6dnj-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 23 Nov 2020 09:58:26 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 09:58:25 -0800 Received: from SC-EXCH03.marvell.com (10.93.176.83) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 09:58:24 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.169) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Mon, 23 Nov 2020 09:58:23 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CuAxJmgA65qMso3rrvrDr1n7+75yRPhkcvaQcSRGedTTNl7GJAbcrpw+j8IPtwEzh8tdf8Raqt0l6h0gCEmHV2Dqa+JxTSa0zMkt4taqeFNFqnO63VR5YjdP5icdbfL+muK6L/e4JIvmLFBSvit3vhHgALd/g4dGzDpVtvisvUZyb91J7L2OKDa9ZCOdI0admNZYPvjtCqxyWtlbDHV2Jev/bqdKx0wof/RbFe4lxrLiopGcFxLwL0DYEFAmLmZHXLAov67aKuYJcjFYKPtNoXY9tup0Ku2aen/j0fWrLvGQZOKA7Ne7zMPcqdUhQ1Wd397nrCPPkMjLfX2hQexIFg== 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=XdATJSpoCgQBdRF9UUyxPd2r0o++/lQNfaFSdjxtaio=; b=UcTgJSBwF3lXkz0NVHtkLVcAzm0DcLgojBQABjldmeHZc2bRZ1lxxvIOVJz82vkcecdO9VQk4OjZf3h3eoUlVgODc/EWCFkY6U9OjYQSQfjbQ4oh5OzP3X49UAoCCR4GTerM9/Gn9VyFbzRacyowPMPxrsxqwsR4ONNIZqHzDgFcvwQlZTO81bCS0N8PKnrdsWLGGmjzJ/UvDdbaQAgL1b9K5Sj0gO6XFBQFJCZYLdL6+nIy5Asbg9dJslOnL5h8nO/pJH3U6Nf75QyhqhjXncLlvzqUG36ym69NF1WPG1LPEUbqIgde20Y/0s9xvzs7LxijowcEMaSWYM/LvuxDVw== 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=XdATJSpoCgQBdRF9UUyxPd2r0o++/lQNfaFSdjxtaio=; b=lOcVajSTeCkc/woZt0aYFJn7FrBX8L2sRFdlA3vSfEVojjWk/gAt1nr7TsbAsR1VSw3t/cOPkBIv3RKyXuy9gxle9NANEzrve3nm5DhWhQ+c4MrsUvuewNje284afdL/iJ4BTka5KuMIo8U4Etw6j07oBFXDREftlmVnziGRKg8= Received: from MW2PR18MB2267.namprd18.prod.outlook.com (2603:10b6:907:3::11) by MW3PR18MB3530.namprd18.prod.outlook.com (2603:10b6:303:55::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.22; Mon, 23 Nov 2020 17:58:22 +0000 Received: from MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703]) by MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703%4]) with mapi id 15.20.3564.039; Mon, 23 Nov 2020 17:58:23 +0000 From: Alex Belits To: "nitesh@redhat.com" , "frederic@kernel.org" CC: Prasun Kapoor , "linux-api@vger.kernel.org" , "davem@davemloft.net" , "trix@redhat.com" , "mingo@kernel.org" , "catalin.marinas@arm.com" , "rostedt@goodmis.org" , "linux-kernel@vger.kernel.org" , "peterx@redhat.com" , "tglx@linutronix.de" , "linux-arch@vger.kernel.org" , "mtosatti@redhat.com" , "will@kernel.org" , "peterz@infradead.org" , "leon@sidebranch.com" , "linux-arm-kernel@lists.infradead.org" , "pauld@redhat.com" , "netdev@vger.kernel.org" Subject: [PATCH v5 7/9] task_isolation: don't interrupt CPUs with tick_nohz_full_kick_cpu() Thread-Topic: [PATCH v5 7/9] task_isolation: don't interrupt CPUs with tick_nohz_full_kick_cpu() Thread-Index: AQHWwcI7UCf8Z8jL1UuRW32Ea/eUhA== Date: Mon, 23 Nov 2020 17:58:22 +0000 Message-ID: <76ed0b222d2f16fb5aebd144ac0222a7f3b87fa1.camel@marvell.com> References: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> In-Reply-To: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=marvell.com; x-originating-ip: [173.228.7.197] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: cea56759-e00c-492c-c81a-08d88fd95e8f x-ms-traffictypediagnostic: MW3PR18MB3530: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4502; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: bLDrjD+9lnjmxV9F+EySYhTlotHp0FjHcIrUjdVoLAAQB42DwvoeHFRaze9tSdD9xhLp6rrPvcOB3gfcpBLiT6/FzHK/Gy3OcyBHqDtg/0rlusiRnAkWp5msAAors4tcvLB5rlAVta1bsYvtgjAPpCkGmW4j2AFWzwZpIK/4auTBrCEwg2wGf7imgb+LlQMtGG1xvRSmcOgheJPx4rArZeVqMWg8hzA4bHpJ/LEu4oUcScONx0oFG4RfxChgZXVVugMFcYajRWbQ4y23MWqd58rYdpZS+awTylWWLq4e1Ot2oWLt76QR6GAoN6l/HibttQFndlK7CgeSRYoIq/UugQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW2PR18MB2267.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(346002)(376002)(39860400002)(136003)(396003)(2906002)(2616005)(71200400001)(5660300002)(6512007)(83380400001)(110136005)(26005)(54906003)(6486002)(186003)(6506007)(36756003)(66946007)(8676002)(316002)(478600001)(8936002)(86362001)(7416002)(66476007)(66556008)(64756008)(66446008)(91956017)(76116006)(4744005)(4326008); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: KG7oxR91hDBvUIpN/2hA7AWWFm21HMzpjBYEyEtwZ0Hn2AfNKwSwP230FCAD3dhUmRlpTtRUWy7hjBVi03wmPPo3l+F2xa16XqLnQkCroM9l23UbsrBZbC3myP12inA5SvdpNk2SFXPJpfkXMlX4GDZF2cxsLw0Ohv7ObMkkK9wMkkIx+HmKI3E46vhQGwKYgURyzxRCo5zNS4DmjKqs4WjtkORl/049IMVWfd1GjEDe2IqA0RV3JCvq4kLwUr+3O4FpCwjww4HWsAxCIcmaRHF+ife8+ROpi7+0JHbwb3NyGtZjV2zonoqJdSZ3pheggfRdFXulX91fgpraB94Ms/J6AOuwriZrISpooNG24MELYjh2fWowg4bUxiWC6G33VqcEp59y7ajuj/UmoeQ1PFuZsWTzy9U0GVHDpVA7O8XEvt5C3zja7wDRobQYhistVdYhIArC7O8DWZzq8fZ/fKKniCxC0K6PudyE73s34eHDBjvyKYTBrUQTPSJYaGlWfserIDxtfbz9VnGtPL1QiNHURD+lVU6QvkXbdjAqvNDxmBhMJa9Rla8UrPMTIPasJeAlDl1ssh15gJJYRqxXvtkOZjIpvs06buQHmS2LcJudkvo3NxbgzDC3CKUSXFpoXR/tFIucg7lcb3MeJp8d9iBZ8uLM6V8tIddqkErrC3G4d8pRNaAlrhzSCl4wSaBDKhCs2VpdWNNZYkKa8epYMHWBzSLCXQ37hYHjci2BA8q6iIsUkLccjmT8DebECsSrkE/c7dsCeyfE/SGQ3RlEBhVnIfZvTWX6HlxFXC+7YfG0i+wIbrGoIdzqsy0AcuFTpcTlEL6Nn4+JXd5bYjd890or7iVzLIzyyf6gq2x/kk4MHY6775rf/Q4EenIQJcuBnOJPuaFr52O4pCrIm7bCcw== Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW2PR18MB2267.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cea56759-e00c-492c-c81a-08d88fd95e8f X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Nov 2020 17:58:22.8372 (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: zDAfApfUXSDuufDXRJM2KfzvBkMCj8DhqrMEZsiXfnjqCpS/9SI3IthFoAh3bRarU9naR263bnE32olvyY5aug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR18MB3530 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-23_17:2020-11-23,2020-11-23 signatures=0 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index a213952541db..6c8679e200f0 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -268,7 +269,8 @@ static void tick_nohz_full_kick(void) */ void tick_nohz_full_kick_cpu(int cpu) { - if (!tick_nohz_full_cpu(cpu)) + smp_rmb(); + 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 Mon Nov 23 17:58:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 331967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B09AC6379D for ; Mon, 23 Nov 2020 18:00:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6D6020758 for ; Mon, 23 Nov 2020 18:00:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="HcUYG0LE"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="PDnprjLv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390588AbgKWR7V (ORCPT ); Mon, 23 Nov 2020 12:59:21 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:46840 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390562AbgKWR7T (ORCPT ); Mon, 23 Nov 2020 12:59:19 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0ANHsitC021505; Mon, 23 Nov 2020 09:58: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=pfpt0220; bh=6sfi8us8khBcVaHLEcbGHrXGjcwBkTMGdxvJ+kVM7BE=; b=HcUYG0LEmGg7MdhLhn5gPrfw+jdPyuE7nJfKJgI7WA1q21mO17ZYUCCi6B9J+/Iyuqxn ILolWu21oJpWRX3dCh//BgjtJmPih8LwnVL/xCH+NFXMF/EG+DxSdxx9GjmBfZURsY0z jeje72ijdXZesOSNFY7YZKajlup9W+7R0tVO+cHV7sL995XZfYfgU3lUS9cGq+1aLmdo IJ6AklFV99CYdjqA/3kDiG5TFpvCrtEcyYpNLn1b7I3YzkUYDVQWu5mxSW+QaxMbusMx IaBLuFBAPNklT8KTBqHdtwNzYTAtfYpGDUwodgdYz/BMCIiRYeA2TPMkZxjCyAioLIX2 9g== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 34y39r6dph-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 23 Nov 2020 09:58:38 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 09:58:37 -0800 Received: from SC-EXCH03.marvell.com (10.93.176.83) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 09:58:36 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.173) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Mon, 23 Nov 2020 09:58:35 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=STmRXFTjxsFnD8u8HCEy3tmAg0pz6I7ny2jVLBrZESd9bSnFSHtCk2BrpTYI7TrNrf8kwc1aIctsulSrJnktqqfJSDN2/lkJFvWi9riEHWrOuszvP0G5XrfMm49tfiJRbrHOogK+zCj8GnSGwsLNu3HgYAZOYe+nvOQIigBSArzcCRRjhPxPEUkx5XTkf9JQCa8E7ZoNANOn1+UcLN/lFobFZn07RvMbwkrppz3SYSMAQ7UCj/WB6IZaA8qGZ5WE3pWuNLjVjpNaJ27+rH3WB3Lbt64wMWNe6ZaAOkxuSf+1RVr9R3pgIwvT4BvrClzpiQzmo8CQmrPPJlBOus2YTA== 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=6sfi8us8khBcVaHLEcbGHrXGjcwBkTMGdxvJ+kVM7BE=; b=n6hP9jhmEdvaJRPYI7gRhy9yicR+YZDoBqzZLQfWmDvVP0cJ99uAXlNPNlVDrEKBrJjKchRQ/XN5aJJEsBFqWapSMuGY0rv9l8j1Q114wS8lG716LZfs6IrIoCuw/0rFeyaiimdI/dUUTJ/zWTUUU92C0SNN5ZW6TmawIoQ4272TB/7zfKScfY7xzKEigDjFIFRzL9QmPuMxIcl7qJHkjHh8t7Eqc0oPfigLNvhhh7A29BmAMaf4ztLB44RA9sy7aL3hzw5kfTC/7Ex6yrI1+8NdA+A7Zcsn1aLXB4iycYQKvFIXI3vxc5fj2PyoXQbzVMpq8eGtAL5EozCNGGFunw== 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=6sfi8us8khBcVaHLEcbGHrXGjcwBkTMGdxvJ+kVM7BE=; b=PDnprjLvAq/9DlCxJb5IcpuQAQzMy9Duzr6UAV+nKKCKXo9F99QkQOwCxpGzmJ6ZTA899bogCszARhtgLrN3ew571xvqposqUE/wEA3tTWt89LC3uTnm3jXS2QF8NIc1iklM4Be3nV4/KbNz3KwmlQLDtW55/EYe6d781INK+4g= Received: from MW2PR18MB2267.namprd18.prod.outlook.com (2603:10b6:907:3::11) by MW3PR18MB3530.namprd18.prod.outlook.com (2603:10b6:303:55::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.22; Mon, 23 Nov 2020 17:58:34 +0000 Received: from MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703]) by MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703%4]) with mapi id 15.20.3564.039; Mon, 23 Nov 2020 17:58:34 +0000 From: Alex Belits To: "nitesh@redhat.com" , "frederic@kernel.org" CC: Prasun Kapoor , "linux-api@vger.kernel.org" , "davem@davemloft.net" , "trix@redhat.com" , "mingo@kernel.org" , "catalin.marinas@arm.com" , "rostedt@goodmis.org" , "linux-kernel@vger.kernel.org" , "peterx@redhat.com" , "tglx@linutronix.de" , "linux-arch@vger.kernel.org" , "mtosatti@redhat.com" , "will@kernel.org" , "peterz@infradead.org" , "leon@sidebranch.com" , "linux-arm-kernel@lists.infradead.org" , "pauld@redhat.com" , "netdev@vger.kernel.org" Subject: [PATCH v5 8/9] task_isolation: ringbuffer: don't interrupt CPUs running isolated tasks on buffer resize Thread-Topic: [PATCH v5 8/9] task_isolation: ringbuffer: don't interrupt CPUs running isolated tasks on buffer resize Thread-Index: AQHWwcJCaZAYvgqyU0uLj2p5N5OAJA== Date: Mon, 23 Nov 2020 17:58:34 +0000 Message-ID: References: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> In-Reply-To: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=marvell.com; x-originating-ip: [173.228.7.197] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0ea533cc-7124-4083-3063-08d88fd965a1 x-ms-traffictypediagnostic: MW3PR18MB3530: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ltrLKCokWctmzGqeKU3Dhh8h22z5mBJzfk6nVTXlGS8z3Yek8fIf+hTdLD6vPwzTRj+172kH/Y+TPmp99CpN01T7I2KEweM4bOLYZFBCQrEn6wS4MVLPgqgCTfr3GCmNAyhB+e+WDte5rmhydS9jJeX2mI2SvP6+ceXLtkz+0upo9xID/I69u0PmasiyG+id7AVuwRnC00dyBEZgNNNRVdso38B0gbYy7quueqdXdQexuKdFBFMocfniBGPWvITnx80MLCh1UukjZeHKLf9ZT+G+D4OSZf/iGElLN0n41L1zybZH1EQapyCSW9tLpucvxbZ9t5Gxr4xjHbDMF2w0jw== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW2PR18MB2267.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(346002)(376002)(39860400002)(136003)(396003)(2906002)(2616005)(71200400001)(5660300002)(6512007)(83380400001)(110136005)(26005)(54906003)(6486002)(186003)(6506007)(36756003)(66946007)(8676002)(316002)(478600001)(8936002)(86362001)(7416002)(66476007)(66556008)(64756008)(66446008)(91956017)(76116006)(4326008); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: ZlO9Y1FX87Fky2QnkKBlk6HdmUqs+cTdJ3gFccetqIaZcOM/DouXCSwrrsrpncpwA0rsfjxgna4MnKaXkoLE4x4t590yCErrIqbP1Bwa4slLzSmId4Zsc2uOtEZdsjlZ5G1VzHgbl44tID8V3oG3g3pWeIxT3346bwrsD8ZVholJyZgWPStMhKJ+8bJL3ZesmGBMBZ3iwrwuUkOgcjttlH16LVKsF5y8de4Hu8iqJ2U+lv5EphDqYDzoFxyDiftZRRHUy1iWVW0rdVjVeXWmAIiV/qS79B2ZyVtJzjn7k5CiSvAnuaEVJmz4QnDopc+/nGprhY4Ygl/UPswgK17PpRIvbv2yyR0WrJzyEckZpFIZKYnjHzYKzd4JBqe7x4QOxOwFLCFBb8uLYkuBLZPT6OzdYkkg5sJ0iebAiNKtrKdYSW2hMey/6brzRbQnAHyUVmMqy+lMOnDquaZIgmNNkYWe4MzHQQcy/3yh1FbcRmTpgcfberkdTof18Ilb+w35CeSn9BbJnrxjxfBeUkmoLKpcnWwZQCNbz2UfnjkSPtGeAL0Ef/NA5OWc3/cXdNMdZPV0n+4pEiB4DueETNyJoqhGK/XeG4tXLVmiFIJdtIbw94S5B0+gxvh91INWUMU5HwKZhzOUqZ9RQd3m4FsxFDZSJhp832WgoTrdz9s8r0zFUflrz0I08EWHExPDd32xDAFvAr6R9PnxdNlratTfJA6b+yFmieoS1f7GwL75d0PfenFjztKdaYROH6XpOgKy346XFexPbHKzCH5D+95ed/9bYViqkxs6nZBg6nPOtFBKaJbMppSqKRsiUlv5nqSmZorQmQe0rF9XEd8OEUY27imoldJkvyfsiNrwN16ua1VdiW8sKsScufLtTI37Kl9gbWvO9id418Twf1njOaSazQ== Content-ID: <79CB53C96CF18B418B712DFEDA3F74B1@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW2PR18MB2267.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ea533cc-7124-4083-3063-08d88fd965a1 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Nov 2020 17:58:34.6903 (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: DLwRSqj8L0DPkKrUz7rkl/wZBvMJoC4tkggCKOQfSP8Ut4BW27alTAxLq6ubKqD9U//VvRtazEj7CaXWp1pNmg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR18MB3530 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-23_17:2020-11-23,2020-11-23 signatures=0 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 | 63 ++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 6 deletions(-) -- 2.20.1 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index dc83b3fa9fe7..9e4fb3ed2af0 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -1939,6 +1940,38 @@ 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; + + smp_rmb(); + 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. @@ -2028,13 +2061,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); } } @@ -2083,13 +2125,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 Mon Nov 23 17:58:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Belits X-Patchwork-Id: 331968 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C454C63697 for ; Mon, 23 Nov 2020 17:59:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02E3E20758 for ; Mon, 23 Nov 2020 17:59:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="N32Zmxq9"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="VGv332Uy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390572AbgKWR7P (ORCPT ); Mon, 23 Nov 2020 12:59:15 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:48446 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390562AbgKWR7O (ORCPT ); Mon, 23 Nov 2020 12:59:14 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0ANHteX0032523; Mon, 23 Nov 2020 09:58:45 -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=pfpt0220; bh=BVwqlvoPhM/wuTJr+wxw3IWTjQZ6NEVvb6vvs5Ie2Bg=; b=N32Zmxq9JvqrpfyYB8MHByGZ4/L6QqGNOP5CBth2Q5qa7HuRQLv0kDwLRK8evwMv2xUP rlW4Hc+nfM2IFPQmrx1tDJ3z0XHpsLeQXd1m8LDE0wITRHqw8NFD5YBeKbQDDuj1RSKA V8RuBy+EjOP+GzhB7aVEJD9Gr9r648cof1Hs626ivR3nGm70mCEF+SkpM7RgVEdWCPNq 5tju0/KEcEeza/KcOLhMT/Hk5kdFYltpzCz6/qupQRM4PapGhXbv7fllXggHrDTm7pR8 daxtmW82PJhXA81nziWYPshkYbqX8hWq7a01bAuqNLdDG/HyxKFnsGUFj0T/U8uO4DOg hw== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 34y14u6u44-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 23 Nov 2020 09:58:44 -0800 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Nov 2020 09:58:43 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.103) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Mon, 23 Nov 2020 09:58:43 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RxZSWSVGuWLFMz6+Cc3wuEy93bPj4j123CHEp+hNDhnUnj4GaMEWpcxJwSa3n+wdWX7qdSDzF6+g8/exvJN2m+Zn8qAdEcOmKVVJuwZ0TeUzf6YeZUs5//JVxtZpyHcpM2f7Hf9PqyWI/faERK0tG5C0IRDwczdg7IfaTJJ4dUnwfVp2bvrTdlzEdiIfUYlTVjedfIWT8NEbhShOFJcqfl2n6Ya+4BGpGBcMrJ92VdPl73b1Q4amwdcDZU9odgFXiYWo0QgqOXWQUDeJuQC2FKEGWycTn308sVbAi3jMy2bIT3ho0vDJfy91Hzu6bmbURT2b/8Evme7UvGBXcQSW3w== 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=BVwqlvoPhM/wuTJr+wxw3IWTjQZ6NEVvb6vvs5Ie2Bg=; b=jS4LmarhlpJ0Ui9dTOM/7LOnwqq+x16N3jiDGwpsU/KXA7FeBusE9lhw4om5dy5zDmHnf497wATJFEiivw/mgVH6T5RK39p8CXe9hhokAu2tc2SPh1i7ys+U9o9yDBUt73g6OY6tUylAF3c3Y2mQCAiT74ytJpU9KJFQoqP4LH26mOLpH6Z6LPnMrQnQU69S9LtoyeB6T1VA2XfiM4xSkIVnsPCVJx/iJ6ZCY/wdk8kYqevD+Idz/CExyDy1GC7/XycuFnz0N6HNsD5Jmd4OrTKeVj4202edAWJIGTeTFM3pcVSI1u/jdkTN/q3TDduPoVNponJ0XzZieSouYE5ynQ== 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=BVwqlvoPhM/wuTJr+wxw3IWTjQZ6NEVvb6vvs5Ie2Bg=; b=VGv332Uysji/q4eXDp6SF02OLtuenqj7Yj4QkcJypepdZdrIVkTtMxSPTLZTqWHueyw9Ef3/W0D3MA1F8OXSM9I1dReKKKmqFaRzyXI5FaxZtjKSQKXQyTOMGVmt2JvTZZ3Y7LIen89ZSq9mXSDsgssxrXNHLaEIMPXRyRcpSAk= Received: from MW2PR18MB2267.namprd18.prod.outlook.com (2603:10b6:907:3::11) by CO6PR18MB3954.namprd18.prod.outlook.com (2603:10b6:5:34d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.22; Mon, 23 Nov 2020 17:58:43 +0000 Received: from MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703]) by MW2PR18MB2267.namprd18.prod.outlook.com ([fe80::e17f:37fb:4eb3:c703%4]) with mapi id 15.20.3564.039; Mon, 23 Nov 2020 17:58:43 +0000 From: Alex Belits To: "nitesh@redhat.com" , "frederic@kernel.org" CC: Prasun Kapoor , "linux-api@vger.kernel.org" , "davem@davemloft.net" , "trix@redhat.com" , "mingo@kernel.org" , "catalin.marinas@arm.com" , "rostedt@goodmis.org" , "linux-kernel@vger.kernel.org" , "peterx@redhat.com" , "tglx@linutronix.de" , "linux-arch@vger.kernel.org" , "mtosatti@redhat.com" , "will@kernel.org" , "peterz@infradead.org" , "leon@sidebranch.com" , "linux-arm-kernel@lists.infradead.org" , "pauld@redhat.com" , "netdev@vger.kernel.org" Subject: [PATCH v5 9/9] task_isolation: kick_all_cpus_sync: don't kick isolated cpus Thread-Topic: [PATCH v5 9/9] task_isolation: kick_all_cpus_sync: don't kick isolated cpus Thread-Index: AQHWwcJHihlNClCxdEOODDjRi5wCaA== Date: Mon, 23 Nov 2020 17:58:42 +0000 Message-ID: <3236b13f42679031960c5605be20664e90e75223.camel@marvell.com> References: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> In-Reply-To: <8d887e59ca713726f4fcb25a316e1e932b02823e.camel@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=marvell.com; x-originating-ip: [173.228.7.197] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7614d635-248f-4799-17b3-08d88fd96a81 x-ms-traffictypediagnostic: CO6PR18MB3954: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:873; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: qER3sfnTTuDLLWWCARVG9rtl20GVKOxey6n1X/MREWonKNi2lKgmuan4dgsjilqAU2W/s1G5zlZhI9vIsACUq5d9njWfVYvk4lsy5mZyJ4ZvqMVbF5KBQ/PjklVkZFLuxiYLeH+qxsTZqMol8puOgbW9fp6TBEmrNkUSPD5j5W2zPoRcJvkP3pE6dFPkSCIwumiu6+vlH8ia+e4Qoc6EOTkKU/Rk2hMJceekVnNlb/lyI3a6FoBLSet01xwmB7nP2qJbLiTpKzAMJf8xsB/FWhhyf6ON+HPBM8PWu0sDO1Nzil3ZPYoE4EBhJJ5aTxArVgJyw4l9VJkV/jH/+YjPJQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW2PR18MB2267.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(136003)(376002)(366004)(396003)(39860400002)(2906002)(6506007)(6512007)(64756008)(8676002)(66476007)(66446008)(66556008)(7416002)(6486002)(4326008)(8936002)(71200400001)(26005)(36756003)(2616005)(478600001)(54906003)(66946007)(4744005)(86362001)(5660300002)(316002)(76116006)(83380400001)(91956017)(186003)(110136005); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: Uc++Q0zDoBBqFLkK/WIrBjb+jFlP7IHh/ZFMeGfIsegwpj1hQw/8gYS6hFc46iD9x7YqDPlnwppEm3LPAM+GzAYFf0qmQTSWJ1kqmLJ0yx8EZlyaRjWFwCO2NyCbhpOczuznUba8pY35TtZoG7a9K1Q9cvyTl85DQvmJrdyQkbfnOwOusHyoAitCX+eyac1WhLIKRgwKt/CT6xEPNQnc/QDScz7xqhbgkYLWrkcIx0s5CkQIQfarkUu9oh8ubMCO/g+iuZOeL1+niGZIoHgE6sxMroaRjEaOdO8EoOJK0F/crFFoXco89Yic/cgDva6q1bJZb4onS9G3PRpvDyY01c/kQ7n/cHak9r7Cvqz5th4F7gTuABRaPnOUix31QL3EikbLiRdXsDKMC8EC0JVoCgWdO2SWpUM52aKksT8mOTANc+JyY7XkXqZydIgFb7imwFXffQzrt7/y8q1nZm7NETLbVROH7OeIhu+n4JMQCpqBOBE9IKixO26qtkVEVQ/J4Tb8I8VaTMRt2hqUbI22UGJMd/nB1kJibNX88LfXFbJrlJUMaLsYDKH3M28wlTQJU8YbzloRQ/E5UkV+WYGh0x2C3zVy+MzJs36BMMOigHPdOu5wMowV4ePiFyWbdYXAATOj7hIHl1ikB7VHnqCuE8pHAQeLLxxd0oVGQwxhdgnPwb18iPs71h4hp9NycuUoOLClTIw9U1IxenMv37sPAfupFc0jBlgSveSQBD3132HOrZIFnJiX0L76P4UivkU1vrHfbgqLGkmQf9W+MtAXUw6EGi8JXkZPbABGge9NZ1jTLViTQYJirn5uTbYYmdR0TadKNh/1Rp9MHHZQUNdeDnxSwwSO5GD9JO5swljSwyjWlAeBRCB2N2PtT/3DlivpfcNp37f8xV2N2DMiBXWzzg== Content-ID: <2AE8B164648E7447927CA17247F364CF@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW2PR18MB2267.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7614d635-248f-4799-17b3-08d88fd96a81 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Nov 2020 17:58:42.8436 (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: Qa2HetpZ00P+IutNvahZVG3iVBoBzCW4xalzAM/nlurAGq0rR7BbT/tS3MyRKsjrKePHL+JTz8VEiRYczmv0uQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR18MB3954 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-23_17:2020-11-23,2020-11-23 signatures=0 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(-) -- 2.20.1 diff --git a/kernel/smp.c b/kernel/smp.c index 4d17501433be..b2faecf58ed0 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -932,9 +932,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);