From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796295438; b=SE9Vstk6tax2VmFCWeaXA5//AY0xGjDIBgBZ5HXLXvPsb/0tBYhI1ZJsu/kLFcptDrrZ ToY49S2mKTZ3XpgjYLihHYE9OEE8BE3R+toBB08DVgi8oWETdwOYnz+5HTDyPm28Qx3B7 WUsxGY+3bwfEN5vxmA6IabUo81aEhPPvK93TBCmJuiQ9OFXElt8/1nYOZUNOFNBHPcnGB qCeQKvkFn0Z5+EZ/0yEr5WDd42y1vRexpWxa2Yerf6ztGBKVqtMfWYiV2iRfks4d+Q+5L 246YRQI/xCLrkIpqbnjOLOAKTvdC0qAfaeY4yd76ZR5hBlM1Ndu7NNPXUbpT1vvkChw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796295438; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To; bh=9HKn93quecmWcH+ItQ6SeciNgWx5Ex4bLTXmdUE662Q=; b=QQ8wvK7EuxAZLYGiNNWVMQ62X4RQ1muu2tfM1qoD2tepGEXW4277aO8TnYkTB4Kpev7u te3ZfxYTyfnBbnOqyQPEini2WTOGpEG63RVUW0GE/oYgXnHKYb/mEsZXbp9hzvbG3BRlx N19B/5AWGly2+jIY00Z6thDapzZgAsREEOtZ1ZSUZHgFsivBeC2dVnTJAJ0rvVM+VD+0Z jNxIXQGSJHpP8bpawMTwN05x6sP8sGzrt99eHJuq7blutyaTRAKxD/UiUcY1Ck1oHFqA+ eu1sGI4ulV3pt5Zt7F7OyvYKZ88k2WwwMcbWW3lNI3wLMheEgOh3L1sG8GvWat/+mQA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=lF3cu6bZ; arc=none smtp.remote-ip=209.85.128.44 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B63B1606A337 for ; Thu, 3 Dec 2026 10:57:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B63B1606A337 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=lF3cu6bZ Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4bb6860f867so40685e9.1 for ; Thu, 03 Dec 2026 02:57:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796295436; x=1796900236; darn=lists.linux.dev; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=9HKn93quecmWcH+ItQ6SeciNgWx5Ex4bLTXmdUE662Q=; b=lF3cu6bZgsCL8awRvSRHsvOdscC7E5/u1P7upYqeswULJ401Q5ny6Qn18CRh1PjSLJ Moe71VD+pYFig8GTeJ1Mmpbl51JFXK5uDGZKw1cRkuFGfwKPLBcebNiXyjtqPc25fN0v j6lTiswQ9Dfv9qkKCp8yB3tacucmmJ6lw/vps4e0xhJSwdz8zhFUxzEKYdaqZUNA+qwI Kppgqt9uRSuLcH6YwN4jLGL9dSJLTVRRhG/SfC6IRa+pm8zT6GvhHO8f6pPZJ4/FVVN3 bgDF+BG3qbTHSenGrdVAYh3KZUIegTjc9Tjoy9pQ7p1SLgytDB3pJ0M1y/uDiXV/MaQ6 sgBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796295436; x=1796900236; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=9HKn93quecmWcH+ItQ6SeciNgWx5Ex4bLTXmdUE662Q=; b=pBd1yeb+FRlurjugUsxBMp1lKZ4fm7JP+nzL8hE5b5GEVymK6/SgH7LZvm4DZhS5TF PfZniFvHl53OG384od/mrGmLzVeliQdakggQ+CE5B7A3WIEsKXa4EAKp0KEC4vBciRk0 q0ethR6szAnnKYvXCKBSzWV1LW9B6ueXAp1qNX2RiEPzjeQo6axiJgEdI/ssO/7SUmUB dIAaE/K4AQJKPC1e3l+U/k/0CyLclGBch6Wo7d/OWCRPK7XLX/27mO6OOpXwyXaGWgWj sD1eeN3RDp1fg7rTSJG4jybBzmcU/k904FWZdt27pOM8xdl0shWZOeNX1/HpcD062r/4 8YJg== X-Gm-Message-State: APuU4Z94PcpKCRkT/OdYH9BwaEmfkdLxWNjbEVoXgkOpuPjYJ7D3Qtqa qmdaJlrNx7zM2TuwbM++2wcxDgceMauGw+0tu2Xb1B5oCP0zH5kK20FIrOyMIrpeSQ== X-Gm-Gg: AZFdTZf72DuHhySORCV0iDNpICpz+6E1LY4gbLJh7txc89PbW4pAgWBU9jKw3nNAb02 Mt9jmaSjwlg3VpPMl7BxtNuE3m/CsNQ2Z1i6Q1qVO7Q9uhibT6AIGi9IRTFU7MF0yJnAwsau9ES dInfAb3hwVhRdrnSm9RrGgsZ+PgfTclLXDyNP7h/KJvuFWf8+M05KuZgCq70EMjZzeGVmMSIVf/ wMXX/NnBYm3coIFQ6ed2/zrHlrBqUg0UEtJaztqikQWpVCd494GI5Z2FYuBn3oBUzOMMbJMkxW1 iZ2JPH4AJ0xUBZdi4LL85ZmyyxH+kP0S5l+1WtKS9jU4O8C2xEDKYkR/qZrxi6X4AATl7XJkGc6 eEhGA08LQf47DRw52x6RNAcZWbo1j2El23NepuLA4/6cqAIAMWvD3jVO9KS2wEncj9qLVH81p2Y eOmVPjLXinz/1QNpUIDAdmiV1ZhpRBnmnQr9MN2lA0ztOrba31kLWJ4c5sO5/CH0HJH5/0JH5w5 uRCNKFGpyIzDk6P7X7lspyVbc5l3P7tLCVAPP5Ue9Caru+PsWGcnQdhwUIPUBYjx1hOi3po/1kQ k5rtlsBnH7ErhnzcAE9Adf8diR9fjbT1BR8ZCciM8aEhhJVJlkfJySu9oXRn1oxBRu9EvjKqjKR 4Zx0CCTzkSRps42M= X-Received: by 2002:a05:600c:5588:b0:4a1:83f5:44ed with SMTP id 5b1f17b1804b1-4bbe1effb95mr479565e9.16.1796295435607; Thu, 03 Dec 2026 02:57:15 -0800 (PST) Received: from google.com (160.193.189.35.bc.googleusercontent.com. [35.189.193.160]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb906d6a13sm733808655e9.3.2026.12.03.02.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 02:57:14 -0800 (PST) Date: Thu, 3 Dec 2026 10:57:09 +0000 From: Mostafa Saleh To: =?iso-8859-1?Q?J=F6rg_R=F6del?= Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, will@kernel.org, robin.murphy@arm.com Subject: Re: [PATCH v2 2/2] iommu: debug-pagealloc: Fix mappings starting at phys 0 Message-ID: References: <20261202112047.509228-1-smostafa@google.com> <20261202112047.509228-3-smostafa@google.com> X-Mailing-List: iommu@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Dec 03, 2026 at 08:48:54AM +0100, Jörg Rödel wrote: > On Wed, Dec 02, 2026 at 11:20:46AM +0000, Mostafa Saleh wrote: > > __iommu_debug_map() warns and counts nothing when phys is 0, but unmap > > only skips the page that iommu_iova_to_phys() reports as 0 and > > decrements the others, > > Unmapping a multi-page mapping that starts at physical address 0 > > therefore underflows every other page. > > > > Drop the warning and skip only that page, as unmap does. > > > > Fixes: 7e84593795b3 ("iommu: debug-pagealloc: Track IOMMU pages") > > Signed-off-by: Mostafa Saleh > > --- > > drivers/iommu/iommu-debug-pagealloc.c | 9 +++++++-- > > 1 file changed, 7 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/iommu/iommu-debug-pagealloc.c b/drivers/iommu/iommu-debug-pagealloc.c > > index 5faf53aa29f9..348fc4c57ed2 100644 > > --- a/drivers/iommu/iommu-debug-pagealloc.c > > +++ b/drivers/iommu/iommu-debug-pagealloc.c > > @@ -102,11 +102,16 @@ void __iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t siz > > phys_addr_t end; > > size_t page_size = iommu_debug_page_size(domain); > > > > - if (!size || WARN_ON(!phys || check_add_overflow(phys, size - 1, &end))) > > + if (!size || WARN_ON(check_add_overflow(phys, size - 1, &end))) > > return; > > Do phys and size need alignment checks for page_size? Otherwise ... > > > > > - for (off = 0 ; off < size ; off += page_size) > > + for (off = 0 ; off < size ; off += page_size) { > > ... off can overflow here when the above checked add with size passed but > page_size is added here. > I see, I haven't thought about unaligned addresses/sizes in that case. I see that in iommu.c __iommu_{map, unmap}_domain_pgtbl() check for alignment but doesn't cover the iommupt case. However, iommu_debug_map() is called after pages are mapped with the mapped size only so it shouldn't overflow. iommu_debug_unmap_begin() is called before the unmap and the check so it can overflow first. I can add the alignment check in __iommu_debug_update_iova() but that won't be related to this fix as this existed before the series, it can be a new hardening patch. Alternatively, I think in iommu.c we can move the alignment check at the top of __iommu_unmap() and that would also cover the iommupt case. (and maybe for iommu_map_nosync() also?). AFAIU from 99fb8afa16ad ("iommupt: Directly call iommupt's unmap_range()"), the iommu_pgsize() calculations are not needed for iommupt as it adds overhead, but an alignment check should be cheap. Which of the two would you prefer? Thanks, Mostafa > -Joerg