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 7065AC433EF for ; Tue, 14 Jun 2022 00:46:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D56058D01FA; Mon, 13 Jun 2022 20:46:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D056C8D01EE; Mon, 13 Jun 2022 20:46:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA5B88D01FA; Mon, 13 Jun 2022 20:46:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AC8FF8D01EE for ; Mon, 13 Jun 2022 20:46:44 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7A71E2C073 for ; Tue, 14 Jun 2022 00:46:44 +0000 (UTC) X-FDA: 79575001128.24.637DFCD Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf17.hostedemail.com (Postfix) with ESMTP id 2932C4009A for ; Tue, 14 Jun 2022 00:46:44 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id 129so7096293pgc.2 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=rvxV+aeZDCDUxwP0itCRQzrmMF04H5CKxU/ERu1h9eJDZAGo23paatbhjaZUOw7Gmp h7D6UCcfyaqGDL7XNDB50A1tHJX+1p4OCc9afzTg2Ulo6YFCARobubzcFoR0EMJPtUSr tzvECLm83jPtAkM0jt+aclW7ct20Jqdw1HeVWsy1iSiNCFa6M1PHHa6z9axHiKtgH3rf e34turHXo38j2LDzoljHrjxVjXu4E7itmNpbzHvwmTXll6QpZeVu16Ee0bK/FI1ZSLOC uEOG97nsrfsBm9ybO8nI6qP0Ht5PctVbAqzWOV7i6Lpwnbxwj77Xf3IRAOxBgqqJag2j dhmA== X-Gm-Message-State: AOAM530L7rk5P73UXrcKvqeIgSDngFBHMZT9+JNa64Y94q6He10K05lL l/iDOFMLAtygrXIZJmeFbGB6fg== X-Google-Smtp-Source: ABdhPJyqpKu6p1u5KzVVLMZAfN9ra4WcAcLZdMNT/RwAJ4w3TWcPwfXbJl2ut/OvLAU1lo600eJCYA== 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> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655167604; h=from:from:sender: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:dkim-signature; bh=s2FWD/PtgY9oueUwTZqKdyU1Zetmw+d/ZG43eXlDlcM=; b=zeveFgV+k7d8prQpBB1a027WXONXhSBN83soMVSfKOGy1HRPans933YRuSG9xWXou32Qb7 YjT9XGUZrW7x/oAqxLsDBTV3OeAhO2qQIQ+YnAsTbB865Y+OtydwsuG3vfbx4GXITD1MtC U8dXmzy6gHP8Ip7Zwqg5HdzfsI9WDr8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655167604; a=rsa-sha256; cv=none; b=ab6gHpUkNHZi85OHejfVXON4W6SdwXTpuY0n3AA/10BrS8tba/mKAVlDKG1jbjn7F+6dIF BAnVysDTcx9j7LuYXS0+BWM6vicUqb035G0HyNLXkicAiey629eLSYxx85IplcNyoiPdVc 7Ltt5ztpNLqgS4MDWNVTlQIowTFiCfg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YgSLK9gv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of seanjc@google.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=seanjc@google.com Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YgSLK9gv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of seanjc@google.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=seanjc@google.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: p4454sqpurwfoaca57aqxy7ok5wwc3u6 X-Rspamd-Queue-Id: 2932C4009A X-HE-Tag: 1655167604-938253 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: 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.