Message ID | 20221013210714.16320-1-fmdefrancesco@gmail.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 y7csp483032wrs; Thu, 13 Oct 2022 14:11:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4S0yUPr+kR28i0whAlsm7z2NzR9FYaM3TPBY/pSZ08bWVtKV33ZiFLNnJPoxnLZTb2M3vQ X-Received: by 2002:a17:907:2bd4:b0:78d:48c9:29b0 with SMTP id gv20-20020a1709072bd400b0078d48c929b0mr1186248ejc.562.1665695519552; Thu, 13 Oct 2022 14:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665695519; cv=none; d=google.com; s=arc-20160816; b=mkTP8Ryyg2YvKmjQV2069iu5SyUXW8YJtLUqoEyu7bLVRdJU8uV46RSXqsDWGoHZGE NwXF0xgUB527X6s/fjhKHH1+g245KTAprbTHF+tbMB81slW6nLv3sDIz03fA6G1D1tSJ np9YVy1YVDzDWk1kxxpgehK3oQaW613W1ZwiAKuSsv/ctimBgGfK9RVbXxDD/OTaykHm dLUgrGWP8XSxLS9xwr1oblBqc3KPotmFrgHPB53sTIO8sxVUOV79CdhC+MMP/EU9tR8g dQ2yReCfOz5vI9XtE1aV/eMSzSDhU9JWZ86mqxkoYafAGvvTv15O1R4hBUC66nCDDfPU xvyQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=IZ5njUsMjpaWj9YOz1Vm++un7O5+eC1XTxzvAZerpow=; b=s3zNVbV1Ok+XN+pRutS5sAio7t8zXkRWp5Xlvo0mWuheKRInJ+Jxw1q2CbKi1tY0YJ zuQXvXHSHoP/lnqB3ugoXvHZ36kyAcbsmh12PizLLHCmWwZKpTKNjisz1+F2pJMeOPFv 81/gxdb8D5eSJYfRiRZ76xEIjka349lhwLM4iUKLdo+CBrGSN/76ZeDSK4983Jz4PRsa CRQOiZYF+DBZvMyNZ4gnhgQmzlBfNjCThR9RqAskwrn15JFnY6hHGdKu5L7MEXyPVsb0 jQpbsnQmlLTBU2VMvFiXj6ZtexevPAWW/pJwkTChlkReAt824/15m+wvCkQ5/Kb82MQs 6rjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=faWAR8yx; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pk21-20020a170906d7b500b0078db6f488c2si620611ejb.56.2022.10.13.14.11.33; Thu, 13 Oct 2022 14:11:59 -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=@gmail.com header.s=20210112 header.b=faWAR8yx; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229559AbiJMVHR (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Thu, 13 Oct 2022 17:07:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229550AbiJMVHQ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 13 Oct 2022 17:07:16 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25F33183DB8; Thu, 13 Oct 2022 14:07:15 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id fy4so6565008ejc.5; Thu, 13 Oct 2022 14:07:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IZ5njUsMjpaWj9YOz1Vm++un7O5+eC1XTxzvAZerpow=; b=faWAR8yx9y/ximCfiagbNCy/0PAKrBsY8wEvnxUxd7VFrwze8WrW/LXuOEsD1B1MgC bmzapz1zdHF1jE76T+mA54DNMXKki/cswG3sXkx6RAEOiC9LYHXvBWUkBqkVC/OutC6w TBoPedYKZEP4+ld5ZJzts0nQv+3AjeM1WBzF9oIZsaGYMjz2koC525mlMh4cImsSStp6 XSWzJkXeoFofq4dZ0tkjtoHD4Jl4nliDAg9B+Vd6RKf38AjPS//hn7h+QcZjjgk0xM+g X3Q+S3ElOX8GsPkSJbBAoFNFKK+vjKbNMwCVHL9RQlOConV4BRjaHXXF9yIEoDbdhF1L 19Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IZ5njUsMjpaWj9YOz1Vm++un7O5+eC1XTxzvAZerpow=; b=JrAgMraWu9PHel5PSEmuAjHc+NRsWwuD5UjI2njwqbWzvA1+e+qRablmULnEt+5Ehp HVGYkMUYyOW1hDjuHGuAQjSQJkPbF1QiLhlrogPEL8xKnrQExHCQiDRtO1DN+OBi2BXt qDsbCCFE5ZNBxqFZq54bz9kna9uqR42Z2fmurVJXB620vharTvZtAS2FVXUGPHIuhcfm 93hDFB+BoMfZ6G8MwfkRUbHSm6zc1hpn2gKKiorhmkqWzbtepSYpQ1vBzMYgM821anga empHjWbIPb67nKnpc6DatZaZybQsGlwQQpQ8vgBhA+9JXm+rsnFdGFSpoSY+TZf9pCIk ZXqw== X-Gm-Message-State: ACrzQf0sAnlrVlRbJntAcXjAF0s/AnFkWJQzhhqYZVhgJuFDmXtQnrL6 INeu+/dGUimt90HmsPEbeoA= X-Received: by 2002:a17:907:980e:b0:78d:b6d5:661e with SMTP id ji14-20020a170907980e00b0078db6d5661emr1253849ejc.46.1665695233566; Thu, 13 Oct 2022 14:07:13 -0700 (PDT) Received: from localhost.localdomain (host-95-250-231-122.retail.telecomitalia.it. [95.250.231.122]) by smtp.gmail.com with ESMTPSA id v25-20020a17090651d900b0078da24ea9c7sm443973ejk.17.2022.10.13.14.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 14:07:12 -0700 (PDT) From: "Fabio M. De Francesco" <fmdefrancesco@gmail.com> To: Alex Deucher <alexander.deucher@amd.com>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com>, "Pan, Xinhui" <Xinhui.Pan@amd.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Christian Brauner <brauner@kernel.org>, Sumit Semwal <sumit.semwal@linaro.org>, Jean Delvare <jdelvare@suse.com>, Guenter Roeck <linux@roeck-us.net>, Kees Cook <keescook@chromium.org>, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-hwmon@vger.kernel.org, linux-hardening@vger.kernel.org Cc: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>, "Venkataramanan, Anirudh" <anirudh.venkataramanan@intel.com>, Ira Weiny <ira.weiny@intel.com> Subject: [PATCH] drm/radeon: Replace kmap() with kmap_local_page() Date: Thu, 13 Oct 2022 23:07:14 +0200 Message-Id: <20221013210714.16320-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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?1746608344778052444?= X-GMAIL-MSGID: =?utf-8?q?1746608344778052444?= |
Series |
drm/radeon: Replace kmap() with kmap_local_page()
|
|
Commit Message
Fabio M. De Francesco
Oct. 13, 2022, 9:07 p.m. UTC
The use of kmap() is being deprecated in favor of kmap_local_page().
There are two main problems with kmap(): (1) It comes with an overhead as
the mapping space is restricted and protected by a global lock for
synchronization and (2) it also requires global TLB invalidation when the
kmap’s pool wraps and it might block when the mapping space is fully
utilized until a slot becomes available.
With kmap_local_page() the mappings are per thread, CPU local, can take
page faults, and can be called from any context (including interrupts).
It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore,
the tasks can be preempted and, when they are scheduled to run again, the
kernel virtual addresses are restored and still valid.
Therefore, replace kmap() with kmap_local_page() in radeon_ttm_gtt_read().
Cc: "Venkataramanan, Anirudh" <anirudh.venkataramanan@intel.com>
Suggested-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
drivers/gpu/drm/radeon/radeon_ttm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On Thu, Oct 13, 2022 at 11:07:14PM +0200, Fabio M. De Francesco wrote: > The use of kmap() is being deprecated in favor of kmap_local_page(). > > There are two main problems with kmap(): (1) It comes with an overhead as > the mapping space is restricted and protected by a global lock for > synchronization and (2) it also requires global TLB invalidation when the > kmap’s pool wraps and it might block when the mapping space is fully > utilized until a slot becomes available. > > With kmap_local_page() the mappings are per thread, CPU local, can take > page faults, and can be called from any context (including interrupts). > It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, > the tasks can be preempted and, when they are scheduled to run again, the > kernel virtual addresses are restored and still valid. > > Therefore, replace kmap() with kmap_local_page() in radeon_ttm_gtt_read(). > > Cc: "Venkataramanan, Anirudh" <anirudh.venkataramanan@intel.com> > Suggested-by: Ira Weiny <ira.weiny@intel.com> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Reviewed-by: Kees Cook <keescook@chromium.org>
Am 13.10.22 um 23:07 schrieb Fabio M. De Francesco: > The use of kmap() is being deprecated in favor of kmap_local_page(). > > There are two main problems with kmap(): (1) It comes with an overhead as > the mapping space is restricted and protected by a global lock for > synchronization and (2) it also requires global TLB invalidation when the > kmap’s pool wraps and it might block when the mapping space is fully > utilized until a slot becomes available. > > With kmap_local_page() the mappings are per thread, CPU local, can take > page faults, and can be called from any context (including interrupts). > It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, > the tasks can be preempted and, when they are scheduled to run again, the > kernel virtual addresses are restored and still valid. > > Therefore, replace kmap() with kmap_local_page() in radeon_ttm_gtt_read(). > > Cc: "Venkataramanan, Anirudh" <anirudh.venkataramanan@intel.com> > Suggested-by: Ira Weiny <ira.weiny@intel.com> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Reviewed-by: Christian König <christian.koenig@amd.com> > --- > drivers/gpu/drm/radeon/radeon_ttm.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c > index d33fec488713..bdb4c0e0736b 100644 > --- a/drivers/gpu/drm/radeon/radeon_ttm.c > +++ b/drivers/gpu/drm/radeon/radeon_ttm.c > @@ -869,11 +869,11 @@ static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf, > > page = rdev->gart.pages[p]; > if (page) { > - ptr = kmap(page); > + ptr = kmap_local_page(page); > ptr += off; > > r = copy_to_user(buf, ptr, cur_size); > - kunmap(rdev->gart.pages[p]); > + kunmap_local(ptr); > } else > r = clear_user(buf, cur_size); >
Applied. Thanks! On Fri, Oct 14, 2022 at 3:03 AM Christian König <christian.koenig@amd.com> wrote: > > Am 13.10.22 um 23:07 schrieb Fabio M. De Francesco: > > The use of kmap() is being deprecated in favor of kmap_local_page(). > > > > There are two main problems with kmap(): (1) It comes with an overhead as > > the mapping space is restricted and protected by a global lock for > > synchronization and (2) it also requires global TLB invalidation when the > > kmap’s pool wraps and it might block when the mapping space is fully > > utilized until a slot becomes available. > > > > With kmap_local_page() the mappings are per thread, CPU local, can take > > page faults, and can be called from any context (including interrupts). > > It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, > > the tasks can be preempted and, when they are scheduled to run again, the > > kernel virtual addresses are restored and still valid. > > > > Therefore, replace kmap() with kmap_local_page() in radeon_ttm_gtt_read(). > > > > Cc: "Venkataramanan, Anirudh" <anirudh.venkataramanan@intel.com> > > Suggested-by: Ira Weiny <ira.weiny@intel.com> > > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> > > Reviewed-by: Christian König <christian.koenig@amd.com> > > > --- > > drivers/gpu/drm/radeon/radeon_ttm.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c > > index d33fec488713..bdb4c0e0736b 100644 > > --- a/drivers/gpu/drm/radeon/radeon_ttm.c > > +++ b/drivers/gpu/drm/radeon/radeon_ttm.c > > @@ -869,11 +869,11 @@ static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf, > > > > page = rdev->gart.pages[p]; > > if (page) { > > - ptr = kmap(page); > > + ptr = kmap_local_page(page); > > ptr += off; > > > > r = copy_to_user(buf, ptr, cur_size); > > - kunmap(rdev->gart.pages[p]); > > + kunmap_local(ptr); > > } else > > r = clear_user(buf, cur_size); > > >
On lunedì 17 ottobre 2022 18:52:10 CET Alex Deucher wrote:
> Applied. Thanks!
Many thanks to you!
However, about a week ago, I received a report saying that this patch is "Not
Applicable".
That email was also referring to another patch, for which I'll reply in its
own thread.
That report has a link to https://patchwork.linuxtv.org/project/linux-media/
patch/20221013210714.16320-1-fmdefrancesco@gmail.com/
Can you please let me understand why, despite it was applied, this patch later
shifted "State" to "Not Applicable"?
Thanks,
Fabio
On Wed, Nov 02, 2022 at 12:11:53AM +0100, Fabio M. De Francesco wrote: > On lunedì 17 ottobre 2022 18:52:10 CET Alex Deucher wrote: > > Applied. Thanks! > > Many thanks to you! > > However, about a week ago, I received a report saying that this patch is "Not > Applicable". > > That email was also referring to another patch, for which I'll reply in its > own thread. > > That report has a link to https://patchwork.linuxtv.org/project/linux-media/ > patch/20221013210714.16320-1-fmdefrancesco@gmail.com/ > > Can you please let me understand why, despite it was applied, this patch later > shifted "State" to "Not Applicable"? The kernel has multiple patchwork instances, so you got an "N/A" from linux-media, but it was applied to the drm tree. (Yes, confusing. :P)
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index d33fec488713..bdb4c0e0736b 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -869,11 +869,11 @@ static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf, page = rdev->gart.pages[p]; if (page) { - ptr = kmap(page); + ptr = kmap_local_page(page); ptr += off; r = copy_to_user(buf, ptr, cur_size); - kunmap(rdev->gart.pages[p]); + kunmap_local(ptr); } else r = clear_user(buf, cur_size);