Re: Cross-Modifying Code
From: Matt Taylor (para_at_tampabay.rr.com)
Date: 05/14/04
- Next message: John Lynn: "MIP rating of today's Pentiums?"
- Previous message: Matt Taylor: "Re: 16 bit jumps in pmode linux"
- In reply to: Alex McDonald: "Re: Cross-Modifying Code"
- Next in thread: Bx.C // Shiragajin: "Re: Cross-Modifying Code"
- Reply: Bx.C // Shiragajin: "Re: Cross-Modifying Code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 14 May 2004 03:36:05 +0000 (UTC)
"Alex McDonald" <alex_mcd@btopenworld.com> wrote in message
news:c8119q$cbo$1@titan.btinternet.com...
> "Matt Taylor" <para@tampabay.rr.com> wrote in message
> news:S3Poc.609486$Po1.600590@twister.tampabay.rr.com...
> > I was reading in the IA-32 System Programming Guide (Vol. 3) in Ch. 7
> about
> > handling of cross-modifying code, and Intel warns against modifying code
> > that may be executing in another processor. I'm working on some code
which
> > cross-modifies, although I don't really care about synchronization. I
was
> > wondering if anybody could clarify on their warning.
> >
> > If I modified the displacement part of a jmp/call instruction, would the
> > processor branch only to the original address or to the newly written
> > address? I am updating with lock, but the docs hint in 7.1.2.2 that
> > instruction fetch supercedes lock, so I'm thinking that an unaligned
> branch
> > target could cause a race. This still raises another question: are there
> > still caveats even if the branch target is aligned and updated
atomically?
> >
> > -Matt
> >
>
> There's an explicit warning that instruction fetch and page table accesses
> don't honour LOCKed instructions, as you note. There's an implication they
> don't honour xFENCE for prefetched code either. CPUID or some other xFENCE
> would appear to need to be temporally executed (that is, after the
> modification) on the _other_ MP to ensure consistency. My reading has
either
> the old instruction or the new executed, depending on what's in the
> instruction pipeline. Without a lock (the example given uses a spin lock)
> then you don't know when to issue the CPUID.
>
> However, if you can get the processor to pass through a CPUID on its way
to
> your instruction, that might do. In other words;
>
> CPUID
> JMP xxxx
>
> where xxxx is the modified address, and the processor can't get to the
jump
> except through the CPUID (or an xFENCE might suffice). Would make the code
> slow though, especially if the jump is frequently taken and infrequently
> modified.
>
> Does a hyperthreaded processor suffer from the same issue? Or AMDs?
The Opteron manuals don't comment on the interaction between executing code
and locked updates. However, I would presume that the processor would
invalidate the caches in other processors before the update proceeded. I
would expect a Hyperthreaded processor to treat cross-modifying code between
logical processors the same way it treats self-modifying code since both
logical processors share the caches.
As long as instruction fetch can't violate the atomic nature of a locked
update even when unaligned, then I'm unconcerned with the note in the
manual.
-Matt
- Next message: John Lynn: "MIP rating of today's Pentiums?"
- Previous message: Matt Taylor: "Re: 16 bit jumps in pmode linux"
- In reply to: Alex McDonald: "Re: Cross-Modifying Code"
- Next in thread: Bx.C // Shiragajin: "Re: Cross-Modifying Code"
- Reply: Bx.C // Shiragajin: "Re: Cross-Modifying Code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|