From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796117951; b=YSfviwwQytJpiyNwbru5daEq4KNUIwZqEuI6SWwmOr2hBfgtPbMb4kUpLE3KZxsdsCjg 2GY1dXSpxl5EJnGtaceJ5SOh5EOd4keKYEmbjHSF+Eez1gAmj101UXpLY1wjN/N2zjHje KRY1ihb5urM0KJHJblZvfTvVX4LTbmwYqam0KZ6hhL/Db7h4sOePTqE/AVCHIr6KY+YVC Zl/TijgS+FTcAsUHG2qjHUwhA4/R7xU7H0slcNs6IErF/Aifm4J+3nyGLLYq1mfSbO4SU 4AFjEjd2EDiAtNJ4XvvhRJ+Fk4x4oQ123CfHvo6vfOtPQXEpdRtTBO33dNkEogFztYw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796117951; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Message-ID: Date:MIME-Version:User-Agent:From:Subject:To:Cc:References: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding: X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Spam-Info: X-Authority-Analysis:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=UrIxnxHMI8gezbN6gFNjRbtB4Gh3K7IDe7P+1/m+lEY=; b=j0vemaoKLyvuZHquLZqsXaG1ev5HevqVjl+N82dskvpxsbeUbnMUrWwCpuAkX09w+1C3 B5hqmwUHmUuDwgSxCrFS0yoEUQymKoI3LozAV3n7Ci7Z3K2ISrXhhoLgNIaJ+gS4Otjh7 O+Gof9ji60sfKMdsSI7xGNNB9+4OyLIVU1HpmtUDIPkFWcgD3E3wH80vzdXT5ndowceUH 15F7MjnPQCse1jLI4QcrUfSJARSRk7G1TtTz7ryhwpK58rVpbO0nOCxQIzYH/GCOYb+Lw hpkNdv4S+BxYIbr2wyFe7mAWXsdildjCF+0NybNVdawQUkYS/hKJ9pfZGieNdtzLisw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=GTWaSxn7; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=e5ejGyD2; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6648A606A31A for ; Tue, 1 Dec 2026 09:39:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6648A606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.a=rsa-sha256 header.s=qcppdkim1 header.b=GTWaSxn7; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=e5ejGyD2 Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B18LhR53573900 for ; Tue, 1 Dec 2026 09:39:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= UrIxnxHMI8gezbN6gFNjRbtB4Gh3K7IDe7P+1/m+lEY=; b=GTWaSxn7UkOVgMBi x+0jy4LPGqPIlEpfgCm7zUEu2x8m28bFN2acwNDLnjhWMH3a1/Gldt9l/nfHiBRy 5O5jlBDnSMowhmGGxHui3SsdHRGgJTH2yU6nkqZ/P7hLRJDKvlUrCJ9YS1M0OfL5 iAXERNO5p9DacQxRsbqrsC0v3oeqRL+JCgy+WTgY2r5EWP5BqF2+wIVfhMkeJixi wYfTiL6kELyhpzXcKjpwbNyVL4z5KpOP2pDJygx563Le3AUBjuJPTVNS7lFFfCEL YdBu5g80tvicK6njA8zp8kUc8XJ6PLAVhJDpX/qzgLH4Hdv1o038SWHiLJ4euLfE wjiKSg== Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j9tng0btx-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2026 09:39:09 +0000 (GMT) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-8a05b68f851so9171155b3a.1 for ; Tue, 01 Dec 2026 01:39:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796117949; x=1796722749; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=UrIxnxHMI8gezbN6gFNjRbtB4Gh3K7IDe7P+1/m+lEY=; b=e5ejGyD2QFZ69OZzu+ov/smIyX4SXQc8tjA0Ezl9MsAMM/bVf5zNyNeUEX9OWi+dZW pD1CihIiTfvChPXdx1Q+/9fNvoOVj+vinLwAqYPO40j/78t+2GlwK5g1GcYwwK+7VnIx LznJvlQd1e9M5oHAuUbAia1e8ACi8BRGemp4ND00gVlBEVdngSEIbji30yHLi+SFQ2pV iBhOLJB7dvXpVfpASnzjB1dbTqiHL+kjFWOmti8rPNSxeie4WkUWG98TEJZI1CP9SyiG J8zgktOSP0QqYvAQNgHu5o8HF2BCvWg+e3nr2VMl9Vjd/zryttIEMQpqv2z+zM3IdtoP Zlow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796117949; x=1796722749; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=UrIxnxHMI8gezbN6gFNjRbtB4Gh3K7IDe7P+1/m+lEY=; b=2hQbaCIuVAH/qQjk5T6IQ6XZqVCptdm/PnfrrPhM84+rxRSw+ljrzJotvwqwXDmchz HPmxkyyCGefUxcd+g6UJ8kL2zA/VHu9dtVEENrVNVSDN8S1OupUXKfEo+PWVnwHYI+lF 4wr0wj0G30RhEgzsPFMm1ElPYn+l5KQlZow4MWrJcLv1Jt5V3tidSlf/fZcmmL3jYkd5 TlpyAJsS2xxp5IzFAPL0W+Q0GwvMwypHgf4uMOi9EW/+wkzZ9fH+ZjIlbFOLq9hT/yWt 0kM0UXC1TPXyfIrZjT04+tXw9eT9mxpvUkn6LRsJzRn8NQkB3z1wjWO8K2vh6D4Sd19p N7yg== X-Forwarded-Encrypted: i=1; AL+hErG4hqXaPebLMZ8Ig5E12VlZTp40QOXkhh/RG+9SIyuUfD4e+7CkcWYBzmeg+tMRSUZGdoVQOuURGu4BvXY=@vger.kernel.org X-Gm-Message-State: APuU4Z9W5FM5gQcKj+okCT+aA+NKT1HtLgok4wTopLTMO1u0p0uxCaYY +qgz+76cMLo4UoKBvUCTZKJAr8cX8ugWB9dgSGJ6mEvzrKJmEgixWVPrD/ztVZcPcyoHzh8K0am yIOURt/U2EybgxIDHpy5ECFGGnOuRbg8q6nBn9L5seD18Xmb4yK15XoRSYibyGukHI2E= X-Gm-Gg: AZFdTZf88QDg3zcBGLzgPwcswBV8oHT4t7tuo9jyy+i5v4QH53H0AyBPsm4S934mYeV bQ21bKqzME+DE91tkzfCWan9KNbF6adeBlB2rbUOYroFDz9Y8xEQuVsuVauG1ls3Zcmjl/YqWFU nmkHwLIQUFRotRyuF1qVMsMejyzsQSr2DvhGH7GcqEUR0qXFb67hSW5hfPUcf4leG+VKnXY542m psj4wATWSHZHABiPD4a/hVt/FOvBzIQH92CPmf92o0kO33kDtwORFXHQF1apxDXa+Spyb9K55VH GaPm6d9bBnBKA//Uqna/xPKPOtM5IpGrqqZgjKtagdf6eJtwJB7sXMiOS1wBGqMkenJxDE1qNHN MgxwQ3OtPsWcnZ40KhAXkDcZjd4K74JzKQqh7doASWYpIQKhDQWnditW345a9wk3IxTDLtO2Kbv ozw9S/ X-Received: by 2002:a05:6a21:e113:b0:3de:48ab:3b90 with SMTP id adf61e73a8af0-4014db62867mr30720785637.26.1796117948500; Tue, 01 Dec 2026 01:39:08 -0800 (PST) X-Received: by 2002:a05:6a21:e113:b0:3de:48ab:3b90 with SMTP id adf61e73a8af0-4014db62867mr30720765637.26.1796117947868; Tue, 01 Dec 2026 01:39:07 -0800 (PST) Received: from [10.218.39.50] ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87077fe3fsm20060093b3a.4.2026.12.01.01.39.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Dec 2026 01:39:07 -0800 (PST) Message-ID: <6ea181d4-3b6c-4ad9-9aba-30a8d596e8a0@oss.qualcomm.com> Date: Tue, 1 Dec 2026 15:09:03 +0530 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Vijayanand Jitta Subject: Re: [PATCH v5] iommu/io-pgtable-arm: Add support for contiguous hint bit To: Robin Murphy , Will Deacon , "Joerg Roedel (AMD)" Cc: linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Prakash Gupta References: <20260921-iommu_contig_hint-v5-1-e7fbd1c3774d@oss.qualcomm.com> <2a2a81fc-5402-4f07-aaf2-a0dc853f1bad@arm.com> Content-Language: en-US In-Reply-To: <2a2a81fc-5402-4f07-aaf2-a0dc853f1bad@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: pHeH1Qcy5Z6dSRaQlYrQWiNBEet_z-cH X-Proofpoint-GUID: pHeH1Qcy5Z6dSRaQlYrQWiNBEet_z-cH X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDAzOCBTYWx0ZWRfX68ndjMTGLkR9 sJV4LKXJrWSDKx5sxOsu7AeJEz5LEisCiOhTMLQyqmOZNJm50Siwcy/cYf2shpBpYolnPirhCfc /8HMWhu2pPbm0XMpgaHPhn4VZ3GesjjgNzqKuO9S0UZfFBWxVdmxDJKZF35K3cLc03AeP5qD5l9 /VDLq+D3vhiDvXvR6I1tPgv2bqlkcq6o0CrJl3PF43l7bez6Pwxr8ekkFhUJNlnSUdWwtDre1k3 CeO/9CmxezCupJde8nz2afr90j/IMRbJhHGGNZofjYaht6efTHGdmSVh+zrrTmhiAPuNB/qu4KF UHWuzhwQYPNGlEFwJeRm6WbODF6RhfrCawfEAX7r+va4A1F7QjTBXJI1KaxmbRyOA0Ew5TWOetc K4bfaKxOpS0gdJwkNacri2rVCjx5qd+c50iyQVrI3uQruoLxLn/aNihvhh24aCRihRnNIoIOCHG 90UCldj6E9gtT5VoUMA== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDAzOCBTYWx0ZWRfX3x+Ypr0vfWZA ln0TTXamxsgKGO/GgDtbc98EzNb83au2Ru8bijyXQYOm22QKxTr90NXr8PW2LTUfuxR0Bz4pxGa ASQGsbQAr7AYyPr/Ojx4wiwOeWxhV1M= X-Authority-Analysis: v=2.4 cv=O5ysLx9W c=1 sm=1 tr=0 ts=6b0e95bd cx=c_pps a=rEQLjTOiSrHUhVqRoksmgQ==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=bC-a23v3AAAA:8 a=7CQSdrXTAAAA:8 a=tA7aZXjiAAAA:8 a=JfrnYn6hAAAA:8 a=hXNdBlZ-3iUmYrvAi5UA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=2VI0MkxyNR6bbpdq8BZq:22 a=FO4_E8m0qiDe52t0p3_H:22 a=a-qgeE7W1pNrGK8U0ZQC:22 a=kIIFJ0VLUOy1gFZzwZHL:22 a=1CNFftbPRP8L7MoqJWF3:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_01,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 adultscore=0 impostorscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010038 On 10/10/2026 12:27 AM, Robin Murphy wrote: > On 21/09/2026 12:14 pm, Vijayanand Jitta wrote: >> From: Prakash Gupta >> >> Add support for the contiguous hint (CONT) bit in ARM LPAE page tables. >> When a set of consecutive PTEs map a naturally aligned contiguous block of >> memory, set CONT on every descriptor in that group so the hardware can >> combine translations and improve TLB reach. >> >> Advertise the supported CONT group sizes in pgsize_bitmap. Callers select >> those sizes through the normal page-size selection path; io-pgtable-arm >> then installs the corresponding tagged descriptors directly. A partial >> unmap of a tagged CONT group is rejected before modifying any descriptor, >> so a rejected request cannot leave the group partly unmapped. >> >> The IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT quirk allows SMMU drivers to disable >> CONT support for hardware with implementation-specific errata. >> >> Suggested-by: Robin Murphy >> Signed-off-by: Vijayanand Jitta >> Signed-off-by: Prakash Gupta >> --- >> Changes in v5: >> - Keep CONT sizes that exactly span the configured IAS or OAS, allowing a >>    valid mapping at address zero. >> - Derive CONT sizes from the architecture-valid base page-size bitmap and >>    constrain the final result by IAS and OAS, replacing the bespoke >>    arm_lpae_get_cont_sizes() helpers. >> - Guard CONT-size expansion against 32-bit overflow. >> - Let callers select exact CONT sizes through pgsize_bitmap, and remove the >>    internal prefix/group/suffix promotion path. >> - Reject a partial CONT-group unmap before any PTE is cleared, making the >>    rejection a complete no-op. >> - Link to v4: https://lore.kernel.org/all/20260804-iommu_contig_hint-v4-1-d7a47ed5db98@oss.qualcomm.com/ >> >> Changes in v4: >> - Merge each run of consecutive aligned (or consecutive non-aligned) >>    num_cont windows within arm_lpae_install_leaf() into a single >>    arm_lpae_init_pte() call instead of one call per window. idx and >>    paddr both advance by block_size per entry, so once a window >>    qualifies (or fails to qualify) for the CONT hint, every later whole >>    window in the same call does too - collapsing the common fully- >>    aligned or fully-unaligned case back down to one call, matching v2's >>    call count without reintroducing v2's alignment gaps. >> - Fix min_t(int, pgcount, max_entries) truncating pgcount (size_t) to a >>    signed int in both __arm_lpae_map() and __arm_lpae_unmap(), which >>    could go negative and spin the caller's while (pgcount) loop forever >>    for a large enough single request - especially reachable now that >>    pgcount is scaled by num_cont (up to 128) for whole-CONT-group >>    requests. Compare in size_t via min_t(size_t, ...) instead; the >>    result remains bounded by max_entries before being stored back into >>    the int num_entries. Reported by the Sashiko AI review bot on v3. >> - Stop short of the offending entry instead of returning 0 outright >>    when __arm_lpae_unmap() detects a misaligned CONT group mid-loop. >>    Earlier entries in the same call may already have had non-leaf >>    sub-tables torn down and freed, so returning 0 both under-reports >>    the actual unmap progress to the caller and skips the bulk >>    clear/gather for those already-freed entries. Breaking out of the >>    loop at the current index lets the existing post-loop clear/gather >>    path handle entries [0, i) correctly and report i * size unmapped. >>    Reported by the Sashiko AI review bot on v3. >> - Link to v3: https://lore.kernel.org/all/20260722-iommu_contig_hint-v3-1-10923a683441@oss.qualcomm.com/ >> >> Changes in v3: >> - Collapse arm_lpae_cont_ptes()/arm_lpae_cont_blks()/ >>    arm_lpae_cont_pte_size()/arm_lpae_cont_blk_size()/ >>    arm_lpae_find_num_cont() into a single arm_lpae_num_cont(size_t size) >>    helper, since leaf/block/L1-block sizes never overlap across granules. >> - Fix arm_lpae_pte_is_contiguous_range() never checking that iova/paddr >>    are aligned to the contiguous group size, by removing it entirely - >>    __arm_lpae_map()'s new arm_lpae_install_leaf() helper scans for >>    aligned sub-chunks and independently verifies paddr alignment for >>    each one before applying the CONT hint. >> - Fold the CONT case into __arm_lpae_map()'s existing size == block_size >>    leaf path instead of duplicating arm_lpae_init_pte() in a separate >>    branch. A request whose size exactly matches a whole CONT group is >>    normalized down to block_size/scaled pgcount so it reaches that path; >>    arm_lpae_install_leaf() then walks the resulting range in chunks, >>    tagging only the sub-chunks that are both index-aligned and >>    paddr-aligned to the group size, since a single map_pages() call at >>    the plain block_size can still contain such an aligned group midway >>    through a larger, otherwise ungrouped range. >> - Replace the unmap-side WARN_ON_ONCE(!IS_ALIGNED(iova, size)) with a >>    check on the actual ARM_LPAE_PTE_CONT bit of the PTEs being cleared. >>    The previous check incorrectly warned on any unmap whose size >>    happened to numerically match a CONT group size, even when the >>    underlying PTEs were never CONT-tagged (e.g. because the original >>    iommu_map() wasn't group-aligned), and even though iommu_unmap() can >>    legitimately assemble such a size from multiple independent prior >>    iommu_map() calls. >> - Close a leak where ARM_MALI_LPAE would gain CONT-sized entries in its >>    pgsize_bitmap despite the format having no CONT bit, by having >>    arm_mali_lpae_alloc_pgtable() set IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT >>    internally rather than special-casing the format in the shared >>    arm_lpae_restrict_pgsizes()/arm_lpae_get_cont_sizes() path. >> - Gate each contiguous-hint size in arm_lpae_get_cont_sizes() on whether >>    a single group actually fits within the configured IAS/OAS, so e.g. a >>    16G level-1 CONT group is never advertised for an IAS too small to >>    address it. >> - Link to v2: https://patch.msgid.link/20260721-iommu_contig_hint-v2-1-90c731a41163@oss.qualcomm.com >> >> Changes in v2: >> - Extend contiguous hint support to level-1 (1G) blocks for the 4K granule, >>    adding a CONT L1 (16G) grouping alongside the existing CONT PTE/CONT Block >>    sizes. >> - Replace the compile-time CONFIG_IOMMU_IO_PGTABLE_CONTIG_HINT Kconfig option >>    with a runtime quirk, IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT, so SMMU drivers >>    can opt out per page table instance instead of at build time. >> - Simplify __arm_lpae_map() to program the CONT-sized block directly via >>    arm_lpae_init_pte() instead of recursing into the next level with an >>    adjusted pgcount. >> - Reject unmaps that are not aligned to the contiguous group size with >>    WARN_ON_ONCE(), instead of clearing the CONT bit on a partial group before >>    invalidation. >> - Link to v1: https://patch.msgid.link/20260618-iommu_contig_hint-v1-1-4502a59e6388@oss.qualcomm.com >> >> Changes in v1: >> - Initial version. >> >> To: Will Deacon >> To: Robin Murphy >> To: "Joerg Roedel (AMD)" >> Cc: linux-arm-msm@vger.kernel.org >> Cc: linux-arm-kernel@lists.infradead.org >> Cc: iommu@lists.linux.dev >> Cc: linux-kernel@vger.kernel.org >> --- >>   drivers/iommu/io-pgtable-arm.c | 125 ++++++++++++++++++++++++++++++++++++----- >>   include/linux/io-pgtable.h     |   3 + >>   2 files changed, 115 insertions(+), 13 deletions(-) >> >> diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c >> index 476c0e25631af..01d98959c514f 100644 >> --- a/drivers/iommu/io-pgtable-arm.c >> +++ b/drivers/iommu/io-pgtable-arm.c >> @@ -86,6 +86,21 @@ >>   /* Software bit for solving coherency races */ >>   #define ARM_LPAE_PTE_SW_SYNC        (((arm_lpae_iopte)1) << 55) >>   +/* PTE Contiguous Bit */ >> +#define ARM_LPAE_PTE_CONT        (((arm_lpae_iopte)1) << 52) >> + >> +/* >> + * Contiguous hint group sizes per granule: >> + * >> + *------------------------------------------------------------------ >> + *| Page Size | CONT PTE |  Block  | CONT Block | L1 Block | CONT L1 | >> + *------------------------------------------------------------------ >> + *|     4K    |   64K    |   2M    |    32M     |    1G    |   16G   | >> + *|    16K    |    2M    |  32M    |     1G     |          |         | >> + *|    64K    |    2M    | 512M    |    16G     |          |         | >> + *------------------------------------------------------------------ >> + */ >> + >>   /* Stage-1 PTE */ >>   #define ARM_LPAE_PTE_AP_UNPRIV        (((arm_lpae_iopte)1) << 6) >>   #define ARM_LPAE_PTE_AP_RDONLY_BIT    7 >> @@ -453,6 +468,24 @@ static arm_lpae_iopte arm_lpae_install_table(arm_lpae_iopte *table, >>       return old; >>   } >>   +static int arm_lpae_num_cont(size_t size) >> +{ >> +    switch (size) { >> +    case SZ_4K: >> +    case SZ_2M: >> +    case SZ_1G: >> +        return 16; >> +    case SZ_64K: >> +    case SZ_32M: >> +    case SZ_512M: >> +        return 32; >> +    case SZ_16K: >> +        return 128; >> +    default: >> +        return 1; >> +    } >> +} >> + >>   static int __arm_lpae_map(struct arm_lpae_io_pgtable *data, unsigned long iova, >>                 phys_addr_t paddr, size_t size, size_t pgcount, >>                 arm_lpae_iopte prot, int lvl, arm_lpae_iopte *ptep, >> @@ -462,20 +495,41 @@ static int __arm_lpae_map(struct arm_lpae_io_pgtable *data, unsigned long iova, >>       size_t block_size = ARM_LPAE_BLOCK_SIZE(lvl, data); >>       size_t tblsz = ARM_LPAE_GRANULE(data); >>       struct io_pgtable_cfg *cfg = &data->iop.cfg; >> -    int ret = 0, num_entries, max_entries, map_idx_start; >> +    int num_cont = arm_lpae_num_cont(block_size); >> +    size_t cont_size = 0, entries_per_map; >> +    int num_entries, max_entries, map_idx_start; >> +    bool cont = false; >> + >> +    if (num_cont > 1 && block_size <= SIZE_MAX / num_cont) >> +        cont_size = num_cont * block_size; > > Again, why can't this just be: > >     if (num_cont > 1 && size / num_cont == block_size) { >         size = block_size; >         pgcount *= num_cont; >         prot |= ARM_LPAE_PTE_CONT; >     } > > Although TBH even just one non-constant division is still more than necessary, as "block_size * num_cont == size" will actually work correctly for 32-bit anyway (since unsigned overflow in C is well-defined and "size" cannot be 0). > > (I guess if you really really wanted to then you could put an "#ifdef CONFIG_64BIT" around the "case SZ_1G:" in arm_lpae_num_cont(), but I'd hope it's sufficiently obvious already why it could never realistically matter.) > Ack, simplified as suggested. >>       /* Find our entry at the current level */ >>       map_idx_start = ARM_LPAE_LVL_IDX(iova, lvl, data); >>       ptep += map_idx_start; >>         /* If we can install a leaf entry at this level, then do so */ >> -    if (size == block_size) { >> +    if (size == block_size || >> +        (!(cfg->quirks & IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT) && >> +         size == cont_size)) { >> +        int ret; >> + >> +        cont = size == cont_size; >> +        if (cont && (!IS_ALIGNED(iova, size) || !IS_ALIGNED(paddr, size))) >> +            return -EINVAL; > > We don't validate that the addresses are aligned to "size" in any other case, so why complicate this one? Either we trust callers to interpret pgsize_bitmap correctly, or we don't. > Ack, dropped the CONT alignment validation and rely on callers to honour pgsize_bitmap, consistently with the existing map_pages() contract. >> + >> +        entries_per_map = size / block_size; > > Why are we recalculating something we know already (cont ? num_cont : 1), in about the most expensive way possible!? > Ack, removed entries_per_map and use num_cont directly. >>           max_entries = arm_lpae_max_entries(map_idx_start, data); >> -        num_entries = min_t(int, pgcount, max_entries); >> -        ret = arm_lpae_init_pte(data, iova, paddr, prot, lvl, num_entries, ptep); >> +        num_entries = min_t(size_t, pgcount, >> +                    max_entries / entries_per_map) * entries_per_map; > > This is so confusing - what does "per_map" mean, and what does the whole thing even achieve? Is it once again just conditionally multiplying by num_cont in about the most expensive way possible? > Ack, this was unnecessary since aligned CONT groups cannot cross a table boundary. Removed it and retained the existing num_entries calculation. >> +        if (!num_entries) >> +            return -EINVAL; > > How could that ever happen at all!? > Ack. removed this aswell. >> +        if (cont) >> +            prot |= ARM_LPAE_PTE_CONT; >> + >> +        ret = arm_lpae_init_pte(data, iova, paddr, prot, lvl, >> +                    num_entries, ptep); >>           if (!ret) >> -            *mapped += num_entries * size; >> - >> +            *mapped += num_entries * block_size; >>           return ret; >>       } >>   @@ -660,12 +714,18 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, >>   { >>       arm_lpae_iopte pte; >>       struct io_pgtable *iop = &data->iop; >> +    size_t block_size = ARM_LPAE_BLOCK_SIZE(lvl, data); >> +    int num_cont = arm_lpae_num_cont(block_size); >> +    size_t cont_size = 0, entries_per_map; >>       int i = 0, num_entries, max_entries, unmap_idx_start; >>         /* Something went horribly wrong and we ran out of page table */ >>       if (WARN_ON(lvl == ARM_LPAE_MAX_LEVELS)) >>           return 0; >>   +    if (num_cont > 1 && block_size <= SIZE_MAX / num_cont) >> +        cont_size = num_cont * block_size; >> + >>       unmap_idx_start = ARM_LPAE_LVL_IDX(iova, lvl, data); >>       ptep += unmap_idx_start; >>       pte = READ_ONCE(*ptep); >> @@ -675,9 +735,27 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, >>       } >>         /* If the size matches this level, we're in the right place */ >> -    if (size == ARM_LPAE_BLOCK_SIZE(lvl, data)) { >> +    if (size == block_size || >> +        (!(data->iop.cfg.quirks & IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT) && >> +         size == cont_size)) { >> +        entries_per_map = size / block_size; >>           max_entries = arm_lpae_max_entries(unmap_idx_start, data); >> -        num_entries = min_t(int, pgcount, max_entries); >> +        num_entries = min_t(size_t, pgcount, >> +                    max_entries / entries_per_map) * entries_per_map; >> +        if (!num_entries) >> +            return 0; > > All the same comments as before for all this lot, although in this case we could actually do with the "bool cont" for the sake of the validation below. > >> + >> +        /* >> +         * A CONT group must be invalidated as a unit. Reject a request that >> +         * starts or ends inside a tagged group before changing any PTEs. >> +         */ >> +        if ((READ_ONCE(*ptep) & ARM_LPAE_PTE_CONT && > > We already have the first entry read into "pte", we don't need to read it again. > Ack. >> +             !IS_ALIGNED(iova, cont_size)) || >> +            (READ_ONCE(ptep[num_entries - 1]) & ARM_LPAE_PTE_CONT && >> +             !IS_ALIGNED(iova + num_entries * block_size, cont_size))) { > > How's that ever going to do anything if we've already rounded "num_entries" down to to a multiple of "num_cont" (i.e. the confusingly quasi-redundant "entries_per_map") above? > > That said, I think this could be even simpler anyway - for any _valid_ unmap of a cont range the original "size" will be the cont size, so it should simply be the case that if we ever see PTE_CONT set when the original size was _not_ the cont size (i.e. just the base block_size) then it must be an erroneous partial unmap, so that can just be an extra condition in the loop below where we're checking every PTE already. > > Again as for the IOVA alignment, we should either factor the cont size into the ARM_LPAE_LEVEL_IDX() calculations to be consistent with the existing behaviour (perhaps another argument for having it as a cont_shift rather than a num_cont), or if we did want to change and start checking for bogus usage which should never exist anyway then we should just test "iova & (pgsize - 1)" right after we validate "pgsize" itself at the very beginning. What we should not have is inconsistently different behaviour depending on the request size. > Agreed. I simplified this as suggested, a valid CONT unmap is identified when it is the effective CONT size at the current level; otherwise, seeing PTE_CONT in the existing descriptor loop indicates an invalid partial unmap. Also made IOVA alignment a uniform iova & (pgsize - 1) validation at unmap_pages() entry. >> +            WARN_ONCE(true, "Unmap of a partial CONT IOPTE group is not allowed"); >> +            return 0; >> +        } >>             /* Find and handle non-leaf entries */ >>           for (i = 0; i < num_entries; i++) { >> @@ -691,7 +769,8 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, >>                   __arm_lpae_clear_pte(&ptep[i], &iop->cfg, 1); >>                     /* Also flush any partial walks */ >> -                io_pgtable_tlb_flush_walk(iop, iova + i * size, size, >> +                io_pgtable_tlb_flush_walk(iop, >> +                              iova + i * block_size, block_size, >>                                 ARM_LPAE_GRANULE(data)); >>                   __arm_lpae_free_pgtable(data, lvl + 1, iopte_deref(pte, data)); >>               } >> @@ -702,9 +781,10 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, >>             if (gather && !iommu_iotlb_gather_queued(gather)) >>               for (int j = 0; j < i; j++) >> -                io_pgtable_tlb_add_page(iop, gather, iova + j * size, size); >> +                io_pgtable_tlb_add_page(iop, gather, >> +                            iova + j * block_size, block_size); >>   -        return i * size; >> +        return i * block_size; >>       } else if (iopte_leaf(pte, lvl, iop->fmt)) { >>           WARN_ONCE(true, "Unmap of a partial large IOPTE is not allowed"); >>           return 0; >> @@ -943,8 +1023,23 @@ static void arm_lpae_restrict_pgsizes(struct io_pgtable_cfg *cfg) >>       } >>         cfg->pgsize_bitmap &= page_sizes; >> +    if (!(cfg->quirks & IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT)) { >> +        unsigned long sizes = cfg->pgsize_bitmap; >> + >> +        while (sizes) { >> +            unsigned long size = BIT(__ffs(sizes)); >> +            int num_cont = arm_lpae_num_cont(size); >> + >> +            if (size <= ULONG_MAX / num_cont) >> +                cfg->pgsize_bitmap |= num_cont * size; >> +            sizes &= ~size; >> +        } >> +    } > > Open-coded for_each_set_bit()? > ACK. Moved to for_each_set_bit(). >> + >>       cfg->ias = min(cfg->ias, max_addr_bits); >>       cfg->oas = min(cfg->oas, max_addr_bits); >> +    cfg->pgsize_bitmap &= GENMASK_ULL(cfg->ias, 0); >> +    cfg->pgsize_bitmap &= GENMASK_ULL(cfg->oas, 0); > > This is new behaviour for all users irrespective of the new functionality - we never did it before, why start doing it now? > ACK. will remove this. >>   } >>     static struct arm_lpae_io_pgtable * >> @@ -1001,7 +1096,8 @@ arm_64_lpae_alloc_pgtable_s1(struct io_pgtable_cfg *cfg, void *cookie) >>                   IO_PGTABLE_QUIRK_ARM_TTBR1 | >>                   IO_PGTABLE_QUIRK_ARM_OUTER_WBWA | >>                   IO_PGTABLE_QUIRK_ARM_HD | >> -                IO_PGTABLE_QUIRK_NO_WARN)) >> +                IO_PGTABLE_QUIRK_NO_WARN | >> +                IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT)) >>           return NULL; >>         data = arm_lpae_alloc_pgtable(cfg); >> @@ -1103,7 +1199,8 @@ arm_64_lpae_alloc_pgtable_s2(struct io_pgtable_cfg *cfg, void *cookie) >>       typeof(&cfg->arm_lpae_s2_cfg.vtcr) vtcr = &cfg->arm_lpae_s2_cfg.vtcr; >>         if (cfg->quirks & ~(IO_PGTABLE_QUIRK_ARM_S2FWB | >> -                IO_PGTABLE_QUIRK_NO_WARN)) >> +                IO_PGTABLE_QUIRK_NO_WARN | >> +                IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT)) >>           return NULL; >>         data = arm_lpae_alloc_pgtable(cfg); >> @@ -1224,6 +1321,8 @@ arm_mali_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie) >>           return NULL; >>         cfg->pgsize_bitmap &= (SZ_4K | SZ_2M | SZ_1G); >> +    /* Mali LPAE has no CONT bit - never advertise CONT page sizes */ >> +    cfg->quirks |= IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT; >>         data = arm_lpae_alloc_pgtable(cfg); >>       if (!data) >> diff --git a/include/linux/io-pgtable.h b/include/linux/io-pgtable.h >> index e19872e37e067..7b2097aaffb09 100644 >> --- a/include/linux/io-pgtable.h >> +++ b/include/linux/io-pgtable.h >> @@ -86,6 +86,8 @@ struct io_pgtable_cfg { >>        * >>        * IO_PGTABLE_QUIRK_ARM_HD: Enables dirty tracking in stage 1 pagetable. >>        * IO_PGTABLE_QUIRK_ARM_S2FWB: Use the FWB format for the MemAttrs bits >> +     * IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT: Disable use of the contiguous >> +     *    hint for hardware affected by implementation-specific errata. >>        * >>        * IO_PGTABLE_QUIRK_NO_WARN: Do not WARN_ON() on conflicting >>        *    mappings, but silently return -EEXISTS.  Normally an attempt >> @@ -103,6 +105,7 @@ struct io_pgtable_cfg { >>       #define IO_PGTABLE_QUIRK_ARM_HD            BIT(7) >>       #define IO_PGTABLE_QUIRK_ARM_S2FWB        BIT(8) >>       #define IO_PGTABLE_QUIRK_NO_WARN        BIT(9) >> +    #define IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT    BIT(10) > > I'm not changing my mind that this chould be a positive opt-in - again, Panfrost and Panthor still don't want it, and while it is architectural for true VMSA users I'd still be a little wary of whether Adreno might get confused by suddenly getting extra sizes in its bitmap (in the case where it doesn't immediately remove them all anyway). Also it's perhaps notable that historically ipmmu-vmsa only supported cont at L3 (64KB), but I don't know if that was for a specific reason or just that it didn't expect to ever be mapping 32MB+ at once (it also didn't support 1GB blocks either). > > Thanks, > Robin. > Sure, Have made it to opt-in in v6. Thanks, Vijay >>       unsigned long            quirks; >>       unsigned long            pgsize_bitmap; >>       unsigned int            ias; >> >> --- >> base-commit: 5dd1818b15d98d4a20806cd00b1b40320b06004f >> change-id: 20260618-iommu_contig_hint-71ae491fbb52 >> >> Best regards, >> -- >> Vijayanand Jitta >> >