From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx186.postini.com [74.125.245.186]) by kanga.kvack.org (Postfix) with SMTP id 245D96B004F for ; Thu, 26 Jan 2012 13:28:50 -0500 (EST) Received: by wibhj13 with SMTP id hj13so856095wib.14 for ; Thu, 26 Jan 2012 10:28:48 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <4F215FCE.8010209@hitachi.com> References: <20120110114821.17610.9188.sendpatchset@srdronam.in.ibm.com> <20120110114831.17610.88468.sendpatchset@srdronam.in.ibm.com> <4F215FCE.8010209@hitachi.com> From: Denys Vlasenko Date: Thu, 26 Jan 2012 19:28:28 +0100 Message-ID: Subject: Re: [PATCH v9 3.2 1/9] uprobes: Install and remove breakpoints. Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sender: owner-linux-mm@kvack.org List-ID: To: Masami Hiramatsu Cc: Srikar Dronamraju , Peter Zijlstra , Linus Torvalds , Oleg Nesterov , Ingo Molnar , Andrew Morton , LKML , Linux-mm , Andi Kleen , Christoph Hellwig , Steven Rostedt , Roland McGrath , Thomas Gleixner , Arnaldo Carvalho de Melo , Anton Arapov , Ananth N Mavinakayanahalli , Jim Keniston , Stephen Rothwell , yrl.pp-manager.tt@hitachi.com On Thu, Jan 26, 2012 at 3:14 PM, Masami Hiramatsu wrote: > (2012/01/26 0:32), Denys Vlasenko wrote: >> On Wed, Jan 25, 2012 at 4:13 PM, Denys Vlasenko >> wrote: >>>> + =A0 =A0 =A0 /* >>>> + =A0 =A0 =A0 =A0* Convert from rip-relative addressing to indirect ad= dressing >>>> + =A0 =A0 =A0 =A0* via a scratch register. =A0Change the r/m field fro= m 0x5 (%rip) >>>> + =A0 =A0 =A0 =A0* to 0x0 (%rax) or 0x1 (%rcx), and squeeze out the of= fset field. >>>> + =A0 =A0 =A0 =A0*/ >>>> + =A0 =A0 =A0 reg =3D MODRM_REG(insn); >>>> + =A0 =A0 =A0 if (reg =3D=3D 0) { >>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* >>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* The register operand (if any) is ei= ther the A register >>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* (%rax, %eax, etc.) or (if the 0x4 b= it is set in the >>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* REX prefix) %r8. =A0In any case, we= know the C register >>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* is NOT the register operand, so we = use %rcx (register >>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* #1) for the scratch register. >>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/ >>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 uprobe->arch_info.fixups =3D UPROBES_FIX= _RIP_CX; >>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Change modrm from 00 000 101 to 00 00= 0 001. */ >>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 *cursor =3D 0x1; >> >> Hmm. I think we have a bug here. >> >> What if this instruction has REX.B =3D 1? Granted, REX.B =3D 1 has no ef= fect on >> rip-relative addressing and therefore normally won't be generated by gcc= /as, >> but still. If you replace md and r/m fields as above, you are trying to = convert >> 0x12345678(%rip) reference to (%rcx), but if REX.B =3D 1, then you in fa= ct >> converted it to (%r9)! > > Right, thanks for finding :) > And %rax register reference encoding has same problem, doesn't it? Yes. The solution is trivial: "if (REX pfx exists) REX.B =3D 0;" Also, I don't remember whether (%rip) addressing is affected by 0x67 (address size) prefix. If it is, then nothing needs to be done. But if there is an exception and CPU ignores 0x67 pfx for (%rip) addressing, we will need to check for and remove this pfx. Otherwise, it'll instruct to use 32-bit registers for addressing, thus it will turn our (%rax) operand into (%eax). Not good. --=20 vda -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: email@kvack.org