From patchwork Thu Jan 25 11:28:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 192024 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1574205dyi; Thu, 25 Jan 2024 03:36:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGYSxVswOr/PG4CuOmd+ztoTeMhxQF7+1uXsE21Mf3oXMusOVecoR9hr2YPvvTfy+P415vl X-Received: by 2002:a05:620a:8d9:b0:783:c539:16a0 with SMTP id z25-20020a05620a08d900b00783c53916a0mr302078qkz.148.1706182585999; Thu, 25 Jan 2024 03:36:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706182585; cv=pass; d=google.com; s=arc-20160816; b=ZaIe+qpOL5nlOE9QiceJ2Vnci6yLbIwBzmjdn5aYchMiptCBp726LAlpcYijm2Vvxk 1pZCTOQuYsJQw7cLL/iHdYe68KKnYxvWT2VIQ6JCaQfGPGr7GWtFnKWggL++Prn6vWf2 9w0fKBZcZlwV9B3+aOJvVWILT3Yf2Jkbs6bfVoBBYLCNy2GxjOdwdkNEewivtL+VAcNu jmYov330JUmmtluOTeszN8iqjMZRdA7MGu02Z/l/CkNOjej41BnP6wUsIK9X+OIAzEbC nesuHvYLU3ZSB5RtgpkQAwGw7EgbqJHfk4lBsQwxZLwXR5TJQl6zGw9wMvzBbAMSm9+U yxyg== 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=Vu5UpmPKB2YLCZqvfGM/x/cMDohVrJdP/wVfbDfAQyQ=; fh=Mjd69IxHltS/Jba8SYEPy4aDMrScq2KBDxG2XjETtWk=; b=nSjbh/JXilN4TMDMa+PqaRtYsztQlNUsURJKeKovQJVnWKNJ2azl3Mvcpg973Ge4VU v8aB9HsEzkv7YJa9SlZC/fPkROG2568DlaRoq4uPo+mmoEt2JFXAgsPVfvfSxuAQd7wO bBVs6heOi5pMq/XaoIbsb/wzRCFY5wCrt6wXJU7jRVyOAtBbmCvDAhnPBUNV/6ziYPvG 5vzMmYDAI7ctsjMkVYrf1pel5dCJdVRJBV1oiLHISFpAGcuYKf6KXhIOgwZh2K/y9nIo zJ6zI1DAQm75ab6NEO6guva+32jBxaCOYwoFcm/30hukbrFKo9tsn267xX90sWL3zi5j MnXQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=av+QYO+S; 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-38518-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38518-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id k16-20020ae9f110000000b00783a2469a57si7874069qkg.340.2024.01.25.03.36.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 03:36:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38518-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=av+QYO+S; 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-38518-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38518-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7BA921C235C8 for ; Thu, 25 Jan 2024 11:36:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF2F658AA7; Thu, 25 Jan 2024 11:33:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="av+QYO+S" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 8AC8D55C3E for ; Thu, 25 Jan 2024 11:33:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706182392; cv=none; b=J6TS4Kd1IylkbwlGpDM3U2T3r1TgAZImo5D1DJb16IDd3BmJAObBsOpEyliaZggzUYrW/nuWiVJ9CojHe9YBeWcrBFZlMcxey9guWANdX1kA2fHvLOMetKme/YFfc3Cy3ZgxOSw7aw6P7cXLTXEOkEeyyeXlRXph+LQmuzwAJF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706182392; c=relaxed/simple; bh=0byiLPnDWEQfwFYPOageH65AoBGROCIbfIjdgEIOffg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qYKfoj+o2vS4KjcNAUuqZA+/qn1CvE3hcEPVMK+B/Vt5HWNIzR7pb66yaHplextg65YCpvycSpTG088PdG9mdA/4jM84NpCvBFiMJqoSPpEL6OUYXasPahCm1PD/ls++jGl1mftf4QxMnuYocCoj450bhxTOBdsXwSnrfRNko/k= 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=av+QYO+S; arc=none smtp.client-ip=209.85.219.202 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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc37b0ac33cso4472739276.2 for ; Thu, 25 Jan 2024 03:33:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706182389; x=1706787189; 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=Vu5UpmPKB2YLCZqvfGM/x/cMDohVrJdP/wVfbDfAQyQ=; b=av+QYO+S1Ypn4bbQm60XaJny8/I4M0doE43MnICJrrdmJvb0Mb1FrBppM6mJCTCyrs pdJpCQjDs2UqTdbuvnI4hdL3n5+qE5heWujv5qBDWibzy8RaEp4UJk+VCUluGFdahg6W 0CtKZnVW+YkK9Gcjj+wdRrdSdU8h1E3gR5pj54z9PHa37kpywZBd58xgfZ3QZ1VGT4xA XEwekOrgB2LYWcO5Y4rJY4ZCtNifrH4JTHO/EOZj8qU6xD8Ain5g6b16pbPilz2GIHUq 1StI/8LQNN3uwqjHZMwQFm7UcvvHFbgGYBXZNVQPaso2UlcPSwJTsHCfQB1voIDL/eeY YvlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706182389; x=1706787189; 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=Vu5UpmPKB2YLCZqvfGM/x/cMDohVrJdP/wVfbDfAQyQ=; b=T4I8P75EculdxZjF4gGpDLsor80RT8s7YnmnOB8pBfmgr6dUmvty/MlbDhE9Mg8iAv Lgn4cNk2/W9Q8NwuDeCY44yr8YFKwDkV/Oy/uJFXTPtU532XXfDga5t/XzBLXpwcxrPy G64Zq1Ayv+uQRoRTIKirJuUKXe92mWJViUadhXWRsLkylgD/My3TaT7Nfa9wl69EMZMy 6E/H0I6mIrJptFoRN4GjJtqQSZ3R9kaPTt1SZ/izMrE2Caom4ggYNMD4JHFP/nKuZNT/ GhSPCp7E/PphRfhCa/eKgwBR+8/EIMkntJYJtigDRPlJm/8Rl1k7I4JNyERfVqnDRiXV ARqQ== X-Gm-Message-State: AOJu0YxMPwTKZTz68lHJeAvPoHm1vQLJKobRAEc0jxnALmPAVi8zTKbf Kw3rKWyuTu9IXpyQ3/3pD0OjBqJQNzuqIln8BS3Bt+xRrXpQSOTFKoqsa8Jrl6+B3kPY1Mk+fH3 Dz/SXQ6zPCx5xECBm8YyDbzrhLlURhm42kdl94xgqL64yNFB5dRScr0fyFra995QOYzthao765S u0p+72saz4Gu+wMGFUnBvpmrjdGENZsg== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:1ac5:b0:dbe:642c:2124 with SMTP id db5-20020a0569021ac500b00dbe642c2124mr453115ybb.0.1706182389569; Thu, 25 Jan 2024 03:33:09 -0800 (PST) Date: Thu, 25 Jan 2024 12:28:33 +0100 In-Reply-To: <20240125112818.2016733-19-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: <20240125112818.2016733-19-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1898; i=ardb@kernel.org; h=from:subject; bh=Hd3xYUTi1QV5SlyH4OmfppihXDWH6zHA/zraGYWG1jw=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXWT6y/2x/MP/uz3CVv7baNn60+dbbIHuA/9mfjj3f1fR 1/P6RIq7yhlYRDjYJAVU2QRmP333c7TE6VqnWfJwsxhZQIZwsDFKQATmaTAyPD2+pa2Dxbsd/fN jrsvvvyopfMmqYBp+f8FDP72z02YFf2V4X+B2iyJ35HcJiKreLw4Tjw9tO5KjeqymsqthxJdpnt 0O7MAAA== X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240125112818.2016733-33-ardb+git@google.com> Subject: [PATCH v2 14/17] x86/sev: Avoid WARN() in early code 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 , Brian Gerst , linux-arch@vger.kernel.org, llvm@lists.linux.dev X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789062111365732165 X-GMAIL-MSGID: 1789062111365732165 From: Ard Biesheuvel Drop uses of WARN() from code that is reachable from the early primary boot path which executes via the initial 1:1 mapping before the kernel page tables are populated. This is unsafe and mostly pointless, given that printk() does not actually work yet at this point. Signed-off-by: Ard Biesheuvel --- arch/x86/kernel/sev.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index e5793505b307..8eb6454eadd6 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -698,7 +698,7 @@ static void __pitext early_set_pages_state(unsigned long vaddr, unsigned long pa if (op == SNP_PAGE_STATE_SHARED) { /* Page validation must be rescinded before changing to shared */ ret = pvalidate(vaddr, RMP_PG_SIZE_4K, false); - if (WARN(ret, "Failed to validate address 0x%lx ret %d", paddr, ret)) + if (ret) goto e_term; } @@ -711,21 +711,16 @@ static void __pitext early_set_pages_state(unsigned long vaddr, unsigned long pa val = sev_es_rd_ghcb_msr(); - if (WARN(GHCB_RESP_CODE(val) != GHCB_MSR_PSC_RESP, - "Wrong PSC response code: 0x%x\n", - (unsigned int)GHCB_RESP_CODE(val))) + if (GHCB_RESP_CODE(val) != GHCB_MSR_PSC_RESP) goto e_term; - if (WARN(GHCB_MSR_PSC_RESP_VAL(val), - "Failed to change page state to '%s' paddr 0x%lx error 0x%llx\n", - op == SNP_PAGE_STATE_PRIVATE ? "private" : "shared", - paddr, GHCB_MSR_PSC_RESP_VAL(val))) + if (GHCB_MSR_PSC_RESP_VAL(val)) goto e_term; if (op == SNP_PAGE_STATE_PRIVATE) { /* Page validation must be performed after changing to private */ ret = pvalidate(vaddr, RMP_PG_SIZE_4K, true); - if (WARN(ret, "Failed to validate address 0x%lx ret %d", paddr, ret)) + if (ret) goto e_term; }