Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp594198imm; Fri, 22 Jun 2018 01:51:38 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJLTDOOExVY1AnVSjFYtIQJ8DZELbe6vQe03RfZJ4RJvLe0Sjp2Gddk6xmiwt3Bdp9pVTyE X-Received: by 2002:a17:902:b48f:: with SMTP id y15-v6mr725517plr.261.1529657498704; Fri, 22 Jun 2018 01:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529657498; cv=none; d=google.com; s=arc-20160816; b=VCrfgFBMbGb0ktfQk5KEtSZg0INOF0TnZZ508emi3M0/tVY0AgrMjFgPmK+2jDkOz2 qck7cHsH4LlVpItiqtBGI8lw+QRzH3Wl01qtQD7EN63cpaaNRUsOXv+FgVPWhvmV5frF Ht7+vMuJ4zH6vbtsOS3rhJS1WcD2m8l5RJqQRE5ZNpY34o5kTvlai9C42IEW9ZBwa1q1 mmmx0kXTbIz8KtYqgGu1ob8AYscbdxvAd+W7e53OdnHTY0DSrA7TP+jIYCXNIALKzTMX mUcpHhp0PgDiEd5dukQHvaVadQBL8ShEgDuWHzOigqgNeVCxkyy+o0OxlquNXQ+GFyzp mqig== 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=GoqfHZsz3759gPAyr7q/ARALEUDk385h4owJdiH31II=; b=0hEE0VZEKbM7pV9/UZJUTirFEhXazRKt+XxvmlRk3Up9xyOKC6ZgTH2+aEAuJcScnn T/udMlP3S0+FHDLJLCBYijdCmzLGd1MFbc4LZHsBbRviJSeIqbGue63R6dpDgjBDGXwb ntpNtEZ4MB7fwu33mIp1clm2jOaQNIC/27Wq6CjQO+Wcm0OPVOvw3MrxaXnK16xOFfD3 v39zAl7dXw/O8coXk7jQjguNaZe265gg8F++LYFKzBRxfyTM76+CR2fERaEO1VnN1QYF 9UlSl8LwokPWb3pBQ8uI+pf3SvTrd/X2ZXq2mp+5GwD+DJ9FqPoPVxxUqd30I/F4WaGr 4iUg== 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 d26-v6si5658327pge.330.2018.06.22.01.51.24; Fri, 22 Jun 2018 01:51:38 -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 S1751315AbeFVIuk (ORCPT + 99 others); Fri, 22 Jun 2018 04:50:40 -0400 Received: from mx2.suse.de ([195.135.220.15]:53484 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751191AbeFVIui (ORCPT ); Fri, 22 Jun 2018 04:50:38 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 637C7AF8E; Fri, 22 Jun 2018 08:50:37 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 876341E34BE; Fri, 22 Jun 2018 10:50:35 +0200 (CEST) Date: Fri, 22 Jun 2018 10:50:35 +0200 From: Jan Kara To: Matthew Wilcox Cc: Jia-Ju Bai , axboe@kernel.dk, akpm@linux-foundation.or, jack@suse.cz, zhangweiping@didichuxing.com, sergey.senozhatsky@gmail.com, andriy.shevchenko@linux.intel.com, christophe.jaillet@wanadoo.fr, aryabinin@virtuozzo.com, linux-mm@kvack.org, Linux Kernel Mailing List Subject: Re: [BUG] mm: backing-dev: a possible sleep-in-atomic-context bug in cgwb_create() Message-ID: <20180622085035.2zn2voqgqxcx55f3@quack2.suse.cz> References: <626acba3-c565-7e05-6c8b-0d100ff645c5@gmail.com> <20180621033515.GA12608@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180621033515.GA12608@bombadil.infradead.org> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 20-06-18 20:35:15, Matthew Wilcox wrote: > On Thu, Jun 21, 2018 at 11:02:58AM +0800, Jia-Ju Bai wrote: > > The kernel may sleep with holding a spinlock. > > The function call path (from bottom to top) in Linux-4.16.7 is: > > > > [FUNC] schedule > > lib/percpu-refcount.c, 222: > > schedule in __percpu_ref_switch_mode > > lib/percpu-refcount.c, 339: > > __percpu_ref_switch_mode in percpu_ref_kill_and_confirm > > ./include/linux/percpu-refcount.h, 127: > > percpu_ref_kill_and_confirm in percpu_ref_kill > > mm/backing-dev.c, 545: > > percpu_ref_kill in cgwb_kill > > mm/backing-dev.c, 576: > > cgwb_kill in cgwb_create > > mm/backing-dev.c, 573: > > _raw_spin_lock_irqsave in cgwb_create > > > > This bug is found by my static analysis tool (DSAC-2) and checked by my > > code review. > > I disagree with your code review. > > * If the previous ATOMIC switching hasn't finished yet, wait for > * its completion. If the caller ensures that ATOMIC switching > * isn't in progress, this function can be called from any context. > > I believe cgwb_kill is always called under the spinlock, so we will never > sleep because the percpu ref will never be switching to atomic mode. You are right that the sleep under spinlock never happens. And the reason is that percpu_ref_kill() never results in blocking - it does call percpu_ref_kill_and_confirm() but the 'confirm' argument is NULL and thus even percpu_ref_kill_and_confirm() never blocks. Honza -- Jan Kara SUSE Labs, CR