Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp980802iog; Mon, 13 Jun 2022 17:57:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFVM45wIoDxpg+dxUMbS1l4XzIMECA8yBqBu+KRr53O/vIs21gWl/XUPBanSSX+1STcTWa X-Received: by 2002:a65:6d0b:0:b0:408:7ced:3ca1 with SMTP id bf11-20020a656d0b000000b004087ced3ca1mr2113493pgb.476.1655168241527; Mon, 13 Jun 2022 17:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655168241; cv=none; d=google.com; s=arc-20160816; b=PmXgCCGzxaW/iNWGwuSrYmcyHf0AP+D7dgaTFXgZADAwjGiqqSJYarCnZ5t5m8cO+r mxuNk46ue13jq7VAD57/rVjdAXb3myaT4RfQZF1nwjamVWKHsuEqyLfi0g8Rr4cpgSUC R5EpnAJAS+oAyiwLKVXNIxtJ1fNBZdV1k7TJgJSYAwJh8i9cF+U6E4ObudSEY9owgPxf mMoHW0zSWeJ6b14e/ba/pC9D1gUl29IIwJpRpkCC+77e3ZBghywaPr7q/35Z/F5FS1yi aBpDsC9kC5Ez+jBxFXIYNPHIBRYZ28qYxMF61Q2tKnTWoKKfAdeXQy5ipXQyUA76n68l eHQw== 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=s2FWD/PtgY9oueUwTZqKdyU1Zetmw+d/ZG43eXlDlcM=; b=inNPpvTW3nIe90jK7jAclKkAEg+DyVkJCCHNmMbaXLQrtSuJixpscghw1Rsh3Yp1aC KrsCRqnC08ADwxCELLmhyhaD4bUJwbc4IY6NQrzi8THQz7fwUX/EcNSubBZQhEWWjiWo IGWyO/pFkMgK02pQzzh3SUYnHD+BP4bNG5HpkJd3jrQxG5ePo0KzZqonSjttpxllTsN+ L1HrwsDJg80eT/JIuKTvSEohkArUP8lyGhH+mceMBf18zxVtQkvKu8fQuSzG9PaOKAZz xdSs0eeoeNytLjJzO+kAry8DFP4Yad7db7HtHvkURODDjKjZkk7JoF3pXx6aSe03I9Am 9nLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YgSLK9gv; 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 lp2-20020a17090b4a8200b001e67c8309a5si12654779pjb.9.2022.06.13.17.57.04; Mon, 13 Jun 2022 17:57:21 -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=YgSLK9gv; 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 S233760AbiFNAqw (ORCPT + 99 others); Mon, 13 Jun 2022 20:46:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231726AbiFNAqs (ORCPT ); Mon, 13 Jun 2022 20:46:48 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92B782FFED for ; Mon, 13 Jun 2022 17:46:43 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id s135so7062433pgs.10 for ; Mon, 13 Jun 2022 17:46:43 -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=s2FWD/PtgY9oueUwTZqKdyU1Zetmw+d/ZG43eXlDlcM=; b=YgSLK9gviQctEV72wBcPKr3rDhijCNprOQ+gp2fOSYMwl+z8m/ywJFJNdRTPfdRN6x iDRg42v/QZUmhq4AMxM+546r3kFUi55RAc+j47EeF+C6skbeoGymucTmWpWLGBIjymwN uCP4s+WQkriW77kbjxxgNIF7QaYBwwsZzcUDKSti8Czi1gIsPCEV4pAVmZvrc7Ueaqhw lOHhx1muh9QhVGl7UTGDpBBFbxdvLgwbahBIYa67KFXU4u9bWvK0IQr6jEiB+VXErtmh 6ToX5gd8nYLLeOC0TQ5G60KE/adZglCpxc3QxuFm4VL16SHCtIdEzNaKBM/HaQhyF4O5 +Rww== 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=s2FWD/PtgY9oueUwTZqKdyU1Zetmw+d/ZG43eXlDlcM=; b=37uaQz3Yqz+omsx84fW3+Qi/F/SfNeM77GNyUSqnkfsvHbIP8Abte+9iskWykiOz4o nOnsiCVQuyqataAEiZHLEx/CkTsjlao18CZRZnj2uYXkzNJDIdC1zabMOUCfRDTJiLlU pVFD9fUqqBs9DPPdWlT0v9piPv2EMroHlQNbWWuKpjnJmJyXX5FZRYyPb/IKeTv3979/ 33ZuL3x4y/qhOIZxK6AiLzyr1Uux9r1ZcSnX9CBuxne/ljseQ6TX2d+qUO+7scEL5hCn JMrkK9z5kFwf4XAzmc9ODKduCJ6ETUvEHBNAcD/MnxriObNllojal+p6jJiBtKJY0SX8 6GWQ== X-Gm-Message-State: AOAM533yezGJNYPPvBgzdC/4CEiV6jG7OIQ94FxLSlhwBf98gmE3wnyC VSc5Sdqsxj0/rXUrObRLN4Ptew== X-Received: by 2002:a05:6a00:179b:b0:51b:f51f:992e with SMTP id s27-20020a056a00179b00b0051bf51f992emr2018667pfg.60.1655167602802; Mon, 13 Jun 2022 17:46:42 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id u4-20020a17090a2b8400b001e31fea8c85sm8035481pjd.14.2022.06.13.17.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 17:46:42 -0700 (PDT) Date: Tue, 14 Jun 2022 00:46:38 +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 , Michael Roth , 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: <20220307213356.2797205-20-brijesh.singh@amd.com> 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=unavailable 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 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 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.