Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp295703lqg; Fri, 1 Mar 2024 05:42:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUA5kwIqh2hjYpmhq/QWQXK7PvPtQaT6hKLQY30ED1gNw6nPgpIxgopTVAgQfcW65EfotQ2Zxww7n4AgeFm8nrBgQcsjOOK3HgXIWTMqA== X-Google-Smtp-Source: AGHT+IGXZ2OSvcbwfX1f4k72a99GzVXAHwi6u1o57S2/SoJPE91+teEOXgHWBuz48ZKVL6R1T2lJ X-Received: by 2002:ac8:5cc8:0:b0:42e:be5c:9248 with SMTP id s8-20020ac85cc8000000b0042ebe5c9248mr1594376qta.56.1709300526824; Fri, 01 Mar 2024 05:42:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709300526; cv=pass; d=google.com; s=arc-20160816; b=Ny9Utk4NA38Z5QCyKngqcVeNk/SXMviqvXygdF0MLqqPxwsy39GKtdpRD5UrQMZlqd E8fjv8+bN7l9o+m8IApXQueQR+E/SMQ72EuqDoXf2ZSmLxKZNa6DsgB9Rc9KKozoWXH4 N2/LpG2nGwtdF64xAQBD9Nx6akRnPcBJf3ygTVvQK/VCbqCG6mhXHsbNHCQdiP9SjsxF IZmJj9liUW7V75nYLD/4PU5T8MLcwOtl9DkoFkmEPooJedCfuvciFb0XBJHEbSwIMGjp E6MyyQfPo+I0EHm3HQlCjG1zM35t2sWkXMpjBm1QGeaDWxtmO81M+ZsqqMqU77rDizJ/ jdZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=IV5GI9ggtOV7YL4yWU+pWO5696jTgiyXslpZgRz6IkE=; fh=84DXM65GVJuIoGEHPrHXMff4+sOWkUkB3t3YDDWJmXA=; b=Y4SnZrD9mNcNabuUGbgjcSx3WfJbDsXIje/dyYOMfmFK1S51hAZeE3Kx5/27lkaZS6 BSK4VAfPCE56J6iMhg5FD9Cp6L3FJ40EVH1qN69PEj094BRGD1UqwPci1a5cvXErd5OL 0+MHSptA5g6JyzzJPb3wk7G6shc0B2ttD91aIJx4t/RuA9dzeaVC2hQ15diIAPDE1PM5 +auVUfyhd4kxSjJiER3jBteHUx+KozsymMeqrBY97p4qLRKxLgc78GrMa6T2OyL1fGia I/uQTK3iaVv/4xiaZnfFR3qBlK7ecki7BbhAZ271gAarvspbKYhL7bBqGgdZU8sfk5wz 5p4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U7Y2Xi+1; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-88500-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88500-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i3-20020ac85c03000000b0042e6df3902asi3813670qti.285.2024.03.01.05.42.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 05:42:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88500-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U7Y2Xi+1; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-88500-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88500-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 72B621C209FC for ; Fri, 1 Mar 2024 13:42:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A13C46D516; Fri, 1 Mar 2024 13:42:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="U7Y2Xi+1" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 2758A381DE for ; Fri, 1 Mar 2024 13:41:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709300520; cv=none; b=kqYXVIpoU72S42SwKwKPa2/GgE1j1u1FrUZShE3XlzD283HxwzLms3B4rYaiZhwnBeopZBNh+olIzamVC/iua/J6oDpg2KlidBYwdI9D8o8YhokHh1sj4ji1DimByVGla0ZUxO4ZRlbdkrCmvB/rfxiCtlQaWzg330sFhfe6PVk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709300520; c=relaxed/simple; bh=2vk9V19VUlgEPl/3Idd/ZI+pMX1LOMB9aDys6AIl9Ao=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GnKf65K+eoeOc+3+0w2jLR4FtyfDXDQPhT3c5h2ie0CvFZ7FqeaZxyded2Ufepvav41HQmlHOCkrbWQEPsjzMo838+Y8PozmjSmQ+eWc7rUzW/6pZ9oO81YAT0X6KGC8DLsqMnesXNlPjy5W3P+uT8yD/APToq5YRheyAQco1yg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=U7Y2Xi+1; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709300518; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=IV5GI9ggtOV7YL4yWU+pWO5696jTgiyXslpZgRz6IkE=; b=U7Y2Xi+1/tq9+/n3uOSZkq9WWox8vOwnpgfR3JQF9oo1YtH8FArI7wO2QKUKZUhfP3xljQ tDCcZ2ZuoiYpH35gw/dXGqQAKC67V9ltQmSV5P+aMmKr1J96DH70ATfdq7bv6PFVthyyI5 7Bo4+RVczpvd8wWuvL3dxxH32Ao90FM= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-66-Y_dIfbA-OuKv5jE3xYEGpg-1; Fri, 01 Mar 2024 08:41:57 -0500 X-MC-Unique: Y_dIfbA-OuKv5jE3xYEGpg-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a44170156daso160288366b.1 for ; Fri, 01 Mar 2024 05:41:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709300515; x=1709905315; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=IV5GI9ggtOV7YL4yWU+pWO5696jTgiyXslpZgRz6IkE=; b=U3oeWP5rqZ5OSTbkEgl8GKyoMk1DyEVb8vjsjyIT+sHgtoJ1jHCbnflHJRxbLEywOd pydiiTAoDDi8RujCGxC/SNHJf4cpN6V84aLG/iln4nNhLv0xm0LYpcWq1DrlCeukZO56 189rcknFxwz8tg4qxi8PdKslGt8BVWOcLbyAAGojf4SGqDz5qV6+4N1fWVHA9WfHBDbO D2saVGO7PJHrW9Jr+YpM0/6R/5ozxjmRduD1wqNKR6iizREDe7NWauRFZANZlkOH9KEd rtWdJ9zLnoRbysvbf2lJHD25vLYX9BdXtSJ9tdNMkjMlftC3zCcwh2pUp1JvzdG0gTKC K47Q== X-Forwarded-Encrypted: i=1; AJvYcCVjqJkQDQTYLuzmBqmV9VUpDtAbUibMYbeICXwhTkfwvN2eVp9iI02fLbwE2A8yAcI6eronRpKBs5V7L/rFdax3/MbWQuWN9o6FLNZj X-Gm-Message-State: AOJu0YwAUspIBWnDnqEiI6Iq0VRL3Pu7/+SKchn/xAnd8wcqrGtlvJ3s mPkOy+WUk9/6/QY5hCYBlVuZpvG/yUSg5mJrUepEL/WYDRqnEFdk6YDsf6IyeQUhQpKwyl5teqs caNr0FUn+4IykWwYxR2Nh49cDFZf+OwMl4rikWyxq2T0VuqJldmlRG1UbaGONQtA3o0gjTA== X-Received: by 2002:a17:906:b214:b0:a3f:9629:d305 with SMTP id p20-20020a170906b21400b00a3f9629d305mr1372880ejz.28.1709300515431; Fri, 01 Mar 2024 05:41:55 -0800 (PST) X-Received: by 2002:a17:906:b214:b0:a3f:9629:d305 with SMTP id p20-20020a170906b21400b00a3f9629d305mr1372862ejz.28.1709300514951; Fri, 01 Mar 2024 05:41:54 -0800 (PST) Received: from redhat.com ([2.52.158.48]) by smtp.gmail.com with ESMTPSA id vk1-20020a170907cbc100b00a445c16d902sm1267866ejc.96.2024.03.01.05.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 05:41:54 -0800 (PST) Date: Fri, 1 Mar 2024 08:41:50 -0500 From: "Michael S. Tsirkin" To: Robin Murphy Cc: Xuan Zhuo , linux-kernel@vger.kernel.org, Joerg Roedel , Will Deacon , Christoph Hellwig , Marek Szyprowski , iommu@lists.linux.dev, Zelin Deng Subject: Re: [RFC] dma-mapping: introduce dma_can_skip_unmap() Message-ID: <20240301082703-mutt-send-email-mst@kernel.org> References: <20240301071918.64631-1-xuanzhuo@linux.alibaba.com> <64be2e23-c526-45d3-bb7b-29e31241bbef@arm.com> <20240301064632-mutt-send-email-mst@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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. > > - 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