From patchwork Thu Feb 24 21:22:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759270 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 467A2C433F5 for ; Thu, 24 Feb 2022 21:23:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234688AbiBXVYO (ORCPT ); Thu, 24 Feb 2022 16:24:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234661AbiBXVYN (ORCPT ); Thu, 24 Feb 2022 16:24:13 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2056.outbound.protection.outlook.com [40.107.243.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56AF8199E26; Thu, 24 Feb 2022 13:23:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GC6vtxZg7KaqPki4lbz+z4EPGv4DSH2CvjeiB3/Qax94wOxR6biAs50sEOi5x6RGc8bFhRvqdHf9Hc7PIgnOaKQtbHeqmf0DRxALxQV0mOBhSj/9ht4clzRU/wTwb1OohQswxGOPR5p9JMk1dQC00AVGt8EeRj9aBWpSeoE3gFtovAqxirZ7hQMamkqZ8TbihtWGvjrN3LEk2ubp+rxjQ3F9wezug2QLuv8RkAbPVT6BStqsKmrjUCu0T5q5GGq5SizuutDi7Fn+DkGLDabaiCU6H6Nnd8qEGu0qQ1oP4vXD4p3gg7AYfNdX6LnXVcb38MmgFbGgXNUO2PV2xHK7oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MrP/sb71w7FsTtptDQPu5syiA7OiYWzzUM1QutLuIdk=; b=exTPRjj4szVw55fBSSTMUyXVt8GLYL6gmlHFNPUAxcuQf5J89hQI7Cn6Bgvb1r0m/b0F0L2+lnfBT2FISDufhFzZNi2YU8MW/fY84/atBnHjjiDAWJIMYYCvXsD3h7UeF2CT5R2wdJt0tMuruzdgDc7qV9tmWI1L5kSxBGZmY4xvOii0k6ChG0F3q36c9jXt0O3/CEiQfHbv7zoi9QfTwfStcHLuhbIDFfir4w8V2x3XCScO5/dCqikcS+DW7vpL9uyFV8lG4Y53M89/WDfrpZmn4+wg3SRpumG+g/t0V9LhPnQavVvTqozFzflq8Vx2FqR5pqilGl+9SgkhHuF5UA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MrP/sb71w7FsTtptDQPu5syiA7OiYWzzUM1QutLuIdk=; b=nCSx9kOuK5QzpxWV5Q0k/x3V4gOSVxczifAfrwz47Xmj5CMF+tMLU7tniKBtH66yOhU3Zbct+O7x47Ifj7KV8qz1i4AFC8l+05OHis4gyVc2L3WcSD6yW5ZL6gWbG5RfwKwzt1Elznf5renyemW8/2ow2wPkMdBa/zffld5mZeY= Received: from DM5PR21CA0025.namprd21.prod.outlook.com (2603:10b6:3:ed::11) by BN8PR02MB5858.namprd02.prod.outlook.com (2603:10b6:408:bc::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 21:23:40 +0000 Received: from DM3NAM02FT023.eop-nam02.prod.protection.outlook.com (2603:10b6:3:ed:cafe::b6) by DM5PR21CA0025.outlook.office365.com (2603:10b6:3:ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.9 via Frontend Transport; Thu, 24 Feb 2022 21:23:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT023.mail.protection.outlook.com (10.13.5.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:23:40 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:23:39 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:23:39 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLaN-00095B-9q; Thu, 24 Feb 2022 13:23:39 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 01/19] vhost: move the backend feature bits to vhost_types.h Date: Fri, 25 Feb 2022 02:52:41 +0530 Message-ID: <20220224212314.1326-2-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 58cbde5b-8e7a-4754-b5ea-08d9f7dbed8c X-MS-TrafficTypeDiagnostic: BN8PR02MB5858:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yVWhzG+z/gxCel4nSSiuZs+eHnlPiSWv/IVjNy7Thq6IqDzglaA68VwenrhzHWYyfG6nWqfJQzZ2dKEtShr/k0BEr4uumKf0DODObEJuxzGw/DTpD90AjWUGx+IpY820SIsBMI/HyhzR613SeoietuAKTGfgsmG2ffmbbT556pboOqdLImlvvr7IlsoQRZkVlZGGskjP8EQTi72akWzh8JMXS8eoEV0G66jCUIYx1cE3uWw+/UbnM6fA45xS9LIDS1HY7BukexSntcDu+V6TEjKlIMnOxfrscSXWm3nXgUHQKg3AGM1+wcdkKOkAjn0mg6DHKrt2nnaEhOkEy3QXBBy4CW8BehD3YoaMhoL1Nh0lKuaiPjTafOzmxjMi6bv8VobsPdRQc1YU8SAb+P3tnnhDMgtL4XfIbjDOHKD0F4QZ6s0QGWoO4buEcn1bxp64wJtRpqpV4+73VbERFZjj4aIPCHxOUweBcZofIjG7JLc5KDKgDy0C2OFprDZE8bIRw5YlNSXXx3GRouCDV/g5Tnjg/SxSujFzluUxOT3DYeAmDgI0MQA/+H9tvgYg9RY3p5tg9BcGCe7vu0bOBhNM7KfIDHNF053LLazqAbxT+UpS7N8r9MD4+mPNIU25Xjczh1OPGVXseKA2Ckx5X8h4VvjzJXAOOYzpo/uDu6W8IKdz8eKKSHQmwdRwnfcBDSZD7hs4msLMGc30hUxk29dFwQ== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(36756003)(2616005)(26005)(186003)(82310400004)(70206006)(70586007)(356005)(7636003)(109986005)(1076003)(4326008)(8676002)(2906002)(336012)(426003)(54906003)(316002)(47076005)(83380400001)(9786002)(8936002)(7696005)(7416002)(36860700001)(44832011)(508600001)(6666004)(5660300002)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:23:40.4018 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 58cbde5b-8e7a-4754-b5ea-08d9f7dbed8c X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT023.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR02MB5858 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We should store feature bits in vhost_types.h as what has been done for e.g VHOST_F_LOG_ALL. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- include/uapi/linux/vhost.h | 5 ----- include/uapi/linux/vhost_types.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index c998860d7bbc..59c6c0fbaba1 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -89,11 +89,6 @@ /* Set or get vhost backend capability */ -/* Use message type V2 */ -#define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1 -/* IOTLB can accept batching hints */ -#define VHOST_BACKEND_F_IOTLB_BATCH 0x2 - #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64) #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64) diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_types.h index f7f6a3a28977..76ee7016c501 100644 --- a/include/uapi/linux/vhost_types.h +++ b/include/uapi/linux/vhost_types.h @@ -153,4 +153,9 @@ struct vhost_vdpa_iova_range { /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */ #define VHOST_NET_F_VIRTIO_NET_HDR 27 +/* Use message type V2 */ +#define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1 +/* IOTLB can accept batching hints */ +#define VHOST_BACKEND_F_IOTLB_BATCH 0x2 + #endif From patchwork Thu Feb 24 21:22:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759271 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF7A5C433F5 for ; Thu, 24 Feb 2022 21:24:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234710AbiBXVYh (ORCPT ); Thu, 24 Feb 2022 16:24:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234704AbiBXVYe (ORCPT ); Thu, 24 Feb 2022 16:24:34 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2053.outbound.protection.outlook.com [40.107.93.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F31428D39C; Thu, 24 Feb 2022 13:24:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=asjasaJnOD4hoBGXX4hDepP1e/8fY4LcREcSCDCiT4wwnaj8YbBLw4v3A2ymB8a0z//b1jehsUbbclWyaKUzQrkH7Pjq2Saxs/cKMGOxokekDLKLnbqUdGY5k93h1NK+jOUzxftSHRdww7B2XANOR9boWI3f7Lj+rrMeBYwjcbGOtzLq5mP34V8YddF8peomwOplrFH3EU9HjfMzBHTTD4su577lpN+QmZY7HqsQZT2UJImm9s+wxInjf/Kup2JQHc2s1sVUx0WdP4jLS0Gbo8pwwCAU9wVFv1huFGPqBGSrXgN+lOOVHmJ+hZX/6JPffj9eppFc7ohN6qvdgxKViA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fayfmbkixtZKWYN9V7C0LB9cq4o4jjIrmGTXP0klWjM=; b=hYe1Yskgmh+iccbNtUiPKpTpywgNZVMaD+N1OlX5Jon8Ck1WqDAX8vlV7MuRlXHvhTdqa6vft9h6/K+24/sLB0RDo7b1NBjl79ZRYuLVlHPOhmajGWyEv8vyARnsTZLbwOOXYVhp+7KII3VeRfwRzvnNUfK3dknvYodcIvSLedbYcYYQaGf1lW1O1G9xApzMwi6L5yqzh4aEaj1a/rtrrtofewB5obTYwg+aco6LGfumFVVaGhaPCjdgWVQTNXVrv1fr5AWNl7ILkV8DXezGrDd9188SeWo999TXzK+yqQOW7zGF+t0jB9MdA2qcmqFpILJUbLaR2amB4LTAhIG/Ow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fayfmbkixtZKWYN9V7C0LB9cq4o4jjIrmGTXP0klWjM=; b=QV3Obu1hDmmIY6yxReVhggH4bd3grzpryDvwupHLDd5foNIHzyKJaar6JS2In/tnnu6AyLdR4yB4UXL37uZ0UN9vBgMEQGGAmDqnqYplNr2ofUbV9udTQ6Voc1yhZPhikbPQbIAHCqaGoli9cuIhRWOcpr70lfNDsaVFYrUNq3s= Received: from DM5PR19CA0008.namprd19.prod.outlook.com (2603:10b6:3:151::18) by CH2PR02MB6325.namprd02.prod.outlook.com (2603:10b6:610:1::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 21:23:59 +0000 Received: from DM3NAM02FT017.eop-nam02.prod.protection.outlook.com (2603:10b6:3:151:cafe::98) by DM5PR19CA0008.outlook.office365.com (2603:10b6:3:151::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19 via Frontend Transport; Thu, 24 Feb 2022 21:23:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT017.mail.protection.outlook.com (10.13.5.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:23:59 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:23:58 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:23:58 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLag-00095B-1T; Thu, 24 Feb 2022 13:23:58 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 02/19] virtio-vdpa: don't set callback if virtio doesn't need it Date: Fri, 25 Feb 2022 02:52:42 +0530 Message-ID: <20220224212314.1326-3-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5bd0fbb9-d48f-44df-2373-08d9f7dbf8c1 X-MS-TrafficTypeDiagnostic: CH2PR02MB6325:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H3udrbFCGmIMv9ULcvARZdT/taccJu3kV8Wz+sUfpindovajGLlZQRcpaFymCNpB0ODSWHIgrrhmU5FLoYaiCh9wMM6wxz8Ggqlc5xA9hT8GzvJ/Q/RCsNE1frHTt0asGj8MnFxLEfYnnMdf3jYhITbQBBPfOeYF5XwhAUt10wy6i/M54WZr2O+nLqTTOTEKvpal46r6VgfJoA7chqiVrYPLHQFpuPChjGItf1b4dKaQgy3CSu0tl6YKXOnCXPXY0q865Mpr0n6ihhJKVBRHdJzVt4stx2OQRwv/vMJ63siCGol1xMj1x8L69S1Mu+JK7G02OBJhZknUV0T6UzyTCfvoDRW7Lj1xYTMhMSV+DJUUBYFvRJGVPHAcavxsLGMxGaIBvuJrXoD2nzk6pKBu3JoaRrG2fbLjUsgC/VQNgRT2LmxU/BNCdl2czWibY0UVmI9cAYM7emBIcONMgVQL/h7e9lM5kr3467hE2S/DY+JOxBFa+Z/LvZGEQ2EILrWZy79LLmcftih7+igz7omMbW/pM8QNUPm689mtaJXeMTcmGXEDDdbD3vXJw83X5roL31Pz8FUj+woLW+hUb+py+B/X53nMupx6lpu7el4zmEP8HEgGffSBNNG4ZGDX6c9BPip9nMh+OE8pHcQVmv1F78UcfRxv63D685Mt1U2b94BP3FeS7KcTkaEU+tKodw2LZoIwgW6Pn61epjxJKhObW1mDAXYGO6tClB2b/fZdFOw= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(82310400004)(47076005)(7416002)(8936002)(83380400001)(508600001)(2906002)(6666004)(5660300002)(1076003)(9786002)(8676002)(316002)(36860700001)(4326008)(356005)(54906003)(109986005)(2616005)(7636003)(7696005)(44832011)(70586007)(26005)(70206006)(426003)(40460700003)(36756003)(336012)(4744005)(186003)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:23:59.2004 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5bd0fbb9-d48f-44df-2373-08d9f7dbf8c1 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT017.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR02MB6325 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org There's no need for setting callbacks for the driver that doesn't care about that. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/virtio/virtio_vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c index 7767a7f0119b..bc74ba5fa717 100644 --- a/drivers/virtio/virtio_vdpa.c +++ b/drivers/virtio/virtio_vdpa.c @@ -184,7 +184,7 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, } /* Setup virtqueue callback */ - cb.callback = virtio_vdpa_virtqueue_cb; + cb.callback = callback ? virtio_vdpa_virtqueue_cb : NULL; cb.private = info; ops->set_vq_cb(vdpa, index, &cb); ops->set_vq_num(vdpa, index, virtqueue_get_vring_size(vq)); From patchwork Thu Feb 24 21:22:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EB22C433F5 for ; Thu, 24 Feb 2022 21:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234705AbiBXVYy (ORCPT ); Thu, 24 Feb 2022 16:24:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230511AbiBXVYx (ORCPT ); Thu, 24 Feb 2022 16:24:53 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2082.outbound.protection.outlook.com [40.107.243.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9260A278C9B; Thu, 24 Feb 2022 13:24:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nx33ckspCBcnhOsLNC1zrnz3WKqMz8cj0O+nLLNqSgx8p/ozYCW4ikQxz5gUL2ZP8rcMNjYiuBvgapy4bkatcWmSGq5eHym4FDWBPXKYEvegQvjJG1zs9SOqZRIbYd1y3sF8PAtg45ShDBsl05DnieMrOTrkrfEPst+Yd2dpCcfSOOquyPpnYu2br8hqXrzTGz+iWl9ibIbkNI/dyiYLnBzdbLsz6VPmWbhripK+MFOFG3A8B7wx2PomgN7lfFMpbCDB5bHFf6h9J2m4wCuo5m01i7WKyBXB8RXnPWInNt+ncaDzzpLlPCur1EPzEZJykrtZWzZGp+VFAgnJSgGfkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KwvBTSeixOOLHffhoPvMUDqtDdFldJ6wjakUEXHknv8=; b=aG8k9a42adDSfqWXQSskkfw1xAmoOtdwVxqkbEnLiTjBKPa5lJUTiAqvqTyXrfG/ChQPGpEyLA3Jt4sLLHQuPXa7Lncj5k/REdtfvIAUGff2QQPcigWO9WHyMePoAjZy2msUSvV9MsRaxOxPpkA/1177yVAOZPoL81dFnWO3wU+K+bwgZKdgJ7Q05xyiikerqH0iqTGqDExsT/wr4EaOBp6hPYac2JAwfFW89J9prYnndNe4BMaDZ2mTxFQkgzIj7MNerjQiSF7Y4Oiqh8KHHpa9s0vg1SDK3cHyRbebmxPevsLrmFTYgU1sKT1VqL22FNwKrMvBKknzg6na0T6EaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KwvBTSeixOOLHffhoPvMUDqtDdFldJ6wjakUEXHknv8=; b=m7YHi8YO2NlSdRHZmoud+81nXpMfo1mX7aex4ACEYCMXb/gH4TgteQi3Jfv4/cjscpD7tbwvxs5IYfifT/xN4+0GLPmzaTRLIYhZsZ2CFfc8V+JF0Xwfj8M9fqX4rFwRFuyB5HxQodo0Xave1eq7a4gQ3EKU5Va7XOoB3ig++dU= Received: from DM6PR13CA0005.namprd13.prod.outlook.com (2603:10b6:5:bc::18) by BN7PR02MB3972.namprd02.prod.outlook.com (2603:10b6:406:ef::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Thu, 24 Feb 2022 21:24:19 +0000 Received: from DM3NAM02FT046.eop-nam02.prod.protection.outlook.com (2603:10b6:5:bc:cafe::2d) by DM6PR13CA0005.outlook.office365.com (2603:10b6:5:bc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.9 via Frontend Transport; Thu, 24 Feb 2022 21:24:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT046.mail.protection.outlook.com (10.13.4.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:24:19 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:24:17 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:24:17 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLay-00095B-PW; Thu, 24 Feb 2022 13:24:17 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 03/19] vhost-vdpa: passing iotlb to IOMMU mapping helpers Date: Fri, 25 Feb 2022 02:52:43 +0530 Message-ID: <20220224212314.1326-4-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ed647084-f79e-4f6e-ed98-08d9f7dc04b5 X-MS-TrafficTypeDiagnostic: BN7PR02MB3972:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TG1lqB7tLFRkTmVxSIwvriND7BN5d2xQS7KwMDk0Iv7DCc1Ks7TQetEKGxXD1hetoO4at5ijzaIgfzIquPSgHSz9UF18vCilVmFF/reqvvQzg6AdYgzAVYag2uaQQxSRT5Nwa2TtygNx4+LP8hRyIfapPonJ7MqSS2D4fqJ3eGt5iu2e803F1Bq6Q9UvXi8P9LhNBzeA8aRig/s7s+q/ekLEHNGeEJJZr+EKJYhiaq21AlT4VHr1kIl3HP9x2DtAde7hGVqZ2SuLfpVdI7yN4c0bQnC06r5UFn0de3J6Z+t289VW8a5fbgzVqO0+qDHYIJfFfbB7Pdjk9bc55yuTMRfWDG6a2HsyRG3DvHq/bkeLQOEIoxtPdQpF41dBB3WYW5f88vZfP5dDP0ObPbjc4q/j3L98hlwzfetcfyMPdJmjrVVdmHHUTAKLDoFwdsT1/KwNVRlMS93kNH63ClIB+meCdwUzVCRziSrOHUQvFntgtggpzkzzzgtMpdBTPsDL9kV+CeDNAgjbpt0ELPqXZDv5dbBRPrEUZYi2h6h52O9OqRkrrK318UkJq/PwZPxr/O8JzAQPzEE/mMmHQuz7AoIiHsGIdhvJwGKZ9JJw7Fqtnad1l1mlDOTInlDIszy1xeV28GFSQojDdLluv7HxMh9FgiZpMJ9JhZqvWkraqz4+I0iLjs3LaFgmbaGmcIU1KGvuZKMSHhakCIyzlrFspg== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(44832011)(9786002)(356005)(316002)(2906002)(7636003)(36860700001)(83380400001)(109986005)(7416002)(336012)(82310400004)(426003)(54906003)(47076005)(5660300002)(2616005)(6666004)(8936002)(4326008)(1076003)(7696005)(70586007)(36756003)(70206006)(186003)(26005)(508600001)(8676002)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:24:19.2595 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed647084-f79e-4f6e-ed98-08d9f7dc04b5 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT046.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR02MB3972 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org To prepare for the ASID support for vhost-vdpa, try to pass IOTLB object to dma helpers. No functional changes, it's just a preparation for support multiple IOTLBs. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vhost/vdpa.c | 67 ++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 851539807bc9..146911082514 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -503,10 +503,11 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, return r; } -static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v, u64 start, u64 last) +static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, + u64 start, u64 last) { struct vhost_dev *dev = &v->vdev; - struct vhost_iotlb *iotlb = dev->iotlb; struct vhost_iotlb_map *map; struct page *page; unsigned long pfn, pinned; @@ -525,10 +526,10 @@ static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v, u64 start, u64 last) } } -static void vhost_vdpa_va_unmap(struct vhost_vdpa *v, u64 start, u64 last) +static void vhost_vdpa_va_unmap(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, + u64 start, u64 last) { - struct vhost_dev *dev = &v->vdev; - struct vhost_iotlb *iotlb = dev->iotlb; struct vhost_iotlb_map *map; struct vdpa_map_file *map_file; @@ -540,21 +541,24 @@ static void vhost_vdpa_va_unmap(struct vhost_vdpa *v, u64 start, u64 last) } } -static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v, u64 start, u64 last) +static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, + u64 start, u64 last) { struct vdpa_device *vdpa = v->vdpa; if (vdpa->use_va) - return vhost_vdpa_va_unmap(v, start, last); + return vhost_vdpa_va_unmap(v, iotlb, start, last); - return vhost_vdpa_pa_unmap(v, start, last); + return vhost_vdpa_pa_unmap(v, iotlb, start, last); } static void vhost_vdpa_iotlb_free(struct vhost_vdpa *v) { struct vhost_dev *dev = &v->vdev; + struct vhost_iotlb *iotlb = dev->iotlb; - vhost_vdpa_iotlb_unmap(v, 0ULL, 0ULL - 1); + vhost_vdpa_iotlb_unmap(v, iotlb, 0ULL, 0ULL - 1); kfree(dev->iotlb); dev->iotlb = NULL; } @@ -581,15 +585,15 @@ static int perm_to_iommu_flags(u32 perm) return flags | IOMMU_CACHE; } -static int vhost_vdpa_map(struct vhost_vdpa *v, u64 iova, - u64 size, u64 pa, u32 perm, void *opaque) +static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, + u64 iova, u64 size, u64 pa, u32 perm, void *opaque) { struct vhost_dev *dev = &v->vdev; struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; int r = 0; - r = vhost_iotlb_add_range_ctx(dev->iotlb, iova, iova + size - 1, + r = vhost_iotlb_add_range_ctx(iotlb, iova, iova + size - 1, pa, perm, opaque); if (r) return r; @@ -598,13 +602,13 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, u64 iova, r = ops->dma_map(vdpa, iova, size, pa, perm, opaque); } else if (ops->set_map) { if (!v->in_batch) - r = ops->set_map(vdpa, dev->iotlb); + r = ops->set_map(vdpa, iotlb); } else { r = iommu_map(v->domain, iova, pa, size, perm_to_iommu_flags(perm)); } if (r) { - vhost_iotlb_del_range(dev->iotlb, iova, iova + size - 1); + vhost_iotlb_del_range(iotlb, iova, iova + size - 1); return r; } @@ -614,25 +618,27 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, u64 iova, return 0; } -static void vhost_vdpa_unmap(struct vhost_vdpa *v, u64 iova, u64 size) +static void vhost_vdpa_unmap(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, + u64 iova, u64 size) { - struct vhost_dev *dev = &v->vdev; struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; - vhost_vdpa_iotlb_unmap(v, iova, iova + size - 1); + vhost_vdpa_iotlb_unmap(v, iotlb, iova, iova + size - 1); if (ops->dma_map) { ops->dma_unmap(vdpa, iova, size); } else if (ops->set_map) { if (!v->in_batch) - ops->set_map(vdpa, dev->iotlb); + ops->set_map(vdpa, iotlb); } else { iommu_unmap(v->domain, iova, size); } } static int vhost_vdpa_va_map(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, u64 iova, u64 size, u64 uaddr, u32 perm) { struct vhost_dev *dev = &v->vdev; @@ -662,7 +668,7 @@ static int vhost_vdpa_va_map(struct vhost_vdpa *v, offset = (vma->vm_pgoff << PAGE_SHIFT) + uaddr - vma->vm_start; map_file->offset = offset; map_file->file = get_file(vma->vm_file); - ret = vhost_vdpa_map(v, map_iova, map_size, uaddr, + ret = vhost_vdpa_map(v, iotlb, map_iova, map_size, uaddr, perm, map_file); if (ret) { fput(map_file->file); @@ -675,7 +681,7 @@ static int vhost_vdpa_va_map(struct vhost_vdpa *v, map_iova += map_size; } if (ret) - vhost_vdpa_unmap(v, iova, map_iova - iova); + vhost_vdpa_unmap(v, iotlb, iova, map_iova - iova); mmap_read_unlock(dev->mm); @@ -683,6 +689,7 @@ static int vhost_vdpa_va_map(struct vhost_vdpa *v, } static int vhost_vdpa_pa_map(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, u64 iova, u64 size, u64 uaddr, u32 perm) { struct vhost_dev *dev = &v->vdev; @@ -746,7 +753,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, if (last_pfn && (this_pfn != last_pfn + 1)) { /* Pin a contiguous chunk of memory */ csize = PFN_PHYS(last_pfn - map_pfn + 1); - ret = vhost_vdpa_map(v, iova, csize, + ret = vhost_vdpa_map(v, iotlb, iova, csize, PFN_PHYS(map_pfn), perm, NULL); if (ret) { @@ -776,7 +783,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, } /* Pin the rest chunk */ - ret = vhost_vdpa_map(v, iova, PFN_PHYS(last_pfn - map_pfn + 1), + ret = vhost_vdpa_map(v, iotlb, iova, PFN_PHYS(last_pfn - map_pfn + 1), PFN_PHYS(map_pfn), perm, NULL); out: if (ret) { @@ -796,7 +803,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, for (pfn = map_pfn; pfn <= last_pfn; pfn++) unpin_user_page(pfn_to_page(pfn)); } - vhost_vdpa_unmap(v, start, size); + vhost_vdpa_unmap(v, iotlb, start, size); } unlock: mmap_read_unlock(dev->mm); @@ -807,11 +814,10 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, } static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, struct vhost_iotlb_msg *msg) { - struct vhost_dev *dev = &v->vdev; struct vdpa_device *vdpa = v->vdpa; - struct vhost_iotlb *iotlb = dev->iotlb; if (msg->iova < v->range.first || !msg->size || msg->iova > U64_MAX - msg->size + 1 || @@ -823,10 +829,10 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v, return -EEXIST; if (vdpa->use_va) - return vhost_vdpa_va_map(v, msg->iova, msg->size, + return vhost_vdpa_va_map(v, iotlb, msg->iova, msg->size, msg->uaddr, msg->perm); - return vhost_vdpa_pa_map(v, msg->iova, msg->size, msg->uaddr, + return vhost_vdpa_pa_map(v, iotlb, msg->iova, msg->size, msg->uaddr, msg->perm); } @@ -836,6 +842,7 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, struct vhost_vdpa *v = container_of(dev, struct vhost_vdpa, vdev); struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; + struct vhost_iotlb *iotlb = dev->iotlb; int r = 0; mutex_lock(&dev->mutex); @@ -846,17 +853,17 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, switch (msg->type) { case VHOST_IOTLB_UPDATE: - r = vhost_vdpa_process_iotlb_update(v, msg); + r = vhost_vdpa_process_iotlb_update(v, iotlb, msg); break; case VHOST_IOTLB_INVALIDATE: - vhost_vdpa_unmap(v, msg->iova, msg->size); + vhost_vdpa_unmap(v, iotlb, msg->iova, msg->size); break; case VHOST_IOTLB_BATCH_BEGIN: v->in_batch = true; break; case VHOST_IOTLB_BATCH_END: if (v->in_batch && ops->set_map) - ops->set_map(vdpa, dev->iotlb); + ops->set_map(vdpa, iotlb); v->in_batch = false; break; default: From patchwork Thu Feb 24 21:22:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB1F9C433FE for ; Thu, 24 Feb 2022 21:25:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234759AbiBXVZa (ORCPT ); Thu, 24 Feb 2022 16:25:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231127AbiBXVZV (ORCPT ); Thu, 24 Feb 2022 16:25:21 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2053.outbound.protection.outlook.com [40.107.236.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4CE5294FC1; Thu, 24 Feb 2022 13:24:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jngMXUD11HsH5AGliGrOs9eyT4XJ+vi30thELSVVW3pLheIjikHf16uvoVq9dSuyxlQ3l09avY5XpFGOFrVkY6VEYusmK3Yd+yA7lNrfgRiJVNGbmoFDLLqgtDFixIcNIWI5FAyTy+lyRlnoJf8bK7W/L7SZVyW1u/Sd5C7ZDzgMOKQ5ja1MiQ1eRtYFfKqJpS+fnyVe09o/ZSYWnxtAdwWo0kUzFNy2K//K+ZdqQlQf4OhnovfaTRwjEnsIajXu49hjwpH8Xu+lA9ihGMEpxdJbPt8yfc/34sHB9lbGgTH/Ha2Qe9DvQfr+lXHuBidNHkbbtk4QtPMJYkFKmT5Fqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=buj/AiOUmN4Vxv0SoCdhA/v/c7DKN365NkZJYAjNDGE=; b=Pokhum5PdX12btM1Hopccady8GS5pxahHLv8L8faDNCQfQ+kFcQi8vZrdhvXdjGNjJNYGkao0I3Ty9hAWauqEriKUKoJNGYDToGWUALTpSAJ/YiiRUUxhfRpYteCfpQ9kguXutZY3tU2quLaqAZvmDvwNit8R/ayrruAoyG3Jgoe0sIu/LlF8t/GrPorqaCxyX4P6bTLOnB0+d8VRsiblf9YJ5yTJeKon10hdxPWAc4CfpP6obbmMpUL+bxc6IMvdPmnVBwQ01gE0cTNgYwYRzoky3WiwaaD57N9ERELwkQrMOJyNGyqrZR9dF/7lCIJCCPhQvnerXqXcqUz/CS4kA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=buj/AiOUmN4Vxv0SoCdhA/v/c7DKN365NkZJYAjNDGE=; b=IgfD3w8bX5pwrK+2N9Kt++CrO3aT8QNPn2m+ab77tqPtzQCCY9JdAdq7uJZfZDh4DVtIo9pTqKtC0A4YNkuzf2wyTbWDRzXViGrOEHiKDcTza8pAriiJkaEfLT0ppN3Jw+en4Stmzm7LbsxcGdfO7Lj1pZsT5QAR3747PMHAGKg= Received: from DM6PR08CA0066.namprd08.prod.outlook.com (2603:10b6:5:1e0::40) by SN4PR0201MB3519.namprd02.prod.outlook.com (2603:10b6:803:49::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 21:24:38 +0000 Received: from DM3NAM02FT035.eop-nam02.prod.protection.outlook.com (2603:10b6:5:1e0:cafe::1d) by DM6PR08CA0066.outlook.office365.com (2603:10b6:5:1e0::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:24:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT035.mail.protection.outlook.com (10.13.4.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:24:38 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:24:37 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:24:37 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLbI-00095B-Nh; Thu, 24 Feb 2022 13:24:37 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 04/19] vhost-vdpa: switch to use vhost-vdpa specific IOTLB Date: Fri, 25 Feb 2022 02:52:44 +0530 Message-ID: <20220224212314.1326-5-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f8baf735-6864-41ec-a933-08d9f7dc1024 X-MS-TrafficTypeDiagnostic: SN4PR0201MB3519:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fEGfecEY5M57St+uMzVdqulLi+KUWU2k6dz3vhmHIdCL81zULw9A/Kc5S3fNhOvN17jJ2uLk0gY5dQUYYUISr+9qDhs8irlo9RuNPII7UrYA0sxUh2SO+mWabArtrvXXVhWM9Lyuppx+spWICGnOc3RP6sRaN0hBEhk0WynN3AfRc8rB1b1czQRWfdVYY5mONoRArQMm9rW7naBvdhWoOduBmNA1LB1jb6F/fAawRGI8Q9sLZ4yKQEohuwiY+dfQXPu+N/Kiy10+GvUyjp40pgz9BMj27OaayhD/rRNdbJa97LpCfkTJpQtS2JKQmWKpmf/c8b5IMORoGR1NreLYP15LCGofSMX/biFg6NDNd/fdcRgR8Gwh3rE/DTaoBZZLeI6Xkt9wBMGxS9CJgVKUI+1P2FvBcO4PQBVKPAdkoOyOCxPPbDPH5RE/KnCXiy+KvJNXrVLf7zdW5zu9TdWltcKhsWOQzYINWQNcNTN3nTO72TDJ9bActC4DjRuWB3JU7Zlg8JKwqgEY8kZuqcbAp21pFYwnG5M99KQhYW0soJx3HPETlvRrqLobSlEso97gbmg+JWJIK1ikjMZV+Y5Svz6+RftO1NiI3lOOk2OHp2KCGAIBAzqoKGJrROMVBpPKevJKApuLAkrFTqxLCLsHiSXYGllWD6s8wHaHupsAl8NkkN0l3BBjIV2QZ3x9dnhtTkv/C/mWtq3X139i/25zFeoDVLDtesOAV+TTJUskPis= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(36860700001)(2906002)(47076005)(9786002)(82310400004)(70206006)(8936002)(7636003)(356005)(8676002)(4326008)(40460700003)(70586007)(508600001)(316002)(109986005)(44832011)(54906003)(6666004)(83380400001)(5660300002)(426003)(26005)(2616005)(7696005)(186003)(1076003)(7416002)(336012)(36756003)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:24:38.4402 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f8baf735-6864-41ec-a933-08d9f7dc1024 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT035.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR0201MB3519 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org To ease the implementation of per group ASID support for vDPA device. This patch switches to use a vhost-vdpa specific IOTLB to avoid the unnecessary refactoring of the vhost core. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vhost/vdpa.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 146911082514..655ff7029401 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -39,6 +39,7 @@ struct vhost_vdpa { struct vhost_virtqueue *vqs; struct completion completion; struct vdpa_device *vdpa; + struct vhost_iotlb *iotlb; struct device dev; struct cdev cdev; atomic_t opened; @@ -555,12 +556,11 @@ static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v, static void vhost_vdpa_iotlb_free(struct vhost_vdpa *v) { - struct vhost_dev *dev = &v->vdev; - struct vhost_iotlb *iotlb = dev->iotlb; + struct vhost_iotlb *iotlb = v->iotlb; vhost_vdpa_iotlb_unmap(v, iotlb, 0ULL, 0ULL - 1); - kfree(dev->iotlb); - dev->iotlb = NULL; + kfree(v->iotlb); + v->iotlb = NULL; } static int perm_to_iommu_flags(u32 perm) @@ -842,7 +842,7 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, struct vhost_vdpa *v = container_of(dev, struct vhost_vdpa, vdev); struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; - struct vhost_iotlb *iotlb = dev->iotlb; + struct vhost_iotlb *iotlb = v->iotlb; int r = 0; mutex_lock(&dev->mutex); @@ -982,15 +982,15 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) vhost_dev_init(dev, vqs, nvqs, 0, 0, 0, false, vhost_vdpa_process_iotlb_msg); - dev->iotlb = vhost_iotlb_alloc(0, 0); - if (!dev->iotlb) { + v->iotlb = vhost_iotlb_alloc(0, 0); + if (!v->iotlb) { r = -ENOMEM; goto err_init_iotlb; } r = vhost_vdpa_alloc_domain(v); if (r) - goto err_init_iotlb; + goto err_alloc_domain; vhost_vdpa_set_iova_range(v); @@ -998,6 +998,8 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) return 0; +err_alloc_domain: + vhost_vdpa_iotlb_free(v); err_init_iotlb: vhost_dev_cleanup(&v->vdev); kfree(vqs); From patchwork Thu Feb 24 21:22:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759274 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E6FAC433FE for ; Thu, 24 Feb 2022 21:25:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234704AbiBXVZk (ORCPT ); Thu, 24 Feb 2022 16:25:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234750AbiBXVZb (ORCPT ); Thu, 24 Feb 2022 16:25:31 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2051.outbound.protection.outlook.com [40.107.243.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94F7E293A23; Thu, 24 Feb 2022 13:25:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EVt0uVkY4R1bCG4WrmAlVWEaOjY7a9Jo2vWPJ/fFNi/6seHojdckVetnHigQ/b5Si464uX/9sYJg06Rs7s4mrv7FfhDkbTdjud/i7ovaBw1bB19SYTih2XRWekWswJYvzoCgT5Yj/bllBBQYOTQVhYQSgAL3WPktpU7G/6TQlbVhIk4jksOQrk12nyZWkcLI2HCo8pG02wCvLilozitTbhGVxxSWiB41J7FrdAlZ+afygKDyOdKfHXSSakKGRY3lV4MNSQvcgFyqBaImzE6JP1fL5knmKWajLxzLvngKzPWbaueU+sMDM+MVJQZE4uGXUAYeRltLjYF2oV6JHb4sHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jyV3IZwgLLB1SYiMihS28vGApAg0sxiaAEbsRr/1fhQ=; b=Gxha8kpxIkxzySXHTjWQTZqFRPK8hvZczsIAhppucfCOUp7d/KD9qX3KC5lDj4jf7e0HIA/h72JZJriDkmDkEir/ncXINJoT8vil+btf0yJl6y62UWTQuByCKGVl1rQ1YUVPOSiTJl1NloQPrW2BNHyHUCTDliHxAnuP4/x7fJiVCtMkZ/K5x/HBsoiwyXfURC/JyyjCQpHKBweK8Z2k2TDgxfKtUAgltJANZePehoLctcMbEKi686CzFK38m2NOnh6aLuLM+lQu47PCtvSuV/UU2q4DotKnDkKpfOmxfbTWddNfOwZGnW4P+gpbQByV6QKQhSDRuRAI1w+RYfOwGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jyV3IZwgLLB1SYiMihS28vGApAg0sxiaAEbsRr/1fhQ=; b=cvl1efRoqRRizCwFzeUi0LI911gowNXvrrLcqT5hb7w/mRtvXaTCIlsArhob3vwLLbByHQgbvzh+H7lOqT3uSUHYioQew7rRvwKXxQxy7xCTFYVgJvcIXsxZIOaYCODK4/zI5rXVIAu2LijOcB3p1GOt9l6ZaM+f2XxZLivABOk= Received: from DM5PR10CA0016.namprd10.prod.outlook.com (2603:10b6:4:2::26) by DM8PR02MB8278.namprd02.prod.outlook.com (2603:10b6:8:9::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24; Thu, 24 Feb 2022 21:24:58 +0000 Received: from DM3NAM02FT008.eop-nam02.prod.protection.outlook.com (2603:10b6:4:2:cafe::5b) by DM5PR10CA0016.outlook.office365.com (2603:10b6:4:2::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:24:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT008.mail.protection.outlook.com (10.13.5.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:24:58 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:24:56 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:24:56 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLbb-00095B-Gx; Thu, 24 Feb 2022 13:24:56 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 05/19] vdpa: introduce virtqueue groups Date: Fri, 25 Feb 2022 02:52:45 +0530 Message-ID: <20220224212314.1326-6-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 56a8f47a-ee28-4fad-8cc1-08d9f7dc1bda X-MS-TrafficTypeDiagnostic: DM8PR02MB8278:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /dDOc+g/MA3LTLx5PgqfB1MmDtBmnA4O4Ttppx5AfoBXc12NgMIxx3C32JnLpdRtxHcXKE7yDLfrLnleThY4NoqTBB/Mxf5XJvqRtdV/oei8hmsh99AYN16l2ouH0qeEyTIKxrVl1V95hNR/UuiuROSRHB3933jzcw8FjUfnXgDCofqlNtbEwcxKLAAdo5vl/AJoZqzCC5gL9ECY1PAwfHUPrEI+NKaLSbBJxrFOxVughtfzcNj1FTW+ZI4yUpWKwZ9OFb1XTy4l6Kpdnri7bIQQ4gAdV3kwFNkj9lsnpo56HviwUZL+omC6/N8z78ao9hFZvqIraES9M5NIi9lwczQ2DSNgZopjFcCImZN6gm+utavfPtDgRfpUAlkDbrv1DcNygu7tvMF2zamd/n958q4PkIbKQxbbVH4gIL5xbF0wLi+4VUT3tCJYPuf1A44RFkdRIsGQqiwfJiU61O7tFpHCra03a5FgM8yv86CCxO91KN9wAK05TErTiwJi9JIovmwv7qTd3AGsBZCTOuCQHG3I6RdluLJTevRPAP8aAPT95nyVTKRiTQytMU8ZNPv/5XZY//+LTe6Eh81k6PalJb8zXbTTrp3eE1NSscPcURom1b4yOnvAlUq8lSv2nLtDejHAWak6eyx72MibaKkP+75oOlOIWiAOAi0ytII1xJEOnYyO2F8miRUlqN3qjH62vrR2c2A9MJtadWgSfxrGwUddtTRFEQG9yHdizDQHPW4= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(9786002)(36860700001)(316002)(40460700003)(7696005)(1076003)(2906002)(83380400001)(54906003)(7416002)(508600001)(82310400004)(5660300002)(6666004)(186003)(70206006)(70586007)(44832011)(36756003)(109986005)(47076005)(7636003)(26005)(356005)(8936002)(4326008)(8676002)(336012)(2616005)(426003)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:24:58.0871 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 56a8f47a-ee28-4fad-8cc1-08d9f7dc1bda X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT008.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR02MB8278 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch introduces virtqueue groups to vDPA device. The virtqueue group is the minimal set of virtqueues that must share an address space. And the address space identifier could only be attached to a specific virtqueue group. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vdpa/ifcvf/ifcvf_main.c | 8 +++++++- drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 +++++++- drivers/vdpa/vdpa.c | 3 +++ drivers/vdpa/vdpa_sim/vdpa_sim.c | 9 ++++++++- drivers/vdpa/vdpa_sim/vdpa_sim.h | 1 + include/linux/vdpa.h | 16 ++++++++++++---- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index d1a6b5ab543c..c815a2e62440 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -378,6 +378,11 @@ static size_t ifcvf_vdpa_get_config_size(struct vdpa_device *vdpa_dev) return vf->config_size; } +static u32 ifcvf_vdpa_get_vq_group(struct vdpa_device *vdpa, u16 idx) +{ + return 0; +} + static void ifcvf_vdpa_get_config(struct vdpa_device *vdpa_dev, unsigned int offset, void *buf, unsigned int len) @@ -453,6 +458,7 @@ static const struct vdpa_config_ops ifc_vdpa_ops = { .get_device_id = ifcvf_vdpa_get_device_id, .get_vendor_id = ifcvf_vdpa_get_vendor_id, .get_vq_align = ifcvf_vdpa_get_vq_align, + .get_vq_group = ifcvf_vdpa_get_vq_group, .get_config_size = ifcvf_vdpa_get_config_size, .get_config = ifcvf_vdpa_get_config, .set_config = ifcvf_vdpa_set_config, @@ -507,7 +513,7 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, pdev = ifcvf_mgmt_dev->pdev; dev = &pdev->dev; adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa, - dev, &ifc_vdpa_ops, name, false); + dev, &ifc_vdpa_ops, 1, name, false); if (IS_ERR(adapter)) { IFCVF_ERR(pdev, "Failed to allocate vDPA structure"); return PTR_ERR(adapter); diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index b53603d94082..fcfc28460b72 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1847,6 +1847,11 @@ static u32 mlx5_vdpa_get_vq_align(struct vdpa_device *vdev) return PAGE_SIZE; } +static u32 mlx5_vdpa_get_vq_group(struct vdpa_device *vdpa, u16 idx) +{ + return 0; +} + enum { MLX5_VIRTIO_NET_F_GUEST_CSUM = 1 << 9, MLX5_VIRTIO_NET_F_CSUM = 1 << 10, MLX5_VIRTIO_NET_F_HOST_TSO6 = 1 << 11, @@ -2363,6 +2368,7 @@ static const struct vdpa_config_ops mlx5_vdpa_ops = { .get_vq_notification = mlx5_get_vq_notification, .get_vq_irq = mlx5_get_vq_irq, .get_vq_align = mlx5_vdpa_get_vq_align, + .get_vq_group = mlx5_vdpa_get_vq_group, .get_device_features = mlx5_vdpa_get_device_features, .set_driver_features = mlx5_vdpa_set_driver_features, .get_driver_features = mlx5_vdpa_get_driver_features, @@ -2575,7 +2581,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, } ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops, - name, false); + 1, name, false); if (IS_ERR(ndev)) return PTR_ERR(ndev); diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 9846c9de4bfa..a07bf0130559 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -159,6 +159,7 @@ static void vdpa_release_dev(struct device *d) * initialized but before registered. * @parent: the parent device * @config: the bus operations that is supported by this device + * @ngroups: number of groups supported by this device * @size: size of the parent structure that contains private data * @name: name of the vdpa device; optional. * @use_va: indicate whether virtual address must be used by this device @@ -171,6 +172,7 @@ static void vdpa_release_dev(struct device *d) */ struct vdpa_device *__vdpa_alloc_device(struct device *parent, const struct vdpa_config_ops *config, + unsigned int ngroups, size_t size, const char *name, bool use_va) { @@ -203,6 +205,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, vdev->config = config; vdev->features_valid = false; vdev->use_va = use_va; + vdev->ngroups = ngroups; if (name) err = dev_set_name(&vdev->dev, "%s", name); diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index ddbe142af09a..c98cb1f869fa 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -250,7 +250,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) else ops = &vdpasim_config_ops; - vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, + vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, 1, dev_attr->name, false); if (IS_ERR(vdpasim)) { ret = PTR_ERR(vdpasim); @@ -399,6 +399,11 @@ static u32 vdpasim_get_vq_align(struct vdpa_device *vdpa) return VDPASIM_QUEUE_ALIGN; } +static u32 vdpasim_get_vq_group(struct vdpa_device *vdpa, u16 idx) +{ + return 0; +} + static u64 vdpasim_get_device_features(struct vdpa_device *vdpa) { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); @@ -620,6 +625,7 @@ static const struct vdpa_config_ops vdpasim_config_ops = { .set_vq_state = vdpasim_set_vq_state, .get_vq_state = vdpasim_get_vq_state, .get_vq_align = vdpasim_get_vq_align, + .get_vq_group = vdpasim_get_vq_group, .get_device_features = vdpasim_get_device_features, .set_driver_features = vdpasim_set_driver_features, .get_driver_features = vdpasim_get_driver_features, @@ -650,6 +656,7 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = { .set_vq_state = vdpasim_set_vq_state, .get_vq_state = vdpasim_get_vq_state, .get_vq_align = vdpasim_get_vq_align, + .get_vq_group = vdpasim_get_vq_group, .get_device_features = vdpasim_get_device_features, .set_driver_features = vdpasim_set_driver_features, .get_driver_features = vdpasim_get_driver_features, diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h index cd58e888bcf3..0be7c1e7ef80 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -63,6 +63,7 @@ struct vdpasim { u32 status; u32 generation; u64 features; + u32 groups; /* spinlock to synchronize iommu table */ spinlock_t iommu_lock; }; diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 2de442ececae..026b7ad72ed7 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -85,6 +85,7 @@ struct vdpa_device { bool use_va; int nvqs; struct vdpa_mgmt_dev *mdev; + unsigned int ngroups; }; /** @@ -172,6 +173,10 @@ struct vdpa_map_file { * for the device * @vdev: vdpa device * Returns virtqueue algin requirement + * @get_vq_group: Get the group id for a specific virtqueue + * @vdev: vdpa device + * @idx: virtqueue index + * Returns u32: group id for this virtqueue * @get_device_features: Get virtio features supported by the device * @vdev: vdpa device * Returns the virtio features support by the @@ -282,6 +287,7 @@ struct vdpa_config_ops { /* Device ops */ u32 (*get_vq_align)(struct vdpa_device *vdev); + u32 (*get_vq_group)(struct vdpa_device *vdev, u16 idx); u64 (*get_device_features)(struct vdpa_device *vdev); int (*set_driver_features)(struct vdpa_device *vdev, u64 features); u64 (*get_driver_features)(struct vdpa_device *vdev); @@ -314,6 +320,7 @@ struct vdpa_config_ops { struct vdpa_device *__vdpa_alloc_device(struct device *parent, const struct vdpa_config_ops *config, + unsigned int ngroups, size_t size, const char *name, bool use_va); @@ -324,17 +331,18 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, * @member: the name of struct vdpa_device within the @dev_struct * @parent: the parent device * @config: the bus operations that is supported by this device + * @ngroups: the number of virtqueue groups supported by this device * @name: name of the vdpa device * @use_va: indicate whether virtual address must be used by this device * * Return allocated data structure or ERR_PTR upon error */ -#define vdpa_alloc_device(dev_struct, member, parent, config, name, use_va) \ - container_of(__vdpa_alloc_device( \ - parent, config, \ +#define vdpa_alloc_device(dev_struct, member, parent, config, ngroups, name, use_va) \ + container_of((__vdpa_alloc_device( \ + parent, config, ngroups, \ sizeof(dev_struct) + \ BUILD_BUG_ON_ZERO(offsetof( \ - dev_struct, member)), name, use_va), \ + dev_struct, member)), name, use_va)), \ dev_struct, member) int vdpa_register_device(struct vdpa_device *vdev, int nvqs); From patchwork Thu Feb 24 21:22:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7E3CC433FE for ; Thu, 24 Feb 2022 21:25:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234663AbiBXVZz (ORCPT ); Thu, 24 Feb 2022 16:25:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234027AbiBXVZw (ORCPT ); Thu, 24 Feb 2022 16:25:52 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2061.outbound.protection.outlook.com [40.107.94.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 288D029A56B; Thu, 24 Feb 2022 13:25:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PBD0fIF0L0HiVEjtRv9ne/3w6z+aunC5+eU3wLmiH07eOScp9JPOQmNrFFtVbiexNJS5eHDe+PcwCCXKuVTPgM+2nZM98yemqZV5F9ZoOUiTXpIgKh5DQFKc0Cs2Jd+cBFBMQpLe2z94fPP3vEr8JwNE1JEepdXu+CnxJ+wr2kFM5me4WyM2mbLG6dxazrRMuHGWoYGGebNJTraUj6FqPHc7YwRAxDKJ63WveGCPK4smuEMDd/6XExtp6OG6JOJEM5p6ESS35wP45/2QLKn36xt8nU3Wei84i5P5F9T2d4HvUCmykpTiujgFFtLkFODa0gKf0GRMwcHJbR2d8te1Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rB4tGoviTm71x7fMbsUTs9o+zpihoaPWHAxfBn7YGcI=; b=bngoTvpDHZgojUgxZnGKgT7XYMg0nZue2XVZEWG4IH4Kck/DLsTZc2+VA9DXVOYH9MuzM7jlyIt4wSYhMCybB/ay+ywUTzwJKDcOhvL/hImZD8XZUbtDO8XaVLmRdOeWqxv1FVPKKuaUp7r42vP8VGjIEB8uzgpDJU+CkJzt1KtFgV49VGt87XhDXrWtm3FVAANqItrehe/POJRWRUSACv1xb88IynsVC7nxVgN8xlHYpub9mYDV5HYhPI5DaNdoLMI4U8qh2NzESICLkow7luja4uaI3nRpUA4i3uX8/fnhxLvaqYPUDjhCux2cFMz2vu0HOA0LWI/Bhfo2fgjgfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rB4tGoviTm71x7fMbsUTs9o+zpihoaPWHAxfBn7YGcI=; b=SKdCradAFSfB9itTQbzMyMvj1im/TitoOgxskYjMiG/EnckrXgCRRfBeQQq3SnP1U79HqBFzdYVG4nbruePPAdCjQ+Wmhrx9oqnjn0Y4llTH62wjIzIa8nHW/iWVuXFKLBbALoZyt3U9If78MzufgH4RVRkNeMyWpZo8CnLdP60= Received: from DS7PR03CA0324.namprd03.prod.outlook.com (2603:10b6:8:2b::24) by BY5PR02MB6034.namprd02.prod.outlook.com (2603:10b6:a03:1b5::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.17; Thu, 24 Feb 2022 21:25:17 +0000 Received: from DM3NAM02FT006.eop-nam02.prod.protection.outlook.com (2603:10b6:8:2b:cafe::a0) by DS7PR03CA0324.outlook.office365.com (2603:10b6:8:2b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21 via Frontend Transport; Thu, 24 Feb 2022 21:25:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT006.mail.protection.outlook.com (10.13.4.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:25:16 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:25:14 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:25:14 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLbu-00095B-Cd; Thu, 24 Feb 2022 13:25:14 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 06/19] vdpa: multiple address spaces support Date: Fri, 25 Feb 2022 02:52:46 +0530 Message-ID: <20220224212314.1326-7-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 41b76508-e63e-482d-3ab2-08d9f7dc26fe X-MS-TrafficTypeDiagnostic: BY5PR02MB6034:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ctRGZkYlOWkELOpEoxdfeRCw6Ds7qZjNGlsTPD19yceWCcUdsFMof97EOjGjO3EcHZ5Ghe1yK707+xpdrA+rBon+gB12g8IdiSF9l59i0Gl28bgJm212HtCUXc7YVVu5WH3/no5nbcmWf/r3FqmHG0F9KWjklKG83GtMB7MgQW67T1hFUc/v639qff+eBwgqI1y3oEf1R/Gh5Eb5C7lan82IcULDh09kzgIgP/NqaYKhuEl2/Pg0It9b9/7haMJvQVWD98Z80FaxAtqtBd1BgssNDbm10gEFcQ6CeD+7qH4F/2Vwh9k0xd9+qPT/a6C6PmmGuhbcnwqIVrerrj6L3ax09hkp0JwerW6hAJS9zoYO7IEX89XRDuQQQxBPFPjNoFP9gqDFspKgPNWiTUvvJPjFjJzB95i9zQsS/HgLK2/4Pbs1vausuPES1xjTag7D6OuVpyqopEmjZrRxfSguee5xZrn94ZaecgHiLN2mUOcFDV+J8h6leWCvegCj8bB36FGZIEJiKgOAm7rzgXEoq0Izu2q0HjJxp8eNHS/34Dph/Dvu9EV90asXGUqL/A7FcoJNCm3W/R+qHghwvQhSRkL6eYrnrUsMc2hWHaF23XZ90HYVfaxixekIzY1OD3OGjde+UpOBcrCsa4NykhUS/PEEpTYYAzZ7nFwrt7o+RpbY98GNbkpzrNWmq2nlgf6dGOGgLguiSGqikDWTfEVV8Q== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(83380400001)(7696005)(36756003)(70586007)(70206006)(7636003)(36860700001)(336012)(426003)(356005)(47076005)(2906002)(8676002)(4326008)(5660300002)(109986005)(7416002)(54906003)(8936002)(30864003)(44832011)(9786002)(186003)(26005)(316002)(1076003)(2616005)(508600001)(6666004)(82310400004)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:25:16.7759 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41b76508-e63e-482d-3ab2-08d9f7dc26fe X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT006.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR02MB6034 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patches introduces the multiple address spaces support for vDPA device. This idea is to identify a specific address space via an dedicated identifier - ASID. During vDPA device allocation, vDPA device driver needs to report the number of address spaces supported by the device then the DMA mapping ops of the vDPA device needs to be extended to support ASID. This helps to isolate the environments for the virtqueue that will not be assigned directly. E.g in the case of virtio-net, the control virtqueue will not be assigned directly to guest. As a start, simply claim 1 virtqueue groups and 1 address spaces for all vDPA devices. And vhost-vDPA will simply reject the device with more than 1 virtqueue groups or address spaces. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vdpa/ifcvf/ifcvf_main.c | 2 +- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++-- drivers/vdpa/vdpa.c | 4 +++- drivers/vdpa/vdpa_sim/vdpa_sim.c | 10 ++++++---- drivers/vhost/vdpa.c | 14 +++++++++----- include/linux/vdpa.h | 28 +++++++++++++++++++--------- 6 files changed, 41 insertions(+), 22 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index c815a2e62440..a4815c5612f9 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -513,7 +513,7 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, pdev = ifcvf_mgmt_dev->pdev; dev = &pdev->dev; adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa, - dev, &ifc_vdpa_ops, 1, name, false); + dev, &ifc_vdpa_ops, 1, 1, name, false); if (IS_ERR(adapter)) { IFCVF_ERR(pdev, "Failed to allocate vDPA structure"); return PTR_ERR(adapter); diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index fcfc28460b72..a76417892ef3 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -2282,7 +2282,8 @@ static u32 mlx5_vdpa_get_generation(struct vdpa_device *vdev) return mvdev->generation; } -static int mlx5_vdpa_set_map(struct vdpa_device *vdev, struct vhost_iotlb *iotlb) +static int mlx5_vdpa_set_map(struct vdpa_device *vdev, unsigned int asid, + struct vhost_iotlb *iotlb) { struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); bool change_map; @@ -2581,7 +2582,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, } ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops, - 1, name, false); + 1, 1, name, false); if (IS_ERR(ndev)) return PTR_ERR(ndev); diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index a07bf0130559..1793dc12b208 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -160,6 +160,7 @@ static void vdpa_release_dev(struct device *d) * @parent: the parent device * @config: the bus operations that is supported by this device * @ngroups: number of groups supported by this device + * @nas: number of address spaces supported by this device * @size: size of the parent structure that contains private data * @name: name of the vdpa device; optional. * @use_va: indicate whether virtual address must be used by this device @@ -172,7 +173,7 @@ static void vdpa_release_dev(struct device *d) */ struct vdpa_device *__vdpa_alloc_device(struct device *parent, const struct vdpa_config_ops *config, - unsigned int ngroups, + unsigned int ngroups, unsigned int nas, size_t size, const char *name, bool use_va) { @@ -206,6 +207,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, vdev->features_valid = false; vdev->use_va = use_va; vdev->ngroups = ngroups; + vdev->nas = nas; if (name) err = dev_set_name(&vdev->dev, "%s", name); diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index c98cb1f869fa..659e2e2e4b0c 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -251,7 +251,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) ops = &vdpasim_config_ops; vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, 1, - dev_attr->name, false); + 1, dev_attr->name, false); if (IS_ERR(vdpasim)) { ret = PTR_ERR(vdpasim); goto err_alloc; @@ -539,7 +539,7 @@ static struct vdpa_iova_range vdpasim_get_iova_range(struct vdpa_device *vdpa) return range; } -static int vdpasim_set_map(struct vdpa_device *vdpa, +static int vdpasim_set_map(struct vdpa_device *vdpa, unsigned int asid, struct vhost_iotlb *iotlb) { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); @@ -566,7 +566,8 @@ static int vdpasim_set_map(struct vdpa_device *vdpa, return ret; } -static int vdpasim_dma_map(struct vdpa_device *vdpa, u64 iova, u64 size, +static int vdpasim_dma_map(struct vdpa_device *vdpa, unsigned int asid, + u64 iova, u64 size, u64 pa, u32 perm, void *opaque) { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); @@ -580,7 +581,8 @@ static int vdpasim_dma_map(struct vdpa_device *vdpa, u64 iova, u64 size, return ret; } -static int vdpasim_dma_unmap(struct vdpa_device *vdpa, u64 iova, u64 size) +static int vdpasim_dma_unmap(struct vdpa_device *vdpa, unsigned int asid, + u64 iova, u64 size) { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 655ff7029401..6bf755f84d26 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -599,10 +599,10 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, return r; if (ops->dma_map) { - r = ops->dma_map(vdpa, iova, size, pa, perm, opaque); + r = ops->dma_map(vdpa, 0, iova, size, pa, perm, opaque); } else if (ops->set_map) { if (!v->in_batch) - r = ops->set_map(vdpa, iotlb); + r = ops->set_map(vdpa, 0, iotlb); } else { r = iommu_map(v->domain, iova, pa, size, perm_to_iommu_flags(perm)); @@ -628,10 +628,10 @@ static void vhost_vdpa_unmap(struct vhost_vdpa *v, vhost_vdpa_iotlb_unmap(v, iotlb, iova, iova + size - 1); if (ops->dma_map) { - ops->dma_unmap(vdpa, iova, size); + ops->dma_unmap(vdpa, 0, iova, size); } else if (ops->set_map) { if (!v->in_batch) - ops->set_map(vdpa, iotlb); + ops->set_map(vdpa, 0, iotlb); } else { iommu_unmap(v->domain, iova, size); } @@ -863,7 +863,7 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, break; case VHOST_IOTLB_BATCH_END: if (v->in_batch && ops->set_map) - ops->set_map(vdpa, iotlb); + ops->set_map(vdpa, 0, iotlb); v->in_batch = false; break; default: @@ -1128,6 +1128,10 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa) int minor; int r; + /* Only support 1 address space and 1 groups */ + if (vdpa->ngroups != 1 || vdpa->nas != 1) + return -EOPNOTSUPP; + v = kzalloc(sizeof(*v), GFP_KERNEL | __GFP_RETRY_MAYFAIL); if (!v) return -ENOMEM; diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 026b7ad72ed7..de22ca1a8ef3 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -69,6 +69,8 @@ struct vdpa_mgmt_dev; * @cf_mutex: Protects get and set access to configuration layout. * @index: device index * @features_valid: were features initialized? for legacy guests + * @ngroups: the number of virtqueue groups + * @nas: the number of address spaces * @use_va: indicate whether virtual address must be used by this device * @nvqs: maximum number of supported virtqueues * @mdev: management device pointer; caller must setup when registering device as part @@ -86,6 +88,7 @@ struct vdpa_device { int nvqs; struct vdpa_mgmt_dev *mdev; unsigned int ngroups; + unsigned int nas; }; /** @@ -240,6 +243,7 @@ struct vdpa_map_file { * Needed for device that using device * specific DMA translation (on-chip IOMMU) * @vdev: vdpa device + * @asid: address space identifier * @iotlb: vhost memory mapping to be * used by the vDPA * Returns integer: success (0) or error (< 0) @@ -248,6 +252,7 @@ struct vdpa_map_file { * specific DMA translation (on-chip IOMMU) * and preferring incremental map. * @vdev: vdpa device + * @asid: address space identifier * @iova: iova to be mapped * @size: size of the area * @pa: physical address for the map @@ -259,6 +264,7 @@ struct vdpa_map_file { * specific DMA translation (on-chip IOMMU) * and preferring incremental unmap. * @vdev: vdpa device + * @asid: address space identifier * @iova: iova to be unmapped * @size: size of the area * Returns integer: success (0) or error (< 0) @@ -309,10 +315,12 @@ struct vdpa_config_ops { struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev); /* DMA ops */ - int (*set_map)(struct vdpa_device *vdev, struct vhost_iotlb *iotlb); - int (*dma_map)(struct vdpa_device *vdev, u64 iova, u64 size, - u64 pa, u32 perm, void *opaque); - int (*dma_unmap)(struct vdpa_device *vdev, u64 iova, u64 size); + int (*set_map)(struct vdpa_device *vdev, unsigned int asid, + struct vhost_iotlb *iotlb); + int (*dma_map)(struct vdpa_device *vdev, unsigned int asid, + u64 iova, u64 size, u64 pa, u32 perm, void *opaque); + int (*dma_unmap)(struct vdpa_device *vdev, unsigned int asid, + u64 iova, u64 size); /* Free device resources */ void (*free)(struct vdpa_device *vdev); @@ -320,7 +328,7 @@ struct vdpa_config_ops { struct vdpa_device *__vdpa_alloc_device(struct device *parent, const struct vdpa_config_ops *config, - unsigned int ngroups, + unsigned int ngroups, unsigned int nas, size_t size, const char *name, bool use_va); @@ -332,17 +340,19 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, * @parent: the parent device * @config: the bus operations that is supported by this device * @ngroups: the number of virtqueue groups supported by this device + * @nas: the number of address spaces * @name: name of the vdpa device * @use_va: indicate whether virtual address must be used by this device * * Return allocated data structure or ERR_PTR upon error */ -#define vdpa_alloc_device(dev_struct, member, parent, config, ngroups, name, use_va) \ +#define vdpa_alloc_device(dev_struct, member, parent, config, ngroups, nas, \ + name, use_va) \ container_of((__vdpa_alloc_device( \ - parent, config, ngroups, \ - sizeof(dev_struct) + \ + parent, config, ngroups, nas, \ + (sizeof(dev_struct) + \ BUILD_BUG_ON_ZERO(offsetof( \ - dev_struct, member)), name, use_va)), \ + dev_struct, member))), name, use_va)), \ dev_struct, member) int vdpa_register_device(struct vdpa_device *vdev, int nvqs); From patchwork Thu Feb 24 21:22:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87794C433FE for ; Thu, 24 Feb 2022 21:25:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234767AbiBXV0J (ORCPT ); Thu, 24 Feb 2022 16:26:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234788AbiBXV0H (ORCPT ); Thu, 24 Feb 2022 16:26:07 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2048.outbound.protection.outlook.com [40.107.93.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5861294FF8; Thu, 24 Feb 2022 13:25:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nRZu7HeThaKHCyfIspQf+wC7CbIPuZfUeiZNg8s21PoMsu1iUqoIPEnRlS1ox3JMxe98CCGJ1iUdX5aosij3B21Rdh9lmAoJw0tJJHzZ3KbyoNsUVASM4xcRHbJ36o/SdzO06VvYVgvRSvwOziMGB5TqfXhS4U9dlq7nTTPUXEzUiRwVvXbCSNGjGYDhZQWR6s/3ygwm7Evwc1fa7qPBzpG8uZkwV5EbS0DyOpy23xhYRFWpCSOaNubG4aDFMmRJFogRSvigkPsAGmzfAVfKDABdYce+Q+ZuQW0zvtkxO66pwJulkSEtM0omFHDjodmj6Chrrv5EblJ/VCV1lTxtBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hWsiA+jInzk8t2UIiVOUl+QIHmmDAtf/1r53lkKWQtc=; b=CR6qDmdZKVAJdp1EzzmsliDciiu5qBbRBcyyfy8bpotm9EWyvQTGPbMU5f7AAJNJoBfoGeJn8KUz/WW3LWn6dHGlz4o9IEbYdSeCAXkGfEN1aaUcH7iTboMhEZa7McZ5tskfJpL15gaBJj6se+gvoBrLbtn3/JUtMCwRg+srkBKzGbh2P6TnDP+udCvbELZdiXOIFgscf2rDyektDcGRSRaedOCCF8rhXBar974qdl0CJIqTq+xw0iPEOpV6DRxZZG9BDBRCkcq8LmF14Pn1Sr7mkOJgJNlX7IAQiVt9PvDLRoTl/QBYWCBSvSoE32FA4zPhOt+BvtInxDy3xpFl/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hWsiA+jInzk8t2UIiVOUl+QIHmmDAtf/1r53lkKWQtc=; b=DqFKTVxs44pw/ujXR6iyNQIlGLwmyZKL8SS226om/0riFVs72gkcuAh9yQOF/o+Mgf4MDQdIxO3fklRWgDppjVgcIhdi49+tkoeGPSsXcJdBFovJ1W9VbbgIwlXLJPDhzNdpmBKTEMlElvwk6Dez7KTAHmm1E1AWRlxILC6rz5I= Received: from DM5PR15CA0071.namprd15.prod.outlook.com (2603:10b6:3:ae::33) by CY4PR02MB2885.namprd02.prod.outlook.com (2603:10b6:903:11d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16; Thu, 24 Feb 2022 21:25:34 +0000 Received: from DM3NAM02FT013.eop-nam02.prod.protection.outlook.com (2603:10b6:3:ae:cafe::50) by DM5PR15CA0071.outlook.office365.com (2603:10b6:3:ae::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24 via Frontend Transport; Thu, 24 Feb 2022 21:25:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT013.mail.protection.outlook.com (10.13.5.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:25:34 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:25:34 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:25:33 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLcD-00095B-87; Thu, 24 Feb 2022 13:25:33 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 07/19] vdpa: introduce config operations for associating ASID to a virtqueue group Date: Fri, 25 Feb 2022 02:52:47 +0530 Message-ID: <20220224212314.1326-8-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d153978a-acd1-4fd9-9738-08d9f7dc31a2 X-MS-TrafficTypeDiagnostic: CY4PR02MB2885:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MUkA8gZMib1QmQ5bYW6rWFuGV422A38/wBgIHMmGC0lGM1Z5J0vyEThvLzUUvii7Vo06aW/NvHAMEEjEX90UvzJt/pEHV4JQp3j7wyV2TdLU1VcvpbNuUAjWSdqBOkpFu0FUkwwxToDV1wT0YLCnrx12wbJk8bIvz/0W3cEEBNtd5xLNMZPHbxxV7ILls5lVt3at+N+nBE5vN214D3etg4t9K753WDJEKT89L6tN2AHZrKPTAUgl+S5xML5Iia8joZmz0eMVS5hyB0gU+EB9qVJzqa/k85ZBGajWMVdJv1sqjPHFQ01ZgHoBIStkDnFu5ar3S8fUG1wLevMDHP27wEvV8ShNDRjSiLBJCImVOhfbCADAf7I4YCBWmNR12YuhHhY17kC2VjlfPHYS3TRupih+/H1jYcFh9m2Fd32MOvYg7ow67fouYYIPj2K01ZA6bnOoTDdFbtz6K6ecmhjXO8ziD+jWLgrs4o6RFWqVWGNbxrCzxNC4fRTquEsGO9IGzRo44wrwnSaFy127yhq95692UVW4ILnWQxb9qbyuryQuMGVFgq9/RSMPNmrKXeneBlGQ3AJ0JpfZcSXXqSKPrm906/WhjgxGwg3/cnS1wUaECOLzpLyWeJuR8OoA+guvQ7wM48AwmKRBfN7D8tsLu0o1/VcogPNOUKUA94FAfKsRyH0RhUpXsQ4fJeebTKLTcGjvUWn2Q5j7yXu822jARmeKPSdlG0xx7S5IztBmJ+Y= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(36860700001)(83380400001)(47076005)(54906003)(426003)(36756003)(44832011)(2906002)(316002)(7416002)(186003)(2616005)(9786002)(8936002)(7696005)(40460700003)(70586007)(82310400004)(7636003)(1076003)(70206006)(26005)(4326008)(109986005)(356005)(508600001)(5660300002)(8676002)(336012)(6666004)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:25:34.6459 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d153978a-acd1-4fd9-9738-08d9f7dc31a2 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT013.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR02MB2885 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch introduces a new bus operation to allow the vDPA bus driver to associate an ASID to a virtqueue group. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- include/linux/vdpa.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index de22ca1a8ef3..7386860c3995 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -239,6 +239,12 @@ struct vdpa_map_file { * @vdev: vdpa device * Returns the iova range supported by * the device. + * @set_group_asid: Set address space identifier for a + * virtqueue group + * @vdev: vdpa device + * @group: virtqueue group + * @asid: address space id for this group + * Returns integer: success (0) or error (< 0) * @set_map: Set device memory mapping (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) @@ -321,6 +327,10 @@ struct vdpa_config_ops { u64 iova, u64 size, u64 pa, u32 perm, void *opaque); int (*dma_unmap)(struct vdpa_device *vdev, unsigned int asid, u64 iova, u64 size); + int (*set_group_asid)(struct vdpa_device *vdev, unsigned int group, + unsigned int asid); + + /* Free device resources */ void (*free)(struct vdpa_device *vdev); From patchwork Thu Feb 24 21:22:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8F9FC4332F for ; Thu, 24 Feb 2022 21:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234800AbiBXV0f (ORCPT ); Thu, 24 Feb 2022 16:26:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232277AbiBXV0d (ORCPT ); Thu, 24 Feb 2022 16:26:33 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2065.outbound.protection.outlook.com [40.107.237.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E26FE29DD06; Thu, 24 Feb 2022 13:26:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jozj4Vvpli5nWu1I7/vstWyge75psVZZvWmLflwXSBEKuoHhV6LpvOkZSk6AkxJ2IFtDpLRXI1QyFlrohtECf0BdfCjQbOSJJYN87lVEYZt7hVFNFPthmaPKMCS5iwXYmI8bn7ODCFtC38euUfxe5Yc+SGymkdug1POag4BjoQD/XXjIx/0ywcuVQuLgqJNUuCByBQtnm+vkozzbnZMMP265fxsg5ihvfh77jliu13PLJKkBZXVI+MUy0Tz9ALfHUmq1DodqVJ/QWzyZhWQZkR8SP8oDYiLZR5+MaGjVmGCUXxD1r+8QZjNvWi2LC78FUEcZR9Q75N3Jo1EbeXyVfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8i/LMAOsTt6791zzKm07df7sjVoBknaIcJCDvAx5Qxw=; b=P53LuGxMbjvMzlPCEOpuwVvaS9c0XpUTIYdK2I74/w/S4VyOb3ObW2j1e04adI2TWkx0cvVQFD+Ma/XwinzZMyrmoK0OE9nCkgXZYaTjaBuC+nM/3qmONNhr6fhCARmXbwIIvWSDtbAxS093IVVIMQW6okztjK1fn3rvsvMscFky6KUCT033qahOLsjdxexhu+AQvdciN5hWhSlw5U830WOlcXNOdd5BRU8zPiIo5bjO+GvdBe2JJZoq6JnTXcGRw+xM2DHekVFEtZHNOmH0pd6gsHNbmzHbibSykO8vGNG9o+lDKpRxv+tn3NLChtXUUTlgnQIcN6oxjeewhzhvEg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8i/LMAOsTt6791zzKm07df7sjVoBknaIcJCDvAx5Qxw=; b=bSJTBceVOHxcOdCmMNpZ/vsM7KpYxyi5/o8+76f/mdB9VjqrnlRmvsW5jZgma1Bj0pz4G4xgYH74FlaG3FyYZC/zRdfJicIE29yVNsKoIJdPcPPf45abgLkwNixojS8wcW+T9xxf1Y2P6NoHmNadJik0Z3m4G7gZdARquDU2dT0= Received: from DM5PR2001CA0023.namprd20.prod.outlook.com (2603:10b6:4:16::33) by DM8PR02MB8248.namprd02.prod.outlook.com (2603:10b6:8:6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 21:25:57 +0000 Received: from DM3NAM02FT063.eop-nam02.prod.protection.outlook.com (2603:10b6:4:16:cafe::d1) by DM5PR2001CA0023.outlook.office365.com (2603:10b6:4:16::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.25 via Frontend Transport; Thu, 24 Feb 2022 21:25:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT063.mail.protection.outlook.com (10.13.5.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:25:55 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:25:53 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:25:53 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLcX-00095B-CP; Thu, 24 Feb 2022 13:25:53 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 08/19] vhost_iotlb: split out IOTLB initialization Date: Fri, 25 Feb 2022 02:52:48 +0530 Message-ID: <20220224212314.1326-9-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e2b66660-5d5a-4649-f7c0-08d9f7dc3e31 X-MS-TrafficTypeDiagnostic: DM8PR02MB8248:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 37S2bZkcJavRObjS4C5JnKAVtReJqcjBW+CRh6oq+HFPKtHvwDBUbMJ6XUoquJ2mPHZbiciS4LJLT0PEia+PFZpz5O07vOYmZlDNIALLUNJU0uY4mX1MrIPdDZkADu3oJBym58wTEI1z8CR9TbDda4KYv5j3CPQ+JdLKog/mL4rJD8SovkW8AlT8hhT+TsGXQK4QlOsyZoz/+vuEKmNNE3cwv3TMRds1LOQRyVVo4kkVL1ZoLpvnZcSWCgFCMor1Yd5LRpunptmynqUNuMq9/d99PP4iYbw1I7dSsXQPPHQg/OikBVWGTXbxs5RNdsYQlW8aBWisG9bmStYmXDKaJ/c3CEH4W63dVQ7on3KKJ2YsPhg8ROdFOg/7cMUlzYfihmOgEq0Lk2Z0zaJVAJteN0o9ae/ZfQP96wWvNhz6cuMKRqbFyNccF8ScOpcnx0kyQrxC7T4X8nZkz5j/X96j08EZwtFePsoJCAZQEDs68HtyY/ZmmRCgcqj24FpJgVSgQspr7g/Md1beUr2bj8NbejV4f3XAC73zFybkZqG6FpnMwf9PgcvWUj633/2hReo5QTuf3P83PN1E5rENw4aritB6quOEdwBIE1RfYa+EUbX2Xv5ISDmTWFiCmByO2r/xBU59iFuoK4HODuU8jfvEW2uovotopSS+uSoEHAT3phJMXI2AKNmTz9hv4UNW/MRQZCSO7e6QODjpnS/1AezWKUl1s2G9Erdl/isQBmGKQ+xQZFQvwlhEDMPUhNdpu/mt X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(26005)(426003)(70206006)(336012)(54906003)(47076005)(70586007)(8676002)(186003)(6666004)(7696005)(82310400004)(316002)(36860700001)(4326008)(2906002)(508600001)(9786002)(5660300002)(36756003)(7416002)(83380400001)(8936002)(7636003)(44832011)(2616005)(1076003)(109986005)(40460700003)(356005)(102446001)(266003)(21314003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:25:55.7026 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2b66660-5d5a-4649-f7c0-08d9f7dc3e31 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT063.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR02MB8248 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch splits out IOTLB initialization to make sure it could be reused by external modules. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vhost/iotlb.c | 23 ++++++++++++++++++----- include/linux/vhost_iotlb.h | 2 ++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/vhost/iotlb.c b/drivers/vhost/iotlb.c index 670d56c879e5..6239d0ad3853 100644 --- a/drivers/vhost/iotlb.c +++ b/drivers/vhost/iotlb.c @@ -110,6 +110,23 @@ void vhost_iotlb_del_range(struct vhost_iotlb *iotlb, u64 start, u64 last) } EXPORT_SYMBOL_GPL(vhost_iotlb_del_range); +/** + * vhost_iotlb_init - initialize a vhost IOTLB + * @iotlb: the IOTLB that needs to be initialized + * @limit: maximum number of IOTLB entries + * @flags: VHOST_IOTLB_FLAG_XXX + */ +void vhost_iotlb_init(struct vhost_iotlb *iotlb, unsigned int limit, + unsigned int flags) +{ + iotlb->root = RB_ROOT_CACHED; + iotlb->limit = limit; + iotlb->nmaps = 0; + iotlb->flags = flags; + INIT_LIST_HEAD(&iotlb->list); +} +EXPORT_SYMBOL_GPL(vhost_iotlb_init); + /** * vhost_iotlb_alloc - add a new vhost IOTLB * @limit: maximum number of IOTLB entries @@ -124,11 +141,7 @@ struct vhost_iotlb *vhost_iotlb_alloc(unsigned int limit, unsigned int flags) if (!iotlb) return NULL; - iotlb->root = RB_ROOT_CACHED; - iotlb->limit = limit; - iotlb->nmaps = 0; - iotlb->flags = flags; - INIT_LIST_HEAD(&iotlb->list); + vhost_iotlb_init(iotlb, limit, flags); return iotlb; } diff --git a/include/linux/vhost_iotlb.h b/include/linux/vhost_iotlb.h index 2d0e2f52f938..e79a40838998 100644 --- a/include/linux/vhost_iotlb.h +++ b/include/linux/vhost_iotlb.h @@ -36,6 +36,8 @@ int vhost_iotlb_add_range(struct vhost_iotlb *iotlb, u64 start, u64 last, u64 addr, unsigned int perm); void vhost_iotlb_del_range(struct vhost_iotlb *iotlb, u64 start, u64 last); +void vhost_iotlb_init(struct vhost_iotlb *iotlb, unsigned int limit, + unsigned int flags); struct vhost_iotlb *vhost_iotlb_alloc(unsigned int limit, unsigned int flags); void vhost_iotlb_free(struct vhost_iotlb *iotlb); void vhost_iotlb_reset(struct vhost_iotlb *iotlb); From patchwork Thu Feb 24 21:22:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759278 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6289C433F5 for ; Thu, 24 Feb 2022 21:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234813AbiBXV1C (ORCPT ); Thu, 24 Feb 2022 16:27:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234268AbiBXV1A (ORCPT ); Thu, 24 Feb 2022 16:27:00 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2045.outbound.protection.outlook.com [40.107.96.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1029A29DD3F; Thu, 24 Feb 2022 13:26:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BLj+7DV4ip7Zcy4wXahW05r2mA3Tdg0rfiUUQ1F4IcCQwADIKsCXmddptG/TkCM6AMaA+hXulX9xdDMAHH2ZxPSlgEV/hLG7F9HQMXIq7Va+XqVCfQAIMRqt9DFJg2gbwnyjURBV9JsQclVtUSmCWZhqLU2+RbL777S7JuQgKeeywDNZZRQllI6IyDjXJnwbE9Dg50cFWQE7rX2jehILegiKGULNn7Jn7unf5Et61/jtWqxCkhIVuzcCOuRLO55mI6BrSD9v1Nch1hlueAoj8YuE8UWP/pEdh2wdb/K+MvNjFgwmCqX44ock6QYlu5UsY4+bk/J13nDMRcNLqu6w2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Aq9v9QnSl4zFVw86sJrG7QcpWAhGerJfTo+ZwuC/mWQ=; b=ID3P3uh8bwQAMblqOXO/jocw6FiwuiwKcWRLclBDBFXB4OkGoMcYH/jviPizTOFYHyGn96RkmFiU+UJFnjrhptbUx/3NP/xPWx8mQ6EtEwEfxiB0vQjOGJl+SRlTcEf6eqYERsVjS4oBxMksnmgo5dA7Roagm2UZvQZRr9eKR4Zm/VyrY5nbfZbmLRUB8n2SYCdJfbXHO6IIcgjbL7QCk8Duc6JzwxISV5NaikQMyxCrcxZ22efv2ahIg0qjNxDnrsBw7gIeQulSpBu58v6v7ViVLXahVO4/AQhVmk/wSFm/DiDqyS92WQIbcyyWj2FqVJ6f58VnT2sghlgyGqsaHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Aq9v9QnSl4zFVw86sJrG7QcpWAhGerJfTo+ZwuC/mWQ=; b=bFG0rzvdB0LJ9Q1TVkMPzgaUZGbjj2EMM5e0EziCUSGRarjgclYCylmkl0Ivl/78w/xL0DeB6tLxGpPgFAtlcHEr2PnbcyeVqCk9UuSCH50j4aAuJfwc3VH+uhGjUxXrf2IrdXkTS/FJ8AB54cYdCVCf623iu6AUyvvSueOldn4= Received: from DS7PR05CA0047.namprd05.prod.outlook.com (2603:10b6:8:2f::26) by DM6PR02MB4058.namprd02.prod.outlook.com (2603:10b6:5:9f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.24; Thu, 24 Feb 2022 21:26:15 +0000 Received: from DM3NAM02FT050.eop-nam02.prod.protection.outlook.com (2603:10b6:8:2f:cafe::f) by DS7PR05CA0047.outlook.office365.com (2603:10b6:8:2f::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.9 via Frontend Transport; Thu, 24 Feb 2022 21:26:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT050.mail.protection.outlook.com (10.13.5.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:26:15 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:26:12 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:26:12 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLcq-00095B-4Z; Thu, 24 Feb 2022 13:26:12 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 09/19] vhost: support ASID in IOTLB API Date: Fri, 25 Feb 2022 02:52:49 +0530 Message-ID: <20220224212314.1326-10-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4cb3dae9-b3b5-430f-a68f-08d9f7dc49c0 X-MS-TrafficTypeDiagnostic: DM6PR02MB4058:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xxyw77jop7pQHpB29kW9MhAWu4L+jjQ2Qt7CZyRm4ZJwVKy9UtVJ+IKh7a2x9B9nq22+ZGoVpeQtsY74qu8D1GES0obaJst1KVouPDtjsx0becPIh3TXTm92JJR+9YEXtIfFUzly/K5G95/vdcQ3CGM6UcfwE5mpvuLeDd9rVcEz2sK0MWU9mxOlWnKjcUFQqd0rj5wUpqlaLFyOaa+4cwpeSXkPaAFUKhomzn6STOe9pTF5Y0HtKVkJAIy0bURb/sOfiSGtDEun2Q/UI7tPlziM8Rc2hfvqePwRSh/fpKuidzGbQDpq3tRWAZSh/3qAb6FHTqg8d9iAg4HFg7d4FZH6XhDyCyk7RpQ2Y4QcGeYX41q+JMbY3Bvwa0MnDmU4ubEtOmCGeMMjpmvuhng5GqmHZkvk2hvFO3cevNBKchRIQyaozustTwEq7o5P6FJX8atRVtDlx1dmbyOvMoNBdDGJIPAkQkHg8KTJI3zWEjIYV835R1UCEenk2YtejTS4oDYZw7XKnodup7Hj8qhplbPVk7FvtNLUxDNizHoU6YIvjDKphE/6G9Q5F7zkj072zc0egLrmv0n7chnAXH3c8IQKspDjGmDzB+eKZx8Qw3DAq5NbNZCI9oBj2F9nLvJo3iyplEMxQMJGducVSNurRWuh83DqeqRXEG93gt3QuiejZspdE2BLzPncmKHFPqqQPzyc+ZGPFeLyAEM99E+ND+DbT2w9uGbAWoUYdmOL2W4= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(36860700001)(44832011)(47076005)(40460700003)(426003)(5660300002)(336012)(2906002)(2616005)(7636003)(109986005)(26005)(186003)(1076003)(36756003)(7416002)(356005)(70586007)(316002)(8676002)(8936002)(9786002)(4326008)(83380400001)(508600001)(7696005)(82310400004)(54906003)(6666004)(70206006)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:26:15.0926 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4cb3dae9-b3b5-430f-a68f-08d9f7dc49c0 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT050.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB4058 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patches allows userspace to send ASID based IOTLB message to vhost. This idea is to use the reserved u32 field in the existing V2 IOTLB message. Vhost device should advertise this capability via VHOST_BACKEND_F_IOTLB_ASID backend feature. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vhost/vdpa.c | 5 ++++- drivers/vhost/vhost.c | 23 ++++++++++++++++++----- drivers/vhost/vhost.h | 4 ++-- include/uapi/linux/vhost_types.h | 6 +++++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 6bf755f84d26..d0aacc0cc79a 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -836,7 +836,7 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v, msg->perm); } -static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, +static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid, struct vhost_iotlb_msg *msg) { struct vhost_vdpa *v = container_of(dev, struct vhost_vdpa, vdev); @@ -847,6 +847,9 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, mutex_lock(&dev->mutex); + if (asid != 0) + return -EINVAL; + r = vhost_dev_check_owner(dev); if (r) goto unlock; diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 59edb5a1ffe2..1f514d98f0de 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -468,7 +468,7 @@ void vhost_dev_init(struct vhost_dev *dev, struct vhost_virtqueue **vqs, int nvqs, int iov_limit, int weight, int byte_weight, bool use_worker, - int (*msg_handler)(struct vhost_dev *dev, + int (*msg_handler)(struct vhost_dev *dev, u32 asid, struct vhost_iotlb_msg *msg)) { struct vhost_virtqueue *vq; @@ -1090,11 +1090,14 @@ static bool umem_access_ok(u64 uaddr, u64 size, int access) return true; } -static int vhost_process_iotlb_msg(struct vhost_dev *dev, +static int vhost_process_iotlb_msg(struct vhost_dev *dev, u32 asid, struct vhost_iotlb_msg *msg) { int ret = 0; + if (asid != 0) + return -EINVAL; + mutex_lock(&dev->mutex); vhost_dev_lock_vqs(dev); switch (msg->type) { @@ -1141,6 +1144,7 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, struct vhost_iotlb_msg msg; size_t offset; int type, ret; + u32 asid = 0; ret = copy_from_iter(&type, sizeof(type), from); if (ret != sizeof(type)) { @@ -1156,7 +1160,16 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, offset = offsetof(struct vhost_msg, iotlb) - sizeof(int); break; case VHOST_IOTLB_MSG_V2: - offset = sizeof(__u32); + if (vhost_backend_has_feature(dev->vqs[0], + VHOST_BACKEND_F_IOTLB_ASID)) { + ret = copy_from_iter(&asid, sizeof(asid), from); + if (ret != sizeof(asid)) { + ret = -EINVAL; + goto done; + } + offset = sizeof(__u16); + } else + offset = sizeof(__u32); break; default: ret = -EINVAL; @@ -1171,9 +1184,9 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, } if (dev->msg_handler) - ret = dev->msg_handler(dev, &msg); + ret = dev->msg_handler(dev, asid, &msg); else - ret = vhost_process_iotlb_msg(dev, &msg); + ret = vhost_process_iotlb_msg(dev, asid, &msg); if (ret) { ret = -EFAULT; goto done; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 638bb640d6b4..9f238d6c7b58 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -161,7 +161,7 @@ struct vhost_dev { int byte_weight; u64 kcov_handle; bool use_worker; - int (*msg_handler)(struct vhost_dev *dev, + int (*msg_handler)(struct vhost_dev *dev, u32 asid, struct vhost_iotlb_msg *msg); }; @@ -169,7 +169,7 @@ bool vhost_exceeds_weight(struct vhost_virtqueue *vq, int pkts, int total_len); void vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs, int nvqs, int iov_limit, int weight, int byte_weight, bool use_worker, - int (*msg_handler)(struct vhost_dev *dev, + int (*msg_handler)(struct vhost_dev *dev, u32 asid, struct vhost_iotlb_msg *msg)); long vhost_dev_set_owner(struct vhost_dev *dev); bool vhost_dev_has_owner(struct vhost_dev *dev); diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_types.h index 76ee7016c501..634cee485abb 100644 --- a/include/uapi/linux/vhost_types.h +++ b/include/uapi/linux/vhost_types.h @@ -87,7 +87,7 @@ struct vhost_msg { struct vhost_msg_v2 { __u32 type; - __u32 reserved; + __u32 asid; union { struct vhost_iotlb_msg iotlb; __u8 padding[64]; @@ -157,5 +157,9 @@ struct vhost_vdpa_iova_range { #define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1 /* IOTLB can accept batching hints */ #define VHOST_BACKEND_F_IOTLB_BATCH 0x2 +/* IOTLB can accept address space identifier through V2 type of IOTLB + * message + */ +#define VHOST_BACKEND_F_IOTLB_ASID 0x3 #endif From patchwork Thu Feb 24 21:22:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2039CC433FE for ; Thu, 24 Feb 2022 21:27:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234880AbiBXV1l (ORCPT ); Thu, 24 Feb 2022 16:27:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234801AbiBXV1V (ORCPT ); Thu, 24 Feb 2022 16:27:21 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2043.outbound.protection.outlook.com [40.107.243.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD01C2DD67; Thu, 24 Feb 2022 13:26:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VCZNZBFu9PjLuNs7DrPYXNRYGT+4DSm+h6O9KR6PWn5NblTejc8pCohYiO5CqHL/ZGg/E8z7cgIZO7eTiebjHWlYXJNARGTsjoK9oqzEZrdCOjK6ZMwsGPdMpnW3Coi24ldHdoFBnaOPaa48MgKjHhfC01w3d2NJnCMsE9vdaaQ1DZA3+o/xn5wObK0IG9wZklvWpOkSuRlqfpJw9nvR5gJHjABTIo0kBZrkj/mE/lHA5q/7xhuyyY+1+01PTpMRFhLwDipqsE93t8GwodOorJLUxRvX7PoNb9mOTv5ajD5jJA1zKueEjgGcpsOga0w5YCCdxc+upYf0TfaXB2xmYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4UMh827kCyqHeMys6i5nUx2W5HRE3fSujaJcYVcit8E=; b=RoiGkTDHVSIrf6x+Ukek1Wy2nlm7NnDpanbcPXho5Obmc3CjLvb78e8BnRpRviViFddWyQqn96nfxqiaGQmRgySoCuNS4lVajbos/EOBLRAfw+uZnWQUywGjDdjfi5GxHROnu3GQymAAQCY+qAVgTgc2fF8MWrONeVbRtUjKmXph4iCd/Cuc2J0h0XuOUb45Go0GjDlQ2i1DaChH//MF2cRB195M012XNLsFmQLfNV9p6+y72K1Z/pPZWdOojCilnrtrP7JCLnvMVS/vx9VD02OxW2q9QzUCdgUmALr76uOUDozUGhDHfd6Ko8u6fjgHp8swjLhNLSF11RUnw95FOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4UMh827kCyqHeMys6i5nUx2W5HRE3fSujaJcYVcit8E=; b=ScsAmTpELrUQ2sXUlvdq9cwFTUaVfrRuB1OHOVG3ocv4e0VV2tePSmB6EkWpZekIF3eZBk/l3Fc0DzOZLJ9BtS3Zj7Tr3KIr16VmKtvIxHC04CRwOYS/gj3XiiHc1Ug4+ZeBSJG/eOumOXxgkeEx7ZpzQobp9TNZ3HiQxxKpUWk= Received: from DS7PR03CA0143.namprd03.prod.outlook.com (2603:10b6:5:3b4::28) by PH0PR02MB8392.namprd02.prod.outlook.com (2603:10b6:510:10b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 21:26:32 +0000 Received: from DM3NAM02FT041.eop-nam02.prod.protection.outlook.com (2603:10b6:5:3b4:cafe::46) by DS7PR03CA0143.outlook.office365.com (2603:10b6:5:3b4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24 via Frontend Transport; Thu, 24 Feb 2022 21:26:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT041.mail.protection.outlook.com (10.13.5.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:26:31 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:26:31 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:26:31 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLd8-00095B-TL; Thu, 24 Feb 2022 13:26:31 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 10/19] vhost-vdpa: introduce asid based IOTLB Date: Fri, 25 Feb 2022 02:52:50 +0530 Message-ID: <20220224212314.1326-11-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6319486e-3a8f-4100-a64f-08d9f7dc53cb X-MS-TrafficTypeDiagnostic: PH0PR02MB8392:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5j9loyympihenahdZq4fPDJcdWBtmDSVifawbRM/kDANz3OkmhvZru37Fyz9njEyFQmitkyGg7O2JLQ+2Uu0xXtO12PDTIs2wkKIbShtY4tD1QfEEE4wQ7M5QehB8Qr8CJfBmnImyJJW/KEM5mN0hQd0V+8WbAh1OSnebwS6Q1sp0y1a3Zoo1XPPxrjh14Aujx5NnrkYPhEn41w2Io7kYJLmDlGhVmz0nZDDTUPrl1F7JSxBAmK1G4KKDfG7Cl/gQGv/OEkBifnbzcaI2ll955pFT3fV0PxMuxVJzVOB8PLydsr37AzKyskZqjd0bH8cUWBuVIrDkpK+VAFffH86KMKB5ZJwebaUFf8Mxpou1Ef1gXRLD9AlMXVIuEP4RpDm7y0nwTxBm5vwJOdVBQ6gEAUIO90/JOLraHJ5xIbkUAHNinUD6ukjd1Og7yUiHLN/LkAnsVwDgVRj8fCUMkf3g6FQjDUp1NZUt+Oj9Sl6NZl3WaP/trU0+oOXSA2UcYo3QsymfOlt+4wvdoZItlOCSb4bK9UHVGxGZolKT6mb+/N0Df32k1QXomTGBCP5wQkMBEGDyOqmt3jndyL3Y4EwI/orELrvKxcphC8tYs8ziyeo2JjkINB13/rsK4H4JbubcwQG/DIBG6Ezh/dTHd68DGYJ4PJFK7wI/SiypMemvmcSUDEY5pG5cHYIV6tlhAAOJTDfI/lUxT0PflqECgHbT2idvxS6H7TLpVTaSXAZBGY= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(26005)(109986005)(2616005)(508600001)(40460700003)(7696005)(6666004)(1076003)(82310400004)(7636003)(47076005)(356005)(186003)(4326008)(8676002)(54906003)(336012)(2906002)(426003)(316002)(36756003)(7416002)(5660300002)(36860700001)(70206006)(9786002)(44832011)(8936002)(83380400001)(70586007)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:26:31.9419 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6319486e-3a8f-4100-a64f-08d9f7dc53cb X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT041.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR02MB8392 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch converts the vhost-vDPA device to support multiple IOTLBs tagged via ASID via hlist. This will be used for supporting multiple address spaces in the following patches. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vhost/vdpa.c | 104 ++++++++++++++++++++++++++++++++----------- 1 file changed, 79 insertions(+), 25 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index d0aacc0cc79a..4e8b7c4809cd 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -33,13 +33,21 @@ enum { #define VHOST_VDPA_DEV_MAX (1U << MINORBITS) +#define VHOST_VDPA_IOTLB_BUCKETS 16 + +struct vhost_vdpa_as { + struct hlist_node hash_link; + struct vhost_iotlb iotlb; + u32 id; +}; + struct vhost_vdpa { struct vhost_dev vdev; struct iommu_domain *domain; struct vhost_virtqueue *vqs; struct completion completion; struct vdpa_device *vdpa; - struct vhost_iotlb *iotlb; + struct hlist_head as[VHOST_VDPA_IOTLB_BUCKETS]; struct device dev; struct cdev cdev; atomic_t opened; @@ -49,12 +57,64 @@ struct vhost_vdpa { struct eventfd_ctx *config_ctx; int in_batch; struct vdpa_iova_range range; + int used_as; }; static DEFINE_IDA(vhost_vdpa_ida); static dev_t vhost_vdpa_major; +static struct vhost_vdpa_as *asid_to_as(struct vhost_vdpa *v, u32 asid) +{ + struct hlist_head *head = &v->as[asid % VHOST_VDPA_IOTLB_BUCKETS]; + struct vhost_vdpa_as *as; + + hlist_for_each_entry(as, head, hash_link) + if (as->id == asid) + return as; + + return NULL; +} + +static struct vhost_vdpa_as *vhost_vdpa_alloc_as(struct vhost_vdpa *v, u32 asid) +{ + struct hlist_head *head = &v->as[asid % VHOST_VDPA_IOTLB_BUCKETS]; + struct vhost_vdpa_as *as; + + if (asid_to_as(v, asid)) + return NULL; + + as = kmalloc(sizeof(*as), GFP_KERNEL); + if (!as) + return NULL; + + vhost_iotlb_init(&as->iotlb, 0, 0); + as->id = asid; + hlist_add_head(&as->hash_link, head); + ++v->used_as; + + return as; +} + +static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid) +{ + struct vhost_vdpa_as *as = asid_to_as(v, asid); + + /* Remove default address space is not allowed */ + if (asid == 0) + return -EINVAL; + + if (!as) + return -EINVAL; + + hlist_del(&as->hash_link); + vhost_iotlb_reset(&as->iotlb); + kfree(as); + --v->used_as; + + return 0; +} + static void handle_vq_kick(struct vhost_work *work) { struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue, @@ -554,15 +614,6 @@ static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v, return vhost_vdpa_pa_unmap(v, iotlb, start, last); } -static void vhost_vdpa_iotlb_free(struct vhost_vdpa *v) -{ - struct vhost_iotlb *iotlb = v->iotlb; - - vhost_vdpa_iotlb_unmap(v, iotlb, 0ULL, 0ULL - 1); - kfree(v->iotlb); - v->iotlb = NULL; -} - static int perm_to_iommu_flags(u32 perm) { int flags = 0; @@ -842,7 +893,8 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid, struct vhost_vdpa *v = container_of(dev, struct vhost_vdpa, vdev); struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; - struct vhost_iotlb *iotlb = v->iotlb; + struct vhost_vdpa_as *as = asid_to_as(v, 0); + struct vhost_iotlb *iotlb = &as->iotlb; int r = 0; mutex_lock(&dev->mutex); @@ -953,6 +1005,13 @@ static void vhost_vdpa_set_iova_range(struct vhost_vdpa *v) } } +static void vhost_vdpa_cleanup(struct vhost_vdpa *v) +{ + vhost_dev_cleanup(&v->vdev); + kfree(v->vdev.vqs); + vhost_vdpa_remove_as(v, 0); +} + static int vhost_vdpa_open(struct inode *inode, struct file *filep) { struct vhost_vdpa *v; @@ -985,15 +1044,12 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) vhost_dev_init(dev, vqs, nvqs, 0, 0, 0, false, vhost_vdpa_process_iotlb_msg); - v->iotlb = vhost_iotlb_alloc(0, 0); - if (!v->iotlb) { - r = -ENOMEM; - goto err_init_iotlb; - } + if (!vhost_vdpa_alloc_as(v, 0)) + goto err_alloc_as; r = vhost_vdpa_alloc_domain(v); if (r) - goto err_alloc_domain; + goto err_alloc_as; vhost_vdpa_set_iova_range(v); @@ -1001,11 +1057,8 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) return 0; -err_alloc_domain: - vhost_vdpa_iotlb_free(v); -err_init_iotlb: - vhost_dev_cleanup(&v->vdev); - kfree(vqs); +err_alloc_as: + vhost_vdpa_cleanup(v); err: atomic_dec(&v->opened); return r; @@ -1029,11 +1082,9 @@ static int vhost_vdpa_release(struct inode *inode, struct file *filep) vhost_vdpa_clean_irq(v); vhost_vdpa_reset(v); vhost_dev_stop(&v->vdev); - vhost_vdpa_iotlb_free(v); vhost_vdpa_free_domain(v); vhost_vdpa_config_put(v); vhost_dev_cleanup(&v->vdev); - kfree(v->vdev.vqs); mutex_unlock(&d->mutex); atomic_dec(&v->opened); @@ -1129,7 +1180,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa) const struct vdpa_config_ops *ops = vdpa->config; struct vhost_vdpa *v; int minor; - int r; + int i, r; /* Only support 1 address space and 1 groups */ if (vdpa->ngroups != 1 || vdpa->nas != 1) @@ -1177,6 +1228,9 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa) init_completion(&v->completion); vdpa_set_drvdata(vdpa, v); + for (i = 0; i < VHOST_VDPA_IOTLB_BUCKETS; i++) + INIT_HLIST_HEAD(&v->as[i]); + return 0; err: From patchwork Thu Feb 24 21:22:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759280 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3503AC433F5 for ; Thu, 24 Feb 2022 21:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234913AbiBXV1o (ORCPT ); Thu, 24 Feb 2022 16:27:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234850AbiBXV1j (ORCPT ); Thu, 24 Feb 2022 16:27:39 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2080.outbound.protection.outlook.com [40.107.243.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C442D64BCD; Thu, 24 Feb 2022 13:26:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TacHgItltT5Y2Ds7EGKu7hDsnkugae5Bhifdp1tIvoa01hgxAOUoECrHskmkqfeHgRqWGHCBA1oJloL8f5UMjJCVHP8zE28HiUDdv56Llxkshxf/CXhcuERA5cE1JyAQ4uKwm0DfaWwC74Jk0v9woD0zHE4nn0kMrc9XHLos/AfLuI96vuI0QNiTQY0ptMpz4p5H0TB4ZLIsARGGoEMy7KBbCU1j+/FV2kv5JYDvCWCyxxwF2rxv5FVTaVM2Bdgt84MLxerZ99gZECsMaVqG6IUXirCVb0/zvDCjVZCzSh2mwXxbEt4/0g2Za30Jlh6NMFYWrAupk77u7hH7HKqF7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+OzNqprShJ/sPFnbaEsuGL/x+Wq9ZcKHWv4EQt7MqXc=; b=EBd7nEwmdmQnwfC/tJHl2WAYB7zkvuZCntPGEw1b0tLGdEAJb+9iS/Cw8A0A1gzNLbz0yH1RB/1GHExsSyPRi/172ZO+UgMQyZjv1OoEjD8R/4FE6/gK5VQ+757AgRPDnh/WEq7yOb9c+60jlmaj18LQYyZI8O97/8CxB0Fr5sZvPUMdlzMExooSDXNrj4ZBj8+0/KxStMRsh/ZSDKZ7AoDRFfCfWjzh8ixw+UmD1uVvmjZq/CK9lZAiJwWYBCI/xCiYkrmRB3yYWwYYM4447KVAXYeRVa3rGiZOUpBRFQqMHZRMXN4qllw3c++IeyqTJudZyIHqYYTt+t7o0JUD/A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+OzNqprShJ/sPFnbaEsuGL/x+Wq9ZcKHWv4EQt7MqXc=; b=TgoRmiTsSRS2t6XBhMC1w0Edx8GKq2rgoPR9/qRCq4sp09pYN8OIPwVdpM1fHxVvCikFj4v1ywsFr9dJq+ps5OpO+BnA2pqbH0zqw7NDf3s536ikyaSxXZoDnbvjdpqSiUJ4FoOoD02gkKaPBcyiPutl/AvEiIsVzB8TyB3j2Pw= Received: from DM6PR11CA0009.namprd11.prod.outlook.com (2603:10b6:5:190::22) by SN6PR02MB4605.namprd02.prod.outlook.com (2603:10b6:805:b4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 21:26:50 +0000 Received: from DM3NAM02FT032.eop-nam02.prod.protection.outlook.com (2603:10b6:5:190:cafe::a2) by DM6PR11CA0009.outlook.office365.com (2603:10b6:5:190::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23 via Frontend Transport; Thu, 24 Feb 2022 21:26:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT032.mail.protection.outlook.com (10.13.5.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:26:50 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:26:50 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:26:50 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLdR-00095B-ME; Thu, 24 Feb 2022 13:26:50 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 11/19] vhost-vdpa: introduce uAPI to get the number of virtqueue groups Date: Fri, 25 Feb 2022 02:52:51 +0530 Message-ID: <20220224212314.1326-12-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bdacefd3-97ee-4d58-8900-08d9f7dc5eff X-MS-TrafficTypeDiagnostic: SN6PR02MB4605:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bZLIZj2nWS5K028ciBOw+rbexv+/dCNsKTOz66pxADxkAOk5ygOBOCeLabGTAAd7qcf1T5Jt91yslukSScA1GqQK+NIJkfyIcfUauVxWbwKKlNGGqn2ymNEWhkI93p/xGQ0g9Ja3hWpzVnnBXATvPnwSk/LmC2s2TGSlpuDA6XOqMYfUFTS8YAqsPJve1cj/b1eeuCv5GnhKbv7Z7HpXk6BJem0kq/ngV4IaQ3VHdrTMMSB8addDolKlM22ljLyI0bMcen6eR2oumQWcvWBioEF8UQHTxqiWdcWFvft6ImbvWZUN+IlsuSCCySuXBGMN/BpxvxkCnCLu5+2XWUOFBliltA9wuf2JVPIeCmdqe0zg04JkukA+o3x56xU8YMiTTWlRvdOwg7hhFB8HQ+UJMbocGOUXgomOYZS4wq6frTGA8XJYkDsGsH0Fq+dDjIuAbc4cxGQsEREVz2UL3MBZ3MDHZBanPcYPaO2IcQj769HTL2o/NY4FJX+C/+86jrbQ7SfdCCyzUwHPNEutyAib0X9qAAAXlJhuwnFML8+CHRxz1UFhFbuGWCSybYlRT2h3U9BCqcclzpUPRxK8L+yZZtRuMQaV3/5ITaBjcyjtzVRsBnUcL3U4vt9t2KwqgCCmnRBC4m9Bk7YvNsMFJ30G4XRN2IidU/IAuTQHvGqDXHoP5mZScQNIhetpAxl5VdqCCZegNjhlqf5mjgD/f3Ltkzao2C+Y+LVZseHwMM4KS5Cr/konD4WYOFkGa+L3J0RC X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(8676002)(4326008)(316002)(54906003)(508600001)(7636003)(356005)(36756003)(70586007)(70206006)(47076005)(8936002)(426003)(7696005)(336012)(5660300002)(9786002)(40460700003)(44832011)(7416002)(1076003)(186003)(2906002)(2616005)(109986005)(82310400004)(26005)(83380400001)(36860700001)(102446001)(266003)(15583001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:26:50.7525 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bdacefd3-97ee-4d58-8900-08d9f7dc5eff X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT032.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB4605 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Follows the vDPA support for multiple address spaces, this patch introduce uAPI for the userspace to know the number of virtqueue groups supported by the vDPA device. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vhost/vdpa.c | 4 ++++ include/uapi/linux/vhost.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 4e8b7c4809cd..7a8a99cef8a4 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -538,6 +538,10 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, case VHOST_VDPA_GET_VRING_NUM: r = vhost_vdpa_get_vring_num(v, argp); break; + case VHOST_VDPA_GET_GROUP_NUM: + r = copy_to_user(argp, &v->vdpa->ngroups, + sizeof(v->vdpa->ngroups)); + break; case VHOST_SET_LOG_BASE: case VHOST_SET_LOG_FD: r = -ENOIOCTLCMD; diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index 59c6c0fbaba1..8a4e6e426bbf 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -145,4 +145,7 @@ /* Get the valid iova range */ #define VHOST_VDPA_GET_IOVA_RANGE _IOR(VHOST_VIRTIO, 0x78, \ struct vhost_vdpa_iova_range) +/* Get the number of virtqueue groups. */ +#define VHOST_VDPA_GET_GROUP_NUM _IOR(VHOST_VIRTIO, 0x79, unsigned int) + #endif From patchwork Thu Feb 24 21:22:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2634C433EF for ; Thu, 24 Feb 2022 21:29:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232926AbiBXV3s (ORCPT ); Thu, 24 Feb 2022 16:29:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234920AbiBXV1p (ORCPT ); Thu, 24 Feb 2022 16:27:45 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2083.outbound.protection.outlook.com [40.107.237.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F87D42A32; Thu, 24 Feb 2022 13:27:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DynVAkMo0ZzcfwZSLeNuyMd0uetY5RDtVwNc8E4uCMDPiFD+PFd9p/DATum0MEw3Hm7XEyt9L3zWeT+MiW/oBeDfWoGEa8UV0A6CRGSHLIIMDzK7Lbppzy3pTQeDdATuR7BJHlA1CrzwjWvN0upK8Pjk0Lm2Z6UZzk8zy8FzBxMMu/bSX0In9VilAUpP2J5iygAG+05kD1F/ooBuiPCEpzUrbAa0RZigumjm0GGWJxF+aB1PNwbRoTpAOZc3MM4KQpVw6qXhiFR1W8Rkq7FP/XB0fK0YnMGJoqLl+htcagfSjbOas255ZwXhxxwa69Dg/xQ44YllGl5PWfExe19HXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Gl32lLRv/mq2hUkWPlS0apg8KdiMyMf28wYtzAvqtB0=; b=HqVEwYtt5qymSuSjIrGR6ZneRvD95nSxdAPTXrCIGrk8CabdXqLeCIOTA453Vlw7A0JjLhXmGrqMMFwGbCGT/kP0PvBWZ6gjBgLN5JVne+IQtmBEMkAgnhe98gAvbbCRBvw44UslvAEgVeRnmHRwo6IQEJdBpUYRzt0IJ2scnfKen8OH75EwCwdk5azJsRAHdpANNnzJOFWULSG0YQGhg953DNfsMaXZtsrpCp9OHIqS0DhxLbKeaWQT9tn26Pq5Ko20rpSHaoT3+Vx/KLFOfPmCD4a7cCLejmFr7v+euyEWSH4fBbjmfvYyeO64qWL73IbrXtUZpjRSyHsbJmr2nQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Gl32lLRv/mq2hUkWPlS0apg8KdiMyMf28wYtzAvqtB0=; b=V+8Y3x3hq3z/rUvi5p8siwE5vBqQbxWGSTLYIRej+n89ThAuI8KO9RBg6MLfk4YihX0IOE3gDKaw1I+GksxTUG1uANOywO4d7jYKHGBRYTiCcgrte4NihXEjp/bn0laQ2W3rLIx6Vrl/YXdq3z8janaZj3teGQ/TzlLW7sUFHcE= Received: from DS7PR03CA0272.namprd03.prod.outlook.com (2603:10b6:5:3ad::7) by SN6PR02MB5615.namprd02.prod.outlook.com (2603:10b6:805:ea::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 21:27:11 +0000 Received: from DM3NAM02FT055.eop-nam02.prod.protection.outlook.com (2603:10b6:5:3ad:cafe::12) by DS7PR03CA0272.outlook.office365.com (2603:10b6:5:3ad::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24 via Frontend Transport; Thu, 24 Feb 2022 21:27:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT055.mail.protection.outlook.com (10.13.5.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:27:11 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:27:10 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:27:10 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLdl-00095B-VN; Thu, 24 Feb 2022 13:27:10 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 12/19] vhost-vdpa: introduce uAPI to get the number of address spaces Date: Fri, 25 Feb 2022 02:52:52 +0530 Message-ID: <20220224212314.1326-13-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1bfa6b4a-5ce4-4083-57bc-08d9f7dc6b35 X-MS-TrafficTypeDiagnostic: SN6PR02MB5615:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xsBoia07YRfPOTHFEU8aeEQVPHPVrvm4R1Bf7m5UKAoRNqVBrSnPvnLfsi+ekKVT6XSpaSwEaiuVVqkneYP+KmNMZ9PgHgmRQzFH/x/1KwFgIx7+pKXOW8M6ZgG0wKpq6fUmERjZLjHB3wgHQyQ5PXF/j34zg8SDc63Yy9A9u2nxZyOIz5MeP4Avkl+LxiREEov+NdGal/WoqCnBC5z9ALzmzZLv1ycUYPmuDx9INsblrIHewI6+/vAoNWnmMDUMpmhW7E7PMh+WxDRPjXOb5RqUaBqOzIFcE5ZYxqmxLFA3rt2hYqmAY0Y4HKIIXXrnLDrKe3Qy7XB7Mhvgwr4tOKUwmDR0CWD/2tqNj4eLA3foZBLZOjMfUX/N6RRbez09E3seBObY9mltc2h1OvHHt/wjOPBbC4SPsZZ1xtCFmfilkIIIXf8RL//klPXW0Q8lurZ0uWiJUNrg2P5qN3icDijh9Aec1q7fa9K96aLuWVQ7DQ88SmF9FXmtTEQ2N/3BNI4TqPZRJn+gRnK3K7dnA30i8zEMGOnfF7uOUL9470B84pTbjfjpDfN8Y3p5uSUZbRg3Y34XHHXQ4k8/uQ0bU/+cbB+HWzzfSjXKyk0P+UiNgC9qgKCwVd010qU+tfXJA9gccofSDID06ibzlu+m5jghXPP2WhRWhhkV+SR8uC0puNcm6PyjT4jf1+wpM6cUDpsrwjfFfeY9U7zKpPDUQHsXVsxZaTtSQnq89LDGzZcFwvUaIMHa3FvENR0iGSOc X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(82310400004)(2616005)(47076005)(4326008)(1076003)(8676002)(109986005)(5660300002)(70586007)(36860700001)(70206006)(7416002)(356005)(7636003)(6666004)(83380400001)(8936002)(426003)(2906002)(26005)(44832011)(7696005)(316002)(9786002)(40460700003)(186003)(508600001)(36756003)(54906003)(336012)(102446001)(266003)(15583001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:27:11.2222 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1bfa6b4a-5ce4-4083-57bc-08d9f7dc6b35 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT055.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB5615 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch introduces the uAPI for getting the number of address spaces supported by this vDPA device. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vhost/vdpa.c | 3 +++ include/uapi/linux/vhost.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 7a8a99cef8a4..733b305c5029 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -542,6 +542,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, r = copy_to_user(argp, &v->vdpa->ngroups, sizeof(v->vdpa->ngroups)); break; + case VHOST_VDPA_GET_AS_NUM: + r = copy_to_user(argp, &v->vdpa->nas, sizeof(v->vdpa->nas)); + break; case VHOST_SET_LOG_BASE: case VHOST_SET_LOG_FD: r = -ENOIOCTLCMD; diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index 8a4e6e426bbf..8762911a3cb8 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -148,4 +148,6 @@ /* Get the number of virtqueue groups. */ #define VHOST_VDPA_GET_GROUP_NUM _IOR(VHOST_VIRTIO, 0x79, unsigned int) +/* Get the number of address spaces. */ +#define VHOST_VDPA_GET_AS_NUM _IOR(VHOST_VIRTIO, 0x7A, unsigned int) #endif From patchwork Thu Feb 24 21:22:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759282 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75443C433EF for ; Thu, 24 Feb 2022 21:27:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234865AbiBXV2S (ORCPT ); Thu, 24 Feb 2022 16:28:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234887AbiBXV2L (ORCPT ); Thu, 24 Feb 2022 16:28:11 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2054.outbound.protection.outlook.com [40.107.237.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D33B364BCD; Thu, 24 Feb 2022 13:27:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f6HVdpO7amZsvwjH0Ui6YhA9Y0eM/0NW/6+AVFQGIo+7WSQ9JDuuX+nKBZ7FnD6hWuIVPImii2Frmkkfm+bjILUyjIIfuccuNpi9x2V0yrsuk9LqJzPl8Pra2/7K5BYXCdy+4k2x6dHhKGV0BrwoAK7UEhWS5NOZxv5R+JkMF/w6iB6ntn828F38plqLUupyUgb3sR/cEyKqTDf/jsM4GGEwO45ouGd4TO+2Tk/uD3Nw4mEGlskxgyq/6UPEGuWgt23eNL2piyN/T/FtgUYk8DjYhwCjYCDGBWUx3mVCx7ZeArztaiqpi/VGUwyhrR8+XTIQ/tit/0iFQCeUVCiNFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AWSs2PlHjRSaymxGXJYemewGkO5sA2C9iaN9CMO6kCY=; b=d+MBXE0Y23E1mZxpzigYNKGYgRw/QoUy3jMCNrJ3o1LwK7jVQslCy+0ofauXl2XqwtyWIUpgrrU6nJFVQ0rpyyo0jIc2Z/4fppZLWqB7mzba/TUVSR3WMmacDc8l+X78Z94Lvq+Mhs40mdxSoJyk5HRf+aPJ5hUOphFBUgx/1xPvWm3HjOxh4RnSa8LyqUlS+jP0lxa0wqqmkZr6fmPP+XqSWeSILn/LzLc07oeW5snJNPqjbBigLyLqvTSZfxQInXqZ/3E73BsHoA9Mfa3JczYS4bFOSbm0L4+blOSwt/u5fsm+GG0/xi3DxVQ2Bi7CG2xCImXjJE3Cir7nOx25Gw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AWSs2PlHjRSaymxGXJYemewGkO5sA2C9iaN9CMO6kCY=; b=A+DXOltVtClFTUzsfXF/8Utlea6A0hTfNPO1t4gDjSGyEyEkeKy6iLcVOPFIhlq53mLLr39RnqxAUpRFRiJ9FJJo1aP3M24wmbYkigeGfmuWkVzjM8QqRATUI8PrMe2wXO8KKx2o5mWxuhrdRVGqiLAwO4ugBd3DwLt9y4ZTCFQ= Received: from DM6PR05CA0049.namprd05.prod.outlook.com (2603:10b6:5:335::18) by MN2PR02MB6830.namprd02.prod.outlook.com (2603:10b6:208:1d4::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24; Thu, 24 Feb 2022 21:27:30 +0000 Received: from DM3NAM02FT052.eop-nam02.prod.protection.outlook.com (2603:10b6:5:335:cafe::82) by DM6PR05CA0049.outlook.office365.com (2603:10b6:5:335::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.9 via Frontend Transport; Thu, 24 Feb 2022 21:27:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT052.mail.protection.outlook.com (10.13.5.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:27:29 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:27:29 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:27:29 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLe4-00095B-Od; Thu, 24 Feb 2022 13:27:29 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 13/19] vhost-vdpa: uAPI to get virtqueue group id Date: Fri, 25 Feb 2022 02:52:53 +0530 Message-ID: <20220224212314.1326-14-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 215f0a5e-6af4-4274-8287-08d9f7dc7646 X-MS-TrafficTypeDiagnostic: MN2PR02MB6830:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 46rdDkqNZjTLpa0bz/WtkYLlu7rgoaEjP0IUtBTq1+gf6YdffY63eI5Zw96Lqh7FvHUNNyXfggiUKvtZMWseAO8gXBeRDMf9SAEGfgQV4QuQubTueICfFOq27/WA9HZsaKA3/qlnxyrB5fp4h3dTJx4TixeKDon0nJzRgV7W0n/TSGtfzPEkHc8nmzryumWWbpJov1IoALSrSSTzJFFm7bIWkQtF1z7i7PGOrxGl+kWMEw32puEutgB80CPElJywfk6wfSaKhH+ra0eOENMhI8w6eJTUnlv91qckZpNylfh9qWZUseZFwwOgEycLL4LgvgtubVFAOi/NjprBMRLMJh7irYfX9amd8sbITlz2pdljW3elH9KoPxy+35uqzqQOPprBcYqxIlLxgwHSBhmdtNEsRA+B45P8DQfWJfLzYs/HwrmeyTFWw0N2gtw49rHDAwc0kKhvnZRHtjVOrK2DONn4KsKFJjilRdh7onb6I1P8cIggMAw9juVL0UbSSBHEpLreBcg0CdmKmEkKiWh5P+rXb7o0lLKZ889fvHkfFSCqixntxHOTl5Nlf3o6KxeIsCSr+pVJ7SQvSUTpbZbiyptLUnlWeJ5PHIZMEl42gzkE6ypGTf7ijtsxHzxRTS3MCfoxF2IOLtRqrm5xrw5tBx4FiVnS2ZchhHP4jKZBkenIo2yLpt6zxznGFnJQe3rwvTCL5bbvINfhsm3BOTz8EDqRc6dWIY3Xji5cQVjqxxA= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(2906002)(4326008)(7696005)(508600001)(316002)(54906003)(47076005)(36860700001)(186003)(26005)(83380400001)(36756003)(336012)(426003)(7636003)(109986005)(2616005)(82310400004)(356005)(9786002)(5660300002)(6666004)(8936002)(8676002)(70206006)(40460700003)(1076003)(44832011)(7416002)(70586007)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:27:29.7896 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 215f0a5e-6af4-4274-8287-08d9f7dc7646 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT052.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR02MB6830 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Follows the support for virtqueue group in vDPA. This patches introduces uAPI to get the virtqueue group ID for a specific virtqueue in vhost-vdpa. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vhost/vdpa.c | 8 ++++++++ include/uapi/linux/vhost.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 733b305c5029..cfe57f0871a3 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -444,6 +444,14 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, return -EFAULT; ops->set_vq_ready(vdpa, idx, s.num); return 0; + case VHOST_VDPA_GET_VRING_GROUP: + s.index = idx; + s.num = ops->get_vq_group(vdpa, idx); + if (s.num >= vdpa->ngroups) + return -EIO; + else if (copy_to_user(argp, &s, sizeof(s))) + return -EFAULT; + return 0; case VHOST_GET_VRING_BASE: r = ops->get_vq_state(v->vdpa, idx, &vq_state); if (r) diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index 8762911a3cb8..99de06476fdc 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -150,4 +150,12 @@ /* Get the number of address spaces. */ #define VHOST_VDPA_GET_AS_NUM _IOR(VHOST_VIRTIO, 0x7A, unsigned int) + +/* Get the group for a virtqueue: read index, write group in num, + * The virtqueue index is stored in the index field of + * vhost_vring_state. The group for this specific virtqueue is + * returned via num field of vhost_vring_state. + */ +#define VHOST_VDPA_GET_VRING_GROUP _IOWR(VHOST_VIRTIO, 0x7B, \ + struct vhost_vring_state) #endif From patchwork Thu Feb 24 21:22:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759283 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AF77C433FE for ; Thu, 24 Feb 2022 21:28:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234831AbiBXV23 (ORCPT ); Thu, 24 Feb 2022 16:28:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232412AbiBXV2W (ORCPT ); Thu, 24 Feb 2022 16:28:22 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2079.outbound.protection.outlook.com [40.107.94.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 561D6182BC3; Thu, 24 Feb 2022 13:27:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lW1VXrTVz5Q2pMKevvJnWTIdJlJW1i8Fu/feN9Iy48+npgaFJoZA8IgDPlGKRhQDp9bOogAGpTUVf3h2e2fx54dtMQzzCIbzRHcy/+QPJ127u9dCgTmy+/IkBl6VFQ3jwiUvixmZw/lvPrhhIwKcN+E95jZPwPvBSRwJ1P2LOQe36g9HR0N6v8DD9Sk0c6J288nTZ1KL0MjmvkNhOUwgA63ZJkn1EaBllHuOcVXRaXk0n1BnGqw3AOUnqUNmLfXO/vBwWiiUaUMFEYd26v1BOTD5QFYZpoaMF54APv+jXdiNXKfILsAtbXVhGC5YGdtjCBuJnS+KEsVnKKLtGdBXYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Pw8FQn1Tmtp9i5XvFpIl2yHLN1b26+LA4Z57YTRCt9E=; b=GN32XL7hi/HfNsDUvO/GyOzB4nMy8AmAUSGTadlSRl9yNbxBSYIk6pLn5TiQ55P7DWEDMPfJFHi5Hmy7pkfs4BpMQm4y12ZXALKfM3F2dBs7SJKWZ4nnzu5o+1HgUgETUTJpLZ6gsx4Lj9AODaGEV86Y2lRnvQXxfo2nYQmYJ7wjJax9OcBOO4L8EHhCucvij4NBtqxrzA7bwplyIITAdl/SrgJ6C6+YAhWkVMkxdyeqcYt3+FDUsyCcVz6APgVEwP8xEFjMlvfuqx0BwyH8CxOmka9GUbC4uOFd+Vkmyw5y7mTM5WJigfYREKpa0HFlA00qO4IjTSr4CO/PZNB9iA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Pw8FQn1Tmtp9i5XvFpIl2yHLN1b26+LA4Z57YTRCt9E=; b=Abu3d8kBqEDIJQXXkzfu69+w1teUPUmcg+uv3D3dXJ51xUrTzirkeKSCTUZRy85LeJ4ISrg1ERaG+nmXP/KIwb6pQPhX2h581sPzHVGLqbl1tTTCPOPjSAKFwZ1TEaIEQmIdL/KpcJyqXEFjCxPsPrDW5ZcFsYbkLc1yKs0roA0= Received: from DM5PR07CA0077.namprd07.prod.outlook.com (2603:10b6:4:ad::42) by MN2PR02MB6208.namprd02.prod.outlook.com (2603:10b6:208:1bd::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.24; Thu, 24 Feb 2022 21:27:49 +0000 Received: from DM3NAM02FT021.eop-nam02.prod.protection.outlook.com (2603:10b6:4:ad:cafe::d0) by DM5PR07CA0077.outlook.office365.com (2603:10b6:4:ad::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21 via Frontend Transport; Thu, 24 Feb 2022 21:27:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT021.mail.protection.outlook.com (10.13.4.249) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:27:48 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:27:48 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:27:48 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLeN-00095B-Kn; Thu, 24 Feb 2022 13:27:48 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 14/19] vhost-vdpa: introduce uAPI to set group ASID Date: Fri, 25 Feb 2022 02:52:54 +0530 Message-ID: <20220224212314.1326-15-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 60add338-7f7e-44cc-13a8-08d9f7dc819b X-MS-TrafficTypeDiagnostic: MN2PR02MB6208:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r6/cs664NclWU+5fMkMi9ZAJHFAolAfEMwX9oPAp7w2bUHhyuyur/Qz+MH9VsVbOqKMQE1/U8ch6mbCrXddZx6DuZVG7Fb2B0elo/Q5HBZYsjpNQQCTzO2YO4QoMo3GNQA8OqUq06rNpxFkKwdeCCUyjUlRRdxfjNeRAiyJX5pI4pVVxVOBBG59RQh16lBOoNkwJ76KTbT9HGsre55uvCL+FkI1ckN8HHhBGBRowMhCUZuQqZuhDK7DP6ZshdfoJp8d6L6G8OJp9ElvkcL2o/UqcsNKAnbQmGgA59U8GWanJ8jikEcYG6s5lF6cSBrB6a0yK308Klfa9vWm6ifwVVi8F/ruWDde3LIlGtrTzD5Yvyt5Jnja3OBDSd0jfRXicZVqJXqrgDKqpLEU5/mON7fTnixmRMaBR0LcTEda+Yuj4CbeWmrtm3SzEQ9sLcs5dNsf+bd1zysR5+LdL6O70MpNcE+mxuAYEd4KyOE1PpqUt1AZKpFqXSoh7FUFRXORsQ66iufOPK0ycIvPDAjkiE/R80lrvy1V30U5fUqHss1J8knFkPySkj7f6v4MH4WIkCTYAUcGd/SoGhIKSwwGgJ2tx1bqqcKHojF/X/uVNQ/e9Q+sAg5Cu9qWbM/1TaVnCqcj6rW4QGn+BreH/MfmoYtphUToiEuuMU4QZ/0CneGq8hcjpmPotHE5golSp6uTXYvxER/419IgQfb97jmUB+YeWxsecuqs59EZ7DA+K34Y= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(8936002)(82310400004)(7636003)(47076005)(426003)(36860700001)(2906002)(7696005)(1076003)(508600001)(4326008)(8676002)(316002)(336012)(26005)(54906003)(44832011)(356005)(109986005)(5660300002)(6666004)(70206006)(70586007)(9786002)(186003)(40460700003)(7416002)(83380400001)(36756003)(2616005)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:27:48.7988 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 60add338-7f7e-44cc-13a8-08d9f7dc819b X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT021.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR02MB6208 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Follows the vDPA support for associating ASID to a specific virtqueue group. This patch adds a uAPI to support setting them from userspace. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vhost/vdpa.c | 8 ++++++++ include/uapi/linux/vhost.h | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index cfe57f0871a3..47e6cf9d0881 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -452,6 +452,14 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, else if (copy_to_user(argp, &s, sizeof(s))) return -EFAULT; return 0; + case VHOST_VDPA_SET_GROUP_ASID: + if (copy_from_user(&s, argp, sizeof(s))) + return -EFAULT; + if (s.num >= vdpa->nas) + return -EINVAL; + if (!ops->set_group_asid) + return -EOPNOTSUPP; + return ops->set_group_asid(vdpa, idx, s.num); case VHOST_GET_VRING_BASE: r = ops->get_vq_state(v->vdpa, idx, &vq_state); if (r) diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index 99de06476fdc..5e083490f1aa 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -158,4 +158,11 @@ */ #define VHOST_VDPA_GET_VRING_GROUP _IOWR(VHOST_VIRTIO, 0x7B, \ struct vhost_vring_state) +/* Set the ASID for a virtqueue group. The group index is stored in + * the index field of vhost_vring_state, the ASID associated with this + * group is stored at num field of vhost_vring_state. + */ +#define VHOST_VDPA_SET_GROUP_ASID _IOW(VHOST_VIRTIO, 0x7C, \ + struct vhost_vring_state) + #endif From patchwork Thu Feb 24 21:22:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAE65C433EF for ; Thu, 24 Feb 2022 21:28:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234941AbiBXV3I (ORCPT ); Thu, 24 Feb 2022 16:29:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234954AbiBXV3F (ORCPT ); Thu, 24 Feb 2022 16:29:05 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2079.outbound.protection.outlook.com [40.107.93.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A6A5194141; Thu, 24 Feb 2022 13:28:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OWoU7YgngngYKEFAdDiEcnszNxZuzJ8jki1o5XDW+hjuaHcO8i14O2kPmKfIw2Vpscxq7tV81cbVDoUI0wyfxdpkJZaAqWrIgAdR/OdvJGEIDSBjqDcKklm658gVqQ66Non/1KAGehJWSsPN6GEmVrk5/TsxN+VQUeK2/fiersXTcgFty2B5GCSkLLysbgpjCzYixxU9e+FnE7ev+DeUEGRkfjfBS5KvQ3SzwlMLljaGBvHCyfkV/Pq902tYaGux/PrigNwb0ugSlV7ooVwaiXhGG1ixIUeHKHwxwyeTnBv1nPIogb1cEu3nU+JK3WIWOoZViVHrXwXTTM6wBcVMYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RDOtvSYes+zTVSAOjNScVRZ3HXTsTpcTNqEChmm9M88=; b=WyCrzS1TD1K1i4zauiMsrkQOy9eMD72B3vClNdeH+thg2iaUObeQGFF+BGzz57XOx36DZE6feIFXBxQR3jrmakPu3ZsKQ2h7Cnn791JoXsc/eYFA3qXLQ41RLXFiKxSLZHfmzS4Obb6vKTy/E+KRduM/1H4SfKkoW229nCKvMGWTnSjBap6fkK83WnkP1LrwxXnSlfiM1qX+oAQx93qTo/RfoQXMN4LGisWSDQD967QfhwfG/5BN+t0pcmFUmlNJzaTmVYGnqQSCvGSrXSI1mRRPvVVhU0Hx6hIXJubYneyo7si+kz7dN8pSHxFaX7v1g/w7V+dp+w759FuZA8srwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RDOtvSYes+zTVSAOjNScVRZ3HXTsTpcTNqEChmm9M88=; b=st5SqH9jlxUYxZPqJSuZTNYNOvO4ZInZlmogcZEGTljUBoMYhplR4/xcQU0vst4j4//jZ7lMYY5AlF9NQbiToxfVizO/C1XlD+ivqOcaxfwlC5irgcYLd1y8OwkIoNp4dpQGvXeWgQVOkjkeADfvDSIxWiCJzaaffBg8/Qedrl8= Received: from DM5PR07CA0043.namprd07.prod.outlook.com (2603:10b6:3:16::29) by MWHPR02MB2464.namprd02.prod.outlook.com (2603:10b6:300:42::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 21:28:15 +0000 Received: from DM3NAM02FT049.eop-nam02.prod.protection.outlook.com (2603:10b6:3:16:cafe::d7) by DM5PR07CA0043.outlook.office365.com (2603:10b6:3:16::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:28:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT049.mail.protection.outlook.com (10.13.5.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:28:15 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:28:07 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:28:07 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLeg-00095B-HB; Thu, 24 Feb 2022 13:28:07 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 15/19] vhost-vdpa: support ASID based IOTLB API Date: Fri, 25 Feb 2022 02:52:55 +0530 Message-ID: <20220224212314.1326-16-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 22ea36e4-cf4c-4e2e-dbb7-08d9f7dc913f X-MS-TrafficTypeDiagnostic: MWHPR02MB2464:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YWEU/PrlzDRx/eeMV5X8QxDpb5uqMikmY3wRTeiZAjVZZBJ2W8X0WTWMDfTHGpjKbFGQz3ds6jBSPLJgRHiz1t5FSB7VelNRchCW7aDRFu4ElFVl1wcKGW1wChH3XtbRy6E8MRh3O9naq81/Y5qnXgYnMgyU6SR8Nqdjh1EVPkqakd8uCUwhf09HV/CW4MvxJmzfVOBx48V96Xu6g8m3kbtPrwASlEnj32qjOlonhDFMdFXSvIVVjZBDAggNLvRdhWoifYWerNm4XyCL/qQnNA1qU8UKjKoQRKSgxG5+GuPu3ZY51jDPg6gZvKTSXOgPKphYo5W+0io1fQhwqkmJ2ATaVovHqX2EqWOXsXVo5iyZlHbhhzl5e/pFvHfEbybiTuCIp2jCqE0z+LSMFqA5y23KcEr7daHXD9s2KRj2jre0jPVA5cxsYrUc4KjQZD2u1AXMNWaMfFbSe5QJOpsfOVR5vW6HuGDxSOWXUtXBoJ6myNTNSfM2Rshj2/DpCGh7+mmFxSB3pQgTe0DT0DmKdbHJbHMcHleC8F2pqRnFQVmI2lgT/X4X6NRcU+NbeYvhrzwjDmTiNnqRelBMsRQjW+52d0Xwqh/WTsfKU8/ZVdm6rNXylokG8HMPxFcGmFL8LideocEo0EIoXZTkL5qBOOjqIWv9uptGqMXNyvHpE55s6p1AtEEbA/h6Q04CjGouS7jrEJjC8jQb3XTja7bq2EEGD8Mfcg/eO7whdpV49gE= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(44832011)(8936002)(9786002)(70586007)(70206006)(316002)(7416002)(54906003)(5660300002)(4326008)(356005)(7636003)(8676002)(82310400004)(7696005)(6666004)(40460700003)(83380400001)(109986005)(2616005)(1076003)(426003)(508600001)(336012)(26005)(47076005)(2906002)(36860700001)(186003)(36756003)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:28:15.0445 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22ea36e4-cf4c-4e2e-dbb7-08d9f7dc913f X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT049.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR02MB2464 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch extends the vhost-vdpa to support ASID based IOTLB API. The vhost-vdpa device will allocated multiple IOTLBs for vDPA device that supports multiple address spaces. The IOTLBs and vDPA device memory mappings is determined and maintained through ASID. Note that we still don't support vDPA device with more than one address spaces that depends on platform IOMMU. This work will be done by moving the IOMMU logic from vhost-vDPA to vDPA device driver. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vhost/vdpa.c | 129 ++++++++++++++++++++++++++++++++---------- drivers/vhost/vhost.c | 2 +- 2 files changed, 100 insertions(+), 31 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 47e6cf9d0881..4bcf824e3b12 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -28,7 +28,8 @@ enum { VHOST_VDPA_BACKEND_FEATURES = (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2) | - (1ULL << VHOST_BACKEND_F_IOTLB_BATCH), + (1ULL << VHOST_BACKEND_F_IOTLB_BATCH) | + (1ULL << VHOST_BACKEND_F_IOTLB_ASID), }; #define VHOST_VDPA_DEV_MAX (1U << MINORBITS) @@ -57,13 +58,20 @@ struct vhost_vdpa { struct eventfd_ctx *config_ctx; int in_batch; struct vdpa_iova_range range; - int used_as; + u32 batch_asid; }; static DEFINE_IDA(vhost_vdpa_ida); static dev_t vhost_vdpa_major; +static inline u32 iotlb_to_asid(struct vhost_iotlb *iotlb) +{ + struct vhost_vdpa_as *as = container_of(iotlb, struct + vhost_vdpa_as, iotlb); + return as->id; +} + static struct vhost_vdpa_as *asid_to_as(struct vhost_vdpa *v, u32 asid) { struct hlist_head *head = &v->as[asid % VHOST_VDPA_IOTLB_BUCKETS]; @@ -76,6 +84,16 @@ static struct vhost_vdpa_as *asid_to_as(struct vhost_vdpa *v, u32 asid) return NULL; } +static struct vhost_iotlb *asid_to_iotlb(struct vhost_vdpa *v, u32 asid) +{ + struct vhost_vdpa_as *as = asid_to_as(v, asid); + + if (!as) + return NULL; + + return &as->iotlb; +} + static struct vhost_vdpa_as *vhost_vdpa_alloc_as(struct vhost_vdpa *v, u32 asid) { struct hlist_head *head = &v->as[asid % VHOST_VDPA_IOTLB_BUCKETS]; @@ -84,6 +102,9 @@ static struct vhost_vdpa_as *vhost_vdpa_alloc_as(struct vhost_vdpa *v, u32 asid) if (asid_to_as(v, asid)) return NULL; + if (asid >= v->vdpa->nas) + return NULL; + as = kmalloc(sizeof(*as), GFP_KERNEL); if (!as) return NULL; @@ -91,18 +112,24 @@ static struct vhost_vdpa_as *vhost_vdpa_alloc_as(struct vhost_vdpa *v, u32 asid) vhost_iotlb_init(&as->iotlb, 0, 0); as->id = asid; hlist_add_head(&as->hash_link, head); - ++v->used_as; return as; } -static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid) +static struct vhost_vdpa_as *vhost_vdpa_find_alloc_as(struct vhost_vdpa *v, + u32 asid) { struct vhost_vdpa_as *as = asid_to_as(v, asid); - /* Remove default address space is not allowed */ - if (asid == 0) - return -EINVAL; + if (as) + return as; + + return vhost_vdpa_alloc_as(v, asid); +} + +static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid) +{ + struct vhost_vdpa_as *as = asid_to_as(v, asid); if (!as) return -EINVAL; @@ -110,7 +137,6 @@ static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid) hlist_del(&as->hash_link); vhost_iotlb_reset(&as->iotlb); kfree(as); - --v->used_as; return 0; } @@ -665,6 +691,7 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, struct vhost_dev *dev = &v->vdev; struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; + u32 asid = iotlb_to_asid(iotlb); int r = 0; r = vhost_iotlb_add_range_ctx(iotlb, iova, iova + size - 1, @@ -673,10 +700,10 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, return r; if (ops->dma_map) { - r = ops->dma_map(vdpa, 0, iova, size, pa, perm, opaque); + r = ops->dma_map(vdpa, asid, iova, size, pa, perm, opaque); } else if (ops->set_map) { if (!v->in_batch) - r = ops->set_map(vdpa, 0, iotlb); + r = ops->set_map(vdpa, asid, iotlb); } else { r = iommu_map(v->domain, iova, pa, size, perm_to_iommu_flags(perm)); @@ -692,23 +719,35 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, return 0; } -static void vhost_vdpa_unmap(struct vhost_vdpa *v, - struct vhost_iotlb *iotlb, - u64 iova, u64 size) +static int vhost_vdpa_unmap(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, + u64 iova, u64 size) { struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; + u32 asid = iotlb_to_asid(iotlb); + + if (!iotlb) + return -EINVAL; vhost_vdpa_iotlb_unmap(v, iotlb, iova, iova + size - 1); if (ops->dma_map) { - ops->dma_unmap(vdpa, 0, iova, size); + ops->dma_unmap(vdpa, asid, iova, size); } else if (ops->set_map) { if (!v->in_batch) - ops->set_map(vdpa, 0, iotlb); + ops->set_map(vdpa, asid, iotlb); } else { iommu_unmap(v->domain, iova, size); } + + /* If we are in the middle of batch processing, delay the free + * of AS until BATCH_END. + */ + if (!v->in_batch && !iotlb->nmaps) + vhost_vdpa_remove_as(v, asid); + + return 0; } static int vhost_vdpa_va_map(struct vhost_vdpa *v, @@ -916,33 +955,55 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid, struct vhost_vdpa *v = container_of(dev, struct vhost_vdpa, vdev); struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; - struct vhost_vdpa_as *as = asid_to_as(v, 0); - struct vhost_iotlb *iotlb = &as->iotlb; + struct vhost_iotlb *iotlb = NULL; + struct vhost_vdpa_as *as = NULL; int r = 0; mutex_lock(&dev->mutex); - if (asid != 0) - return -EINVAL; - r = vhost_dev_check_owner(dev); if (r) goto unlock; + if (msg->type == VHOST_IOTLB_UPDATE || + msg->type == VHOST_IOTLB_BATCH_BEGIN) { + as = vhost_vdpa_find_alloc_as(v, asid); + if (!as) { + dev_err(&v->dev, "can't find and alloc asid %d\n", + asid); + return -EINVAL; + } + iotlb = &as->iotlb; + } else + iotlb = asid_to_iotlb(v, asid); + + if ((v->in_batch && v->batch_asid != asid) || !iotlb) { + if (v->in_batch && v->batch_asid != asid) { + dev_info(&v->dev, "batch id %d asid %d\n", + v->batch_asid, asid); + } + if (!iotlb) + dev_err(&v->dev, "no iotlb for asid %d\n", asid); + return -EINVAL; + } + switch (msg->type) { case VHOST_IOTLB_UPDATE: r = vhost_vdpa_process_iotlb_update(v, iotlb, msg); break; case VHOST_IOTLB_INVALIDATE: - vhost_vdpa_unmap(v, iotlb, msg->iova, msg->size); + r = vhost_vdpa_unmap(v, iotlb, msg->iova, msg->size); break; case VHOST_IOTLB_BATCH_BEGIN: + v->batch_asid = asid; v->in_batch = true; break; case VHOST_IOTLB_BATCH_END: if (v->in_batch && ops->set_map) - ops->set_map(vdpa, 0, iotlb); + ops->set_map(vdpa, asid, iotlb); v->in_batch = false; + if (!iotlb->nmaps) + vhost_vdpa_remove_as(v, asid); break; default: r = -EINVAL; @@ -1030,9 +1091,17 @@ static void vhost_vdpa_set_iova_range(struct vhost_vdpa *v) static void vhost_vdpa_cleanup(struct vhost_vdpa *v) { + struct vhost_vdpa_as *as; + u32 asid; + vhost_dev_cleanup(&v->vdev); kfree(v->vdev.vqs); - vhost_vdpa_remove_as(v, 0); + + for (asid = 0; asid < v->vdpa->nas; asid++) { + as = asid_to_as(v, asid); + if (as) + vhost_vdpa_remove_as(v, asid); + } } static int vhost_vdpa_open(struct inode *inode, struct file *filep) @@ -1067,12 +1136,9 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) vhost_dev_init(dev, vqs, nvqs, 0, 0, 0, false, vhost_vdpa_process_iotlb_msg); - if (!vhost_vdpa_alloc_as(v, 0)) - goto err_alloc_as; - r = vhost_vdpa_alloc_domain(v); if (r) - goto err_alloc_as; + goto err_alloc_domain; vhost_vdpa_set_iova_range(v); @@ -1080,7 +1146,7 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) return 0; -err_alloc_as: +err_alloc_domain: vhost_vdpa_cleanup(v); err: atomic_dec(&v->opened); @@ -1205,8 +1271,11 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa) int minor; int i, r; - /* Only support 1 address space and 1 groups */ - if (vdpa->ngroups != 1 || vdpa->nas != 1) + /* We can't support platform IOMMU device with more than 1 + * group or as + */ + if (!ops->set_map && !ops->dma_map && + (vdpa->ngroups > 1 || vdpa->nas > 1)) return -EOPNOTSUPP; v = kzalloc(sizeof(*v), GFP_KERNEL | __GFP_RETRY_MAYFAIL); diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 1f514d98f0de..92eeb684c84d 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -1167,7 +1167,7 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, ret = -EINVAL; goto done; } - offset = sizeof(__u16); + offset = 0; } else offset = sizeof(__u32); break; From patchwork Thu Feb 24 21:22:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759284 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40A48C433FE for ; Thu, 24 Feb 2022 21:28:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234876AbiBXV3B (ORCPT ); Thu, 24 Feb 2022 16:29:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234565AbiBXV3A (ORCPT ); Thu, 24 Feb 2022 16:29:00 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2074.outbound.protection.outlook.com [40.107.94.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31CA9190B43; Thu, 24 Feb 2022 13:28:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HCb5rJthZbIAxErIeI2ptOYuEyRGbBi9iaOQqbO58Fvp5OPqu/WSV4kJU+IdVaHdPfERpreBAHpjCe2AHutmfJp7nVJw6d0581nkbcVA3hhWlkOsLwqa6u2QAtMjwGu+73zzX+0sb16d8V6U1YZ9Lh9ixW3lHSH5/on/HezVrAm5hQjQEurOQeD8rg6Q/WpJollS+S4Rr1qDxkqCPpyVE5pWAAwO1mjgw9CK/6f6fTBotEgDKbSYIgKrIoHALBc/+JrCNrSj18KPD/U8KLH36VuyfiC8uIXcKFmABMMlVmgCPuTYhlKJxfzmpwJrpTqgX+w4L1lGQpM1OIF8xNGzMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dggSplGGDZO0vUuyz9yCOEXlnVMwK3uzZ3/hX6LuJoE=; b=H2tLPoU5dqlJisc+VwAfzj+kU315LssLq+bZoHHpK+WO+Yj3jFc38bZC/Ho4ZWlVxS2VwTFfdSMaHKdJBY0PxiuG4q9c10q4y5osm02GgbMwvTCc7U8TXDsfUnONvuxVSBQ3QsTSNpKzs1O25Nx5GSl3FJSUG75GMNYy8tQDRg4B+RFrldnJhGvvIukjVQjeYXWClHGETD0o1zcFYeMnHO1M3XMfejaF1LkE/3Jvrz73dWbl4vAXtDeE4AbD8hBf5EbHIqxL2xJ12VkECpSJT6z2b32hdSJYOmSZp0Fon/M45HlhGcLgbuZ4Uo7kQYPK8gdYXB8mAu/YVPy+fI251A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dggSplGGDZO0vUuyz9yCOEXlnVMwK3uzZ3/hX6LuJoE=; b=ICWuiIWwIUOyvw4iWsP57aoIpTqcO8Kj0TgqS7SIT02BVYYmvxpsaGvL+kdayA1AFWOGamn54H9/fLxmKzRNh9He+gtogJiq2uR0BUqTDrXUAhI5KRPw8qD5IOWopq8N95zl94bFBXdiBd3V+2sY8aMMmK0OyHi9RMd6d+wpom8= Received: from DS7PR06CA0054.namprd06.prod.outlook.com (2603:10b6:8:54::34) by BL0PR02MB4276.namprd02.prod.outlook.com (2603:10b6:208:46::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 21:28:28 +0000 Received: from DM3NAM02FT031.eop-nam02.prod.protection.outlook.com (2603:10b6:8:54:cafe::15) by DS7PR06CA0054.outlook.office365.com (2603:10b6:8:54::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23 via Frontend Transport; Thu, 24 Feb 2022 21:28:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT031.mail.protection.outlook.com (10.13.4.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:28:27 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:28:27 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:28:27 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLf0-00095B-JZ; Thu, 24 Feb 2022 13:28:27 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 16/19] vdpa_sim: advertise VIRTIO_NET_F_MTU Date: Fri, 25 Feb 2022 02:52:56 +0530 Message-ID: <20220224212314.1326-17-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e09f82f1-321c-4f0c-c699-08d9f7dc98d4 X-MS-TrafficTypeDiagnostic: BL0PR02MB4276:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O+xajR0OTZvyW9qDp3UNIawqoV9HE2fFCg3wvpn5EnsNBs1GFqWKaY3+cuXUATku4DP0Rbm8XT5JN1+GuD6Zd1Z4+tXXCx8P33PVKTC5woLKDgxIPJogDg6b8soNxXo1FPWcnZb56bhxC+KtlpUFIlCal3xrF/I2NsPDU9/F+fpckW98U9O876IKWB6h9+yfS9IeqE0FaunDpSAwZzGlpaD8w83Jjhzvh3MjtMK4VOQH2eUX5XSm0LlpzCm8hBm2CY08eQaueH7m2Vv8Rds7MoxvbML40rM+mGejWhjEcENKrald2lDTlCdtoG5lUzL26Iv1tQE12v7PV0KzDr+valelZUiSB7t+BMVEORR/VjxcUgamJabPsbHsPZd1TN/SpjfJpuSqGoarnC3e03pFkgmlKNxuHNCD9p6HLCmjCm7DM4EIWqqlA26aCFWs0NgozBaNOhitaxBmupOtCGU6I2ifOvvNJxOo1vibd5h46bLLnjwXmJC5M9yWMJtl7RicvjCbewvYDmHhJreT0ylfpLD0M4IQbl3uKKEoO9/rCBkPncMykb/KNGupYr1XI9d4JlBj4LsGvr4DAorsnzchbqXUGjY0s044+TMoe4sdfa2lfCS7k43BqpTDbCTFDQR/ycWTPm0IBghIOpKqdOKf8fs2qv9L3qLVz22m1awKmfkMpTdZXv5lvDcAPSBQ2aTvkAXtWu4L7NgKvBf6HReVKA== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(8936002)(7416002)(316002)(4744005)(9786002)(70586007)(2906002)(70206006)(54906003)(8676002)(508600001)(26005)(5660300002)(83380400001)(82310400004)(6666004)(7696005)(36756003)(2616005)(1076003)(7636003)(336012)(186003)(426003)(44832011)(4326008)(356005)(109986005)(36860700001)(47076005)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:28:27.7489 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e09f82f1-321c-4f0c-c699-08d9f7dc98d4 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT031.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB4276 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We've already reported maximum mtu via config space, so let's advertise the feature. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c index d5324f6fd8c7..ff22cc56f40b 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -26,7 +26,8 @@ #define DRV_LICENSE "GPL v2" #define VDPASIM_NET_FEATURES (VDPASIM_FEATURES | \ - (1ULL << VIRTIO_NET_F_MAC)) + (1ULL << VIRTIO_NET_F_MAC) | \ + (1ULL << VIRTIO_NET_F_MTU)); #define VDPASIM_NET_VQ_NUM 2 From patchwork Thu Feb 24 21:22:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759292 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86754C433FE for ; Thu, 24 Feb 2022 21:29:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234867AbiBXV3x (ORCPT ); Thu, 24 Feb 2022 16:29:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232129AbiBXV3s (ORCPT ); Thu, 24 Feb 2022 16:29:48 -0500 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam07on2051.outbound.protection.outlook.com [40.107.95.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2B6D1A8054; Thu, 24 Feb 2022 13:29:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BebUuaRHxd4EeADd6QI8HIpxEDA5NMbpw/HVgE5QbOR1pfI1Mwl5oSDnYfl7TICDo9s22NYKuwpCwFe9mUqmj82V7pljhnPOa+XhkFfqno956ZPn4c24t73hObAbd5FPNIXdP0WQNyBcjsy8f35/3ZnhjuNDHZxKWhk8R+YnXHUwANCMD3WZFWHpdVqiJvD+CuBopddA0yXaGtOo4sB8hjTnYxgZpwb0A1ukmarAVBVqZ5xvLUSlDNvgGey+y+b96yQKK4opZCJy/Jf5JPpckOiIZ/kX2zBcwAzANohcLS+Cg+uRZTvFzEeL+/ZxbV3MEud5pPwHVZykaUwGLleyrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZG5lz7A209qwT9pKY34E8+DEFd4STbJrexWdlQRfO/8=; b=NCreAmai5suiT6mEsy2/u0laF+ogCF2h4SDooY12uEJgE+zIXuAJqexcSaOat+MG0Xo/STBow1pUop2Yv4+gdeALuOfkrIHD4kZB+pjEFZrfT6vlvQDn7g+Z9kqiEf8W6yeRXWJ11Ko+R9SWsgW81jcE9Kpe8nqLSt6qWtTh+60dB/xH6xXxUNBWL9B7ons1w7hJmSS8uSk48/nZdQgpNaVQveZ0JzaFyoI1HvKZC57Fo6LrN/snB4xVIboPIUqg4sZKPRNeB0zrKS1gnu0vENVIaKh2CAy1Y1GFmbya/9wFoOK5CIj0MR4FZujdCrFgLF94voFgHrlvxoQZg6oq3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZG5lz7A209qwT9pKY34E8+DEFd4STbJrexWdlQRfO/8=; b=fcLKEgy9tBsF4aZt/d9YqrxDc+6l7C8DGMsQBnnJ4VO0ZHUYRv8GQHBc42RpibNsx0zvDisFHJv60qGqctuawUj1oGKfkyzo/BmxGsQhIfPVB7/yIm+Q8c2gwYuq+A+3h0kYx5AV6+bi/M6hcqYp4NwLnyg0kWtXri1kxos9XLo= Received: from DS7PR05CA0038.namprd05.prod.outlook.com (2603:10b6:8:2f::23) by BN7PR02MB4146.namprd02.prod.outlook.com (2603:10b6:406:f2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Thu, 24 Feb 2022 21:29:01 +0000 Received: from DM3NAM02FT050.eop-nam02.prod.protection.outlook.com (2603:10b6:8:2f:cafe::9c) by DS7PR05CA0038.outlook.office365.com (2603:10b6:8:2f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.9 via Frontend Transport; Thu, 24 Feb 2022 21:29:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT050.mail.protection.outlook.com (10.13.5.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:29:01 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:28:45 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:28:45 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLfJ-00095B-C9; Thu, 24 Feb 2022 13:28:45 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 17/19] vdpa_sim: factor out buffer completion logic Date: Fri, 25 Feb 2022 02:52:57 +0530 Message-ID: <20220224212314.1326-18-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 504567af-61d0-457c-b15a-08d9f7dcacb7 X-MS-TrafficTypeDiagnostic: BN7PR02MB4146:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hkRym34rLuRB1TSNNLoBw/CoHyfYEPnBekGcrMDgEiANxsa7cPGeHQh73hhqSZ6NRIVBMupdlKmRBNra5QsYn4lWfva2jiOqDf+nFHP75FQCwppCCCgUcEbLI9e09Un7gS8umCq2ph8MOHhMWG6vI5dj7wtUS9pcxcIkqgiWOTyG7a8VehvGe/b8ldzTerjmDab2G3AkkfVegjvI/dp5NUUUydx1W6vlXQbRtCzf2c0L+M6hAIAyNOqkuKFz+Rsz1U3tlOOw92R376vblgYGr4xS7VxeNmzfByIXkCZH2+fD2Dv3IC3xv5ZrOTd8gX2PsefGTpOmOUoNzAiw3/E06UiXzSK7GgABWMdDQ/uaACdPNP5pkroVQaf8QnhUT9FlRZSqDdfsGvkuU3wYe/NMdEXXOOOeDgJdP1xtv+Q64oBtJQ8DfRq5RFIAs//MRNJt0NB3911I/b0A1Z35tdIxhYBMV5F530hVYi9qpru0EiTQB+aDzb4BkmNOiQ3cFP8X3QdBI8w+Bd6j8FKnezOlw1Z2E/fpsWjx+mVL9RvVqz4bua/q9n8z0svThWP0CsQDRfu7futy0HIv15jCEKkeUbjFx7+SLhfrT2psvYDJXMMf/5YEV/JE+uzVyTJHbwoQJN2X9que7VHyAmT6dylZpP1uSEcjkG2udlk87pXTu7okpxH46X0br1W7BcR+n5nyH42gWc5g2SPAriYGBwVwJw== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(7416002)(47076005)(4326008)(8676002)(82310400004)(8936002)(5660300002)(508600001)(7636003)(54906003)(356005)(1076003)(2616005)(9786002)(70586007)(36756003)(70206006)(7696005)(316002)(26005)(186003)(6666004)(83380400001)(2906002)(36860700001)(336012)(426003)(44832011)(109986005)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:29:01.1283 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 504567af-61d0-457c-b15a-08d9f7dcacb7 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT050.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR02MB4146 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Wrap up common buffer completion logic in to vdpasim_net_complete Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 33 +++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c index ff22cc56f40b..05d552cb7f94 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -31,6 +31,22 @@ #define VDPASIM_NET_VQ_NUM 2 +static void vdpasim_net_complete(struct vdpasim_virtqueue *vq, size_t len) +{ + /* Make sure data is wrote before advancing index */ + smp_wmb(); + + vringh_complete_iotlb(&vq->vring, vq->head, len); + + /* Make sure used is visible before rasing the interrupt. */ + smp_wmb(); + + local_bh_disable(); + if (vringh_need_notify_iotlb(&vq->vring) > 0) + vringh_notify(&vq->vring); + local_bh_enable(); +} + static void vdpasim_net_work(struct work_struct *work) { struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); @@ -78,21 +94,8 @@ static void vdpasim_net_work(struct work_struct *work) total_write += write; } - /* Make sure data is wrote before advancing index */ - smp_wmb(); - - vringh_complete_iotlb(&txq->vring, txq->head, 0); - vringh_complete_iotlb(&rxq->vring, rxq->head, total_write); - - /* Make sure used is visible before rasing the interrupt. */ - smp_wmb(); - - local_bh_disable(); - if (vringh_need_notify_iotlb(&txq->vring) > 0) - vringh_notify(&txq->vring); - if (vringh_need_notify_iotlb(&rxq->vring) > 0) - vringh_notify(&rxq->vring); - local_bh_enable(); + vdpasim_net_complete(txq, 0); + vdpasim_net_complete(rxq, total_write); if (++pkts > 4) { schedule_work(&vdpasim->work); From patchwork Thu Feb 24 21:22:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D12EC4332F for ; Thu, 24 Feb 2022 21:29:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234971AbiBXVaS (ORCPT ); Thu, 24 Feb 2022 16:30:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234972AbiBXVaN (ORCPT ); Thu, 24 Feb 2022 16:30:13 -0500 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam07on2085.outbound.protection.outlook.com [40.107.95.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2627D1BE4EF; Thu, 24 Feb 2022 13:29:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AqQ1CJLNGCYwaNNrochh1LbK2KCcSph99+93axdMjXcmgtVUnU7vZzayqW0vMldHdsxsoWl+XbNDiUFPo/Mp8AALc5Xr/Rgg1YP5ImZ8jwE52oiOkzTOCbyPP6ra2lt6alzn1uTSujN70rcPoAWT2lzzlBfjozrs+H6JZCmdOOiBAfjnOANV5+UWWEvX7AdxYRkwebBSGoFgR4B0OhOLz2FxzolDC3NCpV+Rbjz5GzS9o75AFZ5agi4QpsHRGyo40SPHKptjEpVL+F6npGdvxZi5RV19eUFEPDt0fV5XoZuG3sBSZOuPOzon0h09EP1PBjANfAAbGxrjoU7Hiq1kJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WknOEB46P6HUrolnkHi7vdGXd7mgQc+akfqSibPSMt8=; b=Mc7jTe2gU3oEbo1mLrRtkbWQaXCnFJRe3AKZW54by0xF/XI4gKJdr+ySKZR8zUU/g/0M0vk7wfcIPEXy2k4vQEaP7MGZ6HtTX0dZykn2e/nD8oAhJRKNakzwx09DnoGzXi3MERnpbiqlUXIl65hp3F1xH+fs1S8o1YyI31Fz8NkesDVYP3y5lycOIJNEQJa4TQN15fwBn8iufiIH2Nv9ASa6agB2gcuKI58MpEWKtvXcknEwuFz2eai2dIS010k1haKi+6QjOi0TCxgqPpg/9y4rRoKvOXuEDCHOUBk452OVOF9lnJ92WWHdFhZkhvBncLswUQDhvDx4+9npxcIFGQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WknOEB46P6HUrolnkHi7vdGXd7mgQc+akfqSibPSMt8=; b=p7UqLyAt3dB9zNdPJVuHJn8luahTjKq0cwcL89GT9U3WuyUzR1ma+Ht5KSFtl0V4KQJOF/7y90i4b5d/VyHF+1E/FBtOb8L5rD4y3o6CMGsB1nI+OupVSgIud2hYB3LgxL+V4gz7czHE5jbPLNXjMUt4SSI/bZctr+/DHDTXz/k= Received: from DM6PR02CA0164.namprd02.prod.outlook.com (2603:10b6:5:332::31) by MWHPR02MB2864.namprd02.prod.outlook.com (2603:10b6:300:108::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24; Thu, 24 Feb 2022 21:29:18 +0000 Received: from DM3NAM02FT028.eop-nam02.prod.protection.outlook.com (2603:10b6:5:332:cafe::30) by DM6PR02CA0164.outlook.office365.com (2603:10b6:5:332::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21 via Frontend Transport; Thu, 24 Feb 2022 21:29:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT028.mail.protection.outlook.com (10.13.4.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:29:18 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:29:04 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:29:04 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLfc-00095B-7l; Thu, 24 Feb 2022 13:29:04 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 18/19] vdpa_sim: filter destination mac address Date: Fri, 25 Feb 2022 02:52:58 +0530 Message-ID: <20220224212314.1326-19-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95ebf148-603b-430c-0b77-08d9f7dcb6f3 X-MS-TrafficTypeDiagnostic: MWHPR02MB2864:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7jkNOtryP3HLO0cDMpDUxuPwk4g6v48ECBbcecC6DCupr9cBo+wF2l4mjQ0CcBNNu4lQZDiOgIPUONPi77T0S0DOTB2o0/c/pfUSDszjdiTnP28cvgsj7OqpUAOCdh2iWngPaJHpH/+XML+Qilz4fzSdjoAL+Cib7AFn8GFq2u+f43ks9gHrEe/aMDU5OuaHPfv6TRdimGkdVU03eX5b/WswUxSD9hH1Z1HJPGatdbr645X3cwlPFrDbZJVCmobHgiu6aVyMbMeBVelHIODk8wWyZ0dJR0UQ2t+wZnoJJA0TtIbaxBNbeo0v7NgDsnbMfSRU9DaX7Q/aTOcKLgGv3mo5rHtAOrAlUhZ40J0uk/y5lJJnRRL3h230KZ6IV8NCsKebMVQXyMM4JjPlvDNlZMzLTGT+qf0jlmVU9oNdeHWPOU073+yNYuVDaK3RNQFNy9Dx8jBOiHgZdqruxFa3m6pCiHhaeAsyFkobTqlB0tF7gxOB6QZVxhg6WKj9wZ8a5l8tQo3pyCR0gu473su+oFeeai1QEQHWYgctZ3q7NxGCX9+riC7i/l0bi6Qzw/X5kqgz7XrsDGYYdDBWxfyxLt0h1sZXWSrTx6owztlkbSaus/daonTjweAo2VK3Mc4cyMRGwqJbhmwVh79DAdUVPmYdPSHbh3XiZaPKJq7y92xWbsqi0kzs9NvjNPfGLcUWcFd1T00CCxaA8rtzbpE+4SfzkdUjWXXNrc2ugtfZzJk= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(356005)(6666004)(7636003)(44832011)(7696005)(9786002)(2906002)(186003)(40460700003)(26005)(8936002)(109986005)(54906003)(47076005)(336012)(8676002)(83380400001)(82310400004)(2616005)(508600001)(70586007)(70206006)(4326008)(316002)(1076003)(7416002)(36860700001)(36756003)(5660300002)(426003)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:29:18.3101 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95ebf148-603b-430c-0b77-08d9f7dcb6f3 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT028.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR02MB2864 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch implements a simple unicast filter for vDPA simulator. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 49 ++++++++++++++++++---------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c index 05d552cb7f94..ed5ade4ae570 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -47,13 +47,28 @@ static void vdpasim_net_complete(struct vdpasim_virtqueue *vq, size_t len) local_bh_enable(); } +static bool receive_filter(struct vdpasim *vdpasim, size_t len) +{ + bool modern = vdpasim->features & (1ULL << VIRTIO_F_VERSION_1); + size_t hdr_len = modern ? sizeof(struct virtio_net_hdr_v1) : + sizeof(struct virtio_net_hdr); + + if (len < ETH_ALEN + hdr_len) + return false; + + if (!strncmp(vdpasim->buffer + hdr_len, + vdpasim->config.mac, ETH_ALEN)) + return true; + + return false; +} + static void vdpasim_net_work(struct work_struct *work) { struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); struct vdpasim_virtqueue *txq = &vdpasim->vqs[1]; struct vdpasim_virtqueue *rxq = &vdpasim->vqs[0]; ssize_t read, write; - size_t total_write; int pkts = 0; int err; @@ -66,36 +81,34 @@ static void vdpasim_net_work(struct work_struct *work) goto out; while (true) { - total_write = 0; err = vringh_getdesc_iotlb(&txq->vring, &txq->out_iov, NULL, &txq->head, GFP_ATOMIC); if (err <= 0) break; + read = vringh_iov_pull_iotlb(&txq->vring, &txq->out_iov, + vdpasim->buffer, + PAGE_SIZE); + + if (!receive_filter(vdpasim, read)) { + vdpasim_complete(txq, 0); + continue; + } + err = vringh_getdesc_iotlb(&rxq->vring, NULL, &rxq->in_iov, &rxq->head, GFP_ATOMIC); if (err <= 0) { - vringh_complete_iotlb(&txq->vring, txq->head, 0); + vdpasim_net_complete(txq, 0); break; } - while (true) { - read = vringh_iov_pull_iotlb(&txq->vring, &txq->out_iov, - vdpasim->buffer, - PAGE_SIZE); - if (read <= 0) - break; - - write = vringh_iov_push_iotlb(&rxq->vring, &rxq->in_iov, - vdpasim->buffer, read); - if (write <= 0) - break; - - total_write += write; - } + write = vringh_iov_push_iotlb(&rxq->vring, &rxq->in_iov, + vdpasim->buffer, read); + if (write <= 0) + break; vdpasim_net_complete(txq, 0); - vdpasim_net_complete(rxq, total_write); + vdpasim_net_complete(rxq, write); if (++pkts > 4) { schedule_work(&vdpasim->work); From patchwork Thu Feb 24 21:22:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 12759294 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F35D0C433EF for ; Thu, 24 Feb 2022 21:30:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234370AbiBXVae (ORCPT ); Thu, 24 Feb 2022 16:30:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234989AbiBXVa1 (ORCPT ); Thu, 24 Feb 2022 16:30:27 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2080.outbound.protection.outlook.com [40.107.94.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A596E1B30B8; Thu, 24 Feb 2022 13:29:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iEZlCCSQ/7wT3omznt9fwGXYS+9pEmZtzqEC9z4rMxtMdDCSLvnmcYjDt/6kTWsgN3uNwRxB/wLnM6hmCedD6pAtkV0GDDdyoUDazBoVjSoyrxVGJm9Jd10Dps+uFV/VlU+D3a+NXagyumrpWKhB6OmlavuGpSZF9XPMHzX3XIikoo6kHktAghZ42aQrgaol7NCpnq7JEuPhCZHHQO5fqR8lduOwhz2YI5pTLDCS2eEukCFGbUPXz3WLE7nnLyNQWBRPrfZt7JdlSoQhAiS46CE4Egrq5xYjxjgk/l1pFFl+/dIgs0IE9xyc1lqOwbaH+02DXbY/KqqwR2uJ+lfPkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nIVAkmyMu4D/7/q8D7dw9fdXaLEsq0oBEh5MIbgJahw=; b=W9TMlgBTN/7KrYWr0VVuz22FhCk5vmTQtAEykCYdiCKsBKO4D61Xh+Xvi8dmuKNW+dR3fRl1lAWXQ4uw9xiaF8AQlKrPawVFE3Wm8eQ1LdNdKZ5E76vmd8tvciZ4cZxqgi6O2kmOwlYdz5+N8ZlJAFnm2fHrXhfkicw/G/OWImDvewI4dwV4CU7r9mOORICGVzNrzGpGYGKB1ETa6WQ2EiBB2nPK2z7I17YVlNYLOhhkCMO2xcC1oSrI1XcPJRuKWAVZ2AnbjkZLvNs6Cd0viW4phEff0hfkC5M8KVdJntq50rqCYizngPy6I2++6VlkCGsmv4ORX3MyPWNr4Msq6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nIVAkmyMu4D/7/q8D7dw9fdXaLEsq0oBEh5MIbgJahw=; b=XLgc9LOeD4C/bxn9YrsTuhUlfVUUR8UNTWhJ8yIZbwFuc5q69t5fe3NrwCLsxA+EewmAGE0c2Ddhzrc2z33zeJhv4Shv7f1e2tGjPZtQ1r+6Dnz5oEByNJzqNQHpNvtngeDRJvGtvYSoQp9qgtZmhjik0yCDJH6C4L1jaTXcqdk= Received: from DS7PR05CA0032.namprd05.prod.outlook.com (2603:10b6:8:2f::31) by BYAPR02MB4519.namprd02.prod.outlook.com (2603:10b6:a03:59::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23; Thu, 24 Feb 2022 21:29:41 +0000 Received: from DM3NAM02FT050.eop-nam02.prod.protection.outlook.com (2603:10b6:8:2f:cafe::55) by DS7PR05CA0032.outlook.office365.com (2603:10b6:8:2f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.9 via Frontend Transport; Thu, 24 Feb 2022 21:29:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT050.mail.protection.outlook.com (10.13.5.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 21:29:41 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 24 Feb 2022 13:29:23 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 24 Feb 2022 13:29:23 -0800 Envelope-to: eperezma@redhat.com, jasowang@redhat.com, mst@redhat.com, lingshan.zhu@intel.com, sgarzare@redhat.com, xieyongji@bytedance.com, elic@nvidia.com, si-wei.liu@oracle.com, parav@nvidia.com, longpeng2@huawei.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Received: from [10.170.66.102] (port=59620 helo=xndengvm004102.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nNLfv-00095B-48; Thu, 24 Feb 2022 13:29:23 -0800 From: Gautam Dawar CC: , , , , , Jason Wang , "Michael S. Tsirkin" , Zhu Lingshan , Stefano Garzarella , Xie Yongji , Eli Cohen , Si-Wei Liu , Parav Pandit , Longpeng , , , , Subject: [RFC PATCH v2 19/19] vdpasim: control virtqueue support Date: Fri, 25 Feb 2022 02:52:59 +0530 Message-ID: <20220224212314.1326-20-gdawar@xilinx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20220224212314.1326-1-gdawar@xilinx.com> References: <20201216064818.48239-1-jasowang@redhat.com> <20220224212314.1326-1-gdawar@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8be1b091-5f7b-48ef-2e7b-08d9f7dcc491 X-MS-TrafficTypeDiagnostic: BYAPR02MB4519:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0f6fbxVPZBhaGEavcLR8ANCAoYtqmYt49LKfWN0LjWkpskwTQmbIzeia8dopJ8XSmxxNMPUyL/CgJwFmn14D4RKtzetK/+soUOI8XUc3wCfW9exfa92IXhlTR//89VR01UbXvnElsSqloHd6xEKuiGebtQmxjJYtQtUnwNqC3N54Whbjp/NrxVamir3LwN6UdANVSn5pjHUGfJWBeyvKnwFLqqAiQxqnNMax+KV6vsCZxO9Kh7Bmz36WFnJLZtt+6GHb1E3xGUVN1DDq5SWNUAIPX7b2sb/QMQbim7PLI8mc7A0q/K5iWwFBgBXY4cCQJAFaQs+SGhMMJgGOXF/VPYWlTSQ21sLtvDZHt9x+Uo5Ze1T2JCmWxKwS2p7fRBkBJCAd/ZaBy7CwfCEm/MQ9tj7dELDHNMdF6kPIWuFVPcmIsWNYXxTy7EOTQ9dt0SxtboA7dwAGk4dnE6Jlk4+dtyw/x0UcR9pYYOr3G6FrkmkDaLR1jxmNNKCkne4oT9JwzlM8x8CiHH9EKhK8DY6HpRzWYePGGk7ZVQLmPCJbZH2TewY5m+ZEWMh0FS+PTT5M8AnZfNsdYvm0iPmxezD+exOip+TwbiwvdbdKSajqp9/B/aFG51ojgO3SsKklQK2wIzjNxcn/P21cAUEYtddkJrRZmbPak5oC4CdA9kMHMcJEF3dN40vf/AVeOhRRTafoVkLcMAWfGWImrHmSLuYzCA== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(5660300002)(8936002)(508600001)(7416002)(6666004)(9786002)(109986005)(7696005)(316002)(54906003)(8676002)(2906002)(1076003)(4326008)(356005)(7636003)(36756003)(186003)(26005)(2616005)(70586007)(70206006)(336012)(426003)(36860700001)(47076005)(30864003)(83380400001)(82310400004)(44832011)(102446001)(266003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 21:29:41.1413 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8be1b091-5f7b-48ef-2e7b-08d9f7dcc491 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT050.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR02MB4519 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch introduces the control virtqueue support for vDPA simulator. This is a requirement for supporting advanced features like multiqueue. A requirement for control virtqueue is to isolate its memory access from the rx/tx virtqueues. This is because when using vDPA device for VM, the control virqueue is not directly assigned to VM. Userspace (Qemu) will present a shadow control virtqueue to control for recording the device states. The isolation is done via the virtqueue groups and ASID support in vDPA through vhost-vdpa. The simulator is extended to have: 1) three virtqueues: RXVQ, TXVQ and CVQ (control virtqueue) 2) two virtqueue groups: group 0 contains RXVQ and TXVQ; group 1 contains CVQ 3) two address spaces and the simulator simply implements the address spaces by mapping it 1:1 to IOTLB. For the VM use cases, userspace(Qemu) may set AS 0 to group 0 and AS 1 to group 1. So we have: 1) The IOTLB for virtqueue group 0 contains the mappings of guest, so RX and TX can be assigned to guest directly. 2) The IOTLB for virtqueue group 1 contains the mappings of CVQ which is the buffers that allocated and managed by VMM only. So CVQ of vhost-vdpa is visible to VMM only. And Guest can not access the CVQ of vhost-vdpa. For the other use cases, since AS 0 is associated to all virtqueue groups by default. All virtqueues share the same mapping by default. To demonstrate the function, VIRITO_NET_F_CTRL_MACADDR is implemented in the simulator for the driver to set mac address. Signed-off-by: Jason Wang Signed-off-by: Gautam Dawar --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 91 ++++++++++++++++++++++------ drivers/vdpa/vdpa_sim/vdpa_sim.h | 2 + drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 88 ++++++++++++++++++++++++++- 3 files changed, 161 insertions(+), 20 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index 659e2e2e4b0c..59611f18a3a8 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -96,11 +96,17 @@ static void vdpasim_do_reset(struct vdpasim *vdpasim) { int i; - for (i = 0; i < vdpasim->dev_attr.nvqs; i++) + spin_lock(&vdpasim->iommu_lock); + + for (i = 0; i < vdpasim->dev_attr.nvqs; i++) { vdpasim_vq_reset(vdpasim, &vdpasim->vqs[i]); + vringh_set_iotlb(&vdpasim->vqs[i].vring, &vdpasim->iommu[0], + &vdpasim->iommu_lock); + } + + for (i = 0; i < vdpasim->dev_attr.nas; i++) + vhost_iotlb_reset(&vdpasim->iommu[i]); - spin_lock(&vdpasim->iommu_lock); - vhost_iotlb_reset(vdpasim->iommu); spin_unlock(&vdpasim->iommu_lock); vdpasim->features = 0; @@ -145,7 +151,7 @@ static dma_addr_t vdpasim_map_range(struct vdpasim *vdpasim, phys_addr_t paddr, dma_addr = iova_dma_addr(&vdpasim->iova, iova); spin_lock(&vdpasim->iommu_lock); - ret = vhost_iotlb_add_range(vdpasim->iommu, (u64)dma_addr, + ret = vhost_iotlb_add_range(&vdpasim->iommu[0], (u64)dma_addr, (u64)dma_addr + size - 1, (u64)paddr, perm); spin_unlock(&vdpasim->iommu_lock); @@ -161,7 +167,7 @@ static void vdpasim_unmap_range(struct vdpasim *vdpasim, dma_addr_t dma_addr, size_t size) { spin_lock(&vdpasim->iommu_lock); - vhost_iotlb_del_range(vdpasim->iommu, (u64)dma_addr, + vhost_iotlb_del_range(&vdpasim->iommu[0], (u64)dma_addr, (u64)dma_addr + size - 1); spin_unlock(&vdpasim->iommu_lock); @@ -250,8 +256,9 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) else ops = &vdpasim_config_ops; - vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, 1, - 1, dev_attr->name, false); + vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, + dev_attr->ngroups, dev_attr->nas, + dev_attr->name, false); if (IS_ERR(vdpasim)) { ret = PTR_ERR(vdpasim); goto err_alloc; @@ -278,16 +285,20 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) if (!vdpasim->vqs) goto err_iommu; - vdpasim->iommu = vhost_iotlb_alloc(max_iotlb_entries, 0); + vdpasim->iommu = kmalloc_array(vdpasim->dev_attr.nas, + sizeof(*vdpasim->iommu), GFP_KERNEL); if (!vdpasim->iommu) goto err_iommu; + for (i = 0; i < vdpasim->dev_attr.nas; i++) + vhost_iotlb_init(&vdpasim->iommu[i], 0, 0); + vdpasim->buffer = kvmalloc(dev_attr->buffer_size, GFP_KERNEL); if (!vdpasim->buffer) goto err_iommu; for (i = 0; i < dev_attr->nvqs; i++) - vringh_set_iotlb(&vdpasim->vqs[i].vring, vdpasim->iommu, + vringh_set_iotlb(&vdpasim->vqs[i].vring, &vdpasim->iommu[0], &vdpasim->iommu_lock); ret = iova_cache_get(); @@ -401,7 +412,11 @@ static u32 vdpasim_get_vq_align(struct vdpa_device *vdpa) static u32 vdpasim_get_vq_group(struct vdpa_device *vdpa, u16 idx) { - return 0; + /* RX and TX belongs to group 0, CVQ belongs to group 1 */ + if (idx == 2) + return 1; + else + return 0; } static u64 vdpasim_get_device_features(struct vdpa_device *vdpa) @@ -539,20 +554,53 @@ static struct vdpa_iova_range vdpasim_get_iova_range(struct vdpa_device *vdpa) return range; } +static int vdpasim_set_group_asid(struct vdpa_device *vdpa, unsigned int group, + unsigned int asid) +{ + struct vdpasim *vdpasim = vdpa_to_sim(vdpa); + struct vhost_iotlb *iommu; + int i; + + if (group > vdpasim->dev_attr.ngroups) + return -EINVAL; + + if (asid > vdpasim->dev_attr.nas) + return -EINVAL; + + iommu = &vdpasim->iommu[asid]; + + spin_lock(&vdpasim->lock); + + for (i = 0; i < vdpasim->dev_attr.nvqs; i++) + if (vdpasim_get_vq_group(vdpa, i) == group) + vringh_set_iotlb(&vdpasim->vqs[i].vring, &vdpasim->iommu[0], + &vdpasim->iommu_lock); + + spin_unlock(&vdpasim->lock); + + return 0; +} + static int vdpasim_set_map(struct vdpa_device *vdpa, unsigned int asid, struct vhost_iotlb *iotlb) { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); struct vhost_iotlb_map *map; + struct vhost_iotlb *iommu; u64 start = 0ULL, last = 0ULL - 1; int ret; + if (asid >= vdpasim->dev_attr.nas) + return -EINVAL; + spin_lock(&vdpasim->iommu_lock); - vhost_iotlb_reset(vdpasim->iommu); + + iommu = &vdpasim->iommu[asid]; + vhost_iotlb_reset(iommu); for (map = vhost_iotlb_itree_first(iotlb, start, last); map; map = vhost_iotlb_itree_next(map, start, last)) { - ret = vhost_iotlb_add_range(vdpasim->iommu, map->start, + ret = vhost_iotlb_add_range(iommu, map->start, map->last, map->addr, map->perm); if (ret) goto err; @@ -561,7 +609,7 @@ static int vdpasim_set_map(struct vdpa_device *vdpa, unsigned int asid, return 0; err: - vhost_iotlb_reset(vdpasim->iommu); + vhost_iotlb_reset(iommu); spin_unlock(&vdpasim->iommu_lock); return ret; } @@ -573,9 +621,12 @@ static int vdpasim_dma_map(struct vdpa_device *vdpa, unsigned int asid, struct vdpasim *vdpasim = vdpa_to_sim(vdpa); int ret; + if (asid >= vdpasim->dev_attr.nas) + return -EINVAL; + spin_lock(&vdpasim->iommu_lock); - ret = vhost_iotlb_add_range_ctx(vdpasim->iommu, iova, iova + size - 1, - pa, perm, opaque); + ret = vhost_iotlb_add_range_ctx(&vdpasim->iommu[asid], iova, + iova + size - 1, pa, perm, opaque); spin_unlock(&vdpasim->iommu_lock); return ret; @@ -586,8 +637,11 @@ static int vdpasim_dma_unmap(struct vdpa_device *vdpa, unsigned int asid, { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); + if (asid >= vdpasim->dev_attr.nas) + return -EINVAL; + spin_lock(&vdpasim->iommu_lock); - vhost_iotlb_del_range(vdpasim->iommu, iova, iova + size - 1); + vhost_iotlb_del_range(&vdpasim->iommu[asid], iova, iova + size - 1); spin_unlock(&vdpasim->iommu_lock); return 0; @@ -611,8 +665,7 @@ static void vdpasim_free(struct vdpa_device *vdpa) } kvfree(vdpasim->buffer); - if (vdpasim->iommu) - vhost_iotlb_free(vdpasim->iommu); + vhost_iotlb_free(vdpasim->iommu); kfree(vdpasim->vqs); kfree(vdpasim->config); } @@ -643,6 +696,7 @@ static const struct vdpa_config_ops vdpasim_config_ops = { .set_config = vdpasim_set_config, .get_generation = vdpasim_get_generation, .get_iova_range = vdpasim_get_iova_range, + .set_group_asid = vdpasim_set_group_asid, .dma_map = vdpasim_dma_map, .dma_unmap = vdpasim_dma_unmap, .free = vdpasim_free, @@ -674,6 +728,7 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = { .set_config = vdpasim_set_config, .get_generation = vdpasim_get_generation, .get_iova_range = vdpasim_get_iova_range, + .set_group_asid = vdpasim_set_group_asid, .set_map = vdpasim_set_map, .free = vdpasim_free, }; diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h index 0be7c1e7ef80..622782e92239 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -41,6 +41,8 @@ struct vdpasim_dev_attr { size_t buffer_size; int nvqs; u32 id; + u32 ngroups; + u32 nas; work_func_t work_fn; void (*get_config)(struct vdpasim *vdpasim, void *config); diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c index ed5ade4ae570..513970c05af2 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -26,10 +26,15 @@ #define DRV_LICENSE "GPL v2" #define VDPASIM_NET_FEATURES (VDPASIM_FEATURES | \ + (1ULL << VIRTIO_NET_F_MTU) | \ (1ULL << VIRTIO_NET_F_MAC) | \ - (1ULL << VIRTIO_NET_F_MTU)); + (1ULL << VIRTIO_NET_F_CTRL_VQ) | \ + (1ULL << VIRTIO_NET_F_CTRL_MAC_ADDR)); -#define VDPASIM_NET_VQ_NUM 2 +/* 3 virtqueues, 2 address spaces, 2 virtqueue groups */ +#define VDPASIM_NET_VQ_NUM 3 +#define VDPASIM_NET_AS_NUM 2 +#define VDPASIM_NET_GROUP_NUM 2 static void vdpasim_net_complete(struct vdpasim_virtqueue *vq, size_t len) { @@ -63,6 +68,81 @@ static bool receive_filter(struct vdpasim *vdpasim, size_t len) return false; } +static virtio_net_ctrl_ack vdpasim_handle_ctrl_mac(struct vdpasim *vdpasim, + u8 cmd) +{ + struct vdpasim_virtqueue *cvq = &vdpasim->vqs[2]; + virtio_net_ctrl_ack status = VIRTIO_NET_ERR; + size_t read; + + switch (cmd) { + case VIRTIO_NET_CTRL_MAC_ADDR_SET: + read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->in_iov, + (void *)vdpasim->config.mac, + ETH_ALEN); + if (read == ETH_ALEN) + status = VIRTIO_NET_OK; + break; + default: + break; + } + + return status; +} + +static void vdpasim_handle_cvq(struct vdpasim *vdpasim) +{ + struct vdpasim_virtqueue *cvq = &vdpasim->vqs[2]; + virtio_net_ctrl_ack status = VIRTIO_NET_ERR; + struct virtio_net_ctrl_hdr ctrl; + size_t read, write; + int err; + + if (!(vdpasim->features & (1ULL << VIRTIO_NET_F_CTRL_VQ))) + return; + + if (!cvq->ready) + return; + + while (true) { + err = vringh_getdesc_iotlb(&cvq->vring, &cvq->in_iov, + &cvq->out_iov, + &cvq->head, GFP_ATOMIC); + if (err <= 0) + break; + + read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->in_iov, &ctrl, + sizeof(ctrl)); + if (read != sizeof(ctrl)) + break; + + switch (ctrl.class) { + case VIRTIO_NET_CTRL_MAC: + status = vdpasim_handle_ctrl_mac(vdpasim, ctrl.cmd); + break; + default: + break; + } + + /* Make sure data is wrote before advancing index */ + smp_wmb(); + + write = vringh_iov_push_iotlb(&cvq->vring, &cvq->out_iov, + &status, sizeof(status)); + vringh_complete_iotlb(&cvq->vring, cvq->head, write); + vringh_kiov_cleanup(&cvq->in_iov); + vringh_kiov_cleanup(&cvq->out_iov); + + /* Make sure used is visible before rasing the interrupt. */ + smp_wmb(); + + local_bh_disable(); + if (cvq->cb) + cvq->cb(cvq->private); + local_bh_enable(); + } +} + static void vdpasim_net_work(struct work_struct *work) { struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); @@ -77,6 +157,8 @@ static void vdpasim_net_work(struct work_struct *work) if (!(vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK)) goto out; + vdpasim_handle_cvq(vdpasim); + if (!txq->ready || !rxq->ready) goto out; @@ -162,6 +244,8 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, dev_attr.id = VIRTIO_ID_NET; dev_attr.supported_features = VDPASIM_NET_FEATURES; dev_attr.nvqs = VDPASIM_NET_VQ_NUM; + dev_attr.ngroups = VDPASIM_NET_GROUP_NUM; + dev_attr.nas = VDPASIM_NET_AS_NUM; dev_attr.config_size = sizeof(struct virtio_net_config); dev_attr.get_config = vdpasim_net_get_config; dev_attr.work_fn = vdpasim_net_work;