From patchwork Sun Dec 3 13:29:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 172952 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2229274vqy; Sun, 3 Dec 2023 05:18:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHra+ZuVfHRXmVL0ou25y5hWYegv6XC8NpJ7oKZgOxQm3X6iYq1Es0RdYbc+2aQCoRJ3dkU X-Received: by 2002:a05:6a20:3c90:b0:180:e3f1:4f60 with SMTP id b16-20020a056a203c9000b00180e3f14f60mr30163028pzj.45.1701609525621; Sun, 03 Dec 2023 05:18:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609525; cv=none; d=google.com; s=arc-20160816; b=IHkepVhecZtLCS1ywK+JRuVezdwJlHLlJLYfBbHxOhTUagCodgiaiGpleczVs5jnau zBqN/VGkCe/4mbg6ew3aZ7+EUbEqlYdkBEhdoCOWptmvqZTUZ2i8TzOaG3B9M44ArM4Z lFghQGJjIArdhpmjVDj8PalCvo7f3nbOPciskdDzbcXVPl4jh2AtZRg4iQD+Cufjl6zS PWhtY7rHAu2tOeXC/42W0kZyvjmt2OtO5TgU2yMEBeBEPhtKe759YWXlLUJWZylc2lHd csLC9dNnbNTILDxBYCqwPswVgZhf203JCeHdBJC+IomXIOrqO/E0bJR96JYik0LGl7ut rAzQ== 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=sqEHT2dgNS7DMYomacxDBsoEmRPhidC6Q/nAyHINzfw=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=zI1F/WX+jhHOmJttC3Ln92zvjTXE1wI/S6DZn6acWTYxJwgVjhx7K2DsyIOlVLuZKH 7XliBltMp6LL6taZjHca+qe/GKDQZ2HtP+mtyTXfBbm246WhaThj5PYuPoyzL9Lzmeec Pn9EVC8L7QB15zg325FhusmXnpXmK+HHTOqbC0wSzKYZp69XRVuXuUA5+GzsvLXVeHcY APVcIzUN7LF/ylDzSi2CgSFUI5s//Wm58Dr4FfwomoWy/D00u05Q8yAKENFWKbxLQ0TF 1k9lbCXtI/XZam3K0UI2npKbfzltgqkgnpzk2MNC5tGaGsS+WLHguANWGDfbNjYI/IcN TV8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KQdCGtR3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id j9-20020a056a00234900b006cbba705c9esi6346992pfj.207.2023.12.03.05.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KQdCGtR3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id F326E803E305; Sun, 3 Dec 2023 05:18:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233722AbjLCNSR (ORCPT + 99 others); Sun, 3 Dec 2023 08:18:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233673AbjLCNSH (ORCPT ); Sun, 3 Dec 2023 08:18:07 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08414198 for ; Sun, 3 Dec 2023 05:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609489; x=1733145489; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fm2E31LppwjrR39Uy7KnRmjjwMXiEfdx6p7tDjCHHk8=; b=KQdCGtR3QXXuPDMGy8RSCKzxvZtdWMFGsy7Cncm/U/Mlqv5U9XEC57pf aeWdNWvgT1d1fra/IbupjWWwlefvJsh4GH2ZVb9PD8a67MiCw+639FVlY k4G2xNI6sH6mPjMgV9g7hDLHwG3zpttCxEVhe5c8f50IGD3HbseoYEBHq MAJlzaEPXAD9qlSEGodVotpE5RxwN1o4JEpJRc2ACQ4ytTdpJ4qfsCRJZ Z5aMAg+YRxBdrV4qVt5SMWVVCNVSErAjGIHdnTzSdWzfJ2Sqj5IOKOB6s mVFlSCdbLoIHR9vc5cGg3sNoqTj2YeioVufXOsUHIyaEwUHWLWR1p+RRE w==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498245" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498245" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2023 05:18:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262446" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262446" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:18:04 -0800 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Ira Weiny , "Fabio M . De Francesco" , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Zhenyu Wang , Zhao Liu Subject: [PATCH v3 6/9] drm/i915: Use kmap_local_page() in gem/selftests/i915_gem_context.c Date: Sun, 3 Dec 2023 21:29:44 +0800 Message-Id: <20231203132947.2328805-7-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> References: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:40 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784266910007838653 X-GMAIL-MSGID: 1784266910007838653 From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1], and this patch converts the call from kmap_atomic() to kmap_local_page(). The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption. With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults or preemption disables. 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. 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. 2. Any context switch caused by preemption or page faults (page fault 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 Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco --- 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 and his description about why kmap_local_page() should be preferred. --- 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 7021b6e9b219..89d4dc8b60c6 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c @@ -489,12 +489,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); @@ -520,7 +520,7 @@ static noinline int cpu_check(struct drm_i915_gem_object *obj, for (n = 0; n < real_page_count(obj); n++) { u32 *map, m; - 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); @@ -546,7 +546,7 @@ static noinline int cpu_check(struct drm_i915_gem_object *obj, } out_unmap: - kunmap_atomic(map); + kunmap_local(map); if (err) break; }