From: Michael Ellerman Date: Thu, 19 Sep 2019 10:25:57 +0000 Subject: Re: [PATCH 1/4] powerpc/kvm: Move kvm_tmp into .text, shrink to 64K Message-Id: <46YtKg2dGGz9s4Y@ozlabs.org> List-Id: In-Reply-To: <20190911115746.12433-1-mpe@ellerman.id.au> References: <20190911115746.12433-1-mpe@ellerman.id.au> In-Reply-To: <20190911115746.12433-1-mpe@ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Michael Ellerman , linuxppc-dev@ozlabs.org Cc: cai@lca.pw, kvm-ppc@vger.kernel.org On Wed, 2019-09-11 at 11:57:43 UTC, Michael Ellerman wrote: > In some configurations of KVM, guests binary patch themselves to > avoid/reduce trapping into the hypervisor. For some instructions this > requires replacing one instruction with a sequence of instructions. > > For those cases we need to write the sequence of instructions > somewhere and then patch the location of the original instruction to > branch to the sequence. That requires that the location of the > sequence be within 32MB of the original instruction. > > The current solution for this is that we create a 1MB array in BSS, > write sequences into there, and then free the remainder of the array. > > This has a few problems: > - it confuses kmemleak. > - it confuses lockdep. > - it requires mapping kvm_tmp executable, which can cause adjacent > areas to also be mapped executable if we're using 16M pages for the > linear mapping. > - the 32MB limit can be exceeded if the kernel is big enough, > especially with STRICT_KERNEL_RWX enabled, which then prevents the > patching from working at all. > > We can fix all those problems by making kvm_tmp just a region of > regular .text. However currently it's 1MB in size, and we don't want > to waste 1MB of text. In practice however I only see ~30KB of kvm_tmp > being used even for an allyes_config. So shrink kvm_tmp to 64K, which > ought to be enough for everyone, and move it into .text. > > Signed-off-by: Michael Ellerman Series applied to powerpc next. https://git.kernel.org/powerpc/c/0cb0837f9db1a6ed5b764ef61dd5f1a314b8231a cheers