Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1215496ybl; Tue, 13 Aug 2019 09:05:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4r7rKKoQgrr/9ZxZjeinEkd2IWrWkNoR/DPnrDRV3uZC9QNFCgfrojaele+wfGM6Nu2eS X-Received: by 2002:aa7:8b55:: with SMTP id i21mr41802198pfd.155.1565712351626; Tue, 13 Aug 2019 09:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565712351; cv=none; d=google.com; s=arc-20160816; b=hum8LHz7lagL0zg9e5eZFebaUSW5laBpAOEVYIiNhZ7JO5/iQEJvzv4AwoK/y1yIhA JrfR+LjZ836u7ddjPrFHS/86lmmmfCJeq7G/OBptoEhCTl6gpRBLp6oJt+nDTX+sBaqz GHZP5+Uy0NltTsnk+EtxQZuvCxKK9nuUmqhhYQoxrYBzXnAYn3By37o4OL+JVCOSB/sy MvWhZ8eRPZKNDZiMNEm0hLHLbRgYuv5j1/vo4h8KqhkRY0Y+eDOVWuDElj6bsRTzsfjv bQPixNjeV0gmZAddMf8Y3CZoAaiqktq+BUypmfuRaMMbTH4xSXHvESMjWwB4ynJLuD2Q qPjA== 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:dkim-signature; bh=cgcBlbXGFsc/om+/smWu+Pn0e+PGsj2TzOvbc6+E86U=; b=KvCNxClhbMacYdBpRp+uLhzACrWS6S3vENoCmVMdBY3dVSke13mNl6wBIHDA8VnLtR VYQWeVo8GIKXa2FIsgKTo7XRn7nTmQpju825t5M5ExOfqzyB3bEq5lKAVPB37+7qh1Aq x1SThdu4ClBq+lO5ofPUYK9EmSk1D9kexe7MLUYYFNCKwdF1kOtPkV9nIQtcHK62J9Tj Nb72mV6jMxwT/3vlHWn6F2+tJucMcKNMLftuFbuAS3d6ZSpn61zeSFEdzc6mexjqn8aU mzclo7EBuvcaEVqX+sk02vw4tilozVNtiaEEoOrQj2tizro/fK/YX7Pg+IwlK11sCwTZ PpgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=C6Wd4yxw; 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 129si13236943pfa.258.2019.08.13.09.05.35; Tue, 13 Aug 2019 09:05:51 -0700 (PDT) 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; dkim=pass header.i=@joelfernandes.org header.s=google header.b=C6Wd4yxw; 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 S1729526AbfHMOZa (ORCPT + 99 others); Tue, 13 Aug 2019 10:25:30 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37239 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729344AbfHMOZa (ORCPT ); Tue, 13 Aug 2019 10:25:30 -0400 Received: by mail-pl1-f194.google.com with SMTP id bj8so2335052plb.4 for ; Tue, 13 Aug 2019 07:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=cgcBlbXGFsc/om+/smWu+Pn0e+PGsj2TzOvbc6+E86U=; b=C6Wd4yxwaQCT0SiFrDTxUSIkFQODTgQV7PQEXI9kmvPnDsR4HFuL/kHGspte6crI3X niIRYHkysNGFVRaeTjgdQiq57VbO4gQEWfnYaaLSFYY8xqxSoVaRN0B+Y/u0fOLI71aG /pLkgNgZK3s+44ARW92U42yPDfe33KSorJnyE= 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:user-agent; bh=cgcBlbXGFsc/om+/smWu+Pn0e+PGsj2TzOvbc6+E86U=; b=e57NXEg/e0wPE5GdrUEAquC7w5Ms6TY1XEJ/01tKkCayBZayRXDf75PuLFdohT+RFR 2maZch8e86qZQfVuWuRSqw7cbBmfD4uyRtuuPNHOxBXS+AOLafaTN2jjl60P85lQWE8W /OLVyomNP1K8kx6QD0t1/x/uglA/eCMyR/1X2QhqdF+FUEv3Unj9VqkUQtg1wzMEtHhK mT0td07ZBT+Y+E/fPt/mEGO5Ro35cnGUjEgArkfSctKfch1Yx/1+LlxkleuZ0dFSx/z+ q87124Uq8/tdkkhnJBHPh3/HqLF0ZE0yMxEBDqP1Ikd5XR8mkDtq41KmD/vkh+2imjff ebSw== X-Gm-Message-State: APjAAAWyelt2zHs7gBkIwAvB7uMg/RrIvK5MGqIf0MO3Kc+8yQS3Lm/a FcXUWwo1y6h2zp1NBxLyU1Xj9w== X-Received: by 2002:a17:902:a508:: with SMTP id s8mr14691501plq.280.1565706329107; Tue, 13 Aug 2019 07:25:29 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id r137sm24048741pfc.145.2019.08.13.07.25.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 13 Aug 2019 07:25:28 -0700 (PDT) Date: Tue, 13 Aug 2019 10:25:27 -0400 From: Joel Fernandes To: Michal Hocko Cc: Jann Horn , kernel list , Alexey Dobriyan , Andrew Morton , Borislav Petkov , Brendan Gregg , Catalin Marinas , Christian Hansen , Daniel Colascione , fmayer@google.com, "H. Peter Anvin" , Ingo Molnar , Jonathan Corbet , Kees Cook , kernel-team , Linux API , linux-doc@vger.kernel.org, linux-fsdevel , Linux-MM , Mike Rapoport , Minchan Kim , namhyung@google.com, "Paul E. McKenney" , Robin Murphy , Roman Gushchin , Stephen Rothwell , Suren Baghdasaryan , Thomas Gleixner , Todd Kjos , Vladimir Davydov , Vlastimil Babka , Will Deacon Subject: Re: [PATCH v5 1/6] mm/page_idle: Add per-pid idle page tracking using virtual index Message-ID: <20190813142527.GD258732@google.com> References: <20190807171559.182301-1-joel@joelfernandes.org> <20190813100856.GF17933@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190813100856.GF17933@dhcp22.suse.cz> 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 Tue, Aug 13, 2019 at 12:08:56PM +0200, Michal Hocko wrote: > On Mon 12-08-19 20:14:38, Jann Horn wrote: > > On Wed, Aug 7, 2019 at 7:16 PM Joel Fernandes (Google) > > wrote: > > > The page_idle tracking feature currently requires looking up the pagemap > > > for a process followed by interacting with /sys/kernel/mm/page_idle. > > > Looking up PFN from pagemap in Android devices is not supported by > > > unprivileged process and requires SYS_ADMIN and gives 0 for the PFN. > > > > > > This patch adds support to directly interact with page_idle tracking at > > > the PID level by introducing a /proc//page_idle file. It follows > > > the exact same semantics as the global /sys/kernel/mm/page_idle, but now > > > looking up PFN through pagemap is not needed since the interface uses > > > virtual frame numbers, and at the same time also does not require > > > SYS_ADMIN. > > > > > > In Android, we are using this for the heap profiler (heapprofd) which > > > profiles and pin points code paths which allocates and leaves memory > > > idle for long periods of time. This method solves the security issue > > > with userspace learning the PFN, and while at it is also shown to yield > > > better results than the pagemap lookup, the theory being that the window > > > where the address space can change is reduced by eliminating the > > > intermediate pagemap look up stage. In virtual address indexing, the > > > process's mmap_sem is held for the duration of the access. > > > > What happens when you use this interface on shared pages, like memory > > inherited from the zygote, library file mappings and so on? If two > > profilers ran concurrently for two different processes that both map > > the same libraries, would they end up messing up each other's data? > > Yup PageIdle state is shared. That is the page_idle semantic even now > IIRC. Yes, that's right. This patch doesn't change that semantic. Idle page tracking at the core is a global procedure which is based on pages that can be shared. One of the usecases of the heap profiler is to enable profiling of pages that are shared between zygote and any processes that are forked. In this case, I am told by our team working on the heap profiler, that the monitoring of shared pages will help. > > Can this be used to observe which library pages other processes are > > accessing, even if you don't have access to those processes, as long > > as you can map the same libraries? I realize that there are already a > > bunch of ways to do that with side channels and such; but if you're > > adding an interface that allows this by design, it seems to me like > > something that should be gated behind some sort of privilege check. > > Hmm, you need to be priviledged to get the pfn now and without that you > cannot get to any page so the new interface is weakening the rules. > Maybe we should limit setting the idle state to processes with the write > status. Or do you think that even observing idle status is useful for > practical side channel attacks? If yes, is that a problem of the > profiler which does potentially dangerous things? The heap profiler is currently unprivileged. Would it help the concern Jann raised, if the new interface was limited to only anonymous private/shared pages and not to file pages? Or, is this even a real concern? thanks, - Joel