From patchwork Tue Sep 13 19:55:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 12975327 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16176C6FA82 for ; Tue, 13 Sep 2022 19:59:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC28B6B009D; Tue, 13 Sep 2022 15:59:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A717E6B009E; Tue, 13 Sep 2022 15:59:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EC416B009F; Tue, 13 Sep 2022 15:59:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7FE5F6B009D for ; Tue, 13 Sep 2022 15:59:09 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5D6301A04A0 for ; Tue, 13 Sep 2022 19:59:09 +0000 (UTC) X-FDA: 79908126018.04.F1D517D Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf20.hostedemail.com (Postfix) with ESMTP id DF22D1C00C0 for ; Tue, 13 Sep 2022 19:59:08 +0000 (UTC) Received: by mail-qk1-f177.google.com with SMTP id d17so8540092qko.13 for ; Tue, 13 Sep 2022 12:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=lc6C5FZ3R6bpGdrTQfUMqHUthTTami+g742/pfBsTic=; b=RlsLmEiP3JVWhyXjCMSzF7A4AVjyq1jRjWCW9x5GNVTee31Y+zsIXxNeUFqHaiWHyg 8J6hP8RFMjTeETwSHV9ENC6pqQalmeYj6JweS9Tsv7OxuqvPlsMarmRSfwGBaWF+XcBE la0+kyQTMUqV4xn7LwqYCphDGQkUMF9O3ZqeG7FJEIlcBtt95RRsh5UONSCeySm6f9no qWos+YkhM9jVDPaT5oAH5RbFh07TQsfPjWCoTiWZNYZktg0UxgNqKCsIm4np7G5/9pqK Gqu0dk9U2X717zjfg5WZXwdvFki/e2iGeK+mAGJNsof/XN1i9elvjnIO7qYgQkqpgSuo A90g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=lc6C5FZ3R6bpGdrTQfUMqHUthTTami+g742/pfBsTic=; b=EdmZR4w8ZfMFC6ykFR4wfLThkFqFFlx9fQXUrQmDYrGIxeliOeWwc8oQx1VLpUMwfe OUjF8BjeNhK84qCjhOwmpZ2LmIPmEK2ATphogy2TY4SBafs+lfsGGvwRXgVwXkjAS9vE FBztZGvJ1wqtvIim2tfandYEOW+MM/zTWu6ykuog1i1wL34dbqqnQ1iCNu1M0bEfJ80P vrzLEVWPh0MDBRfQIjSDDhNgoiswuC5zxsJ5ZAscEJabtSvgcP/6RmP2T/a4Ldjxgt1R yIhGjqf9tpl0V0VSZIBWA5V0R3LHCK5ujYDlYNY5VMpf+FFctDEMY6FTVxuSj+JdHL7P VIAg== X-Gm-Message-State: ACgBeo1djVr2H0n1JqQrAIg0yRW+N2I64TnZ7BY24uQ4iC5UfTRmNg1b 9l1plN2ZESyI5/9L0S2H9cWyT2G3/VM= X-Google-Smtp-Source: AA6agR4JgnZFDc4dYiN2cHvYsrY/zIDRf84OViiKl4IHPDPBj/qqA4B2wHLv+IBu33IWNCFBvl5WRQ== X-Received: by 2002:a05:620a:22b0:b0:6cd:f06a:7978 with SMTP id p16-20020a05620a22b000b006cdf06a7978mr13621240qkh.106.1663099148142; Tue, 13 Sep 2022 12:59:08 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id s11-20020a05620a29cb00b006b8e049cf08sm276305qkp.2.2022.09.13.12.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 12:59:07 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Frank Rowand , Mike Kravetz , Muchun Song , Mike Rapoport , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Doug Berger , Florian Fainelli , David Hildenbrand , Zi Yan , Oscar Salvador , Hari Bathini , Kees Cook , - , KOSAKI Motohiro , Mel Gorman , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux.dev Subject: [PATCH 20/21] mm/cma: introduce rmem shared-dmb-pool Date: Tue, 13 Sep 2022 12:55:07 -0700 Message-Id: <20220913195508.3511038-21-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220913195508.3511038-1-opendmb@gmail.com> References: <20220913195508.3511038-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663099148; a=rsa-sha256; cv=none; b=0wvk5x3kmTkSIH9vY/lV3M8eVSxfA7rmDfkaunFL2AdBgs3gO1VY8S8gmWPPigdvUMAn0P vJOTEtoTJf4YgkiMW0qRfAOiZOEE+PqUbGCgSbCHIYOBR67x1i+fp/6kX3IK/agZx8L8ZL yBGASMzPzmETrAP37td4E4lvTZGJO7g= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RlsLmEiP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=opendmb@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663099148; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lc6C5FZ3R6bpGdrTQfUMqHUthTTami+g742/pfBsTic=; b=nw/arHPZFM7UlrXoCx9bbuMbykbk3L1pVS/03bToA/Eh/zqVJV8cODonpQ0E4/z0fmBR2U 4hGI0CbqMGkeT5Mvuf0sUJQy2o2NeFJXjkxZJYn3xXsQ2Pnlfup3j+j90yeP3lecwFDBcn zJCvfeu7r0e2bTrnJ7IB1cbgOeyOw/U= Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RlsLmEiP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=opendmb@gmail.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DF22D1C00C0 X-Stat-Signature: ecicp8jc6uysd5pb9z33r8mhtmcky6kr X-Rspam-User: X-HE-Tag: 1663099148-168704 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: A 'shared-dmb-pool' reserved-memory device tree node defines a Designated Movable Block for use by an associated Contiguous Memory Allocator. Devices access the CMA region in the same manner as a 'shared- dma-pool', but the kernel page allocator is free to use the memory like any other ZONE_MOVABLE memory. Signed-off-by: Doug Berger --- drivers/of/of_reserved_mem.c | 5 +++++ kernel/dma/contiguous.c | 33 ++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 0eb9e8898d7b..700c0dc0d3b6 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -123,6 +123,11 @@ static int __init __reserved_mem_alloc_size(unsigned long node, && !nomap) { /* Need adjust the alignment to satisfy the CMA requirement */ align = max_t(phys_addr_t, align, CMA_MIN_ALIGNMENT_BYTES); + } else if (IS_ENABLED(CONFIG_CMA) + && of_flat_dt_is_compatible(node, "shared-dmb-pool")) { + /* Need adjust the alignment to satisfy CMA/DMB requirements */ + align = max_t(phys_addr_t, align, CMA_MIN_ALIGNMENT_BYTES); + align = max_t(phys_addr_t, align, DMB_MIN_ALIGNMENT_BYTES); } prop = of_get_flat_dt_prop(node, "alloc-ranges", &len); diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index 6ea80ae42622..65dda12752a7 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -50,6 +50,7 @@ #include #include #include +#include #ifdef CONFIG_CMA_SIZE_MBYTES #define CMA_SIZE_MBYTES CONFIG_CMA_SIZE_MBYTES @@ -397,10 +398,11 @@ static const struct reserved_mem_ops rmem_cma_ops = { .device_release = rmem_cma_device_release, }; -static int __init rmem_cma_setup(struct reserved_mem *rmem) +static int __init _rmem_cma_setup(struct reserved_mem *rmem, bool in_dmb) { unsigned long node = rmem->fdt_node; bool default_cma = of_get_flat_dt_prop(node, "linux,cma-default", NULL); + phys_addr_t align = CMA_MIN_ALIGNMENT_BYTES; struct cma *cma; int err; @@ -414,16 +416,25 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem) of_get_flat_dt_prop(node, "no-map", NULL)) return -EINVAL; - if (!IS_ALIGNED(rmem->base | rmem->size, CMA_MIN_ALIGNMENT_BYTES)) { + if (in_dmb) { + if (default_cma) { + pr_err("Reserved memory: cma-default cannot be DMB\n"); + return -EINVAL; + } + align = max_t(phys_addr_t, align, DMB_MIN_ALIGNMENT_BYTES); + } + if (!IS_ALIGNED(rmem->base | rmem->size, align)) { pr_err("Reserved memory: incorrect alignment of CMA region\n"); return -EINVAL; } - err = cma_init_reserved_mem(rmem->base, rmem->size, 0, rmem->name, &cma); + err = __cma_init_reserved_mem(rmem->base, rmem->size, 0, rmem->name, + &cma, in_dmb); if (err) { pr_err("Reserved memory: unable to setup CMA region\n"); return err; } + /* Architecture specific contiguous memory fixup. */ dma_contiguous_early_fixup(rmem->base, rmem->size); @@ -433,10 +444,22 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem) rmem->ops = &rmem_cma_ops; rmem->priv = cma; - pr_info("Reserved memory: created CMA memory pool at %pa, size %ld MiB\n", - &rmem->base, (unsigned long)rmem->size / SZ_1M); + pr_info("Reserved memory: created %s memory pool at %pa, size %ld MiB\n", + in_dmb ? "DMB" : "CMA", &rmem->base, + (unsigned long)rmem->size / SZ_1M); return 0; } + +static int __init rmem_cma_setup(struct reserved_mem *rmem) +{ + return _rmem_cma_setup(rmem, false); +} RESERVEDMEM_OF_DECLARE(cma, "shared-dma-pool", rmem_cma_setup); + +static int __init rmem_cma_in_dmb_setup(struct reserved_mem *rmem) +{ + return _rmem_cma_setup(rmem, true); +} +RESERVEDMEM_OF_DECLARE(cma_in_dmb, "shared-dmb-pool", rmem_cma_in_dmb_setup); #endif