iomap: Make sure iomap_end is called after iomap_begin
Subsystems (2)
PATCH 1/1 iomap: Make sure iomap_end is called after iomap_begin
Make sure iomap_end is always called when iomap_begin succeeds: the filesystem may take locks in iomap_begin and release them in iomap_end, for example.
--- fs/iomap/apply.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/iomap/apply.c +5 -4
@@ -46,10 +46,10 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, ret = ops->iomap_begin (inode, pos, length, flags, &iomap, &srcmap);if (ret)return ret; -if (WARN_ON (iomap.offset > pos)) -return -EIO ; -if (WARN_ON (iomap.length ==0 )) -return -EIO ; +if (WARN_ON (iomap.offset > pos) ||WARN_ON (iomap.length ==0 )) { + written = -EIO ; + goto out; + }trace_iomap_apply_dstmap (inode, &iomap);if (srcmap.type !=IOMAP_HOLE )
@@ -80,6 +80,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, written =actor (inode, pos, length, data, &iomap, srcmap.type !=IOMAP_HOLE ? &srcmap : &iomap); +out:/* * Now the data has been copied, commit the range we've copied. This * should not fail unless the filesystem has had a fatal error.
base-commit: 97e0204907ac4c42c6e94ef466a047523f34b853
Signature · 1 line
2.26.2
Quoted 3 lines · Andreas Gruenbacher
Make sure
iomap_endis always called wheniomap_beginsucceeds: the filesystem may take locks iniomap_beginand release them iniomap_end, for example.
Ok, i get that from the patch, but I don't know anything else about this problem, and nor will anyone else trying to determine if this is a fix they need to backport to other kernels. Can you add some more information to the commit message, such as how was this found and what filesystems it affects? It would also be good to know what commit introduced this issue and whether it need stable back ports (i.e. a Fixes tag).
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 5 lines · Dave Chinner
Quoted 3 lines · Andreas Gruenbacher
Make sure
iomap_endis always called wheniomap_beginsucceeds: the filesystem may take locks iniomap_beginand release them iniomap_end, for example.
Quoted 7 lines
Ok, i get that from the patch, but I don't know anything else about this problem, and nor will anyone else trying to determine if this is a fix they need to backport to other kernels. Can you add some more information to the commit message, such as how was this found and what filesystems it affects? It would also be good to know what commit introduced this issue and whether it need stable back ports (i.e. a Fixes tag).
I'd assume Andreas is looking at converting a filesystem to use iomap, since this problem only occurs for filesystems which have returned an invalid extent.
I almost wonder if this should return -EFSCORRUPTED rather than -EIO. Um, except that's currently a per-fs define. Is it time to move that up to errno.h?
Quoted 14 lines · Matthew Wilcox
Quoted 5 lines · Dave Chinner
Quoted 3 lines · Andreas Gruenbacher
Make sure
iomap_endis always called wheniomap_beginsucceeds: the filesystem may take locks iniomap_beginand release them iniomap_end, for example.Quoted 7 lines
Ok, i get that from the patch, but I don't know anything else about this problem, and nor will anyone else trying to determine if this is a fix they need to backport to other kernels. Can you add some more information to the commit message, such as how was this found and what filesystems it affects? It would also be good to know what commit introduced this issue and whether it need stable back ports (i.e. a Fixes tag).
Quoted 3 lines
I'd assume Andreas is looking at converting a filesystem to use iomap, since this problem only occurs for filesystems which have returned an invalid extent.
Well, I can assume it's gfs2, but you know what happens when you assume something....
Quoted 1 line
I almost wonder if this should return
-EFSCORRUPTEDrather than-EIO.
We've typically used -EFSCORRUPTED for metadata corruptions and -EIO for data IO errors that result from metadata corruption. -EIO implies that the IO failed and the state of the data is indeterminate (i.e. may be corrupted), but the filesystem is still ok, whereas EFSCORRUPTED implies the filesystem needs to have fsck run on it to diagnose and fix the metadata corruption.
This code sort of spans the grey area between them. The error could come from in in-memory bug and not actually a filesystem corruption, so it's not clear that corruption is the right thing to report here...
Quoted 2 lines
Um, except that's currently a per-fs define. Is it time to move that up to
errno.h?
Has the "EFSCORRUPTED = EUCLEAN is stupid - let's break a longstanding user API by defining it to something completely new" yelling died down enough in the 6 months since this was last proposed?
https://lore.kernel.org/linux-xfs/[email protected]/
https://lore.kernel.org/linux-xfs/[email protected]/
We've only been trying to get a generic -EFSCORRUPTED definition into the kernel errno headers for ~15 years... :(
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
----- Original Message -----
Quoted 6 lines
Quoted 3 lines
I'd assume Andreas is looking at converting a filesystem to use iomap, since this problem only occurs for filesystems which have returned an invalid extent.
Well, I can assume it's gfs2, but you know what happens when you assume something....
Yes, it's gfs2, which already has iomap. I found the bug while just browsing the code: gfs2 takes a lock in the begin code. If there's an error, however unlikely, the end code is never called, so we would never unlock. It doesn't matter to me whether the error is -EIO because it's very unlikely in the first place. I haven't looked back to see where the problem was introduced, but I suspect it should be ported back to stable releases.
Bob Peterson
Quoted 8 lines · Bob Peterson
----- Original Message -----
Quoted 6 lines
Quoted 3 lines
I'd assume Andreas is looking at converting a filesystem to use iomap, since this problem only occurs for filesystems which have returned an invalid extent.
Well, I can assume it's gfs2, but you know what happens when you assume something....
Quoted 6 lines
Yes, it's gfs2, which already has iomap. I found the bug while just browsing the code: gfs2 takes a lock in the begin code. If there's an error, however unlikely, the end code is never called, so we would never unlock. It doesn't matter to me whether the error is
-EIObecause it's very unlikely in the first place. I haven't looked back to see where the problem was introduced, but I suspect it should be ported back to stable releases.
It shouldn't just be "unlikely", it should be impossible. This is the iomap code checking whether you've returned an extent which doesn't cover the range asked for. I don't think it needs to be backported, and I'm pretty neutral on whether it needs to be applied.
Quoted 16 lines · Matthew Wilcox
Quoted 8 lines · Bob Peterson
----- Original Message -----
Quoted 6 lines
Quoted 3 lines
I'd assume Andreas is looking at converting a filesystem to use iomap, since this problem only occurs for filesystems which have returned an invalid extent.
Well, I can assume it's gfs2, but you know what happens when you assume something....
Quoted 6 lines
Yes, it's gfs2, which already has iomap. I found the bug while just browsing the code: gfs2 takes a lock in the begin code. If there's an error, however unlikely, the end code is never called, so we would never unlock. It doesn't matter to me whether the error is
-EIObecause it's very unlikely in the first place. I haven't looked back to see where the problem was introduced, but I suspect it should be ported back to stable releases.
Quoted 4 lines
It shouldn't just be "unlikely", it should be impossible. This is the iomap code checking whether you've returned an extent which doesn't cover the range asked for. I don't think it needs to be backported, and I'm pretty neutral on whether it needs to be applied.
Right, when these warnings trigger, the filesystem has already screwed up; this fix only makes things less bad. Those kinds of issues are very likely to be fixed long before the code hits users, so it shouldn't be backported.
This bug was in iomap_apply right from the start, so:
Thanks,
Andreas
Quoted 22 lines · Andreas Gruenbacher
Quoted 16 lines · Matthew Wilcox
Quoted 8 lines · Bob Peterson
----- Original Message -----
Quoted 6 lines
Quoted 3 lines
I'd assume Andreas is looking at converting a filesystem to use iomap, since this problem only occurs for filesystems which have returned an invalid extent.
Well, I can assume it's gfs2, but you know what happens when you assume something....
Quoted 6 lines
Yes, it's gfs2, which already has iomap. I found the bug while just browsing the code: gfs2 takes a lock in the begin code. If there's an error, however unlikely, the end code is never called, so we would never unlock. It doesn't matter to me whether the error is
-EIObecause it's very unlikely in the first place. I haven't looked back to see where the problem was introduced, but I suspect it should be ported back to stable releases.Quoted 4 lines
It shouldn't just be "unlikely", it should be impossible. This is the iomap code checking whether you've returned an extent which doesn't cover the range asked for. I don't think it needs to be backported, and I'm pretty neutral on whether it needs to be applied.
Quoted 8 lines
Right, when these warnings trigger, the filesystem has already screwed up; this fix only makes things less bad. Those kinds of issues are very likely to be fixed long before the code hits users, so it shouldn't be backported.
This bug was in
iomap_applyright from the start, so:Fixes ae259a9c8593 ("fs: introduce iomap infrastructure")
So... you found this through code inspection, and not because you actually hit this on gfs2, or any of the other iomap users?
I generally think this looks ok, but I want to know if I should be looking deeper. :)
--D
Quoted 3 lines
Thanks,
Andreas
Am Di., 16. Juni 2020 um 18:26 Uhr schrieb Darrick J. Wong <[email protected]>:
Quoted 28 lines · Andreas Gruenbacher
Quoted 27 lines · Matthew Wilcox
Quoted 16 lines · Bob Peterson
Quoted 8 lines
----- Original Message -----
Quoted 6 lines
Quoted 3 lines
I'd assume Andreas is looking at converting a filesystem to use iomap, since this problem only occurs for filesystems which have returned an invalid extent.
Well, I can assume it's gfs2, but you know what happens when you assume something....
Quoted 6 lines
Yes, it's gfs2, which already has iomap. I found the bug while just browsing the code: gfs2 takes a lock in the begin code. If there's an error, however unlikely, the end code is never called, so we would never unlock. It doesn't matter to me whether the error is
-EIObecause it's very unlikely in the first place. I haven't looked back to see where the problem was introduced, but I suspect it should be ported back to stable releases.Quoted 4 lines
It shouldn't just be "unlikely", it should be impossible. This is the iomap code checking whether you've returned an extent which doesn't cover the range asked for. I don't think it needs to be backported, and I'm pretty neutral on whether it needs to be applied.
Right, when these warnings trigger, the filesystem has already screwed up; this fix only makes things less bad. Those kinds of issues are very likely to be fixed long before the code hits users, so it shouldn't be backported.
Quoted 6 lines
Quoted 3 lines
This bug was in
iomap_applyright from the start, so:Fixes ae259a9c8593 ("fs: introduce iomap infrastructure")So... you found this through code inspection, and not because you actually hit this on gfs2, or any of the other iomap users?
Bob did, yes. I've only hit those warnings in the very early stages of gfs2 iomap development, long before that code was even posted for review.
Quoted 2 lines
I generally think this looks ok, but I want to know if I should be looking deeper. :)
It's really supposed to be a simple, straight forward fix only.
Thanks,
Andreas
----- Original Message -----
Quoted 7 lines
So... you found this through code inspection, and not because you actually hit this on gfs2, or any of the other iomap users?
I generally think this looks ok, but I want to know if I should be looking deeper. :)
--D
Correct. Code-inspection only. I never actually hit the problem. If those errors are really so unusual and catastrophic, perhaps we should just change them to BUG_ONs or something instead. Why bother unlocking if we're already 1.9 meters underground?
Bob Peterson
Quoted 4 lines · Bob Peterson
----- Original Message -----
Quoted 3 lines
So... you found this through code inspection, and not because you actually hit this on gfs2, or any of the other iomap users?
Quoted 8 lines
Quoted 4 lines
I generally think this looks ok, but I want to know if I should be looking deeper. :)
--D
Correct. Code-inspection only. I never actually hit the problem. If those errors are really so unusual and catastrophic, perhaps we should just change them to
BUG_ONsor something instead.
We do not panic a machine because a detectable data or filesystem corruption event has occurred. We have a viable error path to tell userspace a fatal IO error occurred so that is all the generic infrastructure should be doing.
If a loud warning needs to be issued, then WARN_ON_ONCE() may be appropriate, though I suspect even that is overkill for this situation....
Quoted 1 line
Why bother unlocking if we're already 1.9 meters underground?
Because then a filesystem that has shutdown because it has recognised that it is walking dead can be unmounted and the user can then run an autopsy to find and fix the problem without having to reboot the machine....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 14 lines · Andreas Gruenbacher
Make sure
iomap_endis always called wheniomap_beginsucceeds: the filesystem may take locks iniomap_beginand release them iniomap_end, for example.Signed-off-by Andreas Gruenbacher <[email protected]>--- fs/iomap/apply.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)fs/iomap/apply.c +0
-0
fs/iomap/apply.c iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, · line 49
Quoted 8 lines
fs/iomap/apply.c +1
-4@@ -46,10 +46,10 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, ret = ops->iomap_begin (inode, pos, length, flags, &iomap, &srcmap);if (ret)return ret; -if (WARN_ON (iomap.offset > pos)) -return -EIO ; -if (WARN_ON (iomap.length ==0 )) -return -EIO ; +if (WARN_ON (iomap.offset > pos) ||WARN_ON (iomap.length ==0 )) {
<urk> Forgot to actually review the original patch. :P
Why combine these WARN_ON? Before, you could distinguish between your iomap_begin method returning zero length vs. bad offset.
--D
Quoted 19 lines
fs/iomap/apply.c +4
-0+ written = -EIO ; + goto out; + }trace_iomap_apply_dstmap (inode, &iomap);if (srcmap.type !=IOMAP_HOLE )@@ -80,6 +80,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, written =actor (inode, pos, length, data, &iomap, srcmap.type !=IOMAP_HOLE ? &srcmap : &iomap); +out:/* * Now the data has been copied, commit the range we've copied. This * should not fail unless the filesystem has had a fatal error. base-commit:
97e0204907ac4c42c6e94ef466a047523f34b853Signature · 1 line
2.26.2
Quoted 26 lines · Darrick J. Wong
Quoted 14 lines · Andreas Gruenbacher
Make sure
iomap_endis always called wheniomap_beginsucceeds: the filesystem may take locks iniomap_beginand release them iniomap_end, for example.Signed-off-by Andreas Gruenbacher <[email protected]>--- fs/iomap/apply.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)fs/iomap/apply.c +0
-0fs/iomap/apply.c iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, · line 49
Quoted 8 lines
fs/iomap/apply.c +1
-4@@ -46,10 +46,10 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, ret = ops->iomap_begin (inode, pos, length, flags, &iomap, &srcmap);if (ret)return ret; -if (WARN_ON (iomap.offset > pos)) -return -EIO ; -if (WARN_ON (iomap.length ==0 )) -return -EIO ; +if (WARN_ON (iomap.offset > pos) ||WARN_ON (iomap.length ==0 )) {<urk> Forgot to actually review the original patch. :P
Quoted 2 lines
Why combine these
WARN_ON? Before, you could distinguish between youriomap_beginmethod returning zero length vs. bad offset.
Right, the WARN_ONs shouldn't both report the same line number. I'll send an update.
Thanks,
Andreas
Quoted 8 lines · Darrick J. Wong
fs/iomap/apply.c iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, · line 49
Quoted 5 lines
fs/iomap/apply.c +1
-4-if (WARN_ON (iomap.offset > pos)) -return -EIO ; -if (WARN_ON (iomap.length ==0 )) -return -EIO ; +if (WARN_ON (iomap.offset > pos) ||WARN_ON (iomap.length ==0 )) {Why combine these
WARN_ON? Before, you could distinguish between youriomap_beginmethod returning zero length vs. bad offset.
Does it matter? They're both the same problem -- the filesystem has returned an invalid iomap. I'd go further and combine the two:
if (WARN_ON(iomap.offset > pos || iomap.length == 0)) {that'll save a few bytes of .text
Quoted 10 lines · Matthew Wilcox
Quoted 8 lines · Darrick J. Wong
fs/iomap/apply.c iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, · line 49
Quoted 5 lines
fs/iomap/apply.c +1
-4-if (WARN_ON (iomap.offset > pos)) -return -EIO ; -if (WARN_ON (iomap.length ==0 )) -return -EIO ; +if (WARN_ON (iomap.offset > pos) ||WARN_ON (iomap.length ==0 )) {Why combine these
WARN_ON? Before, you could distinguish between youriomap_beginmethod returning zero length vs. bad offset.
Quoted 6 lines
Does it matter? They're both the same problem -- the filesystem has returned an invalid iomap. I'd go further and combine the two:
if (WARN_ON(iomap.offset > pos || iomap.length == 0)) {that'll save a few bytes of .text
That would be fine by me as well. Christoph may have wanted separate warnings for a particular reason though.
Andreas
Quoted 14 lines · Andreas Gruenbacher
Quoted 13 lines · Matthew Wilcox
Quoted 8 lines · Darrick J. Wong
fs/iomap/apply.c iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, · line 49
Quoted 5 lines
fs/iomap/apply.c +1
-4-if (WARN_ON (iomap.offset > pos)) -return -EIO ; -if (WARN_ON (iomap.length ==0 )) -return -EIO ; +if (WARN_ON (iomap.offset > pos) ||WARN_ON (iomap.length ==0 )) {Why combine these
WARN_ON? Before, you could distinguish between youriomap_beginmethod returning zero length vs. bad offset.Does it matter? They're both the same problem -- the filesystem has returned an invalid iomap. I'd go further and combine the two:
Quoted 6 lines
Quoted 3 lines
if (WARN_ON(iomap.offset > pos || iomap.length == 0)) {that'll save a few bytes of .text
That would be fine by me as well. Christoph may have wanted separate warnings for a particular reason though.
Yes. The line number in the WARN_ON will tell you which condition you if they are separate, which is really useful to diagnose what is going on.
Quoted 17 lines · Christoph Hellwig
Quoted 16 lines · Andreas Gruenbacher
Quoted 15 lines · Matthew Wilcox
Quoted 8 lines · Darrick J. Wong
fs/iomap/apply.c iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, · line 49
Quoted 5 lines
fs/iomap/apply.c +1
-4-if (WARN_ON (iomap.offset > pos)) -return -EIO ; -if (WARN_ON (iomap.length ==0 )) -return -EIO ; +if (WARN_ON (iomap.offset > pos) ||WARN_ON (iomap.length ==0 )) {Why combine these
WARN_ON? Before, you could distinguish between youriomap_beginmethod returning zero length vs. bad offset.Does it matter? They're both the same problem -- the filesystem has returned an invalid iomap. I'd go further and combine the two:
if (WARN_ON(iomap.offset > pos || iomap.length == 0)) {
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
that'll save a few bytes of .text
That would be fine by me as well. Christoph may have wanted separate warnings for a particular reason though.
Yes. The line number in the
WARN_ONwill tell you which condition you if they are separate, which is really useful to diagnose what is going on.
Thinking about it, wouldn't the second test be better replaced with:
if (WARN_ON(iomap.offset + iomap.length <= pos))
in case the filesystem returns an extent which finishes before pos? This would be a superset of the test for length being 0.
Quoted 6 lines · Matthew Wilcox
Thinking about it, wouldn't the second test be better replaced with:
if (
WARN_ON(iomap.offset + iomap.length <= pos))in case the filesystem returns an extent which finishes before pos? This would be a superset of the test for length being 0.
The idea was to tell what is wrong. Both with the initial iomap work and later the COW support I had all kinds of weird scenarious during bringup where an obvious error has been very helpful.