Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4496307imu; Tue, 8 Jan 2019 00:59:54 -0800 (PST) X-Google-Smtp-Source: ALg8bN52hu8MscvjeKnFpSrBd7FlOqwf5O+AjK6tHRQqrE1veg0qIwsxbAND1+PNZMllOkcoWs2m X-Received: by 2002:a63:4d0e:: with SMTP id a14mr783252pgb.408.1546937994424; Tue, 08 Jan 2019 00:59:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546937994; cv=none; d=google.com; s=arc-20160816; b=EWxRWUnl/6gu/iUb3dt+bOKAxpH0WmYfCauuJlrWYiQF1sTBfDxn7IDIWNwkXE+Jbr Lm5CL3ow+u/W18DJDz/v0Gt1rAwPEN16UHgrox27lW2iW+JDOVMscVEZbET71eihFye6 EEt8aMA4qeKoS4bUlbocRi+U0BzKND9nkyKYjn85Kny188rwHltkgPhyS5JSD+BN3Vt1 1d9zG4m69lO8cXkDBGZndC846GbFxgM5TNcekymAVOiH4kZWszX7ZdcvC4osOoBlMfeV no0k7F8HuObEPFx3FWx7YIha3vBthIv6bVfY8auziholmTje3SriC+MhQBAm5yt94kN9 oWyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=7aWJhM/LoU/8Gal/lsz0MaLdjLViE0x5AZjjbsEZ6MM=; b=IET7jvnIllpY2GFmzYF9Z5vcHFHAL+BYUJZvmrnV4L6EOg5mt53NlMx6bvd8Rxsv4e WC5ilEbqPTrVi2bSyoSTgWTnq9Rux8n/otmb7cJ2kA2TZqy978R/ejYThejm8EYR1XjY 8NIe7IPQfQoa6NwhDbqxl7uB4PFTR1vKGs0FtaSTR2z+07TNZH2yXF8Cvrrcl6mmsiFU nep7IIwYPsydIKo3mWXLq9W48xrouw3N+sDzX5XBSxxynN4jXC3tw4g/ONnh8LL3o8S5 ettuWN1IhvQp/qXk4jiyTwZBtSFxo+xEPOH59P+ymEH1bkvkZLlAUcRkrhrpqw/M53JZ 1rMA== 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 n8si13546445plk.9.2019.01.08.00.59.39; Tue, 08 Jan 2019 00:59:54 -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 S1728125AbfAHIvF (ORCPT + 99 others); Tue, 8 Jan 2019 03:51:05 -0500 Received: from aws.guarana.org ([13.237.110.252]:35572 "EHLO aws.guarana.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727796AbfAHIvE (ORCPT ); Tue, 8 Jan 2019 03:51:04 -0500 Received: by aws.guarana.org (Postfix, from userid 1006) id 960DDA18B4; Tue, 8 Jan 2019 08:50:58 +0000 (UTC) Date: Tue, 8 Jan 2019 08:50:58 +0000 From: Kevin Easton To: Linus Torvalds Cc: Jiri Kosina , Masatake YAMATO , Andrew Morton , Greg KH , Peter Zijlstra , Michal Hocko , linux-mm@kvack.org, Linux List Kernel Mailing , linux-api@vger.kernel.org Subject: Re: [PATCH] mm/mincore: allow for making sys_mincore() privileged Message-ID: <20190108085058.GA23237@ip-172-31-15-78> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 05, 2019 at 01:54:03PM -0800, Linus Torvalds wrote: > On Sat, Jan 5, 2019 at 12:43 PM Jiri Kosina wrote: > > > > > Who actually _uses_ mincore()? That's probably the best guide to what > > > we should do. Maybe they open the file read-only even if they are the > > > owner, and we really should look at file ownership instead. > > > > Yeah, well > > > > https://codesearch.debian.net/search?q=mincore > > > > is a bit too much mess to get some idea quickly I am afraid. > > Yeah, heh. > > And the first hit is 'fincore', which probably nobody cares about > anyway, but it does > > fd = open (name, O_RDONLY) > .. > mmap(window, len, PROT_NONE, MAP_PRIVATE, .. > > so if we want to keep that working, we'd really need to actually check > file ownership rather than just looking at f_mode. > > But I don't know if anybody *uses* and cares about fincore, and it's > particularly questionable for non-root users. > ... > I didn't find anything that seems to really care, but I gave up after > a few pages of really boring stuff. I've gone through everything in the Debian code search, and this is the stuff that seems like it would be affected at all by the current patch: util-linux Contains 'fincore' as already noted above. e2fsprogs e4defrag tries to drop pages that it caused to be loaded into the page cache, but it's not clear that this ever worked as designed anyway (it calls mincore() before ioctl(fd, EXT4_IOC_MOVE_EXT ..) but then after the sync_file_range it drops the pages that *were* in the page cache at the time of mincore()). pgfincore postgresql extension used to try to dump/restore page cache status of database backing files across reboots. It uses a fresh mapping with mincore() to try to determine the current page cache status of a file. nocache LD_PRELOAD library that tries to drop any pages that the victim program has caused to be loaded into the page cache, uses mincore on a fresh mapping to see what was resident beforehand. Also includes 'cachestats' command that's basically another 'fincore'. xfsprogs xfs_io has a 'mincore' sub-command that is roughly equivalent to 'fincore'. vmtouch vmtouch is "Portable file system cache diagnostics and control", among other things it implements 'fincore' type functionality, and one of its touted use-cases is "Preserving virtual memory profile when failing over servers". qemu qemu uses mincore() with a fresh PROT_NONE, MAP_PRIVATE mapping to implement the "x-check-cache-dropped" option. ( https://patchwork.kernel.org/patch/10395865/ ) (Everything else I could see was either looking at anonymous VMAs, its own existing mapping that it's been using for actual IO, or was just using mincore() to see if an address was part of any mapping at all). - Kevin