From nobody Sun Jun 28 08:41:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AB8EC433EF for ; Wed, 9 Feb 2022 23:31:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230235AbiBIXa4 (ORCPT ); Wed, 9 Feb 2022 18:30:56 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:52626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229777AbiBIXaR (ORCPT ); Wed, 9 Feb 2022 18:30:17 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C36B9E05111C for ; Wed, 9 Feb 2022 15:30:18 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 219KYQ2U020178; Wed, 9 Feb 2022 23:29:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=vikfQxERUFBfKJD8ex3HEUPJE9sExSR4JsWfRTsN1EE=; b=Vybrh8Pb1UR/86Y/B+VvX4KrDgXjXWkfifmNfmLuzMca5DypTU0ethcTq4YmKlJRThve H6Up7qL9EoVA0f/B7c1ifsHT9rfyh/jheuw4n50JP63mr5gm94KwrxgtewpQHSkSfpT0 7FQbLx9l1a0NoUzU5pnrp8KORQRYSmn+6j0Babqs0NDJGuQ2zq8hIXRlP5CeS3+YFAeB fXE8LZIiAa7ylYkl099yZJhCyh7SHLP1BjJ0hcFAMeDZkUQNtSEkWIU+GXRP1FJURRa1 f5CsZ9tzsWyEyYqTaEMuqDShMVDv1dLyDCkcZsfGSC+W4grp17htd4ye/L9CxsfpDRqI BQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e366wyd42-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:54 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 219NFrFV117827; Wed, 9 Feb 2022 23:29:53 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2170.outbound.protection.outlook.com [104.47.73.170]) by userp3030.oracle.com with ESMTP id 3e1ec3m196-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QMfZaNDXAtZ7cta5xEaMVzsZUkrsZtulVoKDPoc/EObbaBc+HA6zmHwxfzKZC4kobwvO/eYn0Lb1bx58UgV3qVB43wuKkFerCZaFSL4O/MS2ZP00mTDzlCHUR3Nyv6U9NEt4x1zcMTA1kUashaaww8tEP0HBTyWNGT0MIkAlJJiKmBBSBx9H3nmsZbW0xW7tG/LePpmllaQDSIPxowa21YjgtTGyYdVOunYBYj4vrkMJMF4I8fZQN5SFkrd4fjqy+qjwxi2DEm7CLyU7nR81iFAl2EwGYujRF/ikT2CGtWuc1r0++mCK+pvfG+x1LhZoCdmT3pj3I9p4jqMk2GQynA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vikfQxERUFBfKJD8ex3HEUPJE9sExSR4JsWfRTsN1EE=; b=SV2wUoiLSF9zuSc6u1AEQz6COBRU/w21wIv5ryXGeApgHJUEsCqEpvgd0LAKU154xbEl22a3Gk8O1jkAU4xcOcsorOggaDaLhotOMUbvg/ogsLZc3bX4jYriZp+WVmjPSydwUNB1QuqGhrppxcZmaCGmpKygmjsceztAtkPDHPD5z7XrHHAKSVVmLvbVE51iIlyowHgmhcfq1aZd7JQX7OJ2YtC0hfNRHy5zDfR7kvoOSYF3eMt8rKo4vXppXKcOgCPqLG8GEJwYb/pmPQ25c7L1rgEQjXKkujUjXJMTWSga5DWMgLxYv/Q24WRin+JsGgHq6ttnvWp5Gg+6VQWHBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vikfQxERUFBfKJD8ex3HEUPJE9sExSR4JsWfRTsN1EE=; b=Ta+fkgrgExdBNITIP7H1tvynpEid0WTPRD2CWW3I40ExWox90Tr7cB0tbkNIhjsbpmcp03ZzRLzkLimhdawAjaZj6zWUHvLtoqvmwcT5xXMLSVIQIPIRzXxxi7McSBdTqochkIndxL/vKsbfZ5MHm1QmhEAnuvDLej7exZ8Mr/8= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by SN6PR10MB3007.namprd10.prod.outlook.com (2603:10b6:805:d9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Wed, 9 Feb 2022 23:29:50 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5%5]) with mapi id 15.20.4951.019; Wed, 9 Feb 2022 23:29:50 +0000 From: Mike Christie To: geert@linux-m68k.org, hdanton@sina.com, hch@infradead.org, stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org, christian.brauner@ubuntu.com, axboe@kernel.dk, ebiederm@xmission.com, linux-kernel@vger.kernel.org Cc: Mike Christie , Christoph Hellwig Subject: [PATCH V8 1/8] fork: Make IO worker options flag based Date: Wed, 9 Feb 2022 17:29:32 -0600 Message-Id: <20220209232939.9169-2-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209232939.9169-1-michael.christie@oracle.com> References: <20220209232939.9169-1-michael.christie@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR03CA0043.namprd03.prod.outlook.com (2603:10b6:610:b3::18) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2ae3ee28-9f43-4827-d071-08d9ec2410ee X-MS-TrafficTypeDiagnostic: SN6PR10MB3007:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2512; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NyWI2VyLKvizM9pDoeT6sfxvVijMwfp4kdoY+9g2YZntgRFjTnrJIfrdr3mHwCAbUc9dRoD9dv2PhFX/upvwWS3I5vFXVpE4sile57GJlcY9yYCzWn7jX+IFDEF8IhbYMQW2UPikgRWJW20NuLpejiXYBJBBaXxjA8/Jg2HzyUjdIgpJ8Vwes/DUa+FRkLyfIq2dC5JauAjwvtEXhc4sJ7uKqMsDTL/4Kyk201WVxnzZn8FcG41sccxmQcv4CZDkGyDQh49W3hKXW6RT08CUu6IY+1h3WghPUSssQMx/ZP3NnLR2+4Zs1ztBVSY3TKiWyFnijdg1/NBm3JHoF/6ZW2LF2uwNF0TNnWQt6tN++Jc0eCum2fPxfMh5IgYDarl3kkR33gcNb3+gKSsPVtxGIR+b1ELaFB+LDYngqRFEQj90pVtsVunHGTo71XlB1G2WDcOfNrEDkgTYceRKO5YlmrQ015p/0DAj1CIOn2Oa14S/EGZvlc1kNiVY9DO45AlfjDiNrBx49+DQMi1suBqatlVEz7YcJO2IZK9fFWMqxJaPvMVYwCE+5tRFuGYK8kvcHNNaQ+OyPgLVlY565vsbf4YQ0UZ0Z0QZmtqRSDUfNEIHOrdbvVxzLhqLPah1PzAtLKHFsvP0m9M2w+PUchdezD72LBkAPUHmo4weSVZMMZ/VWD734f+T8vCSRscMklHZX/0pqeVqtDQ6j56AE/drjTsjwSABCfrCRk8CURIQmpA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR10MB1466.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(921005)(86362001)(508600001)(2616005)(1076003)(2906002)(36756003)(26005)(186003)(83380400001)(6486002)(6506007)(8936002)(52116002)(38350700002)(38100700002)(54906003)(66476007)(66556008)(66946007)(4326008)(8676002)(7416002)(6666004)(5660300002)(316002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?IGnonroSM85zyIpPZHCDIe6km2bD+8OOuOCNKfCc8A3Bkj+y4BvX2iPnx53p?= =?us-ascii?Q?6SBuxZrvCcXYLGpUSAWOUsJUtzy7YTktebIcCVdJWOCC2X8hOLBkrFCx/4Xw?= =?us-ascii?Q?TIDQcTl08gj0XpXiV78s7VXdNpPzab0JLHlUgMwLTv69HqRvklYz7a0gp+iX?= =?us-ascii?Q?sgBMmhnu4cwJxEeQ9ioko+9DJS9/LRc5tgGuF3vgxvkFbRZoY7mHg3HVkYcU?= =?us-ascii?Q?U3IlSmFLmSnP9AeIiX/PR/B5cZ1M+Ha7NxooJYG0FkCZ2Y1ums9uJE9k4d45?= =?us-ascii?Q?J2WMUSwTkix9qb5/hu0UKJTrrbnC5cfhU3yULN84z4nzWrKUQ5WQ6A5uoTR5?= =?us-ascii?Q?6kQ+NDtfPJ31rFy/S1jXVHakKNs+tZt3sp8VshkQMPlnryHB6ANdMmfkRrr6?= =?us-ascii?Q?vFADWRhg0CxTZ3OuKX0vkuWCxCERaALZqp/nvd1HD50N/NS8apoms1taxZ0f?= =?us-ascii?Q?XZ1Qmeu6xsfVVBen7XHgAuNWeMlDYM8vEff5KIk6YJ5gTnTSzHHlYe6CY3xX?= =?us-ascii?Q?wMEJBLgMN8JCg6hsRKDH/KiJHKu+MPv5ilUCqfInB6dXMDJ98RGKvw/I9YHc?= =?us-ascii?Q?OFCHFK9voqxQoWsMpP9bIUqG93vR4ZpjCYfaNqYijViSYVxqC1s3neowYuNp?= =?us-ascii?Q?mTXpPLcDXajEc0uR5AMTaNKW073hICmhQijo1KMI3id+prgZnzLn3syGbpoh?= =?us-ascii?Q?y8YgLFxIm2lUlVJilD7NiobGXlCFjgN8CF8X21RD+e9yzUblXrlcsZIWPI74?= =?us-ascii?Q?fgkdFrb4KETys1zaK5ZL74YAkLuJvWJkBO8nbBctuKfkHXNtUzcBK81jhVZA?= =?us-ascii?Q?Ej/a8KwxOA96QZBl9oSw6JVAafg3vPQ1twj8LzsrAjr4Pf0BiV2UjJxWf3ze?= =?us-ascii?Q?VPlyzjJRKbOZa2PSKa7mtwyJ63hMP2ONSkOXbtyA4BKsJ/+IUjRpKwxChdft?= =?us-ascii?Q?114+5rQvQa3dhs6hvwW5wChMrSOHMMPxIBLtOTiVjuJ7/G1VWGgWczayFEVO?= =?us-ascii?Q?v/cnyMspmKyHD7E1XZcNpAe8Lj6RvO+YyhFpoA/USHsqpbCSAeZGHVIK2AK8?= =?us-ascii?Q?QQUMliyVKgEXqVCH7HqH6aNatA0j5v1bXl4VFPOLC9lLxG58JdGiiipXl5mx?= =?us-ascii?Q?374MeL4Mu+4mjQXciJVtnOtw87YBQywSTPvgtmNfV/NWfeNM8ogpdcPZ8KW1?= =?us-ascii?Q?kFOo4fNwPfbdbbOVUf766ku/gFdyvSiNuEbGzQftLDXRLe4qcVgoRXRhWqZo?= =?us-ascii?Q?8eeKFn/2ZT0fqdZrf/4N+6i1w2HpALjxPkvjH8KI4NmMX697CTtleyt8UJGp?= =?us-ascii?Q?KN2z0PGftlckfFlstXSCtXDHw57hR1ZzhCj/549B3eB116xxV7dz1lX8zRX+?= =?us-ascii?Q?Ag+yV90bXftoD94GUP23GB9u68ykZ9qY7K3iAxbihfw8ZVG8FLrmftdZY96y?= =?us-ascii?Q?vLVtOYVwrYcQZPFTtisor7Z3TJFIkEq51QhxkpcJ7LK8Y/baluNaElYOty0V?= =?us-ascii?Q?XY/+6Dwp/Y+TYYxZ2zaNsYUjYtnfSsA3KaJHDIrOHSyaNvfgv0Jt/JfF8rgE?= =?us-ascii?Q?cpqXiBimCj4vXYl/g08fTRn0VwaKeKhysuVAdAA2ds+BXDBLHVOmEElAbH41?= =?us-ascii?Q?8Hr65W6Oqvz1f7bhi9RRPsVudJveaQIUnid4dUs50NKwGbVRFPbsNacLkHI3?= =?us-ascii?Q?6s3WjQ=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ae3ee28-9f43-4827-d071-08d9ec2410ee X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 23:29:49.7949 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SvkJWOjhY0t6wo3eU5+oNLKlmHFtw0ak1At8nMoQQ3DaKVeqFEdq2faCP70DUstHSI73TlgzeK0jAGQntNz/ZsruEbRIhe43Ffz7VuRFE0o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB3007 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10253 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=938 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202090122 X-Proofpoint-GUID: _gA-PLb7DGrAvZO4t-wtgDvsAkzi87-1 X-Proofpoint-ORIG-GUID: _gA-PLb7DGrAvZO4t-wtgDvsAkzi87-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patchset adds a couple new options to kernel_clone_args for the vhost layer which is going to work like PF_IO_WORKER but will differ enough that we will need to add several fields to kernel_clone_args. This patch moves us to a flags based approach for these types of users. Signed-off-by: Mike Christie Suggested-by: Christian Brauner Acked-by: Christian Brauner Reviewed-by: Christoph Hellwig --- include/linux/sched/task.h | 4 +++- kernel/fork.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index b9198a1b3a84..0bf95966ae7d 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -18,8 +18,11 @@ struct css_set; /* All the bits taken by the old clone syscall. */ #define CLONE_LEGACY_FLAGS 0xffffffffULL =20 +#define USER_WORKER_IO BIT(0) + struct kernel_clone_args { u64 flags; + u32 worker_flags; int __user *pidfd; int __user *child_tid; int __user *parent_tid; @@ -31,7 +34,6 @@ struct kernel_clone_args { /* Number of elements in *set_tid */ size_t set_tid_size; int cgroup; - int io_thread; struct cgroup *cgrp; struct css_set *cset; }; diff --git a/kernel/fork.c b/kernel/fork.c index d75a528f7b21..9273fd81a329 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1998,7 +1998,7 @@ static __latent_entropy struct task_struct *copy_proc= ess( p =3D dup_task_struct(current, node); if (!p) goto fork_out; - if (args->io_thread) { + if (args->worker_flags & USER_WORKER_IO) { /* * Mark us an IO worker, and block any signal that isn't * fatal or STOP @@ -2497,7 +2497,7 @@ struct task_struct *create_io_thread(int (*fn)(void *= ), void *arg, int node) .exit_signal =3D (lower_32_bits(flags) & CSIGNAL), .stack =3D (unsigned long)fn, .stack_size =3D (unsigned long)arg, - .io_thread =3D 1, + .worker_flags =3D USER_WORKER_IO, }; =20 return copy_process(NULL, 0, node, &args); --=20 2.25.1 From nobody Sun Jun 28 08:41:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6D27C433F5 for ; Wed, 9 Feb 2022 23:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230378AbiBIXcZ (ORCPT ); Wed, 9 Feb 2022 18:32:25 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:60962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230240AbiBIXcR (ORCPT ); Wed, 9 Feb 2022 18:32:17 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 697D2E05ADE3 for ; Wed, 9 Feb 2022 15:32:14 -0800 (PST) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 219KLRfV013540; Wed, 9 Feb 2022 23:29:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=hfSrv2SKQZwpNHlRz5pPwTI14Gs+RW+43zGZVmZmuoY=; b=JKYoekXnAFzuR8JwPl+f/NS9lEzJYKytVkOQjU5/3WseBv/vuO81/cpicCGhPgyfomvh Jq4b/cZqebJNXn5ZTAhfU8+reDTUooWXZMfml9NPS7PFw2qDc5hR6Pi7hj56Qzoe4r53 /r5aHzUiJ2ug+OtWSgMlGXOhTjUuVP/M+rb7zmaTALVXY+aS5JdgM7YFMsMVfdb2AqfG /UhhTFqBnzh7c+OxJRRcFRZiwTellKjsS185tncvzCIVidvWWgnVmazPrsz7N1oyr6vQ JWOSR64Wr27htXOsrSFgvRgAr0q7Z+cjTT6IEzHmOaTc0aOqlNcaZor/FTfR43nFWgvm 7w== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e345sr1k6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:56 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 219NFrFW117827; Wed, 9 Feb 2022 23:29:53 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2170.outbound.protection.outlook.com [104.47.73.170]) by userp3030.oracle.com with ESMTP id 3e1ec3m196-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hIN/ljcEK4OKfwxxLCZtgtt3hTwJcf0U3ldzTTSMdCTXLKD4entbse1sTtuff8kXado5JWs9y1Nnm/BHlPH1Drxdq6DlCmUa4k06dLE85IjFF8mwTyYl8XF4D02hHkvCDqiOAUDtLo60LDtn1+NUmTGPqw+EW6x9/Zy0+VJVt3gXmVa9csrE6dUclDjWPdQBxNWnOuwniQFwCovzhoq42oebkLGMfJSABjLDCAP92FnWHQL1TRuU7OHP1MxSBJVa5pDHob4PVoXFyQHVCGpfef9B1pQKH4OJ2KevHJEqw+VjJnxN3aFO/ZdENs81br8hAxRZesiB/XR6BC7+ng0tPQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hfSrv2SKQZwpNHlRz5pPwTI14Gs+RW+43zGZVmZmuoY=; b=TRuSM/DUrRQNmb6ZOmHQGvRfWxQm1wnzff3gAcOCgVJbDloTSH37/lmL7mWsknqo6+K78htpUM+3qp/Ht+rT53UpdmqEbEoqUjtGmU0A8Us3xj0FczgP8wj9noqll5tnEe36ZKeKet59TfBA5LPlWjgoHOLsDmkkfw64durNbK2Z/fieZaE5DqFnk7cKMYmVUfhmiIoxrXhPnbS3JAbcp9wy3azRgYYegormXySEnvSEulD0R6mQH/15qbBqmO36WOaUVjYdqysqGyJ6FRBPjOXhb8DYmDKOdfaZ5QJ+TTH2OWFxDO2hxQ8LVLaxeVP4/Vsw6riFZhzPloLNFmcdUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hfSrv2SKQZwpNHlRz5pPwTI14Gs+RW+43zGZVmZmuoY=; b=FtyaCzbEfX2fvIzTiy15iNQp9P7VnaQAscsARYPyuCngJrPz9+gNEm3kc2wLZs0yGnEP2jU7QnbXVIJigCLJWAmUwB5+aYxy76s73uTq0179O8BgxE4ybQZLJYIuVQm2B50tC1v0XBNKbG+QEhf/VTZ618KDM3nnK0h4Pfl8I6I= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by SN6PR10MB3007.namprd10.prod.outlook.com (2603:10b6:805:d9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Wed, 9 Feb 2022 23:29:50 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5%5]) with mapi id 15.20.4951.019; Wed, 9 Feb 2022 23:29:50 +0000 From: Mike Christie To: geert@linux-m68k.org, hdanton@sina.com, hch@infradead.org, stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org, christian.brauner@ubuntu.com, axboe@kernel.dk, ebiederm@xmission.com, linux-kernel@vger.kernel.org Cc: Mike Christie Subject: [PATCH V8 2/8] fork/vm: Move common PF_IO_WORKER behavior to new flag Date: Wed, 9 Feb 2022 17:29:33 -0600 Message-Id: <20220209232939.9169-3-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209232939.9169-1-michael.christie@oracle.com> References: <20220209232939.9169-1-michael.christie@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR03CA0043.namprd03.prod.outlook.com (2603:10b6:610:b3::18) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 04fcd479-9ed3-43f0-5361-08d9ec241155 X-MS-TrafficTypeDiagnostic: SN6PR10MB3007:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DIu6G+eURYrL6JPqwDW2c7HWXPdZmirBHuG7LUWZk2zBUYuXC1GFVC22nyzSKp1Fs7i1r6JLkkmZVc3XHr6aZBGRNMbqIlzKlpULG7E0Bq+OAbG177UXnk4pNXJ5IZQ8obKXZPgCbMjA6y1MryOQr6DUaHVNGFBr+jtlNTlDPGzn6FEy2Vuroscrubb4CWTPgqnz41YqpEzGaxwHHmEc8KGFfEz4PJJpG2a44gRnUROu9ZZvCousxL9wt1/Lbr0ZYqOFlDRDo9MFB35wtkdc13BXz2O1rEN43hTs+W4njIQ7HTBc9ByNIYSpbOM+qEgAvbuxxSxpGhiWn+Yp9k33cd7auy5YZ29qkeLpC7agzzkxQZcWcosWOzWRj1l4ekWqyElV4slVTtUnowHYPo6nnzW1NyBYxlHioOX2f+3KDIXyFwXSIkyWexYHkSwzVmnnLQZTxpwCqIoyoVgs+kVsHDtbUxdisT1DbLsYnECG79xC4Y0+AYCJYgOucgvfczleP4G4gYUhWF/uDimSMIXC4gUUx9VuYkaPAy6p0mmqKdSNGetDwNMpqbKzQ+m4GyOG0F6HDyvJfSpdX6B2USlfHj3xnysbKAqhLjPQhvVN8UoFLxCiifvZZYEjyNX9oBxEWuHVxgitave5by2wjEs5IEaLf6ZUsIxlCE2U2pQPzGKLmPC1dvZLA/CXiPca6sDGKBd9ouNTwyYSUu0c/JKMuEiY2q819TC5cr+p5Tp1nxk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR10MB1466.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(921005)(86362001)(508600001)(2616005)(107886003)(1076003)(2906002)(36756003)(26005)(186003)(83380400001)(6486002)(6506007)(8936002)(30864003)(52116002)(38350700002)(38100700002)(66476007)(66556008)(66946007)(4326008)(8676002)(7416002)(6666004)(5660300002)(316002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?pOXsbZhtb8DdBDnAyZms/csWgk91kYR8TeRFLs529CZI/v/7v7H4rTXjvygb?= =?us-ascii?Q?U8m/e5YIKuaIyP7CfDe171g9oD9F/EEC4xhlUudebARUQWQMiVT72T6pa6HQ?= =?us-ascii?Q?eAic7Z/q+U40GKFE8RVIoscFKFOJmQaLPccZDiYyDW2iYh8cI1sY6vQPmpAD?= =?us-ascii?Q?YW451OGNCh3QRcG+aO6eEsMCp/cPqGJokJDlJRPjI5rzgC0wOTfmURD/Zn60?= =?us-ascii?Q?MnVvzdi6nj+6cusoe/7+TsD2hQ4L7et/CK48JdvHgpzXnKI1YLkO4ZDKOeEN?= =?us-ascii?Q?m8AGc9tEbWttJTLQjF4UAHAB+3o5fHkfu64LGF/ndh/fqKUQ9sPtJglVVq2M?= =?us-ascii?Q?HnK7wByH6OsYsIOoQ+XSpREO14nRr8BM+N8LB0o547qvwi4BUZCdoDXJPW8H?= =?us-ascii?Q?zg229A+oLqXWPQ255z0CC5m/XDCvphUO0gOO8wxOuCdPQg15pO1Iz/lTtX5+?= =?us-ascii?Q?llH6QTyvn775WLBx8rYOsxxxo4xSaoTObNJyroKAIlHebkNEuf/4G0Lw2E45?= =?us-ascii?Q?8ziJZSCmfzrcwGrOQ4zp/wSye4lVDcOtmx9aArdvQrCX5BeJY2CtwxWO2Ua0?= =?us-ascii?Q?nlT7dZ/PpUO/5rRrVzyIWKtTnw8/RcxMR8YXiaWprHAN6dTA5KHjdJB1fOCa?= =?us-ascii?Q?1Oa371sF5CDRKLU43WQMGfz6oaOKfCLgOZAmo43sdVH7FCfH/qYliTbGekuD?= =?us-ascii?Q?B91/IkjTGmnX9C5lLq672A2G4PhwNw6tiEz8fD+Lz5mDsJBCKXsJ2gsLhlgX?= =?us-ascii?Q?l2GyW2sOM4m5bYquLNI+mZ14vbSxMol/owoK5wB/GuFeL6xIApqaYwhRy+Uv?= =?us-ascii?Q?tw94NvD2/8zucxgJQTpPegSGw24EJFW4x7EKbCutE1LgdqqWKyA/vljMua4K?= =?us-ascii?Q?IhSi9r5ikRJD9NZ1xg9yWKCq+QsDrX7g9rRC5fVmP1PH+BGcRuWjkmiNGMbM?= =?us-ascii?Q?BbzCvzSxpyFf7utaN3TxRL6MR6//D3baHHvXZxVMjGGWqtX1hPu140uPjgQr?= =?us-ascii?Q?dxo5FYJFIEw/ZKiJqGbOjE+M5GdwggmsVylYI0PsGESrMbxLQRDn/NGXQc1X?= =?us-ascii?Q?Qk87DEMx9n9MK3IHiKRGjf4uYcMWwh4BauVH58IXETg98K+VLgLsevSP0XNQ?= =?us-ascii?Q?UKEgYJ1pvQCike3/jl9JvAi83pbMjzcu+ibUyDrgmyWgUs7A/RgJDrvgDHXp?= =?us-ascii?Q?34/RwiIGJNbza84XWblVsmTnrTJD/hscn5KdcZQMOWZb+fS2z1F0Kt0CtBsk?= =?us-ascii?Q?3TsgoXxLQkI4uQD1VrS15+Wb5ItMVizKnGHVjd+9CNHqfiTQkLiiGU3qrgk/?= =?us-ascii?Q?aVwudmsQakakaWtAajjSyPG/LOLj/GWVdT6qekCXXLkFr2oo//glh00u/j96?= =?us-ascii?Q?C59uJm0s9yODD5U5mU/CddA1yJSakTGukroP3Zal0C0iLQlsfbEb4rVlckGH?= =?us-ascii?Q?jeKPvyJwQlwv8kJzZigL5xsG6bsLL6iQ4L11WxSJ893VY50h6V5DBe6pdic2?= =?us-ascii?Q?tLZaiTTiXNV43/uOWlsALo1vlYmrdnRNw7Fw386Boj4advj56JA2i1/eOWRb?= =?us-ascii?Q?7Uk5MKe8Vbo+0yQxfh9sWKVahoVKf+iLQxE9bZuq4TL29YUF31b4IENKg4s4?= =?us-ascii?Q?doAtAAJkXiPeoHdrU5cpsyS54/cGC1QBqbuMiCsO4LNQgRTMp4kdw4IOw6el?= =?us-ascii?Q?A98APQ=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04fcd479-9ed3-43f0-5361-08d9ec241155 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 23:29:50.4980 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xI0Htujzhs14N00QV4Yir6llm86J8MxxB7XasFU5taqOONxSsnq8DWDFC59J/u78lx+EW/mpTjFrwfg3tQA+qosXy2UonWC7WE7A/esmlfo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB3007 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10253 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202090122 X-Proofpoint-GUID: uTKO86xhz4icep-xjt8Mcn2LKxYDPmLt X-Proofpoint-ORIG-GUID: uTKO86xhz4icep-xjt8Mcn2LKxYDPmLt Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This adds a new flag, PF_USER_WORKER, that's used for behavior common to to both PF_IO_WORKER and users like vhost which will use a new helper instead of create_io_thread because they require different behavior. The common behavior PF_USER_WORKER covers is the initial frame and fpu setup and the vm reclaim handling. Signed-off-by: Mike Christie [For m68k changes] Acked-by: Geert Uytterhoeven --- arch/alpha/kernel/process.c | 2 +- arch/arc/kernel/process.c | 2 +- arch/arm/kernel/process.c | 2 +- arch/arm64/kernel/process.c | 2 +- arch/csky/kernel/process.c | 2 +- arch/h8300/kernel/process.c | 2 +- arch/hexagon/kernel/process.c | 2 +- arch/ia64/kernel/process.c | 2 +- arch/m68k/kernel/process.c | 2 +- arch/microblaze/kernel/process.c | 2 +- arch/mips/kernel/process.c | 2 +- arch/nds32/kernel/process.c | 2 +- arch/nios2/kernel/process.c | 2 +- arch/openrisc/kernel/process.c | 2 +- arch/parisc/kernel/process.c | 2 +- arch/powerpc/kernel/process.c | 2 +- arch/riscv/kernel/process.c | 2 +- arch/s390/kernel/process.c | 2 +- arch/sh/kernel/process_32.c | 2 +- arch/sparc/kernel/process_32.c | 2 +- arch/sparc/kernel/process_64.c | 2 +- arch/um/kernel/process.c | 2 +- arch/x86/kernel/fpu/core.c | 4 ++-- arch/x86/kernel/process.c | 2 +- arch/xtensa/kernel/process.c | 2 +- include/linux/sched.h | 1 + include/linux/sched/task.h | 3 ++- kernel/fork.c | 6 +++++- mm/vmscan.c | 4 ++-- 29 files changed, 36 insertions(+), 30 deletions(-) diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c index 5f8527081da9..f4759e4ee4a9 100644 --- a/arch/alpha/kernel/process.c +++ b/arch/alpha/kernel/process.c @@ -249,7 +249,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g usp, childti->pcb.ksp =3D (unsigned long) childstack; childti->pcb.flags =3D 1; /* set FEN, clear everything else */ =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { /* kernel thread */ memset(childstack, 0, sizeof(struct switch_stack) + sizeof(struct pt_regs)); diff --git a/arch/arc/kernel/process.c b/arch/arc/kernel/process.c index 8e90052f6f05..b409ecb1407f 100644 --- a/arch/arc/kernel/process.c +++ b/arch/arc/kernel/process.c @@ -191,7 +191,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g usp, childksp[0] =3D 0; /* fp */ childksp[1] =3D (unsigned long)ret_from_fork; /* blink */ =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { memset(c_regs, 0, sizeof(struct pt_regs)); =20 c_callee->r13 =3D kthread_arg; diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c index d47159f3791c..44603062d661 100644 --- a/arch/arm/kernel/process.c +++ b/arch/arm/kernel/process.c @@ -251,7 +251,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g stack_start, thread->cpu_domain =3D get_domain(); #endif =20 - if (likely(!(p->flags & (PF_KTHREAD | PF_IO_WORKER)))) { + if (likely(!(p->flags & (PF_KTHREAD | PF_USER_WORKER)))) { *childregs =3D *current_pt_regs(); childregs->ARM_r0 =3D 0; if (stack_start) diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 5369e649fa79..2528fb9650ef 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -334,7 +334,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g stack_start, =20 ptrauth_thread_init_kernel(p); =20 - if (likely(!(p->flags & (PF_KTHREAD | PF_IO_WORKER)))) { + if (likely(!(p->flags & (PF_KTHREAD | PF_USER_WORKER)))) { *childregs =3D *current_pt_regs(); childregs->regs[0] =3D 0; =20 diff --git a/arch/csky/kernel/process.c b/arch/csky/kernel/process.c index 3d0ca22cd0e2..509f2bfe4ace 100644 --- a/arch/csky/kernel/process.c +++ b/arch/csky/kernel/process.c @@ -49,7 +49,7 @@ int copy_thread(unsigned long clone_flags, /* setup thread.sp for switch_to !!! */ p->thread.sp =3D (unsigned long)childstack; =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { memset(childregs, 0, sizeof(struct pt_regs)); childstack->r15 =3D (unsigned long) ret_from_kernel_thread; childstack->r10 =3D kthread_arg; diff --git a/arch/h8300/kernel/process.c b/arch/h8300/kernel/process.c index 8833fa4f5d51..050aca44ba6d 100644 --- a/arch/h8300/kernel/process.c +++ b/arch/h8300/kernel/process.c @@ -112,7 +112,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g usp, =20 childregs =3D (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1; =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { memset(childregs, 0, sizeof(struct pt_regs)); childregs->retpc =3D (unsigned long) ret_from_kernel_thread; childregs->er4 =3D topstk; /* arg */ diff --git a/arch/hexagon/kernel/process.c b/arch/hexagon/kernel/process.c index 232dfd8956aa..40f8294c6c7c 100644 --- a/arch/hexagon/kernel/process.c +++ b/arch/hexagon/kernel/process.c @@ -73,7 +73,7 @@ int copy_thread(unsigned long clone_flags, unsigned long = usp, unsigned long arg, sizeof(*ss)); ss->lr =3D (unsigned long)ret_from_fork; p->thread.switch_sp =3D ss; - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { memset(childregs, 0, sizeof(struct pt_regs)); /* r24 <- fn, r25 <- arg */ ss->r24 =3D usp; diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c index 834df24a88f1..29015ebdcf1d 100644 --- a/arch/ia64/kernel/process.c +++ b/arch/ia64/kernel/process.c @@ -338,7 +338,7 @@ copy_thread(unsigned long clone_flags, unsigned long us= er_stack_base, =20 ia64_drop_fpu(p); /* don't pick up stale state from a CPU's fph */ =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { if (unlikely(!user_stack_base)) { /* fork_idle() called us */ return 0; diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c index a6030dbaa089..cbb693012b5e 100644 --- a/arch/m68k/kernel/process.c +++ b/arch/m68k/kernel/process.c @@ -157,7 +157,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g usp, unsigned long arg, */ p->thread.fc =3D USER_DATA; =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { /* kernel thread */ memset(frame, 0, sizeof(struct fork_frame)); frame->regs.sr =3D PS_S; diff --git a/arch/microblaze/kernel/process.c b/arch/microblaze/kernel/proc= ess.c index 5e2b91c1e8ce..de1da9900f7e 100644 --- a/arch/microblaze/kernel/process.c +++ b/arch/microblaze/kernel/process.c @@ -59,7 +59,7 @@ int copy_thread(unsigned long clone_flags, unsigned long = usp, unsigned long arg, struct pt_regs *childregs =3D task_pt_regs(p); struct thread_info *ti =3D task_thread_info(p); =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { /* if we're creating a new kernel thread then just zeroing all * the registers. That's OK for a brand new thread.*/ memset(childregs, 0, sizeof(struct pt_regs)); diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c index cbff1b974f88..6f1ed337cd41 100644 --- a/arch/mips/kernel/process.c +++ b/arch/mips/kernel/process.c @@ -120,7 +120,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g usp, /* Put the stack after the struct pt_regs. */ childksp =3D (unsigned long) childregs; p->thread.cp0_status =3D (read_c0_status() & ~(ST0_CU2|ST0_CU1)) | ST0_KE= RNEL_CUMASK; - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { /* kernel thread */ unsigned long status =3D p->thread.cp0_status; memset(childregs, 0, sizeof(struct pt_regs)); diff --git a/arch/nds32/kernel/process.c b/arch/nds32/kernel/process.c index 49fab9e39cbf..dba91dd1e289 100644 --- a/arch/nds32/kernel/process.c +++ b/arch/nds32/kernel/process.c @@ -156,7 +156,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g stack_start, =20 memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context)); =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { memset(childregs, 0, sizeof(struct pt_regs)); /* kernel thread fn */ p->thread.cpu_context.r6 =3D stack_start; diff --git a/arch/nios2/kernel/process.c b/arch/nios2/kernel/process.c index f8ea522a1588..eabf3452e5e2 100644 --- a/arch/nios2/kernel/process.c +++ b/arch/nios2/kernel/process.c @@ -109,7 +109,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g usp, unsigned long arg, struct switch_stack *childstack =3D ((struct switch_stack *)childregs) - 1; =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { memset(childstack, 0, sizeof(struct switch_stack) + sizeof(struct pt_regs)); =20 diff --git a/arch/openrisc/kernel/process.c b/arch/openrisc/kernel/process.c index 3c0c91bcdcba..aa110383cfa1 100644 --- a/arch/openrisc/kernel/process.c +++ b/arch/openrisc/kernel/process.c @@ -172,7 +172,7 @@ copy_thread(unsigned long clone_flags, unsigned long us= p, unsigned long arg, sp -=3D sizeof(struct pt_regs); kregs =3D (struct pt_regs *)sp; =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { memset(kregs, 0, sizeof(struct pt_regs)); kregs->gpr[20] =3D usp; /* fn, kernel thread */ kregs->gpr[22] =3D arg; diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c index ea3d83b6fb62..a76120e30eb4 100644 --- a/arch/parisc/kernel/process.c +++ b/arch/parisc/kernel/process.c @@ -197,7 +197,7 @@ copy_thread(unsigned long clone_flags, unsigned long us= p, extern void * const ret_from_kernel_thread; extern void * const child_return; =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { /* kernel thread */ memset(cregs, 0, sizeof(struct pt_regs)); if (!usp) /* idle thread */ diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 984813a4d5dc..02f91fcc1417 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -1736,7 +1736,7 @@ int copy_thread(unsigned long clone_flags, unsigned l= ong usp, /* Copy registers */ sp -=3D sizeof(struct pt_regs); childregs =3D (struct pt_regs *) sp; - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { /* kernel thread */ memset(childregs, 0, sizeof(struct pt_regs)); childregs->gpr[1] =3D sp + sizeof(struct pt_regs); diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index 03ac3aa611f5..8deeb94eb51e 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -125,7 +125,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g usp, unsigned long arg, struct pt_regs *childregs =3D task_pt_regs(p); =20 /* p->thread holds context to be restored by __switch_to() */ - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { /* Kernel thread */ memset(childregs, 0, sizeof(struct pt_regs)); childregs->gp =3D gp_in_global; diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c index 71d86f73b02c..51169bb351d4 100644 --- a/arch/s390/kernel/process.c +++ b/arch/s390/kernel/process.c @@ -130,7 +130,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g new_stackp, frame->sf.gprs[9] =3D (unsigned long)frame; =20 /* Store access registers to kernel stack of new process. */ - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { /* kernel thread */ memset(&frame->childregs, 0, sizeof(struct pt_regs)); frame->childregs.psw.mask =3D PSW_KERNEL_BITS | PSW_MASK_DAT | diff --git a/arch/sh/kernel/process_32.c b/arch/sh/kernel/process_32.c index 1c28e3cddb60..0506a739b0a8 100644 --- a/arch/sh/kernel/process_32.c +++ b/arch/sh/kernel/process_32.c @@ -114,7 +114,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g usp, unsigned long arg, =20 childregs =3D task_pt_regs(p); p->thread.sp =3D (unsigned long) childregs; - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { memset(childregs, 0, sizeof(struct pt_regs)); p->thread.pc =3D (unsigned long) ret_from_kernel_thread; childregs->regs[4] =3D arg; diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c index 2dc0bf9fe62e..5386e56b5e6c 100644 --- a/arch/sparc/kernel/process_32.c +++ b/arch/sparc/kernel/process_32.c @@ -296,7 +296,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g sp, unsigned long arg, ti->ksp =3D (unsigned long) new_stack; p->thread.kregs =3D childregs; =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { extern int nwindows; unsigned long psr; memset(new_stack, 0, STACKFRAME_SZ + TRACEREG_SZ); diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c index f5b2cac8669f..6058b3966f71 100644 --- a/arch/sparc/kernel/process_64.c +++ b/arch/sparc/kernel/process_64.c @@ -594,7 +594,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g sp, unsigned long arg, sizeof(struct sparc_stackf)); t->fpsaved[0] =3D 0; =20 - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (unlikely(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { memset(child_trap_frame, 0, child_stack_sz); __thread_flag_byte_ptr(t)[TI_FLAG_BYTE_CWP] =3D=20 (current_pt_regs()->tstate + 1) & TSTATE_CWP; diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c index 4a420778ed87..25dd496fd820 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -158,7 +158,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g sp, unsigned long arg, struct task_struct * p, unsigned long tls) { void (*handler)(void); - int kthread =3D current->flags & (PF_KTHREAD | PF_IO_WORKER); + int kthread =3D current->flags & (PF_KTHREAD | PF_USER_WORKER); int ret =3D 0; =20 p->thread =3D (struct thread_struct) INIT_THREAD; diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index 8dea01ffc5c1..c5b34fa8bb0c 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -579,10 +579,10 @@ int fpu_clone(struct task_struct *dst, unsigned long = clone_flags) set_tsk_thread_flag(dst, TIF_NEED_FPU_LOAD); =20 /* - * No FPU state inheritance for kernel threads and IO + * No FPU state inheritance for kernel threads and user * worker threads. */ - if (dst->flags & (PF_KTHREAD | PF_IO_WORKER)) { + if (dst->flags & (PF_KTHREAD | PF_USER_WORKER)) { /* Clear out the minimal state */ memcpy(&dst_fpu->fpstate->regs, &init_fpstate.regs, init_fpstate_copy_size()); diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 81d8ef036637..b0e58fe55b31 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -195,7 +195,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g sp, unsigned long arg, task_user_gs(p) =3D get_user_gs(current_pt_regs()); #endif =20 - if (unlikely(p->flags & PF_IO_WORKER)) { + if (unlikely(p->flags & PF_USER_WORKER)) { /* * An IO thread is a user space thread, but it doesn't * return to ret_after_fork(). diff --git a/arch/xtensa/kernel/process.c b/arch/xtensa/kernel/process.c index bd80df890b1e..00d81668ead4 100644 --- a/arch/xtensa/kernel/process.c +++ b/arch/xtensa/kernel/process.c @@ -224,7 +224,7 @@ int copy_thread(unsigned long clone_flags, unsigned lon= g usp_thread_fn, #error Unsupported Xtensa ABI #endif =20 - if (!(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { + if (!(p->flags & (PF_KTHREAD | PF_USER_WORKER))) { struct pt_regs *regs =3D current_pt_regs(); unsigned long usp =3D usp_thread_fn ? usp_thread_fn : regs->areg[1]; diff --git a/include/linux/sched.h b/include/linux/sched.h index 75ba8aa60248..fc45e692f6a2 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1690,6 +1690,7 @@ extern struct pid *cad_pid; #define PF_KTHREAD 0x00200000 /* I am a kernel thread */ #define PF_RANDOMIZE 0x00400000 /* Randomize virtual address space */ #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */ +#define PF_USER_WORKER 0x01000000 /* Kernel thread cloned from userspace = thread */ #define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle = with cpus_mask */ #define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy= */ #define PF_MEMALLOC_PIN 0x10000000 /* Allocation context constrained to z= ones which allow long term pinning. */ diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index 0bf95966ae7d..0467b3ce1c94 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -18,7 +18,8 @@ struct css_set; /* All the bits taken by the old clone syscall. */ #define CLONE_LEGACY_FLAGS 0xffffffffULL =20 -#define USER_WORKER_IO BIT(0) +#define USER_WORKER BIT(0) +#define USER_WORKER_IO BIT(1) =20 struct kernel_clone_args { u64 flags; diff --git a/kernel/fork.c b/kernel/fork.c index 9273fd81a329..1f6e7184b31f 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1998,6 +1998,10 @@ static __latent_entropy struct task_struct *copy_pro= cess( p =3D dup_task_struct(current, node); if (!p) goto fork_out; + + if (args->worker_flags & USER_WORKER) + p->flags |=3D PF_USER_WORKER; + if (args->worker_flags & USER_WORKER_IO) { /* * Mark us an IO worker, and block any signal that isn't @@ -2497,7 +2501,7 @@ struct task_struct *create_io_thread(int (*fn)(void *= ), void *arg, int node) .exit_signal =3D (lower_32_bits(flags) & CSIGNAL), .stack =3D (unsigned long)fn, .stack_size =3D (unsigned long)arg, - .worker_flags =3D USER_WORKER_IO, + .worker_flags =3D USER_WORKER | USER_WORKER_IO, }; =20 return copy_process(NULL, 0, node, &args); diff --git a/mm/vmscan.c b/mm/vmscan.c index 090bfb605ecf..bb85b454ff07 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1061,12 +1061,12 @@ void reclaim_throttle(pg_data_t *pgdat, enum vmscan= _throttle_state reason) DEFINE_WAIT(wait); =20 /* - * Do not throttle IO workers, kthreads other than kswapd or + * Do not throttle user workers, kthreads other than kswapd or * workqueues. They may be required for reclaim to make * forward progress (e.g. journalling workqueues or kthreads). */ if (!current_is_kswapd() && - current->flags & (PF_IO_WORKER|PF_KTHREAD)) + current->flags & (PF_USER_WORKER|PF_KTHREAD)) return; =20 /* --=20 2.25.1 From nobody Sun Jun 28 08:41:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EB78C433F5 for ; Wed, 9 Feb 2022 23:32:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230311AbiBIXcf (ORCPT ); Wed, 9 Feb 2022 18:32:35 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:33332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbiBIXcZ (ORCPT ); Wed, 9 Feb 2022 18:32:25 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6EB6E06EEDC for ; Wed, 9 Feb 2022 15:32:19 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 219KX9W5020151; Wed, 9 Feb 2022 23:29:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=5xElEgH6bcMjxMOndqXAbJ3z5HgjC0FhUwvkQXnbmQM=; b=zx9aagLCm9N95U8aRkfs0IwtYrMCUokZREofL905Dar6n/6dEUSErW6h1qMmzEDdWv2B ycFmt/MjqWG2pQ9cy3JotLBH8pb9PkciUsivQ8uRqsctgTyySMRRNGxRLFMQSmzGv66B Qlow9obBcpdEoxg9KlnRfhhz9hyEt9ezocqJ/JeUWVN9sFffc8vRPkiRYAoUlvl9DlOc UUYyxa4Jlw32xIN1CVgGvpdviJRK3PRtik12txf1KAtOqC2YQGfuAbKtyVBXUi3AiRqL bhPR1kVm49MIiKWZ7+IxdK10dOqmvZGhf7VfK8NDss1qflUpvpK7XqxUWOepuWwgT4XK 6A== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e366wyd4d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:55 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 219NFrFX117827; Wed, 9 Feb 2022 23:29:54 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2170.outbound.protection.outlook.com [104.47.73.170]) by userp3030.oracle.com with ESMTP id 3e1ec3m196-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fWa68UIMNN8DDCdlAioyxcHdUgFqV5YnhlpMgbphwXzIrnKLc89O3ghsz8mN3cnD/mS7z6gsamhs0dRa8Toa06RGdQ6V0dSzORsAtwlSUK9kZYg5uWEKvImnbHKFFKslrmsK63kQ0o8g/lcFSfzaLJ3CsMyGJqnwbkDbyTYr+/VucTAoiBHUpgbEH/WCw9O+B703adB43i8c3bz794fbLLh71glBvTNbkQrINAvLgIpyKrLwYPdVFbkK3CdLZhKDq0CsjINbXPa1glwaJaXmZ3FCzo9QbH1SKnXFDEkqQ2KbdJ+phSpsQ8KguTDxrh1DrRYOt3Os43H+6XWgBIyebg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5xElEgH6bcMjxMOndqXAbJ3z5HgjC0FhUwvkQXnbmQM=; b=iX98q4p7VEg8a89ifz+2qNBNUH8jiXYsgVYIFAVLa8bwwGkEn0yCo5cyqSpZ5N88yz6v4d+YbkLWCzsXa8i828cS541gK7uCJadscArE4kyugdorMfZ1gx2zO4RJpiIyg1lRGGvd/L3RyP7UtZl//vITLXn9cax4G2wAMogh0+EO5CfSZyuwTMSPNqpxYnlziwQJd1g5fibUz/K7NEgeK0CjAUxSTRH+Lz594+9VTc75l5AFW9YJXAu0GSiKaljwlAtBK4pLvel2JSiiy3CT0m6Qsq2xnxajI5xbYAnl2XMJSnctss6XGzhdiBhJ9Vw1QUINx5TMPfNDLCcWNIQO8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5xElEgH6bcMjxMOndqXAbJ3z5HgjC0FhUwvkQXnbmQM=; b=IPNbGpXy0p2JTi0XZDFNCuqfEL6yOG1hfLmpjlurGm7TY1aoAKJTEog9jC0FEX9ZrzyjbltxmKSt0wFh+eLR1Jv9vx2TOx9GzZAlzlOc4bqiiB0VzREQ6/+lDdF4kpiLmPiOM0EAIWmiDKRj7sqQaTKlv3PDzdjG6++i97tnFKw= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by SN6PR10MB3007.namprd10.prod.outlook.com (2603:10b6:805:d9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Wed, 9 Feb 2022 23:29:51 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5%5]) with mapi id 15.20.4951.019; Wed, 9 Feb 2022 23:29:51 +0000 From: Mike Christie To: geert@linux-m68k.org, hdanton@sina.com, hch@infradead.org, stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org, christian.brauner@ubuntu.com, axboe@kernel.dk, ebiederm@xmission.com, linux-kernel@vger.kernel.org Cc: Mike Christie , Christoph Hellwig Subject: [PATCH V8 3/8] fork: add USER_WORKER flag to not dup/clone files Date: Wed, 9 Feb 2022 17:29:34 -0600 Message-Id: <20220209232939.9169-4-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209232939.9169-1-michael.christie@oracle.com> References: <20220209232939.9169-1-michael.christie@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR03CA0043.namprd03.prod.outlook.com (2603:10b6:610:b3::18) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0fbf2a44-b044-4f17-8673-08d9ec2411cc X-MS-TrafficTypeDiagnostic: SN6PR10MB3007:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ugtBnuP+5aO+SNJ9phIwrvQYqUTxyalGGbFVut7qCoB58zTl6HDLH9v8wNVSglBFADxISickD/eBT7Dq+qAGIftjppPqrQ8+5Z+NF4IxN+kRV+baI9Ur7CU73B/v80ZVCktgbPgIUNEpbFmfy+g/apJwZCQMBmmDA90zXhY1qkIFMeuUXr46RBu7qSVPI+vaFALTLDlsmsg79cwqUeXDFaRHipfHGOJRwONKDdRE/k9N8engnJXoefEKpZB6PvtwmxVXjNHPbsN6BZJZOjZLDiPIQGowsH5Q3oouMj2YjDxJ8lPprHlwiEV9eRYJ2x6r3xDuoSg9zU5rtc0h9kU5LpEk2GE7ksc89iSZoSC3iUY3rKKlLyzQbUWN07VV5AxIlR+7iWKDXbV9cYDnwU3iJ/AZz7LjGKCT6oYsXkqMx5S6dUnHhAK/6Qdwa5sSOcogCxbeh92Hzp/1B8bdQ5zKf0rFe4IbBrgI9zIhEvzwakqA8ZFm0UnqcqJ3BntmlZLCua1eYJX0EH7UU4EAAvgUfeLR2o65M6MjKp0UYk0FmobdGJd2boCr4IXTJIIqM5kr2zRBtW1fwcf5B17Nh4yi2K9OBnjaRlT3/wJmRtrOGU33nkPX32RGOi1MuLQY+hAslvsq8ELK1sii+WLh+wghw00E//YAtbSZPc9BVATDHG6OoL5ze6WtPxKHOUbNEC4gtm1eAcpSX9msylbz4m0ZrPGU1/GmCYsPpPPcqaSJgSk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR10MB1466.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(921005)(86362001)(508600001)(2616005)(1076003)(2906002)(36756003)(26005)(186003)(83380400001)(6486002)(6506007)(8936002)(52116002)(38350700002)(38100700002)(54906003)(66476007)(66556008)(66946007)(4326008)(8676002)(7416002)(6666004)(5660300002)(316002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?uncSZwZsNt4+aix0p6vEIaFIcdPzH/+6f83fnzurl0ACcCxqrebTK/FimsOV?= =?us-ascii?Q?xiWUmblGF/AADmdNNSUOcaJJtaOv394Rmcvq45jwNDV+isnFPtirmSNc2BRX?= =?us-ascii?Q?nJwgtbmpaTuRahlWM4x36AeBEU/VS8X1mnHpjD4T3CXPeODU8z8lf/rYiCnF?= =?us-ascii?Q?Rvie/8u2NbKdf4SdOO7ikPpvSPdxz5Z3YQ0r9Y00kV+4o5p+C6OjGeDT0VJZ?= =?us-ascii?Q?U8ty24ZRP37zbKuiUF5KqO4K4XQx6bQccN93Gk0bKvgtPs9Bvn9lkPRl1MT+?= =?us-ascii?Q?MQ9rnsuL/zIYfNmx3C2kzqzmcgWMpiGk+QsMNl7fkAXTJ3U92qpQ3PFPySWl?= =?us-ascii?Q?AYTyZRDRL5rMcLUMSc88WO+fDFT5CLgfON7IOCev5OSNX1dkX6eLbCjUqmzS?= =?us-ascii?Q?beTAJtVU+YlOF9e1cXRbXRrp2jJMBU1M9uoFRDmfjGXIUEHqPHlanXO3UbhU?= =?us-ascii?Q?J2RrzUcMbBPxaceB4QuO44JFIlR1VQD0O6WXJ/+u3L+npFv48JZmGNcvVoLp?= =?us-ascii?Q?SoTMvsK4yyOpA2h9Pz6KpZEHzt6M/jyGMsptfgfcHL2Q27V9XB2YE5KYGmTE?= =?us-ascii?Q?wBjukLBqoZ/HL35LZGxXrVOgePjBXg89N/3XKMxokSTxloA8QsAMx56HdZ5E?= =?us-ascii?Q?ZbZ4EJwfA1oV7XzKa29NIz8Y/CegzDVH0Hz1YgHAm3htNj+0DXzhVzZkQni4?= =?us-ascii?Q?AQ6ZV5lQH3pMCNSZOYK3ZeC9/fm3sWMsnqDLgbOn1/zqDQ43sYZCDxZEpwEZ?= =?us-ascii?Q?U+WE6cAxXmtaINHvJ0CLtmYt9hbl93NWfx+aXkgiBDj9sCAZYSp0QTWguHdi?= =?us-ascii?Q?G3yKln49EdBZPx1xqtzHE08nF3iHdvFH0Ye87dV6R6DKdxE80RJHMWY81U61?= =?us-ascii?Q?yo5egxAKkyVDgiAbrRcFW+Junq9BPrO3cMbeLNOmAoyxxp5QvFkRl7xugtqv?= =?us-ascii?Q?xTTf2RqIrLGQQDWCgoRDPjHJ4ujTp24fJC24h14dUWYZJPcaUyVLRF90KPvC?= =?us-ascii?Q?nYxfm3VLg1fnb2+mUOSBXNyQHqWpjUoAFrh8yc8wFpLW5swsaKp6jhwHoCMG?= =?us-ascii?Q?579RjLMEAQ7m9k9Q/Qqn/Ca0ME24Yl2QsQAyC1nSgOTqnJ0ckS4LP/TVM9TI?= =?us-ascii?Q?0N+BwywBybSSJ+ZxJ62S+cOsZKprVs5b1j3BW03FGdnxwFzmu6swmXl3nbmq?= =?us-ascii?Q?9GT4pQMt9BUEk+SkjLwxhcRsFDqcV/WhBBcQtfmNbrHiFB0oq8/FNs4FUbhu?= =?us-ascii?Q?D4QNdUB+SOrts3Y0oAk3nr2w79LO8vD4KUCCDzhxxMymAR+TA30Kdnpq/dUb?= =?us-ascii?Q?yRUtr2QNehTt8bhj4nSL9Zwuh1GZTCzTiTT9KBkretkFJkK7aV2IfHcmoJle?= =?us-ascii?Q?9qUmuIKLbtkU+X7Z3Pub8hTOTZxinD8lFW94bv/3bJgQHCytzyiGIDjSq2yN?= =?us-ascii?Q?91ZpxKRQkITVFyf0AQnGYOF2xmfnGMxnMTYCV3gUKVCWGNgxqpP4hFB+3mVW?= =?us-ascii?Q?LL/6mo+cxuK/zH1f5qJDkHkCBZGijp+IucTWe826709qRybVZHRoOQH+5XAK?= =?us-ascii?Q?J9kPRkyEP1IynOPWuWKWD9dUkYJAZEA7o6BicAEl2LC2kSipOpAU4U5n8acR?= =?us-ascii?Q?c87gI03dwXPMRNIvpwt1i2XdpB+Tr98O0ZV28qRbHnbK+mLEORrZv53x3NoE?= =?us-ascii?Q?jcVInw=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0fbf2a44-b044-4f17-8673-08d9ec2411cc X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 23:29:51.2479 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Y/herNsvyAr/Nz1u/yu2n6ZcXSawpb/4lLAmeCrZfDxcyTDOmecBeWGRsM3b2jTCps/Jw6ZD31sqtjoDTcrwNUjDysplqBBJKcJhTMIQHZs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB3007 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10253 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=947 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202090122 X-Proofpoint-GUID: zJUb634q_kYtQMjk3PEFumu2YUIXtJfu X-Proofpoint-ORIG-GUID: zJUb634q_kYtQMjk3PEFumu2YUIXtJfu Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Each vhost device gets a thread that is used to perform IO and management operations. Instead of a thread that is accessing a device, the thread is part of the device, so when it creates a thread using a helper based on copy_process we can't dup or clone the parent's files/FDS because it would do an extra increment on ourself. Later, when we do: Qemu process exits: do_exit -> exit_files -> put_files_struct -> close_files we would leak the device's resources because of that extra refcount on the fd or file_struct. This patch adds a no_files option so these worker threads can prevent taking an extra refcount on themselves. Signed-off-by: Mike Christie Acked-by: Christian Brauner Reviewed-by: Christoph Hellwig --- include/linux/sched/task.h | 1 + kernel/fork.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index 0467b3ce1c94..706ca3dc3423 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -20,6 +20,7 @@ struct css_set; =20 #define USER_WORKER BIT(0) #define USER_WORKER_IO BIT(1) +#define USER_WORKER_NO_FILES BIT(2) =20 struct kernel_clone_args { u64 flags; diff --git a/kernel/fork.c b/kernel/fork.c index 1f6e7184b31f..81a1096d6ee9 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1530,7 +1530,8 @@ static int copy_fs(unsigned long clone_flags, struct = task_struct *tsk) return 0; } =20 -static int copy_files(unsigned long clone_flags, struct task_struct *tsk) +static int copy_files(unsigned long clone_flags, struct task_struct *tsk, + int no_files) { struct files_struct *oldf, *newf; int error =3D 0; @@ -1542,6 +1543,11 @@ static int copy_files(unsigned long clone_flags, str= uct task_struct *tsk) if (!oldf) goto out; =20 + if (no_files) { + tsk->files =3D NULL; + goto out; + } + if (clone_flags & CLONE_FILES) { atomic_inc(&oldf->count); goto out; @@ -2153,7 +2159,8 @@ static __latent_entropy struct task_struct *copy_proc= ess( retval =3D copy_semundo(clone_flags, p); if (retval) goto bad_fork_cleanup_security; - retval =3D copy_files(clone_flags, p); + retval =3D copy_files(clone_flags, p, + args->worker_flags & USER_WORKER_NO_FILES); if (retval) goto bad_fork_cleanup_semundo; retval =3D copy_fs(clone_flags, p); --=20 2.25.1 From nobody Sun Jun 28 08:41:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36C89C433F5 for ; Wed, 9 Feb 2022 23:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230164AbiBIXav (ORCPT ); Wed, 9 Feb 2022 18:30:51 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:52610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230029AbiBIXaQ (ORCPT ); Wed, 9 Feb 2022 18:30:16 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7489E05111B for ; Wed, 9 Feb 2022 15:30:18 -0800 (PST) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 219KAjBi027666; Wed, 9 Feb 2022 23:29:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=4o5CoxdRVCPF8/Ow59bNL16B/u8lUm0INV/6+C4mVOQ=; b=EZ5LUUtj0STXRZqTIQF4jHM0r2FvgQohaGuS8JEN05jorhCzeTKkmMzuQuCtXcpRghmy 1BJZeIts1HjFtJWH4SKX5Uuh8sL3ElCIszDyXdtkJ49WIVLR6WpDh2YPByTRBO2qJsZa E7Wq7VKECiyX//oxVRTswtwHakGZW0Lwpm+c++oZaut5lXPXRoaxvqffBxfj6Ir0y92v ZKRAVPyK96lzqxPi1hioLPy89+xecT5WP7wgHmpDMxI/WiS+rAbfLixk6C6knI6Fh1O7 DbWVVaUaMpxRp5ZRQGZWpd6qhcGlgDwAO2TrC74ikXZhKCgKh9mCslT6LhiM3z9hFKAg hw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e3hdsx37h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:57 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 219NFrFY117827; Wed, 9 Feb 2022 23:29:55 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2170.outbound.protection.outlook.com [104.47.73.170]) by userp3030.oracle.com with ESMTP id 3e1ec3m196-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XUEO937IJLTy6xFerpKSdYGlvEqihVCLy/eMU4489ltwqHr/hEQAp6H0g5sM19mpiB+As+8DA4jxP60Zo95ZayFmWaVn6kjDSKUpnpaCCrAGZY9DW+ewdhEhMbUsuaet6k2Wv4MmrPpYgi8f801khed+YBTCX+Q0tPtVLynXmBmoPbDk/o8ARmitrHu0Sy3x9RpuHb5e1lzCTT4GhpnBqBXYABFUNXH4rFN64noOoiAmJ1UqUNjhS2IMqBBziAr+VprYJLMSlDA0azjUoGYRV4O7PEfIqV6Y1kVmPmxXM42wV8ITnTLrHRqkxUWuOugsKC5p++asZqh0vRDwDpJ73g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4o5CoxdRVCPF8/Ow59bNL16B/u8lUm0INV/6+C4mVOQ=; b=NDVPKycrp+f/P/r4g8zX/waiPX2wtnUw6I6EGGmYgvvBz2UkkNJiCfDvjNZw/eRO51XpFTTo1RTf+a0EqYbZcKEZvABLAWApbMWurksoV+mGneH+sH8KCMWpelljiWgxs+Cq4Vh+2JcQRDh2QRIwgretWj5whN3iYAebkryxe9Pb08bFGvKgmNFYSSIjFl2+LN5I1qe0HZlAdtixLwRuzz5d7ug27Zb0fQDdbQIhrWGJ1OZkqC3UeZ3M1OMkEDiJD2vv1LffFbm0mjW799VPBcpd9muFlenkRW1r6bRzbfTQJqYpmbwlcJm7ko5Hn0wVgwYbFEUBgVHxjEH7DCGl9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4o5CoxdRVCPF8/Ow59bNL16B/u8lUm0INV/6+C4mVOQ=; b=kg9r0am+owJ8nxhCFLj6KTbnUFhsdRKShfCogXknJGz0PDh4oQ84z9y9baIKlAAijCanNxkap4doFaIN3N1o85oT2lxbYKeVM96mxofX0jQJCbYWjaXR+yBH3Wr73an+sq2PDMhTY5JKJqZwQScCXZp59ytwAOJFUMMgU/tk2lo= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by SN6PR10MB3007.namprd10.prod.outlook.com (2603:10b6:805:d9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Wed, 9 Feb 2022 23:29:52 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5%5]) with mapi id 15.20.4951.019; Wed, 9 Feb 2022 23:29:52 +0000 From: Mike Christie To: geert@linux-m68k.org, hdanton@sina.com, hch@infradead.org, stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org, christian.brauner@ubuntu.com, axboe@kernel.dk, ebiederm@xmission.com, linux-kernel@vger.kernel.org Cc: Mike Christie , Christoph Hellwig Subject: [PATCH V8 4/8] fork: Add USER_WORKER flag to ignore signals Date: Wed, 9 Feb 2022 17:29:35 -0600 Message-Id: <20220209232939.9169-5-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209232939.9169-1-michael.christie@oracle.com> References: <20220209232939.9169-1-michael.christie@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR03CA0043.namprd03.prod.outlook.com (2603:10b6:610:b3::18) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 095d3f05-411d-46ee-5731-08d9ec241241 X-MS-TrafficTypeDiagnostic: SN6PR10MB3007:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:972; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0N0afFyqX33xNNqjf5Wl310BmC9Zu7ga3OTXriwb/QI9fkmsJ+6JrsutexeYEwinn+8wmOg1nJMT28BJwRcDtrdlXmFWfQNtOH4Qtau3UbjmGH4yUNSCDQw8DHw0u+h7fFTL8pq6vvw4e7tYMkQXTKEpCXvdr+v+jxsHQuQBqjCuzLqpvhMkytNLxrvqHO2WURKRmfHsztcbQtepuRDWnb3JCRCNo65es8Yt4IuXouUiCG2ymfQ41QJp7eQnPmYO8Nxl3OV3lM7s/SqhqcCzCcxfn3OcctqJzyxKNsViWmZCKa8XRHXxrNloqIv95oTO9LSzJJMHVmxsfrW/NMSKUesBcQ+oge7BPIuFyIX09cGM/BPCbYxcrTvjBUGA10eGj9Cl+4tVIwjvN/jQ5XS9hfb0Y7LZbUWDKCWvv+6ACfpqz3iT2LQ6LazazoV2MKvpdN3GEz7Z93nLF3Hqj5A5vjpNDXKlOHOwinORjoo6vLQWqgG7tSQnhPGCcfrprFiE6Ho84kb2+dBqTRsTp7TaOlJZI5N7JOqIzKIQVnKow7C/LiHfw3uzpgnwlESF6u3PgeAH2iP5nwt0c+YuBExRykEo5fP580h61hdTzOKOU2kwjUMKnIltAfReFs2UmxfEJq5e7rlzrsxg4twdtVbY+PCIOOU0nFKaYmXDMShvqcuUU1V+U2NAZ2CeXmZL+pPhUYElHIwaFN13qDMLqpBNBVTEfPqvppKR3Dc/e3QiRbk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR10MB1466.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(921005)(86362001)(508600001)(2616005)(1076003)(2906002)(36756003)(26005)(186003)(83380400001)(6486002)(6506007)(8936002)(52116002)(38350700002)(38100700002)(54906003)(66476007)(66556008)(66946007)(4326008)(8676002)(7416002)(6666004)(5660300002)(316002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?/shXJrPoen1Ajaz9yj6X1+j81EUd6tzPKdZtgHB7vKi5tH+uABE/FJ5jKpZd?= =?us-ascii?Q?c5gnZzQWtdapJtl2NVXXDAmyjffLiYRNte0LNoA0STi2w2yRODPxZ94r91vk?= =?us-ascii?Q?N7o+mhvaCugfPy+6WqLVHCGKdAYyeH44+N5LsY34K0mwfT6Y81+uSD3G3HHp?= =?us-ascii?Q?cNj9VFA5bic1jl514QXFekO0AA/VCttF1WsolPKKVEzMJX3u23dQbU0p4JM9?= =?us-ascii?Q?KmuoP2mXpQQmzJkFGpUpcN19bIR9Lf1Fq10xTseEMh3wuFn+wgXxQ4Z0fUVE?= =?us-ascii?Q?OMRP4t/Op+ox1bp9KkgJnqDV1yUWkKKLJCk3d8m/lJuuc3MF6+3sQeslHud8?= =?us-ascii?Q?NcWXY4Mzlhx/yhv1diqC7oKwFy4g2jhl7GrBKF7fGyJmUjQt1iVy9lowoW5N?= =?us-ascii?Q?t4hgyp3POrJLwlPIja7hwbrshZTi2MF+yxlIZ2JSOkSim+oSk1iuVA+qFVOP?= =?us-ascii?Q?6prdlFJJkL+X/pi8Ei6cLu0QNaTH0g35yfzBxiDH3ONwmt32GMYk7b/EqrTC?= =?us-ascii?Q?vX+jQFmcea2iHVAAAY+fUFZCgEGVKeUb/We9bljAShnHPfS71ZfrzdAtC+DS?= =?us-ascii?Q?FycjtWFx0BQsuaFixVFdoBGvN6+wy7IcfRJfhMy5KDE4EsfvIC/Nb5f9HCCe?= =?us-ascii?Q?zx5DbHN+ydQTn29z+ect3QKQJR16sAnoHD57+WTnjpUdww6Z3lxcWecxWx3B?= =?us-ascii?Q?mLhJMFBOw+TWd23y6g9fIJlqSZINqdJKkemPGcrrqDxVHQp6246bNHoPUMfI?= =?us-ascii?Q?mQ2Szd+GJWD0+Q8CTtejWgiLdVUiTKXSO8ZkaPloC/Lr1UlMRW0PGGd0flAR?= =?us-ascii?Q?VZYTSczJinxvaS0Wm82jK7bd6XOjv9xusdRgMVatBBuxwymrd3dIufBUPA9C?= =?us-ascii?Q?QeJWe2tcwpcfTdguCybDhJP59by/ZaONNHMyhFjdIhBKFawx8mZ3wVXmRifs?= =?us-ascii?Q?mQRd3AQt/Pfid0dYvuTnzSjv8yhA8p5jYMUdW1Eg2ziVv77SB8xnuySb3JCM?= =?us-ascii?Q?SAUWcgoT7b/4tlNlW1QAQKgePQDakgDP7VMUY4sCovz/WkGhz1zBgk6pzwHg?= =?us-ascii?Q?capLRg7oQL4R5rt8/+3MMGMzskVCcOEmk7ziRjN0sm2KzFIWI+98Tzozd8QX?= =?us-ascii?Q?0gq42lb0Ntn0bsY2TnpXNPZ/FfmNMORSg7DwItUxA2W0e7Wd27co29HbS57o?= =?us-ascii?Q?81tDh9jud3O1Jn4I4ZHnnsYqlcdwsV2lF+Hqkn0raMnIPLdZL9lBQP/bPEmj?= =?us-ascii?Q?u1sQDDUFjKd4Hvfibjd0CQOm8VWShqXnMNGwn5EKuLNSPyyPSmhN/BPnztpg?= =?us-ascii?Q?KkH0OsF9teRzFKq5D14qaPOkcjUp+/vkPxs6jBpPUVa0FyBBJ1pAKN2MxH3B?= =?us-ascii?Q?dHKc/GTCeLj2U7ceDqYykwKMzqt/HyZtu0d/ZzrCY6zXODOTeZUiXuOkJPsX?= =?us-ascii?Q?jd5Bb+vPc+O/92PGbDdZvf75Ivg8++e8orNF44Gu+D+bk6KC+PxoRG83XJGT?= =?us-ascii?Q?Lncxe8UNp2wa6c5kDO6hCblVKS55fd6/VzQSaQpny304YHIMpTbADmgyrVBE?= =?us-ascii?Q?KlGBpJgfOIIStnuoTeV9hrx58jxLcHR1EC/iQlr5/Et33lLkw8IwtrwZgl3Z?= =?us-ascii?Q?UUIvoo0z9hluOyN4a4N70eOmSCxTJE939ycQOntoos1J9YK3CV+5uES1WIhy?= =?us-ascii?Q?cc3o+Q=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 095d3f05-411d-46ee-5731-08d9ec241241 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 23:29:52.0135 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YwgqhnodzHmQkGuJp4/KMB4eTqJ1pUM1Rq4dxNxFkh8P3KW7tD+izs1pD4YKCgLFieJ1qAkS3Qyoe5jAekPSUi/htq+cP3hVNISgFk4njT0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB3007 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10253 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202090122 X-Proofpoint-GUID: 8yGYRheDKHL6XKqAiDhl3d2xGsEsYQBn X-Proofpoint-ORIG-GUID: 8yGYRheDKHL6XKqAiDhl3d2xGsEsYQBn Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Christian Brauner Since: commit 10ab825bdef8 ("change kernel threads to ignore signals instead of blocking them") kthreads have been ignoring signals by default, and the vhost layer has never had a need to change that. This patch adds an option flag, USER_WORKER_SIG_IGN, handled in copy_process() after copy_sighand() and copy_signals() so vhost_tasks added in the next patches which are based directly off task_structs instead of kthreads can continue to ignore singals. Signed-off-by: Christian Brauner Signed-off-by: Mike Christie Reviewed-by: Christoph Hellwig --- include/linux/sched/task.h | 1 + kernel/fork.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index 706ca3dc3423..c001d0fa1426 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -21,6 +21,7 @@ struct css_set; #define USER_WORKER BIT(0) #define USER_WORKER_IO BIT(1) #define USER_WORKER_NO_FILES BIT(2) +#define USER_WORKER_SIG_IGN BIT(3) =20 struct kernel_clone_args { u64 flags; diff --git a/kernel/fork.c b/kernel/fork.c index 81a1096d6ee9..6a04860fa1ae 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2185,6 +2185,9 @@ static __latent_entropy struct task_struct *copy_proc= ess( if (retval) goto bad_fork_cleanup_io; =20 + if (args->worker_flags & USER_WORKER_SIG_IGN) + ignore_signals(p); + stackleak_task_init(p); =20 if (pid !=3D &init_struct_pid) { --=20 2.25.1 From nobody Sun Jun 28 08:41:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE520C433EF for ; Wed, 9 Feb 2022 23:30:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbiBIXa3 (ORCPT ); Wed, 9 Feb 2022 18:30:29 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:52570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbiBIXaP (ORCPT ); Wed, 9 Feb 2022 18:30:15 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62C7DE055264 for ; Wed, 9 Feb 2022 15:30:18 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 219KSAZo020152; Wed, 9 Feb 2022 23:29:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=Vs8tFpLTMOGvTyZKGEuCsbE6CFo8oWe+4mPnhyqiYJc=; b=msY3xQDppPI6SNEIw3axBRq8SfCDVcSDuTb4v5WGn5YtH0kElqvgudA+cuDZ9siAxair 417uUJJo7adkRCYm4VvLZ0CbxVxtkYK04Dy4jiP0yL1IVAaWxD/I0uHa1S9XcHNqeDBh uqosb1XgByiRlB1LE6mggN6g5zMRx8S/MvQ5UHHKqOn6modD1NNRAd/d/1LVneSW+8TZ nZ50ye7JrkqDv3kbLEKwiX0XLvETngIM7ZI81WiZqhnC7FYOKdq4NkKIhxqOjnmEEeNi up7XPNR/BRchd20K0s4/wVkzlCnHsOti1xoP4ENS9BVDP3ViaNX9PQt2u7mbT/k+jQ1z Dw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e366wyd4j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:57 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 219NFrFZ117827; Wed, 9 Feb 2022 23:29:56 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2170.outbound.protection.outlook.com [104.47.73.170]) by userp3030.oracle.com with ESMTP id 3e1ec3m196-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mLW+gwRRKezKXwtJ9sag3WkDWsGUJ3aayttwdzl7RuvSfD7umhsSMmbI17vN9GQRtcUC+H1+0O5lNiSnWJtQxVUziiYjkuU5txCtjrnk1AoynBrZ/m21Ocr6vZL7B5D8vMUzg+PT21MRrXQXgm3VX03+ZWDhcPGy2y43XwdoQ67nj1LMgf5Wg0S6klTr5cF8rR42RWkKDqOkxu+BIGIdlw6SnzrCUOcmjvcTSndE5KH+VcJ5CBjBs8kVxXguVFim0DI7Weo/2sfZxx8GfK9GdlbRw/1oe5kXJejHz0qK9EdoKjRPR+qWTNqu45bqpzmxPvSWAJDIFz1TodJFrWoKSA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Vs8tFpLTMOGvTyZKGEuCsbE6CFo8oWe+4mPnhyqiYJc=; b=AyhvNwtfNGnpVH4h7Hxisz9QLxTW5Jv6kDzaa4n8RRTdCPsGNunif5zspipKQciVR+wsaxfroZnJtQMVTfIg80bSz4CEI3Ve84Z0eSo2xfTcpyTxsTZNsBsj8ACFSHUEEWnpYsU/TnCy+M8BvtDpMzQLVXDsGyRl84AV9YP9mf6DS+lSpxJgLNv6hQcGlaZ2uEBsoG7df3EQW98eLCnBmtUes4MiBxQajlVb/eZim6kBvVf5zeUOSvZbzUnr5LXZT8ctiXDeRd5LMXSZvc0+d6+jp4h8+HBQRVy94TJqvshUk6WYSdChqwQFtjHlv7pkLUiSLgLvCxE1ApKuBW3hyQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Vs8tFpLTMOGvTyZKGEuCsbE6CFo8oWe+4mPnhyqiYJc=; b=uOZE3F4xdqFFg8ztpPt1vF7qRvsLQVcbGShUo1MlKSZSksQma1J/QugQGAm/niQNDxZhqtSUjqY7xnxWgJgUHTNQcN3WEltgLrIQQxkXpAZtDmv7jzSkGt1+b+SHunBTEyn0rfWooFkgna5IzzNLza8xTw77mDf5noaxkIdy6vU= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by SN6PR10MB3007.namprd10.prod.outlook.com (2603:10b6:805:d9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Wed, 9 Feb 2022 23:29:52 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5%5]) with mapi id 15.20.4951.019; Wed, 9 Feb 2022 23:29:52 +0000 From: Mike Christie To: geert@linux-m68k.org, hdanton@sina.com, hch@infradead.org, stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org, christian.brauner@ubuntu.com, axboe@kernel.dk, ebiederm@xmission.com, linux-kernel@vger.kernel.org Cc: Mike Christie Subject: [PATCH V8 5/8] fork: allow kernel code to call copy_process Date: Wed, 9 Feb 2022 17:29:36 -0600 Message-Id: <20220209232939.9169-6-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209232939.9169-1-michael.christie@oracle.com> References: <20220209232939.9169-1-michael.christie@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR03CA0043.namprd03.prod.outlook.com (2603:10b6:610:b3::18) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f97110d6-5020-4e8e-6359-08d9ec2412b1 X-MS-TrafficTypeDiagnostic: SN6PR10MB3007:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EqlFk+Dl9Qo46DLF6fjRz+nMnAF1gXR9P7Tv/6saQCNulcmB+KhCNLG5AGRsToucroN2yd6J3cbMtiYqXr2sQinN7uthS5YmH9rLPmsm2ut9G2IJ9p7311DdWN3rJ0EuQ2OpkHO7Ll/hqKEkaxw9dSrzORKz7WAWUdgBfo5XjWPtwmDArVc8OM0uaKIcZ3WRmmRMbIKTqDoCd9brg6XEcafnUg2Fl01ywYbRvT78TLTL4nrjzfXFqo5PHqWvjwDZVg7SUezlYtzHClkg/tDTdGuu5/PD/RvTb2Y5Qhjv0VRRrY4IPadkRu5GqKlD1/rpz6TlwlvbUsiI18PRQwla6LhnNkcs8suB5cC/pXAmml4Mi8NuU7grXL3ihzup5kLyeoI4gFL8DEOGxJX3vUgQ1rUPyadPgIGLRmW0seAjU7ev6UanC0+cMDsqS7Cl5xiNoUQ6YBLhgGp4ArOpfzdvvzfIINVD1W7m1IrJ3xw5m1tstdXgNW8VR6BDsS66zFOB6+lbqsrxfyJjiHCh2IQ6/EsO5EvhfB8fqD8Kx+U0QlqEd2rrZbcdBCR2GYkqhmjuMCDIxQu7RH82BvB0EByufzPrqZUS8Vu91NNflgQCATpApoq/K/1gG31GywuWGkPlhbG4cZX/bJgtzhZ9RnEfA1pTZkIeesqOKk/Z/HClJhj8gBqgCdkZAE6idgflF6ekw7bVFQdCnXRGsH+58+gAACaxs3/RYLqOdGGoJaQzTDI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR10MB1466.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(921005)(86362001)(508600001)(2616005)(107886003)(1076003)(2906002)(36756003)(26005)(186003)(83380400001)(6486002)(6506007)(8936002)(52116002)(38350700002)(38100700002)(66476007)(66556008)(66946007)(4326008)(8676002)(7416002)(6666004)(5660300002)(316002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?rhBVI2OZGGTTMVIgNvBH7e0QBRy4qogpme381Ibsc2LvhgzoiOShsXzTuVJJ?= =?us-ascii?Q?4Tin/XTqidZYteHJkiZMx2eFkax4DK55gloepjxRMqwzBFFs+aA5J2NPOnsP?= =?us-ascii?Q?hExk6PCPiga7wSbTN3/jVPcUfuarVPCZ076S2MIhr/hFQiyhBRBL02tEDJDl?= =?us-ascii?Q?aIlnrHOJBbCbXCNES7ftO/fPZdDya6wVEubaATE7HzX2hoxTcaQoEuL0733T?= =?us-ascii?Q?gzXzTboPMgT1xBY0mZ2IWAFvy82WDQg8PnnLA+K6CVQ4VK/luKJDhyPdj1Sm?= =?us-ascii?Q?TuukgE1DHFFYHTWEMAEPI2gBRrj9/Ff2S08l7Sup2dWFfvfDigAQ3uEhvL8b?= =?us-ascii?Q?ctdlUMDmErQFBYE+PR/QLtTsKCXe3BPWz2fpZF4j3zFCq6vSXJpw/qeb3zpG?= =?us-ascii?Q?dfAVuFfxnFBywFU8l0KJLe9r0/59LKyuOrBDqALtpek+COuLA5LnZ5cel5+n?= =?us-ascii?Q?c4G6/5yQnWuspmEUacukuXAxax3rNidr7nidTBODWUTXU7zBljWpynPOTegy?= =?us-ascii?Q?emU1Ml+F/xXmBNleQP1M1enBue4bXSArgYAD5ACmR+hHs0UxPElZBXSgNrty?= =?us-ascii?Q?MYJsE52j7LV09KEhFxUac7taatZTBq2cecqkIWgfjBW6Df1WXp1f1KBw58li?= =?us-ascii?Q?toGIeQSJKuV6ARGbXQsCimJZYWrfNttMaLhyKfcYmhZ01SoEU39nMd/hQS5R?= =?us-ascii?Q?mGhK1ac/kNmOZoOi6y7nQhsWjrn2DrAGoklU7THfy28/oWRoyItNuV/+XtAc?= =?us-ascii?Q?bLqJadw8xn3fP90qL3GD/ijeIlbmVTlLhvMsv+KpRzOqhHlUB0LkzLs2SUIl?= =?us-ascii?Q?vs0HjQwy8E5s14S1ZXodxDyKjMEOLX5ly/+FmZfaf4SlEGBO3ErVv+YyE9nl?= =?us-ascii?Q?ZcOB64fXxWDvowHvJvy2tuM5bTp+achykoReoEcSm3/+HF6wt3MWRttWY21v?= =?us-ascii?Q?Ln2GngABwVYlU+w7BDoKdO6GozOVdjdNok8jDaG7VvfO8Tu2t/num0oGXcHA?= =?us-ascii?Q?XqnPKiKr98sh2RkJCtyWY22dIqhkLVWlVL7HOtAPXJYQux4Y3JJHvY9QJlRj?= =?us-ascii?Q?fIaZzbMYN35M71gzeFqFYuAds+rLHF+9Z7v+ihDmisTD6Mx/7UEyzEdpYrPx?= =?us-ascii?Q?Z0aTs8LqoMMCv5OU9eFt30QiUIq18Kkt/ewE0969uhb9ZAOW0Nr6KMj2fO2r?= =?us-ascii?Q?Ljaj/zkZxutIEj+LTM6z+FmILoPRFUZm3DTaFhBh9vLuA4jzRdylIZp/ythQ?= =?us-ascii?Q?Ufyb47Mo+N8CwgZXlHrRcaaaBRWAczHKk0dc0UnPzPrpUwDTeWdHu8ySqNa6?= =?us-ascii?Q?zY2L3z0YLMjtVLgxclVxxIJ4F7VPM2AkGWQbQ6Hww9NSqjEJTI99eZ72xPmc?= =?us-ascii?Q?7inMzM7RDoqqHWLFxewL96JRttenoG/eIFwzrDnThpO7bciLXzVQw3ysrX37?= =?us-ascii?Q?ebYgPJ6A4eNfDEgytPmYejUTVG2TRJuQSDpOQh7p4BGk3oQCthpaF8CVJnKj?= =?us-ascii?Q?XuquJlme3cFWrjJ8cNUVS190FJPrIJRwBT5FqUijrX9Z9vs1Amh3fjvBkAYG?= =?us-ascii?Q?Glp8KWju94M8BXKSkFBdCmKJwdXFuM6wShHWgz/yuUQhC/nmurNRFHxKWpsU?= =?us-ascii?Q?nyDNymfbA3IX2/19sUrKfaL4RVZqlTRoiVLduF0maH7fQKM0TEByT+Sqr0gN?= =?us-ascii?Q?oeS93A=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f97110d6-5020-4e8e-6359-08d9ec2412b1 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 23:29:52.7478 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iqSyih47tZBEmzIVuDr8dFYNWkUfxXFjkjsHeEUnMI5MNUXOxjmAxbc6Hpt8PjE54DOrr32in7ZuxL8prbO9aVcBmKHvV64SDuXurT3pXoc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB3007 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10253 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202090122 X-Proofpoint-GUID: H7TRreMLSnA-bpw2zlOagYOdsOD98RfN X-Proofpoint-ORIG-GUID: H7TRreMLSnA-bpw2zlOagYOdsOD98RfN Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The next patch adds helpers like create_io_thread, but for use by the vhost layer. There are several functions, so they are in their own file instead of cluttering up fork.c. This patch allows that new file to call copy_process. Signed-off-by: Mike Christie --- include/linux/sched/task.h | 2 ++ kernel/fork.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index c001d0fa1426..787e6108fd65 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -90,6 +90,8 @@ extern void exit_files(struct task_struct *); extern void exit_itimers(struct signal_struct *); =20 extern pid_t kernel_clone(struct kernel_clone_args *kargs); +struct task_struct *copy_process(struct pid *pid, int trace, int node, + struct kernel_clone_args *args); struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int nod= e); struct task_struct *fork_idle(int); struct mm_struct *copy_init_mm(void); diff --git a/kernel/fork.c b/kernel/fork.c index 6a04860fa1ae..04eb7fc50a13 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1905,7 +1905,7 @@ static void copy_oom_score_adj(u64 clone_flags, struc= t task_struct *tsk) * parts of the process environment (as per the clone * flags). The actual kick-off is left to the caller. */ -static __latent_entropy struct task_struct *copy_process( +__latent_entropy struct task_struct *copy_process( struct pid *pid, int trace, int node, --=20 2.25.1 From nobody Sun Jun 28 08:41:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C86CC433EF for ; Wed, 9 Feb 2022 23:31:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230084AbiBIXbX (ORCPT ); Wed, 9 Feb 2022 18:31:23 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:52678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbiBIXaS (ORCPT ); Wed, 9 Feb 2022 18:30:18 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40332E06145B for ; Wed, 9 Feb 2022 15:30:19 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 219KSAZr020152; Wed, 9 Feb 2022 23:29:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=JVVMWWAgJZkOZl8pzLkY0CwA8WarJlNyYk4gZe4QNp8=; b=qVcspgzQ4MEhJuapMrFyk4WlmaxIo+75Bs5UToJz6sQXipMSsurrEktd0Zyc5nTrfYk7 UEUL3JmerWiCS6uDqBqB43Dlsyy2XW3YRvxWW88Ox8YlyE0rDmvPsEePhT9EZoQWJR7U hDa8AFeaWWfaz6gI4fWarPoqDf/iD+Ieinedu12ribIHb3fXoIga4txXA2vzdV2QIMKA uxJiJTOHLHOaasn6mvzzySpy4qXs24gg5k8YjvhIiP7XCaG5Q3p/OuA+vCtMsgdagst2 vKT28DKg/OoKSD+njYiCwKYlq6upNdPCC37i/XBiynm+xcwTNBZwZTYHhSmjnUB2OefI TA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e366wyd4v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:58 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 219NFrFa117827; Wed, 9 Feb 2022 23:29:56 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2170.outbound.protection.outlook.com [104.47.73.170]) by userp3030.oracle.com with ESMTP id 3e1ec3m196-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C5sZFgslWTZ98YNYyQzpOoH3WBKXWboL9kd+7kKmZxtcmv7RNOV6H/TP0KSncPKsdk88s6H9Qifwj1qJTvKRZj+37B/KpV7ahSlMQeyeJOgTWhYTWBnGnzR9m3HXtkWIuYAiUfw+q+LRc59svC7fiuU+e4u6ng/pDM7X1tp5t68Nn0dRsjVP+mJOfucIECKbqDXXl017I9CF2Mh8KYpUpbjddKud5pOgWYJ38d6i6JXn+XYVbyZbmK2K9C25/WMtL9EveSQEYzQJfccmtOf8t++WXPRpyKA/WCpBG2Jx92+FY92SQOBWYC692g5HqMXgv6RMXYxzSV07rKnkEvObnQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JVVMWWAgJZkOZl8pzLkY0CwA8WarJlNyYk4gZe4QNp8=; b=ZTNYmIt1wCXtbjLuGIMTQAEWbNtgxyuMn8je6zUcmiG1LRNPss4ezFPs+GDWxIebRvUHUL/FMlMgTf+z+pjLNiBm+/qC1gj4eaLmN2W0Rrwbs+aDbTCr3iNgKkON1eDP4IgLoM7BE2aWKwLRjZTNNEiWmfqalpIq/0KjsPb/VdfcU4kDQhLrOjX+BIckbhTMnavK1xo2ayIH2sDCiMUOR3lVuQt80+YwXn3NaefVucqXD+L1LQXwI+VbMtGwNZeVKFky/gaAEisFxi2xnwQP29JlfRENDraUwnGVJuFjMPY8AXgiKP3s0ryCFwkTgEeYHrpEU+OF+hYj5lZmxmdx9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JVVMWWAgJZkOZl8pzLkY0CwA8WarJlNyYk4gZe4QNp8=; b=XVBBkKDH7vR3sYJnsLqKrJYKuO52m8VTYUPfE7w/VsOfE7Zhg99qLMN3yje1u/C+uQQNWVWWMbdb6gF472MHGkFrc3uktMWQfl6sfLlFHPfvZx+THPkEkGNnlXubbB5yVacYirS44nFkVMWK2T0SQWDwCvR6b6tUD6JTjElq7qU= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by SN6PR10MB3007.namprd10.prod.outlook.com (2603:10b6:805:d9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Wed, 9 Feb 2022 23:29:53 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5%5]) with mapi id 15.20.4951.019; Wed, 9 Feb 2022 23:29:53 +0000 From: Mike Christie To: geert@linux-m68k.org, hdanton@sina.com, hch@infradead.org, stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org, christian.brauner@ubuntu.com, axboe@kernel.dk, ebiederm@xmission.com, linux-kernel@vger.kernel.org Cc: Mike Christie Subject: [PATCH V8 6/8] vhost_task: Allow vhost layer to use copy_process Date: Wed, 9 Feb 2022 17:29:37 -0600 Message-Id: <20220209232939.9169-7-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209232939.9169-1-michael.christie@oracle.com> References: <20220209232939.9169-1-michael.christie@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR03CA0043.namprd03.prod.outlook.com (2603:10b6:610:b3::18) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4a2feccb-9005-4255-0d30-08d9ec24131f X-MS-TrafficTypeDiagnostic: SN6PR10MB3007:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /hLTHB6RalHLdlWB0LjFjLAcmDu3NKOBby6AMZzkzHBJBqCzocBOv1tVwjT1/vqEyggRSmkAVxKN7D32h4V96Ap/bUZCTBhABifj6IyuW9NFv9yYj20z0gdENPscfbjtPvmTTRXG4kA1t66Wgt7TkLo1YTxTCN8xs35SFy0mhBUsLM2UZGH+jXMzmySDt42PcNxiHkISi9Gn/xUO2xKQ/JW5B6Lx2Diy2Jy7T0Q+j1YC8SDDdOzO2RWJZ1YgE3iMrvVUCX9r6zOIcaj0jU1HrP8NSL9Smpt5BehD+l2TkBdpwjDbojLYAN4t3V7AIGQKZmKbXzyTX1EZvxiJHxc9YNZgt0mgBlde8pknYw18Y2HWeMFCSY6vcL1WPHf/Stm0GzvOg1EItZkcaDxBBLER0cH0+L4gAYKkPIt/Gg6mdPEnGZtY4TgxVF2Pyg6jDQr3nX7vE6mqwtC0s8qVXIPceaLCaquyBKKiER0ik0zuI7TMBfefXjIAoh7UGXCVv+4LW6ctikW4h8MJtmnIV7FZA4zdzH6BPDBd3YcbVtpGZ5a6Z4XSalOe8zbz2z85q5LUUQjaiS2vA20+LoCmiYxZTmofqe4WxBRFEPjDwshBjfS6oYv2hpEuZwKyQP+PpZDPkBOtRJAItv5glXCSH+Wxzs/rULrS3h7W2GQIxKjc7dUTPIBBMiULfce6wYLk1ZE3zcFhovd2yCBM25b+6kIe3bOmKfKrX4PZLqoSlZU6g5Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR10MB1466.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(921005)(86362001)(508600001)(2616005)(107886003)(1076003)(2906002)(36756003)(26005)(186003)(83380400001)(6486002)(6506007)(8936002)(52116002)(38350700002)(38100700002)(66476007)(66556008)(66946007)(4326008)(8676002)(7416002)(6666004)(5660300002)(316002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?KrNGaVcmbfsvjU583W/+IEk8/avYSuOHZBMGfkymmmUL1tB7+jwxsdD8J2MY?= =?us-ascii?Q?DSycVtWTVeYnThoO1Ac1hZxTLNUB7zXx53k9bLpUlQ6Kvua7D3IdAuSxKRfC?= =?us-ascii?Q?HHdefHfh3T6c6HI4MZB7mBU8egpqQrn4NkkUWVkAmk9pUN3Fv3Zg2GBtfYit?= =?us-ascii?Q?SeOEt/hOEYyDD1CS5p9owaUAIvk2xkv8ft7JjfeIdnYprkckhQX+KPkMgP48?= =?us-ascii?Q?7nww5F1xw5HqiL/25wl/gUNfz2SDACU4RMwOaugQcAfIF8xwaF6rCIXh5osg?= =?us-ascii?Q?LCmJUuRPuWZEZESXmyccB4RV6gHvAkE5yz1HVkowFYLAGhno+P9UNS81EIzy?= =?us-ascii?Q?ONbonQdPwU9Djdgj3x/BFqtqoLLC+Ul8cr8nVJxNTy/gBmyuM7HaOb+qdUKK?= =?us-ascii?Q?zrVl4l+i1JSNwilXBLlfi1dsSCm5GwsVFQI3/4qNH2NBMFqzwIT6jBvSZZI6?= =?us-ascii?Q?H5t9fkmtEBmNKqag1BaCoS4hTCc0ujiX6cefsG418y9uIUJbZ522PDZSFcgh?= =?us-ascii?Q?zxQAOfRW+/oMYawh+GtppqxjbpeA58oyrcyBdC1u71bN0QB9mbsWK5VJrtgm?= =?us-ascii?Q?njIYRIAu/7TC8nSz4Soo4mlng+GIewKu+CLYNJvonM60zr8o6ei835DLHCf3?= =?us-ascii?Q?PuFqErW6HCKu7QYQ++NcVjuP9PnPL3QdSyD5psh8Ie5jtDCwCbEbWYp8j5l3?= =?us-ascii?Q?G+6Ymza5jnwoghoq4jFdf3mSLNvOjlaMZpwvxCYpLzM98rg0+aXZN12850kv?= =?us-ascii?Q?yztwg9Hzjzr4cX8hxQgnYrMUNOLhMzvDWveG3LwBRDesWHRbZxm3CBd4qt1L?= =?us-ascii?Q?oloWH5f9SoNVzJ71jps/YYOkHAK3S+hFh3OsHyKDhBLh9EH3ZZQ7x0O+yf0g?= =?us-ascii?Q?VynSWkZeZaUmwTu+/ATLXreuAM8RNZ55ypc9ZS/zMTpxtCKE7LRhi3ZrAHur?= =?us-ascii?Q?lEuBjttYWiMmuV10rUDHc5RcX6M+ViR0MDJwKaTBN7/+cY7UkjnrxVPUVXjP?= =?us-ascii?Q?Alko51LUvjVU4MKzWSswlZurFJGD6xH5GM5//GR3/D+Jc0Ui6N0qAZ6Z3YRc?= =?us-ascii?Q?4g0M3jYhyGx0Tpa8bshMAx/cDaJKq+hdWsheGkcYjZJ8HSeFK1h8Mu7NbW/a?= =?us-ascii?Q?RRBo6aczTl2JnX37XJfK1PiqhmV3XCfGX+YtgYV9aBiDSEQ72/RFZzPLC4Fn?= =?us-ascii?Q?m50Dd6R+9XihbULw46R8yPD1fH92frxTK+l5DIcfWjgfzUTqepB+uAM+owZk?= =?us-ascii?Q?DLOdSpGPCXFKwxZZ9SlGwdXco5CiKwIfzJ3zCO58kiGnkjAepWujfTUEQ602?= =?us-ascii?Q?WUE47PkSnfAu+Urio/LtLj+ZwZsIgAgzy/mjQIf2mubJDJZlBAD47KBf1FQY?= =?us-ascii?Q?yVfjTWPlEcKRSA9LrE2Ekw2ylgfZdlyePhT2bUI/+YJ7SP92tWfdRoy2OhGE?= =?us-ascii?Q?+vbwSy/nm2RUEJz18pnGOao3z1gLsKaKlHQKW6SF+y76JIcMNveUFC9KNpkz?= =?us-ascii?Q?fkNchtKub40hhvyHp+VXpW+n6VuipkNVE42WC/147bxtb21gkfLOynChaFiH?= =?us-ascii?Q?sHbGMDSACDQWo1iWRHFNmvWZZEIG29hzILlkAFkqmSims3jTczBim0ClXnc4?= =?us-ascii?Q?Zj/yD/HfW3i9jP9LdaTyBOGrin6gCxNbmXff9+U4IsZ0Kh86PSQWAq2HaEcq?= =?us-ascii?Q?8lB+eA=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a2feccb-9005-4255-0d30-08d9ec24131f X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 23:29:53.4978 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nW5edfpJf7M9cxRbB/U8bl710U5iP0L9ZmFPfFxQQPTskpD06if7xfRtFb3/utSeaXmOX/axZs8V40HBDxxSv0SB8Olppe2TT084c3I8S64= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB3007 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10253 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202090122 X-Proofpoint-GUID: HJ6CKZzgio3Gs4DxOE79OeuPAvQt7GlB X-Proofpoint-ORIG-GUID: HJ6CKZzgio3Gs4DxOE79OeuPAvQt7GlB Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Qemu will create vhost devices in the kernel which perform network, SCSI, etc IO and management operations from worker threads created by the kthread API. Because the kthread API does a copy_process on the kthreadd thread, the vhost layer has to use kthread_use_mm to access the Qemu thread's memory and cgroup_attach_task_all to add itself to the Qemu thread's cgroups, and it bypasses the RLIMIT_NPROC limit. This patch adds a new struct vhost_task which can be used instead of kthreads. They allow the vhost layer to use copy_process and inherit the userspace process's mm and cgroups and the task is accounted for under the userspace's nproc count. Signed-off-by: Mike Christie --- MAINTAINERS | 2 + drivers/vhost/Kconfig | 5 ++ include/linux/sched/vhost_task.h | 23 ++++++ kernel/Makefile | 1 + kernel/vhost_task.c | 123 +++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 include/linux/sched/vhost_task.h create mode 100644 kernel/vhost_task.c diff --git a/MAINTAINERS b/MAINTAINERS index 3e461db9cd91..4a3d9541e3cc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20477,7 +20477,9 @@ L: virtualization@lists.linux-foundation.org L: netdev@vger.kernel.org S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git +F: kernel/vhost_task.c F: drivers/vhost/ +F: include/linux/sched/vhost_task.h F: include/linux/vhost_iotlb.h F: include/uapi/linux/vhost.h =20 diff --git a/drivers/vhost/Kconfig b/drivers/vhost/Kconfig index 587fbae06182..b455d9ab6f3d 100644 --- a/drivers/vhost/Kconfig +++ b/drivers/vhost/Kconfig @@ -13,9 +13,14 @@ config VHOST_RING This option is selected by any driver which needs to access the host side of a virtio ring. =20 +config VHOST_TASK + bool + default n + config VHOST tristate select VHOST_IOTLB + select VHOST_TASK help This option is selected by any driver which needs to access the core of vhost. diff --git a/include/linux/sched/vhost_task.h b/include/linux/sched/vhost_t= ask.h new file mode 100644 index 000000000000..50d02a25d37b --- /dev/null +++ b/include/linux/sched/vhost_task.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_VHOST_TASK_H +#define _LINUX_VHOST_TASK_H + +#include + +struct task_struct; + +struct vhost_task { + int (*fn)(void *data); + void *data; + struct completion exited; + unsigned long flags; + struct task_struct *task; +}; + +struct vhost_task *vhost_task_create(int (*fn)(void *), void *arg, int nod= e); +__printf(2, 3) +void vhost_task_start(struct vhost_task *vtsk, const char namefmt[], ...); +void vhost_task_stop(struct vhost_task *vtsk); +bool vhost_task_should_stop(struct vhost_task *vtsk); + +#endif diff --git a/kernel/Makefile b/kernel/Makefile index 56f4ee97f328..d82f388082b8 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -15,6 +15,7 @@ obj-y =3D fork.o exec_domain.o panic.o \ obj-$(CONFIG_USERMODE_DRIVER) +=3D usermode_driver.o obj-$(CONFIG_MODULES) +=3D kmod.o obj-$(CONFIG_MULTIUSER) +=3D groups.o +obj-$(CONFIG_VHOST_TASK) +=3D vhost_task.o =20 ifdef CONFIG_FUNCTION_TRACER # Do not trace internal ftrace files diff --git a/kernel/vhost_task.c b/kernel/vhost_task.c new file mode 100644 index 000000000000..4ab1c195bc76 --- /dev/null +++ b/kernel/vhost_task.c @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2021 Oracle Corporation + */ +#include +#include +#include +#include +#include + +enum vhost_task_flags { + VHOST_TASK_FLAGS_STOP, +}; + +static void vhost_task_fn(void *data) +{ + struct vhost_task *vtsk =3D data; + int ret; + + ret =3D vtsk->fn(vtsk->data); + complete(&vtsk->exited); + do_exit(ret); +} + +/** + * vhost_task_stop - stop a vhost_task + * @vtsk: vhost_task to stop + * + * Callers must call vhost_task_should_stop and return from their worker + * function when it returns true; + */ +void vhost_task_stop(struct vhost_task *vtsk) +{ + pid_t pid =3D vtsk->task->pid; + + set_bit(VHOST_TASK_FLAGS_STOP, &vtsk->flags); + wake_up_process(vtsk->task); + /* + * Make sure vhost_task_fn is no longer accessing the vhost_task before + * freeing it below. If userspace crashed or exited without closing, + * then the vhost_task->task could already be marked dead so + * kernel_wait will return early. + */ + wait_for_completion(&vtsk->exited); + /* + * If we are just closing/removing a device and the parent process is + * not exiting then reap the task. + */ + kernel_wait4(pid, NULL, __WCLONE, NULL); + kfree(vtsk); +} +EXPORT_SYMBOL_GPL(vhost_task_stop); + +/** + * vhost_task_should_stop - should the vhost task return from the work fun= ction + */ +bool vhost_task_should_stop(struct vhost_task *vtsk) +{ + return test_bit(VHOST_TASK_FLAGS_STOP, &vtsk->flags); +} +EXPORT_SYMBOL_GPL(vhost_task_should_stop); + +/** + * vhost_task_create - create a copy of a process to be used by the kernel + * @fn: thread stack + * @arg: data to be passed to fn + * @node: numa node to allocate task from + * + * This returns a specialized task for use by the vhost layer or NULL on + * failure. The returned task is inactive, and the caller must fire it up + * through vhost_task_start(). + */ +struct vhost_task *vhost_task_create(int (*fn)(void *), void *arg, int nod= e) +{ + struct kernel_clone_args args =3D { + .flags =3D CLONE_FS | CLONE_UNTRACED | CLONE_VM, + .exit_signal =3D 0, + .stack =3D (unsigned long)vhost_task_fn, + .worker_flags =3D USER_WORKER | USER_WORKER_NO_FILES | + USER_WORKER_SIG_IGN, + }; + struct vhost_task *vtsk; + struct task_struct *tsk; + + vtsk =3D kzalloc(sizeof(*vtsk), GFP_KERNEL); + if (!vtsk) + return ERR_PTR(-ENOMEM); + + init_completion(&vtsk->exited); + vtsk->data =3D arg; + vtsk->fn =3D fn; + args.stack_size =3D (unsigned long)vtsk; + + tsk =3D copy_process(NULL, 0, node, &args); + if (IS_ERR(tsk)) { + kfree(vtsk); + return NULL; + } + + vtsk->task =3D tsk; + + return vtsk; +} +EXPORT_SYMBOL_GPL(vhost_task_create); + +/** + * vhost_task_start - start a vhost_task created with vhost_task_create + * @vtsk: vhost_task to wake up + * @namefmt: printf-style format string for the thread name + */ +void vhost_task_start(struct vhost_task *vtsk, const char namefmt[], ...) +{ + char name[TASK_COMM_LEN]; + va_list args; + + va_start(args, namefmt); + vsnprintf(name, sizeof(name), namefmt, args); + set_task_comm(vtsk->task, name); + va_end(args); + + wake_up_new_task(vtsk->task); +} +EXPORT_SYMBOL_GPL(vhost_task_start); --=20 2.25.1 From nobody Sun Jun 28 08:41:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0B34C433EF for ; Wed, 9 Feb 2022 23:30:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229924AbiBIXan (ORCPT ); Wed, 9 Feb 2022 18:30:43 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:52568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbiBIXaP (ORCPT ); Wed, 9 Feb 2022 18:30:15 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A4E4E0513B7 for ; Wed, 9 Feb 2022 15:30:18 -0800 (PST) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 219KLRfZ013540; Wed, 9 Feb 2022 23:29:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=ZwRoUTCdhHp+eUdKNxuRYpvCkMuqJs+ple1/71xBtLY=; b=DYGlGe/Zcfa8qZXJoq3iyBlThExTWda9h+D9jZZ+FP3X/3eZZ8jl/4MMvmXa3dlFrnOy E1c8a/H1mF5IUJ27p3iSsFkS3gUsYEjCH21kk49FM8pjoinGTVwZd8fhu2BNWjB1TkyV VSbo+GFIT3510rFzH/9956UUltjPm7YYHe7vL4BabhM5kA02+mAgS3zhUNB+gpINcRCH jS6O4eqobDNf/i5RwELC2oNtqMAQ/Ixl94YDqZr8B3swASj1MXEfzZjsbrN8/k1T0Q+t 9J8ZTN2To+QUDRfuwU+Xt8lJfwAzl39C8XxfzOmdRlviw2YyG+JYwwu+5u9bLVGg6xAE uw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e345sr1ks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:59 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 219NFrFb117827; Wed, 9 Feb 2022 23:29:57 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2170.outbound.protection.outlook.com [104.47.73.170]) by userp3030.oracle.com with ESMTP id 3e1ec3m196-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iKZrgfF66OggA4Mnhz+W8wzjG4JZfZtxTWEAs/vS+1IhHnNPPTDizaNumuMhx3XDwYn/p5P1NN3FDIt9JP3xNgwRZHyYMwZ0BAQsW1rxOBV3R9AjAcS2V8tlmQ1wBsVkV6cu/vjAdaYG/WAwwuC0UoCZv8z6TgWojPpticaRI7rcAdUdqgUDVMTDXt2qcKFF3FRuAuxsWUOKMZPjigj630SWE+e7ZGnOqdvbW65wiSVdAfGsI3jcT3SzcjgK54Q+AmUxPVzAhbUpinZZGs7BN7C4SlHkyM++X//qpbpcVpTCrd5QQaS07/gotE3ENPqJH5BYgICj9e+9so/UCeL1fw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZwRoUTCdhHp+eUdKNxuRYpvCkMuqJs+ple1/71xBtLY=; b=mYnnKU3T3lgPHcEcmSsq3vnvRDZq1Pxwb1fTOmHy3hWEigwj7uEYrd1SVPNSIPyNd0bq5jjPJM3TPr4xDvMu8roYImVJRuoGNWrEKdJUvsg5mQciRMA4YgCO+bamee9MZOTWcDGsu5iCzKyDmv0RylNkCLEKNizth2jpC7YHI/MBiql/G4cSc23ADS7l7FJksz8+HOo6UotYqMJY5hlAQkDqE9uCp+X46xwQpS9drvRUEXev/LNoS2CXEaM/3k/K50q+NFJGrZPTDkDzTVEQUnr5d0/ZkccfiQQUQOs5vxhe2dGz3rma1L10b9LvFcWgK5l/Qp+s2ZnLYPaI1Tlmtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZwRoUTCdhHp+eUdKNxuRYpvCkMuqJs+ple1/71xBtLY=; b=g4QCR3/RSWstSioPC8QzR9E9Ff7qx20xcMjQRALNTeZBRPtGLIxeH57jTXoE6SsyS89/P+rEtYw/c7AxHJfDmsg4C6A+HD2wqqYUeoArtXJ+F8GWemoxPaBP4v+Zjj6YUvy+PVSSwQMP1fBCMRe+488RfDgoMjscdePrCZu+Z0Q= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by SN6PR10MB3007.namprd10.prod.outlook.com (2603:10b6:805:d9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Wed, 9 Feb 2022 23:29:54 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5%5]) with mapi id 15.20.4951.019; Wed, 9 Feb 2022 23:29:54 +0000 From: Mike Christie To: geert@linux-m68k.org, hdanton@sina.com, hch@infradead.org, stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org, christian.brauner@ubuntu.com, axboe@kernel.dk, ebiederm@xmission.com, linux-kernel@vger.kernel.org Cc: Mike Christie , Christoph Hellwig Subject: [PATCH V8 7/8] vhost: move worker thread fields to new struct Date: Wed, 9 Feb 2022 17:29:38 -0600 Message-Id: <20220209232939.9169-8-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209232939.9169-1-michael.christie@oracle.com> References: <20220209232939.9169-1-michael.christie@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR03CA0043.namprd03.prod.outlook.com (2603:10b6:610:b3::18) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 37efed19-2ac5-44c1-7ba8-08d9ec241391 X-MS-TrafficTypeDiagnostic: SN6PR10MB3007:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Nb/GK5xmn2ksqs1JPnCRmA740ZFnRzf+jT1mta14NgE73VJL0T2c6aFL2pz40pjeeyuRZ2c8w3gX1mFsSXLFR0LYkNJ9RJkKtBTjIIJGbK0h2rtrh9WE3aeMBB7MUfWUVtrEIPYNlmbiJDyl/qXUebyPPomOeZ3S4uNZtZRNKGVRcR/yWPCOug/BRmj5ZcVEoEsOP6eJ7EOSAOTKynRPalGEz6REF1g+K3su2limC07R7gMsMGyXvqLfwOT6KV5bmO6gid2aGzhLWvJKLHZS+MJglyLPmqQxudDG+CGvrw8SskuOz74blO1lb9LK6Z72aJ6HPxTltR8h4T9x8KdPw4uAsRREeNWjI3KJDriRfYo95+wj9GQIXTE9/62K+ClpJQk3EI3Swmmg2EB6vCRJfHeco1qu3XSBEw1aZqZvLQFHVcGx4OHltF/bAX2YdPKkeCeysy6wj2jHpbNCMk5Q8jSrsb8k5r61JOFWqx4U+Jjq9ul/9frg86QgWcrmM42TmlzAR1fjHYHXnMYpdDf10muxqbZSoXeAZ8LGRzbnWJUKxNEcPuaRZCjqnnC4t53ScOl3F5wcE+RmlmqIbl7bBu7Z8CZ1bp45P62Mu2CcnrgdT9FLzaW9aULVPNGw6adnGylpI5pfIF2vp9AkEHdeB1HiJZXcJHz5AhrGqboQzwhsfFTcr1C4hk5V7TDJDrSpFgAM8SrdKTfLfcyqaajiDPpFJRhyuJj6rHZbiiuJ73g= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR10MB1466.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(921005)(86362001)(508600001)(2616005)(1076003)(2906002)(36756003)(26005)(186003)(83380400001)(6486002)(6506007)(8936002)(52116002)(38350700002)(38100700002)(54906003)(66476007)(66556008)(66946007)(4326008)(8676002)(7416002)(6666004)(5660300002)(316002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ZmxdVLYbkfZA+/j4aE4E/O/Z0WYCyzznoA95Rl8MIorzW65C/ZGetENdvAxc?= =?us-ascii?Q?d1v3mn8RPJ3DN8Iz5B+fp3ddCa7A9Dj9trMmSwNQc7EcDU4FcxEzJZ/zjZHz?= =?us-ascii?Q?rixhgwrNklJm87Kj0AypRZ4lZWqMtI/W1gwl6TqlDizEEVGbEdcXJMXPNK3i?= =?us-ascii?Q?6ZhS+tt3FvFpOwPoOWHTQXx/OJ2hmHgsxffms1uZQyGYnGXI+rd7bhTZM9vL?= =?us-ascii?Q?17XkNzb9/26a0x3o0k2A5HxZuDLCVAPJ/ZJqB3aL/plhMSy4m5p2uvJ3od3l?= =?us-ascii?Q?3rqU+zRP693uqwEbRamy8rO6IzXUxGn/aUWdXviChsCjvreOf3aA2QTLjxek?= =?us-ascii?Q?c3ui8APq5NiXVsqwA0bykEaLOllGMIXnFE4lKp/3SkTqnDT1EBp+oAOYp7nM?= =?us-ascii?Q?juIlRIMXQIsE8Vhd7tI80TPrUbwJPUitCFzcfO1P0eN2x05zkO3LlBotcaDq?= =?us-ascii?Q?ZCz4sr+4HD5+VAsSW3/QyoUtrBgj4JSkJNade81LdnCafoHYiPrtRVfM0ctV?= =?us-ascii?Q?uwL26bt4GpQh9ykLRBUki7Kpb/0sW/PRkHlWQ3pFnB7viFYEp/foHYhtaiQ/?= =?us-ascii?Q?J4oGLYSuYLi0hcBzWszrdmVM6wfI+dFVhsRw5TZ9E3C+Nn+ww7t0LI8SGjpn?= =?us-ascii?Q?/eOGjn9xW1q//AlPKEqVjG9pDrOQDRFFK1V5FgfvV5qbcinQ7k0rzKhmSOex?= =?us-ascii?Q?VkZ2BCAzQPG0O0VSvIwpw+0+QmG95COG07BmRn16u+Oh+Y1ZaSbB6N/c8P+H?= =?us-ascii?Q?qIgs64sR1Tz4JE5lIeUOwI01MF3qTzi4SpKf+oScba38jurynV5770WoTFFB?= =?us-ascii?Q?PlFgI/sopuYy8YxlakXM5U+DVPYved9ZGV5y5faAw/QQ4lAS58Ckl710clMR?= =?us-ascii?Q?VFp6FzutWRHqmr5DheFFeYFx28WMMbRqvP7L/NqXTTsFrrwGbD0NcaZMmLck?= =?us-ascii?Q?RBgvkZSV+VH2HefJ31pfX5vHQBJTT+i7flMfDD/Vs4/H0dpLXWmy3MhEeVlm?= =?us-ascii?Q?ctuE0I6BLRz65ZFhpYvRGqk0PmoiXym/jY8dzyxa85AP9cEZMv48Kbt1P0O3?= =?us-ascii?Q?0VDPRYa3UHVJ8pGoM0R+0Xsi0554Bx69pKqzjd+2Kz32OtIutn0IYqi2DLhp?= =?us-ascii?Q?RIBmwcUtMuy/5EY7staH07WIe7v9+9Kq6p4DXbph0w8egAakyLdijdEk2+v7?= =?us-ascii?Q?taecI1/Ta4v6RQq/xMeW6sseHvAzstHxVSLykTfjny/wtXudOL/w7XRYn3ul?= =?us-ascii?Q?zkYlfIKiuxeFCgn1r1XDUtg4/BjX2gWhIzRE5o+CWQHNcW/awIxwP3wefzfx?= =?us-ascii?Q?ipGtFSl+GJRQ7NVUuGzR8i/DXffaynLqgPdLdoER5iVzzOo6yIhsZvqeg1Fk?= =?us-ascii?Q?SkRvjr7w4NqQuuKZtwYDHredVtWwPMJdBm+txlZrCzsczr1iwzC70p0E8CPa?= =?us-ascii?Q?TMzwJzxJ7xNX4Hk9jPHj/gr4DCWnco6Nm9sh/OifEVQJhMRX7shgvKkWXpqn?= =?us-ascii?Q?wMURWfV0mAOg0P6VfeQ4DirAobGHfzkcdMr+9IRahGY3ngXcLOtgpJdbdbyY?= =?us-ascii?Q?WDXyQHx9sjBb9LicGgfi1ZwopICay301JR1+piI3oLkHHBaP2Ktm8199r+Xd?= =?us-ascii?Q?4FTsiEAkyTPFfxOpz4IMjpRINyyV4PttM0QK6P3xXLzKjQGplz2aEnW2GNWV?= =?us-ascii?Q?0iaz1Q=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37efed19-2ac5-44c1-7ba8-08d9ec241391 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 23:29:54.2477 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eRit/Vpn2ZowpLo0vNVbrHpR56q5fnHL4Q5thnQNegU3QuTMzYCw/q32ePlaIEWTWrklWP8XLEkvx+IXZ8bnt8/CmgTo4Pa6VTityEvE4ms= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB3007 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10253 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202090122 X-Proofpoint-GUID: sq1xv2t0mbvOufOdpDkicR01qRebeRr_ X-Proofpoint-ORIG-GUID: sq1xv2t0mbvOufOdpDkicR01qRebeRr_ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This is just a prep patch. It moves the worker related fields to a new vhost_worker struct and moves the code around to create some helpers that will be used in the next patch. Signed-off-by: Mike Christie Reviewed-by: Stefan Hajnoczi Acked-by: Michael S. Tsirkin Reviewed-by: Christoph Hellwig --- drivers/vhost/vhost.c | 98 ++++++++++++++++++++++++++++--------------- drivers/vhost/vhost.h | 11 +++-- 2 files changed, 72 insertions(+), 37 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 59edb5a1ffe2..c9a1f706989c 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -263,8 +263,8 @@ void vhost_work_queue(struct vhost_dev *dev, struct vho= st_work *work) * sure it was not in the list. * test_and_set_bit() implies a memory barrier. */ - llist_add(&work->node, &dev->work_list); - wake_up_process(dev->worker); + llist_add(&work->node, &dev->worker->work_list); + wake_up_process(dev->worker->task); } } EXPORT_SYMBOL_GPL(vhost_work_queue); @@ -272,7 +272,7 @@ EXPORT_SYMBOL_GPL(vhost_work_queue); /* A lockless hint for busy polling code to exit the loop */ bool vhost_has_work(struct vhost_dev *dev) { - return !llist_empty(&dev->work_list); + return dev->worker && !llist_empty(&dev->worker->work_list); } EXPORT_SYMBOL_GPL(vhost_has_work); =20 @@ -343,7 +343,8 @@ static void vhost_vq_reset(struct vhost_dev *dev, =20 static int vhost_worker(void *data) { - struct vhost_dev *dev =3D data; + struct vhost_worker *worker =3D data; + struct vhost_dev *dev =3D worker->dev; struct vhost_work *work, *work_next; struct llist_node *node; =20 @@ -358,7 +359,7 @@ static int vhost_worker(void *data) break; } =20 - node =3D llist_del_all(&dev->work_list); + node =3D llist_del_all(&worker->work_list); if (!node) schedule(); =20 @@ -368,7 +369,7 @@ static int vhost_worker(void *data) llist_for_each_entry_safe(work, work_next, node, node) { clear_bit(VHOST_WORK_QUEUED, &work->flags); __set_current_state(TASK_RUNNING); - kcov_remote_start_common(dev->kcov_handle); + kcov_remote_start_common(worker->kcov_handle); work->fn(work); kcov_remote_stop(); if (need_resched()) @@ -487,7 +488,6 @@ void vhost_dev_init(struct vhost_dev *dev, dev->byte_weight =3D byte_weight; dev->use_worker =3D use_worker; dev->msg_handler =3D msg_handler; - init_llist_head(&dev->work_list); init_waitqueue_head(&dev->wait); INIT_LIST_HEAD(&dev->read_list); INIT_LIST_HEAD(&dev->pending_list); @@ -579,10 +579,60 @@ static void vhost_detach_mm(struct vhost_dev *dev) dev->mm =3D NULL; } =20 +static void vhost_worker_free(struct vhost_dev *dev) +{ + struct vhost_worker *worker =3D dev->worker; + + if (!worker) + return; + + dev->worker =3D NULL; + WARN_ON(!llist_empty(&worker->work_list)); + kthread_stop(worker->task); + kfree(worker); +} + +static int vhost_worker_create(struct vhost_dev *dev) +{ + struct vhost_worker *worker; + struct task_struct *task; + int ret; + + worker =3D kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT); + if (!worker) + return -ENOMEM; + + dev->worker =3D worker; + worker->dev =3D dev; + worker->kcov_handle =3D kcov_common_handle(); + init_llist_head(&worker->work_list); + + task =3D kthread_create(vhost_worker, worker, "vhost-%d", current->pid); + if (IS_ERR(task)) { + ret =3D PTR_ERR(task); + goto free_worker; + } + + worker->task =3D task; + wake_up_process(task); /* avoid contributing to loadavg */ + + ret =3D vhost_attach_cgroups(dev); + if (ret) + goto stop_worker; + + return 0; + +stop_worker: + kthread_stop(worker->task); +free_worker: + kfree(worker); + dev->worker =3D NULL; + return ret; +} + /* Caller should have device mutex */ long vhost_dev_set_owner(struct vhost_dev *dev) { - struct task_struct *worker; int err; =20 /* Is there an owner already? */ @@ -593,36 +643,21 @@ long vhost_dev_set_owner(struct vhost_dev *dev) =20 vhost_attach_mm(dev); =20 - dev->kcov_handle =3D kcov_common_handle(); if (dev->use_worker) { - worker =3D kthread_create(vhost_worker, dev, - "vhost-%d", current->pid); - if (IS_ERR(worker)) { - err =3D PTR_ERR(worker); - goto err_worker; - } - - dev->worker =3D worker; - wake_up_process(worker); /* avoid contributing to loadavg */ - - err =3D vhost_attach_cgroups(dev); + err =3D vhost_worker_create(dev); if (err) - goto err_cgroup; + goto err_worker; } =20 err =3D vhost_dev_alloc_iovecs(dev); if (err) - goto err_cgroup; + goto err_iovecs; =20 return 0; -err_cgroup: - if (dev->worker) { - kthread_stop(dev->worker); - dev->worker =3D NULL; - } +err_iovecs: + vhost_worker_free(dev); err_worker: vhost_detach_mm(dev); - dev->kcov_handle =3D 0; err_mm: return err; } @@ -712,12 +747,7 @@ void vhost_dev_cleanup(struct vhost_dev *dev) dev->iotlb =3D NULL; vhost_clear_msg(dev); wake_up_interruptible_poll(&dev->wait, EPOLLIN | EPOLLRDNORM); - WARN_ON(!llist_empty(&dev->work_list)); - if (dev->worker) { - kthread_stop(dev->worker); - dev->worker =3D NULL; - dev->kcov_handle =3D 0; - } + vhost_worker_free(dev); vhost_detach_mm(dev); } EXPORT_SYMBOL_GPL(vhost_dev_cleanup); diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 638bb640d6b4..102ce25e4e13 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -25,6 +25,13 @@ struct vhost_work { unsigned long flags; }; =20 +struct vhost_worker { + struct task_struct *task; + struct llist_head work_list; + struct vhost_dev *dev; + u64 kcov_handle; +}; + /* Poll a file (eventfd or socket) */ /* Note: there's nothing vhost specific about this structure. */ struct vhost_poll { @@ -148,8 +155,7 @@ struct vhost_dev { struct vhost_virtqueue **vqs; int nvqs; struct eventfd_ctx *log_ctx; - struct llist_head work_list; - struct task_struct *worker; + struct vhost_worker *worker; struct vhost_iotlb *umem; struct vhost_iotlb *iotlb; spinlock_t iotlb_lock; @@ -159,7 +165,6 @@ struct vhost_dev { int iov_limit; int weight; int byte_weight; - u64 kcov_handle; bool use_worker; int (*msg_handler)(struct vhost_dev *dev, struct vhost_iotlb_msg *msg); --=20 2.25.1 From nobody Sun Jun 28 08:41:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F9D8C433EF for ; Wed, 9 Feb 2022 23:31:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230317AbiBIXbH (ORCPT ); Wed, 9 Feb 2022 18:31:07 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:52674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230053AbiBIXaS (ORCPT ); Wed, 9 Feb 2022 18:30:18 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3D90E05ADC0 for ; Wed, 9 Feb 2022 15:30:18 -0800 (PST) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 219KAjBl027666; Wed, 9 Feb 2022 23:30:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=PXXdV0JicyRwxDzTfgVc9CnWFDR1h6e3mgSqpxLKbUs=; b=di8OuzAXxtJZazxtMZ5SbNRmE9qYiwwgFB6rkEE7qRyifJ11sGgyPSS6GSI6VbWRFSqR 39puxRp6bRpxKL10aAgOJs9AZUOsMg8M+wIYBU/5CiY+AzGrgv6JYlRKEdWxqUxQDKyX 9mD4oZu8c1axTI5nH9zaOHDuTJvHX5YcEkihMCVT0ELjktg9yPqw4h2AJN+jOgnVigJy nwy/SslVid5rIMiRD3A7cUa+PvnYmWDyeL2990mIqe0WePRmLR/lr6kOEOvuR98WddBh dpiHrE8ytlCsAp7C03yMykFn9XzcHQFPtl/kTxw6UrwDYXuAeNQQHGQhNGEo44tojM54 1Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3e3hdsx383-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:59 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 219NFrFc117827; Wed, 9 Feb 2022 23:29:58 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2170.outbound.protection.outlook.com [104.47.73.170]) by userp3030.oracle.com with ESMTP id 3e1ec3m196-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 09 Feb 2022 23:29:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VzI8jc8suHAIsELU0vZc3cHrClwNid/Q45PXBGaYSHsAgmsxo7el3J2lzQ4XPT8aBVhS/Gn73ewxyFJIj0kCDjxj8a9FVletUEfd9Q0eFKumMchNPpcnSyd+C6qu1qvg3eQ1PkwoPxO5+CdwM7Bu38V7Nzx93Cf+cuRgK7sFPhEawnbcHN6hW3g7GIiaSZx8bl8ttI/yUuMZrUqv0lLCPTTLrH3TIGVgXEuXORa8vgVQA4Ahtn6dDLi39Bhya+I/qd8O302EtjFi32GZ4UFqeyD7OHQ0JRl5OL/1MKm+KayBr9EWd/brRdcnkGnX6nSdi2Ryv3AJJ7OAPjePLmYnqA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PXXdV0JicyRwxDzTfgVc9CnWFDR1h6e3mgSqpxLKbUs=; b=ga+2hVyy7Ay3frl6sIaUq91qZplLEPHiUoKebN44psVgsvpx22kHdv1U6xId1GuK0l6C/iMVETew93zm1b0We0uKzd+9JY8k2jQ/iIbT50KPbTTSEQxIaqkRG/M92m/2K/IjRCLWEsJ6jyJbcHAFOFFYT3MmMWL9RssjCDbst8kx2mkfPo808gQUdHCD+UkCalKAVUwHxhQdN1AIOJ+OOBDXnjl/8SCfZYl+L0o/VXaUZKM7SO5GB4KjdQlHcOxaNBoizClzAmpX0zQTh5WULcAQ5vCPAPE5P6OkTGbDh29DNWwLPsThZ4S7lXMMujl58Kewygv1L+3HY0axYKY50Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PXXdV0JicyRwxDzTfgVc9CnWFDR1h6e3mgSqpxLKbUs=; b=curc3ZGjSjC7bYFI+ejp7gnEzR6zWVilaThwHJzPBuG/A9kJ4LO2ANUdmqGIdWpuS3DJfTJ31wAPKE/TIQ33ZxCfMDG6xwaYOju/HoJaEsDrFWziI/kVit3CuvdQph5bmo8hj9AW+lx5JnlQ32YkXIqrp/ppmIh1HRZDOrJ5JTs= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by SN6PR10MB3007.namprd10.prod.outlook.com (2603:10b6:805:d9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Wed, 9 Feb 2022 23:29:55 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::3448:8685:9668:b4d5%5]) with mapi id 15.20.4951.019; Wed, 9 Feb 2022 23:29:55 +0000 From: Mike Christie To: geert@linux-m68k.org, hdanton@sina.com, hch@infradead.org, stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org, christian.brauner@ubuntu.com, axboe@kernel.dk, ebiederm@xmission.com, linux-kernel@vger.kernel.org Cc: Mike Christie Subject: [PATCH V8 8/8] vhost: use vhost_tasks for worker threads Date: Wed, 9 Feb 2022 17:29:39 -0600 Message-Id: <20220209232939.9169-9-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209232939.9169-1-michael.christie@oracle.com> References: <20220209232939.9169-1-michael.christie@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR03CA0043.namprd03.prod.outlook.com (2603:10b6:610:b3::18) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 178ea36a-d7a1-4b09-257f-08d9ec2413ff X-MS-TrafficTypeDiagnostic: SN6PR10MB3007:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:334; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ze/CADhCRIDR/3wA8YTBPcrcsY0wjlS1MniA4GUxjZCkfdcmxUaN7EE0uc5Z62MfJDMhU+JZpB/M3Grq/pn7fvZxepIVyvPj2q66EFdxKrfqcbObyverMEu0KE2hqTTm+YgrNrij1dClWfxhiyrJsYUeUlkoOyxv6VU/Ogbg2o1YWj3AczCZieSZKCzcJhgl0xHUebIOfrKOFo9tvPhp1ntHKx77uTaI0f44WKtCSZW26YoLRkt7Sq9rfHqh5fv1Ny+XeExQEkhJ8dlojGnyllZ8qbXsGz2R0tJfbnrq1yRw+hjjNsiNizBU2tC8QqudJ92QRuVjJC0gpB8/y7mR8xivt5k/XxbmIHeUfukTanAZZevWwjuVN13T6unnZQ3vgKKKBuwZAKHgjto+1cjsUKgZg09QSBEbZ8qiC+BzB8v9XmATv5logJENasgFZcoUkw8lB4Lro70YBO6bFv8LL0KtvSAfLfU0mKKRpkqzyXGckE1H0Zzl2W0zc4V9C9zKsTBF8CAu8DyTOn1Y5QyCAFUXU0/qKk6Yj2pGQneS5TCROJbyKPoXs1EzYCIbv1AnRkqrTPNPG9gqR8bmAh69aQrMm3TK/v4aHIuHWfyS2XTXY72hQLKVxqh43eyLodK23gahEk55GD1F3Q+Oj9nt89P9ufM8AgS60r+7ULeb1gQkqi2LEzC/B+KnXo31hj65teAKPZPWCwkWqEzFkysSrlFTTbEpeD9tIzy6IIszYG8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR10MB1466.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(921005)(86362001)(508600001)(2616005)(107886003)(1076003)(2906002)(36756003)(26005)(186003)(83380400001)(6486002)(6506007)(8936002)(52116002)(38350700002)(38100700002)(66476007)(66556008)(66946007)(4326008)(8676002)(7416002)(6666004)(5660300002)(316002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?w4umnrYY5aK0tMJlylJths4HQY49UEg5sPovCa+oDHPk8xTU49RbTadNlEA6?= =?us-ascii?Q?1ghk4r0kCTbyVET8zlFZLsCY0TEc3lub6vR9/K2jWD+5oypXZHLcbpbaBrk/?= =?us-ascii?Q?nhLvj96FcxM1p/77LsdVEQeQS0okxhpsqdd2AVCWcx6BvkJ9fZyZGbBYIj20?= =?us-ascii?Q?UJFxFX4K+qSCmltAjIjHUrrxwtpIQkSulxQWWLir+d6k/zHIQ6b3Hj5+6taH?= =?us-ascii?Q?Kq9RmCTi6MxzvcvcvBM6Ka98iTgwIlPHb5LLrNrxGhA2aqiOL6LyDttpih4C?= =?us-ascii?Q?bi2wNvBCkXWVzrtzauLE30vZyHBdWfysKjw5c2pSVs9lsN2GyEpm4rD/iSXj?= =?us-ascii?Q?HwdeXT4IrF8qY9OUl01AFPSk2UkjjGgpjcKUfdXT/n8orlGsE0MELhlRwOjJ?= =?us-ascii?Q?s35VUQcvYtFmU5882LvvieXaon66yezAvVsGdZKJYTtKD74nk5SAU0DpwEjA?= =?us-ascii?Q?eyCQM8OQYF+Ht8J7rojGYsIxDIi2UaGiZCMujM8rMZN6CiuILK5i2R8jGP/o?= =?us-ascii?Q?/pUY8u7Vc7r/GifG7MaXTsgi06gQbU0TSrzQNaB5LNmkllR8nbtUSoKvHqnI?= =?us-ascii?Q?XRscjLhFaLG+XmBrXDsWWz4hwuIPJXNsnRyl3FS3qYZa7nK3vDtZAJdDAsSY?= =?us-ascii?Q?U1XN9VXLEcTUHfzYy97B/maD79Z/566gmvxarHc4cdr/25pst8GfH7Izv1Mm?= =?us-ascii?Q?dVVDh1uKCxpFVFRaxBJtX/viHBed28he/k7p9hKEbOhct2sEXo4ejoQ4bQQi?= =?us-ascii?Q?FG+U0tVBuTC1tU/g+9FUa170T4wCzIjce4eddjCv26QjK7Kqfidn7AasUXfu?= =?us-ascii?Q?yWbjLe0sCjX/hn7duaK7P74AFpzyl8YCPAn7uGNQNfP4ZgtAgkx/CSHsw0eg?= =?us-ascii?Q?iuMk+9GRNIFxVryWHLGNJOXIaITqdRggOFzJEg1TpKCM0vntKj6Dp7r23rV6?= =?us-ascii?Q?Bfj3lEsXNjG6ObnT6jgBvoTsm4JZq2iiG0qawvWZR/qFmhY+WFX5En1hTPku?= =?us-ascii?Q?36FK0frkgoyX/+rjTuGMV7UhIEDVKTle2m0Ke+eflncVjuzi/VKXoBmzlNiu?= =?us-ascii?Q?ZZgLbvpKu8YiMdon3kLpJZjts3unuH/WR/rztt6ZY5xzTjgpY7f/Ggf6QrZr?= =?us-ascii?Q?TaGTuOyZkZEQrOFmqqNBAGmnOp3SIDU+Eq6yLptVkxHI4UaYnWuIAiNuTVhg?= =?us-ascii?Q?CZYI7+yIWg3WWI+7Z1BwmUqes8zYhKmV0mXvjGsc3Hs0pG3H/lzwZnpzdt02?= =?us-ascii?Q?jQ3sg9F7JPE4KMR3VNtLMhroQ+KaKxe3zONgHOWg7Snpkn07+RoMAOEknOWy?= =?us-ascii?Q?CYS6NPjwztVR4hHRYOgoA1xsA3AlHCi7aoFG+GAX8+xpAcNVO0k2+oqlPn8S?= =?us-ascii?Q?0MdRvuyYcO6l42pcqUbTmyTcQz0y7rd1Hpw/VSvn/FcKdvX68M9j/MCYGnRT?= =?us-ascii?Q?aar0zIch1lPyMum8eiI/gjaVToC5Bqe3GzbjFg0j0R9NI2QNGKmQmdKLizYt?= =?us-ascii?Q?JvClkXtf6ACLmwAYJKrGKgWFzJ6CYZNttWW0NEplfFgWPiPvmYgHKI5PuWHs?= =?us-ascii?Q?rvFreB/pgUsq9TX/i4xY/Llbybz8TrM4d9Gqf+5fwAEAAI1s80ZfYxL63SMQ?= =?us-ascii?Q?kH+t+mUVEQHiH0TFs7ttW31ELP2od6LMi6gx1KW8mK3bDEqtRd6v9YFIDeAl?= =?us-ascii?Q?fYEpBA=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 178ea36a-d7a1-4b09-257f-08d9ec2413ff X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 23:29:54.9508 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Gjjt7WWShifTxgDos3Dp6lKXNR6xO8xANeFCeOplCFV9SS8jqeP8Jv8jeEd4c7jc5EcdSOGIIXlDAjU+8jHYv8SuaBiZeiGBUKZ2ZbX/oQo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB3007 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10253 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202090122 X-Proofpoint-GUID: p-9BZ38JFy1X6KuprSzKDsypVoteTPH3 X-Proofpoint-ORIG-GUID: p-9BZ38JFy1X6KuprSzKDsypVoteTPH3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For vhost workers we use the kthread API which inherit's its values from and checks against the kthreadd thread. This results in the wrong RLIMITs being checked, so while tools like libvirt try to control the number of threads based on the nproc rlimit setting we can end up creating more threads than the user wanted. This patch has us use the vhost_task helpers which will inherit its values/checks from the thread that owns the device similar to if we did a clone in userspace. Signed-off-by: Mike Christie --- drivers/vhost/vhost.c | 58 ++++++++----------------------------------- drivers/vhost/vhost.h | 4 +-- 2 files changed, 13 insertions(+), 49 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index c9a1f706989c..ce356f5dc751 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -22,11 +22,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include @@ -264,7 +264,7 @@ void vhost_work_queue(struct vhost_dev *dev, struct vho= st_work *work) * test_and_set_bit() implies a memory barrier. */ llist_add(&work->node, &dev->worker->work_list); - wake_up_process(dev->worker->task); + wake_up_process(dev->worker->vtsk->task); } } EXPORT_SYMBOL_GPL(vhost_work_queue); @@ -344,17 +344,14 @@ static void vhost_vq_reset(struct vhost_dev *dev, static int vhost_worker(void *data) { struct vhost_worker *worker =3D data; - struct vhost_dev *dev =3D worker->dev; struct vhost_work *work, *work_next; struct llist_node *node; =20 - kthread_use_mm(dev->mm); - for (;;) { /* mb paired w/ kthread_stop */ set_current_state(TASK_INTERRUPTIBLE); =20 - if (kthread_should_stop()) { + if (vhost_task_should_stop(worker->vtsk)) { __set_current_state(TASK_RUNNING); break; } @@ -376,7 +373,7 @@ static int vhost_worker(void *data) schedule(); } } - kthread_unuse_mm(dev->mm); + return 0; } =20 @@ -517,31 +514,6 @@ long vhost_dev_check_owner(struct vhost_dev *dev) } EXPORT_SYMBOL_GPL(vhost_dev_check_owner); =20 -struct vhost_attach_cgroups_struct { - struct vhost_work work; - struct task_struct *owner; - int ret; -}; - -static void vhost_attach_cgroups_work(struct vhost_work *work) -{ - struct vhost_attach_cgroups_struct *s; - - s =3D container_of(work, struct vhost_attach_cgroups_struct, work); - s->ret =3D cgroup_attach_task_all(s->owner, current); -} - -static int vhost_attach_cgroups(struct vhost_dev *dev) -{ - struct vhost_attach_cgroups_struct attach; - - attach.owner =3D current; - vhost_work_init(&attach.work, vhost_attach_cgroups_work); - vhost_work_queue(dev, &attach.work); - vhost_work_dev_flush(dev); - return attach.ret; -} - /* Caller should have device mutex */ bool vhost_dev_has_owner(struct vhost_dev *dev) { @@ -588,14 +560,14 @@ static void vhost_worker_free(struct vhost_dev *dev) =20 dev->worker =3D NULL; WARN_ON(!llist_empty(&worker->work_list)); - kthread_stop(worker->task); + vhost_task_stop(worker->vtsk); kfree(worker); } =20 static int vhost_worker_create(struct vhost_dev *dev) { struct vhost_worker *worker; - struct task_struct *task; + struct vhost_task *vtsk; int ret; =20 worker =3D kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT); @@ -603,27 +575,19 @@ static int vhost_worker_create(struct vhost_dev *dev) return -ENOMEM; =20 dev->worker =3D worker; - worker->dev =3D dev; worker->kcov_handle =3D kcov_common_handle(); init_llist_head(&worker->work_list); =20 - task =3D kthread_create(vhost_worker, worker, "vhost-%d", current->pid); - if (IS_ERR(task)) { - ret =3D PTR_ERR(task); + vtsk =3D vhost_task_create(vhost_worker, worker, NUMA_NO_NODE); + if (!vtsk) { + ret =3D -ENOMEM; goto free_worker; } =20 - worker->task =3D task; - wake_up_process(task); /* avoid contributing to loadavg */ - - ret =3D vhost_attach_cgroups(dev); - if (ret) - goto stop_worker; - + worker->vtsk =3D vtsk; + vhost_task_start(vtsk, "vhost-%d", current->pid); return 0; =20 -stop_worker: - kthread_stop(worker->task); free_worker: kfree(worker); dev->worker =3D NULL; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 102ce25e4e13..c9f391326dd5 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -16,6 +16,7 @@ #include =20 struct vhost_work; +struct vhost_task; typedef void (*vhost_work_fn_t)(struct vhost_work *work); =20 #define VHOST_WORK_QUEUED 1 @@ -26,9 +27,8 @@ struct vhost_work { }; =20 struct vhost_worker { - struct task_struct *task; + struct vhost_task *vtsk; struct llist_head work_list; - struct vhost_dev *dev; u64 kcov_handle; }; =20 --=20 2.25.1