Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752735AbcKRI6h (ORCPT ); Fri, 18 Nov 2016 03:58:37 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:58017 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752323AbcKRI6f (ORCPT ); Fri, 18 Nov 2016 03:58:35 -0500 From: Arnd Bergmann To: Binoy Jayan Cc: Sagi Grimberg , Doug Ledford , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org, Linux kernel mailing list Subject: Re: [PATCH v4 05/10] IB/isert: Replace semaphore sem with completion Date: Fri, 18 Nov 2016 09:58:15 +0100 Message-ID: <3477625.cZS9dUaHfE@wuerfel> User-Agent: KMail/5.1.3 (Linux/4.4.0-34-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: References: <1477551554-30349-1-git-send-email-binoy.jayan@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:GgjtTsLE0J9iIhDbKYz+3Ga45RjP5OipEP5uXTiac4e9FJCdO8a o8Lyw+JWQeZ8T606AVa9PZUzdjbQ6+b0M8bPK05Sz1sf8ewiHMwaKZ4AWpRo7HxkDIUltGr jOvPkZhImZOx4ZAssCRKuwRgh7LcUyXXLfVQ/k5PearM1ehh/jrBfgPZj2STMS+uKbknGCR iCd6Mb4xEkgJc2JuXXKpA== X-UI-Out-Filterresults: notjunk:1;V01:K0:luhwgfNL8JQ=:Of+n8hlnc0C5J5tyxLv//u ODNAEZjOYpgewXCwOR2KHeYOR/Ir9Nl5xi3XgC/jW7WR5f2XPe+dDmhiEdoAG6nJhKR1lY6vH +bdW0TPpuYEJX0GzUGL6+w6LW/LbL9BUrh9SuwPJkqSWVrF5o/pfk/G6lVy2gEVLw4GWpPGIM /bDN5EqzS+Vk3HSc1w2I09DWmIB3kUezE7Q2LoPRvmq3N1WwJt+e5lwtO3QyUSVFS2wl32Y0x yNSVmgsv4WlLk6YW3BqZ5sIkEGCi1U7rWoVIImqqp0YbocYqXcwRa2aLguc/1RzgNItKwOwpp UJdHHz6zq0m5MSquKKocrChG20TRqQqxaSf9YAFS4dqQimtrkF0hfCZ6LadeiQDYbwKw3lj0S 9I//IVfhywo6YRfOWB8eMELuvcGnDoEO7nPTNvMAbvRgKWCLBwFWxfeB8xbPsedy+x+YJA7cb TsYfXvDpigSi8xD11UMsX2+e2DU+tBKvoEG90mwP7FUqyC5r/+MvMbVGk9zd9LZDciCHGVrJa xUfTSzymMqSRaCKFanfohn8DCeIQiSROHkBq5/3zjolENi1pZD894KFEqrO2mwazjgJaT0VWl HRAbjrnRHksfCmYF3KesqdQApLU0Ot+9DyoHMQwXILCJBnN2yBrqmXfCtXSOtfoP/OhV/Rrcl jMYPOaXlvzeYMtZJW3J+e9NHZH+EagaO4zSyZfRQfCL+LbfdIKNAL9GpFU1pBl9NaTfs0b3qq zPiqtihBWVgHxKg4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2849 Lines: 60 On Friday, November 18, 2016 12:27:32 PM CET Binoy Jayan wrote: > Hi Sagi, > > On 31 October 2016 at 02:42, Sagi Grimberg wrote: > >> The semaphore 'sem' in isert_device is used as completion, so convert > >> it to struct completion. Semaphores are going away in the future. > > > > > > Umm, this is 100% *not* true. np->sem is designed as a counting to > > sync the iscsi login thread with the connect requests coming from the > > initiators. So this is actually a reliable bug insertion :( > > > > NAK from me... > > Sorry for the late reply as I was held up in other activities. > > I converted this to a wait_event() implementation but as I was doing it, > I was wondering how it would have been different if it was a completion > and not a semaphore. > > File: drivers/infiniband/ulp/isert/ib_isert.c > > If isert_connected_handler() is called multiple times, adding an entry to the > list, and if that happens while we use completion, 'done' (part of struct > completion) would be incremented by 1 each time 'complete' is called from > isert_connected_handler. After 'n' iterations, done will be equal to 'n'. If we > call wait_for_completion now from isert_accept_np, it would just decrement > 'done' by one and continue without blocking, consuming one node at a time > from the list 'isert_np->pending'. > > Alternatively if "done" becomes zero, and the next time wait_for_completion is > called, the API would add a node at the end of the wait queue 'wait' in 'struct > completion' and block until "done" is nonzero. (Ref: do_wait_for_common) > It exists the wait when a call to 'complete' turns 'done' back to 1. > But if there > are multiple waits called before calling complete, all the tasks > calling the wait > gets queued up and they will all would see "done" set to zero. When complete > is called now, done turns 1 again and the first task in the queue is woken up > as it is serialized as FIFO. Now the first wait returns and the done is > decremented by 1 just before the return. > > Am I missing something here? I think you are right. This is behavior is actuallly documented in Documentation/scheduler/completion.txt: If complete() is called multiple times then this will allow for that number of waiters to continue - each call to complete() will simply increment the done element. Calling complete_all() multiple times is a bug though. Both complete() and complete_all() can be called in hard-irq/atomic context safely. However, this is fairly unusual behavior and I wasn't immediately aware of it either when I read Sagi's reply. While your patch looks correct, it's probably a good idea to point out the counting behavior of this completion as explicitly as possible, in the changelog text of the patch as well as in a code comment and perhaps in the naming of the completion. Arnd