Received: by 10.223.185.116 with SMTP id b49csp3544482wrg; Tue, 6 Mar 2018 00:29:09 -0800 (PST) X-Google-Smtp-Source: AG47ELvRql6oKln5ygGP3N+FiCdgD5PVBt5Zic47px9eaFqjAQp8BJY+SvTmjKKtxvRAlO/JTvZL X-Received: by 10.99.119.72 with SMTP id s69mr14414714pgc.224.1520324949761; Tue, 06 Mar 2018 00:29:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520324949; cv=none; d=google.com; s=arc-20160816; b=dfD+p4/P3fAUlZe8fRnt2vl438scsYwjr4rsidLHAqKs/nj7UBOL2Tp3GXi62SlV/R 7BHMYdmSRRr4e6gHDruMoB+koncZpijn1CwDO4tHlt8N4/JY6EK+Wv2yMhXNOGUwMXfU D/kBx7B+upVpqvBFeLnIPLHshveHjq9Uf6QKtoNPU5qh/R0UhbPzsiNQUM9KBpGrO79O JvHZkCBLyLUtmkoRLtnKY9/esDXKIOoUIvAh77Aah/ay28BwxjFbhd5QpIY3PtWz7Y0Z TQzcNWiKFmLVEIpar9vXqtcA8qNETZD+oc2qvy/3pjksvp9k51K3OhqC3fXr3MT52aSu qmkg== 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:arc-authentication-results; bh=5nhKBuoejGxyFrKcSz96640tLUw+Wc5K7pvku3oCN0A=; b=S1ElakdpQJeRqRngA0idpANMHxki66BdqPFtEODq/ZwujJdcPyFFGhtRTTIzKjCnCY L8NiAN/4Crr8nSrxTE9dpqz/0uboSk6O2iK4gTx1spj9MOFwj/YqNEyJuc/KetLFymMC XOazJZXyeG/dxk1dAOre+i6nCewKaDxwK6i1gR+Uq5uXHndGMGsQdsTKhUCdebUxd9D3 c5TgtmdFmz/2z3o3pfM0EdXMSTzbuxJNgJJwkkW3yS4P5hd2yepioWc7r2nGIkkYwPr6 Gx9hhKVSIBOUMHRuvRlnAvKcUt+C0O3odWYp1wC3O301uRcJWfU6fPF+FbcpSOOVQ5vi 6kRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=V88y2cXR; 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 u10-v6si10592405plu.509.2018.03.06.00.28.55; Tue, 06 Mar 2018 00:29:09 -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; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=V88y2cXR; 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 S1752162AbeCFI2B (ORCPT + 99 others); Tue, 6 Mar 2018 03:28:01 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:40523 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750769AbeCFI17 (ORCPT ); Tue, 6 Mar 2018 03:27:59 -0500 Received: by mail-wm0-f66.google.com with SMTP id t6so20537378wmt.5 for ; Tue, 06 Mar 2018 00:27:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=5nhKBuoejGxyFrKcSz96640tLUw+Wc5K7pvku3oCN0A=; b=V88y2cXRcdPDkm631MJ1tgZ4E453YfmPmBL1SYitG3Fwj75PHzHS0unY7CI/qZob6W e7UEkxs4lpC3qCaN3fLesNQVKwX+WW17qovxBtrg/LLaX8gTE28+Jl2Q9vpYDtRceZn+ IAwOuisu4U2zF1AyT+DF6O/uZnEmo5ZII58bJlSEKm7nOs/NRkY1AcZbylshWanoQpnF mwqJprcDNNGryNCCi8+BUzqCVJLKjzL81Sg2Pa3BlIFJsV5QZOIL8mTa2Ar4+KYxOwvh WKD0mVNo4ugBsUrMsnQjH9Z6FrvTITTretv5oBBSpJsalhJRURHzVDGFI1jrUIWWCzSp P92g== 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=5nhKBuoejGxyFrKcSz96640tLUw+Wc5K7pvku3oCN0A=; b=VSA4D5fe6rd+Y6IkzGAzLRmeg4goLreh0c7ufyUSbDfoOSJDtAkC4aXyRTTrv7v/MV O7b9tHhnenSph+pF+hvEkzH1vaS3L8wkBfH3m+GZh2iTxFamA3CDYtHh83VCgeYZvBal n6vAAOZw92hc+sb45CLVHdz8GW1CR0CGyf7bYtRjrrNOYSXrVgwrR2rLJsgpZi6NKafo bfTvlbVS8XAb/tpIC5TO25qivjd9D2xBVNcfh9mK3QEjzVuvScPu3L7UolC0+90m+flE iiu+8IVBpxETt3ad+hxl/dv3hsvE7RxzLtmwb113YVYFi97pdZpuxcWYnUIVxAmPWVEC 7GkA== X-Gm-Message-State: APf1xPC2ntPX5Ak6woSEyaC75oYKucp+EIM1aINmJZgKSsBWi8epdeV2 ydUDBoUcwxUBFI96OPfrtSybzA== X-Received: by 10.80.169.34 with SMTP id l31mr22086095edc.242.1520324878852; Tue, 06 Mar 2018 00:27:58 -0800 (PST) Received: from node.shutemov.name ([86.57.210.234]) by smtp.gmail.com with ESMTPSA id 8sm11874627edw.72.2018.03.06.00.27.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Mar 2018 00:27:58 -0800 (PST) Received: by node.shutemov.name (Postfix, from userid 1000) id AE5BA648D520; Tue, 6 Mar 2018 11:27:43 +0300 (+03) Date: Tue, 6 Mar 2018 11:27:43 +0300 From: "Kirill A. Shutemov" To: Dave Hansen Cc: "Kirill A. Shutemov" , Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky , Kai Huang , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC, PATCH 13/22] mm, rmap: Free encrypted pages once mapcount drops to zero Message-ID: <20180306082743.2epdfxv4ds7hz7py@node.shutemov.name> References: <20180305162610.37510-1-kirill.shutemov@linux.intel.com> <20180305162610.37510-14-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 05, 2018 at 11:13:36AM -0800, Dave Hansen wrote: > On 03/05/2018 08:26 AM, Kirill A. Shutemov wrote: > > @@ -1292,6 +1308,12 @@ static void page_remove_anon_compound_rmap(struct page *page) > > __mod_node_page_state(page_pgdat(page), NR_ANON_MAPPED, -nr); > > deferred_split_huge_page(page); > > } > > + > > + anon_vma = page_anon_vma(page); > > + if (anon_vma_encrypted(anon_vma)) { > > + int keyid = anon_vma_keyid(anon_vma); > > + free_encrypt_page(page, keyid, compound_order(page)); > > + } > > } > > It's not covered in the description and I'm to lazy to dig into it, so: > Without this code, where do they get freed? Why does it not cause any > problems to free them here? It's the only place where we get it freed. "Freeing" is not the best terminology here, but I failed to come up with something batter. We prepare the encryption page to being freed: flush the cache in MKTME case. The page itself gets freed later in a usual manner: once refcount drops to zero. The problem is that we may not have valid anon_vma around once mapcount drops to zero, so we have to do "freeing" here. For anonymous memory once mapcount dropped to zero there's no way it will get mapped back to userspace. page_remove_anon Kernel still will be able to access the page with kmap() and I will need to be very careful to get it right wrt cache management. I'll update the description. -- Kirill A. Shutemov