From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by dpdk.org (Postfix) with ESMTP id 82B471B160 for ; Wed, 13 Feb 2019 10:59:08 +0100 (CET) Received: by mail-wr1-f66.google.com with SMTP id r2so1719333wrv.10 for ; Wed, 13 Feb 2019 01:59:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=tMeuT/0pK31uqBaTV49bZpftbr4tAzol5qWopycCxZc=; b=LSy/Y0VCarlkxGNiPs63kw6jXG2FlexmbU3RXrFHr1MKew8OWdw0cBrN8G20VYOF7+ bIQmyDbDh6hb4uEJSjfyfu5CIjxHfOKAOajy+hkGgEjBZyb+JlZBRB9eRN/Mh1EeoaaD YAZixf0gOuPwmdzUXIsDFtUwS3883FkdiBIgezJZp3rPUcK8f6nuX5zw+rfK1yLV6Grv cIfoOFMMQOVb5taEdeNdpeQXA5ohFyNIp699b+On3OJVYWsLX/k01bhfAcsJvgwBm4me xIPJwAQWIoxwZgrHK/FLA72c41oKHLuqkJCjwvf/Iq0sbERje5pQAmavTLWwofy+wuct U8FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=tMeuT/0pK31uqBaTV49bZpftbr4tAzol5qWopycCxZc=; b=aPvExUFi2ZNiPB4HOlV+LlCeJTsPpDTUgzgD4FQCEywZCGEujF6qGjzc9D8fDidzV1 NZaKRPQl7WCAHxDiXgpFdauHMZY1ESIScML2csf8USG/3sX1BNITTZ62+3LD/aCCp9D2 9VPIP0/T9YY2wT3NweYUtytekjxkuzD+qExCOclZ8zr5uo2jV7qoih/3lqBpHEwkKWk0 T3kKu+klbTzRnpObkA0/VwTfFAAkGWwRiOpEP0buDM7MdKYDcPtr2xfY0rngZQnTKqvw ifghyNJnXk1xKHC87IpWqTeO/BzdO1Kt1kGXNpvL4lsPv8P89dNxqrEJRbrIsE1eeyWu PanA== X-Gm-Message-State: AHQUAua6BAz94oH9+cLWE9vzaINcwSIgcxCrR6SW61C/HbhzI3/bNigs 21afNJmDglooR8ZZwhcHmNXmfg== X-Google-Smtp-Source: AHgI3IZlaY//AxzHhZMf9airxrBp4YSBGqwlFlZju8jSSY+AHlLIXBdS4n4tOg7uoL+qXriDjRpQCw== X-Received: by 2002:a5d:6203:: with SMTP id y3mr5927475wru.137.1550051948053; Wed, 13 Feb 2019 01:59:08 -0800 (PST) Received: from bidouze.vm.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id t4sm16219796wrb.64.2019.02.13.01.59.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Feb 2019 01:59:07 -0800 (PST) Date: Wed, 13 Feb 2019 10:58:46 +0100 From: =?iso-8859-1?Q?Ga=EBtan?= Rivet To: Shahaf Shuler Cc: anatoly.burakov@intel.com, yskoh@mellanox.com, thomas@monjalon.net, ferruh.yigit@intel.com, nhorman@tuxdriver.com, dev@dpdk.org Message-ID: <20190213095846.qn55sx5smlgvxo6h@bidouze.vm.6wind.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [dpdk-dev] [PATCH 2/6] vfio: don't fail to DMA map if memory is already mapped X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Feb 2019 09:59:08 -0000 On Wed, Feb 13, 2019 at 11:10:22AM +0200, Shahaf Shuler wrote: > Currently vfio DMA map function will fail in case the same memory > segment is mapped twice. > > This is too strict, as this is not an error to map the same memory > twice. > > Instead, use the kernel return value to detect such state and have the > DMA function to return as successful. > > For type1 mapping the kernel driver first implementation returns EBUSY > and since kernel 3.11 returns EEXISTS. For spapr mapping EBUSY is returned > since kernel 4.10. > What is the earliest version supported by DPDK? I thought 3.10 was dropped, should we care about the 3.11 return value? > Signed-off-by: Shahaf Shuler > --- > lib/librte_eal/linuxapp/eal/eal_vfio.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c > index 48ca9465d4..2a2d655b37 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c > +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c > @@ -1263,7 +1263,11 @@ vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, > VFIO_DMA_MAP_FLAG_WRITE; > > ret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map); > - if (ret) { > + /** > + * In case the mapping was already done EEXIST will be > + * returned from kernel. > + */ > + if ((ret != -EEXIST) && (ret != -EBUSY)) { Won't a ret == 0 trigger the error then? It seems ifdef about linux versions are not common in vfio code, but bar that I think it would be cleaner to restrict the acceptable error to it. When a version will be dropped it will be much easier to remove the related code instead of digging in the commit logs, and leaving both would not be clean. > RTE_LOG(ERR, EAL, " cannot set up DMA remapping, error %i (%s)\n", > errno, strerror(errno)); > return -1; > @@ -1324,7 +1328,11 @@ vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, > VFIO_DMA_MAP_FLAG_WRITE; > > ret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map); > - if (ret) { > + /** > + * In case the mapping was already done EBUSY will be > + * returned from kernel. > + */ > + if (ret != -EBUSY) { > RTE_LOG(ERR, EAL, " cannot set up DMA remapping, error %i (%s)\n", > errno, strerror(errno)); > return -1; > -- > 2.12.0 > -- Gaëtan Rivet 6WIND