Received: by 10.223.185.116 with SMTP id b49csp3565150wrg; Tue, 6 Mar 2018 00:55:51 -0800 (PST) X-Google-Smtp-Source: AG47ELt6wN3QVm3dFRgAHL96aNsaGvo7cxJA5JEit1GUAIIlDWTIfeSFrQSyoZjHz9csnbkIr7MX X-Received: by 10.101.74.208 with SMTP id c16mr14553609pgu.116.1520326550921; Tue, 06 Mar 2018 00:55:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520326550; cv=none; d=google.com; s=arc-20160816; b=UXLCLG96i7s+ZLcyiJhnwcxqoSZ9d1n20EXLelHTXLD+XLgeR5wph2H2E40ufUyhYC wOsYSxoXgZAFm/Nubapqw47CfA/dTp7pe95ogXxMzagQThnGtgoXgFDhP1eF8h1eUlFr lGOjOsxiCezZL9/q9/mjn/l6vMC2NumlPbk7eJDMtkZuvaaP3pNGL/f4SjyuSVfJ6U6W +RDXwIPmJoJI/WcFeiw7zQhZalUQUO4mLuu8MGQ40RNR/eApIy5L9hCESo8q2TYdZJ4b UBRVqee4uDb8Jtrmb/gXZ3zMtogTi2r5DPml3W9f6jULO+UT2Ze0xFrbpWd/0nZ0IEjb dyRA== 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=ue1ulx0qGxCJ2k7w5nfeyv8vZaBX9m6CLFujiWnpimk=; b=xCJH7eQvFwQVR4taErExL0d0l0DPgfvOzN7oJDquF7LcuR5fbv04gXO7mwittaRz/T 9pgUWRupNQ2hxSGA51g8sJjZJSVEM+D4kwtbB8bm9pMh7byXErUiUJcIOZ1CI/bvOLVZ 8Px4ihELliR3FXm+TJCBnjbNnNxKqosm3B/udgz58CSWO9jn8nFq/hR35Gs3nM7E1oKS gH01yyLD75bOIrLm7MwO8zWiq9v0uwCj9NjRgq8AbsHdXnqbTrNkTfAJfDeGO6jCfHsL nrplVHI7UITPQZz73uVSgdEdYHke/0XH/f+Iuwl3BKQcn2r8TSoItaow0MaAsJwqY5aF Dr9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=o/YxYlpM; 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 r17si9634428pgo.179.2018.03.06.00.55.35; Tue, 06 Mar 2018 00:55:50 -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=o/YxYlpM; 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 S1753077AbeCFIya (ORCPT + 99 others); Tue, 6 Mar 2018 03:54:30 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:38806 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750864AbeCFIy3 (ORCPT ); Tue, 6 Mar 2018 03:54:29 -0500 Received: by mail-wm0-f67.google.com with SMTP id z9so20548318wmb.3 for ; Tue, 06 Mar 2018 00:54:29 -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=ue1ulx0qGxCJ2k7w5nfeyv8vZaBX9m6CLFujiWnpimk=; b=o/YxYlpM3gRsXGE82HT5mWpMWaNc1x8MNTUyxwog3e5uWbla1H5bpl+GUYNtoq46ga 1yMmMKF3gxLs1F06LULBB0S2R8WGtg1SbDHHjX8y4F/Y0m2n9BVfaYfR4jaufiFiIIYX TzkrrwyusxKy2pD/4QbkCqPFANOgsOicg9+8hM2wDH1Wfz0UVqu5HWZGawiX0b5oCVfB gu6ffzdJBkkyk5b0CrWb4lFkEwFgSZZEyOfN2KnXKlR0XQhcqiPzJXE+NIrec1nUDJbk EG8Qz7oYSClvbNh8qu5B2bdo5GXYj5Cl/4Z9cwmKJi5xudvmRP0df1wim2pXDGAN28Pn Rx2g== 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=ue1ulx0qGxCJ2k7w5nfeyv8vZaBX9m6CLFujiWnpimk=; b=pOnxGpO4WIe0ot0f5OspSdK3VRKMGPMqcYUuvTchXmK5kCQh/zAzunxBvUIEWtl0tV 3ub6L8w7D/MJfoT5EIMMub0vcl4swZMC/UkhcU+037xjFPNhyXsH6nw61AjI4XSJNyGl tAP6PvM7Hnm3Sc33Qvs+QkEPu6YnKXnP2lCEI9P111VRoyGlU2tYQ2QYWMsVWaWTz5uf eV072TsgpWZSBN3ksY+ER8QrW1cAZa6F3kIP5+UO0ixK+ZADFdojFJsBeFxmM++CmhRA VG0zJqep+a9qRruW8u08FyQyXO6iX3aXQtUT7wzXKJMnCpqTfQhv/CUVilkG7z7DPne3 ySWg== X-Gm-Message-State: APf1xPA/mC4353q7NHQYHKLRvIPR9bOm7OWJosWBKaWrrDj3u1fUVn19 9ZwiprHE33oEhUSuCEiXcN/LJQ== X-Received: by 10.80.179.73 with SMTP id r9mr22820056edd.78.1520326468481; Tue, 06 Mar 2018 00:54:28 -0800 (PST) Received: from node.shutemov.name ([86.57.210.234]) by smtp.gmail.com with ESMTPSA id x35sm12791577edb.55.2018.03.06.00.54.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Mar 2018 00:54:27 -0800 (PST) Received: by node.shutemov.name (Postfix, from userid 1000) id 06690648D520; Tue, 6 Mar 2018 11:54:12 +0300 (+03) Date: Tue, 6 Mar 2018 11:54:12 +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 19/22] x86/mm: Implement free_encrypt_page() Message-ID: <20180306085412.vkgheeya24dze53t@node.shutemov.name> References: <20180305162610.37510-1-kirill.shutemov@linux.intel.com> <20180305162610.37510-20-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:07:16AM -0800, Dave Hansen wrote: > On 03/05/2018 08:26 AM, Kirill A. Shutemov wrote: > > +void free_encrypt_page(struct page *page, int keyid, unsigned int order) > > +{ > > + int i; > > + void *v; > > + > > + for (i = 0; i < (1 << order); i++) { > > + v = kmap_atomic_keyid(page, keyid + i); > > + /* See comment in prep_encrypt_page() */ > > + clflush_cache_range(v, PAGE_SIZE); > > + kunmap_atomic(v); > > + } > > +} > > Have you measured how slow this is? No, I have not. > It's an optimization, but can we find a way to only do this dance when > we *actually* change the keyid? Right now, we're doing mapping at alloc > and free, clflushing at free and zeroing at alloc. Let's say somebody does: > > ptr = malloc(PAGE_SIZE); > *ptr = foo; > free(ptr); > > ptr = malloc(PAGE_SIZE); > *ptr = bar; > free(ptr); > > And let's say ptr is in encrypted memory and that we actually munmap() > at free(). We can theoretically skip the clflush, right? Yes we can. Theoretically. We would need to find a way to keep KeyID around after the page is removed from rmap. That's not so trivial as far as I can see. I will look into optimization after I'll got functionality in place. -- Kirill A. Shutemov