Message ID | 20221017093726.2070674-3-zhao1.liu@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1354811wrs; Mon, 17 Oct 2022 02:42:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6oEYhAYK1KsfY4QjqY+UyHSyp4CpCu+HmBshbrt5enO+cZ/QhepKphdFQSR4+EFDGVN86R X-Received: by 2002:a63:2352:0:b0:46b:1dac:bc83 with SMTP id u18-20020a632352000000b0046b1dacbc83mr10263025pgm.98.1665999734422; Mon, 17 Oct 2022 02:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665999734; cv=none; d=google.com; s=arc-20160816; b=mlZ2aztk27Do1oZMzxM8xpi1NHQ/Qs8EBMb7lupUnHlG4S25qZmKoz7UdMF/1CR2wc yIUcNKSPsp3wXKXRhvhgd27VzOOqDBkYQbTpcANT2TCXiInIDGqek4xhz4/dyHpFXSe+ O8wVuA9Pr9rJ7G+1UUs710ekFSPGB52a85c3zxnFPXOHuxsGnpQgAma0s/FPutCPkPRc wXwKchbS5Gr1lPH1CUcLhGgl4JHZC+WNDiLHXR/eVdMG/2evV7GBFKSA+fTOe/7esHnK 0IdRz8WCGKbvO9+6fUKBg5+C9ZQmfmKTz4y50KT9Q5fh5IYzbmmHEKKp5dG6KNLj20qj T2ww== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y124-20020a636482000000b0042bb607f75esi10986406pgb.284.2022.10.17.02.42.02; Mon, 17 Oct 2022 02:42:14 -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 <rfc822;ouuuleilei@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <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>, Matthew Auld <matthew.auld@intel.com>, =?utf-8?q?Thomas_Hellstr=C3=B6m?= <thomas.hellstrom@linux.intel.com>, Nirmoy Das <nirmoy.das@intel.com>, Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Chris Wilson <chris@chris-wilson.co.uk>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com>, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Ira Weiny <ira.weiny@intel.com>, "Fabio M . De Francesco" <fmdefrancesco@gmail.com>, Zhenyu Wang <zhenyu.z.wang@intel.com>, Zhao Liu <zhao1.liu@intel.com>, Dave Hansen <dave.hansen@intel.com> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746927337803309787?= X-GMAIL-MSGID: =?utf-8?q?1746927337803309787?= |
Series |
drm/i915: Replace kmap_atomic() with kmap_local_page()
|
|
Commit Message
Zhao Liu
Oct. 17, 2022, 9:37 a.m. UTC
From: Zhao Liu <zhao1.liu@intel.com> 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 <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> --- 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(-)
Comments
On lunedì 17 ottobre 2022 11:37:18 CEST Zhao Liu wrote: > From: Zhao Liu <zhao1.liu@intel.com> > > 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(). > I have here the same questions as in 1/9. > [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> > --- > 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); Please use memcpy_from_page() instead of open coding mapping + memcpy() + unmapping. > > 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); For the same reasons said above, memcpy_to_page() should be used here and avoid open coding of three functions. Using those helpers forces you to move drm_clflush_virt_range() out of the mapping / un-mapping region. I may be wrong, however I'm pretty sure that the relative positions of each of those call sites is something that cannot be randomly chosen. Thanks, Fabio > > set_page_dirty(page); > if (obj->mm.madv == I915_MADV_WILLNEED)
On Sat, Oct 29, 2022 at 03:32:08PM +0200, Fabio M. De Francesco wrote: > Date: Sat, 29 Oct 2022 15:32:08 +0200 > From: "Fabio M. De Francesco" <fmdefrancesco@gmail.com> > Subject: Re: [PATCH 2/9] drm/i915: Use kmap_local_page() in > gem/i915_gem_pyhs.c > > On luned? 17 ottobre 2022 11:37:18 CEST Zhao Liu wrote: > > From: Zhao Liu <zhao1.liu@intel.com> > > > > 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(). > > > > I have here the same questions as in 1/9. > > > [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> > > --- > > 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); > > Please use memcpy_from_page() instead of open coding mapping + memcpy() + > unmapping. Ok. > > > > > 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); > > For the same reasons said above, memcpy_to_page() should be used here and > avoid open coding of three functions. > > Using those helpers forces you to move drm_clflush_virt_range() out of the > mapping / un-mapping region. I may be wrong, however I'm pretty sure that the > relative positions of each of those call sites is something that cannot be > randomly chosen. I agree. Will use memcpy_to_page(). Thanks, Zhao > > Thanks, > > Fabio > > > > > set_page_dirty(page); > > if (obj->mm.madv == I915_MADV_WILLNEED) > > >
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)