Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1599497iog; Tue, 14 Jun 2022 09:07:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1snb8Li8VpfmAg/I5oSRqcaHoY1KlqRFSrp9nLB0ieu0bY7Ujzybabz0/6FEjfZt9tOl/ij X-Received: by 2002:a17:90b:3e85:b0:1e8:8e0c:88de with SMTP id rj5-20020a17090b3e8500b001e88e0c88demr5292068pjb.151.1655222846888; Tue, 14 Jun 2022 09:07:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655222846; cv=none; d=google.com; s=arc-20160816; b=wLG6POQ8qJ9a5yOcAbeYgteU9Zc8Fp8FUqWJCc9uACBF3MW/bODwGCRq90R0acJDhl m/qy7Yx9XJti56Rv0GP82j6sp7Ub/nc9g8WP68tEbwCscR0WotorpvX+bD3+zosuF2S8 +1BM/YV3lEEPCjR0IKdlnQrM+BZ6nDc/AqEOLUAJ3LT1slV7wx6ahm41U0mW0dbQQDwO 3NO1vwR17JyCBL9aQ3Gq8+HhwjjeHu8hhFkphNXp7fUTVtl2grMQJqZS42UcPsmavokQ yCHabbzcX3Qlq1f7uEcxMko4m9oh1ynluB/H8H6hqRxWwtnX4EdZ+Jf/D90UlrniQ42c NRqQ== 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=v7R3AU8eay3jFLbgOIExfUOsI5EdQhSbQRsdrHwotJw=; b=DDcoA3Q0yHXDns+ImzE8wN7J1HaTOavAvD7gN31+iD7VutrbiCD9g7//zwZiYxFXlB f5hlpIDfqzTZR0EWho2iFbyjzRo9cZRJZ01856AAjVMDxHAStCGPrMDifpRU8Sf+kTf9 Qe2BxS/EarizJcpxWvFvv7SvLZ+OxZyn1z9Ne6v2Z1B7LyQPLE9O/a3EFwpotgC4Kv1A lCtQ3BbIdAGDELOtaG8u63+chjssVZtuuktGvIWwvWd5U7m0hGCna2H4VfyOjwEReAnh pVWwOxIn+ez9G/rwPcD79Q25usnbGgYqy3G4LH1OVUQK/r6Ubw6TlUQbXC1M7xHXtfQA GKaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ehHmS6K8; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k38-20020a63ff26000000b003f25a28a4afsi11685627pgi.241.2022.06.14.09.07.13; Tue, 14 Jun 2022 09:07:26 -0700 (PDT) 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=@google.com header.s=20210112 header.b=ehHmS6K8; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243232AbiFNPn4 (ORCPT + 99 others); Tue, 14 Jun 2022 11:43:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237232AbiFNPny (ORCPT ); Tue, 14 Jun 2022 11:43:54 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8522C366B7 for ; Tue, 14 Jun 2022 08:43:53 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id o17so8072084pla.6 for ; Tue, 14 Jun 2022 08:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=v7R3AU8eay3jFLbgOIExfUOsI5EdQhSbQRsdrHwotJw=; b=ehHmS6K8XnQ2SrjXe0GbtBVb7v2r/7AcW7sIGGWUjjSMTDgZG99AgHzHG+emgMuy78 oJg0pzPpvCtiu3YGgen4uTSgcaIQrSr23K6ULxNbRwaPO6Yv/2KLZXVbn7tBDmMEA+JB /OEgfzksSH1MA4vy1vX+tyavgxHUWffoUJgQft6aRg+kifewPpPNV53IAZXgkNQBHTWY Ql4t/SIvDY0bHTODMSic0GJaxZI6gfqzTzQMvW4xvnj/rmFRw+k9nbzv081yS6sEUTLa VSazk4yWTKuGPfHB+dJmXxfbDPgU54AVHMrrKLFMMzFiEc/Rb9mMF6g9UULaB5YLhewT nzjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=v7R3AU8eay3jFLbgOIExfUOsI5EdQhSbQRsdrHwotJw=; b=zS9N7qHT+ZiFm4vpmVhcJOamp7avwOQJ/Ablsb+5nUJrpASawO2fKzDonAgSgEbeZN fBSoKL3TxR0sW9jbHARUrcMuBd6FFgFwoRzzjcJiDGqdchGSqV4vDr+F4IQD8JmocnrD hKaqddxscvdgoLjx9wWHgsAcO2Yfe29TQ4svPK/oKKM9lW17cFFAjkbxTR2fz316XY9G XTLsbktnN/yJpIZSRGctNbE1BMBCI0O9iU62bNnSRzDaRZ/RNxje8Tgpbbgu9VHBtCjH MDUsCUIwL2UlVAP4XxTfiNyuhRrS1zr3HmBzm1WbuYWcv2/quLbFRaiUA5C/DQldhbfB GFNQ== X-Gm-Message-State: AJIora+OrfJU6xtq5yU8ToQCB4XFkQN07GML58NpGIdDpZQ9UGVzLxVj ni4PtjLzcHCdyJUoI1X81EN3Yw== X-Received: by 2002:a17:90a:fd0d:b0:1ea:b661:4fa1 with SMTP id cv13-20020a17090afd0d00b001eab6614fa1mr5238743pjb.46.1655221432801; Tue, 14 Jun 2022 08:43:52 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id v11-20020a1709028d8b00b00165105518f6sm7390006plo.287.2022.06.14.08.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 08:43:52 -0700 (PDT) Date: Tue, 14 Jun 2022 15:43:48 +0000 From: Sean Christopherson To: Michael Roth 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 , Vitaly Kuznetsov , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Vlastimil Babka , "Kirill A . Shutemov" , 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 v12 19/46] x86/kernel: Make the .bss..decrypted section shared in RMP table Message-ID: References: <20220307213356.2797205-1-brijesh.singh@amd.com> <20220307213356.2797205-20-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Tue, Jun 14, 2022, Sean Christopherson wrote: > s/Brijesh/Michael > > On Mon, Mar 07, 2022, Brijesh Singh wrote: > > The encryption attribute for the .bss..decrypted section is cleared in the > > initial page table build. This is because the section contains the data > > that need to be shared between the guest and the hypervisor. > > > > When SEV-SNP is active, just clearing the encryption attribute in the > > page table is not enough. The page state need to be updated in the RMP > > table. > > > > Signed-off-by: Brijesh Singh > > --- > > arch/x86/kernel/head64.c | 13 +++++++++++++ > > 1 file changed, 13 insertions(+) > > > > diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c > > index 83514b9827e6..656d2f3e2cf0 100644 > > --- a/arch/x86/kernel/head64.c > > +++ b/arch/x86/kernel/head64.c > > @@ -143,7 +143,20 @@ static unsigned long __head sme_postprocess_startup(struct boot_params *bp, pmdv > > if (sme_get_me_mask()) { > > vaddr = (unsigned long)__start_bss_decrypted; > > vaddr_end = (unsigned long)__end_bss_decrypted; > > + > > for (; vaddr < vaddr_end; vaddr += PMD_SIZE) { > > + /* > > + * On SNP, transition the page to shared in the RMP table so that > > + * it is consistent with the page table attribute change. > > + * > > + * __start_bss_decrypted has a virtual address in the high range > > + * mapping (kernel .text). PVALIDATE, by way of > > + * early_snp_set_memory_shared(), requires a valid virtual > > + * address but the kernel is currently running off of the identity > > + * mapping so use __pa() to get a *currently* valid virtual address. > > + */ > > + early_snp_set_memory_shared(__pa(vaddr), __pa(vaddr), PTRS_PER_PMD); > > This breaks SME on Rome and Milan when compiling with clang-13. I haven't been > able to figure out exactly what goes wrong. printk isn't functional at this point, > and interactive debug during boot on our test systems is beyond me. I can't even > verify that the bug is specific to clang because the draconian build system for our > test systems apparently is stuck pointing at gcc-4.9. > > I suspect the issue is related to relocation and/or encrypting memory, as skipping > the call to early_snp_set_memory_shared() if SNP isn't active masks the issue. > I've dug through the assembly and haven't spotted a smoking gun, e.g. no obvious > use of absolute addresses. > > Forcing a VM through the same path doesn't fail. I can't test an SEV guest at the > moment because INIT_EX is also broken. The SEV INIT_EX was a PEBKAC issue. An SEV guest boots just fine with a clang-built kernel, so either it's a finnicky relocation issue or something specific to SME. > The crash incurs a very, very slow reboot, and I was out of cycles to work on this > about three hours ago. If someone on the AMD side can repro, it would be much > appreciated.