Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3462994rwi; Sun, 16 Oct 2022 11:19:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5VhZXgINIHvz5Fo1Y4umuZLoQlOa9tHJ2JVD2MNtKVEJI6eLPirMnddn4YZZ4wKhRAegXM X-Received: by 2002:a17:907:5ce:b0:730:bae0:deb with SMTP id wg14-20020a17090705ce00b00730bae00debmr6030339ejb.181.1665944383699; Sun, 16 Oct 2022 11:19:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665944383; cv=none; d=google.com; s=arc-20160816; b=Dt2eDds3TZ4WjLKJJqlAVnV8OJoCTI45Luz+da4gWdjLEe+MEogi1K68eNQWoatmKw dIgqT16HGA6Z8eYkFgxGLX2NKtzDVI6T6ylb3TqB1EBQsC6C6yT3EPb3SxlUW+l8RB9k oCs7q3CJb/+xoJChHekuilUIyWLRFSSsMmPRJ4v0rBAUY+ZMO1L6wa7o6+RlHWcHG+4W OEAYeN9Gco0eNHzBc/emjgyp2uIerLW1Cjt+zXAdQUru1J+cQhHp7lN8Yr/WruklXFxQ sKgSnJjfX2rMaeoM7Cpn1kE1PJ5BpeYwvlRAAVBMXBFAx8/AdJ/Khscc3PK9a4ei9A5U 56Xw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vKbxvFs7idvHnkpYGCCi9EPfdsQNoN5vylEOpYCziO4=; b=C+V48HA1K6fB5gYESeZ3iVPCQdW3BC2tuLzOyarwUP4ZFCLqYsGxcVgb4Qs91g/Gim j2qjbuwsNI41ccjVUYhGT7wRDZYh0NQSzqvyI6HR8/T49wXL451H4exg1DL5YRSIPzbT BTNo5J67aXuYvpdNr46fPcvCtHUfzHWx110rDE9dcL+eJpyt2ls2r7TPvO+Fe7OUbY+d euYF0oCGM5rlHiOzx1fPxoief5ywdNDKjvWse77QmMtilOl5svrQShxvvSRrlPNV5Ojk Rw8q2tmulBNzjxmalqudOBrCWRABBCZqvrxWgYyicKr+wL4ggGQC1gy6i3wDLv6bf0i5 KsBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HNMiFYEP; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc13-20020a170907168d00b0078de57da349si4694515ejc.463.2022.10.16.11.19.18; Sun, 16 Oct 2022 11:19:43 -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=@gmail.com header.s=20210112 header.b=HNMiFYEP; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbiJPSKN (ORCPT + 99 others); Sun, 16 Oct 2022 14:10:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbiJPSJ6 (ORCPT ); Sun, 16 Oct 2022 14:09:58 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04EAB17AA4 for ; Sun, 16 Oct 2022 11:09:54 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id j16so15174522wrh.5 for ; Sun, 16 Oct 2022 11:09:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vKbxvFs7idvHnkpYGCCi9EPfdsQNoN5vylEOpYCziO4=; b=HNMiFYEP8MVS/aXSpnXOvDvpVc4U0b1DeNUL4mTpjwjXRlCdqzIVEWJfRjuaPWVmEF Ny2iLROeymv7JJNx40kvpa4FBTAG6fvUjggzyZDfjYwVjVNwBX4tTk/vs+1NiQMELEix UIydb9a85ZKjmX1QssDmIsXamzsWB6Zy3Ta0EmC6QCjWCZsX6R7Nb+hnSadGyxbdgeO4 kdW3J++u3bcT4ChnwBYZ5qt/wSejvQXew907KeM4TrNae3qeW4GWFW/7BtkA/ZApC3Dj /Lcb2B2XsO43dg7Qlm2KM/9Hii3JBTQymbvH8T848CT+xL0bKCkpB2SnK8AkOb+Mp7/9 mBdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vKbxvFs7idvHnkpYGCCi9EPfdsQNoN5vylEOpYCziO4=; b=vJ9TW4U3UuG8EX+G8E6bvCVeYWmJDk1Y8cpv0+HlFEeDo7lCIKuJaYhONO5vKgjLL9 RI1uxyqEyKtVqcDKTDudYLLlCxx075W+Dip/XSPOXQdghYeaq1pvMO0qIDai5datKAjJ yKN5FdqbZJ1Ye0CvyzdN2ny0QtiS4RrxO42l0euxqKWD4tDJXs5qx/U/fDbesNSBZM6h 4MahQQu14iUPwcWkZ9xBFkM52K/xv4i3oIu9BSxC26jN/QRZKh5HVt4iBh5hMFbduf/m A0fRW8/cVD8fjRdyTX+oxaWzFjKqHpjHqTf+itok6I7UNQEYz7lfdBOekMqeGxIDZ4i7 dvWg== X-Gm-Message-State: ACrzQf3mmjDiVZicKA2Z+Xcc51GT093+tC2fxsH4KSmH6sm8k4iModE6 X7eKVhBgkH8DyBCjp/xJh7w= X-Received: by 2002:a05:6000:178a:b0:22e:d215:4099 with SMTP id e10-20020a056000178a00b0022ed2154099mr4281979wrg.79.1665943793302; Sun, 16 Oct 2022 11:09:53 -0700 (PDT) Received: from localhost.localdomain (host-95-250-231-122.retail.telecomitalia.it. [95.250.231.122]) by smtp.gmail.com with ESMTPSA id v9-20020a05600c444900b003c6f8d30e40sm156225wmn.31.2022.10.16.11.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 11:09:52 -0700 (PDT) From: "Fabio M. De Francesco" To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Zhenyu Wang , Zhi Wang , Matthew Auld , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , =?UTF-8?q?Christian=20K=C3=B6nig?= , Matt Roper , John Harrison , Daniele Ceraolo Spurio , Lucas De Marchi , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gvt-dev@lists.freedesktop.org Cc: "Fabio M. De Francesco" , "Venkataramanan, Anirudh" , Ira Weiny Subject: [RESEND PATCH 3/3] drm/i915/gem: Replace kmap() with kmap_local_page() Date: Sun, 16 Oct 2022 20:09:38 +0200 Message-Id: <20221016180938.17403-4-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221016180938.17403-1-fmdefrancesco@gmail.com> References: <20221016180938.17403-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 kmap() is being deprecated in favor of kmap_local_page(). There are two main problems with kmap(): (1) It comes with an overhead as mapping space is restricted and protected by a global lock for synchronization and (2) it also requires global TLB invalidation when the kmap’s pool wraps and it might block when the mapping space is fully utilized until a slot becomes available. With kmap_local_page() the mappings are per thread, CPU local, can take page faults, and can be called from any context (including interrupts). It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, the tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and are still valid. Since its use in i915/gem is safe everywhere, it should be preferred. Therefore, replace kmap() with kmap_local_page() in i915/gem. Instead of open-coding local map + memcpy + local unmap, use memcpy_to_page() in a suited call site. Cc: "Venkataramanan, Anirudh" Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 6 ++---- drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c index 4eed3dd90ba8..2bc6ab9964ff 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -640,16 +640,14 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_private *dev_priv, do { unsigned int len = min_t(typeof(size), size, PAGE_SIZE); struct page *page; - void *pgdata, *vaddr; + void *pgdata; err = aops->write_begin(file, file->f_mapping, offset, len, &page, &pgdata); if (err < 0) goto fail; - vaddr = kmap(page); - memcpy(vaddr, data, len); - kunmap(page); + memcpy_to_page(page, 0, data, len); err = aops->write_end(file, file->f_mapping, offset, len, len, page, pgdata); diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c index 3ced9948a331..bb25b50b5688 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c @@ -153,7 +153,7 @@ static int check_partial_mapping(struct drm_i915_gem_object *obj, intel_gt_flush_ggtt_writes(to_gt(i915)); p = i915_gem_object_get_page(obj, offset >> PAGE_SHIFT); - cpu = kmap(p) + offset_in_page(offset); + cpu = kmap_local_page(p) + offset_in_page(offset); drm_clflush_virt_range(cpu, sizeof(*cpu)); if (*cpu != (u32)page) { pr_err("Partial view for %lu [%u] (offset=%llu, size=%u [%llu, row size %u], fence=%d, tiling=%d, stride=%d) misalignment, expected write to page (%llu + %u [0x%llx]) of 0x%x, found 0x%x\n", @@ -171,7 +171,7 @@ static int check_partial_mapping(struct drm_i915_gem_object *obj, } *cpu = 0; drm_clflush_virt_range(cpu, sizeof(*cpu)); - kunmap(p); + kunmap_local(cpu); out: i915_gem_object_lock(obj, NULL); @@ -249,7 +249,7 @@ static int check_partial_mappings(struct drm_i915_gem_object *obj, intel_gt_flush_ggtt_writes(to_gt(i915)); p = i915_gem_object_get_page(obj, offset >> PAGE_SHIFT); - cpu = kmap(p) + offset_in_page(offset); + cpu = kmap_local_page(p) + offset_in_page(offset); drm_clflush_virt_range(cpu, sizeof(*cpu)); if (*cpu != (u32)page) { pr_err("Partial view for %lu [%u] (offset=%llu, size=%u [%llu, row size %u], fence=%d, tiling=%d, stride=%d) misalignment, expected write to page (%llu + %u [0x%llx]) of 0x%x, found 0x%x\n", @@ -267,7 +267,7 @@ static int check_partial_mappings(struct drm_i915_gem_object *obj, } *cpu = 0; drm_clflush_virt_range(cpu, sizeof(*cpu)); - kunmap(p); + kunmap_local(cpu); if (err) return err; -- 2.37.1