From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796295438; b=q2Dmh8yV7LXLd5IgsfjMGaQ25bJ2oiRCIS25CJGJLYkX8Edwf7wMA+TA33bshJu+s7/u gwTKuI+jzFr5VXvN7c1vkWBheHId1l3WmLGrAhcsTlIzvXed4eK/+NtwuliTPorqBc4PY e5Cm7ST66Qogl13/+lbQQgmNwPAV9wgsZVJbQnHt1mo0NbXSviWVrzK/QbM3asCxp6j1i /FD0tcLRQ+uUFvwm7SCsPH1DVtHVoUaf82poKTqOi3kS5mo1sriB8jbfRnFsmmFoYtnZQ TMulonLkR7kWCL5TnOgi9+B1hNsZRhF9+2z1tUA9quVQ5aYVzeh4H0oZc6zwqy4niFg== 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-Forwarded-Encrypted: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=RMXA102EJfE5769Lfccy7xg/kFuvWymarwThmkROEcKj83n8Ak5Qbg51B/XImS4mAekv D0VGtoG+gpk02Rw2bfJDXr9azvM0bywuZu+9BOEMcj0yApb9OMbrSlrrQLPBXQPR7VnP2 N9dzzaZt5TfSXvpeE3jH0ryV/YwGUqgMj9hX1mNSXQjDhh4keHp0EK0ArGxYv7rdfO9kA f7USqUyBLjQt1FDG6z36ZV7yKMlkmVyNWBLuQBpiot3jfr6LDlGXrA75BCnLpcxmrhz3s sEt6BuSuPNdOH3Xl9XIy2BdO5YIAXb+bbSziGWWxewy5slm0w36FZNYfICcYBU5BCUw== 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=TZHhpEpo; arc=none smtp.remote-ip=209.85.128.51 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 B81A8606A338 for ; Thu, 3 Dec 2026 10:57:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B81A8606A338 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) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=TZHhpEpo Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4bb845433b8so41425e9.0 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=vger.kernel.org; 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=TZHhpEpovKkt/S18SWm5RU70zPk60V2gkVTGQrfeCRcR2wrLkaUDNyKT59CJ3Ft0GA eYxcqZYexMRsdXB0ho2PvaySzNqnzEu1nXR/FHX76GorqZom0Ae4ThH2bErNuZ+FZXyW mSFia7LnE0T7bAlHXd80X4mu7hMoMRcguxPJ3xQBI5fS/+N3XIHznFAw1VfcbBLYrJUi lUTIjad5BhRFdMqPkqmOxTsQAstSjSMmTrSv7edUN6OTKH1+w3x6fZx/VWfBiPucZL9f qDqjLsFiKY1uQH+kojrqtY6xUDPQiT3WdLKYU/19DbP/8XpT3wHqcIW2m9zdWsdTMgr/ PD0g== 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=nQH8WcwF/ZpEbGBzfshenmjPbCZ8gIMTkeyXtX2WSmuyJijmNahigRDqwb/vjYDXDH CeRerwSzvQkVNlhRKK90RyCKk+npcpsyfy9XnLDAsHKv7c8AjeX5k4Oujk+ZB5SGKwaF 4Url+siG9RrUJvQZdpRA3hke2L2qNfflNb7dPPZMixH3JAaf/iyEAjpK4gEL+1WKx3DK 36v4Cqz2aWUQnKG4oaHlI7vnKBYYJw82znpftnXEVVkER8sG811oBkwNKUMvtC7mbi3P Ud4ICAIBV+umIBOKRDL6JQiLy8w9gVF52jdhIaEUwgsCYRBZn285gWhhdZPglnBIQlJy HPqQ== X-Forwarded-Encrypted: i=1; AL+hErFXaBcBsFmKWM9hZ4vqCRpulyuHpjeNuehm70OY5Ny3j4KkYB+LXud9ugONeuS6FYq2rP2w/qPX/u7L/Jw=@vger.kernel.org X-Gm-Message-State: APuU4Z8rQ7uKngb6vEjIfSUPPWzwHjXwRMFYfcHdBQ2b7ei6I5GzYDql uPjibYmX4GhidBDILBRJhLsLIlGVzA+F7PCsopXVQAKzVup+YMbCdmAazUNbSfEYHg== X-Gm-Gg: AZFdTZesbkpzc72ClI+5p5ylkf1mG61GwqqmZT6Xyt5/+/5mpy5JZHKPlSXTxTAv0od lB6P7yTZK1x276Nx6gAZwN3Bx3MPOxmtFM/RSC5/yIz6gjN2XloM5B38ASMFxn64eFN1/Bh9Jib IWi1E88k5p+uOSQwD5PcvbhOnAco77boaLr3uh4xTzSQc38jEH0061xw+/ZhXVZhGB0Um0y3b6p 7oXKFFyothj5JBEDvkzr2fcwQUuJBwLJF0WSNbQ+u3ckPOjp6BrMuAMMrJzLbi7NEED+e/i41YC 01su2KRibVi1I0LMdd/yPkyshdwd86TrhnVZeB+3lxQfYW0/vTW6pVOmHkRcvsJx/hmFGPgYXxz ppCooXXGkpf8TVju4I01t2uapQebN0I1Mx8J8PBRoIO6C6lfJp8PfCKsWeii0+nLac8++qx7D7B 8Ez3Q+rx/bZEMsZlNJ8PUuw+XdkHVOW0bAhQvdpQ10Z/fWX7G6iDwlPa+V6KrM2/nMz4MEk0Wzm hY7+D34n6Q9ftpj7Stt6jSiRhef9Xz1LCG2M4SWrT81LjXEf3eIetdFV/aBDtXkvEKGosCnO7xJ 6K6SKc7WiKfONMM2whR7kNr945PJdcJ73k/eE1pPA6yVh9koUS69vUhvDvUOkWmz+MtQwjlEFCP EIYKMFkW9omkuA+s= 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: linux-kernel@vger.kernel.org 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