From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7BC2C433F5 for ; Wed, 16 Feb 2022 22:01:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D368D6B0075; Wed, 16 Feb 2022 17:01:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CE61B6B0078; Wed, 16 Feb 2022 17:01:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B87206B007B; Wed, 16 Feb 2022 17:01:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id A94886B0075 for ; Wed, 16 Feb 2022 17:01:02 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6B91D95C9B for ; Wed, 16 Feb 2022 22:01:02 +0000 (UTC) X-FDA: 79150013964.09.8EF2637 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) by imf18.hostedemail.com (Postfix) with ESMTP id CE0BB1C0003 for ; Wed, 16 Feb 2022 22:01:01 +0000 (UTC) Received: by mail-io1-f45.google.com with SMTP id h16so1437831iol.11 for ; Wed, 16 Feb 2022 14:01:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7aZzAJ7eIu5QJbmd+PhcZrTGihRY4UQTElKA0+XExQo=; b=qXcgQlo2dXFyX+QpjhKZoeF3/dsruzavYOFV/tAHWWLtLyvISOf+ywWrQEmfXm47pb EEZdmdCieMtCiiYxmcpZaiwyMlK9TIk7bvT8tggIILo71oQm5Ma6x19kalqZsSEhwWKl s2bS4X+FiTfqq8DG9+NFFz04z9d0dOn5eNwhhOo7NrLPWs2/wdLF7lvcWKWsw1G9AhFd KG6U/blJ6A3KQn231Ws4SwSau5LBWnlmLf6zAStF/UlIxa2jsKADXrSje7mq5noNV4/y d42zt6eVbiXPL0cBoOgKtn87areTOfsisWzWE80ISEuGVHJpdR8LLHtFsxx82XaTvpC2 FuOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7aZzAJ7eIu5QJbmd+PhcZrTGihRY4UQTElKA0+XExQo=; b=4M4+uKNobx4ToPNxbRL8pwuj9WCRnsA/xQnADk/jAcaILEBv6jPfpPXutVINpVmgsI vj4ZgEdCGEeNHxD23T0xoUTKroOEavgw9wqYoqSNtmwfsZWat7xni57nhL+IpYxq5/LY wxXs54Emsr+ApjGB0cZmbXV/OxPG7Q+MDzRjXWZ3HE33wh6b+aK0rJtSu+b7Wx30nvyW C3mV+Ncv0dM3sRbFt4g3lmOTtyb/uWNX1ecNlZ7sH+t4ikLUSfZETOdDILHAzbyPcT7P 0MbGDyXtZYMq2Bm0FoVTUxQGoUDK5EYNrsLVcmTQjbJcxPFEtlp69gtrLqcK89xl/yjD iLCg== X-Gm-Message-State: AOAM532X0GsYsIiEXJNJ7dwDhjbDO4OL1dIy9bRtlgJ5dXWFSO77+Pk0 tYLKMTRWLnyTPwK9rNxJp2TzOw== X-Google-Smtp-Source: ABdhPJww99WmkOEZ/fUhXlNY4rjl0ow5om1+rpHafSTQKr/wkjDASPwfKKgeMYrpyFDiis66IBEPyA== X-Received: by 2002:a05:6602:482:b0:614:b990:28c9 with SMTP id y2-20020a056602048200b00614b99028c9mr3320749iov.6.1645048861011; Wed, 16 Feb 2022 14:01:01 -0800 (PST) Received: from google.com ([2620:15c:183:200:5929:5114:bf56:ccb6]) by smtp.gmail.com with ESMTPSA id j14sm600635ilc.62.2022.02.16.14.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 14:01:00 -0800 (PST) Date: Wed, 16 Feb 2022 15:00:56 -0700 From: Yu Zhao To: "Huang, Ying" Cc: Mauricio Faria de Oliveira , Minchan Kim , Andrew Morton , Yang Shi , Miaohe Lin , linux-mm@kvack.org, linux-block@vger.kernel.org Subject: Re: [PATCH v3] mm: fix race between MADV_FREE reclaim and blkdev direct IO read Message-ID: References: <20220131230255.789059-1-mfo@canonical.com> <87o837cnnw.fsf@yhuang6-desk2.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CE0BB1C0003 X-Stat-Signature: kfg3zj4neswqrtcsud18s351k97szxgk X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=qXcgQlo2; spf=pass (imf18.hostedemail.com: domain of yuzhao@google.com designates 209.85.166.45 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1645048861-274129 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: On Wed, Feb 16, 2022 at 02:58:36PM -0700, Yu Zhao wrote: > On Wed, Feb 16, 2022 at 02:48:19PM +0800, Huang, Ying wrote: > > Yu Zhao writes: > > > > > On Wed, Feb 02, 2022 at 06:27:47PM -0300, Mauricio Faria de Oliveira wrote: > > >> On Wed, Feb 2, 2022 at 4:56 PM Yu Zhao wrote: > > >> > > > >> > On Mon, Jan 31, 2022 at 08:02:55PM -0300, Mauricio Faria de Oliveira wrote: > > >> > > Problem: > > >> > > ======= > > >> > > > >> > Thanks for the update. A couple of quick questions: > > >> > > > >> > > Userspace might read the zero-page instead of actual data from a > > >> > > direct IO read on a block device if the buffers have been called > > >> > > madvise(MADV_FREE) on earlier (this is discussed below) due to a > > >> > > race between page reclaim on MADV_FREE and blkdev direct IO read. > > >> > > > >> > 1) would page migration be affected as well? > > >> > > >> Could you please elaborate on the potential problem you considered? > > >> > > >> I checked migrate_pages() -> try_to_migrate() holds the page lock, > > >> thus shouldn't race with shrink_page_list() -> with try_to_unmap() > > >> (where the issue with MADV_FREE is), but maybe I didn't get you > > >> correctly. > > > > > > Could the race exist between DIO and migration? While DIO is writing > > > to a page, could migration unmap it and copy the data from this page > > > to a new page? > > > > Check the migrate_pages() code, > > > > migrate_pages > > unmap_and_move > > __unmap_and_move > > try_to_migrate // set PTE to swap entry with PTL > > move_to_new_page > > migrate_page > > folio_migrate_mapping > > folio_ref_count(folio) != expected_count // check page ref count > > folio_migrate_copy > > > > The page ref count is checked after unmapping and before copying. This > > is good, but it appears that we need a memory barrier between checking > > page ref count and copying page. > > I didn't look into this but, off the top of head, this should be > similar if not identical to the DIO case. Therefore, it requires two ^^^ reclaim > barriers -- before and after the refcnt check (which may or may not > exist).