From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0047.outbound.protection.outlook.com [104.47.33.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xgqn929WyzDq66 for ; Mon, 28 Aug 2017 21:49:32 +1000 (AEST) Cc: brijesh.singh@amd.com, linux-kernel@vger.kernel.org, x86@kernel.org, linux-efi@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Andy Lutomirski , Tony Luck , Piotr Luc , Fenghua Yu , Lu Baolu , Reza Arbab , David Howells , Matt Fleming , "Kirill A . Shutemov" , Laura Abbott , Ard Biesheuvel , Andrew Morton , Eric Biederman , Benjamin Herrenschmidt , Paul Mackerras , Konrad Rzeszutek Wilk , Jonathan Corbet , Dave Airlie , Kees Cook , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Arnd Bergmann , Tejun Heo , Christoph Lameter Subject: Re: [RFC Part1 PATCH v3 15/17] x86: Add support for changing memory encryption attribute in early boot To: Borislav Petkov , Tom Lendacky References: <20170724190757.11278-1-brijesh.singh@amd.com> <20170724190757.11278-16-brijesh.singh@amd.com> <20170828105119.xs73tinknqcmrgvk@pd.tnic> From: Brijesh Singh Message-ID: <4b3cec09-ab6a-0400-00fe-328b36564942@amd.com> Date: Mon, 28 Aug 2017 06:49:19 -0500 MIME-Version: 1.0 In-Reply-To: <20170828105119.xs73tinknqcmrgvk@pd.tnic> Content-Type: text/plain; charset=utf-8 List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi Boris, On 8/28/17 5:51 AM, Borislav Petkov wrote: [..] > +static int __init early_set_memory_enc_dec(resource_size_t paddr, >> + unsigned long size, bool enc) >> +{ >> + unsigned long vaddr, vaddr_end, vaddr_next; >> + unsigned long psize, pmask; >> + int split_page_size_mask; >> + pte_t *kpte; >> + int level; >> + >> + vaddr = (unsigned long)__va(paddr); >> + vaddr_next = vaddr; >> + vaddr_end = vaddr + size; >> + >> + /* >> + * We are going to change the physical page attribute from C=1 to C=0 >> + * or vice versa. Flush the caches to ensure that data is written into >> + * memory with correct C-bit before we change attribute. >> + */ >> + clflush_cache_range(__va(paddr), size); >> + >> + for (; vaddr < vaddr_end; vaddr = vaddr_next) { >> + kpte = lookup_address(vaddr, &level); >> + if (!kpte || pte_none(*kpte)) >> + return 1; > Return before flushing TLBs? Perhaps you mean > > ret = 1; > goto out; > > here and out does > > __flush_tlb_all(); > return ret; thanks, good catch. I will fix in next rev. -Brijesh