Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2304294yba; Mon, 15 Apr 2019 08:57:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZ7jbYOjd1c3ybtvDoXCP4mefWh4hcLcUmvP+9oL0q8mNmHVn63azi1b1m1q25zfgmKcC4 X-Received: by 2002:a17:902:2a03:: with SMTP id i3mr76731658plb.229.1555343831584; Mon, 15 Apr 2019 08:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555343831; cv=none; d=google.com; s=arc-20160816; b=mcvc0Ny1RhDMmqsHjdxaR5MI9RGxHVYv5wJ2PZhGs8oINAJ/c3S9VxHhMce62bPlkw 6TulCqV2GK0J5SEi5EvNX7QQjzdyo59jh53NrB8yN+whKteS1SkIdo6+0i8M05OKicE4 hO+f0W+IrqwEC/iYjOSd7+xqVbSILMpJAvAOFFZUkWiYfxSZO0ks7icXzbDbPEK3kc94 zYcfB//p1Bm721yaV3zM7MaqYCoypjWywvG1HNg+RvdHU8ZSVU4F9RqAwBC1mn+sesFo k4HRiYC+hKRz+scZYeD8wB3BxvJZpobhY61K6hG95Su94IyhR1rHSbOlX0wztndZrQOn zPSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :date:in-reply-to:references:message-id:cc:to:subject:from :dkim-signature:dkim-signature; bh=d0W7Z8nFQ4X/vRXX6lWS7UtbrZ1ez/JWeQL7TBTIJzI=; b=UJ0BMNPuFZFc/q6MAb0h38iqHp8vrWPGqcHdfQ1XwKitLFa7cFWKVV96U3Q4zdfUS4 Bxz823qoODx+QNZtu/iiTcwgzMWwPPmeWjvmvsgIgJyJZMyaYv2E9wxIF0XtypULy4ty XhZiIGgJqmIISeg7BYRIWAhnEAg0Nn3WqE7LmP0amW6FjFJIzeIFqzkN7LXLiGhGVoaT WuB8Zpn7LdacZe8bfm9p9F/+2EdYVSoXdA3qrFgNlKrfpa/NK1aSV7IunAyEwvfBwkCZ UoPOZmOihvgHt+7tZstXqXEmraTqBeXVTJPFO+FH0Qh5n7iVeds8q4wD1My9VfdFoKWm VnZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nexedi.com header.s=mandrill header.b=Z6r4nUjn; dkim=pass header.i=@mandrillapp.com header.s=mandrill header.b=TnXRxb07; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c20si45173540pls.53.2019.04.15.08.56.55; Mon, 15 Apr 2019 08:57:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nexedi.com header.s=mandrill header.b=Z6r4nUjn; dkim=pass header.i=@mandrillapp.com header.s=mandrill header.b=TnXRxb07; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727728AbfDOP4K (ORCPT + 99 others); Mon, 15 Apr 2019 11:56:10 -0400 Received: from mail18.wdc04.mandrillapp.com ([205.201.139.18]:8401 "EHLO mail18.wdc04.mandrillapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727691AbfDOP4I (ORCPT ); Mon, 15 Apr 2019 11:56:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=mandrill; d=nexedi.com; h=From:Subject:To:Cc:Message-Id:References:In-Reply-To:Date:MIME-Version:Content-Type:Content-Transfer-Encoding; i=kirr@nexedi.com; bh=d0W7Z8nFQ4X/vRXX6lWS7UtbrZ1ez/JWeQL7TBTIJzI=; b=Z6r4nUjnICcRu92UOvH1XLj1O2A5EDL31V3MLAN3cTrtfpNy4gMSogFswdRkS6H9ireQ0ZYVZi40 jvJBqI0Il8KV93yYFOJshvpgAXUn3qyfKIrxmc8pmATF06UOjskJo3NkO4g5lDbmNo83nIR8OpeY SoyXjTzX78M6O74KugA= Received: from pmta08.mandrill.prod.suw01.rsglab.com (127.0.0.1) by mail18.wdc04.mandrillapp.com id hmikpe1jvmgt for ; Mon, 15 Apr 2019 15:41:06 +0000 (envelope-from ) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; i=@mandrillapp.com; q=dns/txt; s=mandrill; t=1555342866; h=From : Subject : To : Cc : Message-Id : References : In-Reply-To : Date : MIME-Version : Content-Type : Content-Transfer-Encoding : From : Subject : Date : X-Mandrill-User : List-Unsubscribe; bh=d0W7Z8nFQ4X/vRXX6lWS7UtbrZ1ez/JWeQL7TBTIJzI=; b=TnXRxb07AgPlitqE9ik3R/d/o0teu5WwmZL83xejwjmN9SqJcJZ6IZYs60XvLQD2cwNO05 kL9fgCyt7vMEKkIJAVU2TrAz0OeBzRWIDL0HDSKqG0GN8ms4ThIxey9byVQYgpcCJFaVui4/ EDEKVXjz/b+7TTQtBcc//s2QHS3B8= From: Kirill Smelkov Subject: Re: [PATCH] pci/switchtec: fix stream_open.cocci warnings (fwd) Received: from [87.98.221.171] by mandrillapp.com id 0cc2e3a14ea74c468aa4c3d438114fbb; Mon, 15 Apr 2019 15:41:06 +0000 To: Sebastian Andrzej Siewior Cc: Julia Lawall , , Kurt Schwemmer , Logan Gunthorpe , Bjorn Helgaas , , Message-Id: <20190415154102.GB17661@deco.navytux.spb.ru> References: <20190413170056.GA11293@deco.navytux.spb.ru> <20190415143857.kg2dbg3zxsxdktsi@linutronix.de> <20190415145456.GA15280@deco.navytux.spb.ru> <20190415152021.3j3riefeoz7rf2pa@linutronix.de> In-Reply-To: <20190415152021.3j3riefeoz7rf2pa@linutronix.de> X-Report-Abuse: Please forward a copy of this message, including all headers, to abuse@mandrill.com X-Report-Abuse: You can also report abuse here: http://mandrillapp.com/contact/abuse?id=31050260.0cc2e3a14ea74c468aa4c3d438114fbb X-Mandrill-User: md_31050260 Date: Mon, 15 Apr 2019 15:41:06 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sebastian, On Mon, Apr 15, 2019 at 05:20:22PM +0200, Sebastian Andrzej Siewior wrote: > On 2019-04-15 14:55:02 [+0000], Kirill Smelkov wrote: > > Hi Sebastian, > Hi Kirill, > > > On Mon, Apr 15, 2019 at 04:38:57PM +0200, Sebastian Andrzej Siewior wrote: > > > On 2019-04-13 17:00:59 [+0000], Kirill Smelkov wrote: > > > > stream_open.cocci was issuing only warning for pci/switchtec, but after > > > > 8a29a3bae2a2 ("pci/switchtec: Don't use completion's wait queue") they > > > > started to use wait_even_* inside read method and, since > > > > stream_open.cocci considers wait_event_* as blocking the warning became > > > > error. Previously it was completions there, but I added support for wait > > > > events only for simplicity. > > > > > > why is wait_event_interruptible() treated differently compared to > > > wait_for_completion_interruptible()? > > > > No particular reason. I just taught stream_open.cocci to consider > > only "wait_event_*" as blocking: > > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/coccinelle/api/stream_open.cocci?h=v5.1-rc5#n35 > > > > based on original /proc/xen/xenbus deadlock: > > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/xen/xenbus/xenbus_dev_frontend.c?h=v5.1-rc5#n135 > > https://git.kernel.org/linus/581d21a2d02a > > > > We can extend "a function that blocks" rule to cover other kernel > > primitives. > > > > For the reference: the deadlock scenario is described in > > > > https://git.kernel.org/linus/10dce8af3422 > > As far I understand the problem is when the ->read() callback waits for > the ->write() callback. The locking isn't changed by patch you > mentioned. Yes, correct. The patch that I mentioned only adds semantic patch which find places with such problem and can generate a regular patch to change locking. Here is that place for pci/switchtec: https://lab.nexedi.com/kirr/linux/commit/edaeb4101860?expand_all_diffs=1#ccc4baef911c8dad164d4ff29a8c0b287abed7c2_393_393 > So extended might make sense. But then wait_event_* by itself in > ->read() isn't a problem as long as its counter part isn't in ->write(). It is a problem either if its counterpart is in write _or_ if that wait_event depends on external source and waiting can be for potentially unbounded time, like e.g. waiting to receive a character from serial port or network. But you are right that even with wait_event used, cases are possible that there is no blocking that depend on external source and it could be just e.g. spawn kernel thread to do some limited amount of work and wait for it to complete. I did not taught stream_open.cocci about that because when something goes wrong with semantic patch and Coccinelle complains, it is hard to understand what is going on, and because generally it is better to convert files that do not depend on position, even if there is no deadlock at all, to stream_open - i.e. don't do any f_pos_lock locking at all. > But yes, nice finding. Thanks, Kirill