From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E9E07C63797 for ; Fri, 3 Feb 2023 00:35:42 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id CDBEE74C; Fri, 3 Feb 2023 01:34:49 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz CDBEE74C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1675384539; bh=rd2jpbHSBQLXiM0eHy0iWR4fPsO4zdF/vUUs7PxdqBA=; h=Date:From:To:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=YT/jmF3Yq1HiryTSMpvv2+Tri6LrszyXpVPgj9HeRM81ryJCAVe1ohw9i9FDIiac/ YYmBVNXomiFMJD1YQa500rQ7/TLLmqmfCFgkF/vZ7l3IhFvz27KpmA/cLX5WN7Ntmm xvuGRqt82oIOGAjpnfJgo9I8KuuRy7n6XR8sFM2A= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4A358F80271; Fri, 3 Feb 2023 01:34:49 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C5B90F804C2; Fri, 3 Feb 2023 01:34:47 +0100 (CET) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id DC063F800ED for ; Fri, 3 Feb 2023 01:34:36 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DC063F800ED Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.a=rsa-sha256 header.s=fm3 header.b=qbxz0Jif; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=o+LSMLSE Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 1D37A5C00A0; Thu, 2 Feb 2023 19:34:35 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 02 Feb 2023 19:34:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1675384475; x= 1675470875; bh=ls3QJBMTEbPHVfAcVhN6P9TipGx254UEU47tQcG7ILY=; b=q bxz0JifNTE+8ml5CINNSRdTnihPDow5RxeUjVz3EvsyhkWJz2sPSFwq/8xegVHnu dkmuSSWRPO+MKC+K9DLS3X2wMcS2v5/4C8ojPYm3i4WQ9Ul9MGo7zdmRFLpiDKU9 /rJHw8anVVR0BQNsaPFOOLpcN/TA6+bEimbOsd+TWlkiG+dIQ5rwe4vLusPNgd5p 2lAKLQKDgp90GJcHnZ7AoVZq8JHtz30eCEeTQkJ/34Ap1KC7WavakfPdtbbyD3Fm N8/JMrvfiIsy3VETl3GzNmM/EFr972U+EzuFhUgqPESY0bePDC/YsgyggrowH1nW ZBMG52AIRR2FPTfCxQzqw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1675384475; x= 1675470875; bh=ls3QJBMTEbPHVfAcVhN6P9TipGx254UEU47tQcG7ILY=; b=o +LSMLSEm5oY0UoUxgr/C6KypVgQfvHhK76V63kIvJI+EhS+3s2FcM0a9PflCWGjN 1j9a7K5VujeDYPpCIN3r0qh6RbbUsy7iF6aXvmM1AVyIksh4YxLZVkzqEx37isoI HZUL4c8x1m28+N1yHoDZb4bre/PL3OC2YYZPjn3VjuYUcyKmrrtx0VNeTAl2FzbS BY75a1o4MGLeGBFbG3MXMedFLJfTskiWGeSYkW3yJsRjfqCFXhiyVkmMSegRrjSd mJbf70EToDJC27NbqVCqOaFzFsjkGAPn8/shUTYoLRuNGo+Pd4o5w7lFTZC2/6EK PGMzuzs3uqZEk/cpUOW5g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudefledgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtugfgjgesth ekredttddtudenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgr khgrshhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepuddthf ejhfefkeetkefhudefgfetueetgfdvffejtdehtefhuddufeeghffgtddtnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhih esshgrkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 Feb 2023 19:34:33 -0500 (EST) Date: Fri, 3 Feb 2023 09:34:29 +0900 From: Takashi Sakamoto To: Alan Young Subject: Re: Overflow in calculating audio timestamp Message-ID: Mail-Followup-To: Alan Young , alsa-devel@alsa-project.org References: <70ff4e3a-b171-131c-a039-4fc99aa4bbfc@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <70ff4e3a-b171-131c-a039-4fc99aa4bbfc@gmail.com> X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Hi, Thank you for the report. On Thu, Feb 02, 2023 at 01:55:24PM +0000, Alan Young wrote: > sound/core/pcm_lib.c:update_audio_tstamp() contains the following > calculation: > >         audio_nsecs = div_u64(audio_frames * 1000000000LL, >                 runtime->rate); > > This will result in a 64-bit overflow after 4.4 days at 48000 Hz, or 1.1 > days at 192000. > > Are you interested in a patch to improve this? > > The same calculation occurs in a couple of other places. I'm interested in your patch. Would you please post it C.C.ed to the list and me? As you noted, we can see the issue in ALSA PCM core and Intel HDA stuffs at least. * sound/core/pcm_lib.c * sound/pci/hda/hda_controller.c * sound/soc/intel/skylake/skl-pcm.c I note that 'NSEC_PER_SEC' macro is available once including 'linux/time.h'. It is better to use instead of the literal. The macro is defined in 'include/vdso/time64.h'. As another issue, the value of 'audio_frames' comes from the value of 'struct snd_pcm_runtime.hw_ptr_wrap'. In ALSA PCM core, the value is increased by the size of PCM buffer every time hw_ptr cross the boundary of PCM buffer, thus multiples of the size is expected. Nevertheless, there is no check for overflow within 64 bit storage. In my opinion, the committer had less care of it since user does not practically playback or capture PCM substream so long. But the additional check is preferable as long as it does not break the fallback implementation of audio time stamp. Regards Takashi Sakamoto