Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp382325pxj; Thu, 20 May 2021 11:30:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4ZciZnwA0J6THzLKLvlYkgWVmuRqFnMl/0LmFAOWnwoqljihktfl8wkzAHhmRrXSTUVr2 X-Received: by 2002:a05:6402:50b:: with SMTP id m11mr6632032edv.367.1621535415505; Thu, 20 May 2021 11:30:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621535415; cv=none; d=google.com; s=arc-20160816; b=W8CDLc3VMJDD2SV8Ce9ISZRS4OYXgBTextV6nok3CWAXX4nz00UIO0fHkDzv5/S6Jm 9krQHX99vJiVpbBC4HkOeqUQ5BZKTrgBSwli7WoagYBYsicjkeAG6CaPwLttFbmHJ7yr uyeKtwinC3w7LoV/bcWpNo6djGUUJijuxphgX7sHsfsoXIJQ99vxe7heSVxCj0jTXHyp DcqK5up66JdM/M8jZ+HbmJlPElAImP1ZZPyQxqIX4l4lWI4fsCJkDvTqG+Dzz4WVlPDm DTLyG/r5s21zQBHAstAVlkmsEcNLI3qdGZLc1eq3SYz4sY5Gwc/saQPi5YEmVh93iW+S PmKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=x7ZDGNAUDpVATTTZpPJphtqldCsZ8CkR6UY7NyakTnY=; b=kC19H5QalUe2e72MT7YCYVqsGAW4j1v+HhXc/rLWNODH5vyv7lKQBy0pKC81hMrc+G MB6f3YNiXzJj2Ux5D/e9HahqnICQgIsIPwP0VtHjN3iKFli56Wom4P4Gj8DvkGkNGa1q 9EasGGt4yHSyDLVfARhjMKPUTzhLNYpfw+UrMPjaOjZOCZuXe8eFxjoT/B8aVMoo6d13 T4mRMoL+ZUfpDhqPKJ4b5svPseeP2JuJXyWLYJr+FkXXma1k+DUfm2LPtMZG4yj2V5KE y0yzjTsK5vyEeWTGvZF7qtVHqad0JtnD0BZQk2GZl6IdvraxMUGLtI5eZ7Gqv1kdDfwz LLAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yQ4ODMKv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s25si3231419eju.101.2021.05.20.11.29.52; Thu, 20 May 2021 11:30:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yQ4ODMKv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236366AbhETKSX (ORCPT + 99 others); Thu, 20 May 2021 06:18:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:42284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235827AbhETKJ1 (ORCPT ); Thu, 20 May 2021 06:09:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5138261951; Thu, 20 May 2021 09:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503753; bh=KOxEcpLIYjCOySdv0hsp70Jj+86Vk7vNIPq0btkVDE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yQ4ODMKvw3cgpyPZlYOraRQzlvZ1a1T4cHMLFYCBl0jmH+81u4NzXk9NtVQ8LHAel 1lAFmCAAyf4GSIFRB45oFDoXEJIKC6nJJMThXeFBdXKvKdxJAZ763vJ4xZWsW8Bb4S Dbg3tRNy2++jDz9gXO1aqTN9Vec7Q76j8MELU6b4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Kardashevskiy , Michael Ellerman , Sasha Levin Subject: [PATCH 4.19 330/425] powerpc/iommu: Annotate nested lock for lockdep Date: Thu, 20 May 2021 11:21:39 +0200 Message-Id: <20210520092142.261815444@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexey Kardashevskiy [ Upstream commit cc7130bf119add37f36238343a593b71ef6ecc1e ] The IOMMU table is divided into pools for concurrent mappings and each pool has a separate spinlock. When taking the ownership of an IOMMU group to pass through a device to a VM, we lock these spinlocks which triggers a false negative warning in lockdep (below). This fixes it by annotating the large pool's spinlock as a nest lock which makes lockdep not complaining when locking nested locks if the nest lock is locked already. === WARNING: possible recursive locking detected 5.11.0-le_syzkaller_a+fstn1 #100 Not tainted -------------------------------------------- qemu-system-ppc/4129 is trying to acquire lock: c0000000119bddb0 (&(p->lock)/1){....}-{2:2}, at: iommu_take_ownership+0xac/0x1e0 but task is already holding lock: c0000000119bdd30 (&(p->lock)/1){....}-{2:2}, at: iommu_take_ownership+0xac/0x1e0 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&(p->lock)/1); lock(&(p->lock)/1); === Signed-off-by: Alexey Kardashevskiy Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210301063653.51003-1-aik@ozlabs.ru Signed-off-by: Sasha Levin --- arch/powerpc/kernel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index f0dc680e659a..c3d2d5cd7c10 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -1030,7 +1030,7 @@ int iommu_take_ownership(struct iommu_table *tbl) spin_lock_irqsave(&tbl->large_pool.lock, flags); for (i = 0; i < tbl->nr_pools; i++) - spin_lock(&tbl->pools[i].lock); + spin_lock_nest_lock(&tbl->pools[i].lock, &tbl->large_pool.lock); if (tbl->it_offset == 0) clear_bit(0, tbl->it_map); @@ -1059,7 +1059,7 @@ void iommu_release_ownership(struct iommu_table *tbl) spin_lock_irqsave(&tbl->large_pool.lock, flags); for (i = 0; i < tbl->nr_pools; i++) - spin_lock(&tbl->pools[i].lock); + spin_lock_nest_lock(&tbl->pools[i].lock, &tbl->large_pool.lock); memset(tbl->it_map, 0, sz); -- 2.30.2