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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80651C433F5 for ; Wed, 20 Oct 2021 16:52:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6493660FE8 for ; Wed, 20 Oct 2021 16:52:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230416AbhJTQyo (ORCPT ); Wed, 20 Oct 2021 12:54:44 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:50660 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbhJTQym (ORCPT ); Wed, 20 Oct 2021 12:54:42 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id E863821965; Wed, 20 Oct 2021 16:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1634748746; 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=wrRshsfFMHPhi2yObW6vfz1kW3pBMoZozxib/dHQHUk=; b=OzTgPb+HuZwKBGHLKIg6wn+HIz+ilc5HAo5b90RWWUnoZynnEvmGpJiaIMjakx3ilzBcyL 74FAvwVOC6F2Q83gTeXSe7hPMpPzWG6L8Qq10i2QpyfJZyO/0f7eVK1i9pEnxu8lIavSxh l1zItGeoypg09Ivm5kwL9DPCDr9cZZw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1634748746; 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=wrRshsfFMHPhi2yObW6vfz1kW3pBMoZozxib/dHQHUk=; b=TiVTIqstTIryN6goDGDSGJhMGVM1lMVdlGQOnTWBZtndl+YW5IeQ9t04k4V9nAopBtn7yi GTFAZlYvLdAApVCQ== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id E1174A3B81; Wed, 20 Oct 2021 16:52:26 +0000 (UTC) Date: Wed, 20 Oct 2021 18:52:26 +0200 Message-ID: From: Takashi Iwai To: sanekf@nxt.ru Cc: Takashi Iwai , alsa-devel@alsa-project.org, Mark Brown , linux-kernel@vger.kernel.org Subject: Re: WC vs UC mappings in snd_dma_sg_alloc() In-Reply-To: <493661634654791@mail.yandex.ru> References: <493661634654791@mail.yandex.ru> 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 Tue, 19 Oct 2021 17:03:08 +0200, sanekf@nxt.ru wrote: > > 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): Actually this has been already fixed in the latest code for 5.16 together with the rewriting of the SG buffer code. There, sgbuf.c is gone completely, and this inconsistency was resolved, too. thanks, Takashi > > ----------------------------- > > 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); >