From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B2A4C45B09; Thu, 10 Oct 2024 20:21:06 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8E4E5402D7; Thu, 10 Oct 2024 20:21:06 +0200 (CEST) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mails.dpdk.org (Postfix) with ESMTP id 398AA4025D for ; Thu, 10 Oct 2024 20:21:05 +0200 (CEST) Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-656d8b346d2so820798a12.2 for ; Thu, 10 Oct 2024 11:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1728584464; x=1729189264; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=QA2qUE2zLHmYGodir2Dq3I7GjHhRsjm5HlqChpmNXEI=; b=MrHhxtAToDBlmTpaBarwfXKYYQJ7Sr60LoYfgPLRNchFhcFFcUnYJsZfwVG1ihX/kj IE4o9Pa5RkUgA1YPmcz/wj7XYjbaXfwrAun9zrepc8KhW2zSIY3ZwCqs9yDNbrcCitc/ lP++xCq1z0+9Tuj0NXtGccbtJOxHqO8ctGaObawuK000/LvXHnAIe0HrWaT6ijemYrng 9XojSD33edgy4Rl9cI/NsVkXHVqYvsbaUvtVxZ1csBIkcaqnlcFSK+1SHyDE7uPsCPAf M+AtfcV8HEmFNeVtnRGRF1PUkTdrf3rmlpobtFt4yrYtAuAf0Yb0VFKbdFdgqxyIfjYC NYqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728584464; x=1729189264; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QA2qUE2zLHmYGodir2Dq3I7GjHhRsjm5HlqChpmNXEI=; b=QVZp32rWLRyzwRy7s3cKkib10z+Rhv+GiD+TiF/4wg9e/n4M5gLFo6qMoR6tzQ11Ij mjEwdlClxxDK5IHRK3tvutailJ+IzNfS861059Ufcso68tbCwJcYFVYIILBLX5j1v/o0 EI8nHwUDYBkI4KKcY3MICsxToyuk2A1lsGCrWJTONgB1UsIwHhCGOgNnVbUitL0Wci9j TZuvslHp+VVphPYFJRGUrLEddfXNKu3vPDGNW9Q4x8uH7z24T8cCuDXGI9ezjT/7Z390 7OMUE1GRusoCgtfwGZcBvw7xyLEfgf46osWA46zZVPLwYR305DMmVufQP+z+5O+43EX7 7ZFg== X-Forwarded-Encrypted: i=1; AJvYcCXhAlXJLY+omVY9StiTyN7/NFynh7+/B6a6OlG4Pl35LzUgmxrcymsQ6AC6z9imd2QlJJo=@dpdk.org X-Gm-Message-State: AOJu0YyEjm9H2ZMDCbNkikxySSlmMP3FJUq04gfxgOmz66YqiHR8NJc6 rma/FYLVOjgFT1Ug1h717aHXE0ZZqVEAdHa/9Vfhaqcw9O5viVjzgO+7uwm9Tbs= X-Google-Smtp-Source: AGHT+IHltvqMcXz7xNpDoKKFI7kiFKtFACjjkGWIiFwz22OYdLGmUERr5L1tJQEG9rjLyebs6tvuAw== X-Received: by 2002:a05:6a21:9187:b0:1d0:56b1:1c59 with SMTP id adf61e73a8af0-1d8a3c4dbd4mr11945249637.32.1728584464230; Thu, 10 Oct 2024 11:21:04 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7ea448e468asm1313500a12.4.2024.10.10.11.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 11:21:04 -0700 (PDT) Date: Thu, 10 Oct 2024 11:21:02 -0700 From: Stephen Hemminger To: "BillXiang" Cc: "Tyler Retzlaff" , "Anatoly Burakov" , Subject: Re: [PATCH v3] vfio: combine container_create and group_bind Message-ID: <20241010112102.29242cd8@hermes.local> In-Reply-To: <20240703115943.44539-1-xiangwencheng@dayudpu.com> References: <20240703115943.44539-1-xiangwencheng@dayudpu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 On Wed, 3 Jul 2024 19:59:43 +0800 "BillXiang" wrote: > From: BillXiang > > For multi-devices in one group we can only create and bind to one > container. With this new function, device driver does not need to > save the binding info additionally between different devices. > > Signed-off-by: BillXiang Ok, but where is the device driver using it? DPDK upstream doesn't want to keep API's for drivers that are not upstream. > --- > lib/eal/include/rte_vfio.h | 17 +++++++++++++++++ > lib/eal/linux/eal_vfio.c | 24 ++++++++++++++++++++++++ > lib/eal/version.map | 3 +++ > 3 files changed, 44 insertions(+) > > diff --git a/lib/eal/include/rte_vfio.h b/lib/eal/include/rte_vfio.h > index b774625d9f..f6743b3620 100644 > --- a/lib/eal/include/rte_vfio.h > +++ b/lib/eal/include/rte_vfio.h > @@ -407,6 +407,23 @@ int > rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr, > uint64_t iova, uint64_t len); > > +/** > + * Get vfio group fd bound with container fd for certain iommu group. > + * > + * @param iommu_group_num > + * iommu group num > + * @param vfio_group_fd > + * vfio group fd of the iommu group. > + * @param vfio_container_fd > + * vfio container fd of the iommu group. > + * @return > + * 0 if successful > + * <0 if failed > + */ > +__rte_experimental > +int > +rte_vfio_get_fd(int iommu_group_num, int *vfio_group_fd, int *vfio_container_fd); > + > #ifdef __cplusplus > } > #endif > diff --git a/lib/eal/linux/eal_vfio.c b/lib/eal/linux/eal_vfio.c > index 4e69e72e3b..08510df7e2 100644 > --- a/lib/eal/linux/eal_vfio.c > +++ b/lib/eal/linux/eal_vfio.c > @@ -2196,3 +2196,27 @@ rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr, uint64_t iova, > > return container_dma_unmap(vfio_cfg, vaddr, iova, len); > } > + > +int > +rte_vfio_get_fd(int iommu_group_num, int *vfio_group_fd, int *vfio_container_fd) > +{ > + struct vfio_config *vfio_cfg; > + vfio_cfg = get_vfio_cfg_by_group_num(iommu_group_num); > + /* do not create new container if the group has bound with one */ prefer blank line after declaration > + if (vfio_cfg) { > + *vfio_container_fd = vfio_cfg->vfio_container_fd; > + } else { > + *vfio_container_fd = rte_vfio_container_create(); > + if (*vfio_container_fd < 0) > + goto err; If no unwind necessary, then skip the goto and just return -1; > + > + vfio_cfg = get_vfio_cfg_by_container_fd(*vfio_container_fd); > + } > + *vfio_group_fd = vfio_get_group_fd(vfio_cfg, iommu_group_num); > + if (*vfio_group_fd < 0) > + goto err; ditto > + > + return 0; > +err: > + return -1; > +} > diff --git a/lib/eal/version.map b/lib/eal/version.map > index 3df50c3fbb..f26b65a504 100644 > --- a/lib/eal/version.map > +++ b/lib/eal/version.map > @@ -396,6 +396,9 @@ EXPERIMENTAL { > > # added in 24.03 > rte_vfio_get_device_info; # WINDOWS_NO_EXPORT > + > + # added in 24.07 > + rte_vfio_get_fd; # WINDOWS_NO_EXPORT > }; > > INTERNAL {