Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4523997ybv; Mon, 10 Feb 2020 21:42:03 -0800 (PST) X-Google-Smtp-Source: APXvYqyrXAeLxyUyasrDYvI4xsJpro9ZfKwyzUo3+L05FgEmw6Nj1CpiZ+Kmv7iMmXRV72m55z2Z X-Received: by 2002:aca:5fc6:: with SMTP id t189mr1922885oib.166.1581399722782; Mon, 10 Feb 2020 21:42:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581399722; cv=none; d=google.com; s=arc-20160816; b=kD7M1AhHsQ+NweFOWNPbiM9w/TPBOZOqzAmJ6XyIr2T5gOEzh2ROwSkcPXw+oZFmNp vteAuQEuW1UKqU7Z6BCeTD78DCI/Td29HCvrfeEQZ/sHzbv0nRgDeLQ0ZcIE8p1RTKxC 6nXIZk+y5P6Cu1iKDWr55BrxgCFUjjO9Z5m5q70vaKR9GohyS8GO8F3VZ4UyNHEx5CK3 6PL6s/kkLL5Cndzc3Y1lgPL/BwIZvYYH5hGOXJTVNTbiQ/EMWl3eygEhdaiAbsMC26ZP aV0C2T6ujNefZtEphun+ohImnFCP/wUK/acBdUp4SrPl/oMQlftpnM/pQCVNoGYGsr82 M34A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=6HJ00E5SaMJNd5jovvaBQPAR0zDWE5jfRsYbSlTxML4=; b=cGQHIJQOkHzImLcg8V+qbhJRGprxBRXv6sMoH9GMNsDk7NbRfyRoZTsP9GOgh/Y2aE EJ3R4OyHcjn/KJfIz0BWE5PiE9Dj79IwzsVTBECkfB4CA0+MxkK93LuEIhtUzF9hVxSc 3rP+fxQQrtOhy6t/YlbS+bUOaTsXyUCGlKO4Bzr367ZDVZ8XkNzyH1HL+C6DoBSM9v6a cdozDcNrGvcoxLJmrHBFtyACUpys1N8AmWvG13Fvd9drV+uHrBHFqLgEa3VEO/IZ5ZJn 2xtMg9ZPa5YjioeP0dMUUCo9BWH5cM8EEAgI3NB7STkFyiEw5Oi0sAiYKoY8hIDyNcBf xs7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=VO6oLe3N; 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 l13si1511627otq.30.2020.02.10.21.41.50; Mon, 10 Feb 2020 21:42:02 -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=pass header.i=@lca.pw header.s=google header.b=VO6oLe3N; 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 S1727944AbgBKDzs (ORCPT + 99 others); Mon, 10 Feb 2020 22:55:48 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:45104 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727588AbgBKDzr (ORCPT ); Mon, 10 Feb 2020 22:55:47 -0500 Received: by mail-qk1-f193.google.com with SMTP id a2so8375132qko.12 for ; Mon, 10 Feb 2020 19:55:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=6HJ00E5SaMJNd5jovvaBQPAR0zDWE5jfRsYbSlTxML4=; b=VO6oLe3NkOb/LbLNPK1KR16jo0KlzLn1LJ5uVe4IuhOO3oxJFJZsm+spOrlR3bt+oa hZn7blI23Icaz1LM4HTjXmprpS/J5mXdVnrn/l0ii0a6oJ///z8lMLQrnA+pWoD9LtI/ mKgCRwf/JaMT6Ai4t3nQfYdPKkp5kds36lrdwOlFWgRIIQpGXiLLaDQiiEhLvf4GMb/P cNTiigB2wP4MmELLeMhWBgVFKpR0oCP91rrINsHY73xYwSVOywyPV/KxgLxnbGZwAJL1 LTPnTB5shlCi6HqgPrVMYNWtt4sD4mnDy+fINpwKZL6hp/1/f7Op+5tdAwHuD0Q8kZjK 2nvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=6HJ00E5SaMJNd5jovvaBQPAR0zDWE5jfRsYbSlTxML4=; b=q7vna0Zetpv9hViYPcmvQYgJiW+Q+GtUB2tiJCR0OZBDBbpv6aNGUTuwnnR4cw/5tu Bs9KndzOByxuFa6Y2kjmvmwic2J62tU/l8gOKQIkDZjfknPbnNL2SWJbUZM3VdDA5p6G Sd4qhddNx3k5kPKTihq15H6zDb73AdEQohVqOLfXZICdo8cxW3rB7Z/UQxg0AOvoRFz4 uf4E36enwgclwEdBu7UydTJkSAqp5a2X5honpNnQXCEzcaFIh0597Y6uauJN0oS/7aZb 6EANjDSh7kNtP3lU31pF71r6mE3DDQPvfdvJSJ+tN3G1zCkjznP4PKYoFgzwSPKqY4dJ OrHA== X-Gm-Message-State: APjAAAV5XC1cYW8YUW7DZAZgeC0E18KhnRmWfXTIKYW/777GIrQJtyQW iZyykYJIEX18/+2loi7KZj+g+g== X-Received: by 2002:a05:620a:108f:: with SMTP id g15mr1028131qkk.321.1581393346926; Mon, 10 Feb 2020 19:55:46 -0800 (PST) Received: from [192.168.1.153] (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id f59sm1355949qtb.75.2020.02.10.19.55.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Feb 2020 19:55:46 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: [PATCH v2] mm/filemap: fix a data race in filemap_fault() From: Qian Cai In-Reply-To: <20200211034900.GQ8731@bombadil.infradead.org> Date: Mon, 10 Feb 2020 22:55:45 -0500 Cc: Andrew Morton , Marco Elver , Linux Memory Management List , linux-kernel@vger.kernel.org, "Kirill A . Shutemov" Content-Transfer-Encoding: quoted-printable Message-Id: <2EFC8936-4569-418F-82EC-6F7868BEEAE2@lca.pw> References: <20200211030134.1847-1-cai@lca.pw> <20200211034900.GQ8731@bombadil.infradead.org> To: Matthew Wilcox X-Mailer: Apple Mail (2.3608.60.0.2.5) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Feb 10, 2020, at 10:49 PM, Matthew Wilcox = wrote: >=20 > 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, >>=20 >> BUG: KCSAN: data-race in filemap_fault / filemap_map_pages >>=20 >> 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 >>=20 >> 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 >>=20 >> 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 >>=20 >> 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. >>=20 >> Suggested-by: Kirill A. Shutemov >> Signed-off-by: Qian Cai >=20 > That's more than Suggested-by. The correct way to submit this patch = is: >=20 > From: Kirill A. Shutemov > (at the top of the patch, so it gets credited to Kirill) Sure, if Kirill is going to provide his Signed-off-by in the first = place, I=E2=80=99ll be happy to submit it on his behalf. >=20 > then in this section: >=20 > Signed-off-by: Kirill A. Shutemov > Tested-by: Qian Cai >=20 > And now you can add: >=20 > Reviewed-by: Matthew Wilcox (Oracle)