Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2500504imm; Mon, 28 May 2018 09:15:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrFKBj5LLiLjBSJumlblGGx3NwUOiJVGaUV0eXp3xDPS+3X5NX38Ktm0rfkhYp2CFOs5/zi X-Received: by 2002:a62:91b:: with SMTP id e27-v6mr14100363pfd.93.1527524107172; Mon, 28 May 2018 09:15:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527524107; cv=none; d=google.com; s=arc-20160816; b=tibIz5vgP5BFnPU1ce3M2th/YfvmfO5IeZ3lY7C/MSzF6pyPhPtLkteqqyUZEkl+Ro zPkjNnr+yMJ7KCOCl8N+2OgvqGcDhgRA+lSAMG/PtJpdk3Jlw3VGdbm+1iP2tmKOL8vw tGVbEw1JTyY56la5niY06ezvYG+fJDF/t4TDHohL0GSeC8Q9fxQpTRq14QIIitGDD6Jg wA+pKovz1wg8ccQMh+99tC/6FTTmuGpkyAa6KEp95wWd4Bi/PN7ng1lXkmKMQyiYEg2W eib2Vj06FL0b3iWkj57LSyzxWE/WUGWih6VtoQefv7jsAtbURJdumGHe9+q6fMecT/fz GsZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=jZFMJ5XhQ9sNwoaqe6lCJjiGA2yqCBRQlrLllt1yR94=; b=qaAACqtZH6ngLAANFZRozW9P0v1izcDbOOrNU2xaXds8ZHW6KG7/Qa0vOAYKV9CGIi VaWjdLn9xM+9rZvAxESj3XCDstOIK28snwuVoEajcW33MEWECkkpS3yfcDdOtOK9AUCw gN1CsrEM0bZRsmFFlI//bAiHEBvZtBjfiBgeiIaHZ0GWEkLaynhdc28c81sGNroOyTDN EzlYumQXXvyQp/fT5oeaVD5skTKCIeGakl2gUXl2bCmVf2YWyHkw5viyN9SbAWxmmeon RXOeSRq5o8cF1/dXxD8/E0J5FAcHcA/hvmkBdzUmI6+QOhZmS9nCboyFb+S7ua9pizzW nn6A== 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 r7-v6si30979442ple.585.2018.05.28.09.14.52; Mon, 28 May 2018 09:15:07 -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; 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 S939879AbeE1QOW (ORCPT + 99 others); Mon, 28 May 2018 12:14:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:49814 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935137AbeE1QNu (ORCPT ); Mon, 28 May 2018 12:13:50 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 05D99ADD1; Mon, 28 May 2018 16:13:47 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 4FEB51E0570; Mon, 28 May 2018 15:35:03 +0200 (CEST) Date: Mon, 28 May 2018 15:35:03 +0200 From: Jan Kara To: Tetsuo Handa Cc: syzbot , syzkaller-bugs@googlegroups.com, jack@suse.cz, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk, tj@kernel.org, david@fromorbit.com, linux-block@vger.kernel.org Subject: Re: general protection fault in wb_workfn (2) Message-ID: <20180528133503.awomzj6djozbo5bv@quack2.suse.cz> References: <000000000000cbd959056d1851ca@google.com> <0c7c5dea-7312-8a59-9d1b-5467f69719bf@I-love.SAKURA.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0c7c5dea-7312-8a59-9d1b-5467f69719bf@I-love.SAKURA.ne.jp> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun 27-05-18 09:47:54, Tetsuo Handa wrote: > Forwarding http://lkml.kernel.org/r/201805251915.FGH64517.HVFJOOLFFMQStO@I-love.SAKURA.ne.jp . > > Jan Kara wrote: > > > void delayed_work_timer_fn(struct timer_list *t) > > > { > > > struct delayed_work *dwork = from_timer(dwork, t, timer); > > > > > > /* should have been called from irqsafe timer with irq already off */ > > > __queue_work(dwork->cpu, dwork->wq, &dwork->work); > > > } > > > > > > Then, wb_workfn() is after all scheduled even if we check for > > > WB_registered bit, isn't it? > > > > It can be queued after WB_registered bit is cleared but it cannot be queued > > after mod_delayed_work(bdi_wq, &wb->dwork, 0) has finished. That function > > deletes the pending timer (the timer cannot be armed again because > > WB_registered is cleared) and queues what should be the last round of > > wb_workfn(). > > mod_delayed_work() deletes the pending timer but does not wait for already > invoked timer handler to complete because it is using del_timer() rather than > del_timer_sync(). Then, what happens if __queue_work() is almost concurrently > executed from two CPUs, one from mod_delayed_work(bdi_wq, &wb->dwork, 0) from > wb_shutdown() path (which is called without spin_lock_bh(&wb->work_lock)) and > the other from delayed_work_timer_fn() path (which is called without checking > WB_registered bit under spin_lock_bh(&wb->work_lock)) ? In this case, work should still be queued only once. The synchronization in this case should be provided by the WORK_STRUCT_PENDING_BIT. When a delayed work is queued by mod_delayed_work(), this bit is set, and gets cleared only once the work is started on some CPU. But admittedly this code is rather convoluted so I may be missing something. Also you should note that flush_delayed_work() which follows mod_delayed_work() in wb_shutdown() does del_timer_sync() so I don't see how anything could get past that. In fact mod_delayed_work() is in wb_shutdown() path to make sure wb_workfn() gets executed at least once before the bdi_writeback structure gets cleaned up so that all queued items are finished. We do not rely on it to remove pending timers or queued wb_workfn() executions. Honza -- Jan Kara SUSE Labs, CR