From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6C46C433EF for ; Fri, 11 Feb 2022 14:55:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD4236B0073; Fri, 11 Feb 2022 09:55:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D83B36B0078; Fri, 11 Feb 2022 09:55:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C24BA6B007B; Fri, 11 Feb 2022 09:55:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id B56F66B0073 for ; Fri, 11 Feb 2022 09:55:35 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 65E018A3E8 for ; Fri, 11 Feb 2022 14:55:35 +0000 (UTC) X-FDA: 79130797830.13.A309D62 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by imf06.hostedemail.com (Postfix) with ESMTP id B651F180006 for ; Fri, 11 Feb 2022 14:55:28 +0000 (UTC) Received: from zn.tnic (dslb-088-067-221-104.088.067.pools.vodafone-ip.de [88.67.221.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 1DF131EC03E3; Fri, 11 Feb 2022 15:55:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1644591322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=cDkjTWDqKQNWnc/zCRpQ/YG8Cct/yEFoBc7JQrQMptw=; b=JuSz00olsVVdWRlZ0j1y2KYv7/pjY9O+lx/jUcm2MLE2qjB8yQXePonn3SHNbDbdw+b92L q8/zE+9levcBrHllOIfG1/b/etAeXOIKwIAZRBCVMm3S1h+8pWO4OEjcSOBWWsX7cIz4NS tl3iyhz39QI5sYRgPGS35NyMFJC7+oI= Date: Fri, 11 Feb 2022 15:55:23 +0100 From: Borislav Petkov To: Brijesh Singh , "Kirill A . Shutemov" Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Michael Roth , Vlastimil Babka , Andi Kleen , "Dr . David Alan Gilbert" , brijesh.ksingh@gmail.com, tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com Subject: Re: [PATCH v10 21/45] x86/mm: Add support to validate memory when changing C-bit Message-ID: References: <20220209181039.1262882-1-brijesh.singh@amd.com> <20220209181039.1262882-22-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220209181039.1262882-22-brijesh.singh@amd.com> X-Rspamd-Queue-Id: B651F180006 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=alien8.de header.s=dkim header.b=JuSz00ol; spf=temperror (imf06.hostedemail.com: error in processing during lookup of bp@alien8.de: DNS error) smtp.mailfrom=bp@alien8.de; dmarc=pass (policy=none) header.from=alien8.de X-Stat-Signature: r5wwqahxe5cpsnkmtgfts1jcbes334kj X-Rspamd-Server: rspam03 X-HE-Tag: 1644591328-487320 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: + Kirill. On Wed, Feb 09, 2022 at 12:10:15PM -0600, Brijesh Singh wrote: > @@ -2012,8 +2013,22 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc) > */ > cpa_flush(&cpa, !this_cpu_has(X86_FEATURE_SME_COHERENT)); > > + /* > + * To maintain the security guarantees of SEV-SNP guests, make sure > + * to invalidate the memory before clearing the encryption attribute. > + */ > + if (!enc) > + snp_set_memory_shared(addr, numpages); > + > ret = __change_page_attr_set_clr(&cpa, 1); > > + /* > + * Now that memory is mapped encrypted in the page table, validate it > + * so that it is consistent with the above page state. > + */ > + if (!ret && enc) > + snp_set_memory_private(addr, numpages); > + > /* > * After changing the encryption attribute, we need to flush TLBs again > * in case any speculative TLB caching occurred (but no need to flush > -- Right, as tglx rightfully points out here: https://lore.kernel.org/r/875ypyvz07.ffs@tglx this piece of code needs careful coordinated design so that it is clean for both SEV and TDX. First, as we've said here: https://lore.kernel.org/r/1d77e91c-e151-7846-6cd4-6264236ca5ae@intel.com we'd need generic functions which turn a pgprot into an encrypted or decrypted pgprot on both SEV and TDX so we could do: cc_pgprot_enc() cc_pgprot_dec() which does the required conversion on each guest type. Also, I think adding required functions to x86_platform.guest. is a very nice way to solve the ugly if (guest_type) querying all over the place. Also, I was thinking of sme_me_mask and the corresponding tdx_shared_mask I threw into the mix here: https://lore.kernel.org/r/YgFIaJ8ijgQQ04Nv@zn.tnic and we should simply add those without ifdeffery but unconditionally. Simply have them always present. They will have !0 values on the respective guest types and 0 otherwise. This should simplify a lot of code and another unconditionally present u64 won't be the end of the world. Any other aspect I'm missing? -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette