From nobody Mon Apr 6 11:52:01 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F6D1C4332F for ; Mon, 17 Oct 2022 09:34:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230380AbiJQJd6 (ORCPT ); Mon, 17 Oct 2022 05:33:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231394AbiJQJdV (ORCPT ); Mon, 17 Oct 2022 05:33:21 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04FBB5AA1C for ; Mon, 17 Oct 2022 02:33:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999184; x=1697535184; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7DWIlBvRBPlI7C3mshKcaEtH4mYWv0nITpy5+EZ8lew=; b=AFAu9yFKR+W+9Ub/PyHTDF3LQvZxFE451L5OmLOUmEIaRlsXl5IOb1T0 e+aLuZ/InWvpWHAaRqbwwkDJXoIzPICHdfYs+Qw0zI6yhiBXVX3aTq4F+ kNqvWzkqtxxuesIjr2VGzPDjJrFaLEUnZ2RgkcCrDxiPahz5cNUSpEDoP ZReu8PubTpojKbW4wI5C9BdDVsa37BPmXAPgverJo41z0lnLZSw0PRmc9 B36sIo2Rj92vpm/D/fxxBAcU9F13Dwq0RrZRoBgEkzxMivQNcM+ufvlJT oJXiGIxLwAcFlTxkulnxUt34afzqI36YriKvlcROs8oDnk30kPfW0TSsc w==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741669" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741669" 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:33:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431351" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431351" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:33:00 -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 Subject: [PATCH v3] x86/hyperv: Replace kmap() with kmap_local_page() Date: Mon, 17 Oct 2022 17:37:26 +0800 Message-Id: <20221017093726.2070674-11-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Zhao Liu kmap() is being deprecated in favor of kmap_local_page()[1]. There are two main problems with kmap(): (1) It comes with an overhead as m= apping space is restricted and protected by a global lock for synchronizati= on and (2) it also requires global TLB invalidation when the kmap's pool wr= aps and it might block when the mapping space is fully utilized until a slo= t becomes available. With kmap_local_page() the mappings are per thread, CPU local, can take pag= e 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 kerne= l virtual addresses are restored and are still valid. Since its use in hyperv/hv_init.c is safe, it should be preferred. Therefore, replace kmap() with kmap_local_page() in hyperv/hv_init.c. [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu --- Suggested by credits. Ira: Referred to his task documentation and review comments. Fabio: Stole some of his boiler plate commit message. --- Changelog: v2: - Fix wrong incoming parameters in kunmap_local(); - Add Fabio as suggester since I quoted his commit message. --- arch/x86/hyperv/hv_init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 3de6d8b53367..72fe46eb183f 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -459,13 +459,13 @@ void __init hyperv_init(void) wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); pg =3D vmalloc_to_page(hv_hypercall_pg); - dst =3D kmap(pg); + dst =3D kmap_local_page(pg); src =3D memremap(hypercall_msr.guest_physical_address << PA= GE_SHIFT, PAGE_SIZE, MEMREMAP_WB); BUG_ON(!(src && dst)); memcpy(dst, src, HV_HYP_PAGE_SIZE); memunmap(src); - kunmap(pg); + kunmap_local(dst); } else { hypercall_msr.guest_physical_address =3D vmalloc_to_pfn(hv_= hypercall_pg); wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); -- 2.34.1