Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4240289pxb; Tue, 10 Nov 2020 11:12:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHOJP9lAC5kYlgCxzt6fpMmQ5zE44eRvptpQJV5rXFbFSzjN8NSGXplQZUGyNdkBoiW2i6 X-Received: by 2002:a17:907:9e3:: with SMTP id ce3mr21861033ejc.4.1605035573286; Tue, 10 Nov 2020 11:12:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605035573; cv=none; d=google.com; s=arc-20160816; b=HLKqzCssJYGAjPa6SBDnjIQyiCD3HNzHK/8eZmcV3CvNis9Sic0fSnFNEpdKhCdTQH RhHP3yWOKHS7pX8UfEbKrKNWOCrY/xbl1ll6TJCtBcc7FSFd0/tzcJsAem9ddAM9AfZY YQQedGsSy1I/ls1TYQegbWd3NaNn1hCtj/1PN9qsiO3tZI0ONnPjE/H5TIji20AqHpp4 rCd7qRvLI+XcsZxQFZbSW+yaFgIZ8QGi2O/FRS2FeOyZYR6HtpknlGEJwa4FUSU4UyUs Qb2R8R2qjTkFrA6aAL8c5wJ+LXnaqpeRWHVU4G/vN9e2sc/h4p/gidDWmNYz6JOHtrjb XBqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=o/P6FAAbZyAhrgG09vfP1BCKKHct1LeQm/LdrSl6xbo=; b=qLVwYpZd8tDkGJXRHKzNaVnrD9TNwhrepvSMxofBntFvIrb7+E0Y9DxqSPwfLPz368 zpjLmzfvVjEFcdB9hjY1ZcDi9jkkTtyyf72CR3vrfQ0Z0etKjfylVNat3RhWv/QeOjAD fY7LRaQVMdzQlplqyiFOxG4Ez+dW6PcqFHn2DDc3Er4bLapJ9IMtcEQbkgltjSOSGXHf PuLDMQcif8fp9+c62ZcJ5Ox+kgE8TQOcOnCInjI3ZhnxrNz5E2f+IATNUK+X0IVm+RFv f8YgqpdEEgJXmT41SOcVdDx3FFMzCgOFvZDWhiOL2Jyp2VAYyukIiePsvoZBRV++4eMT zRTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=SEkve2d6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r8si10403873edm.62.2020.11.10.11.12.22; Tue, 10 Nov 2020 11:12:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=SEkve2d6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731417AbgKJTIZ (ORCPT + 99 others); Tue, 10 Nov 2020 14:08:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbgKJTIY (ORCPT ); Tue, 10 Nov 2020 14:08:24 -0500 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C781C0613D1 for ; Tue, 10 Nov 2020 11:08:24 -0800 (PST) Received: by mail-qt1-x843.google.com with SMTP id 3so9395987qtx.3 for ; Tue, 10 Nov 2020 11:08:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=o/P6FAAbZyAhrgG09vfP1BCKKHct1LeQm/LdrSl6xbo=; b=SEkve2d6VJEm0fVm001sIsH50qhvSC+fkG3XYb4FWVK0N4jo3NezX45gV3V1c2JJxR RlB9BUM6fCLmSo3s6Y+Ijb8MGuKJEYSBWECV+upj1zkIkqu9mmBWoc3OHP5rnb7Z8dMI XqnnLdzqv17RKQKD79XOWA0pV6et/HWzqgsbx8EIrk+jEXGI7wXbGmDPKkz87HtaKW2k ynWMuyHTCvF6/PVzX8n0E5VJp1o/mlS6Z9aZR3UXWdad07hThGZp/CFnMmCPtki3dz9U Uhu2qAohDJR7toQ5Ir44j97UxPf8mIj/iyXfszUSca9FeYv2Wgvw3oDYY6qsSTqVH0lq B18g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=o/P6FAAbZyAhrgG09vfP1BCKKHct1LeQm/LdrSl6xbo=; b=KTc50wO+g7OiJ1l7J83/T0l18pEAePqDMtKoIVLQuRcyE0EK3kRt3Dwqs2etgLYNRg uSfJ3GlWN+EyIe+O4W4GRgtGQuKqW31jmtDEWRx4vHSpHV/p/QqKrJ7CL1PSkNkLmmDc H/38vLC5uRWKgIGogTSSmGolKCY4NVt94Ve7y02W1KTe1cGyVAgbjny0QK84dZhx0yIc A5fzGKYkLcxqonk43fQlLRFtfDJ0yn5PSWmvPVlyujp4S6cTfbC65bGQQY7j0CkeJdDB +eaeeXsB5pHd+y1BLJxTxtR8TD+FLn+6CwSKAatbYdrG0xMlxmqOeMx7OKIeq8NeecF0 63Tw== X-Gm-Message-State: AOAM530tP0LZFB4NYWkcoDmnIaJLEaV1cOHoIAa7uGyq8ovZacN8G+tA bMURNx0slOi+Rm5/ZzWToRt4Hw== X-Received: by 2002:ac8:d48:: with SMTP id r8mr19575791qti.69.1605035303894; Tue, 10 Nov 2020 11:08:23 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:64f7]) by smtp.gmail.com with ESMTPSA id y17sm9007791qki.134.2020.11.10.11.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 11:08:22 -0800 (PST) Date: Tue, 10 Nov 2020 14:06:35 -0500 From: Johannes Weiner To: Alex Shi Cc: akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, hughd@google.com, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, willy@infradead.org, lkp@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, shakeelb@google.com, iamjoonsoo.kim@lge.com, richard.weiyang@gmail.com, kirill@shutemov.name, alexander.duyck@gmail.com, rong.a.chen@intel.com, mhocko@suse.com, vdavydov.dev@gmail.com, shy828301@gmail.com, Minchan Kim Subject: Re: [PATCH v21 06/19] mm/rmap: stop store reordering issue on page->mapping Message-ID: <20201110190635.GE850433@cmpxchg.org> References: <1604566549-62481-1-git-send-email-alex.shi@linux.alibaba.com> <1604566549-62481-7-git-send-email-alex.shi@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 06, 2020 at 09:20:04AM +0800, Alex Shi wrote: > From 2fd278b1ca6c3e260ad249808b62f671d8db5a7b Mon Sep 17 00:00:00 2001 > From: Alex Shi > Date: Thu, 5 Nov 2020 11:38:24 +0800 > Subject: [PATCH v21 06/19] mm/rmap: stop store reordering issue on > page->mapping > > Hugh Dickins and Minchan Kim observed a long time issue which > discussed here, but actully the mentioned fix missed. > https://lore.kernel.org/lkml/20150504031722.GA2768@blaptop/ > The store reordering may cause problem in the scenario: > > CPU 0 CPU1 > do_anonymous_page > page_add_new_anon_rmap() > page->mapping = anon_vma + PAGE_MAPPING_ANON > lru_cache_add_inactive_or_unevictable() > spin_lock(lruvec->lock) > SetPageLRU() > spin_unlock(lruvec->lock) > /* idletacking judged it as LRU > * page so pass the page in > * page_idle_clear_pte_refs > */ > page_idle_clear_pte_refs > rmap_walk > if PageAnon(page) > > Johannes give detailed examples how the store reordering could cause > a trouble: > "The concern is the SetPageLRU may get reorder before 'page->mapping' > setting, That would make CPU 1 will observe at page->mapping after > observing PageLRU set on the page. > > 1. anon_vma + PAGE_MAPPING_ANON > > That's the in-order scenario and is fine. > > 2. NULL > > That's possible if the page->mapping store gets reordered to occur > after SetPageLRU. That's fine too because we check for it. > > 3. anon_vma without the PAGE_MAPPING_ANON bit > > That would be a problem and could lead to all kinds of undesirable > behavior including crashes and data corruption. > > Is it possible? AFAICT the compiler is allowed to tear the store to > page->mapping and I don't see anything that would prevent it. > > That said, I also don't see how the reader testing PageLRU under the > lru_lock would prevent that in the first place. AFAICT we need that > WRITE_ONCE() around the page->mapping assignment." > > Signed-off-by: Alex Shi > Cc: Johannes Weiner > Cc: Andrew Morton > Cc: Hugh Dickins > Cc: Matthew Wilcox > Cc: Minchan Kim > Cc: Vladimir Davydov > Cc: linux-kernel@vger.kernel.org > Cc: linux-mm@kvack.org Acked-by: Johannes Weiner Thanks Alex!