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 9206DC433EF for ; Wed, 20 Apr 2022 08:01:46 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id E71BC1922; Wed, 20 Apr 2022 10:00:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E71BC1922 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1650441704; bh=9IWR7AFyGNsgvIMJzmZ1qULjOPDpoMZV2VFr9yQ58tw=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=crHrsd/ubHdXWls3ysxgzGXANZAZ5Wy3Xqy3xifofZoJfkQVGrfAqUj9fCJg4oFl4 mEzM2F0rkSSybKtp5moywQ1Uh0Y/jyf9HH7ps00Mj6w2RNtlUEaAkVECROrzskEA8z iE8tZMU0rvhRticOC5JrYCgNnm3o/VV2ZxyXMSkQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 7AFB7F80116; Wed, 20 Apr 2022 10:00:53 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D7775F80125; Wed, 20 Apr 2022 10:00:50 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 4DF26F800F8 for ; Wed, 20 Apr 2022 10:00:48 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4DF26F800F8 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ZEyXdzCF"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="kH34oOtO" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D15FE1F380; Wed, 20 Apr 2022 08:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1650441647; 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=nTqN2uKTgO9t8sRIjlC5jrKREK2dixrGoWGuqIKtYKM=; b=ZEyXdzCFrLNKwoTyaY7I3luB4JwIWOtNmm40bWkcnSVHxmGAEqPPd+f+BAHCiC7+jyFV8i /niR0xB+hP3rYG6KBOjTOQS8hPem2QeeJv6Pu2C3s4Bpu0jGZlxMEqhD9Ym9eUjcEHs1aR fZh1V78+WX2V/JrJd61L/gLKPM1TGZI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1650441647; 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=nTqN2uKTgO9t8sRIjlC5jrKREK2dixrGoWGuqIKtYKM=; b=kH34oOtOzqdyJkEWRI/bVQxUmAof9rRWphrKNgLpkQrJqRo3YKijkwUFsB/a2Fq/Njp5xa VjQbCTHZ1y/xgmAA== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 08ADC2C149; Wed, 20 Apr 2022 08:00:47 +0000 (UTC) Date: Wed, 20 Apr 2022 10:00:47 +0200 Message-ID: From: Takashi Iwai To: Dan Carpenter Subject: Re: [bug report] ALSA: memalloc: Add fallback SG-buffer allocations for x86 In-Reply-To: <20220420074458.GA32681@kili> References: <20220420074458.GA32681@kili> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: alsa-devel@alsa-project.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Wed, 20 Apr 2022 09:44:58 +0200, Dan Carpenter wrote: > > Hello Takashi Iwai, > > The patch 925ca893b4a6: "ALSA: memalloc: Add fallback SG-buffer > allocations for x86" from Apr 13, 2022, leads to the following Smatch > static checker warning: > > sound/core/memalloc.c:732 snd_dma_sg_fallback_alloc() > error: 'p' came from dma_alloc_coherent() so we can't do virt_to_phys() > > sound/core/memalloc.c > 708 static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size) > 709 { > 710 struct snd_dma_sg_fallback *sgbuf; > 711 struct page **pages; > 712 size_t i, count; > 713 void *p; > 714 > 715 sgbuf = kzalloc(sizeof(*sgbuf), GFP_KERNEL); > 716 if (!sgbuf) > 717 return NULL; > 718 count = PAGE_ALIGN(size) >> PAGE_SHIFT; > 719 pages = kvcalloc(count, sizeof(*pages), GFP_KERNEL); > 720 if (!pages) > 721 goto error; > 722 sgbuf->pages = pages; > 723 sgbuf->addrs = kvcalloc(count, sizeof(*sgbuf->addrs), GFP_KERNEL); > 724 if (!sgbuf->addrs) > 725 goto error; > 726 > 727 for (i = 0; i < count; sgbuf->count++, i++) { > 728 p = dma_alloc_coherent(dmab->dev.dev, PAGE_SIZE, > 729 &sgbuf->addrs[i], DEFAULT_GFP); > 730 if (!p) > 731 goto error; > --> 732 sgbuf->pages[i] = virt_to_page(p); > > The warning is a bit useless. It's complaining about __phys_addr() > and not virt_to_phys(). I don't really understand the rules here, it > might be legal in certain contexts. In general it's not good to perform virt_to_page() for the dma_alloc_coherent(), but here the code is special only for x86 and certain circumstances, so this must work -- it's the very same stuff we had over a decade, after all. The code was resurrected in a simplified form as a fallback now. thanks, Takashi