On Fri, Apr 03, 2015 at 05:40:55PM +0200, Quentin Casasnovas wrote:
> So yeah I still think we're not properly padding, if you take my earlier
> example where repl2 = 5 bytes, repl1 = 4 bytes and orin_insn = 3.
> 
> I'll let you re-read my original mail and come back to me to tell me what'd
> I really miss! :)

Dammit, dammit, dammit!

And I thought this aspect was taken care of. I went into the old
branches where I had done this and there I have:

+#define OLDINSTR_2(oldinstr, num1, num2)                               \
+       __OLDINSTR(oldinstr, num1)                                      \
+       ".skip -(((" alt_rlen(num2) ")-(" alt_rlen(num1) ")) > 0) * "   \
+               "((" alt_rlen(num2) ")-(" alt_rlen(num1) ")),0x90\n"    \
+       alt_end_marker ":\n"
+

without the size of the orig_insn factored in into the padding.

And that would work for your example because it would add 1+1 bytes
padding.

Basically, the idea was:

.skip len(repl1) - len(orig), 0x90
.skip len(repl2) - len(repl1), 0x90

BUT!, for some reason I changed it to what's there now and I can't
remember why anymore.

IOW, this should fix your example but I need to think about it on a
clear head first, to try to remember what was the problem with that
original approach:

---
diff --git a/arch/x86/include/asm/alternative-asm.h 
b/arch/x86/include/asm/alternative-asm.h
index 524bddce0b76..708838260f7c 100644
--- a/arch/x86/include/asm/alternative-asm.h
+++ b/arch/x86/include/asm/alternative-asm.h
@@ -50,7 +50,7 @@
        \oldinstr
 141:
        .skip -(((144f-143f)-(141b-140b)) > 0) * ((144f-143f)-(141b-140b)),0x90
-       .skip -(((145f-144f)-(144f-143f)-(141b-140b)) > 0) * 
((145f-144f)-(144f-143f)-(141b-140b)),0x90
+       .skip -(((145f-144f)-(144f-143f)) > 0) * ((145f-144f)-(144f-143f)),0x90
 142:
 
        .pushsection .altinstructions,"a"
diff --git a/arch/x86/include/asm/alternative.h 
b/arch/x86/include/asm/alternative.h
index 5aef6a97d80e..2b8cc1dd7dbf 100644
--- a/arch/x86/include/asm/alternative.h
+++ b/arch/x86/include/asm/alternative.h
@@ -101,8 +101,8 @@ static inline int alternatives_text_reserved(void *start, 
void *end)
  */
 #define OLDINSTR_2(oldinstr, num1, num2)                                       
\
        __OLDINSTR(oldinstr, num1)                                              
\
-       ".skip -(((" alt_rlen(num2) ")-(" alt_rlen(num1) ")-(662b-661b)) > 0) * 
" \
-               "((" alt_rlen(num2) ")-(" alt_rlen(num1) 
")-(662b-661b)),0x90\n"  \
+       ".skip -(((" alt_rlen(num2) ")-(" alt_rlen(num1) ")) > 0) * " \
+               "((" alt_rlen(num2) ")-(" alt_rlen(num1) ")),0x90\n"  \
        alt_end_marker ":\n"
 
 #define ALTINSTR_ENTRY(feature, num)                                         \
---

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to