Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp15991697rwd; Mon, 26 Jun 2023 04:25:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7h5pbmYL/otM3C47v5mm47O0BYOq9rxKjBdvPoGgM6Sp/jCWdpRe2WYrupRxnMXFIYH7CU X-Received: by 2002:a05:6a00:2490:b0:668:7209:1856 with SMTP id c16-20020a056a00249000b0066872091856mr22227102pfv.14.1687778722600; Mon, 26 Jun 2023 04:25:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687778722; cv=none; d=google.com; s=arc-20160816; b=Aln6+ncgm25VKwNnHMRDV63QSDIVXPWnfM/Ex9dhXEPefHubCzp3YEFCHZgwt1R5dW bjDscZ0/556xc2qi76EMDwI4uNx6g1/AC7CycXgOBSwPeTiA/EuaBWKcbteYU5/tr7Cs kdloPF9YMzi6AFbmcg2HOMVY3jatVVyIHsKxD9MKBc1R1Xv1QPNELJzq4WzTpzXxJoVV H7bj5D/jL99+MwTBJmQYjGnoFNwKTB2a2vykfL3YOzGB9+fsXi271hE26M1YbzYkFRYM sEbtB7XKPid6fNgBj8IrrKmgxC7m7DOYsXJI2/WeG/Ev50OXFj5/Kb1rOWGAEU2SZlhm zGqg== 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=vKaUDMX7q/k4wnF5zn+Vr6K9ID3Iq87i7XrGFy/yZkk=; fh=NqilcjSZH/AWx7IwADvYlFuAx03+ZswMmioal0+Tdh0=; b=ZnviLoskx3yvSDVWfxHH7ZLGoaFiUfRs0B5Mfo0l1XZ7HHEeeVwts4doqTfIwHyArr 0CoBqb4YIdZIBGpFYvNOK2KKMji8mMkvY40u/iWhnr//bTq2F6XVoK9mF+6VPgobzd1I CQWom9AYpj+CjYYojJM/D8glBuPW+tcSM1nDE+OFKiz2bYA0JthSBNSzAygSIRBaj53E Qu4B3ZiCIfNayFqGebewvTAX43kem2HknN9xFnp1G07h28gt/QjEu6xl9It3uz4bKGiZ xpNkW9BzTO9VdcNl7cei8QXQa4UVFzN5pMq1imjI2dn3YnbTHYoOwF40S/XB6T6CBzSr 2+sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=xDSvj+cA; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cu12-20020a056a00448c00b00672ad8f038csi3054679pfb.184.2023.06.26.04.25.11; Mon, 26 Jun 2023 04:25:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=xDSvj+cA; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230086AbjFZLN1 (ORCPT + 99 others); Mon, 26 Jun 2023 07:13:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229761AbjFZLN0 (ORCPT ); Mon, 26 Jun 2023 07:13:26 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0099ECE for ; Mon, 26 Jun 2023 04:13:24 -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-out2.suse.de (Postfix) with ESMTPS id ACC391F8AB; Mon, 26 Jun 2023 11:13:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1687778003; 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=vKaUDMX7q/k4wnF5zn+Vr6K9ID3Iq87i7XrGFy/yZkk=; b=xDSvj+cA2CrQW1d62/Hj9ME9axiJ+O/23UMa+mgChTWNbHzBw4uM/vWi5T1dR2joITeEOE H3MVyOpfp1IeqA5cjVs3PZ79QjwUlCIzZ5M5oLdtunX6FHbqJHZUXQPVLgQQmNO0rZYtna VyTxkWulNw7C7ahnlnVhHJzmMyPOHiQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1687778003; 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=vKaUDMX7q/k4wnF5zn+Vr6K9ID3Iq87i7XrGFy/yZkk=; b=MTQZUZ7DNlmCoXdgQk6JahE7IEQ55oYgyNPsqB40wbT1iqRA8yXqESqu/5jzwapNseMsTk UC6JtrgSrpqJw0Cw== 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 7F3FF13483; Mon, 26 Jun 2023 11:13:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id RToNHtNymWT4JAAAMHmgww (envelope-from ); Mon, 26 Jun 2023 11:13:23 +0000 Date: Mon, 26 Jun 2023 13:13:21 +0200 Message-ID: <87ttuuv5m6.wl-tiwai@suse.de> From: Takashi Iwai To: Jaroslav Kysela Cc: Tuo Li , tiwai@suse.com, alsa-devel@alsa-project.org, Linux Kernel , baijiaju1990@outlook.com Subject: Re: [BUG] ALSA: core: pcm_memory: a possible data race in do_alloc_pages() In-Reply-To: <45445f57-0a73-59e6-6f3d-3983ce93a324@perex.cz> References: <877crqwvi1.wl-tiwai@suse.de> <871qhywucj.wl-tiwai@suse.de> <4d0931bf-b356-6969-5aaf-b663d7f2b21a@perex.cz> <87wmzqv64o.wl-tiwai@suse.de> <45445f57-0a73-59e6-6f3d-3983ce93a324@perex.cz> 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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 26 Jun 2023 13:09:00 +0200, Jaroslav Kysela wrote: > > On 26. 06. 23 13:02, Takashi Iwai wrote: > > On Mon, 26 Jun 2023 09:56:47 +0200, > > Jaroslav Kysela wrote: > >> > >> On 26. 06. 23 9:33, Takashi Iwai wrote: > >>> On Mon, 26 Jun 2023 09:31:18 +0200, > >>> Tuo Li wrote: > >>>> > >>>> > >>>> Hello, > >>>> > >>>> Thank you for your reply! > >>> > >>> FWIW, the simplest fix would be something like below, just extending > >>> the mutex coverage. But it'll serialize the all calls, so it might > >>> influence on the performance, while it's the safest way. > >> > >> It may be better to update total_pcm_alloc_bytes before > >> snd_dma_alloc_dir_pages() call and decrease this value when allocation > >> fails to allow parallel allocations. Then the mutex can be held only > >> for the total_pcm_alloc_bytes variable update. > > > > Yes, it'd work. But a tricky part is that the actual allocation size > > can be bigger, and we need to correct the total_pcm_alloc_bytes after > > the allocation result. So the end result would be a patch like below, > > which is a bit more complex than the previous simpler approach. But > > it might be OK. > > The patch looks good, but it may be better to move the "post" variable > updates to an inline function (mutex lock - update - mutex unlock) for > a better readability. Sounds like a good idea. Let me cook later. Takashi