From patchwork Fri Aug 21 08:50:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 11728647 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 E960C722 for ; Fri, 21 Aug 2020 08:50:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C0D4D208DB for ; Fri, 21 Aug 2020 08:50:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0D4D208DB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 908C68D0030; Fri, 21 Aug 2020 04:50:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 780678D0005; Fri, 21 Aug 2020 04:50:43 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F7508D0030; Fri, 21 Aug 2020 04:50:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0060.hostedemail.com [216.40.44.60]) by kanga.kvack.org (Postfix) with ESMTP id 3EF588D0005 for ; Fri, 21 Aug 2020 04:50:43 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 06E4D181AEF10 for ; Fri, 21 Aug 2020 08:50:43 +0000 (UTC) X-FDA: 77173955166.24.chin00_5307d1b27037 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id CDB621A4A7 for ; Fri, 21 Aug 2020 08:50:42 +0000 (UTC) X-Spam-Summary: 1,0,0,09a66b3b1e8616c1,d41d8cd98f00b204,chris@chris-wilson.co.uk,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1431:1437:1515:1534:1542:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3871:3874:4250:4321:4385:4605:5007:6261:6742:7901:8603:10004:11026:11473:11658:11914:12043:12296:12297:12438:12555:12679:12895:12986:13161:13221:13229:13894:14096:14181:14394:14571:14721:21080:21451:21627:30054:30064:30070,0,RBL:77.68.26.236:@chris-wilson.co.uk:.lbl8.mailshell.net-64.201.201.201 62.8.15.100;04yg738ch6sbhwxochui5u7g8d86dope864fn3hg5duj54eo88gmoi31czkyxid.xuooom6j8zje98e3fq4hjqbhosiim3p4tgyj19dmq11eg631ytpdywcq9g9ipoz.r-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: chin00_5307d1b27037 X-Filterd-Recvd-Size: 3905 Received: from fireflyinternet.com (unknown [77.68.26.236]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Aug 2020 08:50:42 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from build.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 22195097-1500050 for multiple; Fri, 21 Aug 2020 09:50:14 +0100 From: Chris Wilson To: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org Cc: linux-mm@kvack.org, Chris Wilson , Pavel Machek , Andrew Morton , Joerg Roedel , Linus Torvalds , Dave Airlie , Joonas Lahtinen , Rodrigo Vivi , David Vrabel , stable@vger.kernel.org Subject: [PATCH 1/4] mm: Export flush_vm_area() to sync the PTEs upon construction Date: Fri, 21 Aug 2020 09:50:08 +0100 Message-Id: <20200821085011.28878-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: CDB621A4A7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The alloc_vm_area() is another method for drivers to vmap/map_kernel_range that uses apply_to_page_range() rather than the direct vmalloc walkers. This is missing the page table modification tracking, and the ability to synchronize the PTE updates afterwards. Provide flush_vm_area() for the users of alloc_vm_area() that assumes the worst and ensures that the page directories are correctly flushed upon construction. The impact is most pronounced on x86_32 due to the delayed set_pmd(). Reported-by: Pavel Machek References: 2ba3e6947aed ("mm/vmalloc: track which page-table levels were modified") References: 86cf69f1d893 ("x86/mm/32: implement arch_sync_kernel_mappings()") Signed-off-by: Chris Wilson Cc: Andrew Morton Cc: Joerg Roedel Cc: Linus Torvalds Cc: Dave Airlie Cc: Joonas Lahtinen Cc: Rodrigo Vivi Cc: Pavel Machek Cc: David Vrabel Cc: # v5.8+ --- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 0221f852a7e1..a253b27df0ac 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -204,6 +204,7 @@ static inline void set_vm_flush_reset_perms(void *addr) /* Allocate/destroy a 'vmalloc' VM area. */ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes); +extern void flush_vm_area(struct vm_struct *area); extern void free_vm_area(struct vm_struct *area); /* for /dev/kmem */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index b482d240f9a2..c41934486031 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3078,6 +3078,22 @@ struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes) } EXPORT_SYMBOL_GPL(alloc_vm_area); +void flush_vm_area(struct vm_struct *area) +{ + unsigned long addr = (unsigned long)area->addr; + + /* apply_to_page_range() doesn't track the damage, assume the worst */ + if (ARCH_PAGE_TABLE_SYNC_MASK & (PGTBL_PTE_MODIFIED | + PGTBL_PMD_MODIFIED | + PGTBL_PUD_MODIFIED | + PGTBL_P4D_MODIFIED | + PGTBL_PGD_MODIFIED)) + arch_sync_kernel_mappings(addr, addr + area->size); + + flush_cache_vmap(addr, area->size); +} +EXPORT_SYMBOL_GPL(flush_vm_area); + void free_vm_area(struct vm_struct *area) { struct vm_struct *ret; From patchwork Fri Aug 21 08:50:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 11728641 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 E4A9C722 for ; Fri, 21 Aug 2020 08:50:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BC1CE208DB for ; Fri, 21 Aug 2020 08:50:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC1CE208DB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0EC3D8D000D; Fri, 21 Aug 2020 04:50:41 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 09D7D8D0005; Fri, 21 Aug 2020 04:50:41 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EAB7A8D000D; Fri, 21 Aug 2020 04:50:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id CFA708D0005 for ; Fri, 21 Aug 2020 04:50:40 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9C1F0181AEF10 for ; Fri, 21 Aug 2020 08:50:40 +0000 (UTC) X-FDA: 77173955040.24.lamp24_500e25d27037 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 747671A4A5 for ; Fri, 21 Aug 2020 08:50:40 +0000 (UTC) X-Spam-Summary: 1,0,0,201340800c9eeddd,d41d8cd98f00b204,chris@chris-wilson.co.uk,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1534:1541:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3867:3871:4250:4321:4385:5007:6261:7901:10004:11026:11657:11658:11914:12043:12297:12555:12679:12895:13069:13221:13229:13311:13357:13894:14096:14181:14384:14394:14571:14721:21080:21451:21627:30054:30064:30070,0,RBL:77.68.26.236:@chris-wilson.co.uk:.lbl8.mailshell.net-62.8.15.100 64.201.201.201;04ygc64xpf6atx5hq8jhozij3t4odypbx4jp7hubrddguy6igc1fbmkeafq6myr.8p4ff6zwti5j3fayhkk6htytuskw8wgdjdssobq8co7yithh3ghehngk5b4tr1i.q-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: lamp24_500e25d27037 X-Filterd-Recvd-Size: 2654 Received: from fireflyinternet.com (unknown [77.68.26.236]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Aug 2020 08:50:39 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from build.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 22195098-1500050 for multiple; Fri, 21 Aug 2020 09:50:15 +0100 From: Chris Wilson To: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org Cc: linux-mm@kvack.org, Chris Wilson , Pavel Machek , Andrew Morton , Joerg Roedel , Linus Torvalds , Dave Airlie , Joonas Lahtinen , Rodrigo Vivi , stable@vger.kernel.org Subject: [PATCH 2/4] drm/i915/gem: Sync the vmap PTEs upon construction Date: Fri, 21 Aug 2020 09:50:09 +0100 Message-Id: <20200821085011.28878-2-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200821085011.28878-1-chris@chris-wilson.co.uk> References: <20200821085011.28878-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 X-Rspamd-Queue-Id: 747671A4A5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Since synchronising the PTE after assignment is a manual step, use the newly exported interface to flush the PTE after assigning via alloc_vm_area(). Reported-by: Pavel Machek References: 2ba3e6947aed ("mm/vmalloc: track which page-table levels were modified") Signed-off-by: Chris Wilson Cc: Andrew Morton Cc: Joerg Roedel Cc: Linus Torvalds Cc: Dave Airlie Cc: Joonas Lahtinen Cc: Rodrigo Vivi Cc: Pavel Machek Cc: # v5.8+ --- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_pages.c b/drivers/gpu/drm/i915/gem/i915_gem_pages.c index 7050519c87a4..0fee67f34d74 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_pages.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_pages.c @@ -304,6 +304,7 @@ static void *i915_gem_object_map(struct drm_i915_gem_object *obj, for_each_sgt_daddr(addr, iter, sgt) **ptes++ = iomap_pte(iomap, addr, pgprot); } + flush_vm_area(area); if (mem != stack) kvfree(mem); From patchwork Fri Aug 21 08:50:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 11728635 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 435EA722 for ; Fri, 21 Aug 2020 08:50:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1A225214F1 for ; Fri, 21 Aug 2020 08:50:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A225214F1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 532046B00A3; Fri, 21 Aug 2020 04:50:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4BB2F8D0005; Fri, 21 Aug 2020 04:50:31 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D2126B00A5; Fri, 21 Aug 2020 04:50:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id 23CB86B00A3 for ; Fri, 21 Aug 2020 04:50:31 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D9544824556B for ; Fri, 21 Aug 2020 08:50:30 +0000 (UTC) X-FDA: 77173954620.15.frog39_3417dbc27037 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 890CA1814B0C8 for ; Fri, 21 Aug 2020 08:50:30 +0000 (UTC) X-Spam-Summary: 1,0,0,e05c86bbfd4a8453,d41d8cd98f00b204,chris@chris-wilson.co.uk,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3867:4250:4321:5007:6261:7903:8603:10004:11026:11473:11657:11658:11914:12043:12296:12297:12438:12555:12679:12895:13069:13311:13357:13894:14096:14181:14384:14394:14571:14721:21080:21451:21627:30054:30064,0,RBL:77.68.26.236:@chris-wilson.co.uk:.lbl8.mailshell.net-62.14.15.100 64.201.201.201;04y8krwnpawotif5axtnxp4dwtpm8ocjtxxda7sdnnjehfu6ysdwo1hw73joe8u.c9xr8pwe3b966bi69361fr4qc5f8uw5amnasp34uqwq5d6bcj387po6xu6p6mfa.h-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: frog39_3417dbc27037 X-Filterd-Recvd-Size: 2983 Received: from fireflyinternet.com (unknown [77.68.26.236]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Aug 2020 08:50:29 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from build.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 22195099-1500050 for multiple; Fri, 21 Aug 2020 09:50:15 +0100 From: Chris Wilson To: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org Cc: linux-mm@kvack.org, Chris Wilson , Matthew Auld Subject: [PATCH 3/4] drm/i915/gem: Use set_pte_at() for assigning the vmapped PTE Date: Fri, 21 Aug 2020 09:50:10 +0100 Message-Id: <20200821085011.28878-3-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200821085011.28878-1-chris@chris-wilson.co.uk> References: <20200821085011.28878-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 X-Rspamd-Queue-Id: 890CA1814B0C8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use set_pte_at() to assign the PTE pointer returned by alloc_vm_area(), rather than a direct assignment. Fixes: 6056e50033d9 ("drm/i915/gem: Support discontiguous lmem object maps") Signed-off-by: Chris Wilson Cc: Matthew Auld --- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_pages.c b/drivers/gpu/drm/i915/gem/i915_gem_pages.c index 0fee67f34d74..6838cf9bdae6 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_pages.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_pages.c @@ -286,23 +286,34 @@ static void *i915_gem_object_map(struct drm_i915_gem_object *obj, } if (i915_gem_object_has_struct_page(obj)) { + unsigned long addr = (unsigned long)area->addr; struct sgt_iter iter; struct page *page; pte_t **ptes = mem; - for_each_sgt_page(page, iter, sgt) - **ptes++ = mk_pte(page, pgprot); + for_each_sgt_page(page, iter, sgt) { + set_pte_at(&init_mm, addr, *ptes, mk_pte(page, pgprot)); + addr += PAGE_SIZE; + ptes++; + } + GEM_BUG_ON(addr != (unsigned long)area->addr + obj->base.size); } else { + unsigned long addr = (unsigned long)area->addr; resource_size_t iomap; struct sgt_iter iter; pte_t **ptes = mem; - dma_addr_t addr; + dma_addr_t offset; iomap = obj->mm.region->iomap.base; iomap -= obj->mm.region->region.start; - for_each_sgt_daddr(addr, iter, sgt) - **ptes++ = iomap_pte(iomap, addr, pgprot); + for_each_sgt_daddr(offset, iter, sgt) { + set_pte_at(&init_mm, addr, *ptes, + iomap_pte(iomap, offset, pgprot)); + addr += PAGE_SIZE; + ptes++; + } + GEM_BUG_ON(addr != (unsigned long)area->addr + obj->base.size); } flush_vm_area(area); From patchwork Fri Aug 21 08:50:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 11728643 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 D64BA1392 for ; Fri, 21 Aug 2020 08:50:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AE1EB208DB for ; Fri, 21 Aug 2020 08:50:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE1EB208DB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 470B68D0011; Fri, 21 Aug 2020 04:50:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 41F808D0005; Fri, 21 Aug 2020 04:50:42 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1FD478D0011; Fri, 21 Aug 2020 04:50:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0018.hostedemail.com [216.40.44.18]) by kanga.kvack.org (Postfix) with ESMTP id 0231E8D0005 for ; Fri, 21 Aug 2020 04:50:41 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BCC0B6103 for ; Fri, 21 Aug 2020 08:50:41 +0000 (UTC) X-FDA: 77173955082.25.coast82_141085827037 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 7EF9F1804E3A0 for ; Fri, 21 Aug 2020 08:50:41 +0000 (UTC) X-Spam-Summary: 1,0,0,fdbab27b5fd3849f,d41d8cd98f00b204,chris@chris-wilson.co.uk,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1542:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3866:3867:3874:4250:4321:4605:5007:6119:6261:7903:9168:9592:10004:11026:11232:11473:11657:11658:11914:12043:12296:12297:12438:12555:12679:12895:12986:13221:13229:13894:14096:14181:14394:14571:14721:21063:21080:21451:21627:21939:21990:30054,0,RBL:77.68.26.236:@chris-wilson.co.uk:.lbl8.mailshell.net-62.8.15.100 64.201.201.201;04ygta5z7p8caio5fqiwbsnraxnstocj9wwg36r99qcf3zaeuz4p7a1tdquwm7y.eqoapq5up4g7gjio91ggrkjk3exsjiaf9dii6b5cecsdeaqnj3i4zsaxg9x4xdj.a-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:27,LUA_SUMMARY:none X-HE-Tag: coast82_141085827037 X-Filterd-Recvd-Size: 3919 Received: from fireflyinternet.com (unknown [77.68.26.236]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Aug 2020 08:50:40 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from build.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 22195100-1500050 for multiple; Fri, 21 Aug 2020 09:50:15 +0100 From: Chris Wilson To: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org Cc: linux-mm@kvack.org, Chris Wilson , Pavel Machek , Joonas Lahtinen , stable@vger.kernel.org Subject: [PATCH 4/4] drm/i915/gem: Replace reloc chain with terminator on error unwind Date: Fri, 21 Aug 2020 09:50:11 +0100 Message-Id: <20200821085011.28878-4-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200821085011.28878-1-chris@chris-wilson.co.uk> References: <20200821085011.28878-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7EF9F1804E3A0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If we hit an error during construction of the reloc chain, we need to replace the chain into the next batch with the terminator so that upon flushing the relocations so far, we do not execute a hanging batch. Reported-by: Pavel Machek Fixes: 964a9b0f611e ("drm/i915/gem: Use chained reloc batches") Signed-off-by: Chris Wilson Cc: Joonas Lahtinen Cc: Pavel Machek Cc: # v5.8+ --- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index 24a1486d2dc5..a09f04eee417 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -972,21 +972,6 @@ static int reloc_gpu_chain(struct reloc_cache *cache) if (err) goto out_pool; - GEM_BUG_ON(cache->rq_size + RELOC_TAIL > PAGE_SIZE / sizeof(u32)); - cmd = cache->rq_cmd + cache->rq_size; - *cmd++ = MI_ARB_CHECK; - if (cache->gen >= 8) - *cmd++ = MI_BATCH_BUFFER_START_GEN8; - else if (cache->gen >= 6) - *cmd++ = MI_BATCH_BUFFER_START; - else - *cmd++ = MI_BATCH_BUFFER_START | MI_BATCH_GTT; - *cmd++ = lower_32_bits(batch->node.start); - *cmd++ = upper_32_bits(batch->node.start); /* Always 0 for gen<8 */ - i915_gem_object_flush_map(cache->rq_vma->obj); - i915_gem_object_unpin_map(cache->rq_vma->obj); - cache->rq_vma = NULL; - err = intel_gt_buffer_pool_mark_active(pool, rq); if (err == 0) { i915_vma_lock(batch); @@ -999,15 +984,31 @@ static int reloc_gpu_chain(struct reloc_cache *cache) if (err) goto out_pool; + GEM_BUG_ON(cache->rq_size + RELOC_TAIL > PAGE_SIZE / sizeof(u32)); + cmd = cache->rq_cmd + cache->rq_size; + *cmd++ = MI_ARB_CHECK; + if (cache->gen >= 8) + *cmd++ = MI_BATCH_BUFFER_START_GEN8; + else if (cache->gen >= 6) + *cmd++ = MI_BATCH_BUFFER_START; + else + *cmd++ = MI_BATCH_BUFFER_START | MI_BATCH_GTT; + *cmd++ = lower_32_bits(batch->node.start); + *cmd++ = upper_32_bits(batch->node.start); /* Always 0 for gen<8 */ + cmd = i915_gem_object_pin_map(batch->obj, cache->has_llc ? I915_MAP_FORCE_WB : I915_MAP_FORCE_WC); if (IS_ERR(cmd)) { + /* We will replace the BBS with BBE upon flushing the rq */ err = PTR_ERR(cmd); goto out_pool; } + i915_gem_object_flush_map(cache->rq_vma->obj); + i915_gem_object_unpin_map(cache->rq_vma->obj); + /* Return with batch mapping (cmd) still pinned */ cache->rq_cmd = cmd; cache->rq_size = 0;