Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4446774imw; Tue, 19 Jul 2022 06:49:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sF56X6sKRg8uJMuML28IESSwlF2G6yTBn+vwATgX032k2ffEr1dhOMvB2p5luveQlkH4c1 X-Received: by 2002:aa7:dc17:0:b0:43b:6c14:8bf with SMTP id b23-20020aa7dc17000000b0043b6c1408bfmr10701053edu.190.1658238569969; Tue, 19 Jul 2022 06:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238569; cv=none; d=google.com; s=arc-20160816; b=gw8G13ZScdjYhbFbYza9L9CZ4Be6sl9rGkYM2sAuwek156Cn1VA611lrB7Yr63FCBZ fsm4tzQpFFj0Q4bkfJIxM95zJP2K2oFxqdMDiozlGjIakB7TQvqJKWlsg6ADQqnC7SdW HJgu86sjGwvx6achanIt5tO425tz3WBeo9WeKNw3W1ab8Mvls/X1P0CyUcXAxAxz1mY5 dSMspdLkI+4b8i9srHY23v1VbzEhzZNwBHSjNK9PVd6lzHAJ1j7oub7tqMU0s7rF7PUW Cwiqf7R7c9IA3Q6GY5mKbQHF9dPsT0ZPJd1W0DSC+dOqzapfvfZ7tudxAUZBzqs5rQOy VaJw== 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=yNX03WdmHmOXEJ6LjepQojp1+GVB/pWVKaGHLfEbEOA=; b=aV1cVSaNpRtHzcGrB/lYVf5cP1Gtzi6tNNqC67bwqyQyGZC/iDOHiWDDojtBfCIr0u upXy9Z1BM6qamBml/NXdktfffKn6b53tsQcTwMb/V/W5dRkSsSjsKmjGHR3A0xJ9kULL Y9VfnQQX9qz7Ipke53nZtqZLoezKr2fac/IUumQxx0G2Iu+aL8tWycsUj8Vs/RWBR1vg L3z8/KUsOhceSixADhCHzGl4TYgu9JqE/FMtz1DmOC7yIDEKD0J7MRYDPYxwNzz7pAJ+ y9uF7xZJXrz0+lDgHHazDpBdfu9YkfjDJlmef4FfYWcnj5SkgiA7n9jbAEJiBw3fdWci 7P8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HXR04hHz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9-20020a1709063ec900b0072b16a6bc33si18022224ejj.352.2022.07.19.06.49.04; Tue, 19 Jul 2022 06:49:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HXR04hHz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240737AbiGSMgP (ORCPT + 99 others); Tue, 19 Jul 2022 08:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241273AbiGSMfC (ORCPT ); Tue, 19 Jul 2022 08:35:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE2F179EEF; Tue, 19 Jul 2022 05:13:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 46093617B2; Tue, 19 Jul 2022 12:13:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30D46C341C6; Tue, 19 Jul 2022 12:13:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232825; bh=AnosrUVgJ41RCxo39PFuWrg6vyGd0GPpnomtsIo9vic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HXR04hHzbswWJ/Pld4oVo6dfc64UksOdfvBn3Ufggo112BnmwXk2jx09awez5QfjM jHOPonr4adcoHyfOsY2QVlL4CnoPTK94JPRFPWplOJm2B9xUj37/saaMfi45WqjnxO qbeBg7rFbiH1wDDNvtLKZngqDU8mwEeCotFK9ywU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Matthew Auld , Sasha Levin Subject: [PATCH 5.15 079/167] drm/i915: Require the vm mutex for i915_vma_bind() Date: Tue, 19 Jul 2022 13:53:31 +0200 Message-Id: <20220719114704.209962814@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114656.750574879@linuxfoundation.org> References: <20220719114656.750574879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Hellström [ Upstream commit c2ea703dcafccf18d7d77d8b68fb08c2d9842b7a ] Protect updates of struct i915_vma flags and async binding / unbinding with the vm::mutex. This means that i915_vma_bind() needs to assert vm::mutex held. In order to make that possible drop the caching of kmap_atomic() maps around i915_vma_bind(). An alternative would be to use kmap_local() but since we block cpu unplugging during sleeps inside kmap_local() sections this may have unwanted side-effects. Particularly since we might wait for gpu while holding the vm mutex. This change may theoretically increase execbuf cpu-usage on snb, but at least on non-highmem systems that increase should be very small. Signed-off-by: Thomas Hellström Reviewed-by: Matthew Auld Link: https://patchwork.freedesktop.org/patch/msgid/20211221200050.436316-5-thomas.hellstrom@linux.intel.com Signed-off-by: Sasha Levin --- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 50 ++++++++++++++++++- drivers/gpu/drm/i915/i915_vma.c | 1 + 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index 1aa249908b64..0d480867fc0c 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -1060,6 +1060,47 @@ static inline struct i915_ggtt *cache_to_ggtt(struct reloc_cache *cache) return &i915->ggtt; } +static void reloc_cache_unmap(struct reloc_cache *cache) +{ + void *vaddr; + + if (!cache->vaddr) + return; + + vaddr = unmask_page(cache->vaddr); + if (cache->vaddr & KMAP) + kunmap_atomic(vaddr); + else + io_mapping_unmap_atomic((void __iomem *)vaddr); +} + +static void reloc_cache_remap(struct reloc_cache *cache, + struct drm_i915_gem_object *obj) +{ + void *vaddr; + + if (!cache->vaddr) + return; + + if (cache->vaddr & KMAP) { + struct page *page = i915_gem_object_get_page(obj, cache->page); + + vaddr = kmap_atomic(page); + cache->vaddr = unmask_flags(cache->vaddr) | + (unsigned long)vaddr; + } else { + struct i915_ggtt *ggtt = cache_to_ggtt(cache); + unsigned long offset; + + offset = cache->node.start; + if (!drm_mm_node_allocated(&cache->node)) + offset += cache->page << PAGE_SHIFT; + + cache->vaddr = (unsigned long) + io_mapping_map_atomic_wc(&ggtt->iomap, offset); + } +} + static void reloc_cache_reset(struct reloc_cache *cache, struct i915_execbuffer *eb) { void *vaddr; @@ -1324,10 +1365,17 @@ eb_relocate_entry(struct i915_execbuffer *eb, * batchbuffers. */ if (reloc->write_domain == I915_GEM_DOMAIN_INSTRUCTION && - GRAPHICS_VER(eb->i915) == 6) { + GRAPHICS_VER(eb->i915) == 6 && + !i915_vma_is_bound(target->vma, I915_VMA_GLOBAL_BIND)) { + struct i915_vma *vma = target->vma; + + reloc_cache_unmap(&eb->reloc_cache); + mutex_lock(&vma->vm->mutex); err = i915_vma_bind(target->vma, target->vma->obj->cache_level, PIN_GLOBAL, NULL); + mutex_unlock(&vma->vm->mutex); + reloc_cache_remap(&eb->reloc_cache, ev->vma->obj); if (err) return err; } diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c index dfd20060812b..3df304edabc7 100644 --- a/drivers/gpu/drm/i915/i915_vma.c +++ b/drivers/gpu/drm/i915/i915_vma.c @@ -376,6 +376,7 @@ int i915_vma_bind(struct i915_vma *vma, u32 bind_flags; u32 vma_flags; + lockdep_assert_held(&vma->vm->mutex); GEM_BUG_ON(!drm_mm_node_allocated(&vma->node)); GEM_BUG_ON(vma->size > vma->node.size); -- 2.35.1