Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4757057pxv; Tue, 20 Jul 2021 10:53:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHme5quRVA7q/0VCFuEu5M8F7E/wFfB28yaOr6StQi0isVU/rRHIs/Pt/j/w3v6ocLsUSR X-Received: by 2002:a5d:8186:: with SMTP id u6mr23481825ion.45.1626803579914; Tue, 20 Jul 2021 10:52:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626803579; cv=none; d=google.com; s=arc-20160816; b=L7PKIjBdeiQTnGKHDXe6QkFTbe4nX2gaLTdOjjQlKN5KUoWsHcCMLke6YORlO0rub4 aTJiRKKteZHtFaceHvrseIELGuOnKc0vzgB6BDqTCDlZE/I/w/OXgncUuLzHDvYyT9++ KxJJHw6tP5W2CzE2BSMSSMbxMuZ6GTAVOko9Vo8TYZw/4VAC7TRJgb8WLNBmF7/PngK3 JMBaIuIHs8+fkb/emnxO+i/ZPbsF2l4cnTV4LUuNjeii6xfA7ZTPNA1uEfMjusPMUJpL tn3s+B3m2Zhlh/qAe8UhHdFkKS3Mf9kviDGtXDvjQ4H0L27Tcczat/AE9Q1rLBD7umpL gnMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=PrNdgdKGT7GkTAqpA/hCe0toDTceMwujLTzJJXQiZgY=; b=ebRxcMKPJqomn+AJ0TdszWjv465hkuSGt5o3UBFBoW8wIE2pBa68RkqGMiK/FsV4RS TZhsgSK8CGqeluTh00JowLQUeG3CA0Frgo53Jk0AnoXMLjlwJTFjJa5+Snmz9wQu8g0y 91j9NRIGk3F90XsQZCHhMiuu+CAR5ZYhYg2kT+GMNyRIH6Py48t6Q58epA6wQPuHFbzC 9vadupdTX141CdnEZzM4ljVYwVDmnIeVCPnDr8O5+Aqbfzp3v9mMrIK01bUkMvcAm3WE H/TnONiddrSzYMsK0Ewr6Ngg4UgdeF9WKFLOZSvBDsIls5dL3gPVIO33rK261lZbYY7z lRwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=ZrvaKCd8; 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h3si22356462ila.128.2021.07.20.10.52.46; Tue, 20 Jul 2021 10:52:59 -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=@ibm.com header.s=pp1 header.b=ZrvaKCd8; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231790AbhGTRJ5 (ORCPT + 99 others); Tue, 20 Jul 2021 13:09:57 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:6158 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231652AbhGTRJF (ORCPT ); Tue, 20 Jul 2021 13:09:05 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16KHYRoN091836; Tue, 20 Jul 2021 13:49:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=PrNdgdKGT7GkTAqpA/hCe0toDTceMwujLTzJJXQiZgY=; b=ZrvaKCd8Qu8UdLsC4p51CPClhJmvbremTjhrRP5fD3x1upaQ9G7T2zm9fetJHiFAVJhE 9EmWDje59VOAvd33CYkiBHPvbsdiqv9oJN5OVg/R5malcVynVOodhNDLbpx6MQZoNaGo 0CvPO3Qad2OkiU3AgN8eOOgSFII9bgWTwfzkIPshf5Sx3DRiM44yEmHyWcdVn8KSqkVx YDlgfHxAqkeFDuTgJd5YYpqWbkS2ZX8OwCuWKXL9Adw09fq58hi/TA0A3PpYRDS+IvbN 29N8k/7fa2EQzlvTTDAnUF1C78+ym2jP9iDboI0s8WtzGTWdUPYymmt3XogAuA/diBjU yw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 39wy71ssf7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Jul 2021 13:49:28 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 16KHYiHX092333; Tue, 20 Jul 2021 13:49:28 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 39wy71sse5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Jul 2021 13:49:28 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 16KHh1ch021003; Tue, 20 Jul 2021 17:49:25 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma06ams.nl.ibm.com with ESMTP id 39vng71357-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Jul 2021 17:49:25 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 16KHnNIC36831672 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Jul 2021 17:49:23 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4DA704C04E; Tue, 20 Jul 2021 17:49:23 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E937F4C044; Tue, 20 Jul 2021 17:49:22 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.178.12]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 20 Jul 2021 17:49:22 +0000 (GMT) Subject: Re: [PATCH v5 06/11] powerpc/pseries/iommu: Add ddw_property_create() and refactor enable_ddw() To: Leonardo Bras , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alexey Kardashevskiy , David Gibson , kernel test robot , Nicolin Chen Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20210716082755.428187-1-leobras.c@gmail.com> <20210716082755.428187-7-leobras.c@gmail.com> From: Frederic Barrat Message-ID: <1ab60060-1435-f77a-d2df-84019e7625a2@linux.ibm.com> Date: Tue, 20 Jul 2021 19:49:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210716082755.428187-7-leobras.c@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Vp1lpu0PQ94KhCgD19zjdSpR8D0EAVv9 X-Proofpoint-ORIG-GUID: iU5tmCzWD_RCq-OULjMweQVVYisVKGpW X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-20_12:2021-07-19,2021-07-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 suspectscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 malwarescore=0 adultscore=0 phishscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107200115 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/07/2021 10:27, Leonardo Bras wrote: > Code used to create a ddw property that was previously scattered in > enable_ddw() is now gathered in ddw_property_create(), which deals with > allocation and filling the property, letting it ready for > of_property_add(), which now occurs in sequence. > > This created an opportunity to reorganize the second part of enable_ddw(): > > Without this patch enable_ddw() does, in order: > kzalloc() property & members, create_ddw(), fill ddwprop inside property, > ddw_list_new_entry(), do tce_setrange_multi_pSeriesLP_walk in all memory, > of_add_property(), and list_add(). > > With this patch enable_ddw() does, in order: > create_ddw(), ddw_property_create(), of_add_property(), > ddw_list_new_entry(), do tce_setrange_multi_pSeriesLP_walk in all memory, > and list_add(). > > This change requires of_remove_property() in case anything fails after > of_add_property(), but we get to do tce_setrange_multi_pSeriesLP_walk > in all memory, which looks the most expensive operation, only if > everything else succeeds. > > Signed-off-by: Leonardo Bras > Reviewed-by: Alexey Kardashevskiy > --- > arch/powerpc/platforms/pseries/iommu.c | 93 ++++++++++++++++---------- > 1 file changed, 57 insertions(+), 36 deletions(-) > > diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c > index b34b473bbdc1..7ca79a04fa52 100644 > --- a/arch/powerpc/platforms/pseries/iommu.c > +++ b/arch/powerpc/platforms/pseries/iommu.c > @@ -1153,6 +1153,35 @@ static int iommu_get_page_shift(u32 query_page_size) > return 0; > } > > +static struct property *ddw_property_create(const char *propname, u32 liobn, u64 dma_addr, > + u32 page_shift, u32 window_shift) > +{ > + struct dynamic_dma_window_prop *ddwprop; > + struct property *win64; > + > + win64 = kzalloc(sizeof(*win64), GFP_KERNEL); > + if (!win64) > + return NULL; > + > + win64->name = kstrdup(propname, GFP_KERNEL); > + ddwprop = kzalloc(sizeof(*ddwprop), GFP_KERNEL); > + win64->value = ddwprop; > + win64->length = sizeof(*ddwprop); > + if (!win64->name || !win64->value) { > + kfree(win64->name); > + kfree(win64->value); > + kfree(win64); > + return NULL; > + } > + > + ddwprop->liobn = cpu_to_be32(liobn); > + ddwprop->dma_base = cpu_to_be64(dma_addr); > + ddwprop->tce_shift = cpu_to_be32(page_shift); > + ddwprop->window_shift = cpu_to_be32(window_shift); > + > + return win64; > +} > + > /* > * If the PE supports dynamic dma windows, and there is space for a table > * that can map all pages in a linear offset, then setup such a table, > @@ -1171,12 +1200,12 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn) > struct ddw_query_response query; > struct ddw_create_response create; > int page_shift; > + u64 win_addr; > struct device_node *dn; > u32 ddw_avail[DDW_APPLICABLE_SIZE]; > struct direct_window *window; > struct property *win64; > bool ddw_enabled = false; > - struct dynamic_dma_window_prop *ddwprop; > struct failed_ddw_pdn *fpdn; > bool default_win_removed = false; > bool pmem_present; > @@ -1293,72 +1322,64 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn) > 1ULL << page_shift); > goto out_failed; > } > - win64 = kzalloc(sizeof(struct property), GFP_KERNEL); > - if (!win64) { > - dev_info(&dev->dev, > - "couldn't allocate property for 64bit dma window\n"); > - goto out_failed; > - } > - win64->name = kstrdup(DIRECT64_PROPNAME, GFP_KERNEL); > - win64->value = ddwprop = kmalloc(sizeof(*ddwprop), GFP_KERNEL); > - win64->length = sizeof(*ddwprop); > - if (!win64->name || !win64->value) { > - dev_info(&dev->dev, > - "couldn't allocate property name and value\n"); > - goto out_free_prop; > - } > > ret = create_ddw(dev, ddw_avail, &create, page_shift, len); > if (ret != 0) > - goto out_free_prop; > - > - ddwprop->liobn = cpu_to_be32(create.liobn); > - ddwprop->dma_base = cpu_to_be64(((u64)create.addr_hi << 32) | > - create.addr_lo); > - ddwprop->tce_shift = cpu_to_be32(page_shift); > - ddwprop->window_shift = cpu_to_be32(len); > + goto out_failed; > > dev_dbg(&dev->dev, "created tce table LIOBN 0x%x for %pOF\n", > create.liobn, dn); > > - window = ddw_list_new_entry(pdn, ddwprop); > + win_addr = ((u64)create.addr_hi << 32) | create.addr_lo; > + win64 = ddw_property_create(DIRECT64_PROPNAME, create.liobn, win_addr, > + page_shift, len); > + if (!win64) { > + dev_info(&dev->dev, > + "couldn't allocate property, property name, or value\n"); > + goto out_remove_win; > + } > + > + ret = of_add_property(pdn, win64); > + if (ret) { > + dev_err(&dev->dev, "unable to add dma window property for %pOF: %d", > + pdn, ret); > + goto out_free_prop; > + } > + > + window = ddw_list_new_entry(pdn, win64->value); > if (!window) > - goto out_clear_window; > + goto out_del_prop; > > 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; > - } > - > - ret = of_add_property(pdn, win64); > - if (ret) { > - dev_err(&dev->dev, "unable to add dma window property for %pOF: %d", > - pdn, ret); > - goto out_free_window; > + goto out_del_list; > } > > spin_lock(&direct_window_list_lock); > list_add(&window->list, &direct_window_list); > spin_unlock(&direct_window_list_lock); > > - dev->dev.archdata.dma_offset = be64_to_cpu(ddwprop->dma_base); > + dev->dev.archdata.dma_offset = win_addr; > ddw_enabled = true; > goto out_unlock; > > -out_free_window: > +out_del_list: > kfree(window); > > -out_clear_window: > - remove_ddw(pdn, true); > +out_del_prop: > + of_remove_property(pdn, win64); > > out_free_prop: > kfree(win64->name); > kfree(win64->value); > kfree(win64); > > +out_remove_win: > + remove_ddw(pdn, true); I believe there's a small problem here. We jump directly to out_remove_win if allocating the property failed. Yet, the first thing remove_ddw() does is look for the property. So it will never find it and the window is never removed by the hypervisor. Fred > + > out_failed: > if (default_win_removed) > reset_dma_window(dev, pdn); >