Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1693031pxb; Wed, 20 Oct 2021 09:54:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyemoNX5FfMfKnfJUvrP2kZ+FAy4/hzYQIIGHF+C7fyZLVL+6DFCDnMxKACB5H+Jo707p1 X-Received: by 2002:a17:906:254b:: with SMTP id j11mr498328ejb.513.1634748893339; Wed, 20 Oct 2021 09:54:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634748893; cv=none; d=google.com; s=arc-20160816; b=JQFLKGySD0Bvs1PlWeUSkv6m14HmkikaKSC/r4vxAZD/9SS+gdMEvQitt1Z5pqisdb mK34k/Ye4o8EHayXJXH6Suu0PY0Z0xFvz6UNe2RlVbnPqb2dFnDPJpobXbMqvI8gd34C fZw/ArDPkra9v71l6nyntolhw3Sg9+wDAnWry3qK5WwgluohgoUxrbQ6PDRBosExn3tC 5MdeNBSOKL6Y8eX6mgG/EU0P3semAxM+6tkdZNOzpfF0X0vGRRXs/BBad+48REb1IKa1 g+krG81PNP1V0r0701QeIAFYU3a4OhoNGPoGxA9nGl7BKqEol9pheyxO37aLJI5VExA0 fp2Q== 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:dkim-signature:dkim-signature; bh=wrRshsfFMHPhi2yObW6vfz1kW3pBMoZozxib/dHQHUk=; b=O/lxDq8Nx7pByVXzX5iVEwy7awG0ml6hA5OTZ3Gv0Z0Rg1xu+Bmtm/O3N6DMi27tZj fYw8O6zGRFYqpZBQJgYp0/HUOAC+KHj19423IQaMre2VwMltg7k8+scBMb9gL/efPkc0 bBDhw7QS5MXLtE/nx20cU+J7c4Nv/Qg61+QjGpTn6q2zoSpqJ5HHo9vwm/IhubhHYXKq gk7G+WRH6egA7mwIfH0zd7f5k3lL3/cmLPkgrlHmbUigS6SKLWPuU0Xd/8cqCcqEN4vY nRf/BEBg0U85kYR7Z65puJH6QuWKfCYWctoLYNVG98fbGrZW01nxNagbN8V6B0UpLWgT 9fOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=OzTgPb+H; dkim=neutral (no key) header.i=@suse.de; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g12si4557404edb.152.2021.10.20.09.54.28; Wed, 20 Oct 2021 09:54:53 -0700 (PDT) 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; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=OzTgPb+H; dkim=neutral (no key) header.i=@suse.de; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230373AbhJTQyn (ORCPT + 99 others); Wed, 20 Oct 2021 12:54:43 -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); >