Received: by 10.223.185.116 with SMTP id b49csp3217853wrg; Mon, 5 Mar 2018 16:48:51 -0800 (PST) X-Google-Smtp-Source: AG47ELtCABwxm/QgDXLgMKEpxnbKRKLIw4+VvdSoCGALxtydgoTwGpECOhc6Ati0IbCZLYEnsIcr X-Received: by 2002:a17:902:550f:: with SMTP id f15-v6mr14694892pli.50.1520297331238; Mon, 05 Mar 2018 16:48:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520297331; cv=none; d=google.com; s=arc-20160816; b=Jp3/fL3Sd0e1ezO/acuNBHqyX9ix1eiEZqnAOnipJFCu+Yjmj8PckTdmvDdw/ZmXJA fhPgeID1Ct5NF1sWenrY7JyYV06n6oIGoRXpud1pYtylhgTEJdLFyQ6ZczuTO/pauwzT tiEhHnDjMmq39fzTYxVYjl5vDUQ4/w2uEklDg7j2n4bWbn0KBUP0PxICsmjzW9lWN9Ka nicrzvOv2cXbAm4obaRIVaSBLhQQmRMNaQBMM73Cgmqdo+UVWRawHZAyS97zZT7qQPoq rojWDKz/oA6DikIwU4nsOe/kEXzELO4VEfD8lQHZWczf291cwHqY1kMpDV1kuaH88qWA uLiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from :arc-authentication-results; bh=PzSvh7R2vnah2PohW/6EphH6gNH+4gB5Tmm6tJfO/6c=; b=V/0mbAWQevHrNIBm6AjYninQfflXWpJFjmOx0kaHwNtBziy/MUlwPEl//qQNMxFLjj 8+za4XlRrI91kKiqAlPjB+YnGRLrFZ7LwRZAS7IzpAUMsKoiqadjQkO70d24SJ0m8ILc VHlnskw42up3rliZ0tSQmQgDeNIVx3PesqaFmgdgKe9BRAANl/iVD1IeM0TV5y4isAxe Umd2eN8XypIaTQqP529RJUu7EnSHu8xzMA8gizzlxv3DuH6ZKVy/6PaH38q1GKaqHzfe 6EGK+rSBfY+gIAEvpbEjfDamWxHfa3VUF0OLk5L8hZYH2cUwWEVmfFAqJeNv61JTOJA4 F4Cw== ARC-Authentication-Results: i=1; mx.google.com; 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 m12si8977468pgr.85.2018.03.05.16.48.35; Mon, 05 Mar 2018 16:48:51 -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; 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 S932863AbeCFArm (ORCPT + 99 others); Mon, 5 Mar 2018 19:47:42 -0500 Received: from mga03.intel.com ([134.134.136.65]:36167 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932287AbeCFArl (ORCPT ); Mon, 5 Mar 2018 19:47:41 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2018 16:47:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,429,1515484800"; d="scan'208";a="35740414" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.13.10]) by fmsmga001.fm.intel.com with ESMTP; 05 Mar 2018 16:47:38 -0800 From: "Huang\, Ying" To: Andrew Morton Cc: , , Minchan Kim , Michal Hocko , Johannes Weiner , Mel Gorman , Dave Hansen , "Chen Liqin" , Russell King , Yoshinori Sato , "James E.J. Bottomley" , Guan Xuetao , "David S. Miller" , Chris Zankel , Vineet Gupta , Ley Foon Tan , Ralf Baechle , Andi Kleen Subject: Re: [PATCH -V2 -mm] mm: Fix races between swapoff and flush dcache References: <20180305083634.15174-1-ying.huang@intel.com> Date: Tue, 06 Mar 2018 08:47:37 +0800 In-Reply-To: <20180305083634.15174-1-ying.huang@intel.com> (Ying Huang's message of "Mon, 5 Mar 2018 16:36:34 +0800") Message-ID: <871sgy2fo6.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Huang, Ying" writes: > From: Huang Ying > > From commit 4b3ef9daa4fc ("mm/swap: split swap cache into 64MB > trunks") on, after swapoff, the address_space associated with the swap > device will be freed. So page_mapping() users which may touch the > address_space need some kind of mechanism to prevent the address_space > from being freed during accessing. > > The dcache flushing functions (flush_dcache_page(), etc) in > architecture specific code may access the address_space of swap device > for anonymous pages in swap cache via page_mapping() function. But in > some cases there are no mechanisms to prevent the swap device from > being swapoff, for example, > > CPU1 CPU2 > __get_user_pages() swapoff() > flush_dcache_page() > mapping = page_mapping() > ... exit_swap_address_space() > ... kvfree(spaces) > mapping_mapped(mapping) > > The address space may be accessed after being freed. > > But from cachetlb.txt and Russell King, flush_dcache_page() only care > about file cache pages, for anonymous pages, flush_anon_page() should > be used. The implementation of flush_dcache_page() in all > architectures follows this too. They will check whether > page_mapping() is NULL and whether mapping_mapped() is true to > determine whether to flush the dcache immediately. And they will use > interval tree (mapping->i_mmap) to find all user space mappings. > While mapping_mapped() and mapping->i_mmap isn't used by anonymous > pages in swap cache at all. > > So, to fix the race between swapoff and flush dcache, __page_mapping() > is add to return the address_space for file cache pages and NULL > otherwise. All page_mapping() invoking in flush dcache functions are > replaced with __page_mapping(). Sorry, I just found I forgot replacing __page_mapping() to page_mapping_file() in the above paragraph. Could you help me to change it in place? Or I should resend the patch with the updated description? Best Regards, Huang, Ying [snip]