Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4693074imu; Tue, 8 Jan 2019 04:48:00 -0800 (PST) X-Google-Smtp-Source: ALg8bN41C+0kWkj5GLUyqtDc/ZHIHSejwcrKuGSO7Taz53Aw8TpPP5hm7LrBoH6PLDx/FbovVtcc X-Received: by 2002:a63:3f89:: with SMTP id m131mr1444317pga.115.1546951680355; Tue, 08 Jan 2019 04:48:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546951680; cv=none; d=google.com; s=arc-20160816; b=mIzaLT0btWJNo+KYz4Ni9T3JRjLTGsjyA8Mk5VF92CUA9FUJgV0m7Z7uvEYFBnGQQZ O4ZLwvoFutRQ+Xxf1WGmpndTWOejcWJYSPD0l0LpXKkVJgV37xnlXC9Ms5zoOZDJN8Ep aW8yukp1BZNDRe9YiQMh4ByyPlL3MZ7uz8tlFUoVnTdFSosfiAQH4bmU/2cDEqG6TuLT ZzANVKuhmSiMRyG/p0auBdbGwuEvM84BHPitO76Rb+hjcL0wHBheTQocZr0XWviXNe7S xqrm1g6rUHERyzBjFtyGapXnS0hoqlVu+c/DhncdQAQLr7D9TsXqiJL7ptu2c0+oW2EG tVIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:to:from:date:content-transfer-encoding :mime-version; bh=ecTr1mXia7tgAo0fmwx76BWV1K6nEs28K1e41o//t7E=; b=RxY1BKe7McXxQukztKiSShsoy9QbEfMi97CHy8RdbNzqjatpLgUm0d4yPAaAWfg7uD wUMl8gHtwY1p3Htrw5e7Mazfms5TJPdgM1ivH9jCO6EAjkZzjYSBQ2vnqPtrK8kSzhYI EazsiUNQLSLKCxwGWm/Yc/1XYzJ5n3E/BcmKlTWCcYKBfJNb56fmNupV2RlYpOem1yT8 TWzjCSSKsQFat18lipNa1pc2ZZohBBz8zJBNXPAuHb4Jb1O+YOY0Ux8uFIKVl5qXSauf QfLY7a7/bLHo1yZTm64WNp1ba8rM161cQg2luRFeXf2icDXrUih6eyc3uVPMG/HDltiF 4Tiw== ARC-Authentication-Results: i=1; mx.google.com; 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 b65si63743921pgc.259.2019.01.08.04.47.45; Tue, 08 Jan 2019 04:48:00 -0800 (PST) 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; 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 S1727779AbfAHMm1 (ORCPT + 99 others); Tue, 8 Jan 2019 07:42:27 -0500 Received: from mx2.suse.de ([195.135.220.15]:51466 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727236AbfAHMm0 (ORCPT ); Tue, 8 Jan 2019 07:42:26 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 791DCAF89; Tue, 8 Jan 2019 12:42:25 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 08 Jan 2019 13:42:25 +0100 From: Roman Penyaev To: Davidlohr Bueso , Jason Baron , Al Viro , Andrew Morton , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] epoll: remove wrong assert that ep_poll_callback is always called with irqs off In-Reply-To: <20190108100121.20247-1-rpenyaev@suse.de> References: <20190108100121.20247-1-rpenyaev@suse.de> Message-ID: X-Sender: rpenyaev@suse.de User-Agent: Roundcube Webmail Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-01-08 11:01, Roman Penyaev wrote: > That was wrong assumption that all drivers disable irqs before waking > up > a wait queue. Even assert line is removed the whole logic stays > correct: > epoll always locks rwlock with irqs disabled and by itself does not > call > from interrupts, thus it is up to driver how to call wake_up_locked(), > because if driver does not handle any interrupts (like fuse in the the > report) of course it is safe on its side to take a simple spin_lock. This is wrong and can lead to dead lock: we always call read_lock(), caller can call us with irqs enabled. Another driver, which also calls ep_poll_callback(), can be called from interrupt context (irqs disabled) thus it can interrupt the one who does not disable irqs. Even we take a read_lock() (which should be fine to interrupt), write_lock(), which comes in the middle, can cause a dead lock: #CPU0 #CPU1 task: task: irq: spin_lock(&wq1->lock); ep_poll_callback(): read_lock(&ep->lock) .... write_lock_irq(&ep->lock) .... #waits reads .... >>>>>>>>>>>>>> IRQ CPU1 spin_lock_irqsave(&wq2->lock) ep_poll_callback(): read_lock(&ep->lock); # to avoid write starve should # wait writer to finish, thus # dead lock What we can do: a) disable irqs if we are not in interrupt. b) revert the patch completely. David, is it really crucial in terms of performance to avoid double local_irq_save() on Xen on this ep_poll_callback() hot path? For example why not to do the following: if (!in_interrupt()) local_irq_save(flags); read_lock(ep->lock); with huge comment explaining performance number. Or just give up and simply revert the original patch completely and always call read_lock_irqsave(). -- Roman