Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1657000lqg; Sun, 3 Mar 2024 22:21:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW/OrUSCh6GVhnLC1P7rwl5fVC4WugYXhid9ZYmbZI78YuOxBuP+I+EsxrCr33h4B9mwRFxAZcoq6nxBf5JjuF762t8ZJXZs6aI2O0nvg== X-Google-Smtp-Source: AGHT+IGjVmxXKVMQCoPulQmtyULEeowoyU7vJHtl5mkOPEkB/Qyd7sKU7IYsrBw/2FCsmm6VgF8i X-Received: by 2002:aa7:88cd:0:b0:6e5:561b:4670 with SMTP id k13-20020aa788cd000000b006e5561b4670mr8629611pff.30.1709533309065; Sun, 03 Mar 2024 22:21:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709533309; cv=pass; d=google.com; s=arc-20160816; b=UYi56R9tQU6/fQUG9aotqpNULw0GIhI6hAck+RVLp1gapIKj06nZmJw0YWDD5dkfXr /Bf14GJOBaeC9IRP95lNNA1bgzWF/gM76a5mY6i+vMaEK5FLt0iu2BUq3o0euT9XEat6 iYI0PwjQvfmM9kADnP736pM2Ez4RXDr0X0frD+KT8MNLG4l6fvTnbFoXN+wKB2Rr/FR1 aK8aeRVFvTFHUyfrPVxt9EcS1JZy54tYW29umEdB81xQqFgHVrhWlxUg8wcjxlBkJiLx IyQHiY4w7XbreeqLiHO0porm+OKDb/+y1B0GFVaMbQnyjCPs+qkDppIdvXUI3E7k2ad3 BhLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to :references:cc:to:from:date:subject:message-id:dkim-signature; bh=dUDdh5wVcfRP3a5H1iRsoBCROf53bWeQiUnd3Swr9r8=; fh=/pVItAZDCh1ZLYJlcXSzXU9I1JR5P287QJ0+YcLNvgk=; b=O0e87lbWWrkjT0qmGKOVtQd2sHb3zjNzXFSqvrfxv+EaBH7IetRdSETFnjmlIbIu6R kxJZXDebVkgTw5lobr+Z1/34WIC6fMLBmzPHQ9QFT6IWugyNLxs4IDU3w8GKpJ+9u8fV IQHP+WQ9OPW0PT8x82iIspeJuV7ZHNU1UjiWIqFiG4opGNRtOMmJWvIyiHKj6SLxM6nC V6OgzCMokQc5bIs3GOEi/BbZ0ImkABq6lC/QdlTm+92MDTwjFB/HE2xuLtN3/+mnbeVb /ZPpz08DIeFpGaOJ5VvkpGreb/WjYZwiDLSnpIkolW8BfrDMMixVJJGvvYukfioAIrvC oRdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=eJ0UGOcm; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-90082-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90082-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s1-20020a056a00178100b006e62525fc17si1002786pfg.293.2024.03.03.22.21.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 22:21:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90082-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=eJ0UGOcm; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-90082-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90082-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BCB532815FF for ; Mon, 4 Mar 2024 06:21:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2EF3CD26B; Mon, 4 Mar 2024 06:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="eJ0UGOcm" Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35CBDBE4C for ; Mon, 4 Mar 2024 06:21:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709533302; cv=none; b=OWWxtEMupVS6Zx/eQNfegIjSW+0cLcOU3Xh85NCRPYnCN3TVYBGqdpH7+aYZwgkQ1l8tzBntbzfOzRR7W7M5pni+QAfPbnWCdpLBOorFFCrE4N5/XFOUEtF2s93vHYSV9sCD8jmg5cgVQYKsPgmu+sH64in0gfXllmiyoIvS1xo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709533302; c=relaxed/simple; bh=RY90ZcVRTd3xTZgswgtC+XVHYgz5ZvIpGUvShK7L7Nk=; h=Message-ID:Subject:Date:From:To:Cc:References:In-Reply-To; b=khgODcGY2+ubtdZv4S/tEmtOorpG96lYibfnFW5iKHH5Acy44BkNXx9I1IDY/K1gu6QiliDpnpu9tL/eEpzI/k7mKZLNJkGdv0zbtT82/zyOwuVlDGBRnaCG9bhXM9SH/C6TWml6l2FJW3isBXR1Jj57r0suay9ksR4mhPohZz4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=eJ0UGOcm; arc=none smtp.client-ip=115.124.30.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1709533291; h=Message-ID:Subject:Date:From:To; bh=dUDdh5wVcfRP3a5H1iRsoBCROf53bWeQiUnd3Swr9r8=; b=eJ0UGOcmlGDp0/TF1/qm3jPa4BRfBL2rnbzCTV6arPW6fucQnbsDNBoLWpi8VG62VKEeMXrmKMpyG4Rvqwib+shtNPOsIZqbXfrM5eBa9pmspmlR6Gohp6mU+YH5m38HZc4v0jXFUFBoeFG2WQ2dTqpEncwe3quftDpQDENhHkw= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R761e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0W1kG4O-_1709533290; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0W1kG4O-_1709533290) by smtp.aliyun-inc.com; Mon, 04 Mar 2024 14:21:31 +0800 Message-ID: <1709533151.0138865-1-xuanzhuo@linux.alibaba.com> Subject: Re: [RFC] dma-mapping: introduce dma_can_skip_unmap() Date: Mon, 4 Mar 2024 14:19:11 +0800 From: Xuan Zhuo To: "Michael S. Tsirkin" Cc: linux-kernel@vger.kernel.org, Joerg Roedel , Will Deacon , Christoph Hellwig , Marek Szyprowski , iommu@lists.linux.dev, Zelin Deng , Robin Murphy References: <20240301071918.64631-1-xuanzhuo@linux.alibaba.com> <64be2e23-c526-45d3-bb7b-29e31241bbef@arm.com> <20240301064632-mutt-send-email-mst@kernel.org> <20240301082703-mutt-send-email-mst@kernel.org> In-Reply-To: <20240301082703-mutt-send-email-mst@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: On Fri, 1 Mar 2024 08:41:50 -0500, "Michael S. Tsirkin" wrote: > On Fri, Mar 01, 2024 at 12:42:39PM +0000, Robin Murphy wrote: > > On 2024-03-01 11:50 am, Michael S. Tsirkin wrote: > > > On Fri, Mar 01, 2024 at 11:38:25AM +0000, Robin Murphy wrote: > > > > Not only is this idea not viable, the entire premise seems flawed - the > > > > reasons for virtio needing to use the DMA API at all are highly likely to be > > > > the same reasons for it needing to use the DMA API *properly* anyway. > > > > > > The idea has nothing to do with virtio per se > > > > Sure, I can see that, but if virtio is presented as the justification for > > doing this then it's the justification I'm going to look at first. And the > > fact is that it *does* seem to have particular significance, since having up > > to 19 DMA addresses involved in a single transfer is very much an outlier > > compared to typical hardware drivers. > > That's a valid comment. Xuan Zhuo do other drivers do this too, > could you check pls? I checked some drivers(gve, mlx, ice), no one has the same operation like virtio-net. We can do it because we have indirect feature. Thanks. > > > Furthermore the fact that DMA API > > support was retrofitted to the established virtio design means I would > > always expect it to run up against more challenges than a hardware driver > > designed around the expectation that DMA buffers have DMA addresses. > > > It seems virtio can't drive any DMA changes then it's forever tainted? > Seems unfair - we retrofitted it years ago, enough refactoring happened > since then. > > > > > - we are likely not the > > > only driver that wastes a lot of memory (hot in cache, too) keeping DMA > > > addresses around for the sole purpose of calling DMA unmap. On a bunch > > > of systems unmap is always a nop and we could save some memory if there > > > was a way to find out. What is proposed is an API extension allowing > > > that for anyone - not just virtio. > > > > And the point I'm making is that that "always" is a big assumption, and in > > fact for the situations where it is robustly true we already have the > > DEFINE_DMA_UNMAP_{ADDR,LEN} mechanism. > > I'd consider it rare for DMA > > addresses to be stored in isolation, as opposed to being part of some kind > > of buffer descriptor (or indeed struct scatterlist, for an obvious example) > > that a driver or subsystem still has to keep track of anyway, so in general > > I believe the scope for saving decidedly small amounts of memory at runtime > > is also considerably less than you might be imagining. > > > > Thanks, > > Robin. > > > Yes. DEFINE_DMA_UNMAP_ exits but that's only compile time. > And I think the fact we have that mechanism is a hint that > enough configurations could benefit from a runtime > mechanism, too. > > E.g. since you mentioned scatterlist, it has a bunch of ifdefs > in place. > > Of course > - finding more examples would be benefitial to help maintainers > do the cost/benefit analysis > - a robust implementation is needed > > > -- > MST >