Message ID | 20231203132947.2328805-9-zhao1.liu@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2229309vqy; Sun, 3 Dec 2023 05:18:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHro2yya03gMpdgvYpWhtiZa3oTnOHl9wuEYILLIqYrdCpXVpySUU30bDJze0r2aChH81Kp X-Received: by 2002:a05:6a20:42a1:b0:18f:1d8b:fadc with SMTP id o33-20020a056a2042a100b0018f1d8bfadcmr2573571pzj.19.1701609530384; Sun, 03 Dec 2023 05:18:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609530; cv=none; d=google.com; s=arc-20160816; b=nLifjQlUquNRybTu4I0cUe2wMJjNAfI1oR1i/i5WkBEIU5T7sOOowrbuHF+r6OVowS L/ea7lLQ+EQVfbjTPKv4EWdY/c1/2zKMarxqKuFs0IeKw48b2fAlWAWXQd5zSyuIvSZ+ XJImzJkCbcxzbSo9yG+vv0XABQ4lctwo8h6/F+IXYICWeBkr1zOKms27Tc5xni4pWi+/ Hs20DZTUnxS0F+xov2l9G0nGbMRyu1weTusnecRMz4EEeT9a3AjSA+AzJ8dZdp2HKMDa j/ice4WKjyILn4FF/sDdsCDptULno8WeFcHdpz9bdR1LwodgIcqNI4kaC+HyIfPU8csB kyig== 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 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bx42-20020a056a02052a00b005c663e195d6si2048633pgb.446.2023.12.03.05.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; 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 23.128.96.33 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 8DAF1806934C; Sun, 3 Dec 2023 05:18:46 -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 <rfc822;pwkd43@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <zhao1.liu@linux.intel.com> To: Jani Nikula <jani.nikula@linux.intel.com>, Joonas Lahtinen <joonas.lahtinen@linux.intel.com>, Rodrigo Vivi <rodrigo.vivi@intel.com>, Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Ira Weiny <ira.weiny@intel.com>, "Fabio M . De Francesco" <fmdefrancesco@gmail.com>, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Dave Hansen <dave.hansen@intel.com>, Zhenyu Wang <zhenyu.z.wang@intel.com>, Zhao Liu <zhao1.liu@intel.com> 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: <linux-kernel.vger.kernel.org> 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:46 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784266914574649654 X-GMAIL-MSGID: 1784266914574649654 |
Series |
drm/i915: Replace kmap_atomic() with kmap_local_page()
|
|
Commit Message
Zhao Liu
Dec. 3, 2023, 1:29 p.m. UTC
From: Zhao Liu <zhao1.liu@intel.com> 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 <dave.hansen@intel.com> Suggested-by: Ira Weiny <ira.weiny@intel.com> Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> --- 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;