1. The alignment code is buggy, as mentioned in comment 15.
2. The iov_discard_undo() API has been added to "qemu/iov.h" to undo the effect of iov_discard_front/back_undoable() calls before unmapping. You can use this API to restore the originally mapped iovecs.
3. The device must follow the spec when handling invalid inputs. If the spec is unclear then it's necessary to check actual hardware or infer the behavior from code that is considered reference material (Linux drivers, emulation code in BOCHS, etc).
Three points stand out:
1. The alignment code is buggy, as mentioned in comment 15.
2. The iov_discard_undo() API has been added to "qemu/iov.h" to undo the effect of iov_discard_ front/back_ undoable( ) calls before unmapping. You can use this API to restore the originally mapped iovecs.
3. The device must follow the spec when handling invalid inputs. If the spec is unclear then it's necessary to check actual hardware or infer the behavior from code that is considered reference material (Linux drivers, emulation code in BOCHS, etc).