Received: by 10.223.185.116 with SMTP id b49csp4222532wrg; Tue, 13 Feb 2018 15:09:25 -0800 (PST) X-Google-Smtp-Source: AH8x227mAK4Fn8TmAKjc+wtMM0e9K2tv4v3WtigNOlajhMa7H2ne5kAq5ymQCpK+UNz451VfQtGW X-Received: by 10.99.152.70 with SMTP id l6mr2139475pgo.87.1518563365588; Tue, 13 Feb 2018 15:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518563365; cv=none; d=google.com; s=arc-20160816; b=m4Vg2SXl8S6iGArru9UHCYxipoyL3lDvXmy8+GVYQPjtvn3/650CQdM9Tsu1j8nSmu YK9qxrREkQoGm+GcNoSC0jkLq9D0TDMseZNA1J2uS2KHNOs5PUysqGrVE3QkBPoybfoK JLUN3yU+5I3mNf+tYWNbOKa+GQq52XHZxSLg8T5GKEqapJ6XzaZa7uZFm6d6jpldSRUd nWmWhpZgROmFquaxAiJvKriHwlbsm8/0hy0dYgFMw0d8c7OIgUu6WotJgCQPeU5Su84/ cmJvmmDgRRJyC14PlswOqzPJRjxRZFm9KywiBOFdpSmwmUmMBTA5bkG3VGiVB0rhShL0 A1ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:cc:to :subject:from:arc-authentication-results; bh=AuTTOGX+ApqEivS2QGV3P0R4KEyl7nTsWDz2T71TXBc=; b=UVCus4EutakdM8N/DEM5n4RXBOtnlAZhsLiEP9mLxVduBXjCsDmjYhYlEzehWJ0H0w RGo5tYXn0uSyVZA5ulcbmCP1PY3z/ZJM8DE1rmOqrGWnRuwIVFrYAWrzufZOuiKlGrMR UZhSrWc3dlBMzDYAi9FV5Pd/nBrDxhjf0jASwi5n9vCOpjlBN5e3lveGZiX2Cixl7vYa Z8RIQpRLh0sSf3buXcdCmNxDYEqoMZ4TDURD/KAe/DnCh7qWKpsHrAUAssg4jAfXigbo Rqgzrk0CDkb7DuP9PwbUuqtitHZsI72ZqvC6gphDp+HFPLwgFpbHj1rxOj/l4mOHjaGh S3wQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si8179526plp.583.2018.02.13.15.09.10; Tue, 13 Feb 2018 15:09:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966133AbeBMXGh (ORCPT + 99 others); Tue, 13 Feb 2018 18:06:37 -0500 Received: from vps-vb.mhejs.net ([37.28.154.113]:54230 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966002AbeBMXGg (ORCPT ); Tue, 13 Feb 2018 18:06:36 -0500 Received: by vps-vb.mhejs.net with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) (envelope-from ) id 1eljel-0002iG-2q; Wed, 14 Feb 2018 00:06:35 +0100 From: "Maciej S. Szmigiero" Subject: [PATCH v3 4/5] ALSA: emu10k1: make sure synth DMA pages are allocated with DMA functions To: Jaroslav Kysela , Takashi Iwai Cc: linux-kernel , alsa-devel@alsa-project.org Message-ID: <048a4aa9-4ca8-5d03-7ff6-097e87306da1@maciej.szmigiero.name> Date: Wed, 14 Feb 2018 00:06:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit a5003fc04113 ("[ALSA] emu10k1 - simplify page allocation for synth") switched from using the DMA allocator for synth DMA pages to manually calling alloc_page(). However, this usage has an implicit assumption that the DMA address space for the emu10k1-family chip is the same as the CPU physical address space which is not true for a system with a IOMMU. Since this made the synth part of the driver non-functional on such systems let's effectively revert that commit (while keeping the __synth_free_pages() simplification). Signed-off-by: Maciej S. Szmigiero --- Changes from v1: None in this patch. Changes from v2: Keep the __synth_free_pages() simplification. sound/pci/emu10k1/memory.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/sound/pci/emu10k1/memory.c b/sound/pci/emu10k1/memory.c index fcb04cbbc9ab..1d0ce7356bbd 100644 --- a/sound/pci/emu10k1/memory.c +++ b/sound/pci/emu10k1/memory.c @@ -461,10 +461,19 @@ static void get_single_page_range(struct snd_util_memhdr *hdr, static void __synth_free_pages(struct snd_emu10k1 *emu, int first_page, int last_page) { + struct snd_dma_buffer dmab; int page; + dmab.dev.type = SNDRV_DMA_TYPE_DEV; + dmab.dev.dev = snd_dma_pci_data(emu->pci); + for (page = first_page; page <= last_page; page++) { - free_page((unsigned long)emu->page_ptr_table[page]); + if (emu->page_ptr_table[page] == NULL) + continue; + dmab.area = emu->page_ptr_table[page]; + dmab.addr = emu->page_addr_table[page]; + dmab.bytes = PAGE_SIZE; + snd_dma_free_pages(&dmab); emu->page_addr_table[page] = 0; emu->page_ptr_table[page] = NULL; } @@ -476,30 +485,31 @@ static void __synth_free_pages(struct snd_emu10k1 *emu, int first_page, static int synth_alloc_pages(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *blk) { int page, first_page, last_page; + struct snd_dma_buffer dmab; emu10k1_memblk_init(blk); get_single_page_range(emu->memhdr, blk, &first_page, &last_page); /* allocate kernel pages */ for (page = first_page; page <= last_page; page++) { - /* first try to allocate from <4GB zone */ - struct page *p = alloc_page(GFP_KERNEL | GFP_DMA32 | - __GFP_NOWARN); - if (!p || (page_to_pfn(p) & ~(emu->dma_mask >> PAGE_SHIFT))) { - if (p) - __free_page(p); - /* try to allocate from <16MB zone */ - p = alloc_page(GFP_ATOMIC | GFP_DMA | - __GFP_NORETRY | /* no OOM-killer */ - __GFP_NOWARN); - } - if (!p) { - __synth_free_pages(emu, first_page, page - 1); - return -ENOMEM; + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, + snd_dma_pci_data(emu->pci), + PAGE_SIZE, &dmab) < 0) + goto __fail; + if (!is_valid_page(emu, dmab.addr)) { + snd_dma_free_pages(&dmab); + goto __fail; } - emu->page_addr_table[page] = page_to_phys(p); - emu->page_ptr_table[page] = page_address(p); + emu->page_addr_table[page] = dmab.addr; + emu->page_ptr_table[page] = dmab.area; } return 0; + +__fail: + /* release allocated pages */ + last_page = page - 1; + __synth_free_pages(emu, first_page, last_page); + + return -ENOMEM; } /*