From patchwork Wed Feb 21 11:35:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 204177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp979234dyc; Wed, 21 Feb 2024 03:39:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX52zGdOQ6FqwddcDZes2Qxl8tgiX0GKwNz36Ar8P3E8yXv+wA0wggbbLwM/31nazP79nFbjTxigniny1O4l5n9mrDBgg== X-Google-Smtp-Source: AGHT+IGiBKnwikTPAYolxj4mL02q/6gaJwkWz3/Z5gOrRplHLKwDyMB346mpnrjpQbPk94ExQcV6 X-Received: by 2002:a05:6402:202a:b0:565:59a:a103 with SMTP id ay10-20020a056402202a00b00565059aa103mr164585edb.33.1708515577397; Wed, 21 Feb 2024 03:39:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708515577; cv=pass; d=google.com; s=arc-20160816; b=HQD3mMPi98lb9KRqNSBby9eg5gEIfVM0QIBZ8wVg38Wk2v0x1O5WT5gKGCSzEUy4HF 8Kwy+lhF5CpBYYIg94S9vTv88VM9/0acHTwVamr7bYyHnZrgqKx/YPKRh/PJka1kjs7K umEn6aVD26QE48AvxBIyuRfiPglJWlB00N4TMUFnq8d9eLYUDpyUbWYTila/Knm/Iqcg jl93l5lcrVn2gOCjjlrzz8ceNBM6WegjpQk+JAKjMJc7OzUS04gZE6lPul1URS2ehgZi iyy5dvcgFp8cBr/NrLJyFBUK0GaXq82shiv4Q42QhdRGBGPYeO/WWsYm1IS1svb0LZxO R4qg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=ygqZ0HdVfjjnya+uCKEPe+HOAs/11yLIprq08KYDjCU=; fh=fMhMPvo8duafGkM4xZHdH7fULbau3etefTGsKa+Qy7I=; b=paIlCY3uh8/dsMGdtEJqgUaQnhqk2GJHsbpLR27n8Eq20g7ozprFunjoEZGO8m0Bv0 DV6mhbeaSXey7SoOstxCO162hprWCLEeiutrQtFoJX+hCyaJIt0NNq+y8Afrn5X/UsUF ZKfY9fzu+3osiebkUAnOlS6BGcbbevKexCcqHtP0/8qo+Kn9snu0gbXdYJsoAKSnQe6Z br1Zi5sYx92B1onMgzDzKHAkmvqdwb1oSMzusvuAa3sDr84/gPqAIiWQvopWUUGt0Bxb e0kQSWTnbKKwv+CdaBrEeBFkoJ/zx4SAScH8FjiwU7ABPMZSPJHqPMLYQ3i55r8FXwY0 /x4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=JlK8D5pv; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-74642-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74642-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 27-20020a50875b000000b00564a94db4c2si2008213edv.564.2024.02.21.03.39.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 03:39:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74642-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=JlK8D5pv; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-74642-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74642-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D39BD1F2385D for ; Wed, 21 Feb 2024 11:39:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40F6C4F611; Wed, 21 Feb 2024 11:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JlK8D5pv" Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86F824E1DE for ; Wed, 21 Feb 2024 11:36:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708515366; cv=none; b=h69xODYXBHwZ/vF7pPcY2fIsmY7oZGXjmvOmyEFx3TUMXYGfwiyby4Korv02ywdU/bZM4FhszIu7ge1fpJ5g9Xh342a+DYIKT/WLf42mnNA1kb9ZMzvf1q9EgavXGVn5BXJUTh5kI410LOmCu6LpG+tubuDt7BpMG24wX1SltXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708515366; c=relaxed/simple; bh=cyP4xFLZtWmSglaQt1bRPcLQO2AlvE55S6UyeZvMgMM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=miCNVbVoPeTLkkA6JaERCq0j/HBnHrtVOarm2Qn/rBaFvku+WSh/XuRFovucgaoRVAYXuOKmWecLcdkKk48V2thUH/fgn0PkaylEKNZ/CxvHOeC+lzr5kMWPfOYa2ZFcoQR2xHle1/YZz++nMZwabmaD4NLrXXYJJyzOxkJcySk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JlK8D5pv; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-33d6eb5e5a9so860189f8f.3 for ; Wed, 21 Feb 2024 03:36:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708515363; x=1709120163; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ygqZ0HdVfjjnya+uCKEPe+HOAs/11yLIprq08KYDjCU=; b=JlK8D5pvk7Isl6HzBVdYrAm+zaNAlQxeZDLUziDxhFpQBDJ56Zjnx21H64Ku7KZuc1 CVfkqzNxy14GGjCSaw4GbPcMzv5BMq3c/xfU4MEvmLed8Clsg8yavTsqLncMlh4lUWrb 8q2tbO9TMckC0lYN++2lBPVnKQyNd0i+5zXtIFoZNCBXwqfMWuER5eH3VEFFIJucgwCC hKvAfWJ81UAIAQmTG7UaLpu40yCP69Uphl5+L9uJQLvG+cZ9Z8ZLBv1gaFK3C3zzBOsX s9gOSC+0FQEVSerpb0L/dCNWbj8JTVRQRKrRUF4h4vEGmrSC/FNfOP3AeIqzd8OlL7XX OBAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708515363; x=1709120163; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ygqZ0HdVfjjnya+uCKEPe+HOAs/11yLIprq08KYDjCU=; b=L2EH8dBkeTTVY6z7A9IxH+Ghbyc6DlNkFwj55f4MEvETFJqZN8QQ8WDa3XRVkYTYdS Jw+0Pq0f/FEpLtsjjS4u2ltrvYbOSpx9o2LdDCHLib8/xGRLgdiiA1YFbzSMDAzVLTUV wsIxc8etqt98A0smHOcAX/EsOEIH5SNvfKsDcRlhmsVU+2gIQxBHdLESt0BzkL8IyQyQ EV4+bZ0Gb+KLqvXqWp2PElzVCRCzq4VOi3V1EhMXbeL3pmcfMAi11uRJ+3xiJGGqcWDe pnQZV17PrGGRLZc1dHKXfYvtZcWA8kMZ9wWj26/vQqAUJclYXSl/QbonTuaNNx0ySVAe 6jGw== X-Gm-Message-State: AOJu0Yxbv3esqYDwgZO5FJRg40O8HAgg+H9diZjkD2yfOyuN85ghF6Qe EtK1rIwp1j5E03c2VknT2LmHKuxxuwKedL9oGBiqISUO4t1RoDMjhyM3M7xixaOtsewQ4XrDH3v yLo7VgphUrxeJnEbJl78s8y5V5KbaGgDVlWmeNzFSM2m+ZvR1B01W2xbPsIA7cTzWaWOFVWPLJa HGXeqb/7SDpWhRffxpZteP3MKQuqE+Jw== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6000:68e:b0:33d:6211:4699 with SMTP id bo14-20020a056000068e00b0033d62114699mr12133wrb.0.1708515362858; Wed, 21 Feb 2024 03:36:02 -0800 (PST) Date: Wed, 21 Feb 2024 12:35:19 +0100 In-Reply-To: <20240221113506.2565718-18-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240221113506.2565718-18-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2183; i=ardb@kernel.org; h=from:subject; bh=FIfYcIT0zte0p7QudMXkiQVk0sZSk5MJFoxtVIwXDvE=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXq/c9nhK593//oPlvM+uJnf5Nc71pP9q7bFnDn2vKpe juuWl3h7yhlYRDjYJAVU2QRmP333c7TE6VqnWfJwsxhZQIZwsDFKQATefaLkaGrnXW+jfYSrgsP p9+equA17UpPH4dg3J10EcZptlf7eCUYfrN0v79eFNqz2qvx2ofQ+R1Z77et35Z4RktOxt5mUal rEB8A X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240221113506.2565718-30-ardb+git@google.com> Subject: [PATCH v5 12/16] efi/libstub: Add generic support for parsing mem_encrypt= From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Justin Stitt , Kees Cook , Brian Gerst , linux-arch@vger.kernel.org, llvm@lists.linux.dev X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791508430250822530 X-GMAIL-MSGID: 1791508430250822530 From: Ard Biesheuvel Parse the mem_encrypt= command line parameter from the EFI stub if CONFIG_ARCH_HAS_MEM_ENCRYPT=y, so that it can be passed to the early boot code by the arch code in the stub. This avoids the need for the core kernel to do any string parsing very early in the boot. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub-helper.c | 8 ++++++++ drivers/firmware/efi/libstub/efistub.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index bfa30625f5d0..3dc2f9aaf08d 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -24,6 +24,8 @@ static bool efi_noinitrd; static bool efi_nosoftreserve; static bool efi_disable_pci_dma = IS_ENABLED(CONFIG_EFI_DISABLE_PCI_DMA); +int efi_mem_encrypt; + bool __pure __efi_soft_reserve_enabled(void) { return !efi_nosoftreserve; @@ -75,6 +77,12 @@ efi_status_t efi_parse_options(char const *cmdline) efi_noinitrd = true; } else if (IS_ENABLED(CONFIG_X86_64) && !strcmp(param, "no5lvl")) { efi_no5lvl = true; + } else if (IS_ENABLED(CONFIG_ARCH_HAS_MEM_ENCRYPT) && + !strcmp(param, "mem_encrypt") && val) { + if (parse_option_str(val, "on")) + efi_mem_encrypt = 1; + else if (parse_option_str(val, "off")) + efi_mem_encrypt = -1; } else if (!strcmp(param, "efi") && val) { efi_nochunk = parse_option_str(val, "nochunk"); efi_novamap |= parse_option_str(val, "novamap"); diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 212687c30d79..a1c6ab24cd99 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -37,8 +37,8 @@ extern bool efi_no5lvl; extern bool efi_nochunk; extern bool efi_nokaslr; extern int efi_loglevel; +extern int efi_mem_encrypt; extern bool efi_novamap; - extern const efi_system_table_t *efi_system_table; typedef union efi_dxe_services_table efi_dxe_services_table_t;