From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C3ACE3C08F; Fri, 29 Mar 2024 20:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711744952; cv=none; b=XhaK8gSGuO2O9CzBOOOzcEIjn5jY2PnW9ieLhcBwDptjDoNblQaS72BFbwoNBKvcs/9FavA0b13L+bJR7VD0fkdSjW7WzEc90Pj1A1gA8VHpS7znBDHly7mJdvpedUZeH3Y0XfMPOWA2zHOzIzcE/yy91PVE0soZmjQQinAI1jk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711744952; c=relaxed/simple; bh=hz5RR0GReCD0o+TbGpPzwpXzow8mvQnlmHPDe6BzQNU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=cDuFMISyU/0W7NAamxJut++EEeR83zlIzZH/qiyJsJdnezPQCTHk2wjeLq6Db47PjB0SJ2aCKz+TP4vUVoiDi6K2DJQWiWFuGeStNdVbfbI+WCVX4YqhhYGxNszGGGOIZ0a6HxnLuiJ+S7OJ5hg2KSP1zz+KxfUS6k9Dsj5j9Jc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=XqiX32Sj; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="XqiX32Sj" Received: from [100.64.65.59] (unknown [20.29.225.195]) by linux.microsoft.com (Postfix) with ESMTPSA id 0787420E6F42; Fri, 29 Mar 2024 13:42:29 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0787420E6F42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1711744950; bh=T3bq+rfTxoFcrWlHxiM/MsuE/8OiSBnZvhXgUAsFCnQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=XqiX32SjGqD3vk/hUo4BhZDOk+DdTVyaYWF0zAdPXk7zAPwBavYyWo7D6sBZ68dFM L/TJp4duCoEIVCMuOHHW4ZCL+J6aZF4kQn9MMkQ/Rrv/qeFr0jl+jI9CJ8Ck9rFn6n NPijVBOT4MeX1n6mROxFMxLlPNRa1eBx5dJHF0DM= Message-ID: <9336949d-6fa4-457c-8d7e-9aaa5d62cbd7@linux.microsoft.com> Date: Fri, 29 Mar 2024 13:42:27 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files() To: Dexuan Cui , "hch@lst.de" , "m.szyprowski@samsung.com" , "robin.murphy@arm.com" , "zhangpeng362@huawei.com" , "iommu@lists.linux.dev" , "mhklinux@outlook.com" Cc: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" References: <20240329192809.17318-1-decui@microsoft.com> <07ed50c1-75a9-494c-8a6a-5edcc2d6f932@linux.microsoft.com> Content-Language: en-CA From: Easwar Hariharan In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/29/2024 1:30 PM, Dexuan Cui wrote: >> From: Dexuan Cui >> Sent: Friday, March 29, 2024 1:23 PM >> To: Easwar Hariharan ; hch@lst.de; >> m.szyprowski@samsung.com; robin.murphy@arm.com; >> zhangpeng362@huawei.com; iommu@lists.linux.dev; >> mhklinux@outlook.com >> Cc: linux-kernel@vger.kernel.org; stable@vger.kernel.org >> Subject: RE: [PATCH] swiotlb: Do not set total_used to 0 in >> swiotlb_create_debugfs_files() >> >>> From: Easwar Hariharan >>> Sent: Friday, March 29, 2024 12:47 PM >>> [...] >>> Sorry, I'm missing a why in this commit message. Can you say what >> happens >>> if the total_used and used_hiwater IS blindly set to 0? Is the only effect >>> the change in the readout of the swiotlb debugfs files? >>> >>> Thanks, >>> Easwar >> >> Right, when the system is not doing any I/O, the readout may >> return a huge number while it should return 0. This is the only effect. >> >> Thanks, >> Dexuan > > Let me share more details. > > kernel/dma/swiotlb.c uses inc_used_and_hiwater() and dec_used() > to do the accounting. > > The issue happens this way: > > 1. inc_used_and_hiwater() adds n to total_used. > 2. swiotlb_create_debugfs_files() sets total_used to 0. > 3. dec_used() decreases total_used by n, i.e. total_used incorrectly > becomes a negative number -n, which is a huge number since > mem_used() converts the 'long' to 'unsigned long'. > > Thanks, > Dexuan > Thanks for the detail. I only ask because the patch is marked for stable, and I was wondering if it meets the criteria. But, as you mentioned off list, two Fixes tags probably do meet the bar. Thanks, Easwar