Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1659561lqg; Sun, 3 Mar 2024 22:30:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVKzVlUzHxSXbKjdENe1Zejtw4UlwEbJFvhkJrl9rq9V3Kk++sjn5UlV+XQoMCdRPhRWV+en21XPRpdtsVN1MAg4MS2rf6j7oNiMBQl6g== X-Google-Smtp-Source: AGHT+IE7k850UmFcyo3jRjKRi/etrcKwk69RH3M5ZCZ1j2luGspWAgFvPvh1NeElmVDfufca4xSR X-Received: by 2002:a50:9e4b:0:b0:566:c156:aac9 with SMTP id z69-20020a509e4b000000b00566c156aac9mr5018834ede.27.1709533849065; Sun, 03 Mar 2024 22:30:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709533849; cv=pass; d=google.com; s=arc-20160816; b=FdjK7GWi5ohxzt7r8SGgDfFNwSbvQ+IG3hZ0q3pZTlYDvKH5/YUkKX15T0CuEsi/+U gIkIni8sgMOLKa5rlAPqX4z5L/554T3ixZ+3aitxUxBGg++Z/XR6S2pmHubXaUW/V80m Hxao7N5GvFXVkmQ2pdddKQrHInLk/LxKiqGprcyNKFUw0yVO93A5nLwB+CFIj0nUzYXW qS7wxeuQYncxZhKRRqMeg8DqT0ufaH0QK158oB6ovxa5zDIubGBr+gqrYuopK8CuAJcb 6sDdIKoTYcEboLKBv0ambKepJIYDEFkLLzbULMWQJoZVHbbJ5J+TJTZXstrwMM3/io0C Tlnw== 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=NGXjorvuk11qTskGv8WPgdXQ88lN94avzSL2JOcc1C8=; fh=UUeTZgGdGVSECJ2tUyU6kBY86j11g2NyOk0fdJ0lhxw=; b=B0JoqpOmdgh/k0wy/coD4sFmTgxprzG5kz/5RBAgEPxqjGqZkySQ1JlAYIO/bx2s4M 9GXY5/hXGZsULsCADuGbIfB6WZejiKE4ZnvfNKxnVREuHP+feWETnaUmBnSJ0izcift0 soFY5QT8HksP3FUKnqsP9vcg6MEgx5yYvF0CAcG5DuU3XYCSuExipkNBAxb39sUUG64l s6jrKLecVRb3jtVRbo3Pu6X1+SzLn/e6P4LbD/QsZsNNf6IUkabiW1TvFe6ZUcIMExqW dbEfI/HxE2lEFlUxqo2VHV7ciDHOkZ74nABvDc7SvCHd2ynAkZmSSLLj+Rpo4ZIp1+Mu hg9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=sPquiY6o; 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-90088-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90088-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 am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f21-20020a0564021e9500b005642ea075aesi3855563edf.314.2024.03.03.22.30.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 22:30:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90088-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=sPquiY6o; 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-90088-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90088-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C6C6F1F215BB for ; Mon, 4 Mar 2024 06:30:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68EE81118F; Mon, 4 Mar 2024 06:30:44 +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="sPquiY6o" Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 AC50F11199 for ; Mon, 4 Mar 2024 06:30:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709533843; cv=none; b=bX8zmzYxDD+NoR4mBzH4wfbNq1TpJPVq08trhzJWg6/p1K9IHqlwfFteHF9bozCnTUjw0cO5RhCP3+CU+XdI7p77CTI492Dsx2K4H0UjUZDiHlqa0EfovbqcccHUhdKh0ffyuza6bUlF+VgcOwpCAyhpKku0DrDAWyUntZI6Q70= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709533843; c=relaxed/simple; bh=oRuL5E03NRBdlsCXDyKaHFjeY88RtCn+H3QpyLpZHgI=; h=Message-ID:Subject:Date:From:To:Cc:References:In-Reply-To; b=ZXcJN0tarQUozJpDZH0Ohe/mx+bvrhaYO8T2hH1psYvArZcztQRsriqSRecu+VZ+QtHwHyf6HPChSWqmFszNCpm2iH/4D4DIPMAmu6OhNVOicvwm5WQwirNH1S6byRgJA6gtiGLZIf+zEsAsnVUgsjjodsJNqJ7WCDpGp7y+xkg= 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=sPquiY6o; arc=none smtp.client-ip=115.124.30.97 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=1709533833; h=Message-ID:Subject:Date:From:To; bh=NGXjorvuk11qTskGv8WPgdXQ88lN94avzSL2JOcc1C8=; b=sPquiY6or+egThxF2tTEh0EE8v8UOQUYiOseVtW3MzTvkr+XUFty0kSDja9xFMf8vJZY8S9k8JPaZF/498yq+a2iZzgR4V8e/KhistVE0i5Z5t6n2crtIttAAIF792c27zFv1VeVtegHgmlusCcU/TT8ABqWpPlhx6sjvoxrvXU= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R631e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0W1kG7dz_1709533832; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0W1kG7dz_1709533832) by smtp.aliyun-inc.com; Mon, 04 Mar 2024 14:30:32 +0800 Message-ID: <1709533720.5072534-2-xuanzhuo@linux.alibaba.com> Subject: Re: [RFC] dma-mapping: introduce dma_can_skip_unmap() Date: Mon, 4 Mar 2024 14:28:40 +0800 From: Xuan Zhuo To: Robin Murphy Cc: linux-kernel@vger.kernel.org, Joerg Roedel , Will Deacon , Christoph Hellwig , Marek Szyprowski , iommu@lists.linux.dev, Zelin Deng , "Michael S. Tsirkin" 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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: On Fri, 1 Mar 2024 18:04:10 +0000, Robin Murphy wrote: > On 2024-03-01 1:41 pm, 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? > > > >> 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. > > No, I'm not saying we couldn't still do things to help virtio if and > when it does prove reasonable to do so; just that if anything it's > *because* that retrofit is mature and fairly well polished by now that > any remaining issues like this one are going to be found in the most > awkward corners and thus unlikely to generalise. > > FWIW in my experience it seems more common for network drivers to > actually have the opposite problem, where knowing the DMA address of a > buffer is easy, but keeping track of the corresponding CPU address can > be more of a pain. > > >>> - 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. > > But what could that benefit be in general? It's not like we can change > structure layouts on a per-DMA-mapping-call basis to save > already-allocated memory... :/ We can put the memory together. If the unmap is not needed, then we do not allocate the memory. That is the way we are trying. Thanks. > > Thanks, > Robin. > > > > > Of course > > - finding more examples would be benefitial to help maintainers > > do the cost/benefit analysis > > - a robust implementation is needed > > > >