Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2929107rwd; Mon, 22 May 2023 06:28:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42lUxzJpUMTZt0r966HxarLZYtcBBGwGzaI5beBWkQn8lQoXTLx6OYL8y9fFbVn4yuZCvw X-Received: by 2002:a05:6a00:1407:b0:64d:7162:9cf0 with SMTP id l7-20020a056a00140700b0064d71629cf0mr4265782pfu.8.1684762083215; Mon, 22 May 2023 06:28:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684762083; cv=none; d=google.com; s=arc-20160816; b=wOVSSUYx5xUGiKb/ezuVq5rDvsZcOptn84d/wjzL+Pg0nUAyXl9w4kylvthrBEy0A7 Lcj/V2bopvmOf2c6+nqwnYw45EmbWjmeKtTu6OCmZ2J/iMSoloBFBbFzcy27m+7kDx/w uHhmr3uCA1aHrRCycB17xGZtkcHpnmxHOBUrxBxv9BOZXAc9kro4TAtlHTQgdRwp4qaP vFBSEfT5FiPWxCri3K6DptK+nlm5+npE/Q2kXA5/80rg6My+PKkDl9BcpGVk7ROV358p VgSum7CKOMhtTI8aiJSO9ZjP8gos39+pfICNkTYIoxmr/Tx9V51Ee+vxCR/Z+RYh8MCS uI7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7u68zoTS07q9s3GBWLsm7KWO4t3fwTtoq09If6Ew5oY=; b=Iue3mZmAYl5jq/TyKBytS1q+3q4gN7OkP2ehW63EpzfvELxqpOEbf9Kls63CVtoPWY m4CtcaoSrQC8nKvbuOkbNHsDfHJYh0HnnSAd5+U+MMvX5a+aHuNSvoiJ/6R2F3ATRpZd SvKJja/16/8q5j2esFbmgG1vLeJjQrBXxYDHriYw3zFh6AQjmK84Og8uu/JLcBGL5Nqw ILRd4EJk7B5LzcMcLrXF35rdaX3/T6X3MMs6GbcEW405zMkS0kHJSbFzzxWjicnOpRMY 9kipMbfyKBMrQ4xwT3OQFIiB1MZMOcRcLYVC0a3LwTtyllvwwjcUgM8Ixo3tgmjAtEFK FtPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NE0oDkB2; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p14-20020aa79e8e000000b0064398a54dc8si4856814pfq.376.2023.05.22.06.27.50; Mon, 22 May 2023 06:28:03 -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=@kernel.org header.s=k20201202 header.b=NE0oDkB2; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234213AbjEVNHl (ORCPT + 99 others); Mon, 22 May 2023 09:07:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233903AbjEVNHi (ORCPT ); Mon, 22 May 2023 09:07:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6021103; Mon, 22 May 2023 06:07:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8253B622A6; Mon, 22 May 2023 13:07:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E36D1C433B0; Mon, 22 May 2023 13:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684760849; bh=rLIjMH2epiWQ/3Lob2C6ObKYXvlX/q1x4S2igdYWzY8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=NE0oDkB2ESWTG0cYJwhI6j2f3UeG38SEQs/tuIfWrCD1HjzYSZ9k603k1rM2XMLxq N0kzsfuIZ1oRfAHeu2GS1QJDtNrX0YxVDorEsbX+OWOu8GIQda2R/9ht4PWy2ZwdTa Agos9U3owbngNVq2cRDABuAGLWd+MBx6U4xvWfI98FHZaCAzSE3MmyY5V/U14IPaxT jR50aLuqbBhzcSnUB1mreYNZiD12aw/Xht/VbAhJzBf7jZ+9CRXEvwfO9WKeHz1PkQ S5oPnVtOfweaSmE0eTeqROw5f0JwylNtQEYHavFvn/4qdQYuKmypybHEsfeCF1SQKd p41BDkaaMsGqA== Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2af30a12e84so22904311fa.0; Mon, 22 May 2023 06:07:29 -0700 (PDT) X-Gm-Message-State: AC+VfDxTRcYEsbsDCtVStsSFJypKoDYOOCcGpJ4VegQnGPaaRGBlPBVE K2/c6+ylWVpf3wTTuYCf8njduF70eW46Tu5kf+0= X-Received: by 2002:a2e:8615:0:b0:2ad:b01b:d458 with SMTP id a21-20020a2e8615000000b002adb01bd458mr3813882lji.30.1684760847855; Mon, 22 May 2023 06:07:27 -0700 (PDT) MIME-Version: 1.0 References: <20230508070330.582131-1-ardb@kernel.org> <20230508070330.582131-18-ardb@kernel.org> In-Reply-To: From: Ard Biesheuvel Date: Mon, 22 May 2023 15:07:12 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 17/20] x86: efistub: Check SEV/SNP support while running in the firmware To: Joerg Roedel Cc: Tom Lendacky , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Evgeniy Baskov , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , Gerd Hoffmann , Dave Young , Mario Limonciello , Kees Cook , "Kirill A . Shutemov" , Linus Torvalds Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Mon, 22 May 2023 at 14:48, Joerg Roedel wrote: > > On Fri, May 19, 2023 at 09:04:46AM -0500, Tom Lendacky wrote: > > Deferring the checks is probably the safest thing to do, since that would > > match the way things are done today and known to work. I'm not sure what > > other things might pop up if we stay with this approach, for example, page > > state change calls using the GHCB MSR protocol that also don't save/restore > > the MSR value. > > > > It is possible to audit these areas and stay with this approach, but I'm > > wondering if that wouldn't be better done as a separate patch series. > > > > Adding @Joerg for any additional thoughts he might have around this area, too. > > If I got it correctly the patch actually moves two things before > ExitBootServices: > > 1) SEV features check > > 2) SEV initialization > > I think it makes a lot of sense to have 1) before ExitBootServices. It > allows to soft-fail in case the kernel does not support all required > SEV-SNP features and move on to a kernel which does. This check also only > needs the SEV_STATUS MSR and not any GHCB calls. > > The problem is the GHCB protocol negotiation with the HV, but the GHCB > protocol is downward-compatible, so an older kernel can work with a > newer HV. > > But 2) needs to stay after ExitBootServices, as it needs resources owned > by UEFI, e.g. the GHCB MSR and potentially the configured GHCB itself. > Fiddling around with the GHCB MSR while it is still owned by UEFI will > bite us in one or the other way (e.g. UEFI, before ExitBootServices, is > free to take IRQs with handlers that rely on the GHCB MSR content). > Thanks for the insight. Note that I have sent a v3 in the mean time that moves all of this *after* ExitBootServices() [0], but I failed to cc you - apologies. So IIUC, we could just read sev_status much earlier just to perform the SNP feature check, and fail the boot gracefully on a mismatch. And the sev_enable() call needs to move after ExitBootServices(), right? That would result in only very minor duplication, afaict. I'll have a stab at implementing this for v4. Thanks, [0] https://lore.kernel.org/all/20230522071415.501717-21-ardb@kernel.org/