From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A869C433ED for ; Thu, 20 May 2021 06:48:05 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 200C1611BE for ; Thu, 20 May 2021 06:48:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 200C1611BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.130642.244587 (Exim 4.92) (envelope-from ) id 1ljcTI-0005IY-GT; Thu, 20 May 2021 06:47:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 130642.244587; Thu, 20 May 2021 06:47:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ljcTI-0005IR-DP; Thu, 20 May 2021 06:47:52 +0000 Received: by outflank-mailman (input) for mailman id 130642; Thu, 20 May 2021 06:47:51 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ljcTG-0005IL-Vx for xen-devel@lists.xenproject.org; Thu, 20 May 2021 06:47:51 +0000 Received: from mail-pg1-x536.google.com (unknown [2607:f8b0:4864:20::536]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 04e0867d-a7d3-40ae-ae32-ee08de62c650; Thu, 20 May 2021 06:47:49 +0000 (UTC) Received: by mail-pg1-x536.google.com with SMTP id k15so11146255pgb.10 for ; Wed, 19 May 2021 23:47:49 -0700 (PDT) Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com. [209.85.210.182]) by smtp.gmail.com with ESMTPSA id r5sm5817767pjd.2.2021.05.19.23.47.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 May 2021 23:47:48 -0700 (PDT) Received: by mail-pf1-f182.google.com with SMTP id e17so1039722pfl.5 for ; Wed, 19 May 2021 23:47:48 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 04e0867d-a7d3-40ae-ae32-ee08de62c650 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oIhFsW3yOUmKSioHfdtl49xT1nsW2ymAOSCthcMXiio=; b=lM9veaUv42y4nXibj1lGSdifgvjsNbUKUEol+uJziWw6kVRwnZkDD52tXqcK/vhasS PUDj92pN5vsIbUfabcqexhaZYlSojZJ1wq1mzK9ZTms/+1Va4jsCnNJ6mu4u4DoMsmtY 16/lsdYHKt3Z41zBC1z7c65B0IdsqOKp+QHbc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oIhFsW3yOUmKSioHfdtl49xT1nsW2ymAOSCthcMXiio=; b=K65/Ma0MtKtPthbBfRk7MNkZRqyuSv1a3RKOSHl6E6S5Fg3v+nRekqZqHNS4p2/UDX rt1h5tO/MdcQGZfWkd0lmUQn4JzuKJHZotNNBJmCh9NHBnj44DFWHKA9Z11jdXP1mLHE TCUz/bTzOmRDf+P5Ngh7x77a0fZFK5HOvyJ1Jp5vbNKLlfYarDTd4B7+ynnkiJR5D2gN c694LGiN+imZrbWSFDCvBdQtHl6Lfuat3iAQ7zms0Cs7OxQpAnUE4tsnUnn+kpXcgIq0 QsIYUczlrq+YxtqVX1TZIk7dDZ6oCWvhIuE/v0f1u+w9JdEvO43wwxzhYjXZ8DDuPNZb Dayw== X-Gm-Message-State: AOAM531K45sgJk6cp7LZgk3K/B2uzvdI20c1+7b6j6vEmTAVVeBX4AAt FJkcfhw++hlgKz3nJ+PDWh6T+lh8vBktYw== X-Google-Smtp-Source: ABdhPJyF/QJOp/NTDxAyajeaHl1mJOdn6Hq/NRyQj8aGcj4BdB1Fzd6TjCMWgsLaTLY+WYPxnPo7kA== X-Received: by 2002:a62:d108:0:b029:25d:497e:2dfd with SMTP id z8-20020a62d1080000b029025d497e2dfdmr3267362pfg.29.1621493268803; Wed, 19 May 2021 23:47:48 -0700 (PDT) X-Received: by 2002:a5d:8c82:: with SMTP id g2mr3632711ion.34.1621492834046; Wed, 19 May 2021 23:40:34 -0700 (PDT) MIME-Version: 1.0 References: <20210518064215.2856977-1-tientzu@chromium.org> <20210518064215.2856977-2-tientzu@chromium.org> <170a54f2-be20-ec29-1d7f-3388e5f928c6@gmail.com> In-Reply-To: <170a54f2-be20-ec29-1d7f-3388e5f928c6@gmail.com> From: Claire Chang Date: Thu, 20 May 2021 14:40:23 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7 01/15] swiotlb: Refactor swiotlb init functions To: Florian Fainelli Cc: Rob Herring , mpe@ellerman.id.au, Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski , benh@kernel.crashing.org, paulus@samba.org, "list@263.net:IOMMU DRIVERS" , sstabellini@kernel.org, Robin Murphy , grant.likely@arm.com, xypron.glpk@gmx.de, Thierry Reding , mingo@kernel.org, bauerman@linux.ibm.com, peterz@infradead.org, Greg KH , Saravana Kannan , "Rafael J . Wysocki" , heikki.krogerus@linux.intel.com, Andy Shevchenko , Randy Dunlap , Dan Williams , Bartosz Golaszewski , linux-devicetree , lkml , linuxppc-dev@lists.ozlabs.org, xen-devel@lists.xenproject.org, Nicolas Boichat , Jim Quinlan , Tomasz Figa , bskeggs@redhat.com, Bjorn Helgaas , chris@chris-wilson.co.uk, Daniel Vetter , airlied@linux.ie, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, jani.nikula@linux.intel.com, Jianxiong Gao , joonas.lahtinen@linux.intel.com, linux-pci@vger.kernel.org, maarten.lankhorst@linux.intel.com, matthew.auld@intel.com, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com Content-Type: text/plain; charset="UTF-8" On Thu, May 20, 2021 at 2:50 AM Florian Fainelli wrote: > > > > On 5/17/2021 11:42 PM, Claire Chang wrote: > > Add a new function, swiotlb_init_io_tlb_mem, for the io_tlb_mem struct > > initialization to make the code reusable. > > > > Note that we now also call set_memory_decrypted in swiotlb_init_with_tbl. > > > > Signed-off-by: Claire Chang > > --- > > kernel/dma/swiotlb.c | 51 ++++++++++++++++++++++---------------------- > > 1 file changed, 25 insertions(+), 26 deletions(-) > > > > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c > > index 8ca7d505d61c..d3232fc19385 100644 > > --- a/kernel/dma/swiotlb.c > > +++ b/kernel/dma/swiotlb.c > > @@ -168,9 +168,30 @@ void __init swiotlb_update_mem_attributes(void) > > memset(vaddr, 0, bytes); > > } > > > > -int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) > > +static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start, > > + unsigned long nslabs, bool late_alloc) > > { > > + void *vaddr = phys_to_virt(start); > > unsigned long bytes = nslabs << IO_TLB_SHIFT, i; > > + > > + mem->nslabs = nslabs; > > + mem->start = start; > > + mem->end = mem->start + bytes; > > + mem->index = 0; > > + mem->late_alloc = late_alloc; > > + spin_lock_init(&mem->lock); > > + for (i = 0; i < mem->nslabs; i++) { > > + mem->slots[i].list = IO_TLB_SEGSIZE - io_tlb_offset(i); > > + mem->slots[i].orig_addr = INVALID_PHYS_ADDR; > > + mem->slots[i].alloc_size = 0; > > + } > > + > > + set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); > > + memset(vaddr, 0, bytes); > > You are doing an unconditional set_memory_decrypted() followed by a > memset here, and then: > > > +} > > + > > +int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) > > +{ > > struct io_tlb_mem *mem; > > size_t alloc_size; > > > > @@ -186,16 +207,8 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) > > if (!mem) > > panic("%s: Failed to allocate %zu bytes align=0x%lx\n", > > __func__, alloc_size, PAGE_SIZE); > > - mem->nslabs = nslabs; > > - mem->start = __pa(tlb); > > - mem->end = mem->start + bytes; > > - mem->index = 0; > > - spin_lock_init(&mem->lock); > > - for (i = 0; i < mem->nslabs; i++) { > > - mem->slots[i].list = IO_TLB_SEGSIZE - io_tlb_offset(i); > > - mem->slots[i].orig_addr = INVALID_PHYS_ADDR; > > - mem->slots[i].alloc_size = 0; > > - } > > + > > + swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false); > > You convert this call site with swiotlb_init_io_tlb_mem() which did not > do the set_memory_decrypted()+memset(). Is this okay or should > swiotlb_init_io_tlb_mem() add an additional argument to do this > conditionally? I'm actually not sure if this it okay. If not, will add an additional argument for it. > -- > Florian