Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2160692rdb; Sun, 3 Dec 2023 05:18:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYrHmiDkIMKsWZcB7EcH7neccZ9z0B3JRhZucQvir9AwRJgQAxd+OnbKL0nPeql5w2d4bM X-Received: by 2002:a17:903:1207:b0:1c6:11ca:8861 with SMTP id l7-20020a170903120700b001c611ca8861mr2602631plh.21.1701609496950; Sun, 03 Dec 2023 05:18:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609496; cv=none; d=google.com; s=arc-20160816; b=ROyQe7273ngOWvPSjO3TLMZp2HQDJ/oQu4HhpB23gd0iAochLnPVS2Z1pc5o6TQ8hm qJ47K1dCPtdg6ftyRSHm7QiHng8GxDxSabgnTeshnAaRky4trWzwRvjGQeH8UtlNh3h5 9nMhmBLW5IjGQcZIh7aKwLLDdOljAaztH4+rDdrjmSSrCL2rzTgvYRSfNlpF4a9g3wC+ mF80FPmxkiZ96JUfnViFzuImmDCU87N4tNlS12e6eOvdMAovbAoa5Svrr/8/MmKmbfw+ 98+fuV7n8ONUla9bo1qi+bw354rIY7ExkuQiuX5Dd2Fxe1bpfn2qKNy6OhxhoAs7WRkl tT8A== 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=d0+aX1ehJ1ea3eQXLNnFqnsRpWHU0i6XHvGRhDTETYQ=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=S6tTanfdT93pIq39DBmSkGVxhdm1cEPKYySZR01xE3F118eJWtyuIjmy0xqnWrjAPU BcWuR7Kqoj3q5dZDCG9t11uOhuD7jsek01izJhS0G4JPqDKje84RdNF2NkulP8jjZ6EG K+8NXegTyDNcVkdjXtyL0/5sQdXGADypmZrppV9m9ZZ74xpgtRK8ONIojZdi9kqFFR+p IUbhn+RP8b1LzvnB4Ir63QM58vOHK2gFi1GgqTOWP6M4/ao8srFVZ5M2QrsXAmBDiS3e Y2mVRbC1qS/fUBjJ8pY93bWBya1+Xvmq60z/1E1nUFLdI8GM5Cb4mGn2F824HD/g4O5J hUZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h8u8zRKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id x7-20020a1709027c0700b001d07c2a582dsi1722993pll.507.2023.12.03.05.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h8u8zRKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id CF833807DED3; Sun, 3 Dec 2023 05:18:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233534AbjLCNRq (ORCPT + 99 others); Sun, 3 Dec 2023 08:17:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233521AbjLCNRn (ORCPT ); Sun, 3 Dec 2023 08:17:43 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26FDB102 for ; Sun, 3 Dec 2023 05:17:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609469; x=1733145469; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RGMem3p2DJYsfNDR22BCHsoG0wKxhOHO8cUgjkpX0Tg=; b=h8u8zRKRGYeNE01Bp2yNO7wAD3ZuK3RNINwjE4Nr+tSbUwI0h5EkMEVq oykpi82UeZpHHKlPielrekhrN4WbPJjnWl1QM//SdnD+DjBgSWeCw0z5s bLaCOlTQRIGvg8qMf4JeInA8ajvz7WvwN6tKAG1oJWEiueiiRR51fMXIW VcgBIK6r++jkek3ouzTwgND6Y+vgYhWu+aJ99GtI7Tfasq6tOwTK8RnTv utn+2FpVA8ltRyJXDt0uIrwRkDG3l7dvpMD3LI0jnOsPQE0Y3IDgKAxba y/n6mBjztFJFWZGZLnZruZKjsN9QRpkqXKjhGvR0rXFHQJQSNEMqfk8G4 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498212" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498212" 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:17:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262333" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262333" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:17:44 -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 1/9] drm/i915: Use kmap_local_page() in gem/i915_gem_object.c Date: Sun, 3 Dec 2023 21:29:39 +0800 Message-Id: <20231203132947.2328805-2-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 fry.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 (fry.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:13 -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 i915_gem_object_read_from_page_kmap() doesn't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe. In drm/i915/gem/i915_gem_object.c, 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. 2. Any context switch caused by preemption or page faults (page fault 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 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/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 c26d87555825..a2a7e5005415 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_object.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c @@ -493,17 +493,15 @@ static void i915_gem_object_read_from_page_kmap(struct drm_i915_gem_object *obj, u64 offset, void *dst, int size) { pgoff_t idx = offset >> PAGE_SHIFT; - void *src_map; void *src_ptr; - src_map = kmap_atomic(i915_gem_object_get_page(obj, idx)); - - src_ptr = src_map + offset_in_page(offset); + src_ptr = kmap_local_page(i915_gem_object_get_page(obj, idx)) + + 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 -- 2.34.1