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 X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A243CC2BBCA for ; Thu, 17 Dec 2020 16:29:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F955239E4 for ; Thu, 17 Dec 2020 16:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729119AbgLQQ3X (ORCPT ); Thu, 17 Dec 2020 11:29:23 -0500 Received: from mx2.suse.de ([195.135.220.15]:55254 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727543AbgLQQ3W (ORCPT ); Thu, 17 Dec 2020 11:29:22 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id F1A76AC90; Thu, 17 Dec 2020 16:28:40 +0000 (UTC) Date: Thu, 17 Dec 2020 17:28:40 +0100 Message-ID: From: Takashi Iwai To: Lars-Peter Clausen Cc: alsa-devel@alsa-project.org, gustavoars@kernel.org, linux-kernel@vger.kernel.org, shengjiu.wang@nxp.com, tiwai@suse.com, pierre-louis.bossart@linux.intel.com, xiang@kernel.org, Robin Gong , akpm@linux-foundation.org Subject: Re: [PATCH v1 ] ALSA: core: memalloc: add page alignment for iram In-Reply-To: <98fd6adb-5bae-56ce-c52b-f778f92f6a2d@metafoo.de> References: <1608221747-3474-1-git-send-email-yibin.gong@nxp.com> <05c824e5-0c33-4182-26fa-b116a42b10d6@metafoo.de> <70074f62-954a-9b40-ab4a-cb438925060c@metafoo.de> <8e103a2b-1097-6d54-7266-34743321efac@metafoo.de> <1fc18b56-effa-9dbc-8263-00c632e163e7@metafoo.de> <98fd6adb-5bae-56ce-c52b-f778f92f6a2d@metafoo.de> 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 17 Dec 2020 16:38:22 +0100, Lars-Peter Clausen wrote: > > >> Maybe what we need is a check that runtime->dma_area is page aligned > >> and runtime->dma_bytes is a multiple of PAGE_SIZE. With a warning at > >> first and then turn this into a error a year later or so. > > OK, how about the following instead? > > Just check SNDRV_PCM_INFO_MMAP in runtime->info; if this is set, the > > buffer size must be aligned with the page size, and we are safe to > > extend the size to clear. > > > > So the revised fix is much simpler, something like below. > > I think this will work for the leaking data issue. > > But it will not help with the original issue that > gen_pool_dma_alloc_align() does not reserve the remainder of the page > and could give it out to other allocations. We'd need a separate patch > for that. That can be fixed by the pcm_memory.c change in the previous patch. Recited below. Of course it won't cover the non-standard allocation case, but then it's rather the responsibility of such driver. Takashi --- --- a/sound/core/pcm_memory.c +++ b/sound/core/pcm_memory.c @@ -36,6 +36,7 @@ static int do_alloc_pages(struct snd_card *card, int type, struct device *dev, { int err; + size = PAGE_ALIGN(size) if (max_alloc_per_card && card->total_pcm_alloc_bytes + size > max_alloc_per_card) return -ENOMEM; @@ -187,7 +188,7 @@ static void snd_pcm_lib_preallocate_proc_write(struct snd_info_entry *entry, buffer->error = -ENOMEM; return; } - substream->buffer_bytes_max = size; + substream->buffer_bytes_max = new_dmab.bytes; } else { substream->buffer_bytes_max = UINT_MAX; }