Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp757906pxa; Thu, 27 Aug 2020 15:12:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKt8Z+u2dAL+54cV+VRY6SQcsJLYARM/ypzjkTcGBMhRJERnUXw0iXb997prmJtYX1sDNC X-Received: by 2002:a17:906:f293:: with SMTP id gu19mr22882824ejb.209.1598566374369; Thu, 27 Aug 2020 15:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598566374; cv=none; d=google.com; s=arc-20160816; b=VUIo738ao4GEiPbzqhjVHL4raX2o6zVJQrfcxFC3kAnqR2wu8hE7XrhFfNrJaOor3v P4bmxQt50Bq/0QuYXc7QRdKddv/65dQgzHYMKfXGW5gmFYatTHzpKYJJq50eCpQirbbe 2huOdosc8HAZ12yYvUszA4p/PHGch4OARgB5oFlzSiBeh7VJoY/5bzhADvtEvF1B24b1 BOaX5rcqMNCXjTmwTqV1YG8PIiCFjhPVG0L2lYSAK0uDj/JfvWizkrIpA1y74vgmbbow NJgPEwBBnQEoF5INwhjxeMLsJjC/Y9J9FYWs0inYWgdWW4uDEAk9nCH01Fk0OBKMlysm G3DQ== 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:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=tckEyhhhQ7HGtoJozq598EKm+bx20MWZHeieMIF9q5g=; b=f0MB/pxZ8aKr0i5uJUyhS+Rwmbcu1aTmntTmEkBvscUpcgnpEfWNZ2DheyR7NiRnZc meSG/0EqiAfJ82zUl/ooNvbaI7X1RpqPHdpxb07Yrh7PZ0sU/goWkRgdrFiHXW0fdkf5 bfhuqzmp+BisFXW6giIUYWn7hpuC82U1+Cif79e7t/nIUdrSVR3k8KC/P48Zx+bAjGhF T8H4JF6OGg+NRk6oKyLYtQH5qnZEQFvEwGlHy1yGO02JGbOZ/Jd/iC40BYw+7EAfWDVT csRZfbqe0HoIJWkrQPK2kBH64qDck2YlPlearyBRFVN/nzuJoxRY2HjLBr5bzjfBh4cX zsvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XufHWbEz; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si2510998edn.508.2020.08.27.15.12.29; Thu, 27 Aug 2020 15:12:54 -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=@gmail.com header.s=20161025 header.b=XufHWbEz; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726953AbgH0WLh (ORCPT + 99 others); Thu, 27 Aug 2020 18:11:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726256AbgH0WLg (ORCPT ); Thu, 27 Aug 2020 18:11:36 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A6AFC061264 for ; Thu, 27 Aug 2020 15:11:36 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id z3so7645153qkz.7 for ; Thu, 27 Aug 2020 15:11:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:user-agent:mime-version:content-transfer-encoding; bh=tckEyhhhQ7HGtoJozq598EKm+bx20MWZHeieMIF9q5g=; b=XufHWbEzrTArFbdd0uvm8hn5uvxsEsVAO3eGPiZJG+A34kNZEwwswC15vWvmQxWbe4 ic9hXfr/HdobtOL/qWXE8X09cd5SECRxF7Nvhjc9tywTzsuI/kb2rK1MWcXoNC1QcTil rWeTMaWqvJeaMWo1xDp6qs8COZPe5OMKNxKoUO8IRfaUWqKI6XIqiR9NwFhe19yg25c0 Dt3syjscZUmmI3s3Zf9PQFjv6C9Sd9ThAcIkQuKLYr4CeUG0ybKD0khabMM+YhyjqTtK GcBHW8KGgand8Vp4WWk6lOg0yUrSlCdN2L9DIi3iPHRIJcs9kGsyHJ+uYtqwT+Iht9to A4iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:organization:user-agent:mime-version :content-transfer-encoding; bh=tckEyhhhQ7HGtoJozq598EKm+bx20MWZHeieMIF9q5g=; b=s/PQRoVfockkDGBCr4nyvgjKzhETeHXY+s0wGuQP7tXVOJhOFuP8gycYcWaBSVGR5H WNZo38VaQrM91o2fWeAAKL2SNkJbAnnLiKX/8wKICWvsMpZOWZjfhcJcKfA15/nDYhVF WWkv9RcXbU01JxO+oB9PMz1oENibhxfMhLA0TDEJS8nDPV90z0G5VyirSVBB2C2n/+uH xA5SDtcYFsnf9dpGDLZT+zCSyrJIm5M9DajLaj/KHlaNn0jOAmGHyqFDGRYebODQLZ6P lKkalth4xbqkElClTw73UTqaMSAmUrJLql0Rn7ZMnq0Q2wO07Xf3g0944hMfAMqARCRH CE7A== X-Gm-Message-State: AOAM5327Y/r/mB7K0fVb1Q0veyG3Tf4KaZHdAwOntH8u8Y7EgvJ7K0om 9XoFloEAj/jK7kuDyzQofHw= X-Received: by 2002:a37:7407:: with SMTP id p7mr21257829qkc.350.1598566295135; Thu, 27 Aug 2020 15:11:35 -0700 (PDT) Received: from LeoBras ([2804:14d:8084:8e41:9b0d:571e:a65:b5d8]) by smtp.gmail.com with ESMTPSA id x5sm2813588qtp.76.2020.08.27.15.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 15:11:34 -0700 (PDT) Message-ID: Subject: Re: [PATCH v1 06/10] powerpc/pseries/iommu: Add ddw_list_add() helper From: Leonardo Bras To: Alexey Kardashevskiy , 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 Date: Thu, 27 Aug 2020 19:11:28 -0300 In-Reply-To: References: <20200817234033.442511-1-leobras.c@gmail.com> <20200817234033.442511-7-leobras.c@gmail.com> Organization: IBM Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.4 (3.34.4-1.fc31) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2020-08-24 at 13:46 +1000, Alexey Kardashevskiy wrote: > > static int find_existing_ddw_windows(void) > > { > > int len; > > @@ -887,18 +905,11 @@ static int find_existing_ddw_windows(void) > > if (!direct64) > > continue; > > > > - window = kzalloc(sizeof(*window), GFP_KERNEL); > > - if (!window || len < sizeof(struct dynamic_dma_window_prop)) { > > + window = ddw_list_add(pdn, direct64); > > + if (!window || len < sizeof(*direct64)) { > > Since you are touching this code, it looks like the "len < > sizeof(*direct64)" part should go above to "if (!direct64)". Sure, makes sense. It will be fixed for v2. > > > > > kfree(window); > > remove_ddw(pdn, true); > > - continue; > > } > > - > > - window->device = pdn; > > - window->prop = direct64; > > - spin_lock(&direct_window_list_lock); > > - list_add(&window->list, &direct_window_list); > > - spin_unlock(&direct_window_list_lock); > > } > > > > return 0; > > @@ -1261,7 +1272,8 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn) > > dev_dbg(&dev->dev, "created tce table LIOBN 0x%x for %pOF\n", > > create.liobn, dn); > > > > - window = kzalloc(sizeof(*window), GFP_KERNEL); > > + /* Add new window to existing DDW list */ > > The comment seems to duplicate what the ddw_list_add name already suggests. Ok, I will remove it then. > > + window = ddw_list_add(pdn, ddwprop); > > if (!window) > > goto out_clear_window; > > > > @@ -1280,16 +1292,14 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn) > > goto out_free_window; > > } > > > > - window->device = pdn; > > - window->prop = ddwprop; > > - spin_lock(&direct_window_list_lock); > > - list_add(&window->list, &direct_window_list); > > - spin_unlock(&direct_window_list_lock); > > I'd leave these 3 lines here and in find_existing_ddw_windows() (which > would make ddw_list_add -> ddw_prop_alloc). In general you want to have > less stuff to do on the failure path. kmalloc may fail and needs kfree > but you can safely delay list_add (which cannot fail) and avoid having > the lock help twice in the same function (one of them is hidden inside > ddw_list_add). > Not sure if this change is really needed after all. Thanks, I understand this leads to better performance in case anything fails. Also, I think list_add happening in the end is less error-prone (in case the list is checked between list_add and a fail). But what if we put it at the end? What is the chance of a kzalloc of 4 pointers (struct direct_window) failing after walk_system_ram_range? Is it not worthy doing that for making enable_ddw() easier to understand? Best regards, Leonardo