Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5609764imm; Mon, 23 Jul 2018 02:52:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfewdvaZXOAtRZUsyNZwsnvG1d3Q9Am58RAkpusquY8curG71ALWOuSs+jsxuH+yhoCNPar X-Received: by 2002:a63:2fc6:: with SMTP id v189-v6mr11501777pgv.61.1532339552840; Mon, 23 Jul 2018 02:52:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532339552; cv=none; d=google.com; s=arc-20160816; b=UdvbI/XISaFa3x5R1cb1Ay00mTt/BI8MWgsH/MtLVfSr/wQPVuO6tMk2fORhVAbuHs K58QYP0mK4ZU26apRd2OPYVhMTbgf+sriqGsF5kS6AtQ2WB3SJEs93tpXE0uWuQCV35l xYgSb/AYTULcCs7ksg80DmMEzbVlsLAh9TG4KEkYworDQoPz1KSgq6M3OS9TqhmUM0Tg NdBrhOopLo75n53IxFGdfKqfZyqWd7tONlGdx8EmcItwgEis+p3kyLAAH1gwXEUIB9YG izXci5zKn8qsL3FtaJMuxa9OVeklrtAfDfkFZR2/hMBO+zWAVxybhLRB76UAvYO9PYjC YtLg== 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=seB4p8Ce99OAz1JgNP1URFi4/nGC1mU2hyKPuBYHYm4=; b=TIBukftBq7N/A4/2eQC6y+yfFK27sYa6olRC+ZEDw85WWCOXjcnKBSIDfTj6gYQwvF fcIDJeFX2sbv1tY4oweRiPOYIdxSbXSVSa6z5qJiWG0uPu/zSZxBjs15Fu2TYUo/Gw6D hWaSTvxWqM0cWr5hKdE7FG96xHRJ/c8WcmjcDhPYgQ+9csMaafzz0bTnGR3MVQYf/vaw Lv44DcH6Pt+V4QMVgZhjMEs6+jvtb/Dky20CXBA8FQ8zzKnfG/dncVcs++bO/xT4F3vu 17HtoNlyHQnRFy0eUXK0iWo6Kb28k7hEKNbTSLdmDADdEgCzyd36ZNzC0b6ontVRi7MB 9Ptw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=Qe8NJdwa; 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 190-v6si8585265pfy.293.2018.07.23.02.52.17; Mon, 23 Jul 2018 02:52:32 -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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=Qe8NJdwa; 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 S2388274AbeGWKvH (ORCPT + 99 others); Mon, 23 Jul 2018 06:51:07 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:36754 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388175AbeGWKvH (ORCPT ); Mon, 23 Jul 2018 06:51:07 -0400 Received: by mail-pl0-f66.google.com with SMTP id e11-v6so14486plb.3 for ; Mon, 23 Jul 2018 02:50:44 -0700 (PDT) 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=seB4p8Ce99OAz1JgNP1URFi4/nGC1mU2hyKPuBYHYm4=; b=Qe8NJdwa+Q4dlh2zHkEFHc6/cZJVppradMxIfeZg9hKxVWJTwMViRXs6Tz5hicHZtY u2dfo0uNdfuLKzfFmr1EljBtvt00PgGYmzyOuKdC0JXELTMiuT+EQgCAZXLvNDu8+bYM 3xQej7QCv6TorRzJ68ypR2mQXO+rf4N0hnyvE6K1tza7sPK/Y5rzZIHeRRbmx1iOYl0n DYLu+9QaNS+HDeMgmwQud6PTYk38S93hhMLdA5I/tHkULV989ZL+wYe6zQMZBvmfcal+ vTX0rKaLiXqAWXvP04O/oY+MQDmQFT9NsQlfu7pX4V50pJgo51cZQkOP9aT7tWbDQLbA lAnA== 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=seB4p8Ce99OAz1JgNP1URFi4/nGC1mU2hyKPuBYHYm4=; b=Ltbhn3dc851rDVrMB5VtwUVjRwmya5oWxOTNrkLqVH4o9WjmyFqJX4XvORzdGc+cAk ecHslpjSJwlIQwXWC/jg+oW+XAs9GaTprntuXN59qS08VpJ4znZF/rTm141wf5RnUUw3 Z2ZAUdtfzUzva0N3LijPND8kJDmX1oEubcqKlXxhsragdPeAWWc5MxZ6++I0AHJ5Qe67 YyqSi8Nih9aJ1R6fUZyeHR2CM3jfNemZIeek6UDGxB4KAYQMfZ/pQzwr4wcSc4y+U/vN XKSFjR/8rcwuiEclySFr3NAMn+XkBZ2BMpPtkvPlEEBA3UHSJNsL591C+tC43POnm4Lx t8fw== X-Gm-Message-State: AOUpUlFvzMbYPw6Dbp0YuUm67EivY4OX5CbtWcVXENI1ubpVBEtAJmlc /USpBVtCxu9P46+zi37l9iq5nw== X-Received: by 2002:a17:902:bc49:: with SMTP id t9-v6mr12223639plz.116.1532339444601; Mon, 23 Jul 2018 02:50:44 -0700 (PDT) Received: from kshutemo-mobl1.localdomain ([192.55.54.40]) by smtp.gmail.com with ESMTPSA id d22-v6sm14740187pfk.69.2018.07.23.02.50.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 02:50:44 -0700 (PDT) Received: by kshutemo-mobl1.localdomain (Postfix, from userid 1000) id 41A5B303A0F; Mon, 23 Jul 2018 12:50:40 +0300 (+03) Date: Mon, 23 Jul 2018 12:50:40 +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 , Jacob Pan , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCHv5 12/19] x86/mm: Implement prep_encrypted_page() and arch_free_page() Message-ID: <20180723095040.w67jp7c7cnxezuwp@kshutemo-mobl1> References: <20180717112029.42378-1-kirill.shutemov@linux.intel.com> <20180717112029.42378-13-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/20180622 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 18, 2018 at 04:53:27PM -0700, Dave Hansen wrote: > The description doesn't mention the potential performance implications > of this patch. That's criminal at this point. > > > --- a/arch/x86/mm/mktme.c > > +++ b/arch/x86/mm/mktme.c > > @@ -1,4 +1,5 @@ > > #include > > +#include > > #include > > > > phys_addr_t mktme_keyid_mask; > > @@ -49,3 +50,51 @@ int vma_keyid(struct vm_area_struct *vma) > > prot = pgprot_val(vma->vm_page_prot); > > return (prot & mktme_keyid_mask) >> mktme_keyid_shift; > > } > > + > > +void prep_encrypted_page(struct page *page, int order, int keyid, bool zero) > > +{ > > + int i; > > + > > + /* It's not encrypted page: nothing to do */ > > + if (!keyid) > > + return; > > prep_encrypted_page() is called in the fast path in the page allocator. > This out-of-line copy costs a function call for all users and this is > also out of the reach of the compiler to understand that keyid!=0 is > unlikely. > > I think this needs to be treated to the inline-in-the-header treatment. Okay. Again as a macros. > > + /* > > + * The hardware/CPU does not enforce coherency between mappings of the > > + * same physical page with different KeyIDs or encryption keys. > > + * We are responsible for cache management. > > + * > > + * We flush cache before allocating encrypted page > > + */ > > + clflush_cache_range(page_address(page), PAGE_SIZE << order); > > It's also worth pointing out that this must be done on the keyid alias > direct map, not the normal one. > > Wait a sec... How do we know which direct map to use? page_address() -> lowmem_page_address() -> page_to_virt() page_to_virt() returns virtual address from the right direct mapping. > > + for (i = 0; i < (1 << order); i++) { > > + /* All pages coming out of the allocator should have KeyID 0 */ > > + WARN_ON_ONCE(lookup_page_ext(page)->keyid); > > + lookup_page_ext(page)->keyid = keyid; > > + > > + /* Clear the page after the KeyID is set. */ > > + if (zero) > > + clear_highpage(page); > > + > > + page++; > > + } > > +} > > + > > +void arch_free_page(struct page *page, int order) > > +{ > > + int i; > > + > > + /* It's not encrypted page: nothing to do */ > > + if (!page_keyid(page)) > > + return; > > Ditto on pushing this to a header. > > > + clflush_cache_range(page_address(page), PAGE_SIZE << order); > > OK, how do we know which copy of the direct map to use, here? The same way as above. > > + for (i = 0; i < (1 << order); i++) { > > + /* Check if the page has reasonable KeyID */ > > + WARN_ON_ONCE(lookup_page_ext(page)->keyid > mktme_nr_keyids); > > + lookup_page_ext(page)->keyid = 0; > > + page++; > > + } > > +} > > > -- Kirill A. Shutemov