sg: Free data buffers after calling blk_rq_unmap_user
Subsystems (2)
This patch fixes a problem with the sg driver that is only visible with the CONFIG_DEBUG_PAGEALLOC kernel config option. The patch works for me, but i would appreciate the review of somebody with more knowledge about the interactions between the sg driver and the block layer.
Christof
---
sg: Free data buffers after calling blk_rq_unmap_user
From: Christof Schmitt <[email protected]>
Running sg_luns on s390x with CONFIG_DEBUG_PAGEALLOC enabled fails with EFAULT from the SG_IO ioctl. The EFAULT is the result from copy_to_user failing in this call chain:
sg_ioctlsg_new_readsg_finish_rem_reqblk_rq_unmap_user__blk_rq_unmap_userbio_uncopy_user__bio_copy_iovcopy_to_user
The sg driver calls sg_remove_scat to free the memory pages before calling blk_rq_unmap_user that tries to copy the data back to userspace. Change the order to first call blk_rq_unmap_user before freeing the pages in sg_remove_scat.
--- drivers/scsi/sg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/scsi/sg.c +5 -5
@@ -1708,11 +1708,6 @@ static int sg_finish_rem_req(Sg_requestSg_scatter_hold *req_schp = &srp->data;SCSI_LOG_TIMEOUT (4 ,printk ("sg_finish_rem_req: res_used=%d\n" , (int ) srp->res_used)); -if (srp->res_used) -sg_unlink_reserve (sfp, srp); -else -sg_remove_scat (req_schp); -if (srp->rq) {if (srp->bio) ret =blk_rq_unmap_user (srp->bio);
@@ -1720,6 +1715,11 @@ static int sg_finish_rem_req(Sg_requestblk_put_request (srp->rq); } +if (srp->res_used) +sg_unlink_reserve (sfp, srp); +else +sg_remove_scat (req_schp); +sg_remove_request (sfp, srp);return ret;
FUJITA Tomonori
Acked-bySorry for the delay,
Quoted 30 lines · On Tue, 15 Sep 2009 18:53:57 +0200 Christof Schmitt…
This patch fixes a problem with the sg driver that is only visible with the
CONFIG_DEBUG_PAGEALLOCkernel config option. The patch works for me, but i would appreciate the review of somebody with more knowledge about the interactions between the sg driver and the block layer.Christof
---
sg: Free data buffers after callingblk_rq_unmap_userFrom: Christof Schmitt <[email protected]>
Running
sg_lunson s390x withCONFIG_DEBUG_PAGEALLOCenabled fails with EFAULT from theSG_IOioctl. The EFAULT is the result fromcopy_to_userfailing in this call chain:
sg_ioctlsg_new_readsg_finish_rem_reqblk_rq_unmap_user__blk_rq_unmap_userbio_uncopy_user__bio_copy_iovcopy_to_userThe sg driver calls
sg_remove_scatto free the memory pages before callingblk_rq_unmap_userthat tries to copy the data back to userspace. Change the order to first callblk_rq_unmap_userbefore freeing the pages insg_remove_scat.
Quoted 4 lines
Signed-off-by Christof Schmitt <[email protected]>--- drivers/scsi/sg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Oops, thanks a lot!
It would be better to add "Cc: [email protected]" tag since this fix needs to be sent to stable trees.
Quoted 40 lines · FUJITA Tomonori
Sorry for the delay,
Quoted 30 lines · On Tue, 15 Sep 2009 18:53:57 +0200 Christof Schmitt…
This patch fixes a problem with the sg driver that is only visible with the
CONFIG_DEBUG_PAGEALLOCkernel config option. The patch works for me, but i would appreciate the review of somebody with more knowledge about the interactions between the sg driver and the block layer.Christof
---
sg: Free data buffers after callingblk_rq_unmap_userFrom: Christof Schmitt <[email protected]>
Running
sg_lunson s390x withCONFIG_DEBUG_PAGEALLOCenabled fails with EFAULT from theSG_IOioctl. The EFAULT is the result fromcopy_to_userfailing in this call chain:
sg_ioctlsg_new_readsg_finish_rem_reqblk_rq_unmap_user__blk_rq_unmap_userbio_uncopy_user__bio_copy_iovcopy_to_userThe sg driver calls
sg_remove_scatto free the memory pages before callingblk_rq_unmap_userthat tries to copy the data back to userspace. Change the order to first callblk_rq_unmap_userbefore freeing the pages insg_remove_scat.Quoted 4 lines
Signed-off-by Christof Schmitt <[email protected]>--- drivers/scsi/sg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 6 lines
Oops, thanks a lot!
Acked-by FUJITA Tomonori <[email protected]>It would be better to add "Cc: [email protected]" tag since this fix needs to be sent to stable trees.
Thanks for the review. I will resend the patch with the added acked-by and cc.
--
Christof