From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 CC5C343637A for ; Wed, 13 May 2026 17:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778695102; cv=none; b=ur4v1jt3s6GxKRZjhOokHbtqDyRYTTy3jyPBH0QddW59n7OBqdQcgRVjshJzpp21rXvQGn3pEEvUBKZrNjQI3x7luMlwAEKwAik+LdyZzWynVDo/VFDvom4Q6n3lQWICSFcxdg19CQtqI3KakOE++CDB4PGjSHHvWPdsXtVGeUo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778695102; c=relaxed/simple; bh=MzXdRwxMA2kEQ6q1Wsb/dOQftZjJ4Cbj6XE+Lz3pOxM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PX0MHXNuYuW0yskba6DCXOKlcZ2bqpPCjluvlP5ConQcivVsqyPt+hIBCM4ivpPJ8mirRiKH4py1B2rEfdKFH8CcAmRV1f6iOfVDAULduoER6tV8+7WPkSjC0oliPXsGTjJ80mowUpCkNmFzNbverjd+edYC2i80F1dxEMPAG90= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QuTr1DNY; arc=none smtp.client-ip=209.85.214.171 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.b="QuTr1DNY" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2ba3b9bcf69so525ad.0 for ; Wed, 13 May 2026 10:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778695100; x=1779299900; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=S3fT1aVwPbo1hAx2uAtxA0S4rzdrTURQ0V1Kv0JH3lw=; b=QuTr1DNYyLV+wj5Hh+bCh5/xDk8Y7kLGAHPZqFqx3qCxMeDRyOkkFLr8jSLoKHj6jw S33kW7AQsvWZY7qXQ0iGKEnZmwSoxJocJgKDBZ+HDuS9g7fR+PnSSuCEc/DNfi74Sy5T koAZEChdDTMcyyPysjmhdzppS7trTw044g0Ja2jDh0ZZerFGnlP1xsV01WbEMggvVb/U MbNwEWY6H6FKXLJ9DIesVCEpOWSMmrmxo64EXNVeT5FN6sPxqD7aw6vHqRDbTpsQzEzh 6vE9XT0rf004c4yTHCZoYcWb29O8N1K/x9y1GufuwdNl8y6e3x8PP4WrcAHjy1bnDb2y xeqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778695100; x=1779299900; h=in-reply-to:content-disposition: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; bh=S3fT1aVwPbo1hAx2uAtxA0S4rzdrTURQ0V1Kv0JH3lw=; b=r8rGD69+ZyntEVM9fbPsv3wkMJ3eX5TTfA0nKC1LoGgkiH9Qh3uc3OjyhhVwlrlwQy UaPQfx7Pi7oQ7rRYSGki8+GVcx4M8HViTycrhJxBrihWSBg0rVyIqrnOuaJSBboNg3C4 gFN8FehWZlJ2IRFPfh8lvuoyJjWm/cawJ/G/BodCPyfUngH/LiRXiBtijWUo76p3SjP4 sgjf4kLhU8MgDfpDMU4i9e8O1lLf5JqRfZoPNZuIqdp+jsjjT05HY7cB03Q93z10nbtD TZojgtnZd0kfLLapB1EEeraDC8AM1IrJp2UQyg6DgPAESHaXUcmbn3BRTlqBBpnu+h5+ tBNQ== X-Forwarded-Encrypted: i=1; AFNElJ9z0fkVHOn6Vt74hBAXPpriHm+wMApVpMlPTiHvVKRnSXMJ6EhoCWrBQWPeQVh6Y37uhnDVHhI=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+7i0bmtM/LfyxHEK46Ym+ZFT+qHkqtq4YqmU1AofaeBtp7e82 EIwaY7PhNckO1+nkmGTUttCUESgwGLGf/b8VH7HR11fbLR+aNa/x9UFfF7bPnOBp6g== X-Gm-Gg: Acq92OEo7/pG9TE/EfB9Z/X25qPS3Zd5EVZmsZNxJmztIJ49E1SbHo95RHsIgVcf0s+ py+kdvi9wFZTfPKVjQMmFTDGRE9Vk1yrDq/rJS1yEg41yj8EZHwx9G9t6UJE4Fu3qyXsb2FTsdt VqNYIdYCxVuxG7tDQ1o6mnKFPEic3A7bewpc5A/eJI0kvjk5PmxvCXTcRy58ucI0Zcs4lwCuVDJ DODEkJL+ShllPznQn4GA1vFW0LyPApXUzMaF4L4R75irFjQf+WqaEvz7JagKzlwizCAkzUyR/WI +jhrl0y61+36/yIViWHRmjADDhsHuwJvcaN2VgQ0t4aAyPRRiQ6aJgzlPwKWkQOhkv6WoegO+Wg RvGZOPsxl6bpsAW2Om6cv7vLRZUU+8QWLuXCcYAC2UWHUh1jUVuUv+C1brB3MyWTUV3mZyQ4dnU YPH54IaN5eyERVIrbqqyHKLOWxVPx5JVvOg6bg5TxHClgoYm9lJWU9cwQSRRPmg7jZsZq5 X-Received: by 2002:a17:902:db09:b0:2b4:58ad:e987 with SMTP id d9443c01a7336-2bd568f44a7mr187755ad.17.1778695099515; Wed, 13 May 2026 10:58:19 -0700 (PDT) Received: from google.com (44.234.124.34.bc.googleusercontent.com. [34.124.234.44]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8267735eccsm15998141a12.32.2026.05.13.10.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 10:58:18 -0700 (PDT) Date: Wed, 13 May 2026 17:58:11 +0000 From: Pranjal Shrivastava To: Jason Gunthorpe Cc: iommu@lists.linux.dev, Joerg Roedel , Robin Murphy , Will Deacon , Alejandro Jimenez , Lu Baolu , Joerg Roedel , Josua Mayer , Kevin Tian , Pasha Tatashin , patches@lists.linux.dev, Samiullah Khawaja , Mostafa Saleh , stable@vger.kernel.org Subject: Re: [PATCH rc 5/5] iommupt: Fix the end_index calculation in __map_range_leaf() Message-ID: References: <0-v1-44b2fef88b25+d3-iommupt_map_rc_jgg@nvidia.com> <5-v1-44b2fef88b25+d3-iommupt_map_rc_jgg@nvidia.com> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5-v1-44b2fef88b25+d3-iommupt_map_rc_jgg@nvidia.com> On Tue, May 12, 2026 at 01:46:17PM -0300, Jason Gunthorpe wrote: > Sashiko noticed a mismatch of units in this math: num_leaves is > actually the number of leaf *entries* (so a 16-item contiguous leaf > is one num_leaves), while index is in items. The mismatch in maths > causes __map_range_leaf() to exit early instead of efficiently > filling a larger range of contiguous PTEs. > > The early exit is caught by the functions above and then > __map_range_leaf() is re-invoked, so there is no functional issue. > > Correct the misuse of units by adjusting num_leaves with the leaf > size and avoid the performance cost of looping externally. > > There are also some mismatched types for num_leaves; simplify > things to remove the duplicated calculations. > > Fixes: d6c65b0fd621 ("iommupt: Avoid rewalking during map") > Signed-off-by: Jason Gunthorpe This is an important catch! It means that today, we were redundantly re-walking the upper page table levels. Reviewd-by: Pranjal Shrivastava Thanks!