Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1574933pxb; Tue, 8 Feb 2022 22:48:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJysQqbfjE2D9aCAIWJVRdGEtHSgEv0RXgkb4DMnP9F14paepcKkRjoEj7QaAYbacg+NleOZ X-Received: by 2002:a17:90b:1c83:: with SMTP id oo3mr1858134pjb.6.1644389333570; Tue, 08 Feb 2022 22:48:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644389333; cv=none; d=google.com; s=arc-20160816; b=c5QsvhY34zl1vLDXj+lQZ7RbmkdLCIHA/oRN3ErMmVaxKCs26QHXrHozpS+sXCoSRn id4+VMaI2NsFQLLEmPkYBa/JU4+FHr6axrM9dThbT77ZPbBymSPgQMEYvHNiDU1lBl1S Sg87nK0pkIzRuMPcf//+VbvvHpTpKkwRaMQCgy+ojYd0ttl26+T0VThFRs6bgSRO24lg 5zj7QnYlLy6tTirzxAVVXbrV5qXIReIFJ2QBXs3j9wtUfjynlMyDMTEi/1P5S8+XqRqR soLxWIMNSZgiClqH8h+F8LDnF5ZwCNOPAYoRBrZP6ndzQw5pel/SoFZtqvuo/RvOYZUr AhWQ== 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=iTzDr07nDR0Kl7lFwHuFFDUEMCGqC9FB/uZHfJ8d1Mw=; b=DvgJ1Sb2bG4HmA13y9POjlgGU9JqN7mCXjbnboENkXS71RuhRbCJfKaoXk5GPZ/wUV dDAhHmxz0pkb9wGIO2si0NzwHmmec16pjU0qxR2mOXlE1qzARMN3vHwqP/lt6UfPX6ta FigxfzJ7LfttRGlKJiNCzjiPzx9DrasVBr/GS9e2EcOJnn4xsKZ63oRtFDe6p7X6rm5i G1ejoRLcD1h6MwncSz81dKocLZeYGqE1X+2tM3LRDbQ/3uZQhfLXAjQYlmbZOwKWkchA hPpbwGmOc0IiIMi9oOiXDxGEntMry6n93AogfEe635sI7feMwxHWNBpN5BYH8TZPBEz1 7nOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IYp6uTWj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id be11si14339800plb.94.2022.02.08.22.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 22:48:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IYp6uTWj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D63D7E00FA51; Tue, 8 Feb 2022 22:17:25 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238499AbiBGWL7 (ORCPT + 99 others); Mon, 7 Feb 2022 17:11:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243692AbiBGWL6 (ORCPT ); Mon, 7 Feb 2022 17:11:58 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB26DC0612A4 for ; Mon, 7 Feb 2022 14:11:57 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id w1so2659083plb.6 for ; Mon, 07 Feb 2022 14:11:57 -0800 (PST) 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=iTzDr07nDR0Kl7lFwHuFFDUEMCGqC9FB/uZHfJ8d1Mw=; b=IYp6uTWjHF7Eyy4PczCpkHeC9xff7BNFIgUZQKzLF6A5XC4d2aZTzFxbsdu7wbLLV+ 8qnuGLKuJS6YV1HIEddyw1WBUHZINajA2y7bT6iItl4bHpP1y3IDp2m5DRlkgZSpXvBx C3c+GD1fb7NhmNCLjgdjXmtW+E6jQ4/6qjaflz3A1pwwoWjAHIZebaoWxL5f/KCtHbRf NAh8BCEcH96Xlbh6SqxxTpPe/NYIUSybli6KNHCMu3R7vj1otLza7HJFHJ7M71x203u1 2eVL46KcknHxwS6gm9Bb18RAjr7p/addt5Ap6SGO+3ThcgyH/nig+9ouMapWeIYw1Kp0 An7A== 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=iTzDr07nDR0Kl7lFwHuFFDUEMCGqC9FB/uZHfJ8d1Mw=; b=RtvLGdmYC3p1xjFRnkwLsdkzpmrYSuew78C7DMLP/2QHcbInPUHm3kSUI4WJ7ZWUOV Ga+g8am9V+57qI+isbj9nR54KmjJhZff7vvluqnAkDtJLQSkUWp4IZHTQM4bR0F56qZB 04IQSibrFROO/Oapk5BpxsCtTz5GH+xDmMxcTSz1IZkOMGE79C8jZc2cNRZ2MD0AIEID wdW+OFb0zeZ/7kT22fbMsDjtBnKgwYMHw7fpnbk9hjV2Kkei03VuJihFmvlpZ6mxx5BU wTxt6OGAlvcuaUOJ6lLNLzkYjdGnZdITxxPBW3Rr5KksAfHhLYhkQm6A+ilg56b5viNr 7HNg== X-Gm-Message-State: AOAM533fnPOk3oGZtZmJf5Smn0zizfGVBv+FceDQ2OqTLpvteLa3Sjno PzwpHqQSvtt4pEG0D0paLl7yqQ== X-Received: by 2002:a17:90b:1b52:: with SMTP id nv18mr1114781pjb.136.1644271917102; Mon, 07 Feb 2022 14:11:57 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id iy13sm321808pjb.51.2022.02.07.14.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 14:11:56 -0800 (PST) Date: Mon, 7 Feb 2022 22:11:53 +0000 From: Sean Christopherson To: Joerg Roedel Cc: x86@kernel.org, Joerg Roedel , Eric Biederman , kexec@lists.infradead.org, hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Martin Radev , Arvind Sankar , linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v3 05/10] x86/sev: Setup code to park APs in the AP Jump Table Message-ID: References: <20220127101044.13803-1-joro@8bytes.org> <20220127101044.13803-6-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220127101044.13803-6-joro@8bytes.org> X-Spam-Status: No, score=-15.3 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_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 On Thu, Jan 27, 2022, Joerg Roedel wrote: > +static int __init sev_setup_ap_jump_table(void) This name is really confusing. AFAICT, it's specific to SEV-ES, but used only "sev" for the namespace because sev_es_setup_ap_jump_table() already exists. I assume this variant is purely for parking/offlining vCPUs? Adding that in the name would be helpful. The two flows are also very, very similar, but apparently do slightly different things. Even more odd is that this version applies different sanity checks on the address than the existing code. It should be fairly simple to extract a common helper. That would likely help with naming problem too. > +{ > + size_t blob_size = rm_ap_jump_table_blob_end - rm_ap_jump_table_blob; > + u16 startup_cs, startup_ip; > + u16 __iomem *jump_table; > + phys_addr_t pa; > + > + if (!cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) > + return 0; > + > + if (ghcb_info.vm_proto < 2) { > + pr_warn("AP jump table parking requires at least GHCB protocol version 2\n"); > + return 0; > + } > + > + pa = get_jump_table_addr(); > + > + /* On UP guests there is no jump table so this is not a failure */ > + if (!pa) > + return 0; > + > + /* Check overflow and size for untrusted jump table address */ > + if (pa + PAGE_SIZE < pa || pa + PAGE_SIZE > SZ_4G) { > + pr_info("AP jump table is above 4GB or address overflow - not enabling AP jump table parking\n"); > + return 0; > + } > + > + jump_table = ioremap_encrypted(pa, PAGE_SIZE); > + if (WARN_ON(!jump_table)) > + return -EINVAL; > + > + /* > + * Save reset vector to restore it later because the blob will > + * overwrite it. > + */ > + startup_ip = jump_table[0]; > + startup_cs = jump_table[1]; > + > + /* Install AP jump table Blob with real mode AP parking code */ > + memcpy_toio(jump_table, rm_ap_jump_table_blob, blob_size); > + > + /* Setup AP jump table GDT */ > + sev_es_setup_ap_jump_table_data(jump_table, (u32)pa); > + > + writew(startup_ip, &jump_table[0]); > + writew(startup_cs, &jump_table[1]); > + > + iounmap(jump_table); > + > + pr_info("AP jump table Blob successfully set up\n"); > + > + /* Mark AP jump table blob as available */ > + sev_ap_jumptable_blob_installed = true; > + > + return 0; > +} > +core_initcall(sev_setup_ap_jump_table);