Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 A564B47B408 for ; Mon, 21 Sep 2026 15:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790003688; cv=none; b=PqK9Q3jwSTgr8CeRrdUXFpUPGxcGKWM3ROMvP9ZotM/06q9iT3wetKkDS/ys7e9DupwvO3GTQohRjtDwqKA8KbJ3/uDWeUjfl7NrGrYg7i31t/LhYe5Usi71vyTSARbDMLrbBoTLTeI6qtnzy0x6M6YlYVo1NANs0pHflzcgPjE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790003688; c=relaxed/simple; bh=Whvk5RInjRcT7w4OABrB+OhDGuJK29mos0BwOanD3hU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=UCF0VHCT6yl8tQTQNOuVcPq2v3g5wCSj3/F5LHM5Guuk24FFL1ENwQejl4zFxCizxhNqT61a9H7sYeX5FbikhKE4iomLQJ7rOI4jnRpA8x6kSA4S/BhebGya5TKKIkTCzHhjGPCat521QQgzH5HRTIf9LqQaWbR6DnjWxyInHIU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=dcH+Et1y; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=A84mEo39; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="dcH+Et1y"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="A84mEo39" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68LFA54W2690739 for ; Mon, 21 Sep 2026 15:14:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=+sC0Yvqh8Q5nitoPDOO2xt DXj5k7Je/RXYaZIXdOYtg=; b=dcH+Et1yC92Lu5dw7AEjH/U1yXQ6mEHF6MbfJO ePttSzU0pXW3tGBgh0USunt9zJbIWlj3bdB5t0Cn98Ns/BgFdhw+YUAC9/UQ9LtS sPzLhE4A3NC8i+VRr9SOmn5wmtolZqWZ64HNcKwQfvt8+3GwTRyecnobNZxqoyTE Kq4iYbAHg9N66jlxI6xfRt1lZUWRrJG1kwOTEeC56ZQEhe95yokRMwleVnIpHlzp 4fwRt16x5LK2thprq9Q0h3V9qAV+3FGNVrBVECSgQHLfNTydcB6UMe/qwSxMPiw2 sFBI1incax2uGm8Mv68+yAvwhxYxcABM9I7tZSfs0C13IXdQ== Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4gtt3wu28v-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 21 Sep 2026 15:14:45 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2dd188e16a2so34822945ad.2 for ; Mon, 21 Sep 2026 08:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1790003685; x=1790608485; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:content-type :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=+sC0Yvqh8Q5nitoPDOO2xtDXj5k7Je/RXYaZIXdOYtg=; b=A84mEo39MHf/Vt9SY82ZOIfJHjtgSIi4o3BLDeIU9lGvON2r59LQrNMToZc11nSFL3 JzSRIX09NJDSrYGMaaF4/7F95t0YYRECuPR32zIHfLtkek/t7D6uvI0GQQMZyx9fU9Ba 39L09h5DU46RQKyexgw7ezmfqEFgBw+7/JUrVsEOh1PmxQSLZNcuorX7MYeX2RYRmOKL aXiC3Y8XwDWchxylh0LQ+vk58/Q6zQgsVd1BE64CQzWo1u0lO+QKAI9W4er+pmYc44Tu oIMUQUZ7XNNbItG132zjaLZ3beoM/7jFKJwAaH073hrlnzAm3po0JGIAabcVMV7hZIHR +VVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790003685; x=1790608485; h=cc:to:message-id:content-transfer-encoding:content-type :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=+sC0Yvqh8Q5nitoPDOO2xtDXj5k7Je/RXYaZIXdOYtg=; b=wep1em9fjIKRu2vZ/hqLxrZQUlF4mkRw/OqM00PG07IX78Pek31VSXVxKj7AF99kA4 decTBJtod6lug1pMsUiX+2yV1DGqflsXebQhI3D2ZZXLwYJhrhXo7NKEQXGmu13KcHA9 dyh7lzu9gsyWu6c6s7AN7fDaxIG+vLPaohVLmyeZ6ipAXcxBqHQcojUHeXndsYW06UmO 3hVW9VHBuVyuA6OMKhhPRwuqg+0gGapiD+kqeZA2oMJSghYkl6f7pQBSBMvrF5xMeuk+ toUnH+WevTUfhjwkUekPiknXJpyEg9SImrUEtK5mkMQaGzwZ2fSenPiFSDovLCcYgrnO EMUQ== X-Gm-Message-State: AFuF++mcmABcyXl/oVPE1suk/JuIQk1f30Uj8lWokKvgglPldTXkZDqd hwAzjut+vqxUKpktjDjDpT8JkAt6RWf2GirHBVP+wNmOnJYy5OW6FjC3Ysq8j64nmro4RAHF5V0 j6eYo4y5+prXQ3kvBmJ0XscWpHsBKTU8UVxm04zABw6/qSfI30GM3N/rZ5fQDIsrKOg== X-Gm-Gg: AYBFou06ZwtFSCQSi8wYq0cT319FGk9MhV4oEuzn0+a2as8NeDqg65dFUybxJhPsXfL 2uYI7DshM7arl6+515sBcIkGl3RBFH6iy1FdUIGpQuX8fXu6Fa3SF+bA2ilPhnnW4MUpp3sGgCo nuuwJ+SVcJ9x2h/qZHDnYDViyQk9r7vwE41IE4v0JlIhgGXeow2SmGnPBtkeC4cZXZl5zL4IU28 ugv8AOWS0xlsiwototSm/C7uMKBF93wTu0z5xbHJZkXQks0l7H/iGK+qQw/Vh04CAUl04YOvLqp 2sU+gECz+21eCeBuIkXLYknby2O86isiRGCQW4cbvRTLBZ5V/Pp/q61mgZajS5ccTXbXCkuLc7c 1mMSULldXj/QWiI5apr64HT4ZHpW6YLHYQzpbcLu9V97lFRbm2TpGlbrBB1BfU8jfY5tVH+r2gd 9pAnGXkaCnJXWyMNu+Zajw X-Received: by 2002:a17:902:e741:b0:2c0:a555:80d6 with SMTP id d9443c01a7336-2ddb1aaf260mr174889455ad.2.1790003685063; Mon, 21 Sep 2026 08:14:45 -0700 (PDT) X-Received: by 2002:a17:902:e741:b0:2c0:a555:80d6 with SMTP id d9443c01a7336-2ddb1aaf260mr174888945ad.2.1790003684406; Mon, 21 Sep 2026 08:14:44 -0700 (PDT) Received: from hu-pankpati-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ddc17ba54dsm35708185ad.54.2026.09.21.08.14.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2026 08:14:43 -0700 (PDT) From: Pankaj Patil Date: Mon, 21 Sep 2026 20:43:41 +0530 Subject: [PATCH] dma-buf: system_heap: align allocation orders to ARM64 hugepage sizes Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260921-dma_buf_improvement-v1-1-23d82e771dec@oss.qualcomm.com> X-B4-Tracking: v=1; b=H4sIAKRJsWoC/yXM0QqDIBTG8VeRcz2HFRr1KiPC7LidC7WpSRC9+ 2Rd/j74/ickjIQJRnZCxEKJgq9oHgzMR/s3clqroRWtEkOj+Or0vOx2JrfFUNChz1yLQWqUqkd poT63iJaOf/U13Y743Ws83yMsOiE3wTnKIyv9s+PRdDBd1w+O3lTQkQAAAA== X-Change-ID: 20260916-dma_buf_improvement-a095ae567e5f To: Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Philipp Stanner , Juan Yescas , Prakash Gupta Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Pankaj Patil X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1790003679; l=3701; i=pankaj.patil@oss.qualcomm.com; s=20251121; h=from:subject:message-id; bh=aYodpMjhjueRZKnta3cynI3TH/uCot98oWss+KQn/3k=; b=+fXkiGBUsgSDeAWL8tAR41f8+8vf5VxpHd5B7u4dqwtqgoHWuab3DmhyN+j3ssNg9tGAgFslE FlGWAWAqZ27D0cmreba2JmnHXGa9MWxZGkFmQY4Q8A/GxWgPpu+fdk7 X-Developer-Key: i=pankaj.patil@oss.qualcomm.com; a=ed25519; pk=pWpEq/tlX6TaKH1UQolvxjRD+Vdib/sEkb8bH8AL6gc= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTIxMDIyMiBTYWx0Z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MCu3Bhb60z6o4u071p g/UE5E+FjyMVukZSPenKfxIJw1FescI= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-21_05,2026-09-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 spamscore=0 adultscore=0 phishscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609210222 From: Prakash Gupta System heap currently uses a fixed allocation order, {8, 4, 0} while requesting pages from the buddy allocator which correspond to 1 MiB, 64 KiB and 4 KiB only on systems using 4 KiB page size. Extending on patch from Juan [1] for ARM64 targets with LPAE, a 1 MiB allocation does not correspond to a PMD block size. For a 4 KiB-granule IOMMU, a 2 MiB allocation can be mapped using a single PMD block entry, reducing IOMMU TLB pressure by requiring fewer translation entries. Use allocation orders corresponding to the ARM64 PMD block and contiguous-PTE sizes for 4 KiB, 16 KiB and 64 KiB page configurations. ARM64 applicable orders are selected for ARM64 targets with default orders being used for rest of the architectures. [1] https://lore.kernel.org/all/20250417201913.2393655-1-jyescas@google.com/ Co-developed-by: Juan Yescas Signed-off-by: Juan Yescas Co-developed-by: Pankaj Patil Signed-off-by: Pankaj Patil Signed-off-by: Prakash Gupta --- drivers/dma-buf/heaps/system_heap.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index c8959eadc71d..7a3e26c3dd43 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -57,12 +58,30 @@ struct dma_heap_attachment { | __GFP_COMP) static gfp_t order_flags[] = {HIGH_ORDER_GFP, HIGH_ORDER_GFP, LOW_ORDER_GFP}; /* - * The selection of the orders used for allocation (1MB, 64K, 4K) is designed - * to match with the sizes often found in IOMMUs. Using order 4 pages instead - * of order 0 pages can significantly improve the performance of many IOMMUs - * by reducing TLB pressure and time spent updating page tables. + * For ARM64, allocation orders correspond to the PMD block and CONT PTE + * hugepage sizes for each CPU page granule, which also align with the + * TLB entry sizes of a 4K-granule IOMMU (arm-smmu, arm-smmu-v3). + * Each order = (level_shift - PAGE_SHIFT), derived from: + * PMD_SHIFT = (PAGE_SHIFT - 3) * 2 + 3 + * CONT_PTE_SHIFT = CONFIG_ARM64_CONT_PTE_SHIFT + PAGE_SHIFT + * + * 4K CPU (PAGE_SHIFT=12): PMD=2MiB (21-12=9), CONT_PTE=64KiB (16-12=4) + * 16K CPU (PAGE_SHIFT=14): PMD=32MiB (25-14=11), CONT_PTE=2MiB (21-14=7) + * 64K CPU (PAGE_SHIFT=16): PMD=512MiB (29-16=13), CONT_PTE=2MiB (21-16=5) + */ +#if defined(CONFIG_ARM64) && (PAGE_SIZE == SZ_4K) +static const unsigned int orders[] = {21 - PAGE_SHIFT, 16 - PAGE_SHIFT, 0}; +#elif defined(CONFIG_ARM64) && (PAGE_SIZE == SZ_16K) +static const unsigned int orders[] = {25 - PAGE_SHIFT, 21 - PAGE_SHIFT, 0}; +#elif defined(CONFIG_ARM64) && (PAGE_SIZE == SZ_64K) +static const unsigned int orders[] = {29 - PAGE_SHIFT, 21 - PAGE_SHIFT, 0}; +#else +/* Fallback to default allocation order for non-arm64 architectures + * On 4K-page systems, these orders correspond to 1MiB, 64KiB and 4KiB, + * matching sizes commonly supported by IOMMUs. */ static const unsigned int orders[] = {8, 4, 0}; +#endif #define NUM_ORDERS ARRAY_SIZE(orders) static int system_heap_set_page_decrypted(struct page *page) --- base-commit: c2cd463d6ee7d55a3ec0719d93c49ff99022d58f change-id: 20260916-dma_buf_improvement-a095ae567e5f Best regards, -- Pankaj Patil