From patchwork Tue Oct 19 15:03:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sanekf@nxt.ru X-Patchwork-Id: 12572703 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AF1FC433F5 for ; Wed, 20 Oct 2021 16:49:02 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 47BFF6137C for ; Wed, 20 Oct 2021 16:48:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 47BFF6137C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=nxt.ru Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org 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 284061674; Wed, 20 Oct 2021 18:48:08 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 284061674 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1634748538; bh=8X4CEBaMvHnZ/ykUsrBW1TzXfkP1+KQl98ZuA92lrkQ=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=AHybOiTrEvTg7yrdrPwgbQ46z3GfijyBpEd0C5g5LGPaNR082Td2UYTW7wbs8erJZ yjqk/+cC5N7+13kakEnzMhIgTIGL5hohW5I+95TnzTpehyR5ga6GC1miaqSSoEXKWA Vr8JxDFKN4Cz0bIQo5bXlULJwd0owKYNBxuSzqLA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B2E17F80082; Wed, 20 Oct 2021 18:48:07 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3E046F80240; Tue, 19 Oct 2021 17:03:20 +0200 (CEST) Received: from forward400p.mail.yandex.net (forward400p.mail.yandex.net [77.88.28.105]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 10E12F80111 for ; Tue, 19 Oct 2021 17:03:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 10E12F80111 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=nxt.ru header.i=@nxt.ru header.b="LuYqnK6k" Received: from sas1-35b601a382d3.qloud-c.yandex.net (sas1-35b601a382d3.qloud-c.yandex.net [IPv6:2a02:6b8:c08:c505:0:640:35b6:1a3]) by forward400p.mail.yandex.net (Yandex) with ESMTP id B3FDE642286; Tue, 19 Oct 2021 18:03:09 +0300 (MSK) Received: from 2a02:6b8:c08:ff10:0:640:4fe1:bb3c (2a02:6b8:c08:ff10:0:640:4fe1:bb3c [2a02:6b8:c08:ff10:0:640:4fe1:bb3c]) by sas1-35b601a382d3.qloud-c.yandex.net (mxback/Yandex) with HTTP id 73eMvu1D8uQ1-38DSiAdb; Tue, 19 Oct 2021 18:03:08 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxt.ru; s=mail; t=1634655788; bh=RySuvpUFF5Z2mnwc3pWWlYjRFA8psdGb79jKB96dvSo=; h=Message-Id:Date:Cc:Subject:To:From; b=LuYqnK6keNdYKAST6FSAFHNtkE91MS1PB7lj3MqEcXkvoNy6ClnCbKgYv1ioDICqU vJECXjXXppNR75wJDFwcufKKOiUm3Od2aAUbM5z4/QApjhIPttIo8zYAUUHULa3l3i PsrTqbm5gNTJLZpfRsEoLG6QpsCpvLyaA1Jlscrs= Authentication-Results: sas1-35b601a382d3.qloud-c.yandex.net; dkim=pass header.i=@nxt.ru Received: by sas2-4fe1bb3c0a49.qloud-c.yandex.net with HTTP; Tue, 19 Oct 2021 18:03:08 +0300 From: sanekf@nxt.ru To: Takashi Iwai Subject: WC vs UC mappings in snd_dma_sg_alloc() MIME-Version: 1.0 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Tue, 19 Oct 2021 18:03:08 +0300 Message-Id: <493661634654791@mail.yandex.ru> X-Mailman-Approved-At: Wed, 20 Oct 2021 18:48:06 +0200 Cc: alsa-devel@alsa-project.org, Mark Brown , linux-kernel@vger.kernel.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" Hi I've stumbled across this code in sound/core/sgbuf.c: 66 static void *snd_dma_sg_alloc(struct snd_dma_buffer *dmab, size_t size) 67 { < ... > 80 if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG) { 81 type = SNDRV_DMA_TYPE_DEV_WC; 82 #ifdef pgprot_noncached 83 prot = pgprot_noncached(PAGE_KERNEL); 84 #endif 85 } < ... > 131 area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP, prot); Does not this violate x86 rules about using the same memory mapping type for all mappings? It seems that the following patch should fix it (only compile tested - my x86 PCs are either without Linux or without sound, and probably in practice this might not trigger any problems since both WC and UC-minus are incoherent types): ----------------------------- ALSA: memalloc: duly use pgprot_writecombine() for WC mapping x86 has strict rules about not having memory type aliasing (Documentation/x86/pat.rst). snd_dma_sg_alloc() violates them by mapping first as WC (with set_memory_wc()) and then as UC- (with pgprot_noncached() + vmap()). Switching to pgprot_writecombine() should fix this. Signed-off-by: Aleksandr Fedorov diff --git a/sound/core/sgbuf.c b/sound/core/sgbuf.c index 8352a5cdb19f..670b30c3b6e5 100644 --- a/sound/core/sgbuf.c +++ b/sound/core/sgbuf.c @@ -79,9 +79,7 @@ static void *snd_dma_sg_alloc(struct snd_dma_buffer *dmab, size_t size) return NULL; if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG) { type = SNDRV_DMA_TYPE_DEV_WC; -#ifdef pgprot_noncached - prot = pgprot_noncached(PAGE_KERNEL); -#endif + prot = pgprot_writecombine(PAGE_KERNEL); } sgbuf->dev = dmab->dev.dev; pages = snd_sgbuf_aligned_pages(size);