From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Arjan van de Ven <arjan@infradead.org>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [patch 0/8] Immediate Values
Date: Sun, 12 Aug 2007 14:55:01 -0400 [thread overview]
Message-ID: <20070812185501.GA4480@Krystal> (raw)
In-Reply-To: <1186943243.2854.17.camel@laptopd505.fenrus.org>
* Arjan van de Ven (arjan@infradead.org) wrote:
>
> On Sun, 2007-08-12 at 11:07 -0400, Mathieu Desnoyers wrote:
> > Hi Andrew,
> >
> > Here is the latest version of immediate values. It applies on 2.6.23-rc2-mm2 in
> > this order:
>
>
> I have a concern; you seem to be patching potentially "live" code....
>
> there are basically two options
> 1) you run the risk of triple faulting (patching an instruction while
> some other core/cpu may be decoding it may cause a triple fault)
> 2) you do an IPI to all other cpus and prevent them from executing any
> code except a small loop during the patching... this is expensive.
>
> To be honest, neither sound very attractive to me ;(
>
Yup, the concern is appropriate. That's why I dealt with it in the
"Immediate Values - i386 Optimization" patch. (I guess your concern
is specific to i386, x86_64 and ia64).
I have currently only implemented the i386 optimization, but x86_64 and
ia64 should be similar.
The triple fault in question is discussed in Intel's errata under the
title "Centrino Duo Processor Technology Specification Update, AH33.
Unsynchronized Cross-Modifying Code Operations Can Cause Unexpected
Instruction Execution Results." (if you refer to something else, please
tell me).
I discuss thoroughly the algorithm I use in the patch comments, which is
none of the two options you point out.
Quoting the patch:
"Overall design
The algorithm proposed by Intel applies not so well in kernel context: it
would imply disabling interrupts and looping on every CPUs while modifying
the code and would not support instrumentation of code called from interrupt
sources that cannot be disabled.
Therefore, we use a different algorithm to respect Intel's erratum (see the
quoted discussion above). We make sure that no CPU sees an out-of-date copy
of a pre-fetched instruction by 1 - using a breakpoint, which skips the
instruction that is going to be modified, 2 - issuing an IPI to every CPU to
execute a sync_core(), to make sure that even when the breakpoint is removed,
no cpu could possibly still have the out-of-date copy of the instruction,
modify the now unused 2nd byte of the instruction, and then put back the
original 1st byte of the instruction.
It has exactly the same intent as the algorithm proposed by Intel, but
it has less side-effects, scales better and supports NMI, SMI and MCE."
Moreover, just to be cautious, I arrange the alignment of instructions
to modify so their updates will be atomic. Therefore, a 5 bytes movl
will always be aligned on 4 bytes boundaries - 1, so the immediate value
that follows the 1 byte opcode will be itself aligned on 4 bytes
boundaries.
Mathieu
--
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
next prev parent reply other threads:[~2007-08-12 18:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-12 15:07 [patch 0/8] Immediate Values Mathieu Desnoyers
2007-08-12 15:07 ` [patch 1/8] Immediate Values - Global Modules List and Module Mutex Mathieu Desnoyers
2007-08-12 15:07 ` [patch 2/8] Immediate Values - Architecture Independent Code Mathieu Desnoyers
2007-08-13 20:51 ` Alexey Dobriyan
2007-08-16 16:02 ` Mathieu Desnoyers
2007-08-12 15:07 ` [patch 3/8] Immediate Values - Kconfig menu in EMBEDDED Mathieu Desnoyers
2007-08-12 15:07 ` [patch 4/8] Immediate Values - Move Kprobes i386 restore_interrupt to kdebug.h Mathieu Desnoyers
2007-08-12 15:07 ` [patch 5/8] Immediate Values - i386 Optimization Mathieu Desnoyers
2007-08-13 3:23 ` [PATCH] Immediate Values - i386 Optimization - fix warnings Mathieu Desnoyers
2007-08-12 15:07 ` [patch 6/8] Immediate Values - Powerpc Optimization Mathieu Desnoyers
2007-08-12 15:07 ` [patch 7/8] Immediate Values - Documentation Mathieu Desnoyers
2007-08-12 15:07 ` [patch 8/8] Scheduler Profiling - Use Immediate Values Mathieu Desnoyers
2007-08-12 18:27 ` [patch 0/8] " Arjan van de Ven
2007-08-12 18:55 ` Mathieu Desnoyers [this message]
2007-08-12 20:58 ` Arjan van de Ven
2007-08-12 21:14 ` Mathieu Desnoyers
-- strict thread matches above, loose matches on Subject: below --
2007-08-20 20:23 Mathieu Desnoyers
2007-08-27 15:59 Mathieu Desnoyers
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=20070812185501.GA4480@Krystal \
--to=mathieu.desnoyers@polymtl.ca \
--cc=akpm@linux-foundation.org \
--cc=arjan@infradead.org \
--cc=linux-kernel@vger.kernel.org \
/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