Re: [PATCH 4/4] powerpc/pseries/iommu: Remove default DMA window before creating DDW

From: kernel test robot
Date: Sat Jun 20 2020 - 02:19:25 EST


Hi Leonardo,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on powerpc/next]
[also build test WARNING on v5.8-rc1 next-20200618]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Leonardo-Bras/Remove-default-DMA-window-before-creating-DDW/20200619-131022
base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-randconfig-r031-20200619 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 63700971ac9cdf198faa4a3a7c226fa579e49206)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install powerpc cross compiling tool for clang build
# apt-get install binutils-powerpc-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> arch/powerpc/platforms/pseries/iommu.c:1111:6: warning: variable 'dfl_win' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (ret)
^~~
arch/powerpc/platforms/pseries/iommu.c:1234:6: note: uninitialized use occurs here
if (dfl_win)
^~~~~~~
arch/powerpc/platforms/pseries/iommu.c:1111:2: note: remove the 'if' if its condition is always false
if (ret)
^~~~~~~~
arch/powerpc/platforms/pseries/iommu.c:1079:34: note: initialize the variable 'dfl_win' to silence this warning
struct property *win64, *dfl_win;
^
= NULL
1 warning generated.

vim +1111 arch/powerpc/platforms/pseries/iommu.c

715a454e17d328 Leonardo Bras 2020-06-19 1056
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1057 /*
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1058 * If the PE supports dynamic dma windows, and there is space for a table
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1059 * that can map all pages in a linear offset, then setup such a table,
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1060 * and record the dma-offset in the struct device.
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1061 *
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1062 * dev: the pci device we are checking
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1063 * pdn: the parent pe node with the ibm,dma_window property
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1064 * Future: also check if we can remap the base window for our base page size
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1065 *
9ae2fddeda4cbf Christoph Hellwig 2019-02-13 1066 * returns the dma offset for use by the direct mapped DMA code.
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1067 */
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1068 static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1069 {
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1070 int len, ret;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1071 struct ddw_query_response query;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1072 struct ddw_create_response create;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1073 int page_shift;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1074 u64 dma_addr, max_addr;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1075 struct device_node *dn;
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 1076 u32 ddw_avail[3];
3248d5f65aac44 Leonardo Bras 2020-06-19 1077
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1078 struct direct_window *window;
3248d5f65aac44 Leonardo Bras 2020-06-19 1079 struct property *win64, *dfl_win;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1080 struct dynamic_dma_window_prop *ddwprop;
61435690a9c781 Nishanth Aravamudan 2013-03-07 1081 struct failed_ddw_pdn *fpdn;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1082
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1083 mutex_lock(&direct_window_init_mutex);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1084
b73a635f348610 Milton Miller 2011-05-11 1085 dma_addr = find_existing_ddw(pdn);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1086 if (dma_addr != 0)
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1087 goto out_unlock;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1088
61435690a9c781 Nishanth Aravamudan 2013-03-07 1089 /*
61435690a9c781 Nishanth Aravamudan 2013-03-07 1090 * If we already went through this for a previous function of
61435690a9c781 Nishanth Aravamudan 2013-03-07 1091 * the same device and failed, we don't want to muck with the
61435690a9c781 Nishanth Aravamudan 2013-03-07 1092 * DMA window again, as it will race with in-flight operations
61435690a9c781 Nishanth Aravamudan 2013-03-07 1093 * and can lead to EEHs. The above mutex protects access to the
61435690a9c781 Nishanth Aravamudan 2013-03-07 1094 * list.
61435690a9c781 Nishanth Aravamudan 2013-03-07 1095 */
61435690a9c781 Nishanth Aravamudan 2013-03-07 1096 list_for_each_entry(fpdn, &failed_ddw_pdn_list, list) {
b7c670d673d118 Rob Herring 2017-08-21 1097 if (fpdn->pdn == pdn)
61435690a9c781 Nishanth Aravamudan 2013-03-07 1098 goto out_unlock;
61435690a9c781 Nishanth Aravamudan 2013-03-07 1099 }
61435690a9c781 Nishanth Aravamudan 2013-03-07 1100
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1101 /*
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1102 * the ibm,ddw-applicable property holds the tokens for:
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1103 * ibm,query-pe-dma-window
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1104 * ibm,create-pe-dma-window
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1105 * ibm,remove-pe-dma-window
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1106 * for the given node in that order.
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1107 * the property is actually in the parent, not the PE
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1108 */
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 1109 ret = of_property_read_u32_array(pdn, "ibm,ddw-applicable",
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 1110 &ddw_avail[0], 3);
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 @1111 if (ret)
ae69e1eddc646f Nishanth Aravamudan 2014-01-10 1112 goto out_failed;
25ebc45b93452d Nishanth Aravamudan 2012-05-15 1113
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1114 /*
3248d5f65aac44 Leonardo Bras 2020-06-19 1115 * First step of setting up DDW is removing the default DMA window,
3248d5f65aac44 Leonardo Bras 2020-06-19 1116 * if it's present. It will make all the resources available to the
3248d5f65aac44 Leonardo Bras 2020-06-19 1117 * new DDW window.
3248d5f65aac44 Leonardo Bras 2020-06-19 1118 * If anything fails after this, we need to restore it.
3248d5f65aac44 Leonardo Bras 2020-06-19 1119 */
3248d5f65aac44 Leonardo Bras 2020-06-19 1120
3248d5f65aac44 Leonardo Bras 2020-06-19 1121 dfl_win = of_find_property(pdn, "ibm,dma-window", NULL);
3248d5f65aac44 Leonardo Bras 2020-06-19 1122 if (dfl_win)
3248d5f65aac44 Leonardo Bras 2020-06-19 1123 remove_dma_window(pdn, ddw_avail, dfl_win);
3248d5f65aac44 Leonardo Bras 2020-06-19 1124
3248d5f65aac44 Leonardo Bras 2020-06-19 1125 /*
3248d5f65aac44 Leonardo Bras 2020-06-19 1126 * Query if there is a window of size to map the
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1127 * whole partition. Query returns number of windows, largest
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1128 * block assigned to PE (partition endpoint), and two bitmasks
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1129 * of page sizes: supported and supported for migrate-dma.
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1130 */
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1131 dn = pci_device_to_OF_node(dev);
0ef1ee0bda323e Leonardo Bras 2020-06-19 1132 ret = query_ddw(dev, ddw_avail, &query, pdn);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1133 if (ret != 0)
ae69e1eddc646f Nishanth Aravamudan 2014-01-10 1134 goto out_failed;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1135
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1136 if (query.windows_available == 0) {
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1137 /*
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1138 * no additional windows are available for this device.
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1139 * We might be able to reallocate the existing window,
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1140 * trading in for a larger page size.
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1141 */
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1142 dev_dbg(&dev->dev, "no free dynamic windows");
ae69e1eddc646f Nishanth Aravamudan 2014-01-10 1143 goto out_failed;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1144 }
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 1145 if (query.page_size & 4) {
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1146 page_shift = 24; /* 16MB */
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 1147 } else if (query.page_size & 2) {
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1148 page_shift = 16; /* 64kB */
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 1149 } else if (query.page_size & 1) {
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1150 page_shift = 12; /* 4kB */
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1151 } else {
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1152 dev_dbg(&dev->dev, "no supported direct page size in mask %x",
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1153 query.page_size);
ae69e1eddc646f Nishanth Aravamudan 2014-01-10 1154 goto out_failed;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1155 }
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1156 /* verify the window * number of ptes will map the partition */
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1157 /* check largest block * page size > max memory hotplug addr */
68c0449ea16d77 Alexey Kardashevskiy 2018-12-19 1158 max_addr = ddw_memory_hotplug_max();
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 1159 if (query.largest_available_block < (max_addr >> page_shift)) {
0ef1ee0bda323e Leonardo Bras 2020-06-19 1160 dev_dbg(&dev->dev, "can't map partition max 0x%llx with %llu "
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1161 "%llu-sized pages\n", max_addr, query.largest_available_block,
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1162 1ULL << page_shift);
ae69e1eddc646f Nishanth Aravamudan 2014-01-10 1163 goto out_failed;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1164 }
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1165 len = order_base_2(max_addr);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1166 win64 = kzalloc(sizeof(struct property), GFP_KERNEL);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1167 if (!win64) {
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1168 dev_info(&dev->dev,
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1169 "couldn't allocate property for 64bit dma window\n");
ae69e1eddc646f Nishanth Aravamudan 2014-01-10 1170 goto out_failed;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1171 }
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1172 win64->name = kstrdup(DIRECT64_PROPNAME, GFP_KERNEL);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1173 win64->value = ddwprop = kmalloc(sizeof(*ddwprop), GFP_KERNEL);
767303349e052a Nishanth Aravamudan 2011-05-06 1174 win64->length = sizeof(*ddwprop);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1175 if (!win64->name || !win64->value) {
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1176 dev_info(&dev->dev,
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1177 "couldn't allocate property name and value\n");
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1178 goto out_free_prop;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1179 }
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1180
b73a635f348610 Milton Miller 2011-05-11 1181 ret = create_ddw(dev, ddw_avail, &create, page_shift, len);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1182 if (ret != 0)
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1183 goto out_free_prop;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1184
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 1185 ddwprop->liobn = cpu_to_be32(create.liobn);
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 1186 ddwprop->dma_base = cpu_to_be64(((u64)create.addr_hi << 32) |
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 1187 create.addr_lo);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1188 ddwprop->tce_shift = cpu_to_be32(page_shift);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1189 ddwprop->window_shift = cpu_to_be32(len);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1190
b7c670d673d118 Rob Herring 2017-08-21 1191 dev_dbg(&dev->dev, "created tce table LIOBN 0x%x for %pOF\n",
b7c670d673d118 Rob Herring 2017-08-21 1192 create.liobn, dn);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1193
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1194 window = kzalloc(sizeof(*window), GFP_KERNEL);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1195 if (!window)
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1196 goto out_clear_window;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1197
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1198 ret = walk_system_ram_range(0, memblock_end_of_DRAM() >> PAGE_SHIFT,
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1199 win64->value, tce_setrange_multi_pSeriesLP_walk);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1200 if (ret) {
b7c670d673d118 Rob Herring 2017-08-21 1201 dev_info(&dev->dev, "failed to map direct window for %pOF: %d\n",
b7c670d673d118 Rob Herring 2017-08-21 1202 dn, ret);
7a19081fc26581 Julia Lawall 2011-08-08 1203 goto out_free_window;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1204 }
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1205
79d1c712958f94 Nathan Fontenot 2012-10-02 1206 ret = of_add_property(pdn, win64);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1207 if (ret) {
b7c670d673d118 Rob Herring 2017-08-21 1208 dev_err(&dev->dev, "unable to add dma window property for %pOF: %d",
b7c670d673d118 Rob Herring 2017-08-21 1209 pdn, ret);
7a19081fc26581 Julia Lawall 2011-08-08 1210 goto out_free_window;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1211 }
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1212
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1213 window->device = pdn;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1214 window->prop = ddwprop;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1215 spin_lock(&direct_window_list_lock);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1216 list_add(&window->list, &direct_window_list);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1217 spin_unlock(&direct_window_list_lock);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1218
9410e0185e6539 Alexey Kardashevskiy 2014-09-25 1219 dma_addr = be64_to_cpu(ddwprop->dma_base);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1220 goto out_unlock;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1221
7a19081fc26581 Julia Lawall 2011-08-08 1222 out_free_window:
7a19081fc26581 Julia Lawall 2011-08-08 1223 kfree(window);
7a19081fc26581 Julia Lawall 2011-08-08 1224
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1225 out_clear_window:
5efbabe09d986f Gavin Shan 2014-08-11 1226 remove_ddw(pdn, true);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1227
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1228 out_free_prop:
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1229 kfree(win64->name);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1230 kfree(win64->value);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1231 kfree(win64);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1232
ae69e1eddc646f Nishanth Aravamudan 2014-01-10 1233 out_failed:
3248d5f65aac44 Leonardo Bras 2020-06-19 1234 if (dfl_win)
3248d5f65aac44 Leonardo Bras 2020-06-19 1235 reset_dma_window(dev, pdn);
25ebc45b93452d Nishanth Aravamudan 2012-05-15 1236
61435690a9c781 Nishanth Aravamudan 2013-03-07 1237 fpdn = kzalloc(sizeof(*fpdn), GFP_KERNEL);
61435690a9c781 Nishanth Aravamudan 2013-03-07 1238 if (!fpdn)
61435690a9c781 Nishanth Aravamudan 2013-03-07 1239 goto out_unlock;
61435690a9c781 Nishanth Aravamudan 2013-03-07 1240 fpdn->pdn = pdn;
61435690a9c781 Nishanth Aravamudan 2013-03-07 1241 list_add(&fpdn->list, &failed_ddw_pdn_list);
61435690a9c781 Nishanth Aravamudan 2013-03-07 1242
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1243 out_unlock:
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1244 mutex_unlock(&direct_window_init_mutex);
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1245 return dma_addr;
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1246 }
4e8b0cf46b2570 Nishanth Aravamudan 2011-02-10 1247

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip