Fixing libfc memory leaks
Subsystems (2)
cover Fixing libfc memory leaks
Hi Hannes,
Could you take a look at those?
At least the first one causes noticeable memory decline over time for some of our deployments.
Igor Druzhinin (2):
scsi: libfc: free response frame from GPN_ID
scsi: libfc: drop extra rport reference in fc_rport_create()
drivers/scsi/libfc/fc_disc.c | 2 ++ drivers/scsi/libfc/fc_rport.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.7.4
PATCH RESEND 1/2 scsi: libfc: free response frame from GPN_ID
fc_disc_gpn_id_resp() should be the last function using it so free it here to avoid memory leak.
--- drivers/scsi/libfc/fc_disc.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/libfc/fc_disc.c +2 -0
@@ -628,6 +628,8 @@ static void fc_disc_gpn_id_resp(struct fc_seq *sp, struct fc_frame *fp, } out:kref_put (&rdata->kref, fc_rport_destroy); +if (!IS_ERR (fp)) +fc_frame_free (fp); }/**
Signature · 1 line
2.7.4
Re: [PATCH RESEND 1/2] scsi: libfc: free response frame from GPN_ID
Quoted 14 lines · Igor Druzhinin
fc_disc_gpn_id_resp()should be the last function using it so free it here to avoid memory leak.Signed-off-by Igor Druzhinin <[email protected]>--- drivers/scsi/libfc/fc_disc.c | 2 ++ 1 file changed, 2 insertions(+)drivers/scsi/libfc/fc_disc.c +0
-0
drivers/scsi/libfc/fc_disc.c static void fc_disc_gpn_id_resp(struct fc_seq *sp, struct fc_frame *fp, · line 635
Quoted 8 lines
drivers/scsi/libfc/fc_disc.c +2
-0@@ -628,6 +628,8 @@ static void fc_disc_gpn_id_resp(struct fc_seq *sp, struct fc_frame *fp, } out:kref_put (&rdata->kref, fc_rport_destroy); +if (!IS_ERR (fp)) +fc_frame_free (fp); }/**
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
Martin K. Petersen
AppliedRe: [PATCH RESEND 1/2] scsi: libfc: free response frame from GPN_ID
In reply to Igor DruzhininIgor,
Quoted 2 lines
fc_disc_gpn_id_resp()should be the last function using it so free it here to avoid memory leak.
Applied to 5.6/scsi-fixes, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
PATCH RESEND 2/2 scsi: libfc: drop extra rport reference in fc_rport_create()
In reply to Igor DruzhininThe callers of this function seem to assume the reference is not taken in case rport already exists. This results in one extra reference taken on each rport re-discovery that will eventually get to inability to free rport structure on port removal.
--- drivers/scsi/libfc/fc_rport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/libfc/fc_rport.c +3 -1
@@ -133,8 +133,10 @@ struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, u32 port_id)lockdep_assert_held (&lport->disc.disc_mutex); rdata =fc_rport_lookup (lport, port_id); -if (rdata) +if (rdata) { +kref_put (&rdata->kref, fc_rport_destroy);return rdata; + }if (lport->rport_priv_size >0 ) rport_priv_size = lport->rport_priv_size;
Signature · 1 line
2.7.4
Re: [PATCH RESEND 2/2] scsi: libfc: drop extra rport reference in fc_rport_create()
Quoted 17 lines · Igor Druzhinin
The callers of this function seem to assume the reference is not taken in case rport already exists. This results in one extra reference taken on each rport re-discovery that will eventually get to inability to free rport structure on port removal.
Signed-off-by Igor Druzhinin <[email protected]>--- drivers/scsi/libfc/fc_rport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/scsi/libfc/fc_rport.c +0
-0@@ -133,8 +133,10 @@ struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, u32 port_id)lockdep_assert_held (&lport->disc.disc_mutex);
drivers/scsi/libfc/fc_rport.c struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, u32 port_id) · line 142
Quoted 10 lines
drivers/scsi/libfc/fc_rport.c +3
-1rdata =fc_rport_lookup (lport, port_id); -if (rdata) +if (rdata) { +kref_put (&rdata->kref, fc_rport_destroy);return rdata; + }if (lport->rport_priv_size >0 ) rport_priv_size = lport->rport_priv_size;
NAK.
The caller _does_ assume that a reference is taken once fc_rport_create() returns non-NULL.
And the caller is responsible to drop the reference once 'rdatat' isn't used anymore.
Any other usage is an error, but should be fixed in the caller, not here.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
Hannes,
Quoted 11 lines
Could you take a look at those?
At least the first one causes noticeable memory decline over time for some of our deployments.Igor Druzhinin (2):
scsi: libfc: free response frame fromGPN_ID
scsi: libfc: drop extra rport reference infc_rport_create()drivers/scsi/libfc/fc_disc.c | 2 ++ drivers/scsi/libfc/fc_rport.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-)
Please review!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering