Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3804679pxb; Fri, 11 Feb 2022 08:06:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmee9erwgzGDGar2N5CWZ+qYC8H0QsFY2p9KLjWtv61C2H0vRDxznYcSnsLyZGvRj+TnMv X-Received: by 2002:a17:90b:1b52:: with SMTP id nv18mr1144649pjb.20.1644595612976; Fri, 11 Feb 2022 08:06:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644595612; cv=none; d=google.com; s=arc-20160816; b=GxFb/kggP6lWqoM/47IJJVTZg+/eUjobhvvlqpYsdKVxK+SvzSfoBai15ZNT6e/yEv pH31t8ppgraE76pstEx0K3VOdExL3LhPkkZHCBxkJ0qNico/nt6QMkQMSSh8f5enUr1/ 8shTTPPeELcWMnnOEYsfYpotsXtkNBixibUDP4UF4LEa+DDkfZldxlaYdtTCKpbC9KXl znD5z9kpZIthtI5DhEYJMzj6GtNnIg7G2HLTPtzpj7riwrJw06l54NYA+FkPf/boLZII a9YOzCoVhylPJDiMyKJe9nQex4nGV6n5XuP9/jyFVBgRWvVcOvZ0QyjcIchXmhBvozS8 RxYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=cDkjTWDqKQNWnc/zCRpQ/YG8Cct/yEFoBc7JQrQMptw=; b=cUm1tKdEsL/11GitdETzNAPRl5dONXfW8whL3Snq9oNTYbKx9vfcwNWO71nm67ogvD u40cjucUirljWBSBfII+wN11U1vnCbPU4YC4MIrxW6n+Iu+GYe8GuMn7gJ8Hr6ZBfKTt xg3oiaOv5Y0tGKPdcT2GnZ4xzw4t5W6drz5S4tLiU+ehbY3wXzg7MXuK/d4hjIIi3fgv vsCrnqGjbIoIZmJeMTg0ly3+wlLQeNKeHmNWVO4huBNabPYARtF5cq38nR9prxwd+1Mi oGfJdTnUq7huO/fGJguoOQM/PsuWCcVRcR1+t+GhGkrjHKgWTtmzOxZETF0C9zHdF5HZ WcMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=JuSz00ol; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r23si5054729pls.138.2022.02.11.08.06.38; Fri, 11 Feb 2022 08:06:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=JuSz00ol; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239073AbiBKOzd (ORCPT + 99 others); Fri, 11 Feb 2022 09:55:33 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349983AbiBKOz3 (ORCPT ); Fri, 11 Feb 2022 09:55:29 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2721A131; Fri, 11 Feb 2022 06:55:28 -0800 (PST) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org + 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