From patchwork Sun Sep 21 17:58:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salter X-Patchwork-Id: 37667 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B374320970 for ; Sun, 21 Sep 2014 17:58:46 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id l4sf2706695lbv.4 for ; Sun, 21 Sep 2014 10:58:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=jYGfW0URqKuX6wQ84pcPd8GRHCN1Pi8110jS1B8sl84=; b=aIcXKM/RUQznTuJyv2AsjmAVFoJF83krp3NinCUlmf1zWMTGnAVOyUI+FUfzwwqYYs aI49byTK1gTFw9AdMIvdosxSpRYPZUhQ9zu/2Ehxnpt0KmhtCi9dJZG3VPFRFjOkjm6S Egw9IKMTrQvw8VagRC7OcbPX592oJhAiPVfPbx66EY2HEoW03VUuqWsbqp/fGdcensJU tjlPRMQ7ff73FSz1wtOTeUep7gB2Bh6W6cQxvMEkdK97bH1GAKOepJkm6aldSkyT0uj+ nV2iPM3fjRlxN4lvIu5lmgldsimBHMs3ZNPj9e+UUh2XU9KrFBgnIS3Vae+OfwHI4PcU WQwA== X-Gm-Message-State: ALoCoQmii54ULgYb2lkNWL1VXuJcdNbiLZMRlgq0qcXrTUEDxaqI7TqY67XKK7rjxm3sErnD+2+l X-Received: by 10.112.144.102 with SMTP id sl6mr3756795lbb.3.1411322325538; Sun, 21 Sep 2014 10:58:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.30.3 with SMTP id o3ls433632lah.14.gmail; Sun, 21 Sep 2014 10:58:44 -0700 (PDT) X-Received: by 10.152.204.231 with SMTP id lb7mr20601368lac.44.1411322324744; Sun, 21 Sep 2014 10:58:44 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com [209.85.217.175]) by mx.google.com with ESMTPS id o5si11564077lao.127.2014.09.21.10.58.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 21 Sep 2014 10:58:44 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by mail-lb0-f175.google.com with SMTP id n15so5625244lbi.34 for ; Sun, 21 Sep 2014 10:58:44 -0700 (PDT) X-Received: by 10.152.22.137 with SMTP id d9mr20675626laf.29.1411322324631; Sun, 21 Sep 2014 10:58:44 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.130.169 with SMTP id of9csp133655lbb; Sun, 21 Sep 2014 10:58:43 -0700 (PDT) X-Received: by 10.66.221.163 with SMTP id qf3mr19402429pac.37.1411322323230; Sun, 21 Sep 2014 10:58:43 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u3si12606624pdb.63.2014.09.21.10.58.42 for ; Sun, 21 Sep 2014 10:58:43 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752483AbaIUR6k (ORCPT + 27 others); Sun, 21 Sep 2014 13:58:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53587 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751463AbaIUR6j (ORCPT ); Sun, 21 Sep 2014 13:58:39 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8LHwUf3004378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 21 Sep 2014 13:58:31 -0400 Received: from deneb.redhat.com (ovpn-113-98.phx2.redhat.com [10.3.113.98]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8LHwTT4022012; Sun, 21 Sep 2014 13:58:29 -0400 From: Mark Salter To: Joerg Roedel Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Suravee Suthikulpanit , Mark Salter Subject: [PATCH] iommu/core: fix bus notifier breakage Date: Sun, 21 Sep 2014 13:58:24 -0400 Message-Id: <1411322304-3925-1-git-send-email-msalter@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: msalter@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , iommu_bus_init() registers a bus notifier on the given bus by using a statically defined notifier block: static struct notifier_block iommu_bus_nb = { .notifier_call = iommu_bus_notifier, }; This same notifier block is used for all busses. This causes a problem for notifiers registered after iommu has registered this callback on multiple busses. The problem is that a subsequent notifier being registered on a bus which has this iommu notifier will also get linked in to the notifier list of all other busses which have this iommu notifier. This patch fixes this by allocating the notifier_block at runtime. Some error checking is also added to catch any allocation failure or notifier registration error. Signed-off-by: Mark Salter --- drivers/iommu/iommu.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 0639b92..f00697a 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -770,18 +770,26 @@ static int iommu_bus_notifier(struct notifier_block *nb, return 0; } -static struct notifier_block iommu_bus_nb = { - .notifier_call = iommu_bus_notifier, -}; - -static void iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops) +static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops) { + int err; + struct notifier_block *nb; struct iommu_callback_data cb = { .ops = ops, }; - bus_register_notifier(bus, &iommu_bus_nb); - bus_for_each_dev(bus, NULL, &cb, add_iommu_group); + nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL); + if (!nb) + return -ENOMEM; + + nb->notifier_call = iommu_bus_notifier; + + err = bus_register_notifier(bus, nb); + if (err) { + kfree(nb); + return err; + } + return bus_for_each_dev(bus, NULL, &cb, add_iommu_group); } /** @@ -805,9 +813,7 @@ int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops) bus->iommu_ops = ops; /* Do IOMMU specific setup for this bus-type */ - iommu_bus_init(bus, ops); - - return 0; + return iommu_bus_init(bus, ops); } EXPORT_SYMBOL_GPL(bus_set_iommu);