From patchwork Mon Oct 17 09:37:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 3338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1354796wrs; Mon, 17 Oct 2022 02:42:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4zF88+pQEk2XTwB4EQ/fdGnnaYaTa9FivhtPj+7u3HAHZhKyK3dNbakWKUEYT7LNuG6YSK X-Received: by 2002:a17:90a:c09:b0:20d:7820:2e60 with SMTP id 9-20020a17090a0c0900b0020d78202e60mr31013075pjs.180.1665999731919; Mon, 17 Oct 2022 02:42:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665999731; cv=none; d=google.com; s=arc-20160816; b=Y8fkcDxKviZnhQh5l8OBuO0pgCG1iLaal+enSqsnTES+ilwDr0UA4WywC+yzcXa/YM edVwOgIN54MMIPd8BVM3kWKuYn4d40ew/cHLZNUXIo7vbABigpibZvJLcpo6qxavHoJB FolO09KNii7pVKMrJnfVjt/UDT973IoHCtJCZhNb0Yo5bz9w7mncrF58hrU7rlGeaZAO oyC0f9yF5IBtEQVsjwvSxhcnlgVFHyjF+C9JQEHPGFqYd0QBh8bsX9DnKaul8UQmHr5Z kjVXcvYzAiZR/g5KpBNMS4hDW5RM4faMhpHqVW4kR4qfJPQ4f93l6IqyLtUmrDCwJW0i WHBQ== 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=7og+DTe91fClZT7f2tVC9darcTNDjgHZDfbwFHs7768=; b=LyXyopc0Rd3m9QG+3jgnNd3I+Qg0cQvSFHEMdjI/qVYz6qXhGh8lg/j/uwmmwKt1mP SMbydyxP9eh4/8HgNniX1CIphZvHlrgM0reFf8pRMQnyDG27MGJ6Lts0JTmIq7Yp2hgy WBvZm5oNGVQ57UE6LQhw98NRb4xZeOjLiEbYvk9ipQAEHHHpSqVnSbI24QJGgtGghHgt Gl5eM8Z9To2O1q8/6TASP2mEgmAeBfdD9HhSZhqMbyYVVaZt9jxcWkVKj4EnbGc6Mzuj G4hEl3a5MlxhR4EQAwTAktJH1yysP095TzcKLIA6vPJ4aIlBQJgVNYliM/uCTJm38fV5 nx1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=byAIm+CZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 69-20020a630448000000b0046af6471adasi12082629pge.282.2022.10.17.02.41.58; Mon, 17 Oct 2022 02:42:11 -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=@intel.com header.s=Intel header.b=byAIm+CZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231276AbiJQJcf (ORCPT + 99 others); Mon, 17 Oct 2022 05:32:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbiJQJc2 (ORCPT ); Mon, 17 Oct 2022 05:32:28 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADDC941D03 for ; Mon, 17 Oct 2022 02:32:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999147; x=1697535147; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tiW6Fpm0hVgB6aQj9aJLze7KS0YilKpmQTotRlfBNY0=; b=byAIm+CZyqpTzAvFjOrdoEfFq1gPFEXGD2l04JB16wzJKzd0NHZoP/GN JiUy9STG+cSEMWAIJa1qAluPP11aa6hqBQTno6G2aAehNqhctoEVWV19u qj1o3pfk55vYhaVKVaC3pAgCkvuYbXHGIKfcbozNTASnLYv/YH8TGvEhD k0bIGc7W/69qubuimCi8e8Xbv4zRAPUUJz0U2tPUXhLXi5XMEm23gfj5+ 8DJCziH9HnNuMAeNGdQ9FhA40uGmMuEK/uyBuBMVAjBW9yo5wq8uw+xaJ lJviY/ZAJB8m8PKkT5Uro5P8aytCrtwG9ybytQdwMrvzSwWuvEaawTTUh w==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741556" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741556" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 02:32:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431213" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431213" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:32:23 -0700 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?utf-8?q?Christian_K=C3=B6nig?= , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu , Dave Hansen Subject: [PATCH 1/9] drm/i915: Use kmap_local_page() in gem/i915_gem_object.c Date: Mon, 17 Oct 2022 17:37:17 +0800 Message-Id: <20221017093726.2070674-2-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> References: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746927334747460565?= X-GMAIL-MSGID: =?utf-8?q?1746927334747460565?= From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1]. The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption. There're 2 reasons why i915_gem_object_read_from_page_kmap() doesn't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe for CPU hotplug when preemption is not disabled. In drm/i915/gem/i915_gem_object.c, the function i915_gem_object_read_from_page_kmap() calls drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global and any issue with cpu's being added or removed can be handled safely. 2. Any context switch caused by preemption or sleep (pagefault may cause sleep) doesn't affect the validity of local mapping. Therefore, i915_gem_object_read_from_page_kmap() is a function where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). And remove the redundant variable that stores the address of the mapped page since kunmap_local() can accept any pointer within the page. [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message. --- drivers/gpu/drm/i915/gem/i915_gem_object.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c b/drivers/gpu/drm/i915/gem/i915_gem_object.c index 369006c5317f..a0072abed75e 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_object.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c @@ -413,17 +413,15 @@ void __i915_gem_object_invalidate_frontbuffer(struct drm_i915_gem_object *obj, static void i915_gem_object_read_from_page_kmap(struct drm_i915_gem_object *obj, u64 offset, void *dst, int size) { - void *src_map; void *src_ptr; - src_map = kmap_atomic(i915_gem_object_get_page(obj, offset >> PAGE_SHIFT)); - - src_ptr = src_map + offset_in_page(offset); + src_ptr = kmap_local_page(i915_gem_object_get_page(obj, offset >> PAGE_SHIFT)) + + offset_in_page(offset); if (!(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_READ)) drm_clflush_virt_range(src_ptr, size); memcpy(dst, src_ptr, size); - kunmap_atomic(src_map); + kunmap_local(src_ptr); } static void From patchwork Mon Oct 17 09:37:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 3339 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1354811wrs; Mon, 17 Oct 2022 02:42:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6oEYhAYK1KsfY4QjqY+UyHSyp4CpCu+HmBshbrt5enO+cZ/QhepKphdFQSR4+EFDGVN86R X-Received: by 2002:a63:2352:0:b0:46b:1dac:bc83 with SMTP id u18-20020a632352000000b0046b1dacbc83mr10263025pgm.98.1665999734422; Mon, 17 Oct 2022 02:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665999734; cv=none; d=google.com; s=arc-20160816; b=mlZ2aztk27Do1oZMzxM8xpi1NHQ/Qs8EBMb7lupUnHlG4S25qZmKoz7UdMF/1CR2wc yIUcNKSPsp3wXKXRhvhgd27VzOOqDBkYQbTpcANT2TCXiInIDGqek4xhz4/dyHpFXSe+ O8wVuA9Pr9rJ7G+1UUs710ekFSPGB52a85c3zxnFPXOHuxsGnpQgAma0s/FPutCPkPRc wXwKchbS5Gr1lPH1CUcLhGgl4JHZC+WNDiLHXR/eVdMG/2evV7GBFKSA+fTOe/7esHnK 0IdRz8WCGKbvO9+6fUKBg5+C9ZQmfmKTz4y50KT9Q5fh5IYzbmmHEKKp5dG6KNLj20qj T2ww== 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=Wpc9T9P4TinzjkXSNtI/VWO+MDWW+pZ8aBO/u+tmaks=; b=MgIMiWqFo2qVonIMpzHUEJVug26HEMzONhexsf/LZ8MBHvF/44H9lPL/Z4L7Qs0vNt zzp6sZTZggSWVCD954XWqYIRRfYjbCk5pHJ8nz44nWS1/gIjijjtzOFJGO120TSdloyD IGh7PdX/CQifFFz1Ooh2uhW3eJw+4/cuX561admidk89B715B5j9YAeYzHkklzfUK/6b FdC2b9BrT64G/L7EJ3uv9+E+x/fEnEbxrVGq/mslEDC845NICXHC2BIVXs4qAyegGO+C V3huRmdxn1ZhkBepjOS6ez+6R40DzgQM38xGJmJ/hOoed8edqpa5eN+mwX/u79qa8Efs cpZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="F3/6TfLJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y124-20020a636482000000b0042bb607f75esi10986406pgb.284.2022.10.17.02.42.02; Mon, 17 Oct 2022 02:42:14 -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=@intel.com header.s=Intel header.b="F3/6TfLJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230047AbiJQJcp (ORCPT + 99 others); Mon, 17 Oct 2022 05:32:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230249AbiJQJcc (ORCPT ); Mon, 17 Oct 2022 05:32:32 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF8484DB1B for ; Mon, 17 Oct 2022 02:32:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999151; x=1697535151; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L0klkS76Kt8Hk/6E4tsClEGhD8s9Fs2w8vteQwCBE8U=; b=F3/6TfLJzL35a+a164pxBFAFgFAIRQKvmyBY5u6X8V5b2WfUFO+IqwNd t6nUkcRPMPdqLmUWJcKz3/MGF0yug1+MCybH0YMKFUkDh/riaa6/DY7sd FMhf5dj9cYbFIAXe3Ov7aDrlxxcI69egrFhP9Xz2KinFzujraqsf2WyEg 2NrnWjnIv3UTIAkc4dyLsGKNGEFTkwWt/DCjgfRVYlibKxH1obKRHBKHz YK7B42adFL7E8sP673f3qV4aVqkrO8o4wdu/cCc3CvgMqNjbu1YujM1iP WNcNn4Lvbpty/VS2HDOLQi18lxKkZJHXGpdQmjH5uQonTAIHxFDtur3lY w==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741570" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741570" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 02:32:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431229" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431229" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:32:27 -0700 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?utf-8?q?Christian_K=C3=B6nig?= , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu , Dave Hansen Subject: [PATCH 2/9] drm/i915: Use kmap_local_page() in gem/i915_gem_pyhs.c Date: Mon, 17 Oct 2022 17:37:18 +0800 Message-Id: <20221017093726.2070674-3-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> References: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746927337803309787?= X-GMAIL-MSGID: =?utf-8?q?1746927337803309787?= From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1]. The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption. In drm/i915/gem/i915_gem_phys.c, the functions i915_gem_object_get_pages_phys() and i915_gem_object_put_pages_phys() don't need to disable pagefaults and preemption for mapping because of these 2 reasons: 1. The flush operation is safe for CPU hotplug when preemption is not disabled. In drm/i915/gem/i915_gem_object.c, the functions i915_gem_object_get_pages_phys() and i915_gem_object_put_pages_phys() calls drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global and any issue with cpu's being added or removed can be handled safely. 2. Any context switch caused by preemption or sleep (pagefault may cause sleep) doesn't affect the validity of local mapping. Therefore, i915_gem_object_get_pages_phys() and i915_gem_object_put_pages_phys() are two functions where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message. --- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_phys.c b/drivers/gpu/drm/i915/gem/i915_gem_phys.c index 0d0e46dae559..d602ba19ecb2 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_phys.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_phys.c @@ -66,10 +66,10 @@ static int i915_gem_object_get_pages_phys(struct drm_i915_gem_object *obj) if (IS_ERR(page)) goto err_st; - src = kmap_atomic(page); + src = kmap_local_page(page); memcpy(dst, src, PAGE_SIZE); drm_clflush_virt_range(dst, PAGE_SIZE); - kunmap_atomic(src); + kunmap_local(src); put_page(page); dst += PAGE_SIZE; @@ -114,10 +114,10 @@ i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj, if (IS_ERR(page)) continue; - dst = kmap_atomic(page); + dst = kmap_local_page(page); drm_clflush_virt_range(src, PAGE_SIZE); memcpy(dst, src, PAGE_SIZE); - kunmap_atomic(dst); + kunmap_local(dst); set_page_dirty(page); if (obj->mm.madv == I915_MADV_WILLNEED) From patchwork Mon Oct 17 09:37:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 3342 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1355615wrs; Mon, 17 Oct 2022 02:44:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6MN/IWzS8wn165lSQVIfqIivI1kOxTj1xG8y/btPLrIajmH4dZfMZtzRHKFSIZ1dQaXyXS X-Received: by 2002:a17:907:72c1:b0:783:34ce:87b9 with SMTP id du1-20020a17090772c100b0078334ce87b9mr7889423ejc.115.1665999889583; Mon, 17 Oct 2022 02:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665999889; cv=none; d=google.com; s=arc-20160816; b=aEIz5t3oj4/qZE0ZWS8QF7XY21YI12/Q0IZbeDae3l2869MpHmwQ9W/BIs+y/n3yhO DHIf8iRbdLaGa5PeiTGER2lErYbPav0NVyJ/F6LIHmjZpcWY0YEC+/y54tV+eZLXncJ7 5S1HPMSFfHkwQrHPmWGVXrScd0za4TWATc/hIwpaZiJHbSO+ovHfpbkosEd3ciTqhsyQ JVxF0Qz0u9AmyaifHBGg6bS6sP8q4X9QABa5lD95jZZPK693sPI79CdmQXdwLfXSy3Vx SoKcOW4LiuSh4pK0IiCWTIVwIZ5FVsecIl3tUs7KT6THPOkNsudSX5lzeEnVYNRjOmT8 XP9g== 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=SMqyV/xiiv2ymvvQ+g3nRimtjyZxLbjBMv3s9DpO6rM=; b=jAi+h1DcvF6uNIqzo8K5LUvamDovCntOFH3jcMDxKSMX9uOZyIZGsMSzScnzTz6P0a Qj//r3A7AWPGyrlfDqiL5IOb6hTpeoRas711HDXQ8Ndwu5n712jhpVM0ZzoA5AQzSdcs 2j5McZwF96dV5F6DUqQumO/kTFx6siz3QfsYrEsk10wHAhxRDV1uEKTtPXb6j1Al6f7j lpWb0TgFSX1qo//AkyokYZFhGP9Lq8x2YQkqaKBGwfgDWlE+L5ndt/ULU6nSGkX58DR1 L6X0JawQAklLH2qb5LEyIzYIZHq+dleCMJUoFuvcjdujwenWtMPXFf8/dxv5xU0CgrUP Qd9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ul4mgQ2P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k20-20020a170906159400b0077bab1f707esi7276513ejd.159.2022.10.17.02.44.24; Mon, 17 Oct 2022 02:44:49 -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=@intel.com header.s=Intel header.b=Ul4mgQ2P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230490AbiJQJcs (ORCPT + 99 others); Mon, 17 Oct 2022 05:32:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231191AbiJQJcm (ORCPT ); Mon, 17 Oct 2022 05:32:42 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D86752802 for ; Mon, 17 Oct 2022 02:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999155; x=1697535155; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h0hmpKyvdxb2sKw8lROgYrffCQobTfXddN7YtzQHU7M=; b=Ul4mgQ2PEWvaEHTyCXo+CpuOqncgpmy7bqoqyJLIaDvc0LS0uGxTBa7q xGSfbEPWNDAcbn1EEklVi0+OMzGQrUCwC0UJsMs2Y3UJXHXkmcmWjbf+3 q4h6zIyS//A0GM0phFQyG5AK8OTNT+c2epftNrFUT3LZX7miEC78ZOl8P kEIDverLDm6dOPMNvmufC2NmtxTFfT+m8RjLr0K2qUO+960SQ2KpFAfc3 KFJMkB8dudpBdwUaa/MAiNouKZvB0bJAT3yCKYL03HjtWraAlISk/hzER tRzANd8yFzjNhkAu2ReA1klGptaBniNjOwGSElWB7WE4V+sg34MFboUHz Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741585" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741585" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 02:32:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431242" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431242" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:32:31 -0700 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?utf-8?q?Christian_K=C3=B6nig?= , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu Subject: [PATCH 3/9] drm/i915: Use kmap_local_page() in gem/i915_gem_shmem.c Date: Mon, 17 Oct 2022 17:37:19 +0800 Message-Id: <20221017093726.2070674-4-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> References: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746927500561095431?= X-GMAIL-MSGID: =?utf-8?q?1746927500561095431?= From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1]. The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption. In drm/i915/gem/i915_gem_shmem.c, the function shmem_pwrite() need to disable pagefault to eliminate the potential recursion fault[2]. But here __copy_from_user_inatomic() doesn't need to disable preemption and local mapping is valid for sched in/out. So it can use kmap_local_page() / kunmap_local() with pagefault_disable() / pagefault_enable() to replace atomic mapping. [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com [2]: https://patchwork.freedesktop.org/patch/295840/ Suggested-by: Ira Weiny Signed-off-by: Zhao Liu Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco --- Suggested by credits: Ira: Referred to his suggestions about keeping pagefault_disable(). --- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c index f42ca1179f37..e279a3e30c02 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -472,11 +472,13 @@ shmem_pwrite(struct drm_i915_gem_object *obj, if (err < 0) return err; - vaddr = kmap_atomic(page); + vaddr = kmap_local_page(page); + pagefault_disable(); unwritten = __copy_from_user_inatomic(vaddr + pg, user_data, len); - kunmap_atomic(vaddr); + pagefault_enable(); + kunmap_local(vaddr); err = aops->write_end(obj->base.filp, mapping, offset, len, len - unwritten, page, data); From patchwork Mon Oct 17 09:37:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 3340 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1355072wrs; Mon, 17 Oct 2022 02:43:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6U20QQbongpG2tjaxLrK+Wk586GX60CV1Gy21wsbzH7wrBtKZ5pBWwe3fzIveUvLk+Bq1O X-Received: by 2002:a63:4243:0:b0:439:2031:be87 with SMTP id p64-20020a634243000000b004392031be87mr10024853pga.592.1665999786600; Mon, 17 Oct 2022 02:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665999786; cv=none; d=google.com; s=arc-20160816; b=ISWtVhzyAiMi/YFMBYAIeEkM+xfQIukWsVUeqg4mVtluCuPekEKEYf4LtD4u/hLgKB D5qnlzLmN962rh+fDYj4gsNAZpwYGtkj/N2CTNgNjZhCCLq2qUue9zflggDSkJHgvwJw RnA5/fZAGSYtrjh/FTbP+fUdi6S5k08Mrh4g2IiP3qPVUWEAnZNYsJeqOFDP4oegsT0h YfC2h5GBSuexOyAWH3+A73g0Xfu2Z2mOjJxio/2RWx1lHXlJYkQvRpeEtwqRj05c2PJE oF7/XG4ZTt36Yt3JuP140T7BD+ruv8AhMbqK5ayeufxAmg71tqrOTBn62w1n7T0rizi0 YfQQ== 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=+3g8z+0RoiVz2xwg8u61rBprvqD0EXGgXxSlEkSy7j4=; b=dRnpg0qFQc0A9oEC4TEXO7G1D8R/jAUkxGMfGOwafHsOOieEEO66oj77QNpWk7nGS2 bc5tgrSrNmADsDFXVUTanmvxc22EZ+g9THYT1qby0kxF6HlnJ1PfKakXWz8pQ9x+AFoj c+j6HWmbF9Wk7ibmmx232TiCChaynLzmaCmc2GiqXy+cWAbqg3ZlFUbhZqNFhJrPn6dQ kGSfp/k92HPyrWkjrPJiyi74JMCdO/Nms38H75cetnupRCL+d+PpkTGu9hoxUvGJivFv 4avrm84XSkd9Eq5FEsuqNifPDj1Vb5GT3OHE8fvRUQzwYoyjyLaMlEXjFfvSVRhi5NJX XwYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZBVwtOMG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o3-20020a655203000000b004639c679346si10956294pgp.837.2022.10.17.02.42.53; Mon, 17 Oct 2022 02:43:06 -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=@intel.com header.s=Intel header.b=ZBVwtOMG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231312AbiJQJcw (ORCPT + 99 others); Mon, 17 Oct 2022 05:32:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231317AbiJQJcn (ORCPT ); Mon, 17 Oct 2022 05:32:43 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C95B58DD6 for ; Mon, 17 Oct 2022 02:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999160; x=1697535160; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZXOTrqnB1S2hiIrW6AdSeUKTfgzUpr1fFCYC+QaCffw=; b=ZBVwtOMGjrVr/Cz2gSBb3HB2GjVyFD7+JWmQLxCVebjsKl9DAgl7YpPt 3aMUVr4eAKuZFIVzGNxsy0Gv2mOr3nF+hcrazTVmdiQkVmHlyFCyeZet+ go+nOOlgUjQeGjbp5ioISj6r1FrAgAlN+HEGEeun8O+AiAQXNkLA99cv4 VpzaMc6Nzwe/WCTlyS3XBXIG0yKjaNK6oIcbPoFmckcs/K/5vZOC0PS8U BRHsMo5Ze2MQdZMksRnSJ6eIn9f5whqe1nWMeujyJiwxCiA+6o+FiKhsF QHXSG6ED1SuY2J62KZg3FwJc4Murj2fNefBEsek8n94BYaYkigU3EXRnB Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741593" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741593" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 02:32:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431262" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431262" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:32:35 -0700 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?utf-8?q?Christian_K=C3=B6nig?= , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu , Dave Hansen Subject: [PATCH 4/9] drm/i915: Use kmap_local_page() in gem/selftests/huge_pages.c Date: Mon, 17 Oct 2022 17:37:20 +0800 Message-Id: <20221017093726.2070674-5-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> References: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746927392423508720?= X-GMAIL-MSGID: =?utf-8?q?1746927392423508720?= From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1]. The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption. In drm/i915/gem/selftests/huge_pages.c, function __cpu_check_shmem() mainly uses mapping to flush cache and check the value. There're 2 reasons why __cpu_check_shmem() doesn't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe for CPU hotplug when preemption is not disabled. Function __cpu_check_shmem() calls drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global and any issue with cpu's being added or removed can be handled safely. 2. Any context switch caused by preemption or sleep (pagefault may cause sleep) doesn't affect the validity of local mapping. Therefore, __cpu_check_shmem() is a function where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message. --- drivers/gpu/drm/i915/gem/selftests/huge_pages.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c index c570cf780079..6f4efe905105 100644 --- a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c +++ b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c @@ -1022,7 +1022,7 @@ __cpu_check_shmem(struct drm_i915_gem_object *obj, u32 dword, u32 val) goto err_unlock; for (n = 0; n < obj->base.size >> PAGE_SHIFT; ++n) { - u32 *ptr = kmap_atomic(i915_gem_object_get_page(obj, n)); + u32 *ptr = kmap_local_page(i915_gem_object_get_page(obj, n)); if (needs_flush & CLFLUSH_BEFORE) drm_clflush_virt_range(ptr, PAGE_SIZE); @@ -1030,12 +1030,12 @@ __cpu_check_shmem(struct drm_i915_gem_object *obj, u32 dword, u32 val) if (ptr[dword] != val) { pr_err("n=%lu ptr[%u]=%u, val=%u\n", n, dword, ptr[dword], val); - kunmap_atomic(ptr); + kunmap_local(ptr); err = -EINVAL; break; } - kunmap_atomic(ptr); + kunmap_local(ptr); } i915_gem_object_finish_access(obj); From patchwork Mon Oct 17 09:37:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 3360 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1361860wrs; Mon, 17 Oct 2022 03:04:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7A7ZJRqBM8V6oIbVR6h93ixI+1fQYuK1hpoDwMyhdhMbSgVnzVGmHx2fpBuKOrGrlu4P7g X-Received: by 2002:a17:903:189:b0:183:7473:57f1 with SMTP id z9-20020a170903018900b00183747357f1mr10672857plg.28.1666001095638; Mon, 17 Oct 2022 03:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666001095; cv=none; d=google.com; s=arc-20160816; b=LjcPYjB25rfmFsF+PfH5xJK89BfeZcValI/wQFwj0Y5IRDykGHkbR5JAfvKxEGVb35 JegSS/aHdLbj6iIAMjjgdhVHuzRS4EIvfPAeUh8rH9pYJPrDHKBly/ai5PIwHO6O4Fwb 90bAj1KavQGS5Bp1sSIzEhh8xsfBLdN5CjQ04CP2VgVUKJF3PsJSIkvmIYnIRLXPhtIY 7MdELmy3bhvOEJVHuRAjGJWlJ11K882xalOVmE8DriopY8t8WAvnIQ3RL9FiRnItiB9u hOO1ujDAK+wNjL6JiWrmh/iXZNd22aVNEaNJ8qoC1Ij+pfG++N7e8rbvQLxEZDUBm6o3 EkCw== 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=jSBMLiMjX5wwR6oTvo8wjcHxq/xfc2sQ4BbSCWaXG+E=; b=DOKUXFA9dba1uo0Y4ajylBxL1c10PzzMgE6yPGULC4Tqd0hVB56k8BdHYAE/Z9DEjL zMBG3/v9AknfkatoRgr3mGH4zvhBqRcNLLX080L2EDmBOanNmP17zTE6zWhlfO4a/wWO 5C7yQgWl4/FamyG+AFq9bDDDLSRxldzb4yvW6VMGsNtBn5Q4USawGzUsZhNqrjFE5g9n GmQIsiFX1PDnInrXGAATqAyC+xFObZ962rBdczWcE3gzcn7Jb4ezhEl66N5Uohq2RFoZ s13REQUi9yzgUQLeEmpVG6YApNhDShRVAiCqjxQZsFvQt5H1QPz16wvv+29eLoQTMTpF YCcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AoE485pc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e20-20020a056a001a9400b00562be402e14si12140542pfv.353.2022.10.17.03.04.42; Mon, 17 Oct 2022 03:04:55 -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=@intel.com header.s=Intel header.b=AoE485pc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231321AbiJQJcy (ORCPT + 99 others); Mon, 17 Oct 2022 05:32:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231298AbiJQJcp (ORCPT ); Mon, 17 Oct 2022 05:32:45 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28B9446632 for ; Mon, 17 Oct 2022 02:32:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999164; x=1697535164; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qa17WTfuPuByL/pGxqJjZfPv2fBRDy/8RHd7BwsgD1E=; b=AoE485pcIrMn+qUcfTmyZ55ZUcGRRjDdAIMlg6nPbId6mCkR1PMayGiX yA/4Y5zJ/4Ko50nVGRf6C0M3SKP3bauloEu1bOOZGxc4JbytLDEHqPg+p gBMQOP9+3Oi8N+UHAqoF1GgZyHnpHGS0vY6ySVHZHKUr27xmHJK4cmMoP 3ByHnNk6/fCOW45oruW1uDTra2wTji9BxhkKWv57iDKYou7imQtZPBcno eIHiF2sg4otnbT8Y5UsUF1+hORorSWENHr1fzK/VvLzl3qUwRIJXvG8ys VsVwPgP21LGHWIx9a2oA3DW4gG9xJSylEUucX6MsDd2Tlb2eZJu8TiUsx Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741608" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741608" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 02:32:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431281" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431281" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:32:39 -0700 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?utf-8?q?Christian_K=C3=B6nig?= , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu , Dave Hansen Subject: [PATCH 5/9] drm/i915: Use kmap_local_page() in gem/selftests/i915_gem_coherency.c Date: Mon, 17 Oct 2022 17:37:21 +0800 Message-Id: <20221017093726.2070674-6-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> References: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746928764853717456?= X-GMAIL-MSGID: =?utf-8?q?1746928764853717456?= From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1]. The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption. In drm/i915/gem/selftests/i915_gem_coherency.c, functions cpu_set() and cpu_get() mainly uses mapping to flush cache and assign the value. There're 2 reasons why cpu_set() and cpu_get() don't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe for CPU hotplug when preemption is not disabled. cpu_set() and cpu_get() call drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global and any issue with cpu's being added or removed can be handled safely. 2. Any context switch caused by preemption or sleep (pagefault may cause sleep) doesn't affect the validity of local mapping. Therefore, cpu_set() and cpu_get() are functions where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message. --- .../gpu/drm/i915/gem/selftests/i915_gem_coherency.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c index a666d7e610f5..b12402c74424 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c @@ -24,7 +24,6 @@ static int cpu_set(struct context *ctx, unsigned long offset, u32 v) { unsigned int needs_clflush; struct page *page; - void *map; u32 *cpu; int err; @@ -34,8 +33,7 @@ static int cpu_set(struct context *ctx, unsigned long offset, u32 v) goto out; page = i915_gem_object_get_page(ctx->obj, offset >> PAGE_SHIFT); - map = kmap_atomic(page); - cpu = map + offset_in_page(offset); + cpu = kmap_local_page(page) + offset_in_page(offset); if (needs_clflush & CLFLUSH_BEFORE) drm_clflush_virt_range(cpu, sizeof(*cpu)); @@ -45,7 +43,7 @@ static int cpu_set(struct context *ctx, unsigned long offset, u32 v) if (needs_clflush & CLFLUSH_AFTER) drm_clflush_virt_range(cpu, sizeof(*cpu)); - kunmap_atomic(map); + kunmap_local(cpu); i915_gem_object_finish_access(ctx->obj); out: @@ -57,7 +55,6 @@ static int cpu_get(struct context *ctx, unsigned long offset, u32 *v) { unsigned int needs_clflush; struct page *page; - void *map; u32 *cpu; int err; @@ -67,15 +64,14 @@ static int cpu_get(struct context *ctx, unsigned long offset, u32 *v) goto out; page = i915_gem_object_get_page(ctx->obj, offset >> PAGE_SHIFT); - map = kmap_atomic(page); - cpu = map + offset_in_page(offset); + cpu = kmap_local_page(page) + offset_in_page(offset); if (needs_clflush & CLFLUSH_BEFORE) drm_clflush_virt_range(cpu, sizeof(*cpu)); *v = *cpu; - kunmap_atomic(map); + kunmap_local(cpu); i915_gem_object_finish_access(ctx->obj); out: From patchwork Mon Oct 17 09:37:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 3341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1355489wrs; Mon, 17 Oct 2022 02:44:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM76pNY6TTZtPr9aoeJxPl8x/+R+MF2qUCD7v4g81Sz1P6DtVlPefrYIhSyKUtdqM6mpIW5m X-Received: by 2002:a63:4949:0:b0:442:b733:2fae with SMTP id y9-20020a634949000000b00442b7332faemr9708501pgk.424.1665999869872; Mon, 17 Oct 2022 02:44:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665999869; cv=none; d=google.com; s=arc-20160816; b=Da832FzSnctW7huJaWugTeUxTyLgLm7mp4SS6zEMCkRCOut3Bro24ZPEf7EIoLYznv yirfXABdzwF1Q+JiLU1WV7czypD5Pyl9b4Cme6n9h6v5CZ164sa7JGXGeiMEv+eY2Mjj 7JWaqeT18YhJtqd6Jh/sajfRGmW1n8dvdwEQPoQvKpIT6if5fCai88R+yivqTWnmGYKC Dl8RiZQgAh3niV1c+rexB9jX0nGUs7taPnA8rTuYTxwnX8/ljiCNTcBJY7PpYzSDRPam q8MrFsV9OeSHEKTuZGMxeBFHatY4XQ+Do8I+rjUUny/6/hqA1HRHBzDtEu+uqk55u5y7 hVeA== 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=PQbkmN4fS23R9NP2D3fOVeKGQIdLXPOuzdLIRk3ajFo=; b=kij89ooaiTIJ0LCvxcjsLfDKiSUhCGy1N1Pze3/q6UkgQJGDsUSF60A3rjac6cRvoQ xOzsz4wwReiK3zMjHrxors+Z4yV6dL5jKhhujEF+RVA47+qcAOU2xHGXAYtugPxsga+5 +g4pGixy5VQGtjhZAVmsv/NQnH4wh1hsLVyTSezAq30r9+0XAWyHlzqeYxLxRh1pRm8f jlSt0C0mnIcs8MW1QfVlqNbtlHpMdl7V6eC1pOUUmMbzXGxP3crfHL7Ey7cedjpqVke9 AhSc/JI3+vmPmFTefckr3G2m4wV2e2sdnZZkO059vejvyQK8LSlu+zgiG6DT1B75RC9h 6DZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="BaZt/XIx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l27-20020a63ba5b000000b0046301a9c718si12741598pgu.21.2022.10.17.02.44.15; Mon, 17 Oct 2022 02:44:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="BaZt/XIx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231340AbiJQJdE (ORCPT + 99 others); Mon, 17 Oct 2022 05:33:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231304AbiJQJcu (ORCPT ); Mon, 17 Oct 2022 05:32:50 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9E0A53D14 for ; Mon, 17 Oct 2022 02:32:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999168; x=1697535168; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KW/vA0zXivrgHf+ZcWE46VMbBD0S6IoDScJkHoJEmxA=; b=BaZt/XIxFWbxluyydED/EOzxWFV1nuSHg3lFe+2xXBrvc0X6Y2MPZTZn b9ISGTSFA+yWOrmEf60LUA2PV0EdH1BfP88jUYYgz58mG307aSswsvQ9+ 06O19IXRnHQUFU5KqGtXCNA3ujoKMtSUD9bTcmK/jjuDA6t3J9rQxobLd fbjQjvmmGFu+UDnO8xkatMHIBuBsZ2xWgKFZIlh7E9DuLZVJnzG58Jd07 AfYSWh01H10ToNdJ3Glm0c6dGvARQ9+VviuhsJwFzAO2BKyN1Xku6dFga zjSAasr2HyEN9hyoEyUPubzHk8r3OawnAUqvyeW6jF3k+ecJZipVrx/MS g==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741620" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741620" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 02:32:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431302" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431302" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:32:44 -0700 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?utf-8?q?Christian_K=C3=B6nig?= , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu , Dave Hansen Subject: [PATCH 6/9] drm/i915: Use kmap_local_page() in gem/selftests/i915_gem_context.c Date: Mon, 17 Oct 2022 17:37:22 +0800 Message-Id: <20221017093726.2070674-7-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> References: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746927479522053303?= X-GMAIL-MSGID: =?utf-8?q?1746927479522053303?= From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1]. The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption. In drm/i915/gem/selftests/i915_gem_context.c, functions cpu_fill() and cpu_check() mainly uses mapping to flush cache and check/assign the value. There're 2 reasons why cpu_fill() and cpu_check() don't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe for CPU hotplug when preemption is not disabled. cpu_fill() and cpu_check() call drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global and any issue with cpu's being added or removed can be handled safely. 2. Any context switch caused by preemption or sleep (pagefault may cause sleep) doesn't affect the validity of local mapping. Therefore, cpu_fill() and cpu_check() are functions where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message. --- drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c index c6ad67b90e8a..736337f23f78 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c @@ -466,12 +466,12 @@ static int cpu_fill(struct drm_i915_gem_object *obj, u32 value) for (n = 0; n < real_page_count(obj); n++) { u32 *map; - map = kmap_atomic(i915_gem_object_get_page(obj, n)); + map = kmap_local_page(i915_gem_object_get_page(obj, n)); for (m = 0; m < DW_PER_PAGE; m++) map[m] = value; if (!has_llc) drm_clflush_virt_range(map, PAGE_SIZE); - kunmap_atomic(map); + kunmap_local(map); } i915_gem_object_finish_access(obj); @@ -496,7 +496,7 @@ static noinline int cpu_check(struct drm_i915_gem_object *obj, for (n = 0; n < real_page_count(obj); n++) { u32 *map; - map = kmap_atomic(i915_gem_object_get_page(obj, n)); + map = kmap_local_page(i915_gem_object_get_page(obj, n)); if (needs_flush & CLFLUSH_BEFORE) drm_clflush_virt_range(map, PAGE_SIZE); @@ -522,7 +522,7 @@ static noinline int cpu_check(struct drm_i915_gem_object *obj, } out_unmap: - kunmap_atomic(map); + kunmap_local(map); if (err) break; } From patchwork Mon Oct 17 09:37:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 3343 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1355740wrs; Mon, 17 Oct 2022 02:45:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Gk4mGJ2n5Mck/nV2nZzfhFPvZsUqZ3qoNJtV/XYWUODD3qw+xp8k92vUQMMl8zPC61ctl X-Received: by 2002:a63:24d:0:b0:452:87c1:9781 with SMTP id 74-20020a63024d000000b0045287c19781mr9945737pgc.512.1665999915920; Mon, 17 Oct 2022 02:45:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665999915; cv=none; d=google.com; s=arc-20160816; b=m3EJE/38bX2tbwyBcARvBp7XhytE/CrEYRVk8aEt0hZKpj2RdiorIAvgHGysJQMj+E aUnd/7mp3+PXyHRWqfHmOpZU4KCAHyMfKoehK0Cc3FZkIPXXYdZrtF7/rb5/A+HOdTOK EdXRgS2zheH39VQQzNkkidyXPzqlDX4p1jP+yBpb1P7N7rQCIInntcD1P1bAsTPIqpTJ Dmnh1BrZXtVcVyNoC9iYK9rsun5ujfMWCYBumOwN4kJAUvd6hPrGKgP8a8+yPsku5pZa W2btQYuclxTHCriRvkba+bU3hq1P/DW6ZoIPK6kGxeT1hy4rbMshvZI8Nvg0A9PCHrwb N0cw== 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=IhntDfmc/Q2aCzm3w1Yf/3LBrCryjoIEhNxOyxpFbm8=; b=byfUll8LJBmCk7vpGdZLAmWamE1+K8P3YpD22TASzQ7aac+5em+GNnAAjw/eYiDRA9 b2XFif2DI+f4OGHcAprF498M6I2eD+Vg5ch7wGVIZvx3n1qwrxEU+YiaIlV6DDvo6d2z R8x8qp5Z0Rdfp/aVPkbVQtqX4jXcP19MvzlOWmh8rbtpw0xutXiQ/YGhrds4pochDaTf VQrcsIzQ0pDcN+KsRWNriljTNjco2/SiHdu+HuNPYsXwJLbVdTM2zY5/th7SBfxtU1CK VavYvdsx1iNJEMpb8pvfges30PqjtC05qYU/bcNlGHKzZoGL5pqADFOOIuR7gklXKpLY AbGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PrqjAqat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oa9-20020a17090b1bc900b0020d4dffd6e6si12776984pjb.99.2022.10.17.02.45.03; Mon, 17 Oct 2022 02:45:15 -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=@intel.com header.s=Intel header.b=PrqjAqat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229939AbiJQJdV (ORCPT + 99 others); Mon, 17 Oct 2022 05:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbiJQJdH (ORCPT ); Mon, 17 Oct 2022 05:33:07 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5ABA58DDA for ; Mon, 17 Oct 2022 02:32:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999172; x=1697535172; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w7/TXOlwKuSkPVUCwoST/WEVHFeOcyRbxSbjIiLRy7U=; b=PrqjAqatzmj+SDSe7Zmp0LLH3c6tgxjGuGgJSJEmAO7DoyDCCAB2rSIU rjM1mm1xQ0xNTH1weArVIFuy8hads1OPRXplQ/LDEpcKh6wt/VRvUNKFl Aw0da7Mz1NaXYQLfGriz90/MwEtO3FbOTqwBFEQgiUrhT34L4wijhs89V 0K4+rATJZUQFeYNnkWIqW74OttLC+WHYOXrqNFc4aU1z/maCjsowI+cLE pGOIdfULdGhP8jAfkn0+ijPC6RHbWsZQxKW6vs0HfnTfUGtXuf29iBxdi Ef3dg1064iC07Zzi4qvLVSSs7DQrd3/dJasu34ZPN+91blw+NBgh//9Ue g==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741632" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741632" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 02:32:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431321" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431321" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:32:48 -0700 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?utf-8?q?Christian_K=C3=B6nig?= , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu Subject: [PATCH 7/9] drm/i915: Use memcpy_from_page() in gt/uc/intel_uc_fw.c Date: Mon, 17 Oct 2022 17:37:23 +0800 Message-Id: <20221017093726.2070674-8-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> References: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746927527619259073?= X-GMAIL-MSGID: =?utf-8?q?1746927527619259073?= From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1]. The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption. In drm/i915/gt/uc/intel_us_fw.c, the function intel_uc_fw_copy_rsa() just use the mapping to do memory copy so it doesn't need to disable pagefaults and preemption for mapping. Thus the local mapping without atomic context (not disable pagefaults / preemption) is enough. Therefore, intel_uc_fw_copy_rsa() is a function where the use of memcpy_from_page() with kmap_local_page() in place of memcpy() with kmap_atomic() is correctly suited. Convert the calls of memcpy() with kmap_atomic() / kunmap_atomic() to memcpy_from_page() which uses local mapping to copy. [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com/T/#u Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu Reviewed-by: Ira Weiny --- Suggested by credits: Ira: Referred to his task document and suggestions about using memcpy_from_page() directly. Fabio: Referred to his boiler plate commit message. --- drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c index b91ad4aede1f..64d56f175d32 100644 --- a/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +++ b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c @@ -962,16 +962,13 @@ size_t intel_uc_fw_copy_rsa(struct intel_uc_fw *uc_fw, void *dst, u32 max_len) for_each_sgt_page(page, iter, uc_fw->obj->mm.pages) { u32 len = min_t(u32, size, PAGE_SIZE - offset); - void *vaddr; if (idx > 0) { idx--; continue; } - vaddr = kmap_atomic(page); - memcpy(dst, vaddr + offset, len); - kunmap_atomic(vaddr); + memcpy_from_page(dst, page, offset, len); offset = 0; dst += len; From patchwork Mon Oct 17 09:37:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 3344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1355744wrs; Mon, 17 Oct 2022 02:45:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM48MJQvFUmOU7BFrW7G8De2Ny3n+4cfftYVkXk3Jd51dlHocX74i2+gBrCpt2Xs5zN3kdZH X-Received: by 2002:a17:903:509:b0:179:ffcf:d275 with SMTP id jn9-20020a170903050900b00179ffcfd275mr11094981plb.150.1665999916425; Mon, 17 Oct 2022 02:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665999916; cv=none; d=google.com; s=arc-20160816; b=irXtvbYkiGEJQ+ixa8MXlp+6WgPRFurp9FP46IzuQ/I55grqi/phmecKqCCWcvZXmf bs+9VbiY5pUz3/5kPHKyKfQP7iNOfeDwD7Cf+xdVkC09rxP7q4IM+VX9ApaCd9mVQbjV hVH9URfKzELl4J6jRuBLa5HiHUsguAuqajv/jzh69WRMm/BfonIsPAFtXrUEZzu2aWUz f5SeB17yyIBlc0xiehbtoSoYLd0CKX9bdUcP7lLO+++zLQocB1l313tRDX3ybmpNd8KL 2R35Wdth+JOkB8tc6Nb3xmnWYakJwcBrwY88gzcddrOVbVQlyn5j5vOgArD/XkqHkHSQ vJ3A== 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=Tfq3bUoe5xAbnivYgs0Om88UaoQZh6VnTAQ9wYbZVRo=; b=Oy1tRqhGKDJY6nRXAHS9W9cqr11u34a8yenAYWb9u17yTNeUYYg+FN+NpKaNLZKJsg ebxVrSGhjWJPtNqoiy3DBVZkTLe8kyJdCgySckce/IIMuE0qmTNQs6+HfvZazcpBDMCS SsZVveucoe+0EoCkSxW272rNvRKO+iCPjrfIUZNGdVvIADUIg/DgUDzZcy5xZlACL3YB 9nG8sTd1HqcFM5Tt1SMBNXFV81pAh8tEFYvzADUZxMUWXUMaPCvxBOYtKqWRoWfSoTTE 33ZWpGpXYeI6mPtRUmAqoBo79MTZebtgYs0568XGhJwfl96mlXaJ4oeUQOy65V9Ecmnf Pwzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jgCItgeC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pj4-20020a17090b4f4400b0020cedba54fcsi11784556pjb.55.2022.10.17.02.45.04; Mon, 17 Oct 2022 02:45:16 -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=@intel.com header.s=Intel header.b=jgCItgeC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231371AbiJQJdY (ORCPT + 99 others); Mon, 17 Oct 2022 05:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231354AbiJQJdR (ORCPT ); Mon, 17 Oct 2022 05:33:17 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86D905A808 for ; Mon, 17 Oct 2022 02:32:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999176; x=1697535176; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0Ch/gzI1CiEltsWtZiZ1vnI7GDsumr0SEFm747ErScU=; b=jgCItgeC1R/Zp94KyKUhQnOWheZ9NvWIOckwNkWRHkjNznPwLqAZsUb6 MEZtEmJhJNDS2ooI4yuMy3552pwR2w0zCOKFAGQF3Tgba+HmIP943UcIp pRsLLJsbPNNuwFAlO4blrePUBbUS4WaVAG4gCs2BiIL3Ks44SMPMXVxoO An5oaMC49vxjX+zh3Kk1BQPdJn+WJvOeoxG/y5elWau+SnSCGBJTy/6vn Dv3jZTT3ENkzf62GaMbrZAC9qbQkD1fla//f6X7HfJ9CRNtilZw/dduyz gAyQSxCLx7Fkf9IxoW7wi2hpRBK8KgYDXKpNdNBQsi/2hjEnQWwpXRS6r w==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741641" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741641" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 02:32:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431333" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431333" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:32:52 -0700 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?utf-8?q?Christian_K=C3=B6nig?= , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu , Dave Hansen Subject: [PATCH 8/9] drm/i915: Use kmap_local_page() in i915_cmd_parser.c Date: Mon, 17 Oct 2022 17:37:24 +0800 Message-Id: <20221017093726.2070674-9-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> References: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746927528241966596?= X-GMAIL-MSGID: =?utf-8?q?1746927528241966596?= From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1]. The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption. There're 2 reasons why function copy_batch() doesn't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe for CPU hotplug when preemption is not disabled. In i915_cmd_parser.c, the function copy_batch() calls drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global and any issue with cpu's being added or removed can be handled safely. 2. Any context switch caused by preemption or sleep (pagefault may cause sleep) doesn't affect the validity of local mapping. Therefore, copy_batch() is a function where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message. --- drivers/gpu/drm/i915/i915_cmd_parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c b/drivers/gpu/drm/i915/i915_cmd_parser.c index f93e6122f247..1a56000d7476 100644 --- a/drivers/gpu/drm/i915/i915_cmd_parser.c +++ b/drivers/gpu/drm/i915/i915_cmd_parser.c @@ -1211,11 +1211,11 @@ static u32 *copy_batch(struct drm_i915_gem_object *dst_obj, for (n = offset >> PAGE_SHIFT; remain; n++) { int len = min(remain, PAGE_SIZE - x); - src = kmap_atomic(i915_gem_object_get_page(src_obj, n)); + src = kmap_local_page(i915_gem_object_get_page(src_obj, n)); if (src_needs_clflush) drm_clflush_virt_range(src + x, len); memcpy(ptr, src + x, len); - kunmap_atomic(src); + kunmap_local(src); ptr += len; remain -= len; From patchwork Mon Oct 17 09:37:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 3345 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1355750wrs; Mon, 17 Oct 2022 02:45:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7+Y2mLX/Sfii/5RcYbdzAP4sDW49JYGHkgRgff7ugAhoVZW+4esbc+t8gdlq+0VWIT5mXB X-Received: by 2002:a65:6bd4:0:b0:443:94a1:429c with SMTP id e20-20020a656bd4000000b0044394a1429cmr10006391pgw.606.1665999916763; Mon, 17 Oct 2022 02:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665999916; cv=none; d=google.com; s=arc-20160816; b=DxvACJRTigfxnYX9prz+yckpCsuUuZx0MmHrxY54p+OtuHuirRbopX/zP3BzmhWi9P mOZdeezZHs8hAy5+549yRSuMvyIbApoekgYwn5i6cnmR5LgWAjBrctNhFnGHqoxl+0fB +LjBlljjZI3FEAvJ5GGZzjJmRiTaXmLQxQq6J7bnmRKQVXDP4e4XGXOoKij6zvCPXm+U 3NVoTBz5n/NCPXP7ByaVDlFREOdFVFsb0FGmjkkb9PeriVMwg8CRT2wu+P+NX5qzvkuN IAJeA41+x9JdRcNwzkkkeMAWFnBmG9OVVBe6O4LUO6a7Vfk0Lg84uLPrGp9WqVZFTDMr EqnA== 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=973smkPTc6TiGD0NM5DENyEvsgYwMxKPwobaRaZRJQc=; b=SC7UE2zTa2CsbNc9DanQPThiJPRfif/dtuWD8BDxqSWb303CgvBTfLpuQ+b5uExJgs xzqZ5fHC4zTyl+1YbPJM7foV8i+u64zdDDsOjjaV4Xs7ncOJFhqB4+fSO6kzpzo+t1c+ NfhuJDaSb1JwNpNA8IY3eos7gEBjzVC8b96hdQ6JK2mBdecGIHk8ddTJAHzFNaYplQhE XVM7UnsPiwLJG033LSGRJqEiBWSiIcjYh7NkFG8iwVAPxPMpLEBz5Y/kNvSIgizqdt5y jv1Ag3MdH9Mh2Tikx+aOMRplBiUI9EhEf4/7bLegO4ywMPJhD/YSxHueQwSIJPH7qpr8 N78Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lT5vhBu0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q3-20020a170902eb8300b00174c5fdc8d2si10732778plg.307.2022.10.17.02.45.04; Mon, 17 Oct 2022 02:45:16 -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=@intel.com header.s=Intel header.b=lT5vhBu0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229992AbiJQJdz (ORCPT + 99 others); Mon, 17 Oct 2022 05:33:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231301AbiJQJdV (ORCPT ); Mon, 17 Oct 2022 05:33:21 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C108F5AA16 for ; Mon, 17 Oct 2022 02:33:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999180; x=1697535180; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JEcLb6X6ZbdiyJg/wD23ZbxE1Ia5HJhKof7dQaZ62+0=; b=lT5vhBu0RWIm+b3ZiSz3PqoK3NAJ9LbXO07/zGGeOyfITp6qXxlVMqHT tfjx7pqEZTLLq4oZpwVvuR5vmQbH2UwL1ETqCACeuZY2/QIqYBtzFEMc1 Ac0TIbMbd9580A8rq4O1LP7dOkaOGSq0Hlh8dY4wxTCG/Q632TyxbNWBq rgx0tOfr/BMK9KjxX8CSZyn258clRIB37iaJzjORXNDsgoKzYPI60jX3r cu44bFr5sE81JMgi8VUu7S3ULEPzP6Qpi2QFqwgGWO1SjhsdY91bqZrF6 Lxu6QfKmuaNtvtJehdmLrhIGldBeZ2i/YFxDt+d55spof+UaINeqXbTKb g==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741659" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741659" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 02:33:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431340" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431340" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:32:56 -0700 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?utf-8?q?Christian_K=C3=B6nig?= , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu Subject: [PATCH 9/9] drm/i915: Use kmap_local_page() in gem/i915_gem_execbuffer.c Date: Mon, 17 Oct 2022 17:37:25 +0800 Message-Id: <20221017093726.2070674-10-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> References: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746927528532107563?= X-GMAIL-MSGID: =?utf-8?q?1746927528532107563?= From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1]. The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption. In i915_gem_execbuffer.c, eb->reloc_cache.vaddr is mapped by kmap_atomic() in eb_relocate_entry(), and is unmapped by kunmap_atomic() in reloc_cache_reset(). And this mapping/unmapping occurs in two places: one is in eb_relocate_vma(), and another is in eb_relocate_vma_slow(). The function eb_relocate_vma() or eb_relocate_vma_slow() doesn't need to disable pagefaults and preemption during the above mapping/ unmapping. So it can simply use kmap_local_page() / kunmap_local() that can instead do the mapping / unmapping regardless of the context. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Ira Weiny Signed-off-by: Zhao Liu --- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index 845023c14eb3..8263d4e6620a 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -1110,7 +1110,7 @@ static void reloc_cache_unmap(struct reloc_cache *cache) vaddr = unmask_page(cache->vaddr); if (cache->vaddr & KMAP) - kunmap_atomic(vaddr); + kunmap_local(vaddr); else io_mapping_unmap_atomic((void __iomem *)vaddr); } @@ -1126,7 +1126,7 @@ static void reloc_cache_remap(struct reloc_cache *cache, if (cache->vaddr & KMAP) { struct page *page = i915_gem_object_get_page(obj, cache->page); - vaddr = kmap_atomic(page); + vaddr = kmap_local_page(page); cache->vaddr = unmask_flags(cache->vaddr) | (unsigned long)vaddr; } else { @@ -1156,7 +1156,7 @@ static void reloc_cache_reset(struct reloc_cache *cache, struct i915_execbuffer if (cache->vaddr & CLFLUSH_AFTER) mb(); - kunmap_atomic(vaddr); + kunmap_local(vaddr); i915_gem_object_finish_access(obj); } else { struct i915_ggtt *ggtt = cache_to_ggtt(cache); @@ -1188,7 +1188,7 @@ static void *reloc_kmap(struct drm_i915_gem_object *obj, struct page *page; if (cache->vaddr) { - kunmap_atomic(unmask_page(cache->vaddr)); + kunmap_local(unmask_page(cache->vaddr)); } else { unsigned int flushes; int err; @@ -1210,7 +1210,7 @@ static void *reloc_kmap(struct drm_i915_gem_object *obj, if (!obj->mm.dirty) set_page_dirty(page); - vaddr = kmap_atomic(page); + vaddr = kmap_local_page(page); cache->vaddr = unmask_flags(cache->vaddr) | (unsigned long)vaddr; cache->page = pageno;