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 X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D18E8C10DCE for ; Thu, 12 Mar 2020 20:42:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 83A0A206CD for ; Thu, 12 Mar 2020 20:42:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83A0A206CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DF0776B0007; Thu, 12 Mar 2020 16:42:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA0DD6B0008; Thu, 12 Mar 2020 16:42:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C67A76B000A; Thu, 12 Mar 2020 16:42:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0141.hostedemail.com [216.40.44.141]) by kanga.kvack.org (Postfix) with ESMTP id A9FAC6B0007 for ; Thu, 12 Mar 2020 16:42:02 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 68D0D82437D1 for ; Thu, 12 Mar 2020 20:42:02 +0000 (UTC) X-FDA: 76587882084.30.cause75_690317e79fe50 X-HE-Tag: cause75_690317e79fe50 X-Filterd-Recvd-Size: 5780 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Mar 2020 20:42:01 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id d5so8937387wrc.2 for ; Thu, 12 Mar 2020 13:42:01 -0700 (PDT) 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; bh=/GOyUPEGrvjCpyOnL6OSyyemn025t1zSIlLcVN5M0V8=; b=i2XxQL6ea/3LylgoqC7goZCNj9B98Rct1geskPrMges3C39C/HIb+bdeEB+qMPgUub dAQbjWY59htoiVw9y2ZPXOajcD0WhMxVP38PjoAGEkZXyXBsiKs3A2torgUZpqMzE+t0 iIB6wSJ/f+S3Rc+Jfqb1RVTWalLCjIyApJkbsgFKBROFFivoNOjoiRmFagFV5BA/ShYM k0pfkDb768zzw2rgvwXp2Aq5FoT8B/9lN12rLEzhS2Jj8GFXwddoepSyIRBmsZZNIQby SvwE2eDdDLEu2N7qcd8XV8a3KgdU959fJawhZ4ou1LJ7G2p4/ziW5CftLJEddZO26HnA BMVQ== X-Gm-Message-State: ANhLgQ3EQYgQPpiyhDUAI6ls0pRji5x/pZfuv18gEhXkywnbWREteUlo 3NeB5IYjidVwttfORoKqiyc= X-Google-Smtp-Source: ADFU+vvb04mJu44wUMzDGo4x9i4vJFR2V4homWxXiGO5dwhURp2Z2ZjgGJOqj2JJS+4T0phUZl0Wsg== X-Received: by 2002:adf:fa8d:: with SMTP id h13mr3378044wrr.155.1584045720413; Thu, 12 Mar 2020 13:42:00 -0700 (PDT) Received: from localhost (ip-37-188-253-35.eurotel.cz. [37.188.253.35]) by smtp.gmail.com with ESMTPSA id r23sm20870015wrr.93.2020.03.12.13.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 13:41:59 -0700 (PDT) Date: Thu, 12 Mar 2020 21:41:55 +0100 From: Michal Hocko To: Minchan Kim Cc: Jann Horn , Linux-MM , kernel list , Daniel Colascione , Dave Hansen , "Joel Fernandes (Google)" , Andrew Morton Subject: Re: interaction of MADV_PAGEOUT with CoW anonymous mappings? Message-ID: <20200312204155.GE23944@dhcp22.suse.cz> References: <20200312082248.GS23944@dhcp22.suse.cz> <20200312201602.GA68817@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200312201602.GA68817@google.com> 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 Thu 12-03-20 13:16:02, Minchan Kim wrote: > On Thu, Mar 12, 2020 at 09:22:48AM +0100, Michal Hocko wrote: [...] > > From eca97990372679c097a88164ff4b3d7879b0e127 Mon Sep 17 00:00:00 2001 > > From: Michal Hocko > > Date: Thu, 12 Mar 2020 09:04:35 +0100 > > Subject: [PATCH] mm: do not allow MADV_PAGEOUT for CoW pages > > > > Jann has brought up a very interesting point [1]. While shared pages are > > excluded from MADV_PAGEOUT normally, CoW pages can be easily reclaimed > > that way. This can lead to all sorts of hard to debug problems. E.g. > > performance problems outlined by Daniel [2]. There are runtime > > environments where there is a substantial memory shared among security > > domains via CoW memory and a easy to reclaim way of that memory, which > > MADV_{COLD,PAGEOUT} offers, can lead to either performance degradation > > in for the parent process which might be more privileged or even open > > side channel attacks. The feasibility of the later is not really clear > > I am not sure it's a good idea to mention performance stuff because > it's rather arguble. You and Johannes already pointed it out when I sbumit > early draft which had shared page filtering out logic due to performance > reason. You guys suggested the shared pages has higher chance to be touched > so that if it's really hot pages, that whould keep in the memory. I agree. Yes, the hot memory is likely to be referenced but the point was an unexpected latency because of the major fault. I have to say that I have underestimated the issue because I was not aware of runtimes mentioned in the referenced links. Essentially a lot of CoW memory shared over security domains. > I think the only reason at this moment is just vulnerability. > > > to me TBH but there is no real reason for exposure at this stage. It > > seems there is no real use case to depend on reclaiming CoW memory via > > madvise at this stage so it is much easier to simply disallow it and > > this is what this patch does. Put it simply MADV_{PAGEOUT,COLD} can > > operate only on the exclusively owned memory which is a straightforward > > semantic. > > > > [1] http://lkml.kernel.org/r/CAG48ez0G3JkMq61gUmyQAaCq=_TwHbi1XKzWRooxZkv08PQKuw@mail.gmail.com > > [2] http://lkml.kernel.org/r/CAKOZueua_v8jHCpmEtTB6f3i9e2YnmX4mqdYVWhV4E=Z-n+zRQ@mail.gmail.com > > > > Signed-off-by: Michal Hocko > > --- > > mm/madvise.c | 12 +++++++++--- > > 1 file changed, 9 insertions(+), 3 deletions(-) > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > index 43b47d3fae02..4bb30ed6c8d2 100644 > > --- a/mm/madvise.c > > +++ b/mm/madvise.c > > @@ -335,12 +335,14 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, > > } > > > > page = pmd_page(orig_pmd); > > + > > + /* Do not interfere with other mappings of this page */ > > > How about this? > /* > * paging out only single mapped private pages for anonymous mapping, > * otherwise, it opens a side channel. > */ I am not sure this is much more helpful without a larger context. I would stick with the wording unless you insist. > Otherwise, looks good to me. Thanks for the review. -- Michal Hocko SUSE Labs