Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1921313pxa; Sun, 23 Aug 2020 22:47:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXxr4dhCjzP0Cbka9YLfmiBXZaCvPKVYomu7sUXJUnGNtnw9HsxRzefJ6ibPN/My3xUYz7 X-Received: by 2002:a05:6402:1758:: with SMTP id v24mr3957111edx.274.1598248024724; Sun, 23 Aug 2020 22:47:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598248024; cv=none; d=google.com; s=arc-20160816; b=tAalMkUCHVmCqrL2wq7M8DqKSxixcp0Y04DHEo89crDfGbYmMVaVmJPayVBGXAMBOs 6wxHSBFk1Vkzha+o5dba6tEWIj/13eevNhnhKi2XQ8nXEUNoDHqKqklROBbBBUObn7M7 wD3M6S3z1k7gI+nHZtvvHdNjvTZBgNEBnVJm2XtEDdLIRmbjFBO7EFZIkhG22ABFTC1Z kZU8Q9lKceN+AIov+0/9QXaOnPBea4YvNYMxzfnUIPIsTPlIxe85XZxiXaNssCsnckzJ zQ8DjC4BOLrrH80laIrCYg8qOXW8fRt9xX8eA3LUZKAkJPUlwrRQ2n/pctpo3U64Qp+4 pUhQ== 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:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject:dkim-signature; bh=M/9hECGSRmL3KSE+kMIwcqbc+Rwjzw1H9zWt9gra3Cc=; b=yjTtduOGa3Ew1gNGqXauUCoaQPw0CnxcSwfz7STcEwo8fxzlS6FMak+u+gR+7ei0+S Rj+jdNjKOTAAs5fr1bZ1C3TOn3JDZpaYOAGMuRbqwHjrofSoskf62kHIo9ibKI6SJ7Bs LNi3KX/PojS8wt2Vb8MvHXEWZb7rrevosXIZKA3xetYea8aar6kjdzZK9gI3B7vgyq/p wqS/Huj/RGIZNY/sNhUaGfgmKVhRNppDPHDaEwCoFx9GQ92DOqadxQJJPJllaE+gzS5O Q6q+kTfjRyoceq62UoeAAkjMm5w2RCJrl/LnzCCYE8QyK4EjNtOeJzV0qVUif/ZsEICC IBbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ozlabs-ru.20150623.gappssmtp.com header.s=20150623 header.b=XrQEN6fW; 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 g1si6071649ejj.660.2020.08.23.22.46.41; Sun, 23 Aug 2020 22:47:04 -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=@ozlabs-ru.20150623.gappssmtp.com header.s=20150623 header.b=XrQEN6fW; 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 S1727915AbgHXFRv (ORCPT + 99 others); Mon, 24 Aug 2020 01:17:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725998AbgHXFRu (ORCPT ); Mon, 24 Aug 2020 01:17:50 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AC89C061573 for ; Sun, 23 Aug 2020 22:17:50 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id d4so3587860pjx.5 for ; Sun, 23 Aug 2020 22:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ozlabs-ru.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:autocrypt:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=M/9hECGSRmL3KSE+kMIwcqbc+Rwjzw1H9zWt9gra3Cc=; b=XrQEN6fWLFaKTZhrIvmjgbzJMboIqukewCl7z8ES8BtJKHG2IVcBwVFRLnHDcDndi2 ptH5uE79+FCpP060ZQbaxcDEFuxSuOiKwLznzUO+lEZYVhgQ9JHgGFbdUrAq++jUkoJ1 HRT3hUCLVY6kM3Lkj5RqKtCGds5TpLxeISRshzkA9Erv8ds6CfyhM2prrJ4bC4gH8Mq8 KPHoRfBvaZ6qdozGMFPNX973SGDEdJL772rtClK9geY5qAYiwZx5N+7UEn9mI8I8XEa7 kqrdH/vgoz1JCBS0jDQ5CByYz88L4md7sILkeycgWfN9lWPlrBe3oZZLP7qvABYpWxt/ Khag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=M/9hECGSRmL3KSE+kMIwcqbc+Rwjzw1H9zWt9gra3Cc=; b=OI/7LpvQXpLi+pJpD8R6IFR93JsqT6xq1u/0aFZwLreaAlkxrDG9dowmojAvRmBB3r JPQAg5tn85FFj8wRbUfBjzZG4Rvq3mrmSFZ4EjbtqxV58qhWn3UIJbh12wRC6TbnhxO+ D67tCxD5O0o5MLo7Xt9V+6PZHXqaSvI4JmZ5epNNpZdVVEm4IVoiwNuukGQ2NgXx5qFN X70MRUIldiOc3BPlSEmlTwclWei32PMsXVA+cksySPqgn4vSvVSSAEyLONlw3n7H+lNl moEwyo9bIQW32QMCVhQg2/KXeld8gArXQ3rYPTJsG2i4GdkbNlZJPXNT+MwJH2q1aL4U SLOQ== X-Gm-Message-State: AOAM531JX+5Abpsk+mvYfGitPFEphYmVPG+nyJMAhNYHSlv21Nq0z5/q wTgGOsOdVU1KhwCO+CcYvMuiBcG5FUWAbQ== X-Received: by 2002:a17:90a:dd45:: with SMTP id u5mr3386847pjv.198.1598246269441; Sun, 23 Aug 2020 22:17:49 -0700 (PDT) Received: from [192.168.10.94] (124-171-83-152.dyn.iinet.net.au. [124.171.83.152]) by smtp.gmail.com with ESMTPSA id 78sm1562924pfv.200.2020.08.23.22.17.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 23 Aug 2020 22:17:48 -0700 (PDT) Subject: Re: [PATCH v1 09/10] powerpc/pseries/iommu: Make use of DDW even if it does not map the partition To: Leonardo Bras , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Christophe Leroy , Joel Stanley , Thiago Jung Bauermann , Ram Pai , Brian King , Murilo Fossa Vicentini , David Dai Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20200817234033.442511-1-leobras.c@gmail.com> <20200817234033.442511-10-leobras.c@gmail.com> From: Alexey Kardashevskiy Autocrypt: addr=aik@ozlabs.ru; keydata= mQINBE+rT0sBEADFEI2UtPRsLLvnRf+tI9nA8T91+jDK3NLkqV+2DKHkTGPP5qzDZpRSH6mD EePO1JqpVuIow/wGud9xaPA5uvuVgRS1q7RU8otD+7VLDFzPRiRE4Jfr2CW89Ox6BF+q5ZPV /pS4v4G9eOrw1v09lEKHB9WtiBVhhxKK1LnUjPEH3ifkOkgW7jFfoYgTdtB3XaXVgYnNPDFo PTBYsJy+wr89XfyHr2Ev7BB3Xaf7qICXdBF8MEVY8t/UFsesg4wFWOuzCfqxFmKEaPDZlTuR tfLAeVpslNfWCi5ybPlowLx6KJqOsI9R2a9o4qRXWGP7IwiMRAC3iiPyk9cknt8ee6EUIxI6 t847eFaVKI/6WcxhszI0R6Cj+N4y+1rHfkGWYWupCiHwj9DjILW9iEAncVgQmkNPpUsZECLT WQzMuVSxjuXW4nJ6f4OFHqL2dU//qR+BM/eJ0TT3OnfLcPqfucGxubhT7n/CXUxEy+m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wNe0ezgGiWxxvyNwThOHc5JvpzJLd32VDFilbxgu4Hhnf6LcgZJ2c Zd44XWqUu7FzVOYaSgIvTP0hNrBYm/E6M7yrLbs3JY74fGzPWGRbBUHTZXQEqQnZglXaVB5V ZhSFtHopZnBSCUSNDbB+QGy4B/E++Bb02IBTGl/JxmOwG+kZUnymsPvTtnNIeTLHxN/H/ae0 c7E5M+/NpslPCmYnDjs5qg0/3ihh6XuOGggZQOqrYPC3PnsNs3NxirwOkVPQgO6mXxpuifvJ DG9EMkK8IBXnLulqVk54kf7fE0jT/d8RTtJIA92GzsgdK2rpT1MBKKVffjRFGwN7nQVOzi4T XrB5p+6ML7Bd84xOEGsj/vdaXmz1esuH7BOZAGEZfLRCHJ0GVCSssg== Message-ID: Date: Mon, 24 Aug 2020 15:17:42 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200817234033.442511-10-leobras.c@gmail.com> Content-Type: text/plain; charset=utf-8 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 On 18/08/2020 09:40, Leonardo Bras wrote: > As of today, if the biggest DDW that can be created can't map the whole > partition, it's creation is skipped and the default DMA window > "ibm,dma-window" is used instead. > > DDW is 16x bigger than the default DMA window, 16x only under very specific circumstances which are 1. phyp 2. sriov 3. device class in hmc (or what that priority number is in the lpar config). > having the same amount of > pages, but increasing the page size to 64k. > Besides larger DMA window, "Besides being larger"? > it performs better for allocations over 4k, Better how? > so it would be nice to use it instead. I'd rather say something like: === So far we assumed we can map the guest RAM 1:1 to the bus which worked with a small number of devices. SRIOV changes it as the user can configure hundreds VFs and since phyp preallocates TCEs and does not allow IOMMU pages bigger than 64K, it has to limit the number of TCEs per a PE to limit waste of physical pages. === > > The DDW created will be used for direct mapping by default. > If it's not available, indirect mapping will be used instead. > > For indirect mapping, it's necessary to update the iommu_table so > iommu_alloc() can use the DDW created. For this, > iommu_table_update_window() is called when everything else succeeds > at enable_ddw(). > > Removing the default DMA window for using DDW with indirect mapping > is only allowed if there is no current IOMMU memory allocated in > the iommu_table. enable_ddw() is aborted otherwise. > > As there will never have both direct and indirect mappings at the same > time, the same property name can be used for the created DDW. > > So renaming > define DIRECT64_PROPNAME "linux,direct64-ddr-window-info" > to > define DMA64_PROPNAME "linux,dma64-ddr-window-info" > looks the right thing to do. I know I suggested this but this does not look so good anymore as I suspect it breaks kexec (from older kernel to this one) so you either need to check for both DT names or just keep the old one. Changing the macro name is fine. > > To make sure the property differentiates both cases, a new u32 for flags > was added at the end of the property, where BIT(0) set means direct > mapping. > > Signed-off-by: Leonardo Bras > --- > arch/powerpc/platforms/pseries/iommu.c | 108 +++++++++++++++++++------ > 1 file changed, 84 insertions(+), 24 deletions(-) > > diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c > index 3a1ef02ad9d5..9544e3c91ced 100644 > --- a/arch/powerpc/platforms/pseries/iommu.c > +++ b/arch/powerpc/platforms/pseries/iommu.c > @@ -350,8 +350,11 @@ struct dynamic_dma_window_prop { > __be64 dma_base; /* address hi,lo */ > __be32 tce_shift; /* ilog2(tce_page_size) */ > __be32 window_shift; /* ilog2(tce_window_size) */ > + __be32 flags; /* DDW properties, see bellow */ > }; > > +#define DDW_FLAGS_DIRECT 0x01 This is set if ((1<= ddw_memory_hotplug_max()), you could simply check window_shift and drop the flags. > + > struct direct_window { > struct device_node *device; > const struct dynamic_dma_window_prop *prop; > @@ -377,7 +380,7 @@ static LIST_HEAD(direct_window_list); > static DEFINE_SPINLOCK(direct_window_list_lock); > /* protects initializing window twice for same device */ > static DEFINE_MUTEX(direct_window_init_mutex); > -#define DIRECT64_PROPNAME "linux,direct64-ddr-window-info" > +#define DMA64_PROPNAME "linux,dma64-ddr-window-info" > > static int tce_clearrange_multi_pSeriesLP(unsigned long start_pfn, > unsigned long num_pfn, const void *arg) > @@ -836,7 +839,7 @@ static void remove_ddw(struct device_node *np, bool remove_prop) > if (ret) > return; > > - win = of_find_property(np, DIRECT64_PROPNAME, NULL); > + win = of_find_property(np, DMA64_PROPNAME, NULL); > if (!win) > return; > > @@ -852,7 +855,7 @@ static void remove_ddw(struct device_node *np, bool remove_prop) > np, ret); > } > > -static bool find_existing_ddw(struct device_node *pdn, u64 *dma_addr) > +static bool find_existing_ddw(struct device_node *pdn, u64 *dma_addr, bool *direct_mapping) > { > struct direct_window *window; > const struct dynamic_dma_window_prop *direct64; > @@ -864,6 +867,7 @@ static bool find_existing_ddw(struct device_node *pdn, u64 *dma_addr) > if (window->device == pdn) { > direct64 = window->prop; > *dma_addr = be64_to_cpu(direct64->dma_base); > + *direct_mapping = be32_to_cpu(direct64->flags) & DDW_FLAGS_DIRECT; > found = true; > break; > } > @@ -901,8 +905,8 @@ static int find_existing_ddw_windows(void) > if (!firmware_has_feature(FW_FEATURE_LPAR)) > return 0; > > - for_each_node_with_property(pdn, DIRECT64_PROPNAME) { > - direct64 = of_get_property(pdn, DIRECT64_PROPNAME, &len); > + for_each_node_with_property(pdn, DMA64_PROPNAME) { > + direct64 = of_get_property(pdn, DMA64_PROPNAME, &len); > if (!direct64) > continue; > > @@ -1124,7 +1128,8 @@ static void reset_dma_window(struct pci_dev *dev, struct device_node *par_dn) > } > > static int ddw_property_create(struct property **ddw_win, const char *propname, > - u32 liobn, u64 dma_addr, u32 page_shift, u32 window_shift) > + u32 liobn, u64 dma_addr, u32 page_shift, > + u32 window_shift, bool direct_mapping) > { > struct dynamic_dma_window_prop *ddwprop; > struct property *win64; > @@ -1144,6 +1149,36 @@ static int ddw_property_create(struct property **ddw_win, const char *propname, > ddwprop->dma_base = cpu_to_be64(dma_addr); > ddwprop->tce_shift = cpu_to_be32(page_shift); > ddwprop->window_shift = cpu_to_be32(window_shift); > + if (direct_mapping) > + ddwprop->flags = cpu_to_be32(DDW_FLAGS_DIRECT); > + > + return 0; > +} > + > +static int iommu_table_update_window(struct iommu_table **tbl, int nid, unsigned long liobn, > + unsigned long win_addr, unsigned long page_shift, > + unsigned long window_size) Rather strange helper imho. I'd extract the most of iommu_table_setparms_lpar() into iommu_table_setparms() (except of_parse_dma_window) and call new helper from where you call iommu_table_update_window; and do iommu_pseries_alloc_table/iommu_tce_table_put there. > +{ > + struct iommu_table *new_tbl, *old_tbl; > + > + new_tbl = iommu_pseries_alloc_table(nid); > + if (!new_tbl) > + return -ENOMEM; > + > + old_tbl = *tbl; > + new_tbl->it_index = liobn; > + new_tbl->it_offset = win_addr >> page_shift; > + new_tbl->it_page_shift = page_shift; > + new_tbl->it_size = window_size >> page_shift; > + new_tbl->it_base = old_tbl->it_base; Should not be used in pseries. > + new_tbl->it_busno = old_tbl->it_busno; > + new_tbl->it_blocksize = old_tbl->it_blocksize; 16 for pseries and does not change (may be even make it a macro). > + new_tbl->it_type = old_tbl->it_type; TCE_PCI. > + new_tbl->it_ops = old_tbl->it_ops; > + > + iommu_init_table(new_tbl, nid, old_tbl->it_reserved_start, old_tbl->it_reserved_end); > + iommu_tce_table_put(old_tbl); > + *tbl = new_tbl; > > return 0; > } > @@ -1171,12 +1206,16 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn) > struct direct_window *window; > struct property *win64 = NULL; > struct failed_ddw_pdn *fpdn; > - bool default_win_removed = false; > + bool default_win_removed = false, maps_whole_partition = false; s/maps_whole_partition/direct_mapping/ > + struct pci_dn *pci = PCI_DN(pdn); > + struct iommu_table *tbl = pci->table_group->tables[0]; > > mutex_lock(&direct_window_init_mutex); > > - if (find_existing_ddw(pdn, &dev->dev.archdata.dma_offset)) > - goto out_unlock; > + if (find_existing_ddw(pdn, &dev->dev.archdata.dma_offset, &maps_whole_partition)) { > + mutex_unlock(&direct_window_init_mutex); > + return maps_whole_partition; > + } > > /* > * If we already went through this for a previous function of > @@ -1258,16 +1297,24 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn) > query.page_size); > goto out_failed; > } > + > /* verify the window * number of ptes will map the partition */ > - /* check largest block * page size > max memory hotplug addr */ > max_addr = ddw_memory_hotplug_max(); > if (query.largest_available_block < (max_addr >> page_shift)) { > - dev_dbg(&dev->dev, "can't map partition max 0x%llx with %llu " > - "%llu-sized pages\n", max_addr, query.largest_available_block, > - 1ULL << page_shift); > - goto out_failed; > + dev_dbg(&dev->dev, "can't map partition max 0x%llx with %llu %llu-sized pages\n", > + max_addr, query.largest_available_block, > + 1ULL << page_shift); > + > + len = order_base_2(query.largest_available_block << page_shift); > + } else { > + maps_whole_partition = true; > + len = order_base_2(max_addr); > } > - len = order_base_2(max_addr); > + > + /* DDW + IOMMU on single window may fail if there is any allocation */ > + if (default_win_removed && !maps_whole_partition && > + iommu_table_in_use(tbl)) > + goto out_failed; > > ret = create_ddw(dev, ddw_avail, &create, page_shift, len); > if (ret != 0) > @@ -1277,8 +1324,8 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn) > create.liobn, dn); > > win_addr = ((u64)create.addr_hi << 32) | create.addr_lo; > - ret = ddw_property_create(&win64, DIRECT64_PROPNAME, create.liobn, win_addr, > - page_shift, len); > + ret = ddw_property_create(&win64, DMA64_PROPNAME, create.liobn, win_addr, > + page_shift, len, maps_whole_partition); > if (ret) { > dev_info(&dev->dev, > "couldn't allocate property, property name, or value\n"); > @@ -1297,12 +1344,25 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn) > if (!window) > goto out_prop_del; > > - ret = walk_system_ram_range(0, memblock_end_of_DRAM() >> PAGE_SHIFT, > - win64->value, tce_setrange_multi_pSeriesLP_walk); > - if (ret) { > - dev_info(&dev->dev, "failed to map direct window for %pOF: %d\n", > - dn, ret); > - goto out_free_window; > + if (maps_whole_partition) { > + /* DDW maps the whole partition, so enable direct DMA mapping */ > + ret = walk_system_ram_range(0, memblock_end_of_DRAM() >> PAGE_SHIFT, > + win64->value, tce_setrange_multi_pSeriesLP_walk); > + if (ret) { > + dev_info(&dev->dev, "failed to map direct window for %pOF: %d\n", > + dn, ret); > + goto out_free_window; > + } > + } else { > + /* New table for using DDW instead of the default DMA window */ > + if (iommu_table_update_window(&tbl, pci->phb->node, create.liobn, > + win_addr, page_shift, 1UL << len)) > + goto out_free_window; > + > + set_iommu_table_base(&dev->dev, tbl); > + WARN_ON(dev->dev.archdata.dma_offset >= SZ_4G); What is this check for exactly? Why 4G, not >= 0, for example? > + goto out_unlock; > + > } > > dev->dev.archdata.dma_offset = win_addr; > @@ -1340,7 +1400,7 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn) > > out_unlock: > mutex_unlock(&direct_window_init_mutex); > - return win64; > + return win64 && maps_whole_partition; > } > > static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev) > -- Alexey