Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2160966rdb; Sun, 3 Dec 2023 05:18:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGq8fTKdWBVBBKFkvoy2G0fTCj90G3RothB3sfGCS5bhaPJ5zZBqrAiBHHkJqbwwyZaPgw/ X-Received: by 2002:a17:903:41c8:b0:1d0:8092:685 with SMTP id u8-20020a17090341c800b001d080920685mr2041853ple.100.1701609534222; Sun, 03 Dec 2023 05:18:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609534; cv=none; d=google.com; s=arc-20160816; b=UM1AEJX0BMu9TtoyHQ2T+dUtL1TuOsoa9L8/9GV4l1hjRir1dMR+KHIJrXy6+TBs3/ v+JNFoNe1Emwl9SHi6vDbnlzhl6Uthwbrz47oPhgZWzaz0ecJRM5ywkwvOu4dUSQkeDw lfrAMK1dhh16n2aKsmI4O7pdtcKYfYQstj7xc5v2zh3Cg8kVyH3K8AkBOSBtlgZHS1YM hsw2s+NQeYlZ5u1aHKO7tWTy1prGI++D2dpNAnlv5qpMgF9UtEIie2qCpILu+gXYnu/Q FPGYUTl+YCegtFjScVQZh0eJfvkLzPI0FhKlx7Gj3tyNr3DCJlIu4QDXH8dHSRFVBuwO If8A== 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=cpFJJ62nhZXxViT9wjr4rIi2YXSu0JLoDVwraCWB6z0=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=ejq/EX9JK+rMSDkHIiEmGtgxMVaKehzhY0Hxp8DWxgVUfIt6FHgDO9pf1fGQCMGQZT oczjeXMsDBjpPi8onqDlH2eM+d0577kqBxQRuO6OwKDkfIT8x1PdoZX2n9M++5Z47dRz LwltRPVPwTGdDH/1mYu6gVbMBw/Xo0K3v702K2op1ka3PRosJxw3baE647mnkA4YZDmw oJ+XU5VVN2NoPF4p/+ZcZSfy0yeRD7TdYC/cCHBJ259Q1gsoW+KPP4ErK1A3D6Gzt86/ 4XvEBzsz/RzUxmlYJiC12gHbL2mB19XLFeMeULMdwPPkMCwaM6V4tKI8wZOZVxPGdqGk 1xhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="OA/89Uy3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id b17-20020a170902d51100b001cfb84c92fasi4972899plg.70.2023.12.03.05.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="OA/89Uy3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id EE6D480681DD; Sun, 3 Dec 2023 05:18:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233802AbjLCNSe (ORCPT + 99 others); Sun, 3 Dec 2023 08:18:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233674AbjLCNSR (ORCPT ); Sun, 3 Dec 2023 08:18:17 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD61010F0 for ; Sun, 3 Dec 2023 05:18:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609497; x=1733145497; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EKKa4BOOnEyA4HUJAkWqKp5uSW09uVdvjZ+3UJneSag=; b=OA/89Uy3NIrSEw3ijxLzfAYfrpr5RrzPn8PJ9akyDrPM2unDkofxIj5S uxlfGxz0oF9swS92wMdsx93kypSNfpBX6vaOfOMEz9/4LLkmSHKVN6MDC lM6jG3gpCvk6eUO0YrfrDD0IbpH6JGwFeZ/xI6VIKLRPr7m+W0ZXuLx5A xpV0jLARztv2RF7kwq/Cp6t5HjTDXFae/6blhvPdOS0AmpNXYATvQ1Ctd BNwT+T8Zp0ycVjZ2u/OTiHw0a4fqqZo7kVvTig7f5//iz7RwPlkiUo0lu xIIPIi+/74PkwxydGY3VU9zGO+erq3D22vyRKQczL44mWOVT1zvgmWsd3 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498263" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498263" 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:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262478" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262478" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:18:12 -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 8/9] drm/i915: Use kmap_local_page() in i915_cmd_parser.c Date: Sun, 3 Dec 2023 21:29:46 +0800 Message-Id: <20231203132947.2328805-9-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 Content-Transfer-Encoding: 8bit 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:51 -0800 (PST) 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 (the preemption is disabled for !PREEMPT_RT case, otherwise it only disables migration). With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults and preemption disables. There're 2 reasons why function copy_batch() doesn't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe. In i915_cmd_parser.c, 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. 2. Any context switch caused by preemption or page faults (page fault 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 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/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 ddf49c2dbb91..2905df83e180 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; -- 2.34.1