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 6D084C433DF for ; Thu, 16 Jul 2020 15:47:35 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 3B4732076D for ; Thu, 16 Jul 2020 15:47:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ArPd4X/h"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="aPfB56bi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B4732076D 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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject: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=CloYTeutbpWoEF+brUJXb1z/uWi0SFebs9FLrrlgDNI=; b=ArPd4X/hUA/mqo+gGhsTXC9SH SKThF/kTDkismcrcGmAK0flZRD3DCAAIbNWgkHnku8EHTkzN4CnYovKI4wFXEFGZ0GQlAgptP0XBh fJCHChTvIttXss07dc7buwBNM3YE37YBBQlQSP1u06tVAjetYRgS0zGE5NwpY/RPjVD9BqBzkvUk9 +z8zCxSovue4oqv3C97BBwewAnHpaNS8UZFkE6h+vc6C9I1L1AQIOFg+0Kl9wpJJW5DlF4mnZv/Yg L03fQLONBwWs9T/o2Uzl7VfHC616LO5Nk97RIGXOzy0Rr6w5IARHhwDUzz/kY7hpUhbsG1lonmD3l 0ZGr96keg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jw65R-0003FI-5z; Thu, 16 Jul 2020 15:46:17 +0000 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jw65N-0003Dp-PD for linux-arm-kernel@lists.infradead.org; Thu, 16 Jul 2020 15:46:14 +0000 Received: by mail-ed1-x542.google.com with SMTP id z17so5074694edr.9 for ; Thu, 16 Jul 2020 08:46:13 -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=6ljVtEAns8z/jn7DCignaoAnzmnNFDfpuHqi7UerqxU=; b=aPfB56bi8qbQ9Bnwzyzn1R7YAPhRGG2a7TuNSTdn1VG+EFU2a3GK0Os96HBqBxOA4Q crd5Uc/b5vofjrBBPsO1A1M1u9mJ8VlxCnRA3zghwvh+MzJO18eT+hOHd3EY1SY7BLTm yXhBPQr9E6IN6tHfotQyQ8cWkV+jODeykTCbVZVR6MfzIvqJy/PiX1x19JHDutuE9nan d//Grc923sXLl6RS3HS503/R80t9jP8jYvTth/s5OGZUNqw/HgDHl/08+hIEx5VKGemC wKzoutyUUbjWCgX8MnAhynaEkuG0UbKh7rrHT4Fo0p+uhXu48OFPLlynHiobSNh3EFZx rwQA== 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=6ljVtEAns8z/jn7DCignaoAnzmnNFDfpuHqi7UerqxU=; b=hFOWQSg+ijBSIg/ynUsFI3p0nH+QVgVXoJGadtENr+qgOabUvapPgF0w7NJrmMssJt czVPCDv8gRpqkMgW0HG/RF0K/i6NI2uUGf3OFqU8yMOvsTtOsH+wUXgNvE+Ztm6jg3KT usyam0ySdoOnaT1wv9I0O1GFQ0v49pArtaeeUOeU4KWDX9rNU61+ROAmQbzn9RRmtLjt EfO4mXdCN+IJSkgxguss5ZsqRFaq8s9MtU3SSCNlcF1RdTa6ojRuTwFTEBs2WYsYWJo2 Rp01gUy6OZIoBztuTLJ0nPNLQmPLzBM66VIFfkFOMfzIx++Lls79QaCxJl2g6iJsnjEp dihQ== X-Gm-Message-State: AOAM533jl4996wcVsZozMCMR4ttjI+pxIRPVGechmB7osHDpO6it1ay4 Q6ZlB4f6cD17olQ7QsenGKHYlg== X-Google-Smtp-Source: ABdhPJwbdkI3Q+F63rYDOBFMMWI1aDZf4JEWa5oyS7j5a2G8ovxWK10g6L0x8GCJgTIZg2aQM1EIpg== X-Received: by 2002:a05:6402:31ba:: with SMTP id dj26mr5026934edb.181.1594914372307; Thu, 16 Jul 2020 08:46:12 -0700 (PDT) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id f16sm5367024ejr.0.2020.07.16.08.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2020 08:46:11 -0700 (PDT) Date: Thu, 16 Jul 2020 17:45:58 +0200 From: Jean-Philippe Brucker To: Will Deacon Subject: Re: [PATCH v8 07/12] iommu/arm-smmu-v3: Share process page tables Message-ID: <20200716154558.GC447208@myrica> References: <20200618155125.1548969-1-jean-philippe@linaro.org> <20200618155125.1548969-8-jean-philippe@linaro.org> <20200713202236.GA3575@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200713202236.GA3575@willie-the-truck> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200716_114613_907707_56D0E492 X-CRM114-Status: GOOD ( 17.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fenghua.yu@intel.com, jacob.jun.pan@linux.intel.com, Suzuki K Poulose , catalin.marinas@arm.com, joro@8bytes.org, zhengxiang9@huawei.com, hch@infradead.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, Jonathan.Cameron@huawei.com, zhangfei.gao@linaro.org, robin.murphy@arm.com, xuzaibo@huawei.com, linux-arm-kernel@lists.infradead.org, baolu.lu@linux.intel.com 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 Mon, Jul 13, 2020 at 09:22:37PM +0100, Will Deacon wrote: > > +static struct arm_smmu_ctx_desc *arm_smmu_share_asid(u16 asid) > > +{ > > + struct arm_smmu_ctx_desc *cd; > > > > - xa_erase(&asid_xa, cd->asid); > > + cd = xa_load(&asid_xa, asid); > > + if (!cd) > > + return NULL; > > + > > + if (cd->mm) { > > + /* All devices bound to this mm use the same cd struct. */ > > + refcount_inc(&cd->refs); > > + return cd; > > + } > > How do you handle racing against a concurrent arm_smmu_free_asid() here? Patch 8 adds an asid_lock to deal with this, but it should be introduced in this patch. There is a potential use-after-free here, if arm_smmu_domain_free() runs concurrently. > > > +__maybe_unused > > +static struct arm_smmu_ctx_desc *arm_smmu_alloc_shared_cd(struct mm_struct *mm) > > +{ > > + u16 asid; > > + int ret = 0; > > + u64 tcr, par, reg; > > + struct arm_smmu_ctx_desc *cd; > > + struct arm_smmu_ctx_desc *old_cd = NULL; > > + > > + lockdep_assert_held(&sva_lock); > > Please don't bother with these for static functions (but I can see the > value in having them for functions with external callers). > > > + > > + asid = mm_context_get(mm); > > + if (!asid) > > + return ERR_PTR(-ESRCH); > > + > > + cd = kzalloc(sizeof(*cd), GFP_KERNEL); > > + if (!cd) { > > + ret = -ENOMEM; > > + goto err_put_context; > > + } > > + > > + arm_smmu_init_cd(cd); > > + > > + old_cd = arm_smmu_share_asid(asid); > > + if (IS_ERR(old_cd)) { > > + ret = PTR_ERR(old_cd); > > + goto err_free_cd; > > + } else if (old_cd) { > > Don't need the 'else' > > > + if (WARN_ON(old_cd->mm != mm)) { > > + ret = -EINVAL; > > + goto err_free_cd; > > + } > > + kfree(cd); > > + mm_context_put(mm); > > + return old_cd; > > This is a bit messy. Can you consolidate the return path so that ret is a > pointer and you have an 'int err', e.g.: > > return err < 0 ? ERR_PTR(err) : ret; Sure, I think it looks a little nicer this way Thanks, Jean _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel