Received: by 10.223.185.116 with SMTP id b49csp2940999wrg; Mon, 5 Mar 2018 11:08:21 -0800 (PST) X-Google-Smtp-Source: AG47ELsxkCLm9t7EG3+h2HWNtziQKs6EnJL2soFKpKcrjrLGlaNzWGh05G94fz78tdJugVFjGbXh X-Received: by 10.99.2.140 with SMTP id 134mr13197374pgc.117.1520276901213; Mon, 05 Mar 2018 11:08:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520276901; cv=none; d=google.com; s=arc-20160816; b=hZ/j/G01Q4BTes6wIvbiKCJK37HAsQR7D+JJflAKFRgvsZJXi3c+ZJ+mWshIdFt7Z0 ERl+3y0mgNCy6qOpVF+z3SAPEc1fvijmQ2UGoHf1iZOJswk2CEZ9kVFbQ4D+jfioo4Rk Lg4EIza5UNOw21wWEYsqKygyV6QC5qJMMYsahQa8vTvMKneshsoinagCyn+MKfW1HRmD PS7YL38XDWQCgkZH1QxwUU0aik8tLQBfmkWP8bjvFVXj3oIpzlO8ztGlznJD8N6Itj2b brQPTp+fIRxymrpavY4UJHS+UkUn7YRxJWEae4Gto35b2170ShuFxrOyEzKPjRrbzj4p 9CJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:cc:references:to:subject:arc-authentication-results; bh=UhbChAa2gjy58t1q1XeTpknxWqenUDuen+B+GZX5cIA=; b=nMSijlsLh6kljLVnx78ScQmupLLWGC174P0zPPTpanKHu2pqH4J2d+J439gX1l8KZT gIJFArxVe0omy+KfD2Dpl1NjNOFoa8FDGDkj5Uv6pZFm5V/0cna0L55omRbWyFJwG/zS qATUjCyo/26asBjZ/hqs0opYLDwhFj71En7NllP+KYqcw0xHUeAORtAiur6Ch03h/+n1 331NRvqcJNASgZlsMJpsVtj4O9e0xNXzAVFNvwoqoFKRSCqM0lFr7F29+MVR9BBJRmMs l4kOStnWAk4YgMoUYmC+TsuUgGOq1fR6zl6p7jEXxclDVl5UWH19cMH+g4R8orTjLTZD KFmw== 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 z8-v6si9718674plh.379.2018.03.05.11.08.07; Mon, 05 Mar 2018 11:08:21 -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 S1752519AbeCETHS (ORCPT + 99 others); Mon, 5 Mar 2018 14:07:18 -0500 Received: from mga14.intel.com ([192.55.52.115]:17179 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751462AbeCETHR (ORCPT ); Mon, 5 Mar 2018 14:07:17 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2018 11:07:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,428,1515484800"; d="scan'208";a="32575151" Received: from ray.jf.intel.com (HELO [10.7.201.16]) ([10.7.201.16]) by orsmga003.jf.intel.com with ESMTP; 05 Mar 2018 11:07:17 -0800 Subject: Re: [RFC, PATCH 19/22] x86/mm: Implement free_encrypt_page() To: "Kirill A. Shutemov" , Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky References: <20180305162610.37510-1-kirill.shutemov@linux.intel.com> <20180305162610.37510-20-kirill.shutemov@linux.intel.com> Cc: Kai Huang , linux-kernel@vger.kernel.org, linux-mm@kvack.org From: Dave Hansen Message-ID: Date: Mon, 5 Mar 2018 11:07:16 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180305162610.37510-20-kirill.shutemov@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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?