From patchwork Fri Jun 14 13:21:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13698712 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B4FD6C27C6E for ; Fri, 14 Jun 2024 13:36:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5F95010E74C; Fri, 14 Jun 2024 13:36:04 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="Gwb28lzW"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="s3/iCzQV"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Gwb28lzW"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="s3/iCzQV"; dkim-atps=neutral Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id 791E810E55B; Fri, 14 Jun 2024 13:36:01 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6F6B13386F; Fri, 14 Jun 2024 13:35:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372159; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q9JOJjVl5Nksmgb1NU5hRG/PLRyBVvGwRQDLWAnPEpE=; b=Gwb28lzWQTc/PKzo14uoSn9n9Dzb5aWgDF1gajDOGstkFuzASSpwXbChLFunXbPcY0KolN rxq0AVHr1Y/b+lm1fkCD/L0k52EOeN+nOaGWvRkez9Kxh5YpA16H77XoxuT18dod6i6LG/ 87YW4mPkI/cj3oNts92j5Xlcbw3iD4U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372159; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q9JOJjVl5Nksmgb1NU5hRG/PLRyBVvGwRQDLWAnPEpE=; b=s3/iCzQVO4XRuHFmirPoZ0tfXx7H4u0JVJvU9u406l8RoV0mPGPv1Oq/Sxh489AYdvTZ51 95z3ZNL8EDu+LWAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372159; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q9JOJjVl5Nksmgb1NU5hRG/PLRyBVvGwRQDLWAnPEpE=; b=Gwb28lzWQTc/PKzo14uoSn9n9Dzb5aWgDF1gajDOGstkFuzASSpwXbChLFunXbPcY0KolN rxq0AVHr1Y/b+lm1fkCD/L0k52EOeN+nOaGWvRkez9Kxh5YpA16H77XoxuT18dod6i6LG/ 87YW4mPkI/cj3oNts92j5Xlcbw3iD4U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372159; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q9JOJjVl5Nksmgb1NU5hRG/PLRyBVvGwRQDLWAnPEpE=; b=s3/iCzQVO4XRuHFmirPoZ0tfXx7H4u0JVJvU9u406l8RoV0mPGPv1Oq/Sxh489AYdvTZ51 95z3ZNL8EDu+LWAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 099D113AB5; Fri, 14 Jun 2024 13:35:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WNgZAT9HbGavPwAAD6G6ig (envelope-from ); Fri, 14 Jun 2024 13:35:59 +0000 From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, daniel@ffwll.ch, lucas.demarchi@intel.com, rodrigo.vivi@intel.com, jani.nikula@linux.intel.com, ray.huang@amd.com, christian.koenig@amd.com, kraxel@redhat.com, airlied@redhat.com, suijingfeng@loongson.cn Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Thomas Zimmermann Subject: [PATCH 1/6] iosys-map: Add allocator flags Date: Fri, 14 Jun 2024 15:21:55 +0200 Message-ID: <20240614133556.11378-2-tzimmermann@suse.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240614133556.11378-1-tzimmermann@suse.de> References: <20240614133556.11378-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[16]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email]; FREEMAIL_TO(0.00)[linux.intel.com,kernel.org,gmail.com,ffwll.ch,intel.com,amd.com,redhat.com,loongson.cn]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add the public field alloc_flags to struct iosys_map. It allows for the allocator of the mapping to store additional flags, such details about the internal alloctor operations. This will be helpful with DRM's TTM memory manager, which supports various types of memory in it's vmap functions. The new field fills existing padding bytes in struct iosys_map, so instances of the type do not grow in size. Signed-off-by: Thomas Zimmermann --- include/linux/iosys-map.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/iosys-map.h b/include/linux/iosys-map.h index 4696abfd311cc..f3b351094bca0 100644 --- a/include/linux/iosys-map.h +++ b/include/linux/iosys-map.h @@ -97,6 +97,11 @@ * * iosys_map_memcpy_to(&map, src, len); * iosys_map_incr(&map, len); // go to first byte after the memcpy + * + * The only public field in :c:type:`struct iosys_map ` is + * alloc_flags. It allows allocators to store additional information about the + * stored memory. Helpers will initialize or clear it to zero, but the values + * are only used by the allocator. */ /** @@ -105,6 +110,7 @@ * @vaddr: The buffer's address if in system memory * @is_iomem: True if the buffer is located in I/O memory, or false * otherwise. + * @alloc_flags Allocator private flags */ struct iosys_map { union { @@ -112,6 +118,7 @@ struct iosys_map { void *vaddr; }; bool is_iomem; + u16 alloc_flags; }; /** @@ -122,6 +129,7 @@ struct iosys_map { { \ .vaddr = (vaddr_), \ .is_iomem = false, \ + .alloc_flags = 0, \ } /** @@ -132,6 +140,7 @@ struct iosys_map { { \ .vaddr_iomem = (vaddr_iomem_), \ .is_iomem = true, \ + .alloc_flags = 0, \ } /** @@ -260,7 +269,8 @@ static inline bool iosys_map_is_set(const struct iosys_map *map) * * Clears all fields to zero, including struct iosys_map.is_iomem, so * mapping structures that were set to point to I/O memory are reset for - * system memory. Pointers are cleared to NULL. This is the default. + * system memory. Pointers are cleared to NULL. The allocator flags in + * struct iosys_map.alloc_flags are cleared to zero. */ static inline void iosys_map_clear(struct iosys_map *map) { @@ -270,6 +280,7 @@ static inline void iosys_map_clear(struct iosys_map *map) } else { map->vaddr = NULL; } + map->alloc_flags = 0; } /** From patchwork Fri Jun 14 13:21:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13698714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4DD8BC2BA15 for ; Fri, 14 Jun 2024 13:36:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 02C5310ED3C; Fri, 14 Jun 2024 13:36:10 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="ZxAw88Zq"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Z9EV6OR8"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ZxAw88Zq"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Z9EV6OR8"; dkim-atps=neutral Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5EE2A10E252; Fri, 14 Jun 2024 13:36:01 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D973D33870; Fri, 14 Jun 2024 13:35:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372159; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rHX6W35lBy+nLaw7C6R+lHBd02eCMOuRYcEF5LhQb7o=; b=ZxAw88ZqvIaujhTO5ePItwkmJEYpFZ5OCgSLsUmCXF+8ZFRMh0MbO9lqwNhPRWmFOBRTrs MKKTvQxeG6ZNN9O3c0ZteFML1vkhEFHcPC4xFurbyUa+slilB7H8pxpQjvULOTqGQGtqZs yUcVSf70LQqAkFFPdPOuF4OxWbp/v3s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372159; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rHX6W35lBy+nLaw7C6R+lHBd02eCMOuRYcEF5LhQb7o=; b=Z9EV6OR8Wp5my78AbIQtuRrh/ResOEbfoYgKed0i6+8kOZqXKFYqugBl5PVNLBKLkvvc9e imJ0yseruJqVi8CQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZxAw88Zq; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Z9EV6OR8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372159; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rHX6W35lBy+nLaw7C6R+lHBd02eCMOuRYcEF5LhQb7o=; b=ZxAw88ZqvIaujhTO5ePItwkmJEYpFZ5OCgSLsUmCXF+8ZFRMh0MbO9lqwNhPRWmFOBRTrs MKKTvQxeG6ZNN9O3c0ZteFML1vkhEFHcPC4xFurbyUa+slilB7H8pxpQjvULOTqGQGtqZs yUcVSf70LQqAkFFPdPOuF4OxWbp/v3s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372159; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rHX6W35lBy+nLaw7C6R+lHBd02eCMOuRYcEF5LhQb7o=; b=Z9EV6OR8Wp5my78AbIQtuRrh/ResOEbfoYgKed0i6+8kOZqXKFYqugBl5PVNLBKLkvvc9e imJ0yseruJqVi8CQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7515713AB1; Fri, 14 Jun 2024 13:35:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gEpWGz9HbGavPwAAD6G6ig (envelope-from ); Fri, 14 Jun 2024 13:35:59 +0000 From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, daniel@ffwll.ch, lucas.demarchi@intel.com, rodrigo.vivi@intel.com, jani.nikula@linux.intel.com, ray.huang@amd.com, christian.koenig@amd.com, kraxel@redhat.com, airlied@redhat.com, suijingfeng@loongson.cn Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Thomas Zimmermann Subject: [PATCH 2/6] drm/ttm: Store the bo_kmap_type in struct iosys_map Date: Fri, 14 Jun 2024 15:21:56 +0200 Message-ID: <20240614133556.11378-3-tzimmermann@suse.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240614133556.11378-1-tzimmermann@suse.de> References: <20240614133556.11378-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: D973D33870 X-Spamd-Result: default: False [-1.72 / 50.00]; BAYES_HAM(-1.71)[93.21%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCPT_COUNT_TWELVE(0.00)[16]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_TO(0.00)[linux.intel.com,kernel.org,gmail.com,ffwll.ch,intel.com,amd.com,redhat.com,loongson.cn]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from,2a07:de40:b281:106:10:150:64:167:received]; R_RATELIMIT(0.00)[to_ip_from(RLau4tukfh38qp3nirdnk14qe9)]; RCVD_VIA_SMTP_AUTH(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" For each instances of struct iosys_map set up by ttm_bo_vmap(), store the type of allocation in the instance. Use this information to unmap the memory in ttm_bo_vunmap(). This change simplifies the unmap code and puts the complicated logic entirely into the map code. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/ttm/ttm_bo_util.c | 46 +++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index 0b3f4267130c4..a9df0deff2deb 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -36,6 +36,7 @@ #include #include +#include struct ttm_transfer_obj { struct ttm_buffer_object base; @@ -479,24 +480,29 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) if (mem->bus.is_iomem) { void __iomem *vaddr_iomem; + u16 alloc_flags; - if (mem->bus.addr) + if (mem->bus.addr) { vaddr_iomem = (void __iomem *)mem->bus.addr; - else if (mem->bus.caching == ttm_write_combined) - vaddr_iomem = ioremap_wc(mem->bus.offset, - bo->base.size); + alloc_flags = ttm_bo_map_premapped; + } else if (mem->bus.caching == ttm_write_combined) { + vaddr_iomem = ioremap_wc(mem->bus.offset, bo->base.size); + alloc_flags = ttm_bo_map_iomap; #ifdef CONFIG_X86 - else if (mem->bus.caching == ttm_cached) - vaddr_iomem = ioremap_cache(mem->bus.offset, - bo->base.size); + } else if (mem->bus.caching == ttm_cached) { + vaddr_iomem = ioremap_cache(mem->bus.offset, bo->base.size); + alloc_flags = ttm_bo_map_iomap; #endif - else + } else { vaddr_iomem = ioremap(mem->bus.offset, bo->base.size); + alloc_flags = ttm_bo_map_iomap; + } if (!vaddr_iomem) return -ENOMEM; iosys_map_set_vaddr_iomem(map, vaddr_iomem); + map->alloc_flags = alloc_flags; } else { struct ttm_operation_ctx ctx = { @@ -506,6 +512,7 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) struct ttm_tt *ttm = bo->ttm; pgprot_t prot; void *vaddr; + u16 alloc_flags; ret = ttm_tt_populate(bo->bdev, ttm, &ctx); if (ret) @@ -519,8 +526,10 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) vaddr = vmap(ttm->pages, ttm->num_pages, 0, prot); if (!vaddr) return -ENOMEM; + alloc_flags = ttm_bo_map_vmap; iosys_map_set_vaddr(map, vaddr); + map->alloc_flags = alloc_flags; } return 0; @@ -537,20 +546,27 @@ EXPORT_SYMBOL(ttm_bo_vmap); */ void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct iosys_map *map) { - struct ttm_resource *mem = bo->resource; - dma_resv_assert_held(bo->base.resv); if (iosys_map_is_null(map)) return; - if (!map->is_iomem) - vunmap(map->vaddr); - else if (!mem->bus.addr) + switch (map->alloc_flags) { + case ttm_bo_map_iomap: iounmap(map->vaddr_iomem); - iosys_map_clear(map); - + break; + case ttm_bo_map_vmap: + vunmap(map->vaddr); + break; + case ttm_bo_map_premapped: + break; + default: + drm_err(bo->base.dev, "Unsupported alloc_flags 0x%x\n", map->alloc_flags); + return; + } ttm_mem_io_free(bo->bdev, bo->resource); + + iosys_map_clear(map); } EXPORT_SYMBOL(ttm_bo_vunmap); From patchwork Fri Jun 14 13:21:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13698711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C731BC2BA15 for ; Fri, 14 Jun 2024 13:36:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A040A10E252; Fri, 14 Jun 2024 13:36:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="PF2thHKd"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="AFUO5oQW"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="PF2thHKd"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="AFUO5oQW"; dkim-atps=neutral Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id A940B10E746; Fri, 14 Jun 2024 13:36:01 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4EE4B33872; Fri, 14 Jun 2024 13:36:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SaNx5tqAjaiAhSizfBYzjoCWc6At7tuq/F7DXXxrZUI=; b=PF2thHKdPo2R5mQRADdfg2/U2EPXIhcE9/dQfmOAv1cGuq340wcWsB+T5HT0kUgByGa072 MMXo97v82qhd0d1Ry2FmxD9uGeuV6LZq/XHmtL6kxRr3mFg5Gphs/2hucSiEUxG1uYfapU a5PY99sADp2wKtkmLYmTZcEj/PJ2a+s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SaNx5tqAjaiAhSizfBYzjoCWc6At7tuq/F7DXXxrZUI=; b=AFUO5oQWfd7T2q/P6N9bHcGPOAiHKRlw//g1kqcjJb4RZmRB5VZe6KLgahZz0GwEdyzV6y JBj+Bml9scEDcHDw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=PF2thHKd; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=AFUO5oQW DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SaNx5tqAjaiAhSizfBYzjoCWc6At7tuq/F7DXXxrZUI=; b=PF2thHKdPo2R5mQRADdfg2/U2EPXIhcE9/dQfmOAv1cGuq340wcWsB+T5HT0kUgByGa072 MMXo97v82qhd0d1Ry2FmxD9uGeuV6LZq/XHmtL6kxRr3mFg5Gphs/2hucSiEUxG1uYfapU a5PY99sADp2wKtkmLYmTZcEj/PJ2a+s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SaNx5tqAjaiAhSizfBYzjoCWc6At7tuq/F7DXXxrZUI=; b=AFUO5oQWfd7T2q/P6N9bHcGPOAiHKRlw//g1kqcjJb4RZmRB5VZe6KLgahZz0GwEdyzV6y JBj+Bml9scEDcHDw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DF79013AB5; Fri, 14 Jun 2024 13:35:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id wDhUNT9HbGavPwAAD6G6ig (envelope-from ); Fri, 14 Jun 2024 13:35:59 +0000 From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, daniel@ffwll.ch, lucas.demarchi@intel.com, rodrigo.vivi@intel.com, jani.nikula@linux.intel.com, ray.huang@amd.com, christian.koenig@amd.com, kraxel@redhat.com, airlied@redhat.com, suijingfeng@loongson.cn Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Thomas Zimmermann Subject: [PATCH 3/6] drm/ttm: Support partial buffer mappings for ttm_bo_vmap() Date: Fri, 14 Jun 2024 15:21:57 +0200 Message-ID: <20240614133556.11378-4-tzimmermann@suse.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240614133556.11378-1-tzimmermann@suse.de> References: <20240614133556.11378-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCPT_COUNT_TWELVE(0.00)[16]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_TO(0.00)[linux.intel.com,kernel.org,gmail.com,ffwll.ch,intel.com,amd.com,redhat.com,loongson.cn]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received,2a07:de40:b281:104:10:150:64:97:from]; R_RATELIMIT(0.00)[to_ip_from(RLau4tukfh38qp3nirdnk14qe9)]; RCVD_VIA_SMTP_AUTH(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 4EE4B33872 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add offset and size parameters to ttm_bo_vmap() to allow for partial mappings of a buffer object. This brings the functionality on par with ttm_bo_kmap(). Callers pass the byte offset and size within the buffer object and receive a page-aligned mapping of the buffer object's memory for the specified area. Also update all callers of ttm_bo_vmap() for the new parameters. As before, existing callers map the buffer object's complete memory. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/drm_gem_ttm_helper.c | 2 +- drivers/gpu/drm/drm_gem_vram_helper.c | 2 +- drivers/gpu/drm/loongson/lsdc_gem.c | 2 +- drivers/gpu/drm/qxl/qxl_object.c | 2 +- drivers/gpu/drm/ttm/ttm_bo_util.c | 21 +++++++++++++++------ drivers/gpu/drm/xe/xe_lrc.c | 2 +- drivers/gpu/drm/xe/xe_vm.c | 2 +- include/drm/ttm/ttm_bo.h | 4 +++- 8 files changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_ttm_helper.c b/drivers/gpu/drm/drm_gem_ttm_helper.c index 3734aa2d1c5b5..f26b7c9077a68 100644 --- a/drivers/gpu/drm/drm_gem_ttm_helper.c +++ b/drivers/gpu/drm/drm_gem_ttm_helper.c @@ -67,7 +67,7 @@ int drm_gem_ttm_vmap(struct drm_gem_object *gem, { struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem); - return ttm_bo_vmap(bo, map); + return ttm_bo_vmap(bo, 0, gem->size, map); } EXPORT_SYMBOL(drm_gem_ttm_vmap); diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c index 6027584406af6..1670f9a459a9d 100644 --- a/drivers/gpu/drm/drm_gem_vram_helper.c +++ b/drivers/gpu/drm/drm_gem_vram_helper.c @@ -398,7 +398,7 @@ int drm_gem_vram_vmap(struct drm_gem_vram_object *gbo, struct iosys_map *map) * no mapping present. */ if (iosys_map_is_null(&gbo->map)) { - ret = ttm_bo_vmap(&gbo->bo, &gbo->map); + ret = ttm_bo_vmap(&gbo->bo, 0, gbo->bo.base.size, &gbo->map); if (ret) return ret; } diff --git a/drivers/gpu/drm/loongson/lsdc_gem.c b/drivers/gpu/drm/loongson/lsdc_gem.c index a720d8f532093..f709960c781b9 100644 --- a/drivers/gpu/drm/loongson/lsdc_gem.c +++ b/drivers/gpu/drm/loongson/lsdc_gem.c @@ -77,7 +77,7 @@ static int lsdc_gem_object_vmap(struct drm_gem_object *obj, struct iosys_map *ma return ret; } - ret = ttm_bo_vmap(tbo, &lbo->map); + ret = ttm_bo_vmap(tbo, 0, tbo->base.size, &lbo->map); if (ret) { drm_err(obj->dev, "ttm bo vmap failed\n"); lsdc_bo_unpin(lbo); diff --git a/drivers/gpu/drm/qxl/qxl_object.c b/drivers/gpu/drm/qxl/qxl_object.c index 5893e27a7ae50..9f06d5e26a32c 100644 --- a/drivers/gpu/drm/qxl/qxl_object.c +++ b/drivers/gpu/drm/qxl/qxl_object.c @@ -164,7 +164,7 @@ int qxl_bo_vmap_locked(struct qxl_bo *bo, struct iosys_map *map) goto out; } - r = ttm_bo_vmap(&bo->tbo, &bo->map); + r = ttm_bo_vmap(&bo->tbo, 0, bo->tbo.base.size, &bo->map); if (r) { qxl_bo_unpin_locked(bo); return r; diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index a9df0deff2deb..31f9772f05dac 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -457,17 +457,23 @@ EXPORT_SYMBOL(ttm_bo_kunmap); * ttm_bo_vmap * * @bo: The buffer object. + * @offset: Byte offset into the buffer. + * @size: Number of bytes to map. * @map: pointer to a struct iosys_map representing the map. * * Sets up a kernel virtual mapping, using ioremap or vmap to the * data in the buffer object. The parameter @map returns the virtual * address as struct iosys_map. Unmap the buffer with ttm_bo_vunmap(). + * The address stored in @map will be aligned to the next lower page + * boundaries. * * Returns * -ENOMEM: Out of memory. * -EINVAL: Invalid range. */ -int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) +int ttm_bo_vmap(struct ttm_buffer_object *bo, + unsigned long offset, unsigned long size, + struct iosys_map *map) { struct ttm_resource *mem = bo->resource; int ret; @@ -483,18 +489,18 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) u16 alloc_flags; if (mem->bus.addr) { - vaddr_iomem = (void __iomem *)mem->bus.addr; + vaddr_iomem = (u8 __iomem *)mem->bus.addr + offset; alloc_flags = ttm_bo_map_premapped; } else if (mem->bus.caching == ttm_write_combined) { - vaddr_iomem = ioremap_wc(mem->bus.offset, bo->base.size); + vaddr_iomem = ioremap_wc(mem->bus.offset + offset, size); alloc_flags = ttm_bo_map_iomap; #ifdef CONFIG_X86 } else if (mem->bus.caching == ttm_cached) { - vaddr_iomem = ioremap_cache(mem->bus.offset, bo->base.size); + vaddr_iomem = ioremap_cache(mem->bus.offset + offset, size); alloc_flags = ttm_bo_map_iomap; #endif } else { - vaddr_iomem = ioremap(mem->bus.offset, bo->base.size); + vaddr_iomem = ioremap(mem->bus.offset + offset, size); alloc_flags = ttm_bo_map_iomap; } @@ -510,6 +516,9 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) .no_wait_gpu = false }; struct ttm_tt *ttm = bo->ttm; + unsigned long start_page = offset >> PAGE_SHIFT; + unsigned long aligned_size = size + (offset - (start_page << PAGE_SHIFT)); + unsigned long num_pages = DIV_ROUND_UP(aligned_size, PAGE_SIZE); pgprot_t prot; void *vaddr; u16 alloc_flags; @@ -523,7 +532,7 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) * or to make the buffer object look contiguous. */ prot = ttm_io_prot(bo, mem, PAGE_KERNEL); - vaddr = vmap(ttm->pages, ttm->num_pages, 0, prot); + vaddr = vmap(ttm->pages + start_page, num_pages, 0, prot); if (!vaddr) return -ENOMEM; alloc_flags = ttm_bo_map_vmap; diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c index c1bb85d2e243f..3a68fe6d592ed 100644 --- a/drivers/gpu/drm/xe/xe_lrc.c +++ b/drivers/gpu/drm/xe/xe_lrc.c @@ -1595,7 +1595,7 @@ void xe_lrc_snapshot_capture_delayed(struct xe_lrc_snapshot *snapshot) goto put_bo; xe_bo_lock(bo, false); - if (!ttm_bo_vmap(&bo->ttm, &src)) { + if (!ttm_bo_vmap(&bo->ttm, 0, bo->ttm.base.size, &src)) { xe_map_memcpy_from(xe_bo_device(bo), snapshot->lrc_snapshot, &src, snapshot->lrc_offset, snapshot->lrc_size); diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c index 99bf7412475c0..81306c32f5d09 100644 --- a/drivers/gpu/drm/xe/xe_vm.c +++ b/drivers/gpu/drm/xe/xe_vm.c @@ -3485,7 +3485,7 @@ void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap) if (bo) { xe_bo_lock(bo, false); - err = ttm_bo_vmap(&bo->ttm, &src); + err = ttm_bo_vmap(&bo->ttm, 0, bo->ttm.base.size, &src); if (!err) { xe_map_memcpy_from(xe_bo_device(bo), snap->snap[i].data, diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h index 6ccf96c91f3ae..c421ffe3563b1 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -375,7 +375,9 @@ int ttm_bo_init_validate(struct ttm_device *bdev, struct ttm_buffer_object *bo, int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page, unsigned long num_pages, struct ttm_bo_kmap_obj *map); void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map); -int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map); +int ttm_bo_vmap(struct ttm_buffer_object *bo, + unsigned long offset, unsigned long size, + struct iosys_map *map); void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct iosys_map *map); int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo); int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx, From patchwork Fri Jun 14 13:21:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13698713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DC893C27C6E for ; Fri, 14 Jun 2024 13:36:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EF67810ED4E; Fri, 14 Jun 2024 13:36:06 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="VgximUpZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="XwTQcOrs"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="VgximUpZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="XwTQcOrs"; dkim-atps=neutral Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6F33310E24F; Fri, 14 Jun 2024 13:36:02 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B8D9B2053F; Fri, 14 Jun 2024 13:36:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DC/Tz4Yqkhk7cqmPNeNVbm91VWWVkQP9gT8JczO+Fio=; b=VgximUpZ2x1TJz948ABxvMKD/SJwpWHH/x0f1Me764J6UpcQHs2wVt0jTtiHCrFDPWCtnb xNGTVvRSrKKBFg7HX9Zqi5kfMSyjneZhY1G+UK3w4tE0AsWXcGk4cfGjoQN2w4NiOummgj wqQiN4mzxFNYLZtzweTVJkRclkDFFgg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DC/Tz4Yqkhk7cqmPNeNVbm91VWWVkQP9gT8JczO+Fio=; b=XwTQcOrs1/IMIMT+84RlSXpyejo7f0nzQoxZzzOI3wxYV9gOaQXEiXESaGZnfGHNDv6Xd5 jxUrBo7UviWLMYCQ== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=VgximUpZ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=XwTQcOrs DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DC/Tz4Yqkhk7cqmPNeNVbm91VWWVkQP9gT8JczO+Fio=; b=VgximUpZ2x1TJz948ABxvMKD/SJwpWHH/x0f1Me764J6UpcQHs2wVt0jTtiHCrFDPWCtnb xNGTVvRSrKKBFg7HX9Zqi5kfMSyjneZhY1G+UK3w4tE0AsWXcGk4cfGjoQN2w4NiOummgj wqQiN4mzxFNYLZtzweTVJkRclkDFFgg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DC/Tz4Yqkhk7cqmPNeNVbm91VWWVkQP9gT8JczO+Fio=; b=XwTQcOrs1/IMIMT+84RlSXpyejo7f0nzQoxZzzOI3wxYV9gOaQXEiXESaGZnfGHNDv6Xd5 jxUrBo7UviWLMYCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 54E8013AB1; Fri, 14 Jun 2024 13:36:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4F6AE0BHbGavPwAAD6G6ig (envelope-from ); Fri, 14 Jun 2024 13:36:00 +0000 From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, daniel@ffwll.ch, lucas.demarchi@intel.com, rodrigo.vivi@intel.com, jani.nikula@linux.intel.com, ray.huang@amd.com, christian.koenig@amd.com, kraxel@redhat.com, airlied@redhat.com, suijingfeng@loongson.cn Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Thomas Zimmermann Subject: [PATCH 4/6] drm/ttm: Support kmap for single-page mappings in ttm_bo_vmap() Date: Fri, 14 Jun 2024 15:21:58 +0200 Message-ID: <20240614133556.11378-5-tzimmermann@suse.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240614133556.11378-1-tzimmermann@suse.de> References: <20240614133556.11378-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: B8D9B2053F X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCPT_COUNT_TWELVE(0.00)[16]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_TO(0.00)[linux.intel.com,kernel.org,gmail.com,ffwll.ch,intel.com,amd.com,redhat.com,loongson.cn]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from,2a07:de40:b281:106:10:150:64:167:received]; R_RATELIMIT(0.00)[to_ip_from(RLau4tukfh38qp3nirdnk14qe9)]; RCVD_VIA_SMTP_AUTH(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" In ttm_bo_vmap(), set up single-page mappings with kmap() in certain cases. The feature is already present in ttm_bo_kmap(). This functionality is require by DRM's xe driver, which claims that using kmap() is an optimization over vmap(). [1] Reading the commit at [2] indicates otherwise. It is not possible to use kmap_local_page() and kunmap_local_page(), as TTM cannot guarantee the requirements for ordering these calls. [3] Signed-off-by: Thomas Zimmermann Link: https://elixir.bootlin.com/linux/v6.9/source/drivers/gpu/drm/xe/xe_bo.c#L1870 # 1 Link: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com/T/#u # 2 Link: https://elixir.bootlin.com/linux/v6.9/source/include/linux/highmem.h#L70 # 3 --- drivers/gpu/drm/ttm/ttm_bo_util.c | 33 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index 31f9772f05dac..c06cfccace39d 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -516,6 +516,8 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, .no_wait_gpu = false }; struct ttm_tt *ttm = bo->ttm; + struct ttm_resource_manager *man = + ttm_manager_type(bo->bdev, bo->resource->mem_type); unsigned long start_page = offset >> PAGE_SHIFT; unsigned long aligned_size = size + (offset - (start_page << PAGE_SHIFT)); unsigned long num_pages = DIV_ROUND_UP(aligned_size, PAGE_SIZE); @@ -527,15 +529,25 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, if (ret) return ret; - /* - * We need to use vmap to get the desired page protection - * or to make the buffer object look contiguous. - */ - prot = ttm_io_prot(bo, mem, PAGE_KERNEL); - vaddr = vmap(ttm->pages + start_page, num_pages, 0, prot); - if (!vaddr) - return -ENOMEM; - alloc_flags = ttm_bo_map_vmap; + if (num_pages == 1 && ttm->caching == ttm_cached && + !(man->use_tt && (ttm->page_flags & TTM_TT_FLAG_DECRYPTED))) { + /* + * We're mapping a single page, and the desired + * page protection is consistent with the bo. + */ + vaddr = kmap(ttm->pages[start_page]); + alloc_flags = ttm_bo_map_kmap; + } else { + /* + * We need to use vmap to get the desired page protection + * or to make the buffer object look contiguous. + */ + prot = ttm_io_prot(bo, mem, PAGE_KERNEL); + vaddr = vmap(ttm->pages + start_page, num_pages, 0, prot); + if (!vaddr) + return -ENOMEM; + alloc_flags = ttm_bo_map_vmap; + } iosys_map_set_vaddr(map, vaddr); map->alloc_flags = alloc_flags; @@ -567,6 +579,9 @@ void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct iosys_map *map) case ttm_bo_map_vmap: vunmap(map->vaddr); break; + case ttm_bo_map_kmap: + kunmap(kmap_to_page(map->vaddr)); + break; case ttm_bo_map_premapped: break; default: From patchwork Fri Jun 14 13:21:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13698716 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 36F0EC2BA15 for ; Fri, 14 Jun 2024 13:36:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F38FF10ED58; Fri, 14 Jun 2024 13:36:20 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="LT1Pb7ys"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="lx2sBrbF"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="LT1Pb7ys"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="lx2sBrbF"; dkim-atps=neutral Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id A0A1810E252; Fri, 14 Jun 2024 13:36:02 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2CB9433873; Fri, 14 Jun 2024 13:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372161; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CfNtw5Nm4AZDZ+Hc/tZxBivEuvk7CEMf16k5ZsG0+G4=; b=LT1Pb7ysssOtXmruS7VcmSly/Ax6CVVgY9JdS4VH6DiKCAcXoR2R1k5ArO1Y+Sog79f9Pg 1RzncF71gFVu06LOVjAVt62M/IUFvh5nEYjqDi3FIP6RQAOzpjYH6ruSi7Dn0O/FfO/3wC acyV2Biw2bvegDDxPVf0N1LJyaTbPQA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372161; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CfNtw5Nm4AZDZ+Hc/tZxBivEuvk7CEMf16k5ZsG0+G4=; b=lx2sBrbFSDm4acjsvc6sf6/lv7tDfztJoLRLbnm7swRD5fs5ztsPGatFG5DIXSKmayscPK i8dLm9Nxf8defkCQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372161; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CfNtw5Nm4AZDZ+Hc/tZxBivEuvk7CEMf16k5ZsG0+G4=; b=LT1Pb7ysssOtXmruS7VcmSly/Ax6CVVgY9JdS4VH6DiKCAcXoR2R1k5ArO1Y+Sog79f9Pg 1RzncF71gFVu06LOVjAVt62M/IUFvh5nEYjqDi3FIP6RQAOzpjYH6ruSi7Dn0O/FfO/3wC acyV2Biw2bvegDDxPVf0N1LJyaTbPQA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372161; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CfNtw5Nm4AZDZ+Hc/tZxBivEuvk7CEMf16k5ZsG0+G4=; b=lx2sBrbFSDm4acjsvc6sf6/lv7tDfztJoLRLbnm7swRD5fs5ztsPGatFG5DIXSKmayscPK i8dLm9Nxf8defkCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BF5A013AB5; Fri, 14 Jun 2024 13:36:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id AJp5LUBHbGavPwAAD6G6ig (envelope-from ); Fri, 14 Jun 2024 13:36:00 +0000 From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, daniel@ffwll.ch, lucas.demarchi@intel.com, rodrigo.vivi@intel.com, jani.nikula@linux.intel.com, ray.huang@amd.com, christian.koenig@amd.com, kraxel@redhat.com, airlied@redhat.com, suijingfeng@loongson.cn Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Thomas Zimmermann Subject: [PATCH 5/6] drm/xe: Remove vunmap calls object-freeing code Date: Fri, 14 Jun 2024 15:21:59 +0200 Message-ID: <20240614133556.11378-6-tzimmermann@suse.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240614133556.11378-1-tzimmermann@suse.de> References: <20240614133556.11378-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCPT_COUNT_TWELVE(0.00)[16]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo]; FREEMAIL_TO(0.00)[linux.intel.com,kernel.org,gmail.com,ffwll.ch,intel.com,amd.com,redhat.com,loongson.cn]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; R_RATELIMIT(0.00)[to_ip_from(RLk1j8fm6pferx3phn9ndszqb3)]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Move calls to unmap the buffer-object memory from the object-release code in xe_gem_object_free() to the caller of the release. Doing an unmap for a BO requires holding the reservation lock, which is not allowed while releasing a GEM object. Without the reservation lock, TTM can concurrently evict the buffer object that is to be released; making the mapping invalid. Pushing the unmap calls, namely xe_bo_vunmap(), releases the mapped pages before the buffer object. While at it, add a warning about buffer mappings to the GEM-object release code. The warning message and unmap code can be removed after the driver has been audited to not release mapped buffer objects. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/xe/display/intel_fb_bo.c | 12 +++++++----- drivers/gpu/drm/xe/xe_bo.c | 14 +++++++++++++- drivers/gpu/drm/xe/xe_bo.h | 23 ++++++++++++----------- drivers/gpu/drm/xe/xe_lrc.c | 1 + 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/xe/display/intel_fb_bo.c b/drivers/gpu/drm/xe/display/intel_fb_bo.c index f835492f73fb4..cf2720dbdd51f 100644 --- a/drivers/gpu/drm/xe/display/intel_fb_bo.c +++ b/drivers/gpu/drm/xe/display/intel_fb_bo.c @@ -12,12 +12,14 @@ void intel_fb_bo_framebuffer_fini(struct xe_bo *bo) { - if (bo->flags & XE_BO_FLAG_PINNED) { - /* Unpin our kernel fb first */ - xe_bo_lock(bo, false); + xe_bo_lock(bo, false); + xe_bo_vunmap(bo); + + /* Unpin our kernel fb first */ + if (bo->flags & XE_BO_FLAG_PINNED) xe_bo_unpin(bo); - xe_bo_unlock(bo); - } + + xe_bo_unlock(bo); xe_bo_put(bo); } diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 2bae01ce4e5b9..a98d857ff1e5a 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -1093,6 +1093,19 @@ static void xe_ttm_bo_destroy(struct ttm_buffer_object *ttm_bo) static void xe_gem_object_free(struct drm_gem_object *obj) { + struct xe_bo *bo = gem_to_xe_bo(obj); + + /* + * Trying to free the object with a mapping in place. Resolve + * this warning by calling xe_bo_vunmap() in the code that leads + * ot this object release. + * + * TODO: Audit the driver to not release mapped buffer objects and + * then remove this block. + */ + if (drm_WARN_ON(obj->dev, !iosys_map_is_null(&bo->vmap))) + __xe_bo_vunmap(bo); + /* Our BO reference counting scheme works as follows: * * The gem object kref is typically used throughout the driver, @@ -1106,7 +1119,6 @@ static void xe_gem_object_free(struct drm_gem_object *obj) * driver ttm callbacks is allowed to use the ttm_buffer_object * refcount directly if needed. */ - __xe_bo_vunmap(gem_to_xe_bo(obj)); ttm_bo_put(container_of(obj, struct ttm_buffer_object, base)); } diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h index 6de894c728f54..5d1f8f13fbf13 100644 --- a/drivers/gpu/drm/xe/xe_bo.h +++ b/drivers/gpu/drm/xe/xe_bo.h @@ -170,17 +170,6 @@ static inline bool xe_bo_is_pinned(struct xe_bo *bo) return bo->ttm.pin_count; } -static inline void xe_bo_unpin_map_no_vm(struct xe_bo *bo) -{ - if (likely(bo)) { - xe_bo_lock(bo, false); - xe_bo_unpin(bo); - xe_bo_unlock(bo); - - xe_bo_put(bo); - } -} - bool xe_bo_is_xe_bo(struct ttm_buffer_object *bo); dma_addr_t __xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size); dma_addr_t xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size); @@ -202,6 +191,18 @@ xe_bo_ggtt_addr(struct xe_bo *bo) int xe_bo_vmap(struct xe_bo *bo); void xe_bo_vunmap(struct xe_bo *bo); +static inline void xe_bo_unpin_map_no_vm(struct xe_bo *bo) +{ + if (likely(bo)) { + xe_bo_lock(bo, false); + xe_bo_vunmap(bo); + xe_bo_unpin(bo); + xe_bo_unlock(bo); + + xe_bo_put(bo); + } +} + bool mem_type_is_vram(u32 mem_type); bool xe_bo_is_vram(struct xe_bo *bo); bool xe_bo_is_stolen(struct xe_bo *bo); diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c index 3a68fe6d592ed..8a52797fe79bb 100644 --- a/drivers/gpu/drm/xe/xe_lrc.c +++ b/drivers/gpu/drm/xe/xe_lrc.c @@ -812,6 +812,7 @@ static void xe_lrc_finish(struct xe_lrc *lrc) { xe_hw_fence_ctx_finish(&lrc->fence_ctx); xe_bo_lock(lrc->bo, false); + xe_bo_vunmap(lrc->bo); xe_bo_unpin(lrc->bo); xe_bo_unlock(lrc->bo); xe_bo_put(lrc->bo); From patchwork Fri Jun 14 13:22:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13698717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 778CDC27C6E for ; Fri, 14 Jun 2024 13:36:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CA63E10ED26; Fri, 14 Jun 2024 13:36:26 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="t+3+5ycK"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ryMEyGPY"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="CW8MLZ7F"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Mrb2B2sD"; dkim-atps=neutral Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 120D210E746; Fri, 14 Jun 2024 13:36:04 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 96C9E20542; Fri, 14 Jun 2024 13:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372162; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XFRnd/qhxpPmZMYDORcvPtacx3rDNVTHZIGudbT0oRI=; b=t+3+5ycKXBTaVbcfR0TQE40/enH13hPXxkDrXgniq+YvyJsaiTLE6iF6uHOlxNsOaE/5eo 2Or5AEZwMkFns80o9ZXs/Gi0uUpnYWBDSWQtJP1eAFd7DwtVW1w++QX7JoalLbfnA9iNPN J4z8JPwVDMRmXbhLsc+ONJbcOPn5LvU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372162; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XFRnd/qhxpPmZMYDORcvPtacx3rDNVTHZIGudbT0oRI=; b=ryMEyGPYsDscFnDO6WZCTVfChulzukEDO354XesdUB1Ba7PhwsHxwMMUBeS7dUwAxLU/63 QqB0EpVprbgY2pAQ== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=CW8MLZ7F; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Mrb2B2sD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718372161; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XFRnd/qhxpPmZMYDORcvPtacx3rDNVTHZIGudbT0oRI=; b=CW8MLZ7F3RDCLXX4GsI1Jjb/3I/Dc6+v9NLB8ci+JkVmR1Wg7Twezjn/dZakYOFuRq6jw+ H4/ChZMynxJoETKcIuGAyHA7iceNckvlGIsFvWDB6sgMGpiUClIBLhFfY93SBBooFUliJv 4uttpYEMMAp8bVhiaYupXPvN01ksRhQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718372161; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XFRnd/qhxpPmZMYDORcvPtacx3rDNVTHZIGudbT0oRI=; b=Mrb2B2sD3qoVGMzRwOYOOodGnHneFgSgyCmvwvy0WO/uBeFmBYnT7Xz6gv1vRx0e/VWKMi rcZJcxWeh2Q+//Bg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 33D2C13AB1; Fri, 14 Jun 2024 13:36:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GPtPC0FHbGavPwAAD6G6ig (envelope-from ); Fri, 14 Jun 2024 13:36:01 +0000 From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, daniel@ffwll.ch, lucas.demarchi@intel.com, rodrigo.vivi@intel.com, jani.nikula@linux.intel.com, ray.huang@amd.com, christian.koenig@amd.com, kraxel@redhat.com, airlied@redhat.com, suijingfeng@loongson.cn Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Thomas Zimmermann Subject: [PATCH 6/6] drm/xe: Replace ttm_bo_kmap() with ttm_bo_vmap() Date: Fri, 14 Jun 2024 15:22:00 +0200 Message-ID: <20240614133556.11378-7-tzimmermann@suse.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240614133556.11378-1-tzimmermann@suse.de> References: <20240614133556.11378-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: 96C9E20542 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCPT_COUNT_TWELVE(0.00)[16]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_TO(0.00)[linux.intel.com,kernel.org,gmail.com,ffwll.ch,intel.com,amd.com,redhat.com,loongson.cn]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email,suse.de:dkim]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received,2a07:de40:b281:104:10:150:64:97:from]; R_RATELIMIT(0.00)[to_ip_from(RLau4tukfh38qp3nirdnk14qe9)]; RCVD_VIA_SMTP_AUTH(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Use the newer ttm_bo_vmap() instead of ttm_bo_kmap(). The new interface uses struct iomap_map, which helps with pointer setup and memcpy() ops. Removes a TODO item and quite a bit of workarounds from the code. Signed-off-by: Thomas Zimmermann --- .../compat-i915-headers/gem/i915_gem_object.h | 17 +++------- drivers/gpu/drm/xe/xe_bo.c | 32 ++++--------------- drivers/gpu/drm/xe/xe_bo_types.h | 2 -- 3 files changed, 10 insertions(+), 41 deletions(-) diff --git a/drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_object.h b/drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_object.h index 777c20ceabab1..25ae56d700431 100644 --- a/drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_object.h +++ b/drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_object.h @@ -34,28 +34,19 @@ static inline bool i915_gem_object_is_userptr(const struct xe_bo *bo) static inline int i915_gem_object_read_from_page(struct xe_bo *bo, u32 ofs, u64 *ptr, u32 size) { - struct ttm_bo_kmap_obj map; - void *src; - bool is_iomem; + struct iosys_map src; int ret; ret = xe_bo_lock(bo, true); if (ret) return ret; - ret = ttm_bo_kmap(&bo->ttm, ofs >> PAGE_SHIFT, 1, &map); + ret = ttm_bo_vmap(&bo->ttm, ofs, size, &src); if (ret) goto out_unlock; + iosys_map_memcpy_from(ptr, &src, ofs & ~PAGE_MASK, size); + ttm_bo_vunmap(&bo->ttm, &src); - ofs &= ~PAGE_MASK; - src = ttm_kmap_obj_virtual(&map, &is_iomem); - src += ofs; - if (is_iomem) - memcpy_fromio(ptr, (void __iomem *)src, size); - else - memcpy(ptr, src, size); - - ttm_bo_kunmap(&map); out_unlock: xe_bo_unlock(bo); return ret; diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index a98d857ff1e5a..6158e1a959cd4 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -1888,10 +1888,6 @@ dma_addr_t xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size) int xe_bo_vmap(struct xe_bo *bo) { - void *virtual; - bool is_iomem; - int ret; - xe_bo_assert_held(bo); if (!(bo->flags & XE_BO_FLAG_NEEDS_CPU_ACCESS)) @@ -1900,32 +1896,16 @@ int xe_bo_vmap(struct xe_bo *bo) if (!iosys_map_is_null(&bo->vmap)) return 0; - /* - * We use this more or less deprecated interface for now since - * ttm_bo_vmap() doesn't offer the optimization of kmapping - * single page bos, which is done here. - * TODO: Fix up ttm_bo_vmap to do that, or fix up ttm_bo_kmap - * to use struct iosys_map. - */ - ret = ttm_bo_kmap(&bo->ttm, 0, bo->size >> PAGE_SHIFT, &bo->kmap); - if (ret) - return ret; - - virtual = ttm_kmap_obj_virtual(&bo->kmap, &is_iomem); - if (is_iomem) - iosys_map_set_vaddr_iomem(&bo->vmap, (void __iomem *)virtual); - else - iosys_map_set_vaddr(&bo->vmap, virtual); - - return 0; + return ttm_bo_vmap(&bo->ttm, 0, bo->size, &bo->vmap); } static void __xe_bo_vunmap(struct xe_bo *bo) { - if (!iosys_map_is_null(&bo->vmap)) { - iosys_map_clear(&bo->vmap); - ttm_bo_kunmap(&bo->kmap); - } + if (iosys_map_is_null(&bo->vmap)) + return; + + ttm_bo_vunmap(&bo->ttm, &bo->vmap); + iosys_map_clear(&bo->vmap); } void xe_bo_vunmap(struct xe_bo *bo) diff --git a/drivers/gpu/drm/xe/xe_bo_types.h b/drivers/gpu/drm/xe/xe_bo_types.h index 86422e113d396..5cba681ba73c2 100644 --- a/drivers/gpu/drm/xe/xe_bo_types.h +++ b/drivers/gpu/drm/xe/xe_bo_types.h @@ -42,8 +42,6 @@ struct xe_bo { struct drm_mm_node ggtt_node; /** @vmap: iosys map of this buffer */ struct iosys_map vmap; - /** @ttm_kmap: TTM bo kmap object for internal use only. Keep off. */ - struct ttm_bo_kmap_obj kmap; /** @pinned_link: link to present / evicted list of pinned BO */ struct list_head pinned_link; #ifdef CONFIG_PROC_FS