From patchwork Fri Nov 1 18:15:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dionna Amalie Glaze X-Patchwork-Id: 13859646 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 3ED2E1A7AE8 for ; Fri, 1 Nov 2024 18:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730484948; cv=none; b=a5toMX44YN68YyFkvXK014ueqP8LNRmBn6osTiQLM/fv4iuVxsdE+c5eu+CyhF1Q6maZUg7uz5k7OYrADUYVclS2IZbaVkSeRJFN0gdEf5sQsLI/Nyegv3w55Jgjnt9k0OwA86BHBDc6cc8X6FIyOCcli4mTMjDWxiBWZ3MyHmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730484948; c=relaxed/simple; bh=FW8JHk3YGfbCYGtZ3Mzk1ogv3Mmj+0IgvWXC0ldYUQ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bdggL+NKQsjwjJaav8iIaQw1XVC1k9lSOZuCPH15iHPJhasT/p65+szzIK7gVSO3Em5vU+bkA+Bzb/w8rSZ/TUloF8iRUxgrbUy13p/fAqShdlhUnm5jYzEp3Cu+mPnjA/47gncv6hgEvYwzNNijXYTXYuMN4GdNzPucuTswlK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dionnaglaze.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ojTOAm7Q; arc=none smtp.client-ip=209.85.216.73 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--dionnaglaze.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ojTOAm7Q" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2e2ed2230fcso2694392a91.0 for ; Fri, 01 Nov 2024 11:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730484946; x=1731089746; 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=q2bdkQ9H/fP+Nu98WcPEJqY3qMdHmveh6b6/XkHLIus=; b=ojTOAm7Q/67hxd1hadg8fwcoe3tq1AjHqUYDrSsV9R+uyueMTB7o7m720sUfKoO8Mv 8FWpNgonoXBf3lbQRJwX4afJQzJ0JLcs/XO3r2WQc8YE2Ko1+62hKWQR7UDOIsRiAPjQ PN9UQ2nHM5Ti6889Z5xw0mfDCwIxzNYMY5ZGpRO7NjLG/t37z/mhfpaRINZT45+5Rz0W NnrCE6Ow8k3Kp6F2sij2dgPxGUxhzyiTYDQ1IaPosuIOqM+wcqXL+eu12/smOB0Krb94 DcFClmg0uLLZe5rj7DkQZFUAtGfGCeqWgwJGlIixaDNFLzfxJ6gTVBMIMMyWZX+21ICZ vN8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730484946; x=1731089746; 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=q2bdkQ9H/fP+Nu98WcPEJqY3qMdHmveh6b6/XkHLIus=; b=OkL8lsqF8XE8rJ4+YiXrl7ROGNrrUOK7YXu8lJxegpaYr7PmzjPlX4aN7jXrMeya7o BmrwvpgnGwKNf0eLTv3hVlQMIdZpkepUIAClLkDtzB7znxIREhg7kdENBY7aLTlC1ZIX B33p0sliDyqcsjslP6/8PTIt4N91jIlWgMprQkHSThwtqSbDpxf9YdUAZn/K8zHINB/1 /fv4mJ2n+hEzkp9INV8yyfO2FzOdQanLqCKJBemYxGKn/36ST1as0idpQJnQI3v4PuZx PqJAkkUHplL7WuPKSIONAf0cnCHTQJ642rqJyJna5uLKIBJc0ieHZraS3cj3T2CRfnO5 hDsg== X-Forwarded-Encrypted: i=1; AJvYcCVh8obQMr8rQC5xQasjT32mYNTpC2re025S9XsXY3NDhR+dcDvKrkN5xPTMvtT4rSQaIWo=@vger.kernel.org X-Gm-Message-State: AOJu0YwXDJRyRLYRstDWaU3Y5ZlVq2ZD7SWmiBVgPtiKPFQVEMI4Ahob Qf0vkcJu76iq43khNSrvKMHSg9rmjm0zT0WS0ABqR3pGaPxlHJQyxMNtLfpA/J6ut6MAK7OPZzZ Cl3NMVYbmHBVSDP+6Zc395g== X-Google-Smtp-Source: AGHT+IFlwPuf/K5AJA0znbtgKqO2qjyZICURRqpIPVlJ0DxEHxgaCJsPPCi1KIaDOmrvJ9kcdz+yRyVUuPdSr5nT+g== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:62c5:b0:2e2:bad0:926e with SMTP id 98e67ed59e1d1-2e93c1c9adamr28528a91.4.1730484946570; Fri, 01 Nov 2024 11:15:46 -0700 (PDT) Date: Fri, 1 Nov 2024 18:15:26 +0000 In-Reply-To: <20241101181533.1976040-1-dionnaglaze@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241101181533.1976040-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241101181533.1976040-2-dionnaglaze@google.com> Subject: [PATCH v2 1/4] kvm: svm: Fix gctx page leak on invalid inputs From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org, Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Michael Roth , Brijesh Singh , Ashish Kalra Cc: Dionna Glaze , Tom Lendacky , John Allen , Herbert Xu , "David S. Miller" , Luis Chamberlain , Russ Weight , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Tianfei zhang , kvm@vger.kernel.org Ensure that snp gctx page allocation is adequately deallocated on failure during snp_launch_start. Fixes: 136d8bc931c8 ("KVM: SEV: Add KVM_SEV_SNP_LAUNCH_START command") CC: Sean Christopherson CC: Paolo Bonzini CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: Ashish Kalra CC: Tom Lendacky CC: John Allen CC: Herbert Xu CC: "David S. Miller" CC: Michael Roth CC: Luis Chamberlain CC: Russ Weight CC: Danilo Krummrich CC: Greg Kroah-Hartman CC: "Rafael J. Wysocki" CC: Tianfei zhang Signed-off-by: Dionna Glaze --- arch/x86/kvm/svm/sev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 714c517dd4b72..f6e96ec0a5caa 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2212,10 +2212,6 @@ static int snp_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp) if (sev->snp_context) return -EINVAL; - sev->snp_context = snp_context_create(kvm, argp); - if (!sev->snp_context) - return -ENOTTY; - if (params.flags) return -EINVAL; @@ -2230,6 +2226,10 @@ static int snp_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp) if (params.policy & SNP_POLICY_MASK_SINGLE_SOCKET) return -EINVAL; + sev->snp_context = snp_context_create(kvm, argp); + if (!sev->snp_context) + return -ENOTTY; + start.gctx_paddr = __psp_pa(sev->snp_context); start.policy = params.policy; memcpy(start.gosvw, params.gosvw, sizeof(params.gosvw)); From patchwork Fri Nov 1 18:15:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dionna Amalie Glaze X-Patchwork-Id: 13859647 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.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 7696E1CF286 for ; Fri, 1 Nov 2024 18:15:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730484955; cv=none; b=HjkEN2f0h98VNgryj7r0BNb6XUWxL2JrH89uS59VfTBwNTm2aBSaxyd02uyHG2BbeeP/2+/86rqutcKH5uKexP96lUpdho771t3nO5AU4u4cTLGGT8ZNscme/jtpIHQMw+tC4RMmZvHHK0broxo6vjtDS6CJrS74YtqZm0DLADM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730484955; c=relaxed/simple; bh=GSHbBwZfkYhqvZmnpUSaXG42ezayg8nwJR7cfig/aho=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OWsxoJKt2iK14p93d2fDEockK5wA1SkxWQ8kdT5nHDPGA7N2E41mCBA6sH7hzUGhoMYzoaz1qO4roLEQL0FC99fUmBSjwyxqLMfDx39jbB3bgS9HYQ3juFPkWWke6Jo4wmmu5NKK/2jdY2Qp1YOMBhXix6DDvrb/sCHGKIg3d0A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dionnaglaze.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YpTHgRMA; arc=none smtp.client-ip=209.85.216.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--dionnaglaze.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YpTHgRMA" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2e2fc2b1ce1so2545555a91.0 for ; Fri, 01 Nov 2024 11:15:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730484954; x=1731089754; 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=MEZAnkCadaVg1BrSWxgRmpQSE/TbQcmppmH+q7yf6WQ=; b=YpTHgRMAdoZAKkHFfRpC6r90RhqV0TD28pXPHSyTRIlrKLTuXKZA3RT+jLb9A+siZ4 itulhAA4Yjk+kzxe09vqyvG+OEq7iV0EnBEVNxzKrEbxzQZC/938l+ci149VTBvIPzrZ WAdZvDFKD3rZ9oo0vWUfuRMl+Fo2dm9oSesxWg1OPy51yZFdw1Ixsum4ha8XajpBkvdM up5Nzb6a+F9Ald2mzE81CzXdkQD9W64EIhqRu1F/trpWNTL7XHuM32xDPM3YUOXOOUt6 TZ+xEJzh9Ma9CAKccIYa/X2HUnBc3O0461XALm0ivGX5ZgXEcfQBMdbjRbmbU2UojZWx x2kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730484954; x=1731089754; 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=MEZAnkCadaVg1BrSWxgRmpQSE/TbQcmppmH+q7yf6WQ=; b=qRPdkYvcD2ctmIWoy6KX2y3LsqGmvL7NMXQLiHYOc+6oBu21DTP/v4kmQ/kd5x7W6o zbqe0orQcqtwjHGsGQF17DSk99aPAHK3Sr6dItplD4K4/oEtE6lyshEfE4foz/szy0KK E+mpw9PbW/iY764gWCbVV6iD/fk0gFaw/dOLSfptVyEjywGt94xSJRIPZ+M8kN+aLA1Z MtfsVRVwDOME4onpjdc3FpF5t31bQ1BtbBnhHyqoi5VSqFIiXIFp8z8ukHVnD6z8jpsd gWQeiNax2B4owytBEVZcj+t8GL05Lw2l9J3u+Nlu/HwwUjuhrOLonnHthFBX7BQpJH28 8Njw== X-Forwarded-Encrypted: i=1; AJvYcCXtEYjn0vDpTPLG1Bucws2Y2yz+mnRqxDd/6Aa9FYmECqi4LQtYIdazo3WxYQDh6PufS2Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzaGoDFGcd9Gb38ElQIhO/UdVg4l+g2Jv8fmmG4cOy62QatJjjG OEErfRCoinnoT6oTGjlO9YFxy/qp522QijBpF8n6rClpa2U9+yuNZl3tESf2vRoF1u3EQT/lJNo S/6oRqFGV5Lyr8rQHgY8dew== X-Google-Smtp-Source: AGHT+IEXa+QnTPnVNgHoaewOLlIH8wFAnb+M/ihAEAGqYML1uHaPbaA1TFQ+R1PS5raQE1UTHGA6cnlOKUra43n49A== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a17:90b:616:b0:2e2:af52:a7c3 with SMTP id 98e67ed59e1d1-2e92cf4f915mr20243a91.8.1730484953636; Fri, 01 Nov 2024 11:15:53 -0700 (PDT) Date: Fri, 1 Nov 2024 18:15:29 +0000 In-Reply-To: <20241101181533.1976040-1-dionnaglaze@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241101181533.1976040-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241101181533.1976040-5-dionnaglaze@google.com> Subject: [PATCH v2 4/4] KVM: SVM: Delay legacy platform initialization on SNP From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org, Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Cc: Dionna Glaze , Ashish Kalra , Tom Lendacky , John Allen , Herbert Xu , "David S. Miller" , Michael Roth , Luis Chamberlain , Russ Weight , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Tianfei zhang , kvm@vger.kernel.org When no SEV or SEV-ES guests are active, then the firmware can be updated while (SEV-SNP) VM guests are active. CC: Sean Christopherson CC: Paolo Bonzini CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: Ashish Kalra CC: Tom Lendacky CC: John Allen CC: Herbert Xu CC: "David S. Miller" CC: Michael Roth CC: Luis Chamberlain CC: Russ Weight CC: Danilo Krummrich CC: Greg Kroah-Hartman CC: "Rafael J. Wysocki" CC: Tianfei zhang Co-developed-by: Ashish Kalra Signed-off-by: Ashish Kalra Reviewed-by: Ashish Kalra Signed-off-by: Dionna Glaze --- arch/x86/kvm/svm/sev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index f6e96ec0a5caa..8d365e2e3c1b1 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -445,6 +445,8 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp, goto e_no_asid; init_args.probe = false; + init_args.supports_download_firmware_ex = + vm_type != KVM_X86_SEV_VM && vm_type != KVM_X86_SEV_ES_VM; ret = sev_platform_init(&init_args); if (ret) goto e_free;