Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1527357ybh; Mon, 13 Jul 2020 23:31:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTH22qkGHhq/b5FwtLU0i+VobosqMNVVgSVwQ8GL/ncyCWKnPrHMI7X11WCIEsEfOjL57o X-Received: by 2002:aa7:cf02:: with SMTP id a2mr2947735edy.263.1594708276141; Mon, 13 Jul 2020 23:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594708276; cv=none; d=google.com; s=arc-20160816; b=awKLstX47yM7hhfywvrxvM2uTe73OQaERfujC0tyr57i+3rucr9ZLUXihkoG219sOM thWbzKBL/kV1OA16sKwd8QuMyVEcufBvvsqiZVirNmDaS6tpuPu+RdO3O+UeU9KpMCRq LmKgxXlEbat/70mRTAe4dCO/gLp8QUH+2wvENHm++Lz8iXtjRzdPnJy1UKgmXqbjAGrJ 6Zd5D0brdrtWNdlpF5/ZQt2oA/iYoWoU8BLYH7V10IYiE4/4AYw6IRsR9+pVA/p11DMY 7B6hNbQUjxQF+8t0L8xFEtS8cY/GREK/oPPWQoJZKmyxwI/EOUH9Ni3+Dfcs1zpnSCj1 rpEQ== 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=xKUdb+hbruWq3dXXh4qI/EjjmPYKUivuPGyohFu5Zdc=; b=Mow18NYb6oLLxzBQ+XGftytEVbzkkIOsfy/DLrYhoJNH9EM//gpHhPNIil8JWWtD/w YWioTQ+EVfqxlxFNkDQPT3cuxVi0Ja8JQJyIR7F6MGEblVFoYtL0k/yed+iEf95f0Iey 28LDCmuFekUVBJHl9l4t1y8nI9BrcgTZnIhEJQvAca/FJQEHFxfvEV0kBdSdT8AKKFt3 xUFrNId1OUTxgPXEM2Ie6GZdIgSGuE24EKrtZ/5coX8vhW9AQXY17JShpe0KgkCD/7bs s44qhztxriMYhtGzc8Eh0BuBGD1snPKip5RrmsU8TdXzP3ufHO2LTu0OacZpAIYCItyu 9ySw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z1pIw6B6; 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 z22si9650880edr.357.2020.07.13.23.30.51; Mon, 13 Jul 2020 23:31:16 -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=Z1pIw6B6; 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 S1725890AbgGNGak (ORCPT + 99 others); Tue, 14 Jul 2020 02:30:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725306AbgGNGaj (ORCPT ); Tue, 14 Jul 2020 02:30:39 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AEA6C061755 for ; Mon, 13 Jul 2020 23:30:39 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id g13so11992536qtv.8 for ; Mon, 13 Jul 2020 23:30:39 -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=xKUdb+hbruWq3dXXh4qI/EjjmPYKUivuPGyohFu5Zdc=; b=Z1pIw6B6uzxLqjeiithtmBN//JH5zTwrontI9A0wpciJZKFIN2eVo5jw04Cvg/SIEa DRXXCUTDKiaKUpk8qO74/ajpvPqUKMuHdwYLWgyU3t2MMaNz+AvGVycKWGkE6XXqOakB qZ43yCZIQHokPk2kJhzB6p2AoN1s9Zqf8/+qiI8S8gN7qiQ3HbqYPLrk8mVYyF9q5Qpb ZooRm/AIhdoBzUSwF6np8p/PTjKI46LCIuATVqLZysGmuVIqskp+wRC6ybthvLwcAc02 a6ohhKEpWV23JpphtPF0Z2yq0A+qp3gNhxXYFOuxE2aa+lyS5FdbQtud8ouqWPviOEdC nkrg== 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=xKUdb+hbruWq3dXXh4qI/EjjmPYKUivuPGyohFu5Zdc=; b=U4B8plJ7QfdCYgcnTHEPc1QlKG7Fzet4exwnfsEUfsbOdjHUqRBShAU6uXgKtf5GPY 1DZj5aUGmv1y31stgjmUbO0Ztz8vBcG9PeZ4q6hkARiTVL8nAM91cRIhbGJ3HhlCDip6 DYjMrzWwYr6+tIVlKOsFtL+rbEjTDmRy0pgfyOZYqHFjluYPR16N1YhufgBukTolwXwy TmwqNz5xRj7nloadah1H+XbNPPATC6jOyZ46o/yPRFS+6BX56gUmxe9vlYyZUI4Ex3Ol vChSFMjaqEb6YlYbw+q2hRkhsUoi7cW4DHY8TxWUM4VEOeUyWX1esc/2XtY1W8rinfgG 476Q== X-Gm-Message-State: AOAM531LdscdFJT0eOcjFHsU8BQnrV4W+B5QeXqNMq7WzYt6+laOdvqG azhk7LgUTXpb3rc4vQQPBrI= X-Received: by 2002:ac8:3895:: with SMTP id f21mr3236543qtc.41.1594708238404; Mon, 13 Jul 2020 23:30:38 -0700 (PDT) Received: from LeoBras (179-125-193-229.dynamic.desktop.com.br. [179.125.193.229]) by smtp.gmail.com with ESMTPSA id w1sm20098819qkf.73.2020.07.13.23.30.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 23:30:37 -0700 (PDT) Message-ID: Subject: Re: [PATCH v3 4/6] powerpc/pseries/iommu: Remove default DMA window before creating DDW From: Leonardo Bras To: Alexey Kardashevskiy , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Thiago Jung Bauermann , Ram Pai Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Date: Tue, 14 Jul 2020 03:30:31 -0300 In-Reply-To: <18fd94d2-4365-16d1-7c85-af07d5c9a0f3@ozlabs.ru> References: <20200703061844.111865-1-leobras.c@gmail.com> <20200703061844.111865-5-leobras.c@gmail.com> <8c29be499e8741e7d77d53ca005034a2ca0179ac.camel@gmail.com> <18fd94d2-4365-16d1-7c85-af07d5c9a0f3@ozlabs.ru> 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 Tue, 2020-07-14 at 14:52 +1000, Alexey Kardashevskiy wrote: > > On 14/07/2020 12:40, Leonardo Bras wrote: > > Thank you for this feedback Alexey! > > > > On Mon, 2020-07-13 at 17:33 +1000, Alexey Kardashevskiy wrote: > > > [...] > > > > - int len, ret; > > > > + int len, ret, reset_win_ext; > > > > > > Make it "reset_token". > > > > Oh, it's not a token here, it just checks if the reset_win extension > > exists. The token would be returned in *value, but since we did not > > need it here, it's not copied. > > ah right, so it is a bool actually. In fact I did it a int, as it's the return value of ddw_read_ext(), which can return 0 on success and -error otherwise. > > > > [...] > > > > -out_failed: > > > > +out_restore_defwin: > > > > + if (default_win && reset_win_ext == 0) > > > > > > reset_win_ext potentially may be uninitialized here. Yeah I know it is > > > tied to default_win but still. > > > > I can't see it being used uninitialized here, as you said it's tied to > > default_win. > > Where it is declared - it is not initialized so in theory it can skip > "if (query.windows_available == 0)". Humm, I thought doing if (default_win && reset_win_ext == 0) would guarantee default_win to be tested before reset_win_ext is ever tested, so I could control it using default_win. > > > > Could you please tell me how it can be used uninitialized here, or what > > is bad by doing this way? > > > > > After looking at this function for a few minutes, it could use some > > > refactoring (way too many gotos) such as: > > > > Yes, I agree. > > > > > 1. move (query.page_size & xx) checks before "if > > > (query.windows_available == 0)" > > > > Moving 'page_size selection' above 'checking windows available' will > > need us to duplicate the 'page_size selection' after the new query, > > inside the if. > > page_size selection is not going to change, why? In theory, a query after freeing the default DMA window could have a different (bigger) page size, so we should test again. > > > > I mean, as query will be done again, it will need to get the (new) page > > size. > > > > > 2. move "win64 = kzalloc(sizeof(struct property), GFP_KERNEL)" before > > > "if (query.windows_available == 0)" > > > 3. call "reset_dma_window(dev, pdn)" inside the "if > > > (query.windows_available == 0)" branch. > > > Then you can drop all "goto out_restore_defwin" and move default_win and > > > reset_win_ext inside "if (query.windows_available == 0)". > > > > I did all changes suggested locally and did some analysis in the > > result: > > > > I did not see a way to put default_win and reset_win_ext inside > > "if (query.windows_available == 0)", because if we still need a way to > > know if the default window was removed, and if so, restore in case > > anything ever fails ahead (like creating the node property). > > Ah, I missed that new out_restore_defwin label is between other exit > labels. Sorry :-/ > > > > reset_win_ext = ddw_read_ext(pdn, > > DDW_EXT_RESET_DMA_WIN, NULL); > > - if (reset_win_ext) > > + if (reset_win_ext){ > > + default_win = NULL; > > goto out_failed; > > + } > > This says "if we can reset, then we fail", no? Here ddw_read_ext() should return 0 if extension was found, and (-EINVAL, -ENODATA or -EOVERFLOW) otherwise. So it should return nonzero if we can't find the extension, in which case we should fail. > > > remove_dma_window(pdn, ddw_avail, default_win); > > I think you can do "default_win=NULL" here and later at > out_restore_defwin check if it is NULL - then call reset. Currently I initialize 'default_win = NULL', and it only changes when I read the default DMA window. If reset is not available I restore it to NULL, so it will be not-NULL only when the have removed the default DMA window. If I make it NULL here, we either never reset the default DMA window (as it is now "if (default_win)" ) or we may always reset it (in case "if (default_win == NULL)"). If you think it's better, I can create a bool variable like "default_win_removed", initialized with 'false', which can be assigned here with 'true' and test in the end if(default_win_removed) reset(); This would allow to move default_win inside this 'if block'. What do you think? > > [...] > > > > -out_restore_defwin: > > - if (default_win && reset_win_ext == 0) > > +out_failed: > > + if (default_win) > > reset_dma_window(dev, pdn); > > > > -out_failed: > > fpdn = kzalloc(sizeof(*fpdn), GFP_KERNEL); > > if (!fpdn) > > goto out_unlock; > > > > ##### > > > > What do you think? > > > > > > > > > The rest of the series is good as it is, > > > > Thank you :) > > > > > however it may conflict with > > > https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20200713062348.100552-1-aik@ozlabs.ru/ > > > and the patchset it is made on top of - > > > https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=188385 . > > > > > > > (do not rush, let me finish reviewing this first) > > > > Ok, I have no problem rebasing on top of those patchsets, but what > > would you suggest to be done? > > Polish this patch one more time and if by the time when you reposted it > the other patchset is not in upstream, I'll ask Michael to take yours first. Ok :) > > > Would it be ok doing a big multi-author patchset, so we guarantee it > > being applied in the correct order? > > > (You probably want me to rebase my patchset on top of Hellwig + yours, > > right?) > > Nah, at least not yet. Thank you!