From patchwork Tue Nov 13 05:50:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 299A113B5 for ; Tue, 13 Nov 2018 05:51:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18E8B2A2A0 for ; Tue, 13 Nov 2018 05:51:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1704E2A2D9; Tue, 13 Nov 2018 05:51:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C2BC2A2B7 for ; Tue, 13 Nov 2018 05:51:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE0E06B0275; Tue, 13 Nov 2018 00:51:11 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D3F076B0276; Tue, 13 Nov 2018 00:51:11 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C311B6B0277; Tue, 13 Nov 2018 00:51:11 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 82E266B0275 for ; Tue, 13 Nov 2018 00:51:11 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id d11-v6so8721125plo.17 for ; Mon, 12 Nov 2018 21:51:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=HO8NXoH9HC+Id3/X9jGgx4dOol+odVvFSfDdh7H+ymY=; b=pFEUC0x0h+Dw6vlIK8beQ5RcQ/k1CB4WmjpPFdqNxJ3YNv6r6HmrfR4G4FfKb5emdw IlLqNpSwkgEt40Q4exxfICzlj4rasHGwUszPYs+cV9KfWmQ9r8/s30eoHQeMSNimGa5I MYQ2hZ/1TUj7zZGbhvqgcFfuioUjSow59q1RCaMjUxu06LyDL1N0au5VG73Zes8aGnj1 UPXUIP/jA7eUTx6W+o1RTyg1ZuIbXsVilL9PabWykkg54KImfEvOx+ZnFDWgpzNCYh6E X97yPZUEgqNy/+okvJAyKez/pu7A45XMnqf2ybSvGNOMM4lksuFxntYpRpASnzz3bhA9 KQzA== X-Gm-Message-State: AGRZ1gImJZjk+Y9Hu2D6dDBUjHHbbt7cZgw0cGrxbqNlUgwrdAW0y8id RrFquvJxnTJnnmcoGbqmClq9hzBxVf1p48Eyjuppy+lVe5Ld3zjrCyI1RFbtQxtb5lGoeeT9WnS cLgajCDErNsCb7Ty8tAT+qrBnUidb0k7+BwNVVcZq8bI9Xbk3X9OYty8c//uNkb+M1w== X-Received: by 2002:a63:2141:: with SMTP id s1mr1677740pgm.148.1542088271207; Mon, 12 Nov 2018 21:51:11 -0800 (PST) X-Google-Smtp-Source: AJdET5cd3TSs6OeX+6x2kTrTZb9T48tffFfjMSgQ+8QkQATBpL+GS/vMY3qwsm7RVj5QsjCLMqaO X-Received: by 2002:a63:2141:: with SMTP id s1mr1677713pgm.148.1542088270434; Mon, 12 Nov 2018 21:51:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088270; cv=none; d=google.com; s=arc-20160816; b=WmCpGaE32PGShT/oHB/8R8+uDjwELz01Nu1eGytoWYFqGZvvpPaHSwsCHNsTbWKFiK m3ayv7xbY8ZFLYO2lkmvvecDFegFKcbD+U2ETmZYPmsDRD85ZdCqcf9eyyiQZOEiEF77 MzlztEN8Yx4xIZ24ZIoYiqYYoiAV/Aa+qXs0a0i9BYiXsLLSakyayTlM4r77T4grb4bw Oxnh8cLxQ4aBgQH4fTGuuyLFLxiTfQLAu1BrYO+q3A6gHl8O7Ehf7XKlkzWPIl7JpnIo ZBmDA57+dwl2QuN0Jj0CUnjzXB/oNSQK3RA0c4De6LlPa1aXW1ddGIbFqOTKArVo3XUv Y5Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HO8NXoH9HC+Id3/X9jGgx4dOol+odVvFSfDdh7H+ymY=; b=n1otRO3NAKKSY6aJCfFZGVIb4c4dGqCDhYNzpQN/YEHRXHL8cSfaGq/rnxcK2VhPd1 o03khDxFPfd5LLMByWb4yGTjxV1C1TuJHXmf4HYglIhN379OCKdwLpRGKPPs5Pcn+H7K zdlhEWU3XYPT3VijgR0ppG914RdLLGNVIHzF9iXzcMccIHVArxqgrIa9KKzMYPBXi739 L7sLT8impPSdY63ki1YpVa5fySK8emgywdxbLZyxOJkfmuaUOerErc5t4KvLkoDmJRlp 53l3xSqCIWCT5AOJR32KROV2yER2T7xl0cQXbGjciWjkMtemqSASRkj4Ii+w8sqHKioc 0j9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DcEYEchS; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id b3-v6si19523218pgn.100.2018.11.12.21.51.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:51:10 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DcEYEchS; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EF8462250F; Tue, 13 Nov 2018 05:51:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088270; bh=HdQw+5WkU8qh4QVSfkqGiYGxAIypFX1jiXQeWfoUlIU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DcEYEchSRjY6V75cFYwh3VdfMMWuJynN7OqPFTZw7fF4ps5gwpCxoSD3xzvATZSPX RZUQ0wbrp0xNLJZHgdzQVqZf/awudf90EKa+AMBM6mgTG9L6VKBeDj2Nzhs7OaFeET vaKzB8PG92eEPOwg5IRiHYTBprJkiR5sSUeM5hRw= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jan Kara , Ross Zwisler , Dan Williams , Dave Jiang , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.18 11/39] mm: Fix warning in insert_pfn() Date: Tue, 13 Nov 2018 00:50:25 -0500 Message-Id: <20181113055053.78352-11-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055053.78352-1-sashal@kernel.org> References: <20181113055053.78352-1-sashal@kernel.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Jan Kara [ Upstream commit f2c57d91b0d96aa13ccff4e3b178038f17b00658 ] In DAX mode a write pagefault can race with write(2) in the following way: CPU0 CPU1 write fault for mapped zero page (hole) dax_iomap_rw() iomap_apply() xfs_file_iomap_begin() - allocates blocks dax_iomap_actor() invalidate_inode_pages2_range() - invalidates radix tree entries in given range dax_iomap_pte_fault() grab_mapping_entry() - no entry found, creates empty ... xfs_file_iomap_begin() - finds already allocated block ... vmf_insert_mixed_mkwrite() - WARNs and does nothing because there is still zero page mapped in PTE unmap_mapping_pages() This race results in WARN_ON from insert_pfn() and is occasionally triggered by fstest generic/344. Note that the race is otherwise harmless as before write(2) on CPU0 is finished, we will invalidate page tables properly and thus user of mmap will see modified data from write(2) from that point on. So just restrict the warning only to the case when the PFN in PTE is not zero page. Link: http://lkml.kernel.org/r/20180824154542.26872-1-jack@suse.cz Signed-off-by: Jan Kara Reviewed-by: Andrew Morton Cc: Ross Zwisler Cc: Dan Williams Cc: Dave Jiang Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/memory.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index f94feec6518d..1f5a59204101 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1803,10 +1803,15 @@ static int insert_pfn(struct vm_area_struct *vma, unsigned long addr, * in may not match the PFN we have mapped if the * mapped PFN is a writeable COW page. In the mkwrite * case we are creating a writable PTE for a shared - * mapping and we expect the PFNs to match. + * mapping and we expect the PFNs to match. If they + * don't match, we are likely racing with block + * allocation and mapping invalidation so just skip the + * update. */ - if (WARN_ON_ONCE(pte_pfn(*pte) != pfn_t_to_pfn(pfn))) + if (pte_pfn(*pte) != pfn_t_to_pfn(pfn)) { + WARN_ON_ONCE(!is_zero_pfn(pte_pfn(*pte))); goto out_unlock; + } entry = *pte; goto out_mkwrite; } else