From patchwork Mon Aug 5 02:12:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaoyong He X-Patchwork-Id: 142892 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 227234573B; Mon, 5 Aug 2024 04:14:35 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8AEC74066A; Mon, 5 Aug 2024 04:13:33 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2132.outbound.protection.outlook.com [40.107.236.132]) by mails.dpdk.org (Postfix) with ESMTP id B6E9E40658 for ; Mon, 5 Aug 2024 04:13:30 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pumNSJs1U0CXWWr+sC/qsa2P4ippc+V9Dv1PosEkIS3c73qDxbkV0DQvwOklRbR7YKCSg20dZyjb/OTHycNdKgD6Mxa8H52RhYmor91X/BnLR+UUOnBKw+ky1MzI7dnJCBZDLstZv8Kf9ILlW+VRw0PMHiZeSOfrIqJ9gD0o+E/8Y0cwzOCyqRkurhF3wIPw+8WLlo+J00rHDuzlxgapKun74c1zNFcdKWfJTemsre3fsri8PDOSj3tlEosOnN2LKIKUn+V6XwchTY3bp5L3OQ1pXYKHny3Y8WgWi/bDTwDoRnrVPZ/0rtKeykGetEmRA/tP3K4Us5IwRfo3S1QGdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=C0bGOcLpq7ZKLv9eiKhKNm9d8CtC8bJbMMSOk/WeufU=; b=ZRwdkWr42Poj4QOLLhP4OGb71ICMvTjqUccGCjO9ltUo0nVL5LRkEdTsWtG5XuE9RqgH/k6j0swKTlD7OkI79cEKrgk/K8PYnHArXE6TVWT32Hn5tRBpwY7Hho612GI/GL/uxT8ZgBR5lVnJvPMNtD4cavvX8gd8sWC+qK/AqQHGUayS+4HMZhjmwcuTz48TWTunzxtqILHreX96Pbj1LyIyuCgmRJr86gUg7ZO0MnZktBSh6PJNIAzdrcKA9UaZUIHw+tH1nVI0hwS2FwUiuL2fAGdq3fjF6/UlCSlhB+wg9J0R+Z20LPDrIH4pd6hoKNputg0t1TwB523ev1VvHA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C0bGOcLpq7ZKLv9eiKhKNm9d8CtC8bJbMMSOk/WeufU=; b=O9S9hLF8NwuHSGJ1Quhq0a2EH7gyoYL2iI7Ywrb3rvpfQ5f1VcNTF1JERW4ahN+6sPicfWpd98qZSzwZxDoUgg7OJgYaSwZfsVvri5N+ytV02c4zdsXb/uAwGEFslKGTJ4UJal2riuaJgP8DWzE53/vQ29kIRW7iUX+6/PEWflc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by CH2PR13MB3815.namprd13.prod.outlook.com (2603:10b6:610:91::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22; Mon, 5 Aug 2024 02:13:27 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::b900:5f05:766f:833]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::b900:5f05:766f:833%4]) with mapi id 15.20.7828.023; Mon, 5 Aug 2024 02:13:26 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Xinying Yu , Chaoyong He , Long Wu , Peng Zhang , Maxime Coquelin Subject: [PATCH v4 09/11] vdpa/nfp: setup vring relay thread Date: Mon, 5 Aug 2024 10:12:46 +0800 Message-Id: <20240805021248.1051198-10-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240805021248.1051198-1-chaoyong.he@corigine.com> References: <20240617062708.2932037-1-chaoyong.he@corigine.com> <20240805021248.1051198-1-chaoyong.he@corigine.com> X-ClientProxiedBy: BYAPR01CA0050.prod.exchangelabs.com (2603:10b6:a03:94::27) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|CH2PR13MB3815:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a4420e8-5e6f-4086-8d8d-08dcb4f430bb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: /dmalcu1PN0fu2Rt68kN/T3ly22JPvQQK7d+i6QRe3JOug3b9Sw5RGVrmBWBpxE6/M3+ixvWXt98fA0WZ3DzsMITQ7ZIy0mosJ02Fdc+QWs6NcbUxZG1edleCzCrQTj1WJWIG1mp/aQihEPrRins9rUh1NBFtQJaGnOGl/AqRjG9dcHqfcqq9H/F7xvdfF5txjoDQM0d5A+EQ2IScVq5G53BUiujTBBRYlTwBnf+KnsUf3jYv1NAw7l0C9tb5ZQtT/EgvN4IzKK8IccVrjj7zv+up8v8W6vD2qUON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R7F0XNwnXQw9K5OIn1F8L29Pw3jtZTRiEjKI1aVGRjnjlc5vOy4cBUw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(376014)(52116014)(366016)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HA27SLBkqJYq4hJ7cW+NY7P7M9R3smfG6ph97LQYcQkFpFv8RCEi0/DWX6UvvOJkGWVexyU8KTODsKjFioYwl/Q/mHilgduueCmwNAgb9onMSovbpaTEMmW1HyD3VLAYwdYjpFihFnZ5dPZ7T+dWgQRnIbsUzRmsZ8iOD4L/jEBel744+S/dbUrLeCQr7TZxvjU8Nsh9KFpu1GaxXz8D494RiQSk7km7UtDk2sqXyoYkazQhJT35sLmE6nWWafTGuwHhretCd6kEGjV09A9kx0nMv6Q+D8KwwSFM/ZZitk5uOH53Tia7C4P7msDmi1NE7P2ct71ABHeYfJKtCrCHVWYPmeAufKvOHI7qQInDUpG/qnfy0xiJqI0VHxMt2gMYLBQqNgZw6WiQsWiYY83XswDF+q3IpO73DpLETb5lWCGtICD0VmFKjGYkUnhtlcZV9iiZM1yMCRaIDOPGEoq0LPJGYeW8/FCQ895WHLEJZjls7DejAmOynFygbGvxk4b8lLWGQ1Z7ZTHF2L1mrwiFZoJBhFHPIa2Qtymua7rLf7ikiHdqKKGYBzN7udiQ0LzlXQeM3qp7VYiAuJ/JD5AKo2Wj9KkNlmlfPe07mQZkV+N9qAgdYrkbgWQ8zrn2pTHekIyiqJbDdGt55KjSkrdTLr5mO7+vOvX46JSbmC0vFbKou8asluG9GT+VrfHF54WdLxWck3pLhA34DYj+iuI6oFP0RT3p8FWU0Q0F+8lZKIGAj4KLbVRTtNssHv1YX7Pb3gBc8caMFia9vYI3fZ1FphbUZgjV7+htTbR3Cs+f1U6Z79fA6CQpGkPs82fam5Mc7gi9isAI2zmrpuuloQ8gr+EwV01bDmFjPi7tUXNa5VyWKQuC723PYd14ol2N8bjRwYm2d8cwFOl2FcAsNH+4yO1r7dfxtmn6vteQWNKi/xhDTixAWooqp+1UhqvC/QxZy3qQ7NVr4668YbhCddM4isEHftgepvYA2s/WpxBI/gTH+JSeNG4Rf8WELVPypAUaTwmJQplt/huZPvZG5UoAImpGuQMPp7Rh1Nvn04CqPfJ5kGTzYQ26B5oorj9I4uC+xYT+yPJ4rqBoRKhF/mLscgFG2k/r0qZBzld3i7VOdovvmKu3u8VjSzw8+YsvxwR1rAmFUI2Ou8S+ijuONFxh25/3naKMASl7cz6wD3zV+ll9RVA8hHqMABDE07RwjewOJD2hdzFo+cnVmjtG5lgDMPrXIa7CxQbFeRlImBW5KN+rMkYV3Gq98QVXjSV+q975Ahd2LffgtUGiI0ef3mS3iP0YDr8vTtempGSm7c9UcZaKiFI7q8mXzzvKvTtgQvQX7YwR6d3N+qGun3ryTVNRXB64RVktRY+k7qg/WfDmX3wyRninGFIQvbj/BetUweTPR+vfNrZ/CYBt9cy0YFb/jsi4vOFZH2E9IMe/7ieCNOh1yxPThUUd89opx/8iQpSto5neOTrke2rwq4oCtkwSLPeAHs+DXRt6kZ3EOzM7ZStnL9Qz8FFyxEfc4LUkHTJDFxWgfqVv9Jy033BZKX6T7oie1d3MZEwE5L8FDrsCASZoejIln2ZyHzm3zFBykH5WsI7QGx7vcVF+uXNq4Mw4Og== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a4420e8-5e6f-4086-8d8d-08dcb4f430bb X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 02:13:26.5191 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Vk5jHUGL1ujNPeTKT8UxoQuJi32IUL7KUkG55VtQ1B3WFD9gCMWfuVXKnkt1xW9yGO44VIK3kOzo2PmZG0MbZoeOLVdfLjTIrnStblUAPz0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR13MB3815 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Xinying Yu Setup the vring relay thread to monitor the interruption from device. And do the dirty page logging or notify device according to event data. Signed-off-by: Xinying Yu Reviewed-by: Chaoyong He Reviewed-by: Long Wu Reviewed-by: Peng Zhang Reviewed-by: Maxime Coquelin --- drivers/vdpa/nfp/nfp_vdpa.c | 148 +++++++++++++++++++++++++++++++ drivers/vdpa/nfp/nfp_vdpa_core.c | 9 ++ drivers/vdpa/nfp/nfp_vdpa_core.h | 2 + 3 files changed, 159 insertions(+) diff --git a/drivers/vdpa/nfp/nfp_vdpa.c b/drivers/vdpa/nfp/nfp_vdpa.c index 983123ba08..91f1b8d779 100644 --- a/drivers/vdpa/nfp/nfp_vdpa.c +++ b/drivers/vdpa/nfp/nfp_vdpa.c @@ -26,6 +26,8 @@ #define NFP_VDPA_USED_RING_LEN(size) \ ((size) * sizeof(struct vring_used_elem) + sizeof(struct vring_used)) +#define EPOLL_DATA_INTR 1 + struct nfp_vdpa_dev { struct rte_pci_device *pci_dev; struct rte_vdpa_device *vdev; @@ -777,6 +779,139 @@ update_datapath(struct nfp_vdpa_dev *device) return ret; } +static int +nfp_vdpa_vring_epoll_ctl(uint32_t queue_num, + struct nfp_vdpa_dev *device) +{ + int ret; + uint32_t qid; + struct epoll_event ev; + struct rte_vhost_vring vring; + + for (qid = 0; qid < queue_num; qid++) { + ev.events = EPOLLIN | EPOLLPRI; + rte_vhost_get_vhost_vring(device->vid, qid, &vring); + ev.data.u64 = qid << 1 | (uint64_t)vring.kickfd << 32; + ret = epoll_ctl(device->epoll_fd, EPOLL_CTL_ADD, vring.kickfd, &ev); + if (ret < 0) { + DRV_VDPA_LOG(ERR, "Epoll add error for queue %u", qid); + return ret; + } + } + + /* vDPA driver interrupt */ + for (qid = 0; qid < queue_num; qid += 2) { + ev.events = EPOLLIN | EPOLLPRI; + /* Leave a flag to mark it's for interrupt */ + ev.data.u64 = EPOLL_DATA_INTR | qid << 1 | + (uint64_t)device->intr_fd[qid] << 32; + ret = epoll_ctl(device->epoll_fd, EPOLL_CTL_ADD, + device->intr_fd[qid], &ev); + if (ret < 0) { + DRV_VDPA_LOG(ERR, "Epoll add error for queue %u", qid); + return ret; + } + + nfp_vdpa_update_used_ring(device, qid); + } + + return 0; +} + +static int +nfp_vdpa_vring_epoll_wait(uint32_t queue_num, + struct nfp_vdpa_dev *device) +{ + int i; + int fds; + int kickfd; + uint32_t qid; + struct epoll_event events[NFP_VDPA_MAX_QUEUES * 2]; + + for (;;) { + fds = epoll_wait(device->epoll_fd, events, queue_num * 2, -1); + if (fds < 0) { + if (errno == EINTR) + continue; + + DRV_VDPA_LOG(ERR, "Epoll wait fail"); + return -EACCES; + } + + for (i = 0; i < fds; i++) { + qid = events[i].data.u32 >> 1; + kickfd = (uint32_t)(events[i].data.u64 >> 32); + + nfp_vdpa_read_kickfd(kickfd); + if ((events[i].data.u32 & EPOLL_DATA_INTR) != 0) { + nfp_vdpa_update_used_ring(device, qid); + nfp_vdpa_irq_unmask(&device->hw); + } else { + nfp_vdpa_notify_queue(&device->hw, qid); + } + } + } + + return 0; +} + +static uint32_t +nfp_vdpa_vring_relay(void *arg) +{ + int ret; + int epoll_fd; + uint16_t queue_id; + uint32_t queue_num; + struct nfp_vdpa_dev *device = arg; + + epoll_fd = epoll_create(NFP_VDPA_MAX_QUEUES * 2); + if (epoll_fd < 0) { + DRV_VDPA_LOG(ERR, "failed to create epoll instance."); + return 1; + } + + device->epoll_fd = epoll_fd; + + queue_num = rte_vhost_get_vring_num(device->vid); + + ret = nfp_vdpa_vring_epoll_ctl(queue_num, device); + if (ret != 0) + goto notify_exit; + + /* Start relay with a first kick */ + for (queue_id = 0; queue_id < queue_num; queue_id++) + nfp_vdpa_notify_queue(&device->hw, queue_id); + + ret = nfp_vdpa_vring_epoll_wait(queue_num, device); + if (ret != 0) + goto notify_exit; + + return 0; + +notify_exit: + close(device->epoll_fd); + device->epoll_fd = -1; + + return 1; +} + +static int +nfp_vdpa_setup_vring_relay(struct nfp_vdpa_dev *device) +{ + int ret; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; + + snprintf(name, sizeof(name), "nfp_vring%d", device->vid); + ret = rte_thread_create_internal_control(&device->tid, name, + nfp_vdpa_vring_relay, (void *)device); + if (ret != 0) { + DRV_VDPA_LOG(ERR, "Failed to create vring relay pthread."); + return -EPERM; + } + + return 0; +} + static int nfp_vdpa_sw_fallback(struct nfp_vdpa_dev *device) { @@ -803,10 +938,17 @@ nfp_vdpa_sw_fallback(struct nfp_vdpa_dev *device) if (ret != 0) goto unset_intr; + /* Setup vring relay thread */ + ret = nfp_vdpa_setup_vring_relay(device); + if (ret != 0) + goto stop_vf; + device->hw.sw_fallback_running = true; return 0; +stop_vf: + nfp_vdpa_stop(device, true); unset_intr: nfp_vdpa_disable_vfio_intr(device); error: @@ -860,6 +1002,12 @@ nfp_vdpa_dev_close(int vid) /* Reset VF */ nfp_vdpa_stop(device, true); + /* Remove interrupt setting */ + nfp_vdpa_disable_vfio_intr(device); + + /* Unset DMA map for guest memory */ + nfp_vdpa_dma_map(device, false); + device->hw.sw_fallback_running = false; rte_atomic_store_explicit(&device->dev_attached, 0, diff --git a/drivers/vdpa/nfp/nfp_vdpa_core.c b/drivers/vdpa/nfp/nfp_vdpa_core.c index d7c48e2490..3b3481a99c 100644 --- a/drivers/vdpa/nfp/nfp_vdpa_core.c +++ b/drivers/vdpa/nfp/nfp_vdpa_core.c @@ -270,3 +270,12 @@ nfp_vdpa_notify_queue(struct nfp_vdpa_hw *vdpa_hw, nfp_qcp_notify_ptr_add(vdpa_hw->notify_addr[qid], NFP_QCP_NOTIFY_WRITE_PTR, qid); } + +void nfp_vdpa_irq_unmask(struct nfp_vdpa_hw *vdpa_hw) +{ + struct nfp_hw *hw = &vdpa_hw->super; + + /* Make sure all updates are written before un-masking */ + rte_wmb(); + nn_cfg_writeb(hw, NFP_NET_CFG_ICR(1), NFP_NET_CFG_ICR_UNMASKED); +} diff --git a/drivers/vdpa/nfp/nfp_vdpa_core.h b/drivers/vdpa/nfp/nfp_vdpa_core.h index a339ace601..bc4db556a2 100644 --- a/drivers/vdpa/nfp/nfp_vdpa_core.h +++ b/drivers/vdpa/nfp/nfp_vdpa_core.h @@ -60,4 +60,6 @@ void nfp_vdpa_notify_queue(struct nfp_vdpa_hw *vdpa_hw, uint16_t qid); uint64_t nfp_vdpa_get_queue_notify_offset(struct nfp_vdpa_hw *vdpa_hw, int qid); +void nfp_vdpa_irq_unmask(struct nfp_vdpa_hw *vdpa_hw); + #endif /* __NFP_VDPA_CORE_H__ */