public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Zhao Liu <zhao1.liu@intel.com>,
	Dave Hansen <dave.hansen@intel.com>,
	Ira Weiny <ira.weiny@intel.com>,
	"Fabio M . De Francesco" <fmdefrancesco@gmail.com>,
	Wei Liu <wei.liu@kernel.org>, Sasha Levin <sashal@kernel.org>,
	kys@microsoft.com, haiyangz@microsoft.com,
	sthemmin@microsoft.com, decui@microsoft.com, tglx@linutronix.de,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	x86@kernel.org, linux-hyperv@vger.kernel.org
Subject: [PATCH AUTOSEL 5.15 14/21] x86/hyperv: Replace kmap() with kmap_local_page()
Date: Mon, 17 Oct 2022 20:09:33 -0400	[thread overview]
Message-ID: <20221018000940.2731329-14-sashal@kernel.org> (raw)
In-Reply-To: <20221018000940.2731329-1-sashal@kernel.org>

From: Zhao Liu <zhao1.liu@intel.com>

[ Upstream commit 154fb14df7a3c81dea82eca7c0c46590f5ffc3d2 ]

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
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.

In the fuction hyperv_init() of hyperv/hv_init.c, the mapping is used in a
single thread and is short live. So, in this case, it's safe to simply use
kmap_local_page() to create mapping, and this avoids the wasted cost of
kmap() for global synchronization.

In addtion, the fuction hyperv_init() checks if kmap() fails by BUG_ON().
From the original discussion[2], the BUG_ON() here is just used to
explicitly panic NULL pointer. So still keep the BUG_ON() in place to check
if kmap_local_page() fails. Based on this consideration, memcpy_to_page()
is not selected here but only kmap_local_page() is used.

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
[2]: https://lore.kernel.org/lkml/20200915103710.cqmdvzh5lys4wsqo@liuwe-devbox-debian-v2/

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>
Link: https://lore.kernel.org/r/20220928095640.626350-1-zhao1.liu@linux.intel.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 b6d48ca5b0f1..7c9288143943 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -407,13 +407,13 @@ void __init hyperv_init(void)
 		wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
 
 		pg = vmalloc_to_page(hv_hypercall_pg);
-		dst = kmap(pg);
+		dst = kmap_local_page(pg);
 		src = memremap(hypercall_msr.guest_physical_address << PAGE_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 = vmalloc_to_pfn(hv_hypercall_pg);
 		wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
-- 
2.35.1


  parent reply	other threads:[~2022-10-18  0:38 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18  0:09 [PATCH AUTOSEL 5.15 01/21] crypto: qcom-rng - Fix qcom_rng_of_match unused warning Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 02/21] crypto: ccp - Add a quirk to firmware update Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 03/21] gfs2: Switch from strlcpy to strscpy Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 04/21] powerpc/hw_breakpoint: Avoid relying on caller synchronization Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 05/21] cgroup: Remove data-race around cgrp_dfl_visible Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 06/21] of/fdt: Don't calculate initrd size from DT if start > end Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 07/21] objtool,x86: Teach decode about LOOP* instructions Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 08/21] locking/rwsem: Disable preemption while trying for rwsem lock Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 09/21] gfs2: Check sb_bsize_shift after reading superblock Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 10/21] powerpc/64: don't refer nr_cpu_ids in asm code when it's undefined Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 11/21] m68knommu: fix non-specific 68328 choice interrupt build failure Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 12/21] m68knommu: fix non-mmu classic 68000 legacy timer tick selection Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 13/21] of: Fix "dma-ranges" handling for bus controllers Sasha Levin
2022-10-18  0:09 ` Sasha Levin [this message]
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 15/21] kmsan: disable instrumentation of unsupported common kernel code Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 16/21] kmsan: disable physical page merging in biovec Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 17/21] f2fs: fix to detect corrupted meta ino Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 18/21] 9p: trans_fd/p9_conn_cancel: drop client lock earlier Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 19/21] 9p/trans_fd: always use O_NONBLOCK read/write Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 20/21] net/9p: use a dedicated spinlock for trans_fd Sasha Levin
2022-10-18  0:09 ` [PATCH AUTOSEL 5.15 21/21] virtio_pci: don't try to use intxif pin is zero Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221018000940.2731329-14-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=decui@microsoft.com \
    --cc=fmdefrancesco@gmail.com \
    --cc=haiyangz@microsoft.com \
    --cc=ira.weiny@intel.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=sthemmin@microsoft.com \
    --cc=tglx@linutronix.de \
    --cc=wei.liu@kernel.org \
    --cc=x86@kernel.org \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox