Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF44AC7618A for ; Mon, 20 Mar 2023 12:29:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231356AbjCTM3U (ORCPT ); Mon, 20 Mar 2023 08:29:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231201AbjCTM3M (ORCPT ); Mon, 20 Mar 2023 08:29:12 -0400 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3828A83C0; Mon, 20 Mar 2023 05:29:10 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4PgDMY3bQ6z9y4Sk; Mon, 20 Mar 2023 20:20:09 +0800 (CST) Received: from A2101119013HW2.china.huawei.com (unknown [10.48.148.162]) by APP2 (Coremail) with SMTP id GxC2BwBnOF9kURhkkqGyAQ--.46782S3; Mon, 20 Mar 2023 13:28:42 +0100 (CET) From: Petr Tesarik To: Jonathan Corbet , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Borislav Petkov , "Paul E. McKenney" , Andrew Morton , Randy Dunlap , Damien Le Moal , Kim Phillips , "Steven Rostedt (Google)" , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list), iommu@lists.linux.dev (open list:DMA MAPPING HELPERS) Cc: Roberto Sassu , petr@tesarici.cz Subject: [RFC v1 1/4] dma-mapping: introduce the DMA_ATTR_MAY_SLEEP attribute Date: Mon, 20 Mar 2023 13:28:13 +0100 Message-Id: X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: References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4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07jx wIDUUUUU= X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Petr Tesarik Introduce a DMA attribute to tell the DMA-mapping subsystem that the operation is allowed to sleep. This patch merely adds the flag, which is not used for anything at the moment. It should be used by users who can sleep (e.g. dma-buf ioctls) to allow page reclaim and/or allocations from CMA. Signed-off-by: Petr Tesarik --- Documentation/core-api/dma-attributes.rst | 10 ++++++++++ include/linux/dma-mapping.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/Documentation/core-api/dma-attributes.rst b/Documentation/core-api/dma-attributes.rst index 1887d92e8e92..6481ce2acf5d 100644 --- a/Documentation/core-api/dma-attributes.rst +++ b/Documentation/core-api/dma-attributes.rst @@ -130,3 +130,13 @@ accesses to DMA buffers in both privileged "supervisor" and unprivileged subsystem that the buffer is fully accessible at the elevated privilege level (and ideally inaccessible or at least read-only at the lesser-privileged levels). + +DMA_ATTR_MAY_SLEEP +------------------ + +This tells the DMA-mapping subsystem that it is allowed to sleep. For example, +if mapping needs a bounce buffer, software IO TLB may use CMA for the +allocation if this flag is given. + +This attribute is not used for dma_alloc_* functions. Instead, the provided +GFP flags are used to determine whether the allocation may sleep. diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 0ee20b764000..7a75c503ac38 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -61,6 +61,12 @@ */ #define DMA_ATTR_PRIVILEGED (1UL << 9) +/* + * DMA_ATTR_MAY_SLEEP: This tells the DMA-mapping subsystem that it is allowed + * to sleep. + */ +#define DMA_ATTR_MAY_SLEEP (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.25.1