From patchwork Tue May 25 18:05:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 12279797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9567EC4707F for ; Tue, 25 May 2021 18:06:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 731F0613D8 for ; Tue, 25 May 2021 18:06:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231710AbhEYSHy (ORCPT ); Tue, 25 May 2021 14:07:54 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:56448 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231208AbhEYSHu (ORCPT ); Tue, 25 May 2021 14:07:50 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI6GI3108446; Tue, 25 May 2021 18:06:16 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-2020-01-29; bh=7mBm+Bv9Nw7pAlhNVJAiAXX8Qk6OFRPwIU7RbgE9xFA=; b=ZEkJs5Yu+cXDx7dq5L2O8uUhS3tCkNy/CMSs8DitD8GgLCH6WjM246FEFIZzT8ZdFWS6 2mzCVTkp0Jn5WBCmI6Cmdn4pJiJwaCNSVBP+MgQPod6Q5oBbtwEmFOaYG9qy2b2SPE/o mTrr5z+hCws/uWdlWQfn7ZGXnBcFnyASFiZDvXyDgD9uVzzk7M+Y5Mtjcz9zBth/DfZq /gv/Tba0n6sJto0gQFAMFEXjPM7JScnDXwy5qztY+Br92iuef6BsswrzFdGCGisLT6jE eUSOctNHmTj4p0BEpebfk8+vXlLtvmBVVrEY5ajYeyJn1I/sLown81B/HeEWKCtP508u HA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 38q3q8xc02-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:16 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI6DiE185024; Tue, 25 May 2021 18:06:15 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2049.outbound.protection.outlook.com [104.47.74.49]) by userp3020.oracle.com with ESMTP id 38qbqsga7e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XiRnF0ESSIHbjPuHaeO0PM1MuSZe56kDXwcdY5aisa0N3UlMuONrw/AuFz5UyTFCjyEWwJakwwjgU4rgVEVh5sp9tH4e0MoqLWgc+m3edCveUmKfNmMnSOP+c9zvHG+WcwNzSP9L1mznR/vcTd9UysnuoHW0ajJwJeXX2IelP/qGkcYj1m1XmXfexd0MLjkdk2FW9mPzW4OeZUfqynCRD92diL1yGCz6LdMkjB5QdqC1sN2NVMqZ6OjeT5n1LSNmNbE8QZoksOvPOKAGIOwJ0SfjbMbazMAPB4XKk/Cps0adYvi8are021Wx4mPUNWsH0jfNQOqPGUMNA87SN/gDOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7mBm+Bv9Nw7pAlhNVJAiAXX8Qk6OFRPwIU7RbgE9xFA=; b=bfTBmL+QFi11fsgJbNRYlks1/Tmh7MbjY9epccHxGgL43UsdvhUCCYkbZyGsNH3w8mwRvDcnK3eNg0uFDARaf9wWJR2ahDT/q6ri/4/VOdS5lUhGr4P31KoTsPvqz7DHZuqf10cn9pDgbJ/AGqFpDTHBaFX0rEIbcmAsmeTMk871oImqW1PYM82zbxt0jWEm3efcWncLbxcFJh7RyWvuVKMFhGeaX48v1N5KbsrVNbOcxFlADDn9OM9Esmu3K5RBozkuTdTwhll6WEW6BeAtvIYdEYDqxyQbzvIbtiRXn/1gN0zTde5N+DYJNcqmk7kuNX+CbDVKdrkJoRV6+g+QIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; 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=7mBm+Bv9Nw7pAlhNVJAiAXX8Qk6OFRPwIU7RbgE9xFA=; b=KJjtBF00lee4waJBdc4V5mstmfYVuRFvSplLe/XTJxXJ5oZqUGsBAe7CcrkvlpHBPvOp9AZZLFgF+UWAovnKYCpyq9WFesgDtmcHP64gyRJ7aIThKp2hnRPzuLi2z87TLfkLE4b1+zsfTpPZRKZ0+7YNFK0kyKmxe1YHHVWG2zo= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) by SJ0PR10MB4639.namprd10.prod.outlook.com (2603:10b6:a03:2db::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.25; Tue, 25 May 2021 18:06:11 +0000 Received: from BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0]) by BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0%7]) with mapi id 15.20.4173.020; Tue, 25 May 2021 18:06:11 +0000 From: Mike Christie To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, stefanha@redhat.com, pbonzini@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org Cc: Mike Christie Subject: [PATCH 1/9] vhost: move worker thread fields to new struct Date: Tue, 25 May 2021 13:05:52 -0500 Message-Id: <20210525180600.6349-2-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210525180600.6349-1-michael.christie@oracle.com> References: <20210525180600.6349-1-michael.christie@oracle.com> X-Originating-IP: [73.88.28.6] X-ClientProxiedBy: DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) To BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (73.88.28.6) by DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.12 via Frontend Transport; Tue, 25 May 2021 18:06:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fa303427-5ea2-4b41-79f2-08d91fa7c70f X-MS-TrafficTypeDiagnostic: SJ0PR10MB4639: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OvVhchLpaWc+Eb9OEFLfEc9HH8SxFZJQqmnfu1Dkhm+AbgA8vni6qf02vr1hAnkAFXYWvBCu9YjItadmL8TIZs7KLFrv+MpXZLYDtQcGyu1ME9Bb/Qp6DPj5mnNRtwmEgyI2Jli4aU/IjpHoU77qjG8udfBLUBJxFm9yVsyoTliUnIPdXZr0R3qnDkaZQT/j3rRdq/rC2nlC++wEus2DOe2aoUUSBAr90KnOcHAEGKn9Ay5BkqQAKKDV+hqsk+RCesJHJefBZzzWfjhXSTjHOgFgWRRO6RpjhzWf+WjFFpSjt2mF2VCiJYw1y5s9bstqh4ecAhYoZ8lowxXabRr8a5/KbPFmaY18+Ph+jnjh4A8zjOENPqpbZNgewJwtayikBtkciHAQQnwihaUproau0Au/PYGK8lrivPux8gJXK597Mrkc20yqEYb3YYUFiu5FkIzRd/uWGqzqWzgbBRifH8Ao004hj4dmki/bs0gAoIySxoq86T4KG3w7qe7UaqpU6tye82zZTdCbaEB6BE40EQm2Una3Y21FG2rEk3lYqM0gVyuBP7CDyCD0GcMMYdhWvFXpRLga/+Po9y4VlQ/RfGAnYyqCO/CzhjlTKy+qu1RYgrRz+H0H4kGe7xJiV2j65EYLQgnGawGq3Jwrnm+LsbM3W77XzDuc5NH9zhBz+wfqQbsG2mE2EwqVbpTrW4IX X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3573.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(396003)(376002)(366004)(136003)(346002)(36756003)(2616005)(83380400001)(4326008)(186003)(316002)(6512007)(6666004)(6486002)(1076003)(8676002)(16526019)(478600001)(2906002)(52116002)(66556008)(38350700002)(86362001)(66476007)(26005)(5660300002)(38100700002)(956004)(66946007)(8936002)(6506007)(107886003)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Cwyp0HBsjc+v2FHqpwI1Cvi8ItcnnvJIg9Ec50FOPtlvX4x3yHJH9M/ihjC0pMHWBVSZcbg69PQ1CyewftfqvxiYpnBDzHuRqk+f8yeD27E3XaewlqAMw2Pq3JaNX1+IG1j/3bJwkQXqf1KwB2rUB2yeKus/17yoE9MhUN6Cz7R/OlBTf69BvOYwQ5ck8o4zb24Cgy2DXcdWy+WzHbor+qegkoqgTehosVmutbqFndEG1lhczwX/mCf51xN5yfZWo+QZP7ZlLZ6LzEvjibgPBxNCOek7YVzpw3xbBKu62grlbITQPIb6l5WvhPJJL9uaUa0ro29mNYz/QP9kGH6YeU+TlbtTn/60WXm7dFU24Q7DmEIZ3678U44WY/IEamig2CQfStmVAm0SU4vQ3bot/jMfhMevtgI5z+uoFMnXXwYt9aPd5fEGwl3OlU+lNUvoQbEIs2NOFFBcoCnN6l26aMs2NmFptTsVLzNf8ckxiU6XDyUJhAiaUZE02oDoZlg3SkOJZhUVMzy2pb2Y8tOgfVCDzYUsuGjtQV4n84+jgD99shRGqso6zd51qoVKRY2tkhv1/t5yVaFUWCQ4H5l7acZms9LDT4IemvV79+Q6GKg6VjKBkG8VAzrCnRzbk2BPjoC8Z+ntux5N7WJ5w996oyYCaS0d/B5J/MmKzsESs3ZwmBMHku90Ho0gkql2n1SPL4Yo/ugvgeL71xDfZQl5zikcm3v/Y99tIaX1Ot+72q9cHaZ02cL6az042hR8WUJfIzCNcNIw62SEePG6vaq7i4g7gyBI30Xq3YLbfUA5IE+btNTmwq6O+19PsGNk/3v29sK1Mulxc6JMT+tTm13m92UWrRVs9VtJPGMd6NqUolLudxqDnjGO3I/Y7XsDoTou079fJ4TqskeThXe1JKugxEXzS1eTgh2R2u+ezWx5EusScAnmfbCtdzXjMSsiLO5H2qbqsLaiLACbphYzH4TWqrxB94NJ5XyM/6SLVL9LJ1rMikNpnjd1ryfj+0I5YN79wfy9AZqNYVg0LU1tquUBR/YTiX+WPPZA0wbGB3FKe+a9SCuyQk8/TJS1t/ABONR8jIIlHsxsjaxaMGznNH5soCBdKxL0N2MaNszOOUDdhD/68clA+BVf9Zmp6x/PwTAxOWIlNgsXLw7QEMDSCH5IWJQzra7dSt46kvHBNPWGajveV+B4QqXa8jtv6nMjeWWNTn0I+V8LcIJvVJjcYfjwcYFIL2Ji/FteLIwTwqDoaQb85G32hpaRe4MWit2P7nEeIYapNcNvOoCDI5IIocvdc2weSMG0YBk1Ub1/506KAhPWQFQsL9/peE9qUnZ3bfft X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa303427-5ea2-4b41-79f2-08d91fa7c70f X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3573.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2021 18:06:11.1024 (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: SWhzxd53zRNFYNFax7DefvO5+VBm58jCbCVuATghf/9JcF5lrzwR5g781nLpdxcpeFLE9/+LbSE7aeOq5q17VlSDhlzaBnNA2c+PO9Q6kJ8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4639 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 X-Proofpoint-GUID: Wl7tpj7NeluM9ThkvHN6nLrXSTupJpOe X-Proofpoint-ORIG-GUID: Wl7tpj7NeluM9ThkvHN6nLrXSTupJpOe X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 clxscore=1015 malwarescore=0 bulkscore=0 impostorscore=0 phishscore=0 spamscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org 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 patches. Signed-off-by: Mike Christie Reviewed-by: Stefan Hajnoczi --- drivers/vhost/vhost.c | 94 +++++++++++++++++++++++++++++-------------- drivers/vhost/vhost.h | 9 ++++- 2 files changed, 70 insertions(+), 33 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index b9e853e6094d..0cd19b1a832e 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -263,8 +263,8 @@ void vhost_work_queue(struct vhost_dev *dev, struct vhost_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); @@ -343,7 +343,8 @@ static void vhost_vq_reset(struct vhost_dev *dev, static int vhost_worker(void *data) { - struct vhost_dev *dev = data; + struct vhost_worker *worker = data; + struct vhost_dev *dev = worker->dev; struct vhost_work *work, *work_next; struct llist_node *node; @@ -358,7 +359,7 @@ static int vhost_worker(void *data) break; } - node = llist_del_all(&dev->work_list); + node = llist_del_all(&worker->work_list); if (!node) schedule(); @@ -487,7 +488,6 @@ void vhost_dev_init(struct vhost_dev *dev, dev->byte_weight = byte_weight; dev->use_worker = use_worker; dev->msg_handler = 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,59 @@ static void vhost_detach_mm(struct vhost_dev *dev) dev->mm = NULL; } +static void vhost_worker_free(struct vhost_dev *dev) +{ + struct vhost_worker *worker = dev->worker; + + if (!worker) + return; + + dev->worker = 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 = kzalloc(sizeof(*worker), GFP_KERNEL); + if (!worker) + return -ENOMEM; + + dev->worker = worker; + worker->dev = dev; + init_llist_head(&worker->work_list); + + task = kthread_create(vhost_worker, worker, "vhost-%d", current->pid); + if (IS_ERR(task)) { + ret = PTR_ERR(task); + goto free_worker; + } + + worker->task = task; + wake_up_process(task); /* avoid contributing to loadavg */ + + ret = vhost_attach_cgroups(dev); + if (ret) + goto stop_worker; + + return 0; + +stop_worker: + kthread_stop(worker->task); +free_worker: + kfree(worker); + dev->worker = NULL; + return ret; +} + /* Caller should have device mutex */ long vhost_dev_set_owner(struct vhost_dev *dev) { - struct task_struct *worker; int err; /* Is there an owner already? */ @@ -595,31 +644,18 @@ long vhost_dev_set_owner(struct vhost_dev *dev) dev->kcov_handle = kcov_common_handle(); if (dev->use_worker) { - worker = kthread_create(vhost_worker, dev, - "vhost-%d", current->pid); - if (IS_ERR(worker)) { - err = PTR_ERR(worker); - goto err_worker; - } - - dev->worker = worker; - wake_up_process(worker); /* avoid contributing to loadavg */ - - err = vhost_attach_cgroups(dev); + err = vhost_worker_create(dev); if (err) - goto err_cgroup; + goto err_worker; } err = vhost_dev_alloc_iovecs(dev); if (err) - goto err_cgroup; + goto err_iovecs; return 0; -err_cgroup: - if (dev->worker) { - kthread_stop(dev->worker); - dev->worker = NULL; - } +err_iovecs: + vhost_worker_free(dev); err_worker: vhost_detach_mm(dev); dev->kcov_handle = 0; @@ -712,13 +748,9 @@ void vhost_dev_cleanup(struct vhost_dev *dev) dev->iotlb = 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 = NULL; - dev->kcov_handle = 0; - } + vhost_worker_free(dev); vhost_detach_mm(dev); + dev->kcov_handle = 0; } EXPORT_SYMBOL_GPL(vhost_dev_cleanup); diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 7d5306d1229d..bfc4563e612f 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -25,6 +25,12 @@ struct vhost_work { unsigned long flags; }; +struct vhost_worker { + struct task_struct *task; + struct llist_head work_list; + struct vhost_dev *dev; +}; + /* Poll a file (eventfd or socket) */ /* Note: there's nothing vhost specific about this structure. */ struct vhost_poll { @@ -149,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; From patchwork Tue May 25 18:05:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 12279799 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 130F7C47089 for ; Tue, 25 May 2021 18:06:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA72960FE4 for ; Tue, 25 May 2021 18:06:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231975AbhEYSH5 (ORCPT ); Tue, 25 May 2021 14:07:57 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:42856 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231441AbhEYSHx (ORCPT ); Tue, 25 May 2021 14:07:53 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI58p1038630; Tue, 25 May 2021 18:06:16 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-2020-01-29; bh=xe34tHZ+UCvb6dLGEIVeD6yY1wvQS4hdwAXiIbxKTuc=; b=vMtPIugEnTu/Ar5tJB9rPUvqiRWnmBqr1jRVDTHEFwqyKUxYUiwKJ3fL6qWAfZyiREW/ r1Z6xsg7sXYevyfaEXrrnFXENzXOxDayyuJaRXM9obUQ/tmy03DWSLjr0bHzHRx8ppvM 1ldAFFoY/MhpboHArWU1kiddvghfdEwc96EltA4ihgLv/IdhXZ9dqeWuaukKQ0O15nxs apBzqcgRuuycXdPd5X74dyuNeLrtK/AeJsRZcoZwasNrPnRdG8w3SOQePPxyF3tFQubU PhRrm/XbjLvQlI4plAxzioMSl95+xHSUGwsPyQ8TZFkHHs/UACKlvS7K2ukrDsW9TWCI pQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 38rne42fxe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:16 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI6D77185054; Tue, 25 May 2021 18:06:15 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by userp3020.oracle.com with ESMTP id 38qbqsga75-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b7v+S1mDGRN1e1ljtypOESRMewCrw5Gz0QeztVR2/HT+u62bNcLaWlFC+gcGKu5WVk+8MfUf6zxgNew4dwTeNve9MPfgut1wGPA+UttpxrGSjL+6w+0eV8PDsjgGwdmKjpsLN31EwXrVpob7Hwf0w9VWB66U8tE7hwC5tvChBBOwTZLBJDTRPsjochIJ1tHKOX5jmdUCBE+oVoJAVSKBT1TqbqQUpjKrbJKtF/XhQtE5oKv/xxQlnSwFfRzoJDB4mWFSK/eXbjQe6hvPV7SphA5yDZOgMBT7eEtv6pPNhbnCpcquIs2Zxp9kGAHXlZpGqZPGx18P9I6xxAdW8eUwEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xe34tHZ+UCvb6dLGEIVeD6yY1wvQS4hdwAXiIbxKTuc=; b=AT8rGppJIUBgJu27S+Ww5MY29qygyTXWVB3C76kPG6D9pkp4ESWjwa2acoDNqWSFe3IBpeiio9S6caD17ZmC9i/Jno2Dw2woxT1wBTcSB/r0sdW13F71tnatvr8rd0GovVSVT1QCmn8cCtWC8pdcrOS5FT1BYzQtveXwijZ49gGz+PyHU6wmmhM1JP3+s9W1NQ91TGK5Lt3wHa/9VpnT1zL7ozRP+Xw3W4VpuAaIW7v8eWegfORYvDzZ5tDCYuwXDtZEwOCPPk5410nRN4Fs3U/VNDJfpb3v+VA4Sybta+0xzLKpiB52AgNgjvQxzHvDctq/KhZg8NFa8TzEvoSzYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; 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=xe34tHZ+UCvb6dLGEIVeD6yY1wvQS4hdwAXiIbxKTuc=; b=WtdwQaTPwRHQBs1/cNSCLlzREC+fR/HTyRa95xzcqhxTHsGAhUpQn5ew6zYJTY/wXuXo3gcUf/v9bvfWgqOvBOsAQNaLaoN43w4PI+CMlAtuvxz1jaguioWeWjJKV2ZtX0BA4h25WiRnET0VFrR3/YDjzv9+HJiky0aU7LAUDIg= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) by BYAPR10MB3431.namprd10.prod.outlook.com (2603:10b6:a03:86::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Tue, 25 May 2021 18:06:12 +0000 Received: from BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0]) by BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0%7]) with mapi id 15.20.4173.020; Tue, 25 May 2021 18:06:12 +0000 From: Mike Christie To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, stefanha@redhat.com, pbonzini@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org Cc: Mike Christie Subject: [PATCH 2/9] vhost: move vhost worker creation to kick setup Date: Tue, 25 May 2021 13:05:53 -0500 Message-Id: <20210525180600.6349-3-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210525180600.6349-1-michael.christie@oracle.com> References: <20210525180600.6349-1-michael.christie@oracle.com> X-Originating-IP: [73.88.28.6] X-ClientProxiedBy: DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) To BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (73.88.28.6) by DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.12 via Frontend Transport; Tue, 25 May 2021 18:06:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 75e128ff-53b5-4f1c-c58f-08d91fa7c7f3 X-MS-TrafficTypeDiagnostic: BYAPR10MB3431: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7zXF9m/D1buLmjVY+bYXkTqRerSjFlVp0uhxZ6/LdMjyPZ1Z4+4JHbRlxv1fHp0Hv4UrmYfBvhgPbTQLhyvzKmj7mN031Mo9bcTBG/zANyQg0P0auZuUzaouHIPrsKh3OsYMU9PFRpAswwq1M94YUmdzZe6oFfNMmIpjdhPBWhOsifbOJqGdlT1UH16ryWKZaFsJQL/QSRkRVEqBoeLnbPVZTY1RFmlDP1Z2bS0YFil9LkUlIvlgMBgCtsIckxMyotyz/T4Twr90DlqVfszUF9GBfOk6zAgxF1CQfteuLNHT0qj7KeJGJ/FYHyzUcifo2zJxOKXsP3LT0qTCOE7pwgSIt5YVVET4NC+l2v7kZy9fvbCHBz4oXv4CL9vz4NmsPd1qLJ0A+w3HKmMEKPJmU3y1al2FyyA16nTCWlWrxyxuWfTcjhpxZgyDsI3GqL77skKq9KLspQqInv0GQr4gQr44ify7bDo3bBd4mN6FFrDIh8pQpi981DUpZMDGh3kP4gS4vdu5ILTIQqASJyd2LXH1C7Tzb1BVXs0xqprlPNvL4ropttGKXrKM9huZyGbNg/G/lgb2+spEJ8O4w7JGik1UTzHKyrUPinrGm2K31CN4NqnJDJ1yw0L+g2xILXdpnRXUC3xT7yuMI6/kfe9Pgp2zzo+WlaFwwLF+qCPkkIeGlzPMPMjcLpS6ZPfZ4YQu X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3573.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(346002)(396003)(39860400002)(136003)(366004)(6512007)(26005)(38350700002)(186003)(66556008)(66476007)(52116002)(2616005)(8936002)(86362001)(6506007)(38100700002)(83380400001)(956004)(66946007)(8676002)(4326008)(5660300002)(2906002)(1076003)(6486002)(316002)(16526019)(6666004)(107886003)(478600001)(36756003)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: E7MyYDJiF801PVqunbcWh9qc+GVFk9OtRdxdoBQoNUlFXK/kHyz54tvU2wc7JQeQcPYUui+VOIY6whWLCOqj1qk1chGlIRxydWIFdQLdTfyIGjHsSmm8D8e+4MhRAKefEPSv5F6Iy7ZWvGIIgtfvyeh0ydCD8gbjMYvQrwg2o0qY6iLkDu4Zv8vllod5v+N50H1Ta+kepvGKpvR/P5xuOfDJws726blJ4QNFVG39MfCjkKNhbK3kZFnbwaLwxmdJDD7LiTvxui1XlWfG4+NXWVTaJjELecKHxHo8/BtnG4AP80yerySkriUjcJcQCNGHn3YYobmLiXDA71gH8A+eRSdRiedORkBjJyXtEiPm8mGuiumfH+wQ3fRCo+g4Wec6FRi5yfQA4DNb800i8QGADyfaluSucxqVvj58izUHFgqjwD5LO3T/HlZB4CYLZUSej4zy9vEyiVjdYty1oAnYCZBdrHKJMB5RssZ7cqdDqPWYTcPsNpvyVeYZPwJc7GAMQtfn5DX/z4KML61GtQ2addvMpK+pzEMUwdLYNQijP3vqngDRMcC0udPEwrSF/NEP3nWvIvLiGg1DqkLxmW4/jad6Z9+6x4EfDUYU4KYZIxPLOJI5DqqgB5OPKBTwBlGXGfRKjZiEjkuAPfJf9Zgo99iTpvdTV8lBx0wcqlHPV1upXzBnQs3yrJbaUA5Ny2qa+CniV9mvEAjjd/F7RbkI+IcGMezpGqSaeWeWbbkFXg91/SDPbOyXlUCuYMix8UEBvbcbIKRxNtg59jojKwI+sBPrpQEmAgD68Wx+k5xhpTRUFEczDddd1xeiJOM8W8US/TJHDuMvo0PgRi5qdprZSWAg/Udbu93zJ9rc2JxA1Wm1fnctJn9Z1h0lmmjINM5mV0/ddgPLlfERGmz1wcOWdz61IDaHZC1upAHFl9i1r0oRdw2vyWl5RrHxJQGuEnURok3b0zjiOHUbXNM1ydVxsz9ZV+EJ0tKYBTNGJnWcUhy1lWtwkQgeyryijf8Cun3MUZ63BneqfTQ/r9k2fd7xvl40VvQpYXMOisBZB/bElK5Qi47G6SCeDjC/dXBaDELRw5uqnulI2o+l3W/kIn0qQ6p+fCdTIECFv6XgFmSMN8w+6gi180mS/TWxesajy/onLIBEa3QGV+kvrcqyQAxytpiB1jNreBJACaSfs5uVmQAJDdQtlmEKWBiJ8iB9X+wd50r/lo7E5Z5B5NGufS/OSWJgNHpWXmvCVlZsHdbLnyWRgJxzPrrd3CA02MJ4L56/GdkJPPIPI0jM+9I44QMCnHE7pNic0rGkx31qGx0+KjxB13S5xnGcBTJFEDqkArjX X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75e128ff-53b5-4f1c-c58f-08d91fa7c7f3 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3573.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2021 18:06:12.6655 (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: iXbemQs8em70c1ySblAnuyy9dfpUj2u/S8mRZFDnLwwHgnLy1j44reaENGjj0Y6zUKn+/nA34onZwcIxn5LgEu6RUFNe2CRjj/uW0xTn/34= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3431 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 X-Proofpoint-ORIG-GUID: emUMnK7tBc9MxTtuERfw7jv_9CKi_uRZ X-Proofpoint-GUID: emUMnK7tBc9MxTtuERfw7jv_9CKi_uRZ X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 adultscore=0 clxscore=1015 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org The next patch will add new ioctls that allows userspace to create workers and bind them to devs and vqs after VHOST_SET_OWNER. To support older tools, newer tools that want to go wild with worker threads, and newer tools that want the old/default behavior this patch moves the default worker setup to the kick setup. After the first vq's kick/poll setup is done we could start to get works queued, so this is the point when we must have a worker setup. If we are using older tools or the newer tools just want the default single vhost thread per dev behavior then it will automatically be done here. If the tools are using the newer ioctls that have already created the workers then we also detect that here and do nothing. Signed-off-by: Mike Christie Reviewed-by: Stefan Hajnoczi --- drivers/vhost/vhost.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 0cd19b1a832e..a291cde95c43 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -629,6 +629,15 @@ static int vhost_worker_create(struct vhost_dev *dev) return ret; } +/* Caller must have device mutex */ +static int vhost_worker_try_create_def(struct vhost_dev *dev) +{ + if (!dev->use_worker || dev->worker) + return 0; + + return vhost_worker_create(dev); +} + /* Caller should have device mutex */ long vhost_dev_set_owner(struct vhost_dev *dev) { @@ -643,11 +652,6 @@ long vhost_dev_set_owner(struct vhost_dev *dev) vhost_attach_mm(dev); dev->kcov_handle = kcov_common_handle(); - if (dev->use_worker) { - err = vhost_worker_create(dev); - if (err) - goto err_worker; - } err = vhost_dev_alloc_iovecs(dev); if (err) @@ -655,8 +659,6 @@ long vhost_dev_set_owner(struct vhost_dev *dev) return 0; err_iovecs: - vhost_worker_free(dev); -err_worker: vhost_detach_mm(dev); dev->kcov_handle = 0; err_mm: @@ -1665,6 +1667,13 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg r = -EFAULT; break; } + + if (f.fd != VHOST_FILE_UNBIND) { + r = vhost_worker_try_create_def(d); + if (r) + break; + } + eventfp = f.fd == VHOST_FILE_UNBIND ? NULL : eventfd_fget(f.fd); if (IS_ERR(eventfp)) { r = PTR_ERR(eventfp); From patchwork Tue May 25 18:05:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 12279801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C62FFC2B9F8 for ; Tue, 25 May 2021 18:06:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A42E160FE4 for ; Tue, 25 May 2021 18:06:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231895AbhEYSHz (ORCPT ); Tue, 25 May 2021 14:07:55 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:56454 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231430AbhEYSHv (ORCPT ); Tue, 25 May 2021 14:07:51 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI5cg0108029; Tue, 25 May 2021 18:06:17 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-2020-01-29; bh=adkC/lusXAvRBza6cvEif34yOWKLomqy1QYrDWkSuBA=; b=kuSaUPBp7U86jg0/Ffhg9Z0rXdfPqe/4+ePyd402Z+VcPab8soGKX3Kvg2teSZGDjh6n YEg3NbQl2dj4K2AaSFT3xovT708r9leJwm3rzztRfoFNe6aUslGyrwFHvr5VcXBiMV1w pQv44p9STu/QXXeoN6pKpdyHYqOvBqhb/XqrloxZsx0kp749EXuhLbulww/xqLOb/9W5 2DH84NVbTXnIMw82pYF6IZSlNjuwxgWy03KZz7SAB8tdAqKOIHNZ+3i23iC9PaAHLI00 pBIv7FVb7m3i4Ivy/4ZZmX31GLsXnCms7YwMwvcNts1dACHpiTOTxv5rs/hIE+Hl16Kk BA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 38q3q8xc04-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:16 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI6D78185054; Tue, 25 May 2021 18:06:16 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by userp3020.oracle.com with ESMTP id 38qbqsga75-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SPE6AmzCiBYAvsw5INZUsF0z9u3/7rrlMHLxhbKYSshaaJMXUVqOQ4OkUtcPU3bdW9bDFNSnPXy4O4y+iPL7aSaUQeg4FvDEC9dmdd8PQov80ss23Zi0f4OI7kVj7XbPMrRVQPpMOg+J2PJLPBqcaKdj0U++9JpZuMB+kNWqLhkuS9nYf4KfuYVnI0GctHhr0a7nMn+7BX1HBnFj7rvyA30RTaMAk6v77TWsohLuEmQlle4/cYFb23b+6J/rDLgzNJWs+Ls7Y8l/1Z0M4DOPYoFC9aIuxBzSrqnasMiS+WExv8nAr7+Szh9/QJv1zLj1SFc+n6QFlf6G6MMR53kl0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=adkC/lusXAvRBza6cvEif34yOWKLomqy1QYrDWkSuBA=; b=DuVKY6l68loxUuP8aAeyXnl+9kARzHE6ZLGm6DP1fl1xHNWY8j9okvvu94f7JNuBici7vuZ9IZ3zIK62szAlcN3hAteTkwa4feeraSlAuQiPab634uBBuC2Wnygq3gmBBhyMrkEExhCfC9ywZGmu7sgDL/rCryR9l/vxpzyLj8+xZx1O0YAvfGNBi3EtY8A2LYZdEwHxqFE/+pZTWnIRDY9o+NsHWEkcNCEKz8ExnKCegRQdRCwmTgkbBb/gs/vG8baGq5QkV+7oCbpgOcinxS7z5ypEMKGJ8A6kmDtVynCf1TM8eLXtjUAl4NZHiKSnqi2Cd1t6VI3TBdAr/tO4Qw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; 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=adkC/lusXAvRBza6cvEif34yOWKLomqy1QYrDWkSuBA=; b=Drolyypvtrn/a3BMn1MhOnu+NyCYRj9JcEvwlgOit/CIxb6xbk5xHCl20nvgLklusSmQOkIDOnk3OvwcrYF1PosvBKWb3fn/NcfJeJl4pAXaHC6CV0M5FD9mO1HXqdNv6TQ3a3kVMYxuNrSxKOZuT1jL8LOglQgsF2AFrQC2BLg= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) by BYAPR10MB3431.namprd10.prod.outlook.com (2603:10b6:a03:86::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Tue, 25 May 2021 18:06:14 +0000 Received: from BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0]) by BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0%7]) with mapi id 15.20.4173.020; Tue, 25 May 2021 18:06:14 +0000 From: Mike Christie To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, stefanha@redhat.com, pbonzini@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org Cc: Mike Christie Subject: [PATCH 3/9] vhost: modify internal functions to take a vhost_worker Date: Tue, 25 May 2021 13:05:54 -0500 Message-Id: <20210525180600.6349-4-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210525180600.6349-1-michael.christie@oracle.com> References: <20210525180600.6349-1-michael.christie@oracle.com> X-Originating-IP: [73.88.28.6] X-ClientProxiedBy: DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) To BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (73.88.28.6) by DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.12 via Frontend Transport; Tue, 25 May 2021 18:06:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dcf62351-c05d-4a90-5682-08d91fa7c919 X-MS-TrafficTypeDiagnostic: BYAPR10MB3431: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:514; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xSJKwX+OroCDH5GR/LKnWbOUg/uIlUXRjpCn8J26MYhu+PYyWgqlUoULVJdvkuQUhC+9nsc7/AT9SSVnQVTNbc/roP0ZZX3GuoL7zNKpVV2v75Y0XhCsBlLiD8FR2yHxZb3iwPW6HpbnbId7JgGjgEYc2zE9ka0DPK+dobo/28Z0ch0ufPedr+hx1nRd4bZPk/jivqCA/LR618SBi7ptR32NOK7zczi2kDHD0SA83ZCHBb6dA/rIuu951+KCUJTHpjhnpDaOUGDFrpOZUF69DvcEvFwKcqZ9hTAHTvxjYUC3UmrqSeyZY0cqhURn7Wf1ulOlDagklemJAvQy40Nztl3j/k//H/439k80RcFUjyb3AaVvtX/VOmCEI0K4xU+krdQ/FihpbUMneiUg6ioq+vEw4ePyU27R0lgKI4d5y8BMemq9SKap55juWT3M6AJiezx0iWep1l+t4AekHYfYLGDayu1mJr7LfYv22Dj80QQvV1A/W1uEbEW9HxUM96sYoAqMLAPYVMVZoHz78FMfuoAOs4d6VgSiZLHxfnd4E8ys2BM005y6WD4A4nd9ZPM2cz8nCeugSnH8ZfK95xZg4kV1QexRoQsjeiWv0tlswPEdSMe8OZ2wmrYwa/0NZ/2880VuuCElaiMc7EoumDyu9F4cJ7cvr/IdgwBDgU0PSQoDQa1MxaiqgzSRUzmv/k1R X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3573.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(346002)(396003)(39860400002)(136003)(366004)(6512007)(26005)(38350700002)(186003)(66556008)(66476007)(52116002)(2616005)(8936002)(86362001)(6506007)(38100700002)(83380400001)(956004)(66946007)(8676002)(4326008)(5660300002)(2906002)(1076003)(6486002)(316002)(16526019)(6666004)(107886003)(478600001)(36756003)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: xAyqJzp0u0yP5CVIgNkU1Tem62okr0P8OHaUAigbgOWAyllMJG0YYd6+R1QnrQZpqSUwHM8HGLhIq/sSubosbdW+b5SS+ALy6ZteXyHEaSL4+2hsZnP1VZ5oWmR6z8Hvx6rVX0om/KQBV4euAZTdMdLzV54I3xrnnp4Xtz84yDoAruUyYzMoqf7IAk5JUx6v7KFiaAmKbjL4XLESpqU1g0vvWWMm2zWC22jwRA/q1BPULCw86bgNc82/QOvd9ez1XN7KHB9qt3Fx7ZjU6aZLgb9bkObnK+EGAC/o8pcr1F0Z+WKLzUZjNIiCaaOL9OyYj0jenQJv5RzU7V+7pEizj0RVlnG5gOLD8q9QxFme85bwOQgGD7Ib2xJgQRptAWJiVLb+HA1+k7giYGxBPwDuyacZzEI8jfDZQxMkcFbtc+Wq280pcS7JjWi2+lUEGBNtJZbMOdnbZ6uEOO3TuVeZqkq4J9EAvp7SWbUK4+dJ0GOS3q6dq1HeeaxX1z//SrhsBJQFgDxl2AwHIDT8RTeuWqX+PAgw5q0I7gPYTxyuBUjeX6Ak3YuNyxRKp8WLQIgL4gXaFYVCuHGl1RPrXxLQLkRb3TRu7f/4ORuNlXxfG+Xwjk+gmEu5dqtVd1BN1bSdFKvd1fh/ykfRjaQuToAZz6cdS4nJD5YnODnvQqRNTBnECZROR0MWK3CdCo+Zq4e0bNGhjMZENpm8ILsLmySZrBa4FSe60e248I2WROZXKgRjGTfVD0wVHAeUdRb00stQPINLh4RRCPjTswp3vefG3ulMVSbh4lsif8LjcmSC8g5oU2W+QtJW6A9ccMini4AapMcye+UN/iZJbbjDtmilLulfS8FHViflfEi6MO+9X3ZdKIJywbY1BjgSBxNeCBttVHzMvTraFEGWUlcFQcgf9rWjvuw2Yh9L7f0mR2a1y5dMS3JwGfnV31jgjq38i3B8XrQMlMGOzgh+/f8zGAuwOreqjvsXFhSPgOZhXvvzC9c+89OKAz2I05Mp74Ga5Kx77sdrG7WXYh/iQ/ozrRFoLtrvnGYpsAjZ4jnvIQIraRV77Sg1sHFFtEaKXX5vo2m4BZxjnmD2Iq16iiTTmJCM757QOC0J4sfDVOPmLnVITYjeoPZa+Y0LGEUZcpZl8G93Q1ekHFz6/cpW/L5803j8kQYbY+HMdXFkJgMttwtkythHRVzP21VQAgKKOM8A54AQsMsITYKqcIgdO+gUf1sKgXorU+2a71NT6qdS4GUHRyw+yYMwEDnpjmnl76aQa+GpmS45UBrRSZkXSDegMcMAIwsjZ7v9vVjqlKPYSx7lmJzXMjxYH1nHaJgInHKAWow2 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: dcf62351-c05d-4a90-5682-08d91fa7c919 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3573.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2021 18:06:14.5125 (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: szG1x4fGYirS8PybSeHoxl3J6Iv6VmRgaa4oLeACQmTiYfRM+M4wjezCEt487qmhN++WlNr+JmFd0rf4EEIb8kjPbx4dz6vRF++SG3cg/bM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3431 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 X-Proofpoint-GUID: xJuhYMUr_2PPhfqC9alAezf5bt7_OyAn X-Proofpoint-ORIG-GUID: xJuhYMUr_2PPhfqC9alAezf5bt7_OyAn X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 clxscore=1015 malwarescore=0 bulkscore=0 impostorscore=0 phishscore=0 spamscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org The final patches will allow us to have multiple vhost_workers per device and be able to share them across devices. To prepare for that, this patch allow us our internal work queueing, flush and cgroup attach functions to take a vhost_worker as an arg. The poll code required a change to the drivers, so the next patch will convert that code. Signed-off-by: Mike Christie --- drivers/vhost/vhost.c | 136 ++++++++++++++++++++++++++++-------------- drivers/vhost/vhost.h | 4 +- 2 files changed, 94 insertions(+), 46 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index a291cde95c43..4bfa9a7a51bb 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -231,20 +231,6 @@ void vhost_poll_stop(struct vhost_poll *poll) } EXPORT_SYMBOL_GPL(vhost_poll_stop); -void vhost_work_dev_flush(struct vhost_dev *dev) -{ - struct vhost_flush_struct flush; - - if (dev->worker) { - init_completion(&flush.wait_event); - vhost_work_init(&flush.work, vhost_flush_work); - - vhost_work_queue(dev, &flush.work); - wait_for_completion(&flush.wait_event); - } -} -EXPORT_SYMBOL_GPL(vhost_work_dev_flush); - /* Flush any work that has been scheduled. When calling this, don't hold any * locks that are also used by the callback. */ void vhost_poll_flush(struct vhost_poll *poll) @@ -253,26 +239,62 @@ void vhost_poll_flush(struct vhost_poll *poll) } EXPORT_SYMBOL_GPL(vhost_poll_flush); -void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work) +static void vhost_work_queue_on(struct vhost_work *work, + struct vhost_worker *worker) { - if (!dev->worker) - return; - if (!test_and_set_bit(VHOST_WORK_QUEUED, &work->flags)) { /* We can only add the work to the list after we're * sure it was not in the list. * test_and_set_bit() implies a memory barrier. */ - llist_add(&work->node, &dev->worker->work_list); - wake_up_process(dev->worker->task); + llist_add(&work->node, &worker->work_list); + wake_up_process(worker->task); } } + +void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work) +{ + if (!dev->workers) + return; + /* + * devs with use_worker=true created by tools that do not support the + * worker creation ioctl will always have at least one worker. + */ + vhost_work_queue_on(work, dev->workers[0]); +} EXPORT_SYMBOL_GPL(vhost_work_queue); +static void vhost_work_dev_flush_on(struct vhost_worker *worker) +{ + struct vhost_flush_struct flush; + + init_completion(&flush.wait_event); + vhost_work_init(&flush.work, vhost_flush_work); + + vhost_work_queue_on(&flush.work, worker); + wait_for_completion(&flush.wait_event); +} + +void vhost_work_dev_flush(struct vhost_dev *dev) +{ + int i; + + for (i = 0; i < dev->num_workers; i++) + vhost_work_dev_flush_on(dev->workers[i]); +} +EXPORT_SYMBOL_GPL(vhost_work_dev_flush); + /* A lockless hint for busy polling code to exit the loop */ bool vhost_has_work(struct vhost_dev *dev) { - return dev->worker && !llist_empty(&dev->worker->work_list); + int i; + + for (i = 0; i < dev->num_workers; i++) { + if (!llist_empty(&dev->workers[i]->work_list)) + return true; + } + + return false; } EXPORT_SYMBOL_GPL(vhost_has_work); @@ -482,7 +504,8 @@ void vhost_dev_init(struct vhost_dev *dev, dev->umem = NULL; dev->iotlb = NULL; dev->mm = NULL; - dev->worker = NULL; + dev->workers = NULL; + dev->num_workers = 0; dev->iov_limit = iov_limit; dev->weight = weight; dev->byte_weight = byte_weight; @@ -531,14 +554,14 @@ static void vhost_attach_cgroups_work(struct vhost_work *work) s->ret = cgroup_attach_task_all(s->owner, current); } -static int vhost_attach_cgroups(struct vhost_dev *dev) +static int vhost_attach_cgroups_on(struct vhost_worker *worker) { struct vhost_attach_cgroups_struct attach; attach.owner = current; vhost_work_init(&attach.work, vhost_attach_cgroups_work); - vhost_work_queue(dev, &attach.work); - vhost_work_dev_flush(dev); + vhost_work_queue_on(&attach.work, worker); + vhost_work_dev_flush_on(worker); return attach.ret; } @@ -579,20 +602,29 @@ static void vhost_detach_mm(struct vhost_dev *dev) dev->mm = NULL; } -static void vhost_worker_free(struct vhost_dev *dev) +static void vhost_worker_free(struct vhost_worker *worker) { - struct vhost_worker *worker = dev->worker; - - if (!worker) - return; - - dev->worker = NULL; WARN_ON(!llist_empty(&worker->work_list)); kthread_stop(worker->task); kfree(worker); } -static int vhost_worker_create(struct vhost_dev *dev) +static void vhost_workers_free(struct vhost_dev *dev) +{ + int i; + + if (!dev->workers) + return; + + for (i = 0; i < dev->num_workers; i++) + vhost_worker_free(dev->workers[i]); + + kfree(dev->workers); + dev->num_workers = 0; + dev->workers = NULL; +} + +static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) { struct vhost_worker *worker; struct task_struct *task; @@ -600,42 +632,56 @@ static int vhost_worker_create(struct vhost_dev *dev) worker = kzalloc(sizeof(*worker), GFP_KERNEL); if (!worker) - return -ENOMEM; + return NULL; - dev->worker = worker; + worker->id = dev->num_workers; worker->dev = dev; init_llist_head(&worker->work_list); task = kthread_create(vhost_worker, worker, "vhost-%d", current->pid); - if (IS_ERR(task)) { - ret = PTR_ERR(task); + if (IS_ERR(task)) goto free_worker; - } worker->task = task; wake_up_process(task); /* avoid contributing to loadavg */ - ret = vhost_attach_cgroups(dev); + ret = vhost_attach_cgroups_on(worker); if (ret) goto stop_worker; - return 0; + return worker; stop_worker: kthread_stop(worker->task); free_worker: kfree(worker); - dev->worker = NULL; - return ret; + return NULL; } /* Caller must have device mutex */ static int vhost_worker_try_create_def(struct vhost_dev *dev) { - if (!dev->use_worker || dev->worker) + struct vhost_worker *worker; + + if (!dev->use_worker || dev->workers) return 0; - return vhost_worker_create(dev); + dev->workers = kcalloc(1, sizeof(struct vhost_worker *), GFP_KERNEL); + if (!dev->workers) + return -ENOMEM; + + worker = vhost_worker_create(dev); + if (!worker) + goto free_workers; + + dev->workers[worker->id] = worker; + dev->num_workers++; + return 0; + +free_workers: + kfree(dev->workers); + dev->workers = NULL; + return -ENOMEM; } /* Caller should have device mutex */ @@ -750,7 +796,7 @@ void vhost_dev_cleanup(struct vhost_dev *dev) dev->iotlb = NULL; vhost_clear_msg(dev); wake_up_interruptible_poll(&dev->wait, EPOLLIN | EPOLLRDNORM); - vhost_worker_free(dev); + vhost_workers_free(dev); vhost_detach_mm(dev); dev->kcov_handle = 0; } diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index bfc4563e612f..fa1af4106755 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -29,6 +29,7 @@ struct vhost_worker { struct task_struct *task; struct llist_head work_list; struct vhost_dev *dev; + int id; }; /* Poll a file (eventfd or socket) */ @@ -155,7 +156,8 @@ struct vhost_dev { struct vhost_virtqueue **vqs; int nvqs; struct eventfd_ctx *log_ctx; - struct vhost_worker *worker; + struct vhost_worker **workers; + int num_workers; struct vhost_iotlb *umem; struct vhost_iotlb *iotlb; spinlock_t iotlb_lock; From patchwork Tue May 25 18:05:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 12279803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53E63C47086 for ; Tue, 25 May 2021 18:06:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DF1060FE4 for ; Tue, 25 May 2021 18:06:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232083AbhEYSH5 (ORCPT ); Tue, 25 May 2021 14:07:57 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51536 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231273AbhEYSHx (ORCPT ); Tue, 25 May 2021 14:07:53 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI5mqO060529; Tue, 25 May 2021 18:06:19 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-2020-01-29; bh=LcfSH+XJGNeXyrQSX3IWZ3JhXGfiut6RzDMivAGG4YA=; b=Nkn2RSruao8FMbFL2/a+kkk89wlblv0J6ItOTizUpo7jQdanvnNllZ5kMB4HYiiHmWT2 hGYe/zcnO/CPYWeeF2717fxV1XnXBPDkojThPTyIrUjFgmcJLHGvX6bLhXCBaZEsedjW t6CCv87NuHnR7Qx6I0o3QKgv2/S2o1nQwdMyCKq3Q++rvc20skZzwo4PoaS3zYK/aJbU AezyRgZh0LmBDgzVMwho2VaHGJKY4/4+VH76D3DDz33tzASBLmFnU8WNqgHmhdkwdzAA QlEnrwO54ggSp5RE7UGlzGFw6p2GcHt8FgAybVCn1eUExEEVMYF89JLowPROgraujiFx 8w== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 38ptkp6uqf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:18 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI6DTx185061; Tue, 25 May 2021 18:06:18 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by userp3020.oracle.com with ESMTP id 38qbqsga9k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F1+MbKX7jp43q60cPosWFbTPI8HTjHyMPedKi2EIipW5s/aMKT6nwxoPfnjHKf7mfiZC7lKnMFLcBVBUxT21l2qyGRIDRB1tio8T8sRSJCb7/FQHIr52lT7prnRUnbYsLDtfZhm0Rydi7cDy3JZvTYPllPFel0zVuQV8w245r7u+e4NLsOGjZXueUGaxD8EAo7wVdv/NYr9OshFJlr9sDI2Ex22VmIciCFqhHy0drgXZZ4SrZmNSIOlvZheAi1eol/xgSj/3GxhH/ukV3J1JH5ACrlddObGsbPtNb+dgCCB+NeOqxvs/00GLiln6pb6/DJfOlgFyIbRzwF94+fsslw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LcfSH+XJGNeXyrQSX3IWZ3JhXGfiut6RzDMivAGG4YA=; b=IIi+EH1AW9nqowvqg4nphWRyVFL0pUMo2LYXbg9bI4dNtS3Kj7/WROhMUo3dyxxWFgt9a8KRYauCF/e2q1PLQUCjN8saErJ+KqMhUCBh6zm8FprFEsuXigQz7PCCgLeyvh11e5yrvQl+R9o2zxJ/oNrmQvBDUFKB/H4tdyYmVEXpp7iuDqZ8jrYvobmk/EEH6rUyrlrqaW8S0gRYTWN+h0fu1MM+8D3fghB7Y3ykkIu9mESnalfFhaY6017E8vWFWz5CBEgYr2NWrZkBQOmOOYKiVJagct3x8lhfirfpx5pHCepIJVB/rWqPQvU5tqJMbnS5C2uju30ehX1q1R2Lug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; 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=LcfSH+XJGNeXyrQSX3IWZ3JhXGfiut6RzDMivAGG4YA=; b=SDZdv5v8N51J2WUiH1Hf09M77ZzsvZpF384Pq3wxykrQO8djG4WrxomIkU6lEaPBhdv4/O/SUpe2QegeYF3QxFUOR6Qfq72pzGG28oPSc0uDbq56imvtbjUpk9fIJWbZwjrr5sYs7jA13BOa5xuAuD5/TPjP+klAUBIrLwtk9pg= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) by BYAPR10MB3431.namprd10.prod.outlook.com (2603:10b6:a03:86::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Tue, 25 May 2021 18:06:16 +0000 Received: from BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0]) by BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0%7]) with mapi id 15.20.4173.020; Tue, 25 May 2021 18:06:16 +0000 From: Mike Christie To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, stefanha@redhat.com, pbonzini@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org Cc: Mike Christie Subject: [PATCH 4/9] vhost: allow vhost_polls to use different vhost_workers Date: Tue, 25 May 2021 13:05:55 -0500 Message-Id: <20210525180600.6349-5-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210525180600.6349-1-michael.christie@oracle.com> References: <20210525180600.6349-1-michael.christie@oracle.com> X-Originating-IP: [73.88.28.6] X-ClientProxiedBy: DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) To BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (73.88.28.6) by DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.12 via Frontend Transport; Tue, 25 May 2021 18:06:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5ea78da6-24ad-412f-c0d8-08d91fa7c9f8 X-MS-TrafficTypeDiagnostic: BYAPR10MB3431: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: clEyXZfxKj4XUZgYsdfdEBNL2+B39BnHHbBNFo+P0WatVuXApOQSPQx6gE/dm4oF+r6x9UDudXIhGiG0QCL0WZeuoKrUG28+YUnZY5eaSzRmlnLBEVl0gZgLyh/xeojVGL6FFP6gahSMm5LfkC5CNt9HqI1lbM2zURigVHyDn6RyOei/pK7jV1jxviRudWLSXhoGNpoxu4ms3L6C8RmItt/tmIa7QvpqgODNIYJMCYdEpeT8IcXVsQN9svz0ZqgRmul2QqsRPbNmmJA0pFb/n53X5RIrcdVMjhCi4ZIZT0cYE84S/EluZ3BClMfCpzQxvc/y1V+ypYnVtxbzi+6prSHrqkOw3z0jQXwCV/sqC88JPkZxzYRvwnNyofbjFkQgPUVRjUpBtw2eIt19bzvBzrQPuSWnfPkOGmZ9hyWmKrzT+uYqKeD3Y5Fto8GElDfMjn3Mun0GpXzTXZARp16vCPRegar8AvNqRipMvAZuf/Awt3ClvtGCNCeKNYzssb3emnG2jbZvRDkXZ4+hG+CUwsqB1uBqmS37nE+mIjzzzE8yYf0gY0p7Hq/IQ49hjAY+N/mJzS5pzwfgfxYqCZkIbQZ3T0ID4/8DX8tBCo0xQmk3gwaQ8W9qB6NBo6RdHM2Z1gnYM7FqEaC4clJKBGk7qaWjVHXsRYIqqXy6ECFDH+tU7aZOjTQO2IY3K1FZGCis X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3573.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(346002)(396003)(39860400002)(136003)(366004)(6512007)(26005)(38350700002)(186003)(66556008)(66476007)(52116002)(2616005)(8936002)(86362001)(6506007)(38100700002)(83380400001)(956004)(66946007)(8676002)(4326008)(5660300002)(2906002)(1076003)(6486002)(316002)(16526019)(6666004)(107886003)(478600001)(36756003)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 7FskS1m1W9Ol8QNqHH0zbgSayW+0N9pxs5WpniNGkoGrV53jyUI+rmZvpYyleZaIbY+VRkm7NIJiInoglmSM/2Cqt2/YR654driLJWVWXy+8+R5OCnj2WuP7de1jk7WmhSCwp5tFWgNb9NkvKIxa41UrNXbWWGmetEg4MAMWSIbU0xWVq/dmlap8GXGOAedhIrlMxY6D/TqHh+1+WfvCEwd+oqRR+DmPyCE6jF1SaLoUqhOlC8Gm5PKuaARPZIBWYp+Zqjc/Qz0wb10Kt/EubjazSaiekbe/aP/z6vC1rlKQ+4PbVJSkRveXyh9OzHGljCae4htD3H2s0eIIgKj4ARKvp3gZHAYGM7yf6Up05i3jkBkXYxXFJg2oG0qBicOveO6wcbjiIDixjJwqnKvO5l+nBa/1CCX/vlwNPwb9ivwhemMqpyYuMbvg9u4R0Q+8Wgx0NCTC8wyCWodYY4C3qxY1yefuyZQQb+rZvzyA2xN3PwyxnEVEtoyZiRrUMMy2HrzJ8BkY5fILFM3j9eViYBjQfqY6Qdr7/4jIIwsKffkm8p8POLyXcQEsB2SXG1WC9oiygFrraSu/y+U0u/aE9zFASy8uUQb3lcOdseArmsCyrqHJr1fatNn+77KixD03IfywUr5AyMgldynFbApHMEHy6lr5OUsXTziG0PbVbaFtl+M3jR9RKJHupHT4Fn3ijF59UZbRY6rEzVJw6fzVZAHnFwKaQ+fmYgeLU9MDsfMc5OX0TJyGyeYDAlL9GuqKd1MmcyPo8/KJ7t/bfbHg9zrYEYLFCkud92ol/ujJZSFohO5tugWQMBiK3Su7pk5WRAuBI5hdCWe+0Yy3hUA5QG6fH3pqaZvf8RCUNhOk2QKgztjGJsL9jppD7u3r1j5pWs1gXmIlEZ7Tc1v1QiEI6Sb4jBtfKfm/Np90d0npg/dxejHrBNgoZ4GuHrLQcA5AMpBVB/mfgS2FVu9Q9yN8SxWSX9soAcSyeGIYj+ST0+0M2N8e98pDcuOWui2Z4JhWVnYilTBx852QvQQPwmwbpC9pHI0Q0RyOzFEmV06aDxv1MgbQ2y4uhuDZke+uFQ34s9ruHIdlcxOiHl+IbvUvkCoEiPpXaKp32JfdkqhICsrNheFrhsLJSRmHU+JA7qHdwU6bYEfKrVTSmVQNcGdmlZnjNuFemY3iYHs/Dqzob+Ti/ScyFzqgGsEYm0d6prfh4NQAeDVlm2Ta/Pa2WGGVInNaGuoILOgpQMd+X7ptK/SecHL5zF0gQW9OT/ipB5NbqPsNqJdc24+R/T7A3v8J+kUBBj9MuyiF3Thpy6EjMd38iS/WH2g53TyDCuQ7NZAJ X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ea78da6-24ad-412f-c0d8-08d91fa7c9f8 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3573.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2021 18:06:16.1456 (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: T8Iq096rX50Lr3cSBd+rmpcqW2oiuo/hteHLyPdQA3WzJVFFU7dPN4X4EgTamCZM+IErlfmKDoLOMuOeq5WANTdIABq4AVYCE/gBj/m7Nmk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3431 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 X-Proofpoint-GUID: wDukkXbXR0u_4V5LcnlE2emKSQl3FE8i X-Proofpoint-ORIG-GUID: wDukkXbXR0u_4V5LcnlE2emKSQl3FE8i X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 mlxscore=0 suspectscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org This allows vhost_polls to use the worker the vq the poll is associated with. This also exports a helper vhost_vq_work_queue which is used here internally, and will be used in the vhost-scsi patches. Signed-off-by: Mike Christie Reviewed-by: Stefan Hajnoczi --- drivers/vhost/net.c | 6 ++++-- drivers/vhost/vhost.c | 19 ++++++++++++++++--- drivers/vhost/vhost.h | 6 +++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index df82b124170e..948bc3d361ab 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -1334,8 +1334,10 @@ static int vhost_net_open(struct inode *inode, struct file *f) VHOST_NET_PKT_WEIGHT, VHOST_NET_WEIGHT, true, NULL); - vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, EPOLLOUT, dev); - vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, EPOLLIN, dev); + vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, EPOLLOUT, dev, + vqs[VHOST_NET_VQ_TX]); + vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, EPOLLIN, dev, + vqs[VHOST_NET_VQ_RX]); f->private_data = n; n->page_frag.page = NULL; diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 4bfa9a7a51bb..3cc1196d465b 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -187,13 +187,15 @@ EXPORT_SYMBOL_GPL(vhost_work_init); /* Init poll structure */ void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn, - __poll_t mask, struct vhost_dev *dev) + __poll_t mask, struct vhost_dev *dev, + struct vhost_virtqueue *vq) { init_waitqueue_func_entry(&poll->wait, vhost_poll_wakeup); init_poll_funcptr(&poll->table, vhost_poll_func); poll->mask = mask; poll->dev = dev; poll->wqh = NULL; + poll->vq = vq; vhost_work_init(&poll->work, fn); } @@ -298,9 +300,15 @@ bool vhost_has_work(struct vhost_dev *dev) } EXPORT_SYMBOL_GPL(vhost_has_work); +void vhost_vq_work_queue(struct vhost_virtqueue *vq, struct vhost_work *work) +{ + vhost_work_queue_on(work, vq->worker); +} +EXPORT_SYMBOL_GPL(vhost_vq_work_queue); + void vhost_poll_queue(struct vhost_poll *poll) { - vhost_work_queue(poll->dev, &poll->work); + vhost_vq_work_queue(poll->vq, &poll->work); } EXPORT_SYMBOL_GPL(vhost_poll_queue); @@ -359,6 +367,7 @@ static void vhost_vq_reset(struct vhost_dev *dev, vq->busyloop_timeout = 0; vq->umem = NULL; vq->iotlb = NULL; + vq->worker = NULL; vhost_vring_call_reset(&vq->call_ctx); __vhost_vq_meta_reset(vq); } @@ -527,7 +536,7 @@ void vhost_dev_init(struct vhost_dev *dev, vhost_vq_reset(dev, vq); if (vq->handle_kick) vhost_poll_init(&vq->poll, vq->handle_kick, - EPOLLIN, dev); + EPOLLIN, dev, vq); } } EXPORT_SYMBOL_GPL(vhost_dev_init); @@ -662,6 +671,7 @@ static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) static int vhost_worker_try_create_def(struct vhost_dev *dev) { struct vhost_worker *worker; + int i; if (!dev->use_worker || dev->workers) return 0; @@ -674,6 +684,9 @@ static int vhost_worker_try_create_def(struct vhost_dev *dev) if (!worker) goto free_workers; + for (i = 0; i < dev->nvqs; i++) + dev->vqs[i]->worker = worker; + dev->workers[worker->id] = worker; dev->num_workers++; return 0; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index fa1af4106755..6880e7a29872 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -41,14 +41,17 @@ struct vhost_poll { struct vhost_work work; __poll_t mask; struct vhost_dev *dev; + struct vhost_virtqueue *vq; }; void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn); void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work); bool vhost_has_work(struct vhost_dev *dev); +void vhost_vq_work_queue(struct vhost_virtqueue *vq, struct vhost_work *work); void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn, - __poll_t mask, struct vhost_dev *dev); + __poll_t mask, struct vhost_dev *dev, + struct vhost_virtqueue *vq); int vhost_poll_start(struct vhost_poll *poll, struct file *file); void vhost_poll_stop(struct vhost_poll *poll); void vhost_poll_flush(struct vhost_poll *poll); @@ -76,6 +79,7 @@ struct vhost_vring_call { /* The virtqueue structure describes a queue attached to a device. */ struct vhost_virtqueue { struct vhost_dev *dev; + struct vhost_worker *worker; /* The actual ring of buffers. */ struct mutex mutex; From patchwork Tue May 25 18:05:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 12279805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7278C47084 for ; Tue, 25 May 2021 18:06:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD2D2613D8 for ; Tue, 25 May 2021 18:06:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232107AbhEYSIB (ORCPT ); Tue, 25 May 2021 14:08:01 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51548 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbhEYSH4 (ORCPT ); Tue, 25 May 2021 14:07:56 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI5Qt4060362; Tue, 25 May 2021 18:06:21 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-2020-01-29; bh=Su4W3BAyb8WcHT6WIE6SBIOjo6Gf6G84W0MS1fUQASU=; b=htgGKjMyZPALbCp3zb81jNmwVg+tkcXKTXyqcZIbez8goMl8AWY8kA+B3HaO9ol2gjDj hBFIEcMJHG0NN8ZP2Rem9nNxCXUdq1/LHvgIUvU3TPV7UVmNbzOQlbmoO0S0NRqZbdO1 I2dzOsjjqWdFhlbfGZSJMyIRGTSLOLwJIke7LwDhYESItfjOBesAuVcSupeR67wIlQw4 VFlsQzJ9A0s381P0cRpopIUBSRzpa4ewTGouKi+3DaPdvUX8e3xXEd6tCOcOMvVUzo/L ycXodXSzoxRHTcB9GG99G6pbiXrmy73ZiGGRjlZso6Wp2SxY6dvb8PLwBJABOcBlnpAZ zg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 38ptkp6uqh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:21 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PHou15022048; Tue, 25 May 2021 18:06:20 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2172.outbound.protection.outlook.com [104.47.56.172]) by aserp3020.oracle.com with ESMTP id 38rehapch5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X3ZPkzWi/Bj1J/ipvTWVwdPYuNyKil36L6tazABA7Egt5oi6iVb0E+aFJKufIn2fzeJBcXIkuFklE5GiaKVd/aWL3qEFu1gWgOo1KlEEeZR3t7Di56zo+t83zX5GuRm6zoa0wtV4kkv9YEA0E9cbVaowo0wMAvVXCZEd60p6hzuQe+cC5FZ/bQIP4Igyw7OWcV2NiUsONaaMt6lBcIyeUfx2R9eKP66vzCa57s5bjMwD+m/8HbfQU3OhAm3Pa2f1ukOP6HXzvxkHaWRdQWrbjY+oIydhkNDonUJLYWAgenW4S735cJz0Vjmofw1/gLhwdc9w1HhZOMXTpnSgSCA6QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Su4W3BAyb8WcHT6WIE6SBIOjo6Gf6G84W0MS1fUQASU=; b=jfopy9m6NbJKKt96sXyCW+oZdzOJirEFxT8R+bHxI8sm9Z5VpwmDYuQOlKtc/YxZLn6eUx/IYjRKrK+vzr5vlS61RHHIUdykgIvJFh2CVqndk//ur7aAcL6zJTtjnwO5A1zF5D6g3JZoru0sBzHjh5ousFW1wCKEkebheBRQYFAIvCmiWelJAyUi8M1LSiRv2aVumhOF9Zj/wfpXx+pdTVRkr+UYxEVKR4VndEeR3DH1cSkiaCp/JHzHIQ7At3KwTVJSn9F0GVwMbHIaCZVemS3ID6tyQOrFsB7JPdncWWP6sOKR4aGsWFi6UtnFJK0wkbdR3+ZUUrGpE1MpG3nUxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; 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=Su4W3BAyb8WcHT6WIE6SBIOjo6Gf6G84W0MS1fUQASU=; b=Ab8HDJfQekWykgs2LXlqqY0Km1dUdBzOjTj/ZuDlsGTOwB08ONJIhtpd/AGrEgQygc9CYojHo+xcaxrkAfe2hvj/8DLHPfn2+VRFrfhR2r4MYJqNB/CCI7FSuJj9qZGFJ4QnV2NYdGXqoNY4zQAHKBVvcT2wPwH9e/JrN97oj2s= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) by BYAPR10MB3431.namprd10.prod.outlook.com (2603:10b6:a03:86::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Tue, 25 May 2021 18:06:18 +0000 Received: from BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0]) by BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0%7]) with mapi id 15.20.4173.020; Tue, 25 May 2021 18:06:18 +0000 From: Mike Christie To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, stefanha@redhat.com, pbonzini@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org Cc: Mike Christie Subject: [PATCH 5/9] vhost-scsi: flush IO vqs then send TMF rsp Date: Tue, 25 May 2021 13:05:56 -0500 Message-Id: <20210525180600.6349-6-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210525180600.6349-1-michael.christie@oracle.com> References: <20210525180600.6349-1-michael.christie@oracle.com> X-Originating-IP: [73.88.28.6] X-ClientProxiedBy: DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) To BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (73.88.28.6) by DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.12 via Frontend Transport; Tue, 25 May 2021 18:06:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d37ed923-a50e-4b69-bbed-08d91fa7cb00 X-MS-TrafficTypeDiagnostic: BYAPR10MB3431: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0h81gzWEuQPXf+oMwJ8AcPATDcfDpXgY36MVlA0DygjWhWqN8msjk9CDZPDaX559vTjycQTA3eF7T7wQN34pjSeoQShu3UW1FjgYCKtQjrZOLvwqT+oyHhVSFc5vd/OisIB15sS86X9YJ6QzkoqUb+EBz/jG0d94M0IcxUZnuIMhukXrC30PREDqFE7FmDJmQ4epcSwOpP7NIZT9Fjhz2UFFc4LPNYt6FtIB/V4DGej1jsBFcwffEw5mW0LleNB4+W8/avNu6zMu3FQf/W73D/mvFo9Xnw7aw5KIhcFQ+pvuIVchulfhGZQxBwXI8Us1SUyW7rJWzD9RtZfNLdvdxXtudnoiR/wc3BQ2nIMLukP51TJ7Ypoamvg5FgBw6ZJnMIuuPXR6LcWUBRktVGD5bvxOZU//B8dQKAKkJzB9HOY+d/i854BhRHb/4dqkRYJDuQomDTrHZ+DZVINemADGXH1fnFfMBq328E7/vdUYalVV5SjVmVxmV1egDqR6RSHfAny7QvanUaCS/T0B0aTdMqthsWjv3rvmaaTwzkQouWzDlhTTc9KZSGUDmI/Fv0mJi6HyG4kfLa3+QfVDgLGYNvB/p5/BQIDlbbUNHFN/QN8TiXG5chohAjWd+HraqUbM6optnUct+d9NZv92EuLnaVidULTGCCFNujTdh2VEqysX9tyaQuZU4QTSwovxOKie X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3573.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(346002)(396003)(39860400002)(136003)(366004)(6512007)(26005)(38350700002)(186003)(66556008)(66476007)(52116002)(2616005)(8936002)(86362001)(6506007)(38100700002)(83380400001)(956004)(66946007)(8676002)(4326008)(5660300002)(2906002)(1076003)(6486002)(316002)(16526019)(6666004)(107886003)(478600001)(36756003)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Kd9QX6NsMxXv+cS73goBlpJ7V3saYqdMtt34DuRfyFfgT+pMVmtEnZKKQRPBEF89tOfKjlc8WCJImIKccNeqV5v8kI8q/P0OtxT8HpQnhDktM4hcFTsPsrOV9N5PiIr85HnhelPd1M5GEB7N3VKeesLsMr9IS1DF55IOosuNh4rmKyg+bzKN9baMEI7aXlaQe+Mxd7ZmshIXuRTUyCIWG7aafYKijqDqoVC6RT+x41B3xEjVzHwMaeRwnSP3ST8mlQePeX2CvUmYF8b0urft9h5nF9glNAUVf4mocqtJV0CA5BDp4m4o505Sptig98xmwOahIRqmZVhDbeHeYQPqaDlGOnln9B/TWJi8ElN1syENbuM+1H/aNnWupQ00884TXV9ZZ6sFKdbpmmPeVyR8uLszxcEKDTGW1XmWCwFnTLpQvM419n55ByZda8wYfKjuVlKmvfNaE4uFx2EAhAIvpdaHtRtVxdEf6Iu88tbQ2tAO748lOEbKXMHBSpff6pqqLI+ALMcfIofS45lNZSp42nBErBUS9ofHqGkyWYaR+6EqvFhDb+IiSD3e3n/2MWQupXwDYq2gc+w/RJc2oCCMOSxZJAIOiHo3h7OLM/lpuJmqBzeI7nIA3ecobJisrm1kYVCWUDY/58OEnANuT1UO2EWm3Zl/2pVn1Kgysjkp8zxt7tybDT5GnE8JcEgTfhuybUhZy9lZIwoWJ4H2Rk6JmWKyemPypO+DTHSBFEPJjVvu/eswNsjMXQjRaBzMpA6pWu73NNAcsvQ0haw+mFaULdiImXJq3OLAz5N74XfV+CeCkegRISjadgvIz9iXDQnk25rimCrvxYcZqc9ZU2rb887CyV9QRQNneQ9TdywAOfOivVBunxqBxAm6DinZzzhwbLalVbcZQg755VWNskdkjCy6PDg7U+vNV5TbSWhBfGjQTiigDD3fLcFut353oK7jZVHXi9/Dg3oSZkyPdJNfk9m0dLGG4qtrs8zLZaEQPFrWZpVqUGsloJ18pxypneIPh5Y8iaS48Q6gXFNIzfIQLiJemcIkJezmVEfJvouhZER632KQgLq0SW5DY3TAF+kZciFpiD+GrHAluNzAK+zqF9vo2XyD1j+Whrnr+yPvEv5m36UuixUg2jnOtBLmKtwRNOKEeagmV/w2TA63LZjvEkisxYjzvJhNXKinAsnYX7uDWcajBvwYhdrfdjwBKv1mpXLLo9VZ0QhaM7OdUCLAUZz7s81JEUHqnjtT4i3K1gaBnCbSiSufErvuRuy1spAbdZAK/7OR1hKI14A4kYWSvbaKYI+Nctt4FVdd8eW6yFkgfhI+bxSdLJt+bxhMuQM8 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d37ed923-a50e-4b69-bbed-08d91fa7cb00 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3573.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2021 18:06:17.8716 (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: sEvXM9N2L7pRuEK3erKe8UYSgkJFnbQT1QikUN6gVoOdtXCD7y62u2pSVUiDyFB78ldiuzZo0C+p6DBQ5IQwR1tf7hzPjHOA8omENmTsl64= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3431 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250110 X-Proofpoint-GUID: U9eXuwFymvfUDjo_crtPeE0Gt4tdyy9y X-Proofpoint-ORIG-GUID: U9eXuwFymvfUDjo_crtPeE0Gt4tdyy9y X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 mlxscore=0 suspectscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org With one worker we will always send the scsi cmd responses then send the TMF rsp, because LIO will always complete the scsi cmds first which calls vhost_scsi_release_cmd to add them to the work queue. When the next patches adds multiple worker support, the worker threads could still be sending their responses when the tmf's work is run. So this patch has vhost-scsi flush the IO vqs on other worker threads before we send the tmf response. Signed-off-by: Mike Christie Reviewed-by: Stefan Hajnoczi --- drivers/vhost/scsi.c | 17 ++++++++++++++--- drivers/vhost/vhost.c | 6 ++++++ drivers/vhost/vhost.h | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 46f897e41217..e585f2180457 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -1168,12 +1168,23 @@ static void vhost_scsi_tmf_resp_work(struct vhost_work *work) { struct vhost_scsi_tmf *tmf = container_of(work, struct vhost_scsi_tmf, vwork); - int resp_code; + int resp_code, i; + + if (tmf->scsi_resp == TMR_FUNCTION_COMPLETE) { + /* + * When processing a TMF lio completes the cmds then the TMF, + * so with one worker the TMF always completes after cmds. For + * multiple worker support we must flush the IO vqs to make + * sure if they have differrent workers then the cmds have + * completed before we send the TMF response. + */ + for (i = 1; i < tmf->vhost->dev.num_workers; i++) + vhost_vq_work_flush(&tmf->vhost->vqs[i + VHOST_SCSI_VQ_IO].vq); - if (tmf->scsi_resp == TMR_FUNCTION_COMPLETE) resp_code = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED; - else + } else { resp_code = VIRTIO_SCSI_S_FUNCTION_REJECTED; + } vhost_scsi_send_tmf_resp(tmf->vhost, &tmf->svq->vq, tmf->in_iovs, tmf->vq_desc, &tmf->resp_iov, resp_code); diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 3cc1196d465b..345ade0af133 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -300,6 +300,12 @@ bool vhost_has_work(struct vhost_dev *dev) } EXPORT_SYMBOL_GPL(vhost_has_work); +void vhost_vq_work_flush(struct vhost_virtqueue *vq) +{ + vhost_work_dev_flush_on(vq->worker); +} +EXPORT_SYMBOL_GPL(vhost_vq_work_flush); + void vhost_vq_work_queue(struct vhost_virtqueue *vq, struct vhost_work *work) { vhost_work_queue_on(work, vq->worker); diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 6880e7a29872..0a252dd45101 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -47,6 +47,7 @@ struct vhost_poll { void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn); void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work); bool vhost_has_work(struct vhost_dev *dev); +void vhost_vq_work_flush(struct vhost_virtqueue *vq); void vhost_vq_work_queue(struct vhost_virtqueue *vq, struct vhost_work *work); void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn, From patchwork Tue May 25 18:05:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 12279807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5455C4708A for ; Tue, 25 May 2021 18:06:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F42F60234 for ; Tue, 25 May 2021 18:06:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232243AbhEYSIC (ORCPT ); Tue, 25 May 2021 14:08:02 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:56494 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231949AbhEYSH4 (ORCPT ); Tue, 25 May 2021 14:07:56 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI5cui108028; Tue, 25 May 2021 18:06:22 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-2020-01-29; bh=v7Y+n/zT1DDY0nuWoiVGIYe7ZPWqvETQLL/RfPoiY+Q=; b=YLJFzUxT8mDxtnwAuVR4EJo2NOeJpEURIdnE1HAHGEoItQRZK6dbFQzWMZvrdytCx+L0 Dp1ZEzbQj49PvR3EZUB6wB7PYRX2vQSV/YCECO9fLNhgpK7TBFZ63X1Gt/2PO5KWlsJP rAK+iQfdrjkHmhUA9ymf6weN329SMe3jYXvH54Z4BJoOjOfKeTRg+96pVsINdgpRp6M/ IgJKV/Htpkxx+PTH8Hxjm6Rd9ADsUvGj7MFRIb8nA6gTkbhkMaoSEUvEiF+mGxduMXPU PDI6Dk6RJPKPDFo2ueIHhra3Kyx1s11rh/UdeOwcAyfuzWZ8fduoaWimEBLCjlucs1r/ Fg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 38q3q8xc0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:22 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PHosu2021990; Tue, 25 May 2021 18:06:21 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2043.outbound.protection.outlook.com [104.47.56.43]) by aserp3020.oracle.com with ESMTP id 38rehapck3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kKvlC0286aw6oA6cb76wLHGRaog5IesfPm+TVk++PaT09TNlUwQOuS51/RcohjmZjZA8yMAeJRL7VnxetPN04gB8yY38o0E1i1qMqecDesPmDGuwylmyLwmCnBGw4WVb5NgHmb64JmRSv+rn2MnKa/JMnwKdP0CyjLW5OAJR68vJjMo2QXPHsH3B7k+N6MpUWTkASYWWw8rQYMK+7vuJrnmGW8JoUcje3x/KGcqMupuVxptnCn2AvPbVwoJt+OwsrCJFemWBHi0cnTzLXxrldyS15MbESwcsfwC/Bm+WvmkL3TFiTorkL/98K6nzFt1JEq5k9lGHiD2p6Ueux5D4Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v7Y+n/zT1DDY0nuWoiVGIYe7ZPWqvETQLL/RfPoiY+Q=; b=QzxlUJWAg//KhX5/FZNHFaogGI66yipuhLbUcdpBSmfkIfg4S5tEFznXO6gXzOy6yEsb3Ap7C+fOjXKH1CXQZuLWV/zijaZvcDKgdrfkm3f5UAbyBlWnRFOnIesQLtmo2AcmM9pGey9K55k8vjHqx3TcNqYRcg1j8qW8OsIaMsQa/E0k0OHPCBTvI7dBm7p4Zz4AmKj5lEwvQW1M/vVmaDxztORB1/gNzxUAttXyVy97KE5JNJBKuXL9ejA2v40NOLYbe96N1zGKjizyKFlw077eZBrkNNe7eGm3hVJJthBclpDZvc61z6XIXsfXycGmBYtm9kENXyZuPUAoieRo5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; 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=v7Y+n/zT1DDY0nuWoiVGIYe7ZPWqvETQLL/RfPoiY+Q=; b=GSPr8SCG2UUDdO/G2tOSeAKz0Lvll2Bh6DMI4jwEl4BhK41x+l9VUg8CgTIq98N4dqcx1qvCU0N5ekXte0RLhyRgHjNZzKRZqfdR+ebu344pqiUMARkom+L5ZwS0usQnrJ8KYOmnanlKA6wzBqvIdytw5wpdRNIKcVb+JlnOxFo= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) by SJ0PR10MB4639.namprd10.prod.outlook.com (2603:10b6:a03:2db::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.25; Tue, 25 May 2021 18:06:19 +0000 Received: from BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0]) by BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0%7]) with mapi id 15.20.4173.020; Tue, 25 May 2021 18:06:19 +0000 From: Mike Christie To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, stefanha@redhat.com, pbonzini@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org Cc: Mike Christie Subject: [PATCH 6/9] vhost-scsi: make SCSI cmd completion per vq Date: Tue, 25 May 2021 13:05:57 -0500 Message-Id: <20210525180600.6349-7-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210525180600.6349-1-michael.christie@oracle.com> References: <20210525180600.6349-1-michael.christie@oracle.com> X-Originating-IP: [73.88.28.6] X-ClientProxiedBy: DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) To BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (73.88.28.6) by DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.12 via Frontend Transport; Tue, 25 May 2021 18:06:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f339426a-300c-47fe-c510-08d91fa7cbf9 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4639: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TWaRqwwVraO15lVxJbxNMyE6ckk58xu2MX/zU2FltQGmD42KkWzUqlLG3O660+4sL8ootdie+CbqNQ9mu8lCXvM/a4Wa5AxJy7sTJ898k+BZic/mSpwwb9ua+src6L4o/H2v2ggyf/v9IrIX6j832Y1Nx5Pw75ewBAHLl8q9v5PFlqqzFwqzrcKOHZuix/oV7+E80BcRCLLoHXC6GHiHgLJJggWt01JbRvfo/zrXhXUqXMQT6zOBoTrTvbPqeqVHf70e2iY0CHoN38xzrtPOkuUK6p+rhT/+U6YYJRhLVbMnA8iqOHbkaDDKnEChbGs3xaxwrD/G9hj+PLr1oSs2WQ8MJmlDHs6jphwWY5i3/GQCla7Ei/S/ZZtJ5yNiH2BY+vqyvqvnDxe4OXDItKwnjUkGjac53+Myv3ajginiJCjPbBhH7n3VypEbnAyQ7++Q/xZPBmVrlVdbZ7n6zjbaKk4+Jp9D8v22B64Dz6pF7c6fkNHSezdwZShBQuJn/DwhGpdn2nqgTZQNr/WYS71q9GXM9cYJkYlIbzBm40inb7inRqrDflPGEun6ph8pTPaS5hLhLgOjlrKlE0UOyU6aEWE89KbSixlJMsTxh2EZx11mpKUPvs68FdMsLAbWnKdIo72IRDwyX0NFQuGsQCR6WJackmQVSfxv83AIh3IOrYfmGUzU4pLmmoEpBcOYRsg5 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3573.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(396003)(376002)(366004)(136003)(346002)(36756003)(2616005)(83380400001)(4326008)(186003)(316002)(6512007)(6666004)(6486002)(1076003)(8676002)(16526019)(478600001)(2906002)(52116002)(66556008)(38350700002)(86362001)(66476007)(26005)(5660300002)(38100700002)(956004)(66946007)(8936002)(6506007)(107886003)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: kak3ADUNYZj9q4wf5evOgAxpRNG3zT4Zm8rMM0OdPWTvMljNlFJcHWlyq/TfHr2Oz4tsGsL91F8FBOh5HwFO2g6iLTEOZtb43mFYrVNYhnVI1EdQHK1XHk26mYzv37L9ki5ejoC1PLbV45+6QIZ5kVnEQsneMxKr4jGt6jWK+4OCFpIIwlkMbPzfsbjFkIsSqOGt8hSBCgyFnKi7n0RApVJGy4/Hl7fNWEdAywHJOAIMOZrsLUAsQv09mKIGbUoTWf8tnLUW/Pr+B2p+i0+WdtKnKxks9MyA9Lw/rdKwoRhdK2jRp5BkvZmgUDJETgJmatVxVdoP5MqdC/87gElS0GKS91r7Vl1SOtxEWy15XmqaHlstFMZvdSSNXHIuv2CZD7dJYKY8+SuvVwwZk3JydPcBtoKLpQuy4ecSBtRjZm69FDg0jNRTLnOVZdqGrfulTIRhQB1YVMD2XGxA6o6T5HDIwfECqM3oHgJnzkQCizLoDeIX1LZsV9i5De09/ejN0p3HUui7iqBnMLRyXqYwNsQmNTkt07l4X3/3uIZ2l3Aq/HCV/oEoCexi7UszchQgLGq+f0t9O1J5TAkw6pzZ6cxW7jV0B1K1GNUESPlsleY206zALAcjiSztfXksd40D8hs2oTqDXTcMOWlAk8HTAXFtqC1KWJvYo+wliS8QtDWXEpOy39M9HL7UfvYPCs2iESuKE0+fjXuq1xqITcjb5wlmWjGVlv/8Rpmt5J1PiD3eoTHaJLgWGNnQCpKnpO4Zvp9fUEYcnhP3B5Du6Qk/Xv0cZZ4wroY56T25bUvv0vkV+7Yh0rNsVigl6/hwJPAN3iQbetKAStKD95kkQ81UB776y0FuFx8raKDcheW52L3Cri9+aU5RkXisd2uhiUaBRSHsQfDBpXVdtHKYr9bxtIDKwAI8fL2LltxjgM8wRf7jdIT3ReBFu6EKM2DgwsJQMRRINsP6110vSEPGFt7BX1YfmaDH07FKxHPD/CDLl5h+PET9VRGAUGTFgXqYGIEy6i72Fh6vhWGaIgpedNmkwSzvFMq3ENcOcxt2gN4MU42MGAPxHP4AxzInibsN6Sm6vw3rtqV1gzp5L7m9F5+NtRBTHMCQfgS+oht98aPzGDb0edwZz0IIWQSZp4wXcX9z7HWVXJCUgqlhNrpe/8liN5S4Ijr0r5cd+Q+pY6nPP0m7PaBI8j/SM+i0Jcjo9iyIgE+WZ6Lh0fWgMNzhsaBqYEovE9HV9H86pUxIGF8z8+ABuWBRN647e3hq36vVdqqBD7tQGq8duvdbrf3ISb/thnMbPRoHLDw1R36Wpgkw4PJTU5cOSOoRlheCn3Y4Fz5a X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f339426a-300c-47fe-c510-08d91fa7cbf9 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3573.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2021 18:06:19.3518 (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: 9aLcnVk6h063kOrIm61+AwLXd26WIpRrk6DqSVGu5kLHHnktL5dNb8gTLQHbW4LP477KLGihmNMADA4R0ixYQItYZ+tJWtzknwg3nxo+vz0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4639 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250110 X-Proofpoint-GUID: 5chjdaacP6TVIkVK4PqoEGAhmu96sGU4 X-Proofpoint-ORIG-GUID: 5chjdaacP6TVIkVK4PqoEGAhmu96sGU4 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 clxscore=1015 malwarescore=0 bulkscore=0 impostorscore=0 phishscore=0 spamscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org This patch separates the scsi cmd completion code paths so we can complete cmds based on their vq instead of having all cmds complete on the same worker/CPU. This will be useful with the next patch that allows us to create mulitple worker threads and bind them to different vqs, so we can have completions running on different threads/CPUs. Signed-off-by: Mike Christie Reviewed-by: Stefan Hajnoczi --- drivers/vhost/scsi.c | 48 +++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index e585f2180457..b607bff41074 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -176,6 +176,7 @@ enum { struct vhost_scsi_virtqueue { struct vhost_virtqueue vq; + struct vhost_scsi *vs; /* * Reference counting for inflight reqs, used for flush operation. At * each time, one reference tracks new commands submitted, while we @@ -190,6 +191,9 @@ struct vhost_scsi_virtqueue { struct vhost_scsi_cmd *scsi_cmds; struct sbitmap scsi_tags; int max_cmds; + + struct vhost_work completion_work; + struct llist_head completion_list; }; struct vhost_scsi { @@ -200,9 +204,6 @@ struct vhost_scsi { struct vhost_dev dev; struct vhost_scsi_virtqueue vqs[VHOST_SCSI_MAX_VQ]; - struct vhost_work vs_completion_work; /* cmd completion work item */ - struct llist_head vs_completion_list; /* cmd completion queue */ - struct vhost_work vs_event_work; /* evt injection work item */ struct llist_head vs_event_list; /* evt injection queue */ @@ -377,10 +378,11 @@ static void vhost_scsi_release_cmd(struct se_cmd *se_cmd) } else { struct vhost_scsi_cmd *cmd = container_of(se_cmd, struct vhost_scsi_cmd, tvc_se_cmd); - struct vhost_scsi *vs = cmd->tvc_vhost; + struct vhost_scsi_virtqueue *svq = container_of(cmd->tvc_vq, + struct vhost_scsi_virtqueue, vq); - llist_add(&cmd->tvc_completion_list, &vs->vs_completion_list); - vhost_work_queue(&vs->dev, &vs->vs_completion_work); + llist_add(&cmd->tvc_completion_list, &svq->completion_list); + vhost_vq_work_queue(&svq->vq, &svq->completion_work); } } @@ -543,18 +545,17 @@ static void vhost_scsi_evt_work(struct vhost_work *work) */ static void vhost_scsi_complete_cmd_work(struct vhost_work *work) { - struct vhost_scsi *vs = container_of(work, struct vhost_scsi, - vs_completion_work); - DECLARE_BITMAP(signal, VHOST_SCSI_MAX_VQ); + struct vhost_scsi_virtqueue *svq = container_of(work, + struct vhost_scsi_virtqueue, completion_work); struct virtio_scsi_cmd_resp v_rsp; struct vhost_scsi_cmd *cmd, *t; struct llist_node *llnode; struct se_cmd *se_cmd; struct iov_iter iov_iter; - int ret, vq; + bool signal = false; + int ret; - bitmap_zero(signal, VHOST_SCSI_MAX_VQ); - llnode = llist_del_all(&vs->vs_completion_list); + llnode = llist_del_all(&svq->completion_list); llist_for_each_entry_safe(cmd, t, llnode, tvc_completion_list) { se_cmd = &cmd->tvc_se_cmd; @@ -574,21 +575,16 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work) cmd->tvc_in_iovs, sizeof(v_rsp)); ret = copy_to_iter(&v_rsp, sizeof(v_rsp), &iov_iter); if (likely(ret == sizeof(v_rsp))) { - struct vhost_scsi_virtqueue *q; + signal = true; vhost_add_used(cmd->tvc_vq, cmd->tvc_vq_desc, 0); - q = container_of(cmd->tvc_vq, struct vhost_scsi_virtqueue, vq); - vq = q - vs->vqs; - __set_bit(vq, signal); } else pr_err("Faulted on virtio_scsi_cmd_resp\n"); vhost_scsi_release_cmd_res(se_cmd); } - vq = -1; - while ((vq = find_next_bit(signal, VHOST_SCSI_MAX_VQ, vq + 1)) - < VHOST_SCSI_MAX_VQ) - vhost_signal(&vs->dev, &vs->vqs[vq].vq); + if (signal) + vhost_signal(&svq->vs->dev, &svq->vq); } static struct vhost_scsi_cmd * @@ -1799,6 +1795,7 @@ static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features) static int vhost_scsi_open(struct inode *inode, struct file *f) { + struct vhost_scsi_virtqueue *svq; struct vhost_scsi *vs; struct vhost_virtqueue **vqs; int r = -ENOMEM, i; @@ -1811,7 +1808,6 @@ static int vhost_scsi_open(struct inode *inode, struct file *f) if (!vqs) goto err_vqs; - vhost_work_init(&vs->vs_completion_work, vhost_scsi_complete_cmd_work); vhost_work_init(&vs->vs_event_work, vhost_scsi_evt_work); vs->vs_events_nr = 0; @@ -1822,8 +1818,14 @@ static int vhost_scsi_open(struct inode *inode, struct file *f) vs->vqs[VHOST_SCSI_VQ_CTL].vq.handle_kick = vhost_scsi_ctl_handle_kick; vs->vqs[VHOST_SCSI_VQ_EVT].vq.handle_kick = vhost_scsi_evt_handle_kick; for (i = VHOST_SCSI_VQ_IO; i < VHOST_SCSI_MAX_VQ; i++) { - vqs[i] = &vs->vqs[i].vq; - vs->vqs[i].vq.handle_kick = vhost_scsi_handle_kick; + svq = &vs->vqs[i]; + + vqs[i] = &svq->vq; + svq->vs = vs; + init_llist_head(&svq->completion_list); + vhost_work_init(&svq->completion_work, + vhost_scsi_complete_cmd_work); + svq->vq.handle_kick = vhost_scsi_handle_kick; } vhost_dev_init(&vs->dev, vqs, VHOST_SCSI_MAX_VQ, UIO_MAXIOV, VHOST_SCSI_WEIGHT, 0, true, NULL); From patchwork Tue May 25 18:05:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 12279809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C3CEC4708B for ; Tue, 25 May 2021 18:06:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F228A60234 for ; Tue, 25 May 2021 18:06:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232336AbhEYSID (ORCPT ); Tue, 25 May 2021 14:08:03 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:39822 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231960AbhEYSH6 (ORCPT ); Tue, 25 May 2021 14:07:58 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI51Cx110223; Tue, 25 May 2021 18:06:24 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-2020-01-29; bh=BDD2zD4Z9eqQ4D79sxtj+QB1WP36mQ1ylgzUKEXeDy0=; b=mEajGOD6RFZOSnuAgS1GqZO8jpmcN20M/aOE7KYHz6juGepmlzwUas3ErM6CPgg5P+0t ZXK4E7AXxpVTdaUO5Vie6hpPM8BWDiP03NWvXjR64vACXgm2Vx7sK/dAA5saqscWR+V+ qRdS0qe8pWVSGfWCvWbMwllmlSyN8OwtyREkrFNk48oBbPVbOPYLWVzjxSFxhhcSfbqn m/i8He0CeCXRElPDFunQewZQLUFz8OqFrgQrqDdM/bhH0F4cId/N8EBs3PqzKJXk/Yi5 7A64XB4TytlvrzQ+BYwQHEObFutGU+NkvAniW8OqlvkIN+NvqCn+/OJw8GatUq7+pmx3 Tw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 38pqfcexvt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:24 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI6DUZ185109; Tue, 25 May 2021 18:06:23 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2046.outbound.protection.outlook.com [104.47.56.46]) by userp3020.oracle.com with ESMTP id 38qbqsgac5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nu0ejN76PLxN6oiyOKFpNIF5EwZ4BCcWUhDYO23VktnldyctQJtHwq6w8xzWrAa+tuBC6owhTrNQldMGua7Vy7OuSa2eQyswL67c853c1FVdsmm84+FMNCSaCJfSywV5drx7NnehK8/q/119qBWHl8qDUFB/EdUTJNLZyio5WPaRptym0wTM2V2AewuicJA8LHnm3LI6K1gToBGAp93JwaZQar8wCU49KIR0qJRlHTQQJoNM4FMXraHg/ynf/dTk4UryaqaRiV/RpacMsyq38Yx5m+WI8h0qG+REPOLwcYOG8dkneUfHZnQeWHa9IpeVAN7iPaaGP0uV251xwVvjag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BDD2zD4Z9eqQ4D79sxtj+QB1WP36mQ1ylgzUKEXeDy0=; b=n0QiE60/L3wLXS60wLyLEGTnt0so6i9R6cAAMX6vPO3DYx2p5wwmLq4VadJAaFlIzbyuKGMNf6YCVXwLGtF0nQOnDpCdc4P82A+V4hSlbEGIAX90xbsO8eBlUtA3pEty6FUuTtndL0wpSg5DuoEvHP7rC4u+bbxs2CEtGM52VVQ8Uydl8aMxgBMW3En0BqFJtlHqhNIW0JCQKCQ8vxwn4o3ShbBy+f81wHWszEzpSaODFudnR8CGHWlqOdEeLqZRx4BoCI2LxEJSJsiu+y3vksw/gFyg9iyW6E+jJk1KZzyPjUMAnoSSbwnnPvr3PLpEmd1IVbENWpgQouD8F/9S+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; 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=BDD2zD4Z9eqQ4D79sxtj+QB1WP36mQ1ylgzUKEXeDy0=; b=FeY7Mh7NyWbGzF19UXt1MKoCgHK7M/r3HsBAORpGY37anl0iQ7cP6tKBquSuVz9vCwmcUXrNi6MJaihbbb71E9WrtcsuBfTrFkBWkMJJk3qtC9YMQe42P547wMrhVKET9rS+YtqQ+gXolYqPbis47XAj3JLNrlxnKa87YLzUwy0= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) by SJ0PR10MB4639.namprd10.prod.outlook.com (2603:10b6:a03:2db::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.25; Tue, 25 May 2021 18:06:21 +0000 Received: from BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0]) by BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0%7]) with mapi id 15.20.4173.020; Tue, 25 May 2021 18:06:21 +0000 From: Mike Christie To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, stefanha@redhat.com, pbonzini@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org Cc: Mike Christie Subject: [PATCH 7/9] vhost: allow userspace to create workers Date: Tue, 25 May 2021 13:05:58 -0500 Message-Id: <20210525180600.6349-8-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210525180600.6349-1-michael.christie@oracle.com> References: <20210525180600.6349-1-michael.christie@oracle.com> X-Originating-IP: [73.88.28.6] X-ClientProxiedBy: DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) To BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (73.88.28.6) by DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.12 via Frontend Transport; Tue, 25 May 2021 18:06:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d4524a5d-6cdc-46be-d85e-08d91fa7ccdc X-MS-TrafficTypeDiagnostic: SJ0PR10MB4639: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:198; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QIzRP/AnJPEZkdljlCGtbnBq+FD34opBQjI+u+sN6POJ1JiLXHXHqfTHXPkObXLPLTst6DlMlQ0Tgyeo23FT4fgVrd8xy86iGJRYOg5iaoquyaPF9BIqMD6aqMy16P1wdKlcNso//zRFTQ7G9bi3s8NuJleeWwL3FVLTgepuPS/xsRmYChfxZiLYCgMjbOBrH4sMTLwjvE4pVqnxYZ7uTFcz92KfgWyR6fiSWBJ3wmdR2H63ZI9lUvVgK+tLWWEVYCBsa9EAZEFzx+dDTALVo/ZLev2+XiakXJsN4AEdgEtaeSY3uTm015brXywsuIVLLoIW+jE6GFsPagc847eaFFQG2rIbisQ+Jw0uz4svwM1q+cm9llWiK89+jFB9kDEBbQ1KlQ6VgQwhmsiAn0Iao86dlAjJNPEi6tW2TJ7hY8w76XjzH41Elz5SmmVQ5G0ncsBUzzLwN+/KYH5LOHX7xkLXbERCDv7iRmaDv60YeCJ7RPNW/KOmp8lIAsJZQ/R2XXaJC1RWvt4W1LsPk2O4duZg15phdioDqnWqLsTHfgOkP6/wZpRtbSpWiMgpbxCswzWQo9Cz6suYFHgtC1JqGPKZyJraBsZmxsoDPFJmN180yiZ/x9IryUO2MSETEDfHdqqoiwS1tHlMxsVKBx2wa7meaKGbnNGODR+JXmx1Vmr5w4zSsBMfR0VXk6A4q+2P X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3573.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(396003)(376002)(366004)(136003)(346002)(36756003)(2616005)(83380400001)(4326008)(186003)(316002)(6512007)(6666004)(6486002)(1076003)(8676002)(16526019)(478600001)(2906002)(52116002)(66556008)(38350700002)(86362001)(66476007)(26005)(5660300002)(38100700002)(956004)(66946007)(8936002)(6506007)(107886003)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: eXCoNz4Or1M0FfFjF/wcuwJSuc55v5dl+KbIFEeAO3s9/MET51Fo9rGFrIm7O+ZIztZf6y4Bj/QiLrFj3EcylT1S4ySo9oxtmbzVGDMcNxNbdQim9k3Y2l53eEXKLc6I8wmHuC9RVyYnRyJc0lknIP5jfCJBQuppkpmK4r3SD8Oyg8AFbomQOBknxFtVzSzKHClBON30VGhMuj8qSEE17rtqW9/6VvyOfcc9L5WTN72Mn8voD9C/Tfc54XYLiKCe51AmaKfBE9awqwysDVjFit3YcjpywDAe0e07Neh4rFPR395m4ubhuzQOc6Hsh2V38JY28SWIxbxm8wGvHKznpJjBqOvnZU6Azg9vvbAQz8ILdSY/wsz2IzoG6igKvnaEveST4EabDaOQxU7SFrqLbWChnOpj6S9HaYhvqGaWqoAZeIk/2t1AYedFrhHRCr0RUcy0pS3Pitw8d0918U5ntjnK26Ff5Iy9XjDhJ9ffNBHler6jS+Fei82/8UYkY3ierbb1IUJGPyiMkxi83IpSNTAJyvyBDHprCJt+Bdy8dhAjLsoRC5Egk6GNs1PZ/550lSpNhvpfLSh0rSUUMKEbEzZsolkbtKW30zl+QMhfvJDDWN5gDQ2wSUzm2Jqng+AumWTSDfhQlsiFrjoYy/QY5tp5nxmyXa6uaK0ZbKIUtj3hvRrJnhbAajmJVsYhf/vrPsIjFO+Rwd0wjrxvmD+G6LSwSiaF4YqgRwSEF2Zdr4hIDg3HA2IKkYjltw7EPKDiADftJh3IdhpM1fhNVjtqZ0lGMcrfXWd2QfYYi9HeA3BX7fIhOP0ttDZr8piV0Q4Dyb2xfZpIim+1tAwsKv17rDavOIeN1PyVE7Sig7myD3RnE4LnDv464cnwAkJ5xdxxdbC+zwL2yTVEntESeDFyd+i5FjMu/msNoAB5NZ85ewvfBuN2QAn0fDpk4NreY5kfYT3c0Zk0yfdE50ikIK5RNEbRTk+GGtI3KTNs2D1IYqJ92ZM/AUFCJcU7j9qY/nWCnpm1yEwMcyxPpRORkSm8mCJkwdD8+p8tBQEdFISAalZsIpETk5IB6XcfAgGBvGj8T+MjrbBzqwx7ufEuMUoFvG5CsP1aH3qimQ6dNb4qfhfTcS42PDBNCZu3ESycNq1COcEaDpyb4iP3KWxoL6Uf63CqzZphEFyKmOLilg/yRqJd+OzsHelT9VjgguSUWm92+oyV5h7mIsPWCYDnXYDBtMk7bs/Fp3oGPhrdl8n7tARIrqOELQsROJj9u/98M+i8bdO0S2AWshJxw7ktTef7U/dNVdLc6yZzcITg6XckuJwQ652VAhpZaDvIdPFZ/FCV X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d4524a5d-6cdc-46be-d85e-08d91fa7ccdc X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3573.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2021 18:06:21.0778 (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: I3DBZ6InmdHDyA+SjsaeGMi4rkzZ8aQgTNWI996Oyx+GPaY+tAaRRW+enfRDRm6Lwh/3d34uri2sYv5VfNyw0jFZG1B64vdqKFH0Kw6hXZ4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4639 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 X-Proofpoint-ORIG-GUID: mfnR38DOrThe9PWOEm0hT2IW1adgrNL4 X-Proofpoint-GUID: mfnR38DOrThe9PWOEm0hT2IW1adgrNL4 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org This patch allows userspace to create workers and bind them to vqs, so you can have N workers per dev and also share N workers with M vqs. The next patch will allow sharing across devices. Signed-off-by: Mike Christie --- drivers/vhost/vhost.c | 94 +++++++++++++++++++++++++++++++- drivers/vhost/vhost.h | 3 + include/uapi/linux/vhost.h | 6 ++ include/uapi/linux/vhost_types.h | 12 ++++ 4 files changed, 113 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 345ade0af133..981e9bac7a31 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "vhost.h" @@ -42,6 +43,9 @@ module_param(max_iotlb_entries, int, 0444); MODULE_PARM_DESC(max_iotlb_entries, "Maximum number of iotlb entries. (default: 2048)"); +static DEFINE_HASHTABLE(vhost_workers, 5); +static DEFINE_SPINLOCK(vhost_workers_lock); + enum { VHOST_MEMORY_F_LOG = 0x1, }; @@ -617,8 +621,17 @@ static void vhost_detach_mm(struct vhost_dev *dev) dev->mm = NULL; } -static void vhost_worker_free(struct vhost_worker *worker) +static void vhost_worker_put(struct vhost_worker *worker) { + spin_lock(&vhost_workers_lock); + if (!refcount_dec_and_test(&worker->refcount)) { + spin_unlock(&vhost_workers_lock); + return; + } + + hash_del(&worker->h_node); + spin_unlock(&vhost_workers_lock); + WARN_ON(!llist_empty(&worker->work_list)); kthread_stop(worker->task); kfree(worker); @@ -632,7 +645,7 @@ static void vhost_workers_free(struct vhost_dev *dev) return; for (i = 0; i < dev->num_workers; i++) - vhost_worker_free(dev->workers[i]); + vhost_worker_put(dev->workers[i]); kfree(dev->workers); dev->num_workers = 0; @@ -652,6 +665,8 @@ static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) worker->id = dev->num_workers; worker->dev = dev; init_llist_head(&worker->work_list); + INIT_HLIST_NODE(&worker->h_node); + refcount_set(&worker->refcount, 1); task = kthread_create(vhost_worker, worker, "vhost-%d", current->pid); if (IS_ERR(task)) @@ -664,6 +679,9 @@ static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) if (ret) goto stop_worker; + spin_lock(&vhost_workers_lock); + hash_add(vhost_workers, &worker->h_node, worker->task->pid); + spin_unlock(&vhost_workers_lock); return worker; stop_worker: @@ -673,6 +691,67 @@ static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) return NULL; } +static struct vhost_worker *vhost_worker_find(struct vhost_dev *dev, pid_t pid) +{ + struct vhost_worker *worker, *found_worker = NULL; + + spin_lock(&vhost_workers_lock); + hash_for_each_possible(vhost_workers, worker, h_node, pid) { + if (worker->task->pid == pid) { + /* tmp - next patch allows sharing across devs */ + if (worker->dev != dev) + break; + + found_worker = worker; + refcount_inc(&worker->refcount); + break; + } + } + spin_unlock(&vhost_workers_lock); + return found_worker; +} + +/* Caller must have device mutex */ +static int vhost_vq_set_worker(struct vhost_virtqueue *vq, + struct vhost_vring_worker *info) +{ + struct vhost_dev *dev = vq->dev; + struct vhost_worker *worker; + + if (vq->worker) { + /* TODO - support changing while works are running */ + return -EBUSY; + } + + if (info->pid == VHOST_VRING_NEW_WORKER) { + worker = vhost_worker_create(dev); + if (!worker) + return -ENOMEM; + + info->pid = worker->task->pid; + } else { + worker = vhost_worker_find(dev, info->pid); + if (!worker) + return -ENODEV; + } + + if (!dev->workers) { + dev->workers = kcalloc(vq->dev->nvqs, + sizeof(struct vhost_worker *), + GFP_KERNEL); + if (!dev->workers) { + vhost_worker_put(worker); + return -ENOMEM; + } + } + + vq->worker = worker; + + dev->workers[dev->num_workers] = worker; + dev->num_workers++; + return 0; +} + /* Caller must have device mutex */ static int vhost_worker_try_create_def(struct vhost_dev *dev) { @@ -1680,6 +1759,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg struct eventfd_ctx *ctx = NULL; u32 __user *idxp = argp; struct vhost_virtqueue *vq; + struct vhost_vring_worker w; struct vhost_vring_state s; struct vhost_vring_file f; u32 idx; @@ -1794,6 +1874,15 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg if (copy_to_user(argp, &s, sizeof(s))) r = -EFAULT; break; + case VHOST_SET_VRING_WORKER: + if (copy_from_user(&w, argp, sizeof(w))) { + r = -EFAULT; + break; + } + r = vhost_vq_set_worker(vq, &w); + if (!r && copy_to_user(argp, &w, sizeof(w))) + r = -EFAULT; + break; default: r = -ENOIOCTLCMD; } @@ -2726,6 +2815,7 @@ EXPORT_SYMBOL_GPL(vhost_set_backend_features); static int __init vhost_init(void) { + hash_init(vhost_workers); return 0; } diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 0a252dd45101..75b884ad1f17 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -14,6 +14,7 @@ #include #include #include +#include struct vhost_work; typedef void (*vhost_work_fn_t)(struct vhost_work *work); @@ -28,6 +29,8 @@ struct vhost_work { struct vhost_worker { struct task_struct *task; struct llist_head work_list; + struct hlist_node h_node; + refcount_t refcount; struct vhost_dev *dev; int id; }; diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index c998860d7bbc..ce32119cb139 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -70,6 +70,12 @@ #define VHOST_VRING_BIG_ENDIAN 1 #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state) #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state) +/* Create/bind a vhost worker to a virtqueue. If pid > 0 and matches an existing + * vhost_worker thread it will be bound to the vq. If pid is + * VHOST_VRING_NEW_WORKER, then a new worker will be created and bound to the + * vq. + */ +#define VHOST_SET_VRING_WORKER _IOWR(VHOST_VIRTIO, 0x15, struct vhost_vring_worker) /* The following ioctls use eventfd file descriptors to signal and poll * for events. */ diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_types.h index f7f6a3a28977..5113baa8bc3e 100644 --- a/include/uapi/linux/vhost_types.h +++ b/include/uapi/linux/vhost_types.h @@ -47,6 +47,18 @@ struct vhost_vring_addr { __u64 log_guest_addr; }; +#define VHOST_VRING_NEW_WORKER -1 + +struct vhost_vring_worker { + unsigned int index; + /* + * The pid of the vhost worker that the vq will be bound to. If + * pid is VHOST_VRING_NEW_WORKER a new worker will be created and it's + * pid will be returned in pid. + */ + __kernel_pid_t pid; +}; + /* no alignment requirement */ struct vhost_iotlb_msg { __u64 iova; From patchwork Tue May 25 18:05:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 12279811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FF2DC4707F for ; Tue, 25 May 2021 18:06:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3EDAD60234 for ; Tue, 25 May 2021 18:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231273AbhEYSID (ORCPT ); Tue, 25 May 2021 14:08:03 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:56508 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231430AbhEYSH7 (ORCPT ); Tue, 25 May 2021 14:07:59 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI6BGH108199; Tue, 25 May 2021 18:06:25 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-2020-01-29; bh=jNoPSS9OR1afYGivf8txMPOzzrt/zQAPB8PnBy4NwRs=; b=rD0DiOzTbN5AsJIYvW3bcrVXpzEiUhst4lcMgkKlaSa+bODrZH0m+Ptw41e5xvXKBNPo +iSLEqjRKFWyUvwsBKRvQLve5eVyVI4lzDzmDWd4VOBWLfnotu7EbmTg8PkN8VzhYuM2 9bHHcc/qQGK1VJSQ0LONKbyILyDj3vEuicZTzIF0zPG0FT355rqrh8tfAvwnKrzWyoyA 06wCLNFDCvaD9C2m2oSeftHN1TjfMzLbDNCgKfuif29HfZw2GXt2JkT7+N2JP+f7r38+ d1BB5gfqHB0oGfGWMkb0KonEDDMD/E7qMyxIxYSJmMp6ICh2NolaM3dnlRE4Q93Vnvxf 3A== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 38q3q8xc0n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:25 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI63vf094406; Tue, 25 May 2021 18:06:24 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2048.outbound.protection.outlook.com [104.47.56.48]) by aserp3030.oracle.com with ESMTP id 38pr0c0xub-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QaH7+N5B8bX3jO/2X90JSa1f4clH8KiPBmKwZWsBlPquMbs7S6vfIzQ0I+UFGIiqZeL1EN3CahPk/OGw83UzjKjKXF6e0I6RO4GTXdNNm8eU65zdHVFendBRhSTiLA1E7wsiTV2glYWnln+JYXxGXBHcgWyAX1YalG1bfqVpHoMf3ypsWmgFcd5FwjyqalVMmii5MS3d7t1S3XEsmpV+TNNJ6KY+y9++dEbzGNAWf3WNdVYYMR2jOnU5aJvSRFNCO46smXMab66egUIR49yggjoiOL/oPm9hkcQc7z9mo1KL8FmhPwuNwVXkGLr0NI9XRd0ujo7vlNigxezhSIRy+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jNoPSS9OR1afYGivf8txMPOzzrt/zQAPB8PnBy4NwRs=; b=K0SUzclFkhILEEZJrh6GcvJNHsaarnQ0r+6KkzKpDfai7yvfaAGmuB8NnhwMY1FaNRLGTMgepZZPQlw4U1H1RXpPr8ZzIBS924QD9tcMszZqssOk/za1ybPVIT5QoolvbZgzF9wcj3f4sYXbyRWx11IngewPTHWOYu14tcNxd3AI01gy2U9ROiTmGwW5nYUpatit+kaxgy7OD1Yc+SnRtpeqjWiS2aZNgA5w6ydSpoNUZ6r6/v/5IiXXYYTAyWDQEJgwOAHxWKkJql9PP4Rqlzf9uskDhAbewkzGCZZhnBnlzttmRTdw379b9kkhSjVnslpi2yKV0URR7st/ryDN2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; 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=jNoPSS9OR1afYGivf8txMPOzzrt/zQAPB8PnBy4NwRs=; b=s+EgbGvZTS8AXO7xyCasBeU15Jsomb6faYD7uvdsnO2SBdAwodt4HzNvOnnRzrCDkpp5TP1XTKtoiE+abeLUhny8xD/RbIotmIIXX3Ynf3lshday2e24p9OEauNZH3WzMEWIj5ZDwP0k+LcKJFfppUw0IjhTEsKt2huHJZDDa7I= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) by SJ0PR10MB4639.namprd10.prod.outlook.com (2603:10b6:a03:2db::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.25; Tue, 25 May 2021 18:06:23 +0000 Received: from BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0]) by BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0%7]) with mapi id 15.20.4173.020; Tue, 25 May 2021 18:06:23 +0000 From: Mike Christie To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, stefanha@redhat.com, pbonzini@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org Cc: Mike Christie Subject: [PATCH 8/9] vhost: add vhost_dev pointer to vhost_work Date: Tue, 25 May 2021 13:05:59 -0500 Message-Id: <20210525180600.6349-9-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210525180600.6349-1-michael.christie@oracle.com> References: <20210525180600.6349-1-michael.christie@oracle.com> X-Originating-IP: [73.88.28.6] X-ClientProxiedBy: DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) To BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (73.88.28.6) by DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.12 via Frontend Transport; Tue, 25 May 2021 18:06:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1a44b980-049a-42d0-3128-08d91fa7ce3e X-MS-TrafficTypeDiagnostic: SJ0PR10MB4639: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:291; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 14MhCWrYnmrOerTB/xo9jz4W6X+Hbhp8ckBN8heH+p9+6wckyRGRqlQAfE4G8YgKTZ5pSjWfKzovSI3wSeH7bLPlErIdOicX48dRR876kaawHEjzvkZ80zXtgWpYAZrufg9gmIjJAC0DPgEkaph/EzDQfjmjK1wTyV7NQkKelQ7ttFIJwLf736DX4YMKbS76RRld03qhXQUyn5g4pvfgx9kbXiwj5OSm/U+nIc7olhjChuO3qYt4IMVJZlbUF05oOhGtinncSqQkQ+/w/heC7Y67wigyYs1CyFbqRSHvdjBQuyjSQx4+8px85sV7pFdJHEinHObjD0N/SgO9d8pxUjGU4907IXfCCZ4oY40iBqxuN0olbhu6aNHxq8nthstIid5fMl++qoOs5YvzbcK+d0DAqj79fpLWBXordqjwt5DzGwNdNYTdGaAUDjTYctq/d0jH+w/KLLhXNASVpzfe1wLHyp9gtW5zglk8D7NbwzQ2E1avQfdAez8gxWbwgwW/uhVTzPZ+3vr4O3ICMivQdR28HS7By8PO8J+COEtmA80eIQVr3Ti4ndeB2iuvwgAdlSyGrzyR3z1ZeAzUnCoE7fPGa/eG/0rLmf2Ghe+xvThV2kumh4IueByPf6B+J6BliVBU/7GVdtLjZb7jhvIkNwGs5G2XX0KUJD5isbN4KRCbsT7HEuh6cOBWkhfGQ4+c X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3573.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(396003)(376002)(366004)(136003)(346002)(36756003)(2616005)(83380400001)(4326008)(186003)(316002)(6512007)(6666004)(6486002)(1076003)(8676002)(16526019)(478600001)(2906002)(52116002)(66556008)(38350700002)(86362001)(66476007)(26005)(5660300002)(38100700002)(956004)(66946007)(8936002)(6506007)(107886003)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: cJAoJS7YA4ZINs0M82eBteIXyUa5av1Q9j7OoA0wbIb1aP1uCMrA45UKYxEAVJe2Bm+ANos59BlXPg+C8rJwhP7iUjwqre0+sJSuK2pU5Ijj51IpG0uwPb/5nu9IGllF7hWL/+7Qoxn7/Q/B2BbEJOaxA2dYEE5DJkLJRMm2JCiDU4Blkpf6DSMQC/rsbCFjFtErXsz9RY3yUi5aYFcbsutS/5WGKrm3243aQ/ZiGJRt6+cnYCC/4ztV7tMM8v8u2cuIljdNROSrR4dhSgdDT65VPETHS6T5S2XkwETYeNnvxQ0iog2nQelpEITeiHdvSoyTgXwy3GMa+MFoDZuh0PJEdIW4HFZojgy2z2ycxWJ1vaZov1AteZ5/+rvP9oHwuaF5IX56tvAop6XQeihzaZYOE9WAjh4FxfKXN8J7QP/OsYBJwMylO4CdTK3y2Tb3/9nzE0f+3zdxMoFitX8a7iope2fnabqp1HMIQvQ5af9hc0VoASxd35T8JaiMmcuao1AA8WmHUfBJDMZ9C5UlfQGUc/mFWXN1jwsb+7VfODbksVABZOqIrmIw3Txj45EuyNkQY24V/QLxfaJ2FXA2LXK35JELApgBjD9VIlUPwtP0qZMUGsJfDgNiw8iY58/VgJmv7Ov6cgzi/L7yga3iiW9JzuUwWc+5MfSn7GJ44S9+vPdoggX0eItNXcnTxsGtNTQIUBE8kybvG3r3CXeohrO7Dd8Oiq10FlHz7nz7D8+NKPEVfGqKhjZFIPA8hhI7rrI58YIDFpPAWop/lf/5ZZke2u71Bql5Vqubr7YPHcl/l5ei9RHWBopcRwCULoxFiLhQQH+L0i/V3aCgspHBCy4bd6/Q2hzFArM1s18LZrF0lw+mapQqWvVsnHHMm/LaKQJjG+dg2JrX4iho0FhqYlX2vajS2n110UmEMkyzuMfHnJ8kmUrSoZvsii4SxWW7VE/7PhEO2SCRDwtczcUpK/Kyc4LSwBERRIsR4oP7ePvXyrb5UfrFUc59Dl4u+Ymoo1fharqt1Vvk6aRBM7RZwbXqhxWcmevY/Smnyq5NYSryQ8yzI2xS00QhhUkiCPDyAkboQqnqwlTq1H1H13B7X0Z2W30FpJPnemt/DpCCI5oO8AHgxLTeOzj9vcjIBXqFwNFGHzd9lxrNvuzxsxVdD5sFDn/LnJq35P6noyV75mZ92MCmvUA0pBCUkCeaxBUAbCWskJd0ptjdV0VoVxYTefAW9Oe0h9qdLwmSJ58ADEDl59PW/l2qh66xuuiWvJAsGA8KbvtOnrizYDz9GU4ccJuKZNpaavwXdue/mYEFhsGHgcEfGFuURURevqgGH9b7 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a44b980-049a-42d0-3128-08d91fa7ce3e X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3573.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2021 18:06:23.1516 (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: uLh+viGjj9PYhXLI/HmywHqKIjNAPzVPY54IA2vy9/H/pEoSjNyrXMXbl5aOZ5xYcZua9fvOqd4pzHCL8i9jIiAXfsabaXkWkqYqSXp4Z0g= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4639 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 X-Proofpoint-GUID: Nr6yb43KqpaReSeoJ46Rsod6Oaj-CrsM X-Proofpoint-ORIG-GUID: Nr6yb43KqpaReSeoJ46Rsod6Oaj-CrsM X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 clxscore=1015 malwarescore=0 bulkscore=0 impostorscore=0 phishscore=0 spamscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org The next patch allows a vhost_worker to handle different devices. To prepare for that, this patch adds a pointer to the device on the work so we can get to the different mms in the vhost_worker thread. Signed-off-by: Mike Christie Reviewed-by: Stefan Hajnoczi --- drivers/vhost/scsi.c | 7 ++++--- drivers/vhost/vhost.c | 24 ++++++++++++++---------- drivers/vhost/vhost.h | 4 +++- drivers/vhost/vsock.c | 3 ++- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index b607bff41074..073b20bca257 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -1808,7 +1808,7 @@ static int vhost_scsi_open(struct inode *inode, struct file *f) if (!vqs) goto err_vqs; - vhost_work_init(&vs->vs_event_work, vhost_scsi_evt_work); + vhost_work_init(&vs->dev, &vs->vs_event_work, vhost_scsi_evt_work); vs->vs_events_nr = 0; vs->vs_events_missed = false; @@ -1823,7 +1823,7 @@ static int vhost_scsi_open(struct inode *inode, struct file *f) vqs[i] = &svq->vq; svq->vs = vs; init_llist_head(&svq->completion_list); - vhost_work_init(&svq->completion_work, + vhost_work_init(&vs->dev, &svq->completion_work, vhost_scsi_complete_cmd_work); svq->vq.handle_kick = vhost_scsi_handle_kick; } @@ -2017,7 +2017,8 @@ static int vhost_scsi_port_link(struct se_portal_group *se_tpg, if (!tmf) return -ENOMEM; INIT_LIST_HEAD(&tmf->queue_entry); - vhost_work_init(&tmf->vwork, vhost_scsi_tmf_resp_work); + vhost_work_init(&tpg->vhost_scsi->dev, &tmf->vwork, + vhost_scsi_tmf_resp_work); mutex_lock(&vhost_scsi_mutex); diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 981e9bac7a31..eb16eb2bbee0 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -182,10 +182,12 @@ static int vhost_poll_wakeup(wait_queue_entry_t *wait, unsigned mode, int sync, return 0; } -void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn) +void vhost_work_init(struct vhost_dev *dev, struct vhost_work *work, + vhost_work_fn_t fn) { clear_bit(VHOST_WORK_QUEUED, &work->flags); work->fn = fn; + work->dev = dev; } EXPORT_SYMBOL_GPL(vhost_work_init); @@ -201,7 +203,7 @@ void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn, poll->wqh = NULL; poll->vq = vq; - vhost_work_init(&poll->work, fn); + vhost_work_init(dev, &poll->work, fn); } EXPORT_SYMBOL_GPL(vhost_poll_init); @@ -270,12 +272,13 @@ void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work) } EXPORT_SYMBOL_GPL(vhost_work_queue); -static void vhost_work_dev_flush_on(struct vhost_worker *worker) +static void vhost_work_dev_flush_on(struct vhost_dev *dev, + struct vhost_worker *worker) { struct vhost_flush_struct flush; init_completion(&flush.wait_event); - vhost_work_init(&flush.work, vhost_flush_work); + vhost_work_init(dev, &flush.work, vhost_flush_work); vhost_work_queue_on(&flush.work, worker); wait_for_completion(&flush.wait_event); @@ -286,7 +289,7 @@ void vhost_work_dev_flush(struct vhost_dev *dev) int i; for (i = 0; i < dev->num_workers; i++) - vhost_work_dev_flush_on(dev->workers[i]); + vhost_work_dev_flush_on(dev, dev->workers[i]); } EXPORT_SYMBOL_GPL(vhost_work_dev_flush); @@ -306,7 +309,7 @@ EXPORT_SYMBOL_GPL(vhost_has_work); void vhost_vq_work_flush(struct vhost_virtqueue *vq) { - vhost_work_dev_flush_on(vq->worker); + vhost_work_dev_flush_on(vq->dev, vq->worker); } EXPORT_SYMBOL_GPL(vhost_vq_work_flush); @@ -573,14 +576,15 @@ static void vhost_attach_cgroups_work(struct vhost_work *work) s->ret = cgroup_attach_task_all(s->owner, current); } -static int vhost_attach_cgroups_on(struct vhost_worker *worker) +static int vhost_attach_cgroups_on(struct vhost_dev *dev, + struct vhost_worker *worker) { struct vhost_attach_cgroups_struct attach; attach.owner = current; - vhost_work_init(&attach.work, vhost_attach_cgroups_work); + vhost_work_init(dev, &attach.work, vhost_attach_cgroups_work); vhost_work_queue_on(&attach.work, worker); - vhost_work_dev_flush_on(worker); + vhost_work_dev_flush_on(dev, worker); return attach.ret; } @@ -675,7 +679,7 @@ static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) worker->task = task; wake_up_process(task); /* avoid contributing to loadavg */ - ret = vhost_attach_cgroups_on(worker); + ret = vhost_attach_cgroups_on(dev, worker); if (ret) goto stop_worker; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 75b884ad1f17..75ad3aa5adca 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -24,6 +24,7 @@ struct vhost_work { struct llist_node node; vhost_work_fn_t fn; unsigned long flags; + struct vhost_dev *dev; }; struct vhost_worker { @@ -47,7 +48,8 @@ struct vhost_poll { struct vhost_virtqueue *vq; }; -void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn); +void vhost_work_init(struct vhost_dev *dev, struct vhost_work *work, + vhost_work_fn_t fn); void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work); bool vhost_has_work(struct vhost_dev *dev); void vhost_vq_work_flush(struct vhost_virtqueue *vq); diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index f954f4d29c95..302415b6460b 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -648,7 +648,8 @@ static int vhost_vsock_dev_open(struct inode *inode, struct file *file) file->private_data = vsock; spin_lock_init(&vsock->send_pkt_list_lock); INIT_LIST_HEAD(&vsock->send_pkt_list); - vhost_work_init(&vsock->send_pkt_work, vhost_transport_send_pkt_work); + vhost_work_init(&vsock->dev, &vsock->send_pkt_work, + vhost_transport_send_pkt_work); return 0; out: From patchwork Tue May 25 18:06:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 12279813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1847BC2B9F8 for ; Tue, 25 May 2021 18:06:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1502610A8 for ; Tue, 25 May 2021 18:06:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232245AbhEYSIE (ORCPT ); Tue, 25 May 2021 14:08:04 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:39854 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232231AbhEYSIC (ORCPT ); Tue, 25 May 2021 14:08:02 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI5ee1110747; Tue, 25 May 2021 18:06:29 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-2020-01-29; bh=fOauqFxTvnnDuWkdAM9Xn9ghBtvojat93NonAZx9odw=; b=Pi/ZmEzzDbiZ1JI5JbZH5BBd5ZE6Q7kLuG/+9WGQlxSMscVzhz8NZAQlA/XNM6joRHuS 8L4hzlVqR7TLveKQajl7wjXmDT0tHuoilRUYjDLNOriXDgjkqBT676EcSnJzNnDEo0s0 qGJlpuGJPeQ3QH3HgdTNsbYJEzYU+p7aqrqveEjes+23cjQB0zm16vO1q0yvxgwS9IIp 9S6BjVw84gjxPkwxX7MeTr9jk8I23SWw1bn/3LJLj56/IfkNC9aa/n1AeMYjgMmI1plf xYuT8mHPYvpwIPnz5nTxMAkXsNvVxug1bOmDULWgCEHUxN+a3hro5Qe97AskhVpcCV99 xg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 38pqfcexw0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:28 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14PI5GM4084737; Tue, 25 May 2021 18:06:28 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2041.outbound.protection.outlook.com [104.47.56.41]) by userp3030.oracle.com with ESMTP id 38pq2ufcpc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 May 2021 18:06:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QLtxSRXcPvWOlfdnVe7x3DIOa7HL/ryBcUd+vRD+6JZvWriN1KVehSy8r6n4rqAwOr2h2hN/mOE8FL1iEp9wkwJbybV2/0ychDk4K6RYE30o4Jm3OqkUw8uN7ZyYRMzdQbfVqaE9TMzfJ9PPyd3uT4UsjNkVzbuvX5UZPjamsv/9+QBM+9aQvlQM22uEPTjt6kW6sq3WTSvwJISqJI357t8xeJrVIt22SpbwhTWivdpky3LtC3meEnJaViiPubjwRAslaeyleVhDdSGqrC/j1XLcfKyijOSkMsLWK11mtsglYI16O5WdtbLmwUxV8AQwoKHpvqS9POhQbQGW7uifhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fOauqFxTvnnDuWkdAM9Xn9ghBtvojat93NonAZx9odw=; b=fXLpoRWi1qjeEA1b9Mt+1SihxwSCAE3Nx9tn3YcfaqalFJtPPuwbegusgUbquNApf2GnTGPfEZTwiT5Yk3k1xQB03olxM3CUxbZG53K8rj+kpsBQ5AM/WxDIRP6XLG4ckj8/TMJQGXNGkHQnjDBKPQvfBGGUNe3DbAkE/9I3TjKR3vajqXeNhnQTjSEQxzrFWpOFlLfVVlL/zU8zqO1eGAvlpTl/q31RQBBWTvP4RZDwj1jqQdOCZ3zsTU7uT0r2Y9JeLzwx/8XOONkdLMNcvQHTpcAlHBQ8h/YXfoVpXHhDj7Oe3YOjEbamrSDiKQK13/EgP3UPLRFG/pf4LYfq4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; 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=fOauqFxTvnnDuWkdAM9Xn9ghBtvojat93NonAZx9odw=; b=QeYulF+hbWzszxyizJQvaHJjKft5X7Y0HZc1wjXlcDEbG1it8SqUWAvdr1elIOfM/3LTCAuSagrZO61qERx2av1F1M0PBusFykI4pwfdWwLYS4cB4arGZ3/y9NicKQeOm3tuZJh/dozSXckcsKIcQ3E7b2C7JgW+x9MC/t81vk0= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) by SJ0PR10MB4639.namprd10.prod.outlook.com (2603:10b6:a03:2db::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.25; Tue, 25 May 2021 18:06:26 +0000 Received: from BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0]) by BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::b09d:e36a:4258:d3d0%7]) with mapi id 15.20.4173.020; Tue, 25 May 2021 18:06:24 +0000 From: Mike Christie To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, stefanha@redhat.com, pbonzini@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org Cc: Mike Christie Subject: [PATCH 9/9] vhost: support sharing workers across devs Date: Tue, 25 May 2021 13:06:00 -0500 Message-Id: <20210525180600.6349-10-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210525180600.6349-1-michael.christie@oracle.com> References: <20210525180600.6349-1-michael.christie@oracle.com> X-Originating-IP: [73.88.28.6] X-ClientProxiedBy: DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) To BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (73.88.28.6) by DM6PR13CA0021.namprd13.prod.outlook.com (2603:10b6:5:bc::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.12 via Frontend Transport; Tue, 25 May 2021 18:06:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3cd7630d-6ce2-4efc-e994-08d91fa7cf1d X-MS-TrafficTypeDiagnostic: SJ0PR10MB4639: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l7qIYOpT82bZRVsnkGV4ZcH2YHARBVC1Pz33fazUi9kKFvRXZiTCEL/bQn+PedVJr8BrO5UmikPZjocXZ9LoiERxLjBD9hGcSpvNMAZXBpojcbrqCab4ecKSJC6Uetzu9c3uWlTfAyDmYOCNmBLi2Zuyl7h3TyVYkqy7RkXpaxpuYNhiLI4U+yVLf5lCW0d/teKPuUpHcb8PXZp9yQFE1JkXX5fHkeoXfNBZ9Nev4nBsnUOY3dqSNRZaczUgHmgAfmr9FcVWHarWGTBNkq3FxIITR89qDpmFIYkuuiXF2TDaqyBViijltdGBv2w1vgJkl5cPc9QynD1V+tva5mcjEB+slitamZEoZVdRJFxPPNfG2ifzAWw/menVdjUhIKkx+GH+gib5TgmHAMU479Xew/Z767LwXBOlCSJcGfkvSrUzXqEDp3rqm3lwHG2jHjRZ4vCgvApdeQAYoDHFIAP7BfhtU6g/I3yeS2WvD+IB2w+LEiHkzDTzNExNuXwJrNuBtwtEjyeQHpqoH1skKcH7g9hgLWsRENLVEPVXLryJfWY6lcWIlcj3UPYSrkEHxWPSTTGY0iZXjT/M7chujoUx+4WqOiWYG803jZJ4xqUOhFDthDWBUTJCE6hlAP9qrgX/m+FK5ttBvlWj/bx5a7FUMpXIuv+FsVxyaFxLjujgyJI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3573.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(396003)(376002)(366004)(136003)(346002)(36756003)(2616005)(83380400001)(4326008)(186003)(316002)(6512007)(6666004)(6486002)(1076003)(8676002)(16526019)(478600001)(2906002)(52116002)(66556008)(38350700002)(86362001)(66476007)(26005)(5660300002)(38100700002)(956004)(66946007)(8936002)(6506007)(107886003)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: uE11UUqXKVNHZyp7fxTSddCO30THPAklTVEYDbXKp1fRyfven2o+10inr6EYFZArKPu/23yb+pQDXCxP1HipUe3MMH2mR11r1KPgNWcslHbOr+1Jd8KEG3/FfngoF3G8Hanj1Rnc0SNU0UiOGh9/BoEY4G1kGVcPC/Jww0Slfm+4USxwqOGTBSq7tmFDpUAN6RdHt8yQMqJHLToqE+sgFGI79iB+rzZ+RzjdsbTV9tK6huBd4nEx6U68dlpoqwSQ4YWJcKePPGV4M36WfurSHrc1Luw9ypuQ3xn+0bdNcWgXtsEv95KIJ7Kh5I8jwV4/0hyvljrNzhCxkLwMkz0FCH1nuGm14QCoSWW39fj9F1xniXw2QQCpIINNwVvLdsgU2CTjX7ctifc8c8l4UwGYfj4PYrbiH7UaKKXBTIGUAdt1j/oEWxqmXKOVdaBcsLaPItOUgXTI8amJQuadClReS73NbMYPYkKz6teoZzQPTHYmxupep1ufRs7LLuCb9bng0IzKkPxgpFQ46PXXe6mNikdot6/ZDoO1uIkF/iAFMLa0LjQ1H3InkS5cdiom8t7heg2EKiiHbmbhbuUA4/P7zf3nCxgtbsu8AS/uNlghuAbTXuVVU8/ky4TUGGxrrDMfvawvB3o6/HOp0JyV2ppgdBiNC57irp2EiUBTR+ncQOwv7TYG7PhlpVqYa9cvfOjH/AhMyN0b0iXf+wGKlvOKt4Fylf9jl2u3/X7CElT9dLvIU57xDy+/UHuLj/0J3rNFyInm1MxDQsEgl3awWlPY4XY2/Iy7pndcYHTqw9XVp7erRKcP6cgs4dmG0+5o+850UevCZNRglmtPhLpjWTPHBRxEk7bST1841tsYWzzvb3exBy2w3wbj8pRY/gk7GmfToytqNPJGD/w9LXr7V3hF/HX8s0p4gB4QOTeA/Ziof4lN3W4SvERwZyhp+b9MsDMDjQBTeZ2gW6O2YqlEoZBM1KR5NIxuB5FQg3+y3Z8k0UeDzeboekzBiMMpAN1IHQEC/xuSBzQOjjN0Xqml8CJZxIjJkxGLbXl10EeoZkH0+wwGpfCwfpVq9rDH6WrnVMUETx0JGO0GKUShTv/mA+ezGwMXUSeaYZngpE6PCXt1b84bdPXNfYD8f3zRtnoXfgY9GkUNo5nsB2Hsc5TNL2NCMx0wynYaw86Ye0SSXUgMrgDexf6P5PAY4wNLQ3SAGiy40ST0PzwK45+RSCa8i7N81E3ALTgVvzxZ6eDB6WFN6mbC+dFbKQBrixtiBJnJ/cS4R9Uc3LgUuERzpuBMSWIsuoH6MiheOZs4/j+IVEOLQMNl6I5L6dAAyw9qXEg8Qnge X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3cd7630d-6ce2-4efc-e994-08d91fa7cf1d X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3573.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2021 18:06:24.6348 (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: CuKOjWUpTFJ3kRzkscYCoBGlJgccNVyD2ibf9JWxfwj93HPSG12HFkB0W4mrToNGPAToVKqiAvh9J7SXZJufDJlN76f3cVzvuHQGsuA9tCs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4639 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 X-Proofpoint-ORIG-GUID: Z6oNXHcwliieyGRFX3SY4ajHLBPo3uaD X-Proofpoint-GUID: Z6oNXHcwliieyGRFX3SY4ajHLBPo3uaD X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9995 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105250111 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org This allows a worker to handle multiple device's vqs. TODO: - The worker is attached to the cgroup of the device that created it. In this patch you can share workers with devices with different owners which could be in different cgroups. Do we want to restict sharing workers with devices that have the same owner (dev->mm value)? Signed-off-by: Mike Christie --- drivers/vhost/vhost.c | 16 +++++++--------- drivers/vhost/vhost.h | 1 - 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index eb16eb2bbee0..c32f72b1901c 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -388,12 +388,10 @@ static void vhost_vq_reset(struct vhost_dev *dev, static int vhost_worker(void *data) { struct vhost_worker *worker = data; - struct vhost_dev *dev = worker->dev; struct vhost_work *work, *work_next; + struct vhost_dev *dev; struct llist_node *node; - kthread_use_mm(dev->mm); - for (;;) { /* mb paired w/ kthread_stop */ set_current_state(TASK_INTERRUPTIBLE); @@ -412,15 +410,20 @@ static int vhost_worker(void *data) smp_wmb(); llist_for_each_entry_safe(work, work_next, node, node) { clear_bit(VHOST_WORK_QUEUED, &work->flags); + dev = work->dev; + + kthread_use_mm(dev->mm); + __set_current_state(TASK_RUNNING); kcov_remote_start_common(dev->kcov_handle); work->fn(work); kcov_remote_stop(); if (need_resched()) schedule(); + + kthread_unuse_mm(dev->mm); } } - kthread_unuse_mm(dev->mm); return 0; } @@ -667,7 +670,6 @@ static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) return NULL; worker->id = dev->num_workers; - worker->dev = dev; init_llist_head(&worker->work_list); INIT_HLIST_NODE(&worker->h_node); refcount_set(&worker->refcount, 1); @@ -702,10 +704,6 @@ static struct vhost_worker *vhost_worker_find(struct vhost_dev *dev, pid_t pid) spin_lock(&vhost_workers_lock); hash_for_each_possible(vhost_workers, worker, h_node, pid) { if (worker->task->pid == pid) { - /* tmp - next patch allows sharing across devs */ - if (worker->dev != dev) - break; - found_worker = worker; refcount_inc(&worker->refcount); break; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 75ad3aa5adca..40c400172a84 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -32,7 +32,6 @@ struct vhost_worker { struct llist_head work_list; struct hlist_node h_node; refcount_t refcount; - struct vhost_dev *dev; int id; };