Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1375599pxu; Thu, 17 Dec 2020 08:32:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOB8ZydpykgInoGGJ30yrxTTOcHQhSj4JFpBRlmvHhLTsdhx4dBbh4gIkjmhvv7F5BMdud X-Received: by 2002:a17:906:3883:: with SMTP id q3mr35751313ejd.160.1608222741296; Thu, 17 Dec 2020 08:32:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608222741; cv=none; d=google.com; s=arc-20160816; b=o2rj5aaf9/HXW+n//tdmDIPXZURUZ3K00eTNGtvxo0nc6idn/Kmbdud2bJztdF7d6v Pd4CCmsPZyFXPNYYh1WTh53oEgNMOAm/6/8YchOaxkg0+hGPOVFxROCgOgGBiESoy5Cz 8/K8ivDgXmAQGQkZ8BuiiSsQAV6K7arYYvcqQdSBmBPb8Vp/L/Eqty8DkbCCVlWyk5PW IxcK9BaQidtfv8Ay+FWeYxwfbl7VKixHJVOPhBQoTDHY6tDpNr0b+bfWU2qo5dSIjh2o otL+K7bAfNBbhtvRnB6ps0iZywG+/0bBGlFCjMVhlCUOKiB9PKQjBIiPu7JoHlM1S2SZ LjyA== 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; bh=DfvlUwkqH2XHqIbcafmlCEl/4J6lZ/PdC8mgJj3VIYU=; b=08hzozxV/T5NVUEOpsgnhe0jYrr1w0v97JaPnBNgnAP5jhwtFcs4IbsvvB3/EHosBh H5bCAy1Oks7irVkGXBpDmqlGmEPcowIvda5ob3mAOCwhJdTuA16jc1ZpnFCsuXYH0cxI ZonQ5nR6ml2YDpq3X3ySXEunvhWvDoDwBhLK7VAv89YQcpBQPhGyZWHZX/u2BFTISa0A vrYEo5cx+Yh8D3Tm6z5+CAwz0qL+OfUM8Xadx60+UQmEB88Bwq0QSIDGkzznEBmiwoNJ Q3P6oHu7+S69GOMTxWaFI4zshDZ/R9aOm0Wzm/2IMRQdNLp8qrkmJ0qAAQgld4CtvQAr RnxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hs8si2977518ejc.113.2020.12.17.08.31.56; Thu, 17 Dec 2020 08:32:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729111AbgLQQ3X (ORCPT + 99 others); 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; }