linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhao Liu <zhao1.liu@linux.intel.com>
To: Wei Liu <wei.liu@kernel.org>
Cc: "K . Y . Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Dexuan Cui <decui@microsoft.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ira Weiny <ira.weiny@intel.com>,
	"Fabio M . De Francesco" <fmdefrancesco@gmail.com>,
	Zhenyu Wang <zhenyu.z.wang@intel.com>,
	Zhao Liu <zhao1.liu@intel.com>
Subject: Re: [PATCH] x86/hyperv: Replace kmap() with kmap_local_page()
Date: Mon, 10 Oct 2022 20:06:01 +0800	[thread overview]
Message-ID: <Y0QKqS2Ojr+7KYmp@liuzhao-OptiPlex-7080> (raw)
In-Reply-To: <Y0MzKa1nzfP+mhtX@liuwe-devbox-debian-v2>

On Sun, Oct 09, 2022 at 08:46:33PM +0000, Wei Liu wrote:
> Date: Sun, 9 Oct 2022 20:46:33 +0000
> From: Wei Liu <wei.liu@kernel.org>
> Subject: Re: [PATCH] x86/hyperv: Replace kmap() with kmap_local_page()
> 
> On Thu, Oct 06, 2022 at 10:21:43PM +0800, Zhao Liu wrote:
> > On Mon, Oct 03, 2022 at 08:50:16AM +0000, Wei Liu wrote:
> > > Date: Mon, 3 Oct 2022 08:50:16 +0000
> > > From: Wei Liu <wei.liu@kernel.org>
> > > Subject: Re: [PATCH] x86/hyperv: Replace kmap() with kmap_local_page()
> > > 
> > > On Wed, Sep 28, 2022 at 02:08:40PM +0000, Wei Liu wrote:
> > > > On Wed, Sep 28, 2022 at 05:56:40PM +0800, Zhao Liu wrote:
> > > > > From: Zhao Liu <zhao1.liu@intel.com>
> > > > > 
> > > > > 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.
> > > > > 
> > > > 
> > > > The kmap call in that function is not performance critical in any way,
> > > > and at this point in the initialization process I don't expect there to
> > > > be any contention, so the downside of kmap is not really a concern here.
> > > > 
> > > > That being said, kmap getting deprecated is a good enough reason to
> > > > switch to kmap_local_page. And I appreciate this well-written,
> > > > well-reasoned commit message.
> > > > 
> > > > I will apply it to hyperv-next later -- I doubt people will object to
> > > > this change, but just in case.
> > > 
> > > Applied to hyperv-next. Thanks.
> > 
> > Sorry Wei, based on Ira and Fabio's comments, do you agree me to send a
> > follow on patch to remove that BUG_ON()? Or send the v2 patch?
> > 
> 
> I just sent a PR to Linus. That PR includes your v1 patch.
> 
> While the code can be improved, BUG_ON that does nothing is harmless.
> You can send a follow-up patch to remove the BUG_ON.

Thanks Wei! I'll do that.

Regards,
Zhao

> 
> Thanks,
> Wei.
> 
> > Thanks,
> > Zhao

  reply	other threads:[~2022-10-10 12:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-28  9:56 [PATCH] x86/hyperv: Replace kmap() with kmap_local_page() Zhao Liu
2022-09-28 14:08 ` Wei Liu
2022-10-03  8:50   ` Wei Liu
2022-10-06 14:21     ` Zhao Liu
2022-10-09 20:46       ` Wei Liu
2022-10-10 12:06         ` Zhao Liu [this message]
2022-10-03 17:43 ` Fabio M. De Francesco
2022-10-03 20:24   ` Ira Weiny
2022-10-06 14:13     ` Zhao Liu

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=Y0QKqS2Ojr+7KYmp@liuzhao-OptiPlex-7080 \
    --to=zhao1.liu@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=decui@microsoft.com \
    --cc=fmdefrancesco@gmail.com \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.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=sthemmin@microsoft.com \
    --cc=tglx@linutronix.de \
    --cc=wei.liu@kernel.org \
    --cc=x86@kernel.org \
    --cc=zhao1.liu@intel.com \
    --cc=zhenyu.z.wang@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;
as well as URLs for NNTP newsgroup(s).