Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1511330imm; Wed, 20 Jun 2018 20:36:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLpdjGnbxYXyuKZvubRksYps9GQuYkVV+CN15PYEXGFWjuw23VPHBDX8AZsV0eweMmnttkw X-Received: by 2002:a63:4b18:: with SMTP id y24-v6mr21007501pga.54.1529552182528; Wed, 20 Jun 2018 20:36:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529552182; cv=none; d=google.com; s=arc-20160816; b=e5Q6FkUPIR3AgQo4XSGUV8dYUxK6FEwujU8g21C65E6GjGVbvkKD+rMZJd7mtZV1ra exeiQnilbz+lJqS8TICgylCle5i5nyzruPrxL1ujrjvTysRJQ4aUg137b2qRFUd4he1C pPe51NTDbxrDlns/dnk6MQa5WbiRzOthzqDNihHxC39ab2j+/DMr6QEIV9Gg9aUX0qja B4su1jiFjXihfnBzjiRza/L5vdKyUVS8FHZCDCzwbyzIdS2rCknO2m9N6bNqbMTcLw/6 MhiV6NKf7FHfCFOrBveeyB211qEQ447REOBwqnW5J+d54FrUCc0t93HiIqeNatoHWU0a BnEQ== 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:dkim-signature:arc-authentication-results; bh=9rN4WPOaDAdQrHZKtVSKwfnGHageL7nl3Z8DGtCigv0=; b=hD2c8pVv0ncwoSLJhlqrn64TAlNeaggo19m/huOtei8sShENOCHEcf/US7qkqV+YRE kPKLg011BGZ8TxNEmvoVoSSd8MT5Tak2T1Z1xW90ts4TPK64Z3uOcsAOMSaOwe7fPC/a RoxirnhZyAdKf844hcbgbau0pEEyXe/41j4gHO5i+g25jpn6o3EPrmKka4mC0dOTxVP6 fpiahLdD1b9rshmF3o7xodfg2Pmcm/TOKRRujzD1jYtmLxNWe5YbR6+NWT+yEmhOVsDc kvtFrxUa+WDZ3fTdWUcrJSAC58aO3khw3xRSNyMS/cFRwaD1VjwkLwtbuVa2wGiX3/hz zDew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=NklE6PJ5; 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 o25-v6si2221128pge.7.2018.06.20.20.36.08; Wed, 20 Jun 2018 20:36:22 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=NklE6PJ5; 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 S1754356AbeFUDf3 (ORCPT + 99 others); Wed, 20 Jun 2018 23:35:29 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:57236 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754166AbeFUDf2 (ORCPT ); Wed, 20 Jun 2018 23:35:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=9rN4WPOaDAdQrHZKtVSKwfnGHageL7nl3Z8DGtCigv0=; b=NklE6PJ5ubwSxjlLz4NSlG4/L myzDFV0Zy2YerYDp+8gnjubPKYPbuzkSH8SsDAdgWDFT3dDQeW0/D8DGCcrpHUVCXo4GmDmd8rI4P HPMbvJFJFMrF0n6BNbdS0w38UD4II6e5dQC6XGe2UOSntdBgPsrHmXvdYEncxZ8XiEZnx1tkZ5QGQ 9awbJGAEhixHzwzzIDppvohMsEpmm/xBF2NKPhc7hVVDdy7++mAQ3ea26ZTT50+YfnR3JniawcJxZ YeyryO3+nYrYxrmmQ8GNODCz9Svzl3jFP2kGrhrsWWtz2YVvodW4MeC8bG9kejZ7XTgJD8NhTrvY5 hdCnAZjfg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fVqNP-00088l-BD; Thu, 21 Jun 2018 03:35:15 +0000 Date: Wed, 20 Jun 2018 20:35:15 -0700 From: Matthew Wilcox To: Jia-Ju Bai Cc: 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: <20180621033515.GA12608@bombadil.infradead.org> References: <626acba3-c565-7e05-6c8b-0d100ff645c5@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <626acba3-c565-7e05-6c8b-0d100ff645c5@gmail.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. This is complex and subtle, so I could be wrong.