From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA2B924677F for ; Wed, 8 Jul 2026 23:48:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783554537; cv=none; b=c2engMwWpeSHokGIQuF6LFTnrWGLdXx9zDHSMxFUKQPrPJFEtnLFZQ/TjcIstvI9m9x7yCnTsTBa8tMAn5qT+/GTjbwIk1dt+1STtE1G3K9foY206MeEYOTU44vycfwWxOGdcLyradwXjRRwTlzAB6a0vD5B6yuKKTiZgXvKZHg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783554537; c=relaxed/simple; bh=G3caR3ol9l1UAID9NGNJUzLJRALfVwc2Uu3omiML4ws=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=hl0C5O/Zi5YSUQ/1vBHD0gSXinGSPlkz93CEedpYV3wXadzm9H/n8uTUjVG0ARcsJFZOz+hIQaeLWcJhMGA5TcL5GtvetB37N7VYGMw5Qyr6ODQb5hWByD0pWmk78eQipXhVIGBxmmGdKPEOEQazN/+xMK7R0m81rtYo5lJn+S8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--skhawaja.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=P3+IT1zp; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--skhawaja.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="P3+IT1zp" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-84770f89b99so436172b3a.1 for ; Wed, 08 Jul 2026 16:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783554535; x=1784159335; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=CKctKavL+T1fCBJtVjfwPQ5K5bQzru9zHJrkxaBJCqQ=; b=P3+IT1zpkJf8b62jx29a2c2UXTl68uDtWYuJ9qoiS9zsb0w4v5CB8fkpsONVm1VVbN hf//7nUhhMdy59m1lrpiIqcCfe3CAQ9N3ahB9tAX1ioLJ0Rt+J66XtYkS1aT2174qHrD 0NGT6sWN/AQRnMj8bnJt2WAZFYea8MkOAlLDcinf0AjXEC4hdqz6JQBIiCRAvzmQcbqY GNPZ3thf3LeiNW2N9O79AZmAyVOYgm4HL106b3AiOSuXKOuUI3xZHo8BRag5FDXCNmBU zMD6tbS0XOittNoRVs0bsj6fQpz615GviTpScluAgnb42UyRnv5jblW9YtZKho5AVH0n vQfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783554535; x=1784159335; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CKctKavL+T1fCBJtVjfwPQ5K5bQzru9zHJrkxaBJCqQ=; b=elyERphn+T5ocogCHURS4sDEXUi6u3AvevXEWg7fqOu82u0muijM+Zlk3/kEpsbahP HCof5uPHOWrzZhkbaDeOzUmDrfWwPWMuyXjxCcEq9e9+vSclNt4wXhcE0rtjlPUh91Qo E4mW92oF51+SuJl5Xu/eqsWfJ06o4OOeI5Emq8uNfnBMAvGs6vecGOpA1AnpuaEeJXb5 cgqW0965Ww4Hwjsi3p392oJ3bf8hP2RLaZjufwjMT3uGFetuRkPbE6XHre5HnoKz+KWb 9WRQXffk89jUsQ+Qm62oIPusdEVeeRBqbrTV4PcTKrNjdl0jbvAmHLZ/xMIjHsclrxvm HoNQ== X-Forwarded-Encrypted: i=1; AHgh+RqYOdrikPe+8x6I/JW1rqM3sKGlcBvNDIghxy0ISI3q8bZmhFrlb8gBxmVaIu6+bWec+zTjMev9c94eQV0=@vger.kernel.org X-Gm-Message-State: AOJu0YxeeyIqO0XgxeJy7iJWbcakq/Rf391pnCncpua9kXIeLomjuLoh ZXOTSV0N7Mt2kZjHjhg7153jxyGtME35CgM1HALIGJz8O/WEnxB2neeHIPcXesW3r+D+Vy3cw5Q ylsFSXBgg85dWKA== X-Received: from pfblh15.prod.google.com ([2002:a05:6a00:710f:b0:845:eada:32d2]) (user=skhawaja job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:9513:b0:845:db8d:f631 with SMTP id d2e1a72fcca58-84842ec1f1dmr4624788b3a.7.1783554534952; Wed, 08 Jul 2026 16:48:54 -0700 (PDT) Date: Wed, 8 Jul 2026 23:48:44 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.795.g602f6c329a-goog Message-ID: <20260708234854.4044652-1-skhawaja@google.com> Subject: [RFC PATCH v2 00/10] dma-mapping: Add preservation of direct allocations From: Samiullah Khawaja To: Marek Szyprowski , Will Deacon , Jason Gunthorpe Cc: Samiullah Khawaja , Pasha Tatashin , Mike Rapoport , Pratyush Yadav , Alexander Graf , Robin Murphy , Kevin Tian , iommu@lists.linux.dev, kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Matlack , Andrew Morton , Pranjal Shrivastava , Vipin Sharma Content-Type: text/plain; charset="UTF-8" This is an RFC v2 to discuss the preservation of DMA allocations for devices that are using direct allocation mode. Note preservation here means preservation of physical memory using KHO only. IOVAs and IOMMU mappings are out of scope. The complexity and need of this was discussed in the thread mentioned below. It was proposed to allow preservation of only a subset of allocations with minimum support. Offline discussion with Will Deacon concluded that this series is still needed, because we still want to use coherent allocations for Arm sMMUv3 ste/cds, so sending this v2. https://lore.kernel.org/all/aepfYzkI7NsVGCF0@google.com/ https://lore.kernel.org/all/aepRy7Gp7Ng85Zr7@willie-the-truck/ Note DMA allocation allows memory allocation from various allocators in various configurations. This RFC supports preservation with, - Direct Allocation Only. - Pages allocated through alloc_page (Buddy allocator). - No CMA support. - No DMA pools. - No device coherent memory regions. Note that this series does not include/use the page-split and page refcount fixes during KHO restore, that are in review here: https://lore.kernel.org/all/20260703020832.1731864-1-praan@google.com/ The changes are also pushed here: https://github.com/samikhawaja/linux/tree/dma-alloc-preserve-direct-v2 Testing: This patch series includes a Kunit test, for testing dma allocation preservation, by using the KHO stubs added in a separate patch series: https://lore.kernel.org/all/20260521193202.746810-1-skhawaja@google.com/ The following test runs are executed in qemu. Run on x86: KTAP version 1 1..1 KTAP version 1 # Subtest: dma_direct_liveupdate # module: direct_test 1..5 KTAP version 1 # Subtest: test_dma_direct_coherent ok 1 size=128 ok 2 size=4096 ok 3 size=8192 ok 4 size=12288 ok 5 size=32768 # test_dma_direct_coherent: pass:5 fail:0 skip:0 total:5 ok 1 test_dma_direct_coherent KTAP version 1 # Subtest: test_dma_direct_non_coherent ok 1 size=128 ok 2 size=4096 ok 3 size=8192 ok 4 size=12288 ok 5 size=32768 # test_dma_direct_non_coherent: pass:5 fail:0 skip:0 total:5 ok 2 test_dma_direct_non_coherent KTAP version 1 # Subtest: test_dma_direct_coherent_atomic ok 1 size=128 ok 2 size=4096 ok 3 size=8192 ok 4 size=12288 ok 5 size=32768 # test_dma_direct_coherent_atomic: pass:5 fail:0 skip:0 total:5 ok 3 test_dma_direct_coherent_atomic KTAP version 1 # Subtest: test_dma_direct_non_coherent_atomic ok 1 size=128 ok 2 size=4096 ok 3 size=8192 ok 4 size=12288 ok 5 size=32768 # test_dma_direct_non_coherent_atomic: pass:5 fail:0 skip:0 total:5 ok 4 test_dma_direct_non_coherent_atomic ok 5 test_dmam_preservation # dma_direct_liveupdate: pass:5 fail:0 skip:0 total:5 # Totals: pass:21 fail:0 skip:0 total:21 ok 1 dma_direct_liveupdate Run on arm64: KTAP version 1 1..1 KTAP version 1 # Subtest: dma_direct_liveupdate # module: direct_test 1..5 KTAP version 1 # Subtest: test_dma_direct_coherent ok 1 size=128 ok 2 size=4096 ok 3 size=8192 ok 4 size=12288 ok 5 size=32768 # test_dma_direct_coherent: pass:5 fail:0 skip:0 total:5 ok 1 test_dma_direct_coherent KTAP version 1 # Subtest: test_dma_direct_non_coherent ok 1 size=128 ok 2 size=4096 ok 3 size=8192 ok 4 size=12288 ok 5 size=32768 # test_dma_direct_non_coherent: pass:5 fail:0 skip:0 total:5 ok 2 test_dma_direct_non_coherent KTAP version 1 # Subtest: test_dma_direct_coherent_atomic ok 1 size=128 ok 2 size=4096 ok 3 size=8192 ok 4 size=12288 ok 5 size=32768 # test_dma_direct_coherent_atomic: pass:5 fail:0 skip:0 total:5 ok 3 test_dma_direct_coherent_atomic KTAP version 1 # Subtest: test_dma_direct_non_coherent_atomic # test_dma_direct_non_coherent_atomic: DMA allocation using pool, expecting -EOPNOTSUPP ok 1 size=128 # test_dma_direct_non_coherent_atomic: DMA allocation using pool, expecting -EOPNOTSUPP ok 2 size=4096 # test_dma_direct_non_coherent_atomic: DMA allocation using pool, expecting -EOPNOTSUPP ok 3 size=8192 # test_dma_direct_non_coherent_atomic: DMA allocation using pool, expecting -EOPNOTSUPP ok 4 size=12288 # test_dma_direct_non_coherent_atomic: DMA allocation using pool, expecting -EOPNOTSUPP ok 5 size=32768 # test_dma_direct_non_coherent_atomic: pass:5 fail:0 skip:0 total:5 ok 4 test_dma_direct_non_coherent_atomic ok 5 test_dmam_preservation # dma_direct_liveupdate: pass:5 fail:0 skip:0 total:5 # Totals: pass:21 fail:0 skip:0 total:21 ok 1 dma_direct_liveupdate Looking forward to your feedback on this. Changelog: rfc v2: - Add dma_is_from_cma() to check if an allocation is from CMA. - Add dma_is_from_dev_coherent() to check if an allocation is from a device coherent region. - Add support for preserving device-managed DMA allocations (dmam_alloc_*). - Add KUnit test suite for dma-direct liveupdate preservation. Samiullah Khawaja (10): dma: Add DMA allocation preservation KHO ABI dma/pool: Add an API to check if DMA allocation is from pool dma: contiguous: Add API to check if an allocation is from CMA dma-coherent: Allow checking if allocation is from dev coherent region dma-direct: Add API to preserve/restore allocations dma-mapping: Add API to preserve/restore DMA allocation dma-mapping: Add support of preserving dmam allocations dma: contiguous: Export is_from_cma helper for kunit dma: pool: Export the is_from_pool helper for kunit dma-direct: Add KUnit test for liveupdate preservation include/linux/dma-direct.h | 29 +++++ include/linux/dma-map-ops.h | 10 ++ include/linux/dma-mapping.h | 100 ++++++++++++++ include/linux/kho/abi/dma_alloc.h | 32 +++++ kernel/dma/Kconfig | 12 ++ kernel/dma/Makefile | 1 + kernel/dma/coherent.c | 11 ++ kernel/dma/contiguous.c | 27 ++++ kernel/dma/direct.c | 189 +++++++++++++++++++++++++++ kernel/dma/direct_test.c | 208 ++++++++++++++++++++++++++++++ kernel/dma/mapping.c | 132 +++++++++++++++++++ kernel/dma/pool.c | 17 +++ 12 files changed, 768 insertions(+) create mode 100644 include/linux/kho/abi/dma_alloc.h create mode 100644 kernel/dma/direct_test.c base-commit: ec4084bc445027a52f600e30a976928be1ba1950 -- 2.55.0.795.g602f6c329a-goog