Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752285AbbGLEUl (ORCPT ); Sun, 12 Jul 2015 00:20:41 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:35641 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750747AbbGLEUj (ORCPT ); Sun, 12 Jul 2015 00:20:39 -0400 Date: Sat, 11 Jul 2015 21:20:01 -0700 From: Calvin Owens To: Christoph Hellwig CC: Nagalakshmi Nandigama , Praveen Krishnamoorthy , Sreekanth Reddy , Abhijit Mahajan , , , , Subject: Re: [PATCH 6/6] Fix unsafe fw_event_list usage Message-ID: <20150712042001.GA315519@mail.thefacebook.com> References: <1431661322-3097935-1-git-send-email-calvinowens@fb.com> <1433821856-2815280-1-git-send-email-calvinowens@fb.com> <1433821856-2815280-7-git-send-email-calvinowens@fb.com> <20150703160251.GB11815@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <20150703160251.GB11815@infradead.org> User-Agent: Mutt/1.5.20 (2009-12-10) X-Originating-IP: [192.168.52.123] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.14.151,1.0.33,0.0.0000 definitions=2015-07-12_04:2015-07-11,2015-07-12,1970-01-01 signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1918 Lines: 46 On Friday 07/03 at 09:02 -0700, Christoph Hellwig wrote: > On Mon, Jun 08, 2015 at 08:50:56PM -0700, Calvin Owens wrote: > > Since the fw_event deletes itself from the list, cleanup_queue() can > > walk onto garbage pointers or walk off into freed memory. > > > > This refactors the code in _scsih_fw_event_cleanup_queue() to not > > iterate over the fw_event_list without a lock. > > I think this really should be folded into the previous one, with the > fixes in this one the other refcounting change don't make a whole lot > sense. > > > +static struct fw_event_work *dequeue_next_fw_event(struct MPT2SAS_ADAPTER *ioc) > > +{ > > + unsigned long flags; > > + struct fw_event_work *fw_event = NULL; > > + > > + spin_lock_irqsave(&ioc->fw_event_lock, flags); > > + if (!list_empty(&ioc->fw_event_list)) { > > + fw_event = list_first_entry(&ioc->fw_event_list, > > + struct fw_event_work, list); > > + list_del_init(&fw_event->list); > > + fw_event_work_get(fw_event); > > + } > > + spin_unlock_irqrestore(&ioc->fw_event_lock, flags); > > + > > + return fw_event; > > Shouldn't we have a reference for each item on the list that gets > transfer to whomever removes it from the list? Yes, this was a bit weird the way I did it. I redid this in v2, hopefully it's clearer. > Additionally _firmware_event_work should call dequeue_next_fw_event > first in the function so that item is off the list before we process > it, and can then just drop the reference once it's done. That works: cleanup_queue() won't wait on some already-running events, but destroy_workqueue() drains the wq, so we won't run ahead and free things from under the fw_event when unwinding. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/