From: "Jan Beulich" Subject: [PATCH v2 3/4] x86: move I/O emulation stubs off the stack Date: Thu, 21 May 2015 11:17:03 +0100 Message-ID: <555DCCBF020000780007CAA6@mail.emea.novell.com> References: <555DCA7C020000780007CA7E@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part5F6B5A8F.1__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YvNXG-0004V9-Ka for xen-devel@lists.xenproject.org; Thu, 21 May 2015 10:17:06 +0000 In-Reply-To: <555DCA7C020000780007CA7E@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Andrew Cooper , Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part5F6B5A8F.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This is needed as stacks are going to become non-executable. Signed-off-by: Jan Beulich --- v2: Use ~PAGE_MASK instead of PAGE_SIZE - 1 for page offset masking. Comment adjustments. --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -2006,7 +2006,7 @@ static int emulate_privileged_op(struct=20 ? (*(u32 *)®s->reg =3D (val)) \ : (*(u16 *)®s->reg =3D (val))) unsigned long code_base, code_limit; - char io_emul_stub[32]; + char *io_emul_stub =3D NULL; void (*io_emul)(struct cpu_user_regs *) __attribute__((__regparm__(1))= ); uint64_t val; =20 @@ -2191,10 +2191,13 @@ static int emulate_privileged_op(struct=20 =20 /* * Very likely to be an I/O instruction (IN/OUT). - * Build an on-stack stub to execute the instruction with full guest - * GPR context. This is needed for some systems which (ab)use IN/OUT + * Build an stub to execute the instruction with full guest GPR + * context. This is needed for some systems which (ab)use IN/OUT * to communicate with BIOS code in system-management mode. */ + io_emul_stub =3D map_domain_page(this_cpu(stubs.mfn)) + + (this_cpu(stubs.addr) & ~PAGE_MASK) + + STUB_BUF_SIZE / 2; /* movq $host_to_guest_gpr_switch,%rcx */ io_emul_stub[0] =3D 0x48; io_emul_stub[1] =3D 0xb9; @@ -2212,7 +2215,7 @@ static int emulate_privileged_op(struct=20 io_emul_stub[15] =3D 0xc3; =20 /* Handy function-typed pointer to the stub. */ - io_emul =3D (void *)io_emul_stub; + io_emul =3D (void *)(this_cpu(stubs.addr) + STUB_BUF_SIZE / 2); =20 if ( ioemul_handle_quirk ) ioemul_handle_quirk(opcode, &io_emul_stub[12], regs); @@ -2777,9 +2780,13 @@ static int emulate_privileged_op(struct=20 done: instruction_done(regs, eip, bpmatch); skip: + if ( io_emul_stub ) + unmap_domain_page(io_emul_stub); return EXCRET_fault_fixed; =20 fail: + if ( io_emul_stub ) + unmap_domain_page(io_emul_stub); return 0; } =20 --=__Part5F6B5A8F.1__= Content-Type: text/plain; name="x86-ioemul-stub.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-ioemul-stub.patch" x86: move I/O emulation stubs off the stack=0A=0AThis is needed as stacks = are going to become non-executable.=0A=0ASigned-off-by: Jan Beulich = =0A---=0Av2: Use ~PAGE_MASK instead of PAGE_SIZE - 1 = for page offset masking.=0A Comment adjustments.=0A=0A--- a/xen/arch/x86= /traps.c=0A+++ b/xen/arch/x86/traps.c=0A@@ -2006,7 +2006,7 @@ static int = emulate_privileged_op(struct =0A ? (*(u32 = *)®s->reg =3D (val)) \=0A : (*(u16 *)®s->r= eg =3D (val)))=0A unsigned long code_base, code_limit;=0A- char = io_emul_stub[32];=0A+ char *io_emul_stub =3D NULL;=0A void = (*io_emul)(struct cpu_user_regs *) __attribute__((__regparm__(1)));=0A = uint64_t val;=0A =0A@@ -2191,10 +2191,13 @@ static int emulate_privileged_o= p(struct =0A =0A /*=0A * Very likely to be an I/O instruction = (IN/OUT).=0A- * Build an on-stack stub to execute the instruction with = full guest=0A- * GPR context. This is needed for some systems which = (ab)use IN/OUT=0A+ * Build an stub to execute the instruction with = full guest GPR=0A+ * context. This is needed for some systems which = (ab)use IN/OUT=0A * to communicate with BIOS code in system-management= mode.=0A */=0A+ io_emul_stub =3D map_domain_page(this_cpu(stubs.mf= n)) +=0A+ (this_cpu(stubs.addr) & ~PAGE_MASK) +=0A+ = STUB_BUF_SIZE / 2;=0A /* movq $host_to_guest_gpr_switch,%r= cx */=0A io_emul_stub[0] =3D 0x48;=0A io_emul_stub[1] =3D = 0xb9;=0A@@ -2212,7 +2215,7 @@ static int emulate_privileged_op(struct =0A = io_emul_stub[15] =3D 0xc3;=0A =0A /* Handy function-typed pointer = to the stub. */=0A- io_emul =3D (void *)io_emul_stub;=0A+ io_emul = =3D (void *)(this_cpu(stubs.addr) + STUB_BUF_SIZE / 2);=0A =0A if ( = ioemul_handle_quirk )=0A ioemul_handle_quirk(opcode, &io_emul_stub[= 12], regs);=0A@@ -2777,9 +2780,13 @@ static int emulate_privileged_op(struc= t =0A done:=0A instruction_done(regs, eip, bpmatch);=0A skip:=0A+ = if ( io_emul_stub )=0A+ unmap_domain_page(io_emul_stub);=0A = return EXCRET_fault_fixed;=0A =0A fail:=0A+ if ( io_emul_stub )=0A+ = unmap_domain_page(io_emul_stub);=0A return 0;=0A }=0A =0A --=__Part5F6B5A8F.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part5F6B5A8F.1__=--