Received: by 10.223.185.116 with SMTP id b49csp5908568wrg; Wed, 7 Mar 2018 21:34:12 -0800 (PST) X-Google-Smtp-Source: AG47ELtc0fV6KVynk3dLn3RGTeCFT9o0Hlqmid9KMXqGjh9/6QMvifxtGcb+/Hta0RVUXGDRbBel X-Received: by 2002:a17:902:529:: with SMTP id 38-v6mr22465019plf.327.1520487252217; Wed, 07 Mar 2018 21:34:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520487252; cv=none; d=google.com; s=arc-20160816; b=s6hbYuJh8A7YWou5p2CaRyv4E4j/le6OGQQCfOnqG1OreJ1igE7GPufghskH85KRJE Oy6rMZFODe716JaRmYhYrGi4YuQL33WY9ML/Hy3aQzNduMFMXXgn2ZnuX2BA9R0ADRmB zJwN5W8ng63ns3TAbDLhU+9HBLg7f7MYUYqVeOtkciuNsZ2HEoVGSQEvW5yHvulVqqy/ HhOAJZSTy6B84Fj0kuHsvqakW3F3CvGF3OUi47696UH9JICTR6vgenSP7+UV9USd65Bp bHDSSHV59jRaz7kmVJs6miMtIKxzpwOvBDOsTkzMrF7Nd+29Iv+V6k+RYzTx2HXFZJxe 8RZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dmarc-filter:dkim-signature :dkim-signature:arc-authentication-results; bh=yfAEU3Ja/nnP8qJQvFyqRNx8IXVHnBVKSmGtjyuKdo4=; b=a7/15fCNdTqkFjKaZolQw6D9RTXn+q+r8T19oy9qRKryWWT1W/570TajFwOgVO9x7k cQbUmJFKWRAD+e/JatMBrX9ikvc9/haH0JNt2EzrzgyJ9s65o4qYHSDyk9KafoL3M+ux QSfLWqJCkOfMLaYiDQSxiG873jxw/hNHhrxpY3WFdk/aS5pWNhYeC1NZ6Eg15Skkjh6n iuxK6zdMluLVoZ1WTxgIeLO3TwbpWVX4eZnSSI5Fq+IUC1GUj49KUnD6Kr7BuRCQCS+J WRrls0djuZb1skUMm9Mi5LPlv5hEUBSKUlTtntyNm8iv/nrubILTM62ByvVquMbDILMP q3kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=FZs9DrNU; dkim=pass header.i=@codeaurora.org header.s=default header.b=FZs9DrNU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t8-v6si1895443plz.495.2018.03.07.21.33.58; Wed, 07 Mar 2018 21:34:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=FZs9DrNU; dkim=pass header.i=@codeaurora.org header.s=default header.b=FZs9DrNU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966436AbeCHFdH (ORCPT + 99 others); Thu, 8 Mar 2018 00:33:07 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:58206 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751696AbeCHFcw (ORCPT ); Thu, 8 Mar 2018 00:32:52 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id D2D73607E5; Thu, 8 Mar 2018 05:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520487171; bh=P15Zna7qjbB2LlPBWKJA3PIIEQ50ynYGWOOIxWieFR8=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=FZs9DrNUGHctmFhA99fcxQfm3Q3tsveDwvjFPmsJ6NCqw/7p8u9i5BpB5Gvy++DRZ 8shulYWrMtEBEcf8vj9DrLkEB9oAs3Wm8tyKaLXz4j6Yi//Q9NFEx5k0ehPg4gk6OS TBIM6Ob+mArjfRWy7OYwm/FxMcbEPSu7U/tgNZm4= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek.gautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 1B66B6043F; Thu, 8 Mar 2018 05:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520487171; bh=P15Zna7qjbB2LlPBWKJA3PIIEQ50ynYGWOOIxWieFR8=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=FZs9DrNUGHctmFhA99fcxQfm3Q3tsveDwvjFPmsJ6NCqw/7p8u9i5BpB5Gvy++DRZ 8shulYWrMtEBEcf8vj9DrLkEB9oAs3Wm8tyKaLXz4j6Yi//Q9NFEx5k0ehPg4gk6OS TBIM6Ob+mArjfRWy7OYwm/FxMcbEPSu7U/tgNZm4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 1B66B6043F Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vivek.gautam@codeaurora.org Received: by mail-wm0-f47.google.com with SMTP id 139so8758365wmn.2; Wed, 07 Mar 2018 21:32:50 -0800 (PST) X-Gm-Message-State: APf1xPAxGHBtEhvoG3ZUFXnh+H0jGNbJbwkHJZkXh/8hMEgTZTKA80pr WCr6YhOSlyK80CE4yy1vEAX9O5rOiwxfQgtxccI= X-Received: by 10.80.149.236 with SMTP id x41mr30434368eda.64.1520487169729; Wed, 07 Mar 2018 21:32:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.232.133 with HTTP; Wed, 7 Mar 2018 21:32:49 -0800 (PST) In-Reply-To: References: <20180302101050.6191-1-vivek.gautam@codeaurora.org> <20180302101050.6191-2-vivek.gautam@codeaurora.org> From: Vivek Gautam Date: Thu, 8 Mar 2018 11:02:49 +0530 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v8 1/5] iommu/arm-smmu: Destroy domain context in failure path To: Robin Murphy Cc: "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , "robh+dt" , Mark Rutland , "Rafael J. Wysocki" , Will Deacon , Rob Clark , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , devicetree@vger.kernel.org, open list , Tomasz Figa , jcrouse@codeaurora.org, Stephen Boyd , Sricharan R , Marek Szyprowski , Archit Taneja , linux-arm-msm Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 7, 2018 at 5:50 PM, Robin Murphy wrote: > On 02/03/18 10:10, Vivek Gautam wrote: >> >> If we fail after initializing domain_context, we should destroy >> the context to free up resources. > > > Have another think about why the "problem" this patch caters for cannot ever > happen (hint: consider how domain->smmu is used in > arm_smmu_init_domain_context()). And then also about the really > catastrophically bad problem it actually introduces (hint: > "iommu_attach(domain, good_dev); iommu_attach(domain, bad_dev);") Got it, we would end up destroying good_dev's domain context with this. Thanks regards Vivek > > Robin. > > >> Signed-off-by: Vivek Gautam >> --- >> >> * New patch added in this series. >> >> drivers/iommu/arm-smmu.c | 7 ++++++- >> 1 file changed, 6 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c >> index 69e7c60792a8..ffc152c36002 100644 >> --- a/drivers/iommu/arm-smmu.c >> +++ b/drivers/iommu/arm-smmu.c >> @@ -1223,11 +1223,16 @@ static int arm_smmu_attach_dev(struct iommu_domain >> *domain, struct device *dev) >> dev_err(dev, >> "cannot attach to SMMU %s whilst already attached >> to domain on SMMU %s\n", >> dev_name(smmu_domain->smmu->dev), >> dev_name(smmu->dev)); >> - return -EINVAL; >> + ret = -EINVAL; >> + goto destroy_domain; >> } >> /* Looks ok, so add the device to the domain */ >> return arm_smmu_domain_add_master(smmu_domain, fwspec); >> + >> +destroy_domain: >> + arm_smmu_destroy_domain_context(domain); >> + return ret; >> } >> static int arm_smmu_map(struct iommu_domain *domain, unsigned long >> iova, >> > -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation