Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp345443ybm; Thu, 28 May 2020 04:25:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTI47naPjQ40kwJSXZZcNvNRTaCepPkgDN5CKfEs/CSApO8eZWzIZK30bMPIWIsIXnuAhv X-Received: by 2002:a17:906:30c3:: with SMTP id b3mr2441793ejb.126.1590665109103; Thu, 28 May 2020 04:25:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590665109; cv=none; d=google.com; s=arc-20160816; b=fYyl9q5V+Ou1KnpWUWr4nOYy+3ft2Liv9OR2/9Q+XEo3+VApPPXcCI018kGourJslz mhZ2eIH5samC733zOiQxE9O1m87n7i8O+C32zi8t4ZGEvS/LvN/v/Q5ZA5i+1PuRuqV/ ADw69hymwLZc73jiSYSNeTkHggusRSoHgj6o5/PNDv9F1epMxwIqaQYSExJTbg6Sy4qH Sse8Pnn7nTFHMPwfdHRFkSTiAgRotFNmzmvM7Ra+7fxQc1rKLT/4uN5Wm3gyyj0eHlXd wQAnVJiPMGkuWz5WtNuE3agjIVK8VKhSrp6BqZ48kwkzpYikX6OgaMmVIY765e4QeaFM 5Mrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=0pDdsaPJ9DSWTCG29xVVgPA72+92+ZpKaGKhvHYc8/o=; b=O1Il6F/axN4J+hLhyFfcfadAgoLhPjXnuYoYSX0rg+Xrf+rKVD4nCcaZCD6iEyMSdg JuzPmd16kX1FwiARiMXwXtWRJNb1P3+OcRVwsPv0WFHm9ieZtWXQZpl9WZyKH3n79The vDCCmtDmN7EcH3+AtMQEqccubsr6vMEnPEDVt8YzllyMvUiF3M8s2JH+JGVncQsj9b9b +t4pZ1n2kYyBLectyg6+y37xN6EyhERIW5+wp9y4SVLw5vfHm9+7B+aG+Hg+VhuQ1lOn iT38BpGd7Hae2ZLfFU9C2WZsRpdXoCumfCDeXaf7OCs3WaXFmwu3x8mw4jMWvmNIjeEQ 8wvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cnGYK2JC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si3271967edv.364.2020.05.28.04.24.46; Thu, 28 May 2020 04:25:09 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=cnGYK2JC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388321AbgE1LUr (ORCPT + 99 others); Thu, 28 May 2020 07:20:47 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:30686 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388303AbgE1LUn (ORCPT ); Thu, 28 May 2020 07:20:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590664841; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0pDdsaPJ9DSWTCG29xVVgPA72+92+ZpKaGKhvHYc8/o=; b=cnGYK2JC5bYnTT2Pd08ImODjvO31mfBzx6DCuwCatJUslkIA68z3sN8V+SAI0uwCmF7riy oZ98Ejx2vo6hC9D5lt4lZqF3Ah6wX+67qWpQUied2otSd9O0NlcXwKUJNXT0AMsTpkVBtM qZOOCOQ7RFgWFcEOIQTt0/klvhEp9jc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-357-rz4JWXClNKyU_Z2vtGkSbw-1; Thu, 28 May 2020 07:20:37 -0400 X-MC-Unique: rz4JWXClNKyU_Z2vtGkSbw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C3F14805730; Thu, 28 May 2020 11:20:32 +0000 (UTC) Received: from redhat.com (ovpn-113-1.rdu2.redhat.com [10.10.113.1]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E409A7A8B6; Thu, 28 May 2020 11:20:26 +0000 (UTC) Date: Thu, 28 May 2020 07:20:25 -0400 From: Jerome Glisse To: Hugh Dickins Cc: linux-mm@kvack.org, Andrew Morton , Huang Ying , linux-kernel@vger.kernel.org, Steven Capper , Catalin Marinas , Rabin Vincent , linux-arm-kernel@lists.infradead.org, rmk+kernel@arm.linux.org.uk, Guo Ren , linux-mips@vger.kernel.org, Ralf Baechle , Paul Burton , James Hogan , Ley Foon Tan , nios2-dev@lists.rocketboards.org, linux-parisc@vger.kernel.org, Helge Deller , "James E.J. Bottomley" , Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org, "David S. Miller" , sparclinux@vger.kernel.org, Guan Xuetao , linux-xtensa@linux-xtensa.org, Max Filippov , Chris Zankel Subject: Re: Cache flush issue with page_mapping_file() and swap back shmem page ? Message-ID: <20200528112025.GA10175@redhat.com> References: <20200528002033.GB1992500@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 27, 2020 at 08:46:22PM -0700, Hugh Dickins wrote: > Hi Jerome, > > On Wed, 27 May 2020, Jerome Glisse wrote: > > So any arch code which uses page_mapping_file() might get the wrong > > answer, this function will return NULL for a swap backed page which > > can be a shmem pages. But shmem pages can still be shared among > > multiple process (and possibly at different virtual addresses if > > mremap was use). > > > > Attached is a patch that changes page_mapping_file() to return the > > shmem mapping for swap backed shmem page. I have not tested it (no > > way for me to test all those architecture) and i spotted this while > > working on something else. So i hope someone can take a closer look. > > I'm certainly no expert on flush_dcache_page() and friends, but I'd > be very surprised if such a problem exists, yet has gone unnoticed > for so long. page_mapping_file() itself is fairly new, added when > a risk of crashing on a race with swapoff came in: but the previous > use of page_mapping() would have suffered equally if there were such > a cache flushinhg problem here. > > And I'm afraid your patch won't do anything to help if there is a > problem: very soon after shmem calls add_to_swap_cache(), it calls > shmem_delete_from_page_cache(), which sets page->mapping to NULL. > > But I can assure you that a shmem page (unlike an anon page) is never > put into swap cache while it is mapped into userspace, and never > mapped into userspace while it is still in swap cache: does that help? > You are right i missed/forgot the part where shmem is never swapcache and mapped at the same time, thus page_mapping_file() can return NULL for those as they can no longer have alias mapping. Thank you Hugh J?r?me