Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3440191rwi; Sun, 16 Oct 2022 10:54:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7SICM5inRNVPW/muURXT8qyZ4K0dGzgyeqfbSLBxceCrL89DEMwADem/A6phw635ngrEFC X-Received: by 2002:a17:902:da8b:b0:178:3980:4597 with SMTP id j11-20020a170902da8b00b0017839804597mr8340529plx.113.1665942893304; Sun, 16 Oct 2022 10:54:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665942893; cv=none; d=google.com; s=arc-20160816; b=FmovkFaYQp+Ilko1tPMptdtH+hWEYQ60FIqoCXI2cAZMLekWuF+9EYD98nKfVV0DFV CcDop7pKnEkfU55HeIj/2VoYK4TbpaC9RMx5Uf1DPGYEn1e0Ky7Kzjuk3x7XW/ZXee9A zhE/Z7S/dtm6BIcSIJB3ZVq2M/fLLnJecyN8s3A6IxVRICfpqyvPxgGrjTzhBvBemzJv SuBXiUUi6PQXFo87xa6Gyzr9CP4zCH2ZzByGwFW41rCihFORnBNfw5+4xm8s8Mc0BCGD WkRumwJ8fFLpnE2CDYtW9H4FjkY7A2lLzMMkhiEMJzF08LRcEjG0nR/G+K8eGwuiyu/y fq1g== 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=eBoyZFJd/AMWfSTDdNDFLh542tiq7KT1lMhtwEfLBl4=; b=W6vjBm2XjABXax9ceasJLUTH1h/hEYTm5kYB6abjA6MP8FyAmnjHaBW5undZ9u1zRx u91vdKpfAnsqIU4WwOft2ogLtEGg78PAm5sThBBuWs3aO8GhKnmrt+4Ywil3bOfrXXSQ CHwewaNNU5NaCm0UPJmQ7Y/frrvG7jwtpzWcrNThq4rLuH6n/ysJnNaxI9ZeMWEeqxTC BxSpE59l2yQcQ9wF6FMrknw9wDSHIHz18gLagKHUT9CUSj6WgZVQ6/W+55EZ7c+fTxgd QZKLVXkERwpkrM2ymMczJS/t1XCHusOi1h7b+8lRx6M4FBvcUhC+ZyKkMyJyEXgtIxPw NnMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cyxXVAEq; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a170902748200b0017f7de72903si8850470pll.71.2022.10.16.10.54.41; Sun, 16 Oct 2022 10:54:53 -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=cyxXVAEq; 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 S229783AbiJPRmI (ORCPT + 99 others); Sun, 16 Oct 2022 13:42:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbiJPRmG (ORCPT ); Sun, 16 Oct 2022 13:42:06 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0D3531FAD for ; Sun, 16 Oct 2022 10:42:05 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id bv10so15102673wrb.4 for ; Sun, 16 Oct 2022 10:42:05 -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=eBoyZFJd/AMWfSTDdNDFLh542tiq7KT1lMhtwEfLBl4=; b=cyxXVAEqs04ujc9hmfAVf30HVL/pCnILfipPspTFlkQBjzFFQhNOx+3Hsnzv8IBT5Q mKEvizN9ZqA35pVXIw+GnMESFPCSiwgqiFLfLgeFQnvtyFNuAjpc5GCL4mrlNm6layTT tfKBWW0JurCzaM0BbS5VuSKwloE83tjuPMpK4CwXtoV1MMeTgVT1ms7B1Pvn5ROcOGB2 SkafGbGxB2jHqrTZaiTeYenHuoz4h7csoYTfWJxsVMuLmwu3efBD4YWun6Q0xYkebQe2 ZGrPENmNa2okAP3iFZNF+4OO8IfxofZNsEwgG4ir3pkbao1kcw9L0KinBv55MTRKeKK+ /hUA== 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=eBoyZFJd/AMWfSTDdNDFLh542tiq7KT1lMhtwEfLBl4=; b=uGbQvETC+WMsE+d+t/Pm/zTv694fmzEx44BJ49hAIrsEubHdZ7N/AHR2vjesOsE5Uq kCSM6dNOaRdlc9R4YmclO4j/IDd11YtaKaTldoEl4VWGEVezEskJqyCQKnLeSb9PyNDF 6X1KcEFXmiOZ7sdbgXvnF0duGEAuPRrpmRRp+gi402wMROLNAMPiJm0jwn2r/LfkUdWQ CdCbZ4NsBO87Omypt+NYXnLiVnU78c+jfQzzsyU4CZuzmFzLfGZpTYGF/KMS1s/ZrmeL XsIJ09e9SfG0Rwag1qLmKToQ214eK2nrVQYnGCSmhbp4zcbdqITYWw7uwHSV5+vm8pC2 91Uw== X-Gm-Message-State: ACrzQf0y36uDeLc60x+mjaQ+CSiu0SR4gEzeQPlDCM+j7pcuA+eIXcHF v05YFe01v18YdrZVPErmQek= X-Received: by 2002:a05:6000:1689:b0:22e:2c03:36e7 with SMTP id y9-20020a056000168900b0022e2c0336e7mr4464896wrd.252.1665942124233; Sun, 16 Oct 2022 10:42:04 -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 p14-20020a05600c468e00b003c6f3e5ba42sm2820940wmo.46.2022.10.16.10.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 10:42:03 -0700 (PDT) From: "Fabio M. De Francesco" To: Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hawking Zhang , Felix Kuehling , Tao Zhou , Jack Xiao , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: "Fabio M. De Francesco" , Ira Weiny Subject: [RESEND PATCH] drm/amd/amdgpu: Replace kmap() with kmap_local_page() Date: Sun, 16 Oct 2022 19:41:58 +0200 Message-Id: <20221016174158.16638-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.38.0 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: X-Mailing-List: linux-kernel@vger.kernel.org kmap() is being deprecated in favor of kmap_local_page(). There are two main problems with kmap(): (1) It comes with an overhead as 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 are still valid. Since its use in amdgpu/amdgpu_ttm.c is safe, it should be preferred. Therefore, replace kmap() with kmap_local_page() in amdgpu/amdgpu_ttm.c. Suggested-by: Ira Weiny Acked-by: Christian König Signed-off-by: Fabio M. De Francesco --- I'm resending because I suspect that this patch might have been lost. In the meantime I added an "Acked-by" tag from Christian K.. Obviviously, there are no further changes in the code. drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 3b4c19412625..c11657b5915f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -2301,9 +2301,9 @@ static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf, if (p->mapping != adev->mman.bdev.dev_mapping) return -EPERM; - ptr = kmap(p); + ptr = kmap_local_page(p); r = copy_to_user(buf, ptr + off, bytes); - kunmap(p); + kunmap_local(ptr); if (r) return -EFAULT; @@ -2352,9 +2352,9 @@ static ssize_t amdgpu_iomem_write(struct file *f, const char __user *buf, if (p->mapping != adev->mman.bdev.dev_mapping) return -EPERM; - ptr = kmap(p); + ptr = kmap_local_page(p); r = copy_from_user(ptr + off, buf, bytes); - kunmap(p); + kunmap_local(ptr); if (r) return -EFAULT; -- 2.37.1