Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1313854rda; Mon, 23 Oct 2023 08:51:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0EWyRkLdFwpNQVNIhDHzgPs2uA1CgqQix/+U03mlu6y0vsLfL3mbKmRiGopqOJTGDoRIb X-Received: by 2002:a17:90a:c241:b0:27d:694f:195d with SMTP id d1-20020a17090ac24100b0027d694f195dmr9169797pjx.6.1698076293492; Mon, 23 Oct 2023 08:51:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698076293; cv=none; d=google.com; s=arc-20160816; b=eFNRs+KydBk2AyW053EdkmayWoHj9QPY/MUADjOlO5j/H9plJJp100UfkUpJkESUdZ WAn9B2zRADIE43P5GDDVsAiuvKfnewVXKmdNHM9k7V7EpoVtfVQ4Vm61k/EsYmTTfgVJ B4Z5f2tQy6DSjTqkhXPGC9lAGC4dnsaSy6HD3Y6EkBIz7Oqa4Sly7f4libBhviNCBwBf SiJDQCjg0FaIs4aq4fTLDg2lEUYdYq3i7TnR6omXVCftOcmNRwphOsQ65hfSln6VFeFb 6Mq5fj1IQPMFZTTKgI2+6g3bJYnBH6l10dErcci309dTMQjDJvsUCWz6aUHaeAD6cDPJ wXvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=s55KBBdkaxhAnoFxBZ3RJHysL0tvL4Uht6f0m+5T79E=; fh=4Cf43DImL3olS4/DRydcrQ5ZRc5sdN/BZkZZoiyvjw4=; b=IsIVLZlmNuv3Uu0uSqrFChvigB0m3ixMmo9xosYuQfLvsMpHNGq0EDkw7WOFt4U+av ldn2h83grKdkbVpC2lNivdTaxwsKQf+sFBb5xrMdwYusmI/Y33O+I2W8zhVLShTAnLm5 KgtHeK4l7ipuq0Pc7v+aP5afoHOKcPoFMSiqJPHUOGARahXubXjRCfAaciTcu8Q3kd7X z2POznHZBFhp8dQOJM2BrJDkPrB8M6lEE/TxTa7yb8KgKhiCJh6xMDgMSjBC8YtprbTF PWjnD744Gb6NjUXBmUdUqU7TkKIly3PJ+t/GdmRtDNyidAAKU2yByv4OivGHitPuNd7u AH5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=w2XeUGCq; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id z8-20020a170903018800b001c7345bc01csi6841272plg.450.2023.10.23.08.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 08:51:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=w2XeUGCq; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 15AD180924A4; Mon, 23 Oct 2023 08:51:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233324AbjJWPuM (ORCPT + 99 others); Mon, 23 Oct 2023 11:50:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233298AbjJWPuH (ORCPT ); Mon, 23 Oct 2023 11:50:07 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 958AE9D for ; Mon, 23 Oct 2023 08:50:02 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2C3FD21AFC; Mon, 23 Oct 2023 15:50:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1698076201; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=s55KBBdkaxhAnoFxBZ3RJHysL0tvL4Uht6f0m+5T79E=; b=w2XeUGCqssnXKjmZtCZHymL8Nl9c35rbJnRMdqhK3iMyLwihI8/D+BpPt77nS+xmAb1PZu +NxMDTV5w59F2+A9E90Y83AF/MN150lSSV0IRa2EAd/TS2/uxYUqacBjWl5ENufZaXIaHz g6NVRCOmHFNZ7CPmW50E+stXLgWxCiw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1698076201; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=s55KBBdkaxhAnoFxBZ3RJHysL0tvL4Uht6f0m+5T79E=; b=Vy+oN4RgY7IbkWEe8BkFel1fEG9YEejT0ejW70iykea05+L7d2/ijCUba5qJ0n4ZJPP5WM HCUXRCMwPDwVbXDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CD18A132FD; Mon, 23 Oct 2023 15:50:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id pxTGMCiWNmVWHQAAMHmgww (envelope-from ); Mon, 23 Oct 2023 15:50:00 +0000 Date: Mon, 23 Oct 2023 17:50:00 +0200 Message-ID: <87edhlwd7b.wl-tiwai@suse.de> From: Takashi Iwai To: Matias Ezequiel Vara Larsen Cc: anton.yakovlev@opensynergy.com, mst@redhat.com, perex@perex.cz, tiwai@suse.com, virtualization@lists.linux-foundation.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, stefanha@redhat.com, sgarzare@redhat.com, manos.pitsidianakis@linaro.org, mripard@redhat.com Subject: Re: [PATCH v3] ALSA: virtio: use ack callback In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -10.09 X-Spamd-Result: default: False [-10.09 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-3.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_TWELVE(0.00)[13]; MID_CONTAINS_FROM(1.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-2.99)[99.96%] X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 23 Oct 2023 08:51:25 -0700 (PDT) On Mon, 23 Oct 2023 17:06:57 +0200, Matias Ezequiel Vara Larsen wrote: > > +static int virtsnd_pcm_ack(struct snd_pcm_substream *substream) > +{ > + struct virtio_pcm_substream *vss = snd_pcm_substream_chip(substream); > + struct virtio_snd_queue *queue = virtsnd_pcm_queue(vss); > + unsigned long flags; > + struct snd_pcm_runtime *runtime = vss->substream->runtime; > + ssize_t appl_pos = frames_to_bytes(runtime, runtime->control->appl_ptr); > + ssize_t buf_size = frames_to_bytes(runtime, runtime->buffer_size); > + int rc; > + > + spin_lock_irqsave(&queue->lock, flags); > + spin_lock(&vss->lock); > + > + ssize_t bytes = (appl_pos - vss->appl_ptr) % buf_size; The variable declaration should be moved to the beginning of the function. Also, there can be a overlap beyond runtime->boundary (which easily happens for 32bit apps), so the calculation can be a bit more complex with conditional. thanks, Takashi