Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp873529pxk; Thu, 17 Sep 2020 19:56:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJya4RueEs+/8lszKthh1dyn/XC+9abR1GoKQ0TiOid/bj/+rH4iVChtlSAwwQbQQC7cWwCG X-Received: by 2002:a05:6402:1495:: with SMTP id e21mr35539567edv.146.1600397809213; Thu, 17 Sep 2020 19:56:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600397809; cv=none; d=google.com; s=arc-20160816; b=uR9EOeRJ20JPQRaFspZAP0q0ic2Ty+lKdGwS8TlNg4z8EG50Hx+eKmR/90t1nAa+pi CpmZCObrj+RMiYhg3cB/eR6KiUKTWqINvQ2XyNhGqjwoUnh7rZgikXMR7BBcfe2Hqc0P Owz3LeZt1g7mVT7cdWxAyXMJXyF2rJa25LMTitHB9+TLggQXmxUMncD3cw2E4k9quWMl yuLTSE5HNijfBmLyKsTtp1Vz9C2YAZc2a93JKjJzhcuu1GjTyPsvNI+87E8gOd8Hk6Dn 4IXrBAMMSIaiW7+oNs8hj1oM6AKwon6ZaSwGxLKScMBafbux0LSHXRgbZcNdgEfBHY8K tMRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DhB3shMaELHQjKXvHWxC8D0CKv7mG1FVezRe+cS8Azs=; b=gOFXh1dkSsf1IBGra7qJZXhVku+1b9k5zUKDPsXpcqxOzS23iTq4CsUymlfQNaY2V2 OqWCgKORPxA7KnUcmu8/RwbAdSPAZ58bH4bPGIyYMHF5dZg5YtcFGngiry0bg8LEzU6O a2cLDDo5rH5fi88qaQgLU8VMxVPnl4446sH1Y4GyOdJeCaCwd7PqB0Tkhh9XD7w0oddo 2CFykf3PNZLayqU75/eoo5XyQzZOOG67CBTqEeC+hD5fpDj3qWsVi7rvyx7mbyeXS4Wp mr6qja6a2phkU70bpWjB56Jg+OGT9nH7EcOK9hcSAqPp8rnzUUNiOLzmRAQs0Z6LuuUD 7jog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CTKEm9j7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a9si1144001edr.259.2020.09.17.19.56.25; Thu, 17 Sep 2020 19:56:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CTKEm9j7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728675AbgIRCx5 (ORCPT + 99 others); Thu, 17 Sep 2020 22:53:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:58356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727952AbgIRCHp (ORCPT ); Thu, 17 Sep 2020 22:07:45 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9B69B2389E; Fri, 18 Sep 2020 02:07:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394864; bh=Mh4Vt3gLouXRzukpt2kY1pDDHByKAXbINrKSJTuOPM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CTKEm9j7Q5GsN2CKC4DtVi3NO0GRSTfd/T4Bjfumi4sjQB90NhfSJsc/gKPCPIGf8 qZBYGsY3nwILArDNOlH+AJ6wY23BfDYEgnHUv7+CuQOA6eqGWltrm1ChyWxkmqeZtG nP3KoKzLIhCNL+OTmDN+sl78eQjFW2FM/zuX6zqE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Javed Hasan , Girish Basrur , Saurav Kashyap , Shyam Sundar , "Martin K . Petersen" , Sasha Levin , fcoe-devel@open-fcoe.org, linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 317/330] scsi: libfc: Skip additional kref updating work event Date: Thu, 17 Sep 2020 22:00:57 -0400 Message-Id: <20200918020110.2063155-317-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Javed Hasan [ Upstream commit 823a65409c8990f64c5693af98ce0e7819975cba ] When an rport event (RPORT_EV_READY) is updated without work being queued, avoid taking an additional reference. This issue was leading to memory leak. Trace from KMEMLEAK tool: unreferenced object 0xffff8888259e8780 (size 512): comm "kworker/2:1", jiffies 4433237386 (age 113021.971s) hex dump (first 32 bytes): 58 0a ec cf 83 88 ff ff 00 00 00 00 00 00 00 00 01 00 00 00 08 00 00 00 13 7d f0 1e 0e 00 00 10 backtrace: [<000000006b25760f>] fc_rport_recv_req+0x3c6/0x18f0 [libfc] [<00000000f208d994>] fc_lport_recv_els_req+0x120/0x8a0 [libfc] [<00000000a9c437b8>] fc_lport_recv+0xb9/0x130 [libfc] [<00000000a9c437b8>] fc_lport_recv+0xb9/0x130 [libfc] [<00000000ad5be37b>] qedf_ll2_process_skb+0x73d/0xad0 [qedf] [<00000000e0eb6893>] process_one_work+0x382/0x6c0 [<000000002dfd9e21>] worker_thread+0x57/0x5c0 [<00000000b648204f>] kthread+0x1a0/0x1c0 [<0000000072f5ab20>] ret_from_fork+0x35/0x40 [<000000001d5c05d8>] 0xffffffffffffffff Below is the log sequence which leads to memory leak. Here we get the RPORT_EV_READY and RPORT_EV_STOP back to back, which lead to overwrite the event RPORT_EV_READY by event RPORT_EV_STOP. Because of this, kref_count gets incremented by 1. kernel: host0: rport fffce5: Received PLOGI request kernel: host0: rport fffce5: Received PLOGI in INIT state kernel: host0: rport fffce5: Port is Ready kernel: host0: rport fffce5: Received PRLI request while in state Ready kernel: host0: rport fffce5: PRLI rspp type 8 active 1 passive 0 kernel: host0: rport fffce5: Received LOGO request while in state Ready kernel: host0: rport fffce5: Delete port kernel: host0: rport fffce5: Received PLOGI request kernel: host0: rport fffce5: Received PLOGI in state Delete - send busy kernel: host0: rport fffce5: work event 3 kernel: host0: rport fffce5: lld callback ev 3 kernel: host0: rport fffce5: work delete Link: https://lore.kernel.org/r/20200626094959.32151-1-jhasan@marvell.com Reviewed-by: Girish Basrur Reviewed-by: Saurav Kashyap Reviewed-by: Shyam Sundar Signed-off-by: Javed Hasan Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/libfc/fc_rport.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c index aabf51df3c02f..64500417c22ea 100644 --- a/drivers/scsi/libfc/fc_rport.c +++ b/drivers/scsi/libfc/fc_rport.c @@ -483,10 +483,11 @@ static void fc_rport_enter_delete(struct fc_rport_priv *rdata, fc_rport_state_enter(rdata, RPORT_ST_DELETE); - kref_get(&rdata->kref); - if (rdata->event == RPORT_EV_NONE && - !queue_work(rport_event_queue, &rdata->event_work)) - kref_put(&rdata->kref, fc_rport_destroy); + if (rdata->event == RPORT_EV_NONE) { + kref_get(&rdata->kref); + if (!queue_work(rport_event_queue, &rdata->event_work)) + kref_put(&rdata->kref, fc_rport_destroy); + } rdata->event = event; } -- 2.25.1