Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp349498pxt; Fri, 6 Aug 2021 03:38:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrp69WgOyHh87G2NS5tn+sj3UuTugtCKc5bANWMcmh5Jcmi5l0iXq3cpa11UBSu26EWWVH X-Received: by 2002:a02:b047:: with SMTP id q7mr9255142jah.130.1628246280886; Fri, 06 Aug 2021 03:38:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628246280; cv=none; d=google.com; s=arc-20160816; b=Em0hxlr5BvxWg5VzolWac4KXwHNodRcId0Wi0to1qiviLuNt3dTYHizKsHwEfSrtzx u+fIG7VrsJ59/ZRLZrZitHfQWg21cPjJ932e7vkrFa00+BUucDUvnu0bT+gfaN4ecdVy +3pu141/deJ4kEQOTF/JX3Wy2f1Q/PYyWSmxIdTZloqncywlJhG7x3Xf9i6hL5pX51sv 0HVSuWLYihcofvD7ahHm+E4TjuX1pbcpM0PC9XCJcP/N8mvk77Tq5sSKiguwZxUbU4qM jQD5G5YIRF1bPBq4TdqhxGifuutMXvc6K9gg3krKYQgeppVsXCepAgt5mLbDaQB5dEWY SXLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Q1mq8OVdPA80W1OExBfSV/W93H3mior+3W3/MDGRcPA=; b=ZqyfUCOUQN9odp3ehs4qOsTbj4Syc+xCDl3RTCEXp4QvHQER2HLLi9hUrUXs4MGaOW U3lm6ACNFIslsHkoqE9mppgwXTEpvjX2wyOaWdqF1EoyAHxXt8OjttjF/fZYAyvlQ/iO F6O7HETXe9hh7sE8iZsTlSAJLfxltYFoNiNh5h61nmQqzB/gkjh1rtO9ZnSBLWw75HFH O5o2ZBJmzfcq11fki9AuEtXa1Y6l6fgi12Yjwyv6jc9tDHc4rOvwXM5jHL7SyusaidDE YHJTQlU+wdqs59WhFdHh6VZgze2lSknZwtijZR2E8y+j87woiioJhePYirvMsP4Op8C5 8S+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WiK7nCyq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n24si7922572ioz.5.2021.08.06.03.37.48; Fri, 06 Aug 2021 03:38:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WiK7nCyq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245245AbhHFKgB (ORCPT + 99 others); Fri, 6 Aug 2021 06:36:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245180AbhHFKfm (ORCPT ); Fri, 6 Aug 2021 06:35:42 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81860C061798 for ; Fri, 6 Aug 2021 03:35:26 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id e21so6500928pla.5 for ; Fri, 06 Aug 2021 03:35:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q1mq8OVdPA80W1OExBfSV/W93H3mior+3W3/MDGRcPA=; b=WiK7nCyqlQFTBMZR9JJTdkj1kZjISOnsxD0sZZqZRttMOKdD7tNOx7SohDYrRPB/vS jVshrw+ma253776vxv7OuO7qNXWcABcU9y+C+lqyPYQa0LhHzQS7sqOiH4iyzJSxuHLw zBNXvOo7bxz4tkV1givX47JWukXhflrU29vCc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q1mq8OVdPA80W1OExBfSV/W93H3mior+3W3/MDGRcPA=; b=Qn1cmm+6s6Muz9vR7bU47ZCQ3UYOfjt4+nXf2/XbTbYsKzViT8rg8wRtT5sTZ6Np5s 1sTTxEIICwVIwMua7mWbSLXkeYq1usHu2dqKfF45oiZZj32hP0749BljNVNSZflS8Kaw x4qtDeQicDeJm41SYeWdSBEe5CaL0pAatxQTNdO/ySkE8nrcoTRg1rK/ZFJF10yWXF0r KQL7+zLMBkdJtSCC2zACyetvxWcQN9PttjEokrmVvLITTc0qYHW5EDY+2Wk2RFmhimWZ avod1Fw4jhI/i4uH3LaAO4LC65MKdxldx8I+t58zzMdayFv+KthX55NI+Ks6yJUZHLjC Wn9A== X-Gm-Message-State: AOAM532/0BEHE9B7j91hM9OgkeKtKlbPlO9c9l9T3fRl0Rv9ArIwJy1R woUqyU4vfonmwNfSdaUEQ5dpCA== X-Received: by 2002:a17:90a:138f:: with SMTP id i15mr9796044pja.173.1628246126098; Fri, 06 Aug 2021 03:35:26 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:6f20:cf00:347a:afc2]) by smtp.gmail.com with UTF8SMTPSA id x24sm12172935pjk.43.2021.08.06.03.35.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Aug 2021 03:35:25 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: Robin Murphy Cc: Christoph Hellwig , Joerg Roedel , Will Deacon , Sergey Senozhatsky , Lu Baolu , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, David Stevens Subject: [PATCH v2 8/9] dma-mapping: add persistent streaming mapping flag Date: Fri, 6 Aug 2021 19:34:22 +0900 Message-Id: <20210806103423.3341285-9-stevensd@google.com> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog In-Reply-To: <20210806103423.3341285-1-stevensd@google.com> References: <20210806103423.3341285-1-stevensd@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Stevens Add a DMA_ATTR_PERSISTENT_STREAMING flag which indicates that the streaming mapping is long lived and that the caller will manage coherency either through the dma_sync_* functions or via some other use-case specific mechanism. This flag indicates to the platform that it should optimize for more efficient syncing at the cost of more expensive mapping and unmapping. This flag is used to skip optional bounce buffers when CONFIG_IOMMU_BOUNCE_BUFFERS is enabled. With respect to these bounce buffers, in most cases the flag is an optimization. However, callers which do not use the dma_sync_* calls to manage coherency must use this flag to work properly when CONFIG_IOMMU_BOUNCE_BUFFERS is enabled. Signed-off-by: David Stevens --- drivers/iommu/io-bounce-buffers.c | 14 +++++++++++--- include/linux/dma-mapping.h | 11 +++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/io-bounce-buffers.c b/drivers/iommu/io-bounce-buffers.c index af8c2a51eeed..3a0071d5a9ea 100644 --- a/drivers/iommu/io-bounce-buffers.c +++ b/drivers/iommu/io-bounce-buffers.c @@ -409,8 +409,16 @@ static bool io_bounce_buffers_map_buffer(struct io_bounce_buffers *buffers, return mapped >= info->size; } -static bool use_bounce_buffer(bool force_bounce, size_t size) +static bool use_bounce_buffer(struct device *dev, unsigned long attrs, + bool force_bounce, size_t size) { + if (attrs & DMA_ATTR_PERSISTENT_STREAMING) { + WARN_ONCE(force_bounce, + "Skipping bounce buffer for untrusted mapping %s\n", + dev_name(dev)); + return false; + } + if (IS_ENABLED(CONFIG_IOMMU_BOUNCE_BUFFERS) && size <= always_bounce_limit) return true; @@ -429,7 +437,7 @@ bool io_bounce_buffers_map_page(struct io_bounce_buffers *buffers, bool force_bounce = buffers->untrusted && iova_offset(buffers->iovad, offset | size); - if (!use_bounce_buffer(force_bounce, size)) + if (!use_bounce_buffer(dev, attrs, force_bounce, size)) return false; *handle = DMA_MAPPING_ERROR; @@ -476,7 +484,7 @@ bool io_bounce_buffers_map_sg(struct io_bounce_buffers *buffers, buffers->iovad, iter->offset | iter->length); } - if (!use_bounce_buffer(force_bounce, size)) + if (!use_bounce_buffer(dev, attrs, force_bounce, size)) return false; *out_nents = 0; diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 183e7103a66d..5d318753bb79 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -61,6 +61,17 @@ */ #define DMA_ATTR_PRIVILEGED (1UL << 9) +/* + * DMA_ATTR_PERSISTENT_STREAMING: Indicates that the streaming mapping is long + * lived, so syncing performance should be prioritized over mapping/unmapping + * performance. Platform code will establish a mapping which only requires CPU + * cache synchronization. + * + * Callers that create long lived mappings and directly handle CPU cache + * management without calling using dma_sync_* functions must set this flag. + */ +#define DMA_ATTR_PERSISTENT_STREAMING (1UL << 10) + /* * A dma_addr_t can hold any valid DMA or bus address for the platform. It can * be given to a device to use as a DMA source or target. It is specific to a -- 2.32.0.605.g8dce9f2422-goog