From patchwork Mon Oct 21 14:50:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11202447 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 9C1D413BD for ; Mon, 21 Oct 2019 14:50:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 843CD2053B for ; Mon, 21 Oct 2019 14:50:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 843CD2053B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EB40989805; Mon, 21 Oct 2019 14:50:28 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by gabe.freedesktop.org (Postfix) with ESMTPS id EE7006E141 for ; Mon, 21 Oct 2019 14:50:25 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id l10so13921857wrb.2 for ; Mon, 21 Oct 2019 07:50:25 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=EawF//2q4hjTxy/KIquWG4+ZSdR1PhfV7zZnLOG4Fg8=; b=ArPiG6kA3nSXZ/0ao7qS3Z56znyj/hQKL0aR5p6/7scjdJARWJXaNhXhU1jbxuOQmJ nqJM6AfxWg+l0k7zdEHnvQxR5u0uk3sr4igEK8igBE42uaIg0llLUfo+MDm/eoY8kFsF Nr0sgykf9yJedPcYICFYMh2vXPa4JebSYi+JoHUIOgQO6CQECZ4abEqjybX29h2fd5N8 dc15HBhARWC7v0ObAUy+xWaOOc1mFH8S5OgnfX7/48luzDI3ASqlCgoLhOxuG55px4pH iyVnvK7Rxk2VcOGd5eOUT/GW8D5BUGUuhB3S8Mh8r48yb3gHgf1QFOi0Utq2CUuBJ4/Y oSSA== X-Gm-Message-State: APjAAAWWywCFtDoBbT8U0cZNc1UCCJVGHUalKm0IiV0jDH1wMmTnSBTN W/sjxV+lKpwyoxNLDTYVIG2SeQ== X-Google-Smtp-Source: APXvYqzKbGcI4tpv8nTMcfB8S7QnDG5k8a0AxNXLRb5p1mbL/ucWPkg0rA0amrkizVhmj4xuNJurWw== X-Received: by 2002:adf:a141:: with SMTP id r1mr20376458wrr.122.1571669424523; Mon, 21 Oct 2019 07:50:24 -0700 (PDT) Received: from phenom.ffwll.local (212-51-149-96.fiber7.init7.net. [212.51.149.96]) by smtp.gmail.com with ESMTPSA id u7sm7712053wre.59.2019.10.21.07.50.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 07:50:23 -0700 (PDT) From: Daniel Vetter To: DRI Development Date: Mon, 21 Oct 2019 16:50:15 +0200 Message-Id: <20191021145017.17384-2-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191021145017.17384-1-daniel.vetter@ffwll.ch> References: <20191021145017.17384-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EawF//2q4hjTxy/KIquWG4+ZSdR1PhfV7zZnLOG4Fg8=; b=XiZzYKqtkGdDZtrXKTySlvj5UoebVQJ1fPM04KojwP2UGtipoZMFW/trG9Al803qHi Pg2C74LFZq2eJJSg49Ma3ViTbDuSnrnHoCKirBOAN4pew1JEDqRfU8hsRteEuUK430E4 NAz9ANeiM45g5vNcWCbjtrvVouHobzR/l4PrY= Subject: [Intel-gfx] [PATCH 1/3] dma_resv: prime lockdep annotations X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , Thomas Hellstrom , Tomeu Vizoso , Daniel Vetter , Intel Graphics Development , VMware Graphics , Gerd Hoffmann , Thomas Zimmermann , Daniel Vetter , Alex Deucher , Dave Airlie , =?utf-8?q?Christian_K=C3=B6nig?= , Ben Skeggs Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Full audit of everyone: - i915, radeon, amdgpu should be clean per their maintainers. - vram helpers should be fine, they don't do command submission, so really no business holding struct_mutex while doing copy_*_user. But I haven't checked them all. - panfrost seems to dma_resv_lock only in panfrost_job_push, which looks clean. - v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(), copying from/to userspace happens all in v3d_lookup_bos which is outside of the critical section. - vmwgfx has a bunch of ioctls that do their own copy_*_user: - vmw_execbuf_process: First this does some copies in vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself. Then comes the usual ttm reserve/validate sequence, then actual submission/fencing, then unreserving, and finally some more copy_to_user in vmw_execbuf_copy_fence_user. Glossing over tons of details, but looks all safe. - vmw_fence_event_ioctl: No ttm_reserve/dma_resv_lock anywhere to be seen, seems to only create a fence and copy it out. - a pile of smaller ioctl in vmwgfx_ioctl.c, no reservations to be found there. Summary: vmwgfx seems to be fine too. - virtio: There's virtio_gpu_execbuffer_ioctl, which does all the copying from userspace before even looking up objects through their handles, so safe. Plus the getparam/getcaps ioctl, also both safe. - qxl only has qxl_execbuffer_ioctl, which calls into qxl_process_single_command. There's a lovely comment before the __copy_from_user_inatomic that the slowpath should be copied from i915, but I guess that never happened. Try not to be unlucky and get your CS data evicted between when it's written and the kernel tries to read it. The only other copy_from_user is for relocs, but those are done before qxl_release_reserve_list(), which seems to be the only thing reserving buffers (in the ttm/dma_resv sense) in that code. So looks safe. - A debugfs file in nouveau_debugfs_pstate_set() and the usif ioctl in usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this everywhere and needs to be fixed up. v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a dma_resv lock of a different object already. Christian mentioned that ttm core does this too for ghost objects. intel-gfx-ci highlighted that i915 has similar issues. Unfortunately we can't do this in the usual module init functions, because kernel threads don't have an ->mm - we have to wait around for some user thread to do this. Solution is to spawn a worker (but only once). It's horrible, but it works. v3: We can allocate mm! (Chris). Horrible worker hack out, clean initcall solution in. v4: Annotate with __init (Rob Herring) Cc: Rob Herring Cc: Alex Deucher Cc: Christian König Cc: Chris Wilson Cc: Thomas Zimmermann Cc: Rob Herring Cc: Tomeu Vizoso Cc: Eric Anholt Cc: Dave Airlie Cc: Gerd Hoffmann Cc: Ben Skeggs Cc: "VMware Graphics" Cc: Thomas Hellstrom Reviewed-by: Christian König Reviewed-by: Chris Wilson Tested-by: Chris Wilson Signed-off-by: Daniel Vetter Reviewed-by: Thomas Hellstrom --- drivers/dma-buf/dma-resv.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index 709002515550..a05ff542be22 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -34,6 +34,7 @@ #include #include +#include /** * DOC: Reservation Object Overview @@ -95,6 +96,29 @@ static void dma_resv_list_free(struct dma_resv_list *list) kfree_rcu(list, rcu); } +#if IS_ENABLED(CONFIG_LOCKDEP) +static void __init dma_resv_lockdep(void) +{ + struct mm_struct *mm = mm_alloc(); + struct dma_resv obj; + + if (!mm) + return; + + dma_resv_init(&obj); + + down_read(&mm->mmap_sem); + ww_mutex_lock(&obj.lock, NULL); + fs_reclaim_acquire(GFP_KERNEL); + fs_reclaim_release(GFP_KERNEL); + ww_mutex_unlock(&obj.lock); + up_read(&mm->mmap_sem); + + mmput(mm); +} +subsys_initcall(dma_resv_lockdep); +#endif + /** * dma_resv_init - initialize a reservation object * @obj: the reservation object