Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp638560pxj; Thu, 20 May 2021 18:39:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRusUD+9eHZnUGrqp4S49pP98p3QUSJq635hagaFq5+0DUAQ0G00AKo/rQmGdM/Y3tl5xv X-Received: by 2002:a02:354c:: with SMTP id y12mr583640jae.144.1621561151468; Thu, 20 May 2021 18:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621561151; cv=none; d=google.com; s=arc-20160816; b=Sv/nsQAZQXZ8ki8CFjprz4VFdHQKJY7a36aUdhNUSI+4f1/deoxdyKRXSf+Vm67x0h vRx+opU5umTPPJcNnvPJFmuJy+7pgep/wFTzkxnFDuc9Fss2BmATmADlTTlV0fswKyzo r13ARDeQlaufSqm7ofA4KLJCWB0aN/TC4Z2g4X30E7F5sdbTy+d0T8qyhub8sXeNDaGn sBAMu1r4asB2paaQp9WyEYDv3obe/zppOKKKoj+6AvkZswG7TTKBpUPMM+yfv3NJ3CXP K4uCag81zrkri8pewhavK2IMfqlMXUJVV44GeebzjIdD/yQTeB1q7vkGLnMmI9oWoRFe AadQ== 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=lObozqAZWi4lJO+SwpgqqPmFKmRqGq6j3mGswKFoXyc=; b=cpjaQK8BJymUYzrVVsDB8b2BWjDX2mwqHtl0l8+mhW0gGCccR7Q8iL4ka1rzuB1u8+ Xu9aJkZlRZWWSCUujyeY6+DdYRScPruI//w5reItwSvFM6qC8ioWZmlk0hfRQp1245vX NLqr5Kv6QRLmfRonycL/2i/YEOlaedBKWcvWCvzS3YzdqXTHH4WbVBsqVSsDdaT5SlKd FMY/fOgmntQKb5KWnyiwX80N88jFVR/T431y7h61orIm3BgG2igUXAoyTLvT2jg8LOWB nBZf7M1ofdr0WhTRsxPoEHRR1/e4JVIXzqriHH5tDfil1IqgG02tfttKcYyT7+Px1anF uccg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1QgEIH0T; 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 d6si5115712ilv.73.2021.05.20.18.38.58; Thu, 20 May 2021 18:39:11 -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=1QgEIH0T; 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 S241898AbhETLpp (ORCPT + 99 others); Thu, 20 May 2021 07:45:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:43468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241380AbhETLYZ (ORCPT ); Thu, 20 May 2021 07:24:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DD6A861970; Thu, 20 May 2021 10:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505551; bh=xjvGfYWMOWJ3i3GSrinS+hz0zbRt1YtHImF2AmIsz9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1QgEIH0TiPpBn2uSQkFHjF+kL52aWL75d3cOqACU/eDlRuDqGr0MmVflWlry4kMEd ZsIPBxfat8MVTUvnpCRBzQ62AqNCQSYi6hELN5kwCdfGvMYmB4ak2eOSs4vt42t/gR LE01jblXAWsvyD7Q7ukNtlM9Ng6kbXD4QqR+97Fk= 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.4 152/190] powerpc/iommu: Annotate nested lock for lockdep Date: Thu, 20 May 2021 11:23:36 +0200 Message-Id: <20210520092107.201761373@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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 4c9b5970af37..282ad1930593 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -1019,7 +1019,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); @@ -1048,7 +1048,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