Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4204462rwi; Mon, 17 Oct 2022 03:05:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7I1QNfm+CwH4KMavSP8U5AqqE4aCUrAup9PFtVl2G7S1/49gozrBBXOO15wdcvYweChjR8 X-Received: by 2002:a63:69c2:0:b0:46a:eeb1:e784 with SMTP id e185-20020a6369c2000000b0046aeeb1e784mr9994419pgc.589.1666001118381; Mon, 17 Oct 2022 03:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666001118; cv=none; d=google.com; s=arc-20160816; b=ueERxObAcxY1SMa0NFfXP5emNGplC6o0dsCFvLrI/yRgdZuknbzcp32gueToLkQQSs i6P0PpNhPth0XhX9tbjHlF7UNlrQT8jNm68a4aOA3ubOCRTVjfLnb+w8b8KfM/O/QRKo gw9/K+v1x3LtvAvOUlz6GCnNhEBgENXs+zH0NR1d8mTdX8u938O50ivSrXiBTSXkKgq3 96PIB0paCu3zD6y2LPz3nnMyLyeEF+8frbhW8P0GcXOAHBXeLscbXPRQCsEbMnFWQmPm ngnGzW1qb9VB2uZU1nscxl6M6EKULl7kKE3u1s7mBTKKHIlEBXx+E3BuIUzkugb6sKTu yvIw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z12-20020a1709028f8c00b00178a33faa42si10166948plo.66.2022.10.17.03.05.04; Mon, 17 Oct 2022 03:05:18 -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=20Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?UTF-8?q?Christian=20K=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 Content-Transfer-Encoding: 8bit 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 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) -- 2.34.1