return value of ptep_get_and_clear
ptep_get_and_clear has a signature that looks something like:
static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
pte_t *ptep)
It appears that its suppose to return the pte_t pointed to by ptep before its modified. Why do we bother doing this? The caller seems perfectly able to dereference ptep and hold on to it. Am I missing something here?
If not, I'll work up a set of patches to change ptep_get_and_clear and its callers for post 2.6.12 release.
- kumar
Quoted 7 lines · Kumar Gala
ptep_get_and_clearhas a signature that looks something like:static inline
pte_tptep_get_and_clear(structmm_struct*mm, unsigned long addr,
pte_t*ptep)It appears that its suppose to return the
pte_tpointed to by ptep before its modified. Why do we bother doing this? The caller seems perfectly able to dereference ptep and hold on to it. Am I missing something here?
You need to be able to *atomically* clear the pte and retrieve the old value.
Nick
Signature · 1 line
SUSE Labs, Novell Inc.
Quoted 7 lines · Nick Piggin
Quoted 6 lines · Kumar Gala
ptep_get_and_clearhas a signature that looks something like:static inline
pte_tptep_get_and_clear(structmm_struct*mm, unsigned long addr,
pte_t*ptep)
Quoted 8 lines
Quoted 5 lines
It appears that its suppose to return the
pte_tpointed to by ptep before its modified. Why do we bother doing this? The caller seems perfectly able to dereference ptep and hold on to it. Am I missing something here?You need to be able to *atomically* clear the pte and retrieve the old value.
The effect of the clearing is that the present bit is cleared which makes the CPU generate a fault if this pte is referenced.
The problem with replacing pte values is that the code executing is racing with cpu mmu access to the pte (which may set bits on i386 I believe). So if you would access the pte and then clear it later then there would be a small window where the MMU could modify the pte. These changes would not be detected since you later overwrite the pte.
Using ptep_get_and_clear insures that this does not happen...
Quoted 33 lines · Christoph Lameter
Quoted 4 lines · Nick Piggin
Quoted 3 lines · Kumar Gala
ptep_get_and_clearhas a signature that looks something like:static inline
pte_tptep_get_and_clear(structmm_struct*mm,unsigned
Quoted 5 lines
Quoted 5 lines
long addr,
pte_t*ptep)It appears that its suppose to return the
pte_tpointed to by ptep before its modified. Why do we bother doing this? The callerseems
Quoted 1 line
Quoted 1 line
perfectly able to dereference ptep and hold on to it. Am I
missing
Quoted 5 lines
Quoted 2 lines
something here?
You need to be able to *atomically* clear the pte and retrieve the old value.
The effect of the clearing is that the present bit is cleared which makes
the CPU generate a fault if this pte is referenced.The problem with replacing pte values is that the code executing is racing
with cpu mmu access to the pte (which may set bits on i386 I
believe). So
if you would access the pte and then clear it later then there would
be a
small window where the MMU could modify the pte. These changes would
not
be detected since you later overwrite the pte.
Quoted 1 line
Using
ptep_get_and_clearinsures that this does not happen...
Thanks, I was guessing that getting the value atomically was why this was done after I give it a bit more thought.
- kumar
Quoted 10 lines · Kumar Gala
ptep_get_and_clearhas a signature that looks something like:static inline
pte_tptep_get_and_clear(structmm_struct*mm, unsigned long addr,
pte_t*ptep)It appears that its suppose to return the
pte_tpointed to by ptep before its modified. Why do we bother doing this? The caller seems perfectly able to dereference ptep and hold on to it. Am I missing something here?If not, I'll work up a set of patches to change
ptep_get_and_clearand its callers for post 2.6.12 release.- kumar
Because it is an atomic operation. If you dereference it before ptep_get_and_clear() it could change in between.
--
Brian Gerst