Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4450289ybv; Mon, 10 Feb 2020 19:55:00 -0800 (PST) X-Google-Smtp-Source: APXvYqzRICG71zpNmWvzrt2QPgJPs34MKLShJVufHkpm9xb/MXWoFgvK9NEphXo15C4Mgb8iNGmZ X-Received: by 2002:a9d:62d8:: with SMTP id z24mr1554427otk.362.1581393300185; Mon, 10 Feb 2020 19:55:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581393300; cv=none; d=google.com; s=arc-20160816; b=cet2wgCxDxAqVuaFoJl6sgQYN/gaKYWy3Y+SoyUL4WxucdXPS0oQT9aO+rNAyFCV3m jn+VaxcA0kQMT5EaJ0YkjgW3iN+or2LmzyRkJcQZJpi7V9+MaksoAIhU20MjDohhh2wL jLNY6Px9S5+63t4tvzV6JT8kOjCFCyi5QhjHu/bq8+Y98gL0Qv+6mKIHdQbe7GqxF8JL jEHVivacE2bc5VU/QHg3v2c4wjW6bqboN125FRvK3FApxes/8debCl2z4PgXZe0QRYC4 R1/T6106lpCF+BCsFVnQwMHwA+V/3CG5eBAPzEHDRSwmBNyorWoVbSlRLYYVu8qcuURt kpjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=a7NvNilpUl5bhc9T/eXq6L5I1GFPcDpbrAQedowqMwY=; b=LgpMaGZhVCbrrnC5BlAgj/vGeqPCD+f0WMQCx2VdUWc96i9pMYAB9znxgN9avp6Fv7 eY3eaJeqwsCDUiF0BtZ2BgeL44RHbisMNqwJVip44vhhU5XUgCuhrlrDpvHCMJkv+nvJ s0idoB9y+Tmhvs69p/Psko/vgy2o1/dgk2pAQGdahlvyqnPdo2kgBT+Hkuh+DErhox3y cz366ucNoBbfLX8cBdLFmVkSMmrcDABMf9e3IZlTsoNssrJtZNYiYx+uQ6AXVZG6Y+FJ cL0UDvIL3UlVL9yzHao/vGoP1IVRoIAH6ePZ4AOrpLd5ixLcu8e1HPRFQmX1lXaWAH5o WaTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=CYQ9LsW7; 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 g17si1342929otk.252.2020.02.10.19.54.48; Mon, 10 Feb 2020 19:55: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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=CYQ9LsW7; 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 S1727668AbgBKDtF (ORCPT + 99 others); Mon, 10 Feb 2020 22:49:05 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:56026 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727045AbgBKDtF (ORCPT ); Mon, 10 Feb 2020 22:49:05 -0500 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; bh=a7NvNilpUl5bhc9T/eXq6L5I1GFPcDpbrAQedowqMwY=; b=CYQ9LsW7rkCgbKw2z+J2rI0Ma0 Va6fm0irz2nQg6MMMbI8eRTHUzmutpvZiw/YaOuIUFMH0+tAPVU1YkDwJn61UBTqRaadOdRCdn8qb qDi/Y9mUUYaQ8sj7247kA7yYazGNRnY0xrFOKHq+udYn1zDqgtQSpbPRWuwk3ttUCXIjtDPOLcuWv U2WvvYmGkeDqKHQJmZfUuM/pPdQJ6OiW67uFcFvDPtExaLicCdMnLdc1YEK3Fz5i6wjNanH6/ZMFf RoxhuQuyyI7UXfwKp4erVrmnWy9ZHc82s+r68BAGK3fxrSpCb+EGC8tqUKIbCpgnDyNR3kcKLxdLD i1opX2/Q==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j1MXl-0004eR-1f; Tue, 11 Feb 2020 03:49:01 +0000 Date: Mon, 10 Feb 2020 19:49:00 -0800 From: Matthew Wilcox To: Qian Cai Cc: akpm@linux-foundation.org, elver@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A . Shutemov" Subject: Re: [PATCH v2] mm/filemap: fix a data race in filemap_fault() Message-ID: <20200211034900.GQ8731@bombadil.infradead.org> References: <20200211030134.1847-1-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200211030134.1847-1-cai@lca.pw> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 10, 2020 at 10:01:34PM -0500, Qian Cai wrote: > struct file_ra_state ra.mmap_miss could be accessed concurrently during > page faults as noticed by KCSAN, > > BUG: KCSAN: data-race in filemap_fault / filemap_map_pages > > write to 0xffff9b1700a2c1b4 of 4 bytes by task 3292 on cpu 30: > filemap_fault+0x920/0xfc0 > do_sync_mmap_readahead at mm/filemap.c:2384 > (inlined by) filemap_fault at mm/filemap.c:2486 > __xfs_filemap_fault+0x112/0x3e0 [xfs] > xfs_filemap_fault+0x74/0x90 [xfs] > __do_fault+0x9e/0x220 > do_fault+0x4a0/0x920 > __handle_mm_fault+0xc69/0xd00 > handle_mm_fault+0xfc/0x2f0 > do_page_fault+0x263/0x6f9 > page_fault+0x34/0x40 > > read to 0xffff9b1700a2c1b4 of 4 bytes by task 3313 on cpu 32: > filemap_map_pages+0xc2e/0xd80 > filemap_map_pages at mm/filemap.c:2625 > do_fault+0x3da/0x920 > __handle_mm_fault+0xc69/0xd00 > handle_mm_fault+0xfc/0x2f0 > do_page_fault+0x263/0x6f9 > page_fault+0x34/0x40 > > Reported by Kernel Concurrency Sanitizer on: > CPU: 32 PID: 3313 Comm: systemd-udevd Tainted: G W L 5.5.0-next-20200210+ #1 > Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 07/10/2019 > > ra.mmap_miss is used to contribute the readahead decisions, a data race > could be undesirable. Both the read and write is only under > non-exclusive mmap_sem, two concurrent writers could even overflow the > counter. Fixing the underflow by writing to a local variable before > committing a final store to ra.mmap_miss given a small inaccuracy of the > counter should be acceptable. > > Suggested-by: Kirill A. Shutemov > Signed-off-by: Qian Cai That's more than Suggested-by. The correct way to submit this patch is: From: Kirill A. Shutemov (at the top of the patch, so it gets credited to Kirill) then in this section: Signed-off-by: Kirill A. Shutemov Tested-by: Qian Cai And now you can add: Reviewed-by: Matthew Wilcox (Oracle)