On Wed, 17 Oct 2007, Linus Torvalds wrote:In fact, I think you'll hit it even if you use the "for_each_sg()" helper function. Exactly because it does the sg = sg_next(sg) at the end of the for-loop, so it will do it for the last entry too, even though that will access one past the end. So it really *is* the case that every *single* use of that SG chain needs to be switched over to only do the sg_next() when required, or sg_next() needs to be fixed to look at the current-in-use entry (which we *can* access) when it decides what to do about the next one (which we can *not* access). Moving the sg_is_chain() bit to the previous entry would work, but it requires that nobody who could have a chained scatterlist must *ever* access "sg->page" directly - you'd always need to use some helper function that masks off the bit, eg - rename "sg->page" into "sh->page_and_flag", and make it "unsigned long" instead of a pointer. - change every single "sg->page" access to use "sg_page(sg)" instead: #define sg_pointer(sg) ((void *)((sg)->page_and_flag & ~1ul)) static inline struct page *sg_page(struct scatterist *sg) { return sg_pointer(sg); } - change "sg_next()" to do static inline struct scatterlist *sg_next(struct scatterlist *sg) { if (sg->page_and_flag & 1) sg = sg_pointer(sg+1)-1; return ++sg; } where the magic is exactly the fact that now "sg_next()" will *not* derefence the next SG entry unless the current one was marked appropriately. And then *creating* the chain obviously needs to properly mark the next-to-last entry with the "next entry is a pointer" flag. Big diff, it sounds like. But I don't see many alternatives. Jens? Linus -
| Andrew Morton | -mm merge plans for 2.6.23 |
| David Miller | Re: [BUG] New Kernel Bugs |
| Greg KH | [GIT PATCH] driver core patches against 2.6.24 |
| Andrew Morton | Re: Linux 2.6.21-rc4 |
git: | |
| David Miller | [GIT]: Networking |
| Natalie Protasevich | [BUG] New Kernel Bugs |
| Jarek Poplawski | Re: [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| Eric W. Biederman | [PATCH] macvlan: Support creating macvlans from macvlans |
