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=-4.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 5C063C433E0 for ; Fri, 26 Mar 2021 09:52:28 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 A4E5A61935 for ; Fri, 26 Mar 2021 09:52:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4E5A61935 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=geQuNayrJM4QME1QxF8nR06Zf+W5MssHEjyjUmxf7XA=; b=XyoXxIc6QqvqiTzCutsHFd3bW H/4V4U3nQVu68mXHUqPvo2OGNJaYz/maw7k6u/4RlYClCrt4ar/DDgvyq6Td9VOjtMrFlgYBTE0GQ xwI8shIkT92obvAVnITwPMy1bg1UwzJ+TZFE7yOp3ICVDBpnd3wTbVYqbMIzhyIkveG1aig5AVMXL KvvP/pIrycWCrFlcScELKvZPC5mlB6/ED0bQU9k1EZBxVctVHTelXUqG2KBu3a6468cjH6XJugV5A o17T+9ocy9Y2aW5SkPz4pSMfG00Ev70BZLdbZQjmkuSjteJFK0QR2taVFtR9IKRy8Kye2oJkovcLF 5WQ95V3fA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lPj6m-003ENW-Oi; Fri, 26 Mar 2021 09:50:24 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lPj6f-003ELX-J5 for linux-arm-kernel@lists.infradead.org; Fri, 26 Mar 2021 09:50:21 +0000 Received: by mail-wr1-x42d.google.com with SMTP id x7so4978602wrw.10 for ; Fri, 26 Mar 2021 02:50:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=MnI8RxXoHJw/2x8+1FFQSE5mboYTNfWyq0YhdaWKJtM=; b=quboBXKApWPPi+Sz+/0FkCmAg6Kixg1YdFbqHA178/Imd3WpW8k4YpPnDU3AYAZE1U rC+Ro1J3QVilPT4PwBMfYdVDZH7wz57EBkcZblYlFx15hruu5y4qR2vlnNHHETe/WtcI uyVKWYqEj8LFhnEuLeyGExbTpH692wtLRoQSiSbr0LrzyVM6FVKsEYAEO7T2ZdmHFNQl idPnV8krrh1WKw9A4izsTq80vIBW+1zP2qxvWYDpkS9yx0yoJ81ydGOZsjDLkYKidqJo vFyHyh6IRCsxZzSHsfDvs+RCVME7Lv75nUZ/VVIkp5mJt28scLPXIztaS3sNbN/X3XdQ 3KFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=MnI8RxXoHJw/2x8+1FFQSE5mboYTNfWyq0YhdaWKJtM=; b=kM/TR4s9m9cTuDFruTpsLpaQDCbmLX1njYBHJ4mkNaUBVx4eJ6uGVsXiuQmREF0C7s mKEyGt/fMTYPHplN7YXxZpPN3Uov4LZ6/teCnPiw/bbI+3Gwg8kX/nGDRRQuaM+pszmN FgB9YOthjOdGc1uiD/hx+Xuxj+Dfk8UpTm41i8FzVQp3ofblXwdxZnz54g4En9/b+Ctw BoOoDZ7Ku89dNE4pAx4veym24iPPwzq7CK69rEM0Kc3o5Ma7nIWi6uD5WgXPl5eKB9Bv F0SCvDkmljcSyp9hlgev7hMyoNrZ+qsjCYum+TTlEwz/EmZWGJ0WFuRpzTdh0zJyz0ON qTng== X-Gm-Message-State: AOAM533c1TbjIk5X0nclOyrHDwooaIgstJxbwFY7vyBLmIQZDO5ob8GO i/eXRZKRIrKJMzO+DbWCOEBw/RXUtkAQfA== X-Google-Smtp-Source: ABdhPJy8IdrF20cvgAfp2ESQn+iJIkj1mkaWU5rGBnF/yaYKd5OSC6h+yUhCzFWqiLVTmxHEe4956A== X-Received: by 2002:a5d:6381:: with SMTP id p1mr13820517wru.266.1616752216009; Fri, 26 Mar 2021 02:50:16 -0700 (PDT) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id o7sm12079801wrs.16.2021.03.26.02.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:50:15 -0700 (PDT) Date: Fri, 26 Mar 2021 10:49:57 +0100 From: Jean-Philippe Brucker To: Will Deacon Cc: joro@8bytes.org, vivek.gautam@arm.com, guohanjun@huawei.com, linux-acpi@vger.kernel.org, zhangfei.gao@linaro.org, lenb@kernel.org, devicetree@vger.kernel.org, kevin.tian@intel.com, robh+dt@kernel.org, linux-arm-kernel@lists.infradead.org, rjw@rjwysocki.net, iommu@lists.linux-foundation.org, sudeep.holla@arm.com, robin.murphy@arm.com, linux-accelerators@lists.ozlabs.org Subject: Re: [PATCH v13 07/10] iommu/arm-smmu-v3: Maintain a SID->device structure Message-ID: References: <20210302092644.2553014-1-jean-philippe@linaro.org> <20210302092644.2553014-8-jean-philippe@linaro.org> <20210325174807.GD15504@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210325174807.GD15504@willie-the-truck> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210326_095018_239729_EA74527B X-CRM114-Status: GOOD ( 23.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Mar 25, 2021 at 05:48:07PM +0000, Will Deacon wrote: > > +/* smmu->streams_mutex must be held */ > > Can you add a lockdep assertion for that? Sure > > +__maybe_unused > > +static struct arm_smmu_master * > > +arm_smmu_find_master(struct arm_smmu_device *smmu, u32 sid) > > +{ > > + struct rb_node *node; > > + struct arm_smmu_stream *stream; > > + > > + node = smmu->streams.rb_node; > > + while (node) { > > + stream = rb_entry(node, struct arm_smmu_stream, node); > > + if (stream->id < sid) > > + node = node->rb_right; > > + else if (stream->id > sid) > > + node = node->rb_left; > > + else > > + return stream->master; > > + } > > + > > + return NULL; > > +} > > [...] > > > +static int arm_smmu_insert_master(struct arm_smmu_device *smmu, > > + struct arm_smmu_master *master) > > +{ > > + int i; > > + int ret = 0; > > + struct arm_smmu_stream *new_stream, *cur_stream; > > + struct rb_node **new_node, *parent_node = NULL; > > + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(master->dev); > > + > > + master->streams = kcalloc(fwspec->num_ids, sizeof(*master->streams), > > + GFP_KERNEL); > > + if (!master->streams) > > + return -ENOMEM; > > + master->num_streams = fwspec->num_ids; > > + > > + mutex_lock(&smmu->streams_mutex); > > + for (i = 0; i < fwspec->num_ids; i++) { > > + u32 sid = fwspec->ids[i]; > > + > > + new_stream = &master->streams[i]; > > + new_stream->id = sid; > > + new_stream->master = master; > > + > > + /* > > + * Check the SIDs are in range of the SMMU and our stream table > > + */ > > + if (!arm_smmu_sid_in_range(smmu, sid)) { > > + ret = -ERANGE; > > + break; > > + } > > + > > + /* Ensure l2 strtab is initialised */ > > + if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { > > + ret = arm_smmu_init_l2_strtab(smmu, sid); > > + if (ret) > > + break; > > + } > > + > > + /* Insert into SID tree */ > > + new_node = &(smmu->streams.rb_node); > > + while (*new_node) { > > + cur_stream = rb_entry(*new_node, struct arm_smmu_stream, > > + node); > > + parent_node = *new_node; > > + if (cur_stream->id > new_stream->id) { > > + new_node = &((*new_node)->rb_left); > > + } else if (cur_stream->id < new_stream->id) { > > + new_node = &((*new_node)->rb_right); > > + } else { > > + dev_warn(master->dev, > > + "stream %u already in tree\n", > > + cur_stream->id); > > + ret = -EINVAL; > > + break; > > + } > > + } > > + if (ret) > > + break; > > + > > + rb_link_node(&new_stream->node, parent_node, new_node); > > + rb_insert_color(&new_stream->node, &smmu->streams); > > + } > > + > > + if (ret) { > > + for (i--; i >= 0; i--) > > Is 'i--' really what you want for the initial value? Doesn't that correspond > to the ID you *didn't* add to the tree? In case of error we break out of the loop, with i corresponding to the stream that caused a fault but wasn't yet added to the tree. So i-- is the last stream that was successfully added, or -1 in which case we don't enter this for loop. > > + rb_erase(&master->streams[i].node, &smmu->streams); > > + kfree(master->streams); > > Do you need to NULLify master->streams and/or reset master->num_streams > after this? Seems like they're left dangling. master is freed by arm_smmu_probe_device() when we return an error. Since this function is unlikely to ever have another caller I didn't bother cleaning up here Thanks, Jean _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel