From patchwork Tue Jul 28 13:58:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11689225 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E9CE1392 for ; Tue, 28 Jul 2020 13:58:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 47386207E8 for ; Tue, 28 Jul 2020 13:58:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="KqeArdqy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730283AbgG1N6s (ORCPT ); Tue, 28 Jul 2020 09:58:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730279AbgG1N6r (ORCPT ); Tue, 28 Jul 2020 09:58:47 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F169CC0619D5 for ; Tue, 28 Jul 2020 06:58:46 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id d190so778798wmd.4 for ; Tue, 28 Jul 2020 06:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LTjUuKu28q4AP2apkOdAzx1cK7jJDnTHDeP/9uZly44=; b=KqeArdqygfldyaA4gJRiGfTgCwK4wgPCAMC7uombuUYQ1buL6zCp8yoRWk5H+Vp2qt M36J4wt9gCrJShAOCDVpPvxoVn5Osk7fRw15JUm/WE0gwcmaIwLFFiYS3d0f5MnFSxq/ iQOkoFGM5zyBIuGT0vXj0lazqprYYPD+oNhM0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LTjUuKu28q4AP2apkOdAzx1cK7jJDnTHDeP/9uZly44=; b=R1TenyPxdXOYr/U02quYWUn32u/CtK88F8CaDy2UvrzAxgzTmxH3a7uH30WmfkQxc1 rT2hI9gw810X5s4p60jtvPYSIwXFDW6ixDEUVy2WCvohXoVWAJUK2tLFypfmBdYcTpJz a/YgktKBdRELP7naBwK0o2U1eHghGaSe11PYDYQnO2wehaO4foC8VUB8O7bVfusYEG44 uFQLw+jjGU/yTpSWYa+S1HnaYjVF9HgVjfOarQ22Vd8WcDthIC6kgU4nESMPC1dFaxuU m+n72ko2vsfneaJFnyvYx+ObiPbJTP23oEsM5w1b5gqxOQSY0LGcKkSaLhFtd0kfi81Q v+Ig== X-Gm-Message-State: AOAM5317WHn5N2xZf9XQC9ftPS8mDxl3ZHdDDGcyR/1YMQkV5oYWNWn8 B5zWOUVGEHKqcEBAvj7SZs+81Q== X-Google-Smtp-Source: ABdhPJzN7u/m6RCqY38cX52hSfOrqIs4C8PfjuXHcoP5UoM1XsD3zH2RZL3E9SBC/M2256p1vsiwQw== X-Received: by 2002:a7b:c403:: with SMTP id k3mr4097843wmi.35.1595944725621; Tue, 28 Jul 2020 06:58:45 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id q6sm4505414wma.22.2020.07.28.06.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2020 06:58:44 -0700 (PDT) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , Daniel Vetter , Daniel Vetter , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, Dave Chinner , Qian Cai , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_?= =?utf-8?q?Hellstr=C3=B6m?= , Andrew Morton , Jason Gunthorpe , linux-mm@kvack.org, linux-rdma@vger.kernel.org, Maarten Lankhorst Subject: [PATCH] dma-resv: lockdep-prime address_space->i_mmap_rwsem for dma-resv Date: Tue, 28 Jul 2020 15:58:39 +0200 Message-Id: <20200728135839.1035515-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org GPU drivers need this in their shrinkers, to be able to throw out mmap'ed buffers. Note that we also need dma_resv_lock in shrinkers, but that loop is resolved by trylocking in shrinkers. So full hierarchy is now (ignore some of the other branches we already have primed): mmap_read_lock -> dma_resv -> shrinkers -> i_mmap_lock_write I hope that's not inconsistent with anything mm or fs does, adding relevant people. Signed-off-by: Daniel Vetter Cc: Sumit Semwal Cc: "Christian König" Cc: linux-media@vger.kernel.org Cc: linaro-mm-sig@lists.linaro.org Cc: Dave Chinner Cc: Qian Cai Cc: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: Thomas Hellström (Intel) Cc: Andrew Morton Cc: Jason Gunthorpe Cc: linux-mm@kvack.org Cc: linux-rdma@vger.kernel.org Cc: Maarten Lankhorst Reviewed-by: Christian König Reviewed-by: Thomas Hellström --- drivers/dma-buf/dma-resv.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index 0e6675ec1d11..9678162a4ac5 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -104,12 +104,14 @@ static int __init dma_resv_lockdep(void) struct mm_struct *mm = mm_alloc(); struct ww_acquire_ctx ctx; struct dma_resv obj; + struct address_space mapping; int ret; if (!mm) return -ENOMEM; dma_resv_init(&obj); + address_space_init_once(&mapping); mmap_read_lock(mm); ww_acquire_init(&ctx, &reservation_ww_class); @@ -117,6 +119,9 @@ static int __init dma_resv_lockdep(void) if (ret == -EDEADLK) dma_resv_lock_slow(&obj, &ctx); fs_reclaim_acquire(GFP_KERNEL); + /* for unmap_mapping_range on trylocked buffer objects in shrinkers */ + i_mmap_lock_write(&mapping); + i_mmap_unlock_write(&mapping); #ifdef CONFIG_MMU_NOTIFIER lock_map_acquire(&__mmu_notifier_invalidate_range_start_map); __dma_fence_might_wait();