From patchwork Sun Oct 16 17:41:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 3133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1103924wrs; Sun, 16 Oct 2022 10:54:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM43c0R7Z07kwoK2RLzGa5JBD7jeecrP9qqbi2+diTZD9/bSiD/jV7GbsWLbDSIhlN8AaB5C X-Received: by 2002:a17:902:8c81:b0:178:a33f:8b8f with SMTP id t1-20020a1709028c8100b00178a33f8b8fmr8237578plo.50.1665942868234; Sun, 16 Oct 2022 10:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665942868; cv=none; d=google.com; s=arc-20160816; b=mcYN8quqbEj5kE0qZlnVxW3OMmvoCFEErxvqV7ppb/w4/DT2mt/DpNRVXSfFY+xqn0 I/OYwAai69Z5T4GEmYxap6OfCK7SYNYFr15vzNRBRgxmdzObTQLcvPQdFtg8kGhxqIPC AbxNLDFYzNlWJNfdLrNSYGmluDu1Wft/PQC7C+K7KtXoJ7vSzXUHkFlgvnx8+v2jiscM gPy8XCoFpfx2QwLsC8s8u9VjRKHBA+XUMUFgNR9czayK6nUOg/rjaMG2zIY5JZbQH1AL +ANIJim33so/XqeSYTmVng5D0GrwU1vOEWWOC2g7Omjs2/It3zequfZmrV1WiTosjofW QKNQ== 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 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.15; Sun, 16 Oct 2022 10:54:28 -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_K=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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746867709095661023?= X-GMAIL-MSGID: =?utf-8?q?1746867709095661023?= 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;