From patchwork Sat Nov 2 00:08:11 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: 13859837 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 2F21B79C4 for ; Sat, 2 Nov 2024 00:08:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730506112; cv=none; b=HBegGcc4TJxd6sNPNVUBfrWwc1InYFx81f284F0AFvWIiQJeDojJ6z04rXipvToBOUvJd6qqgq/9J87Ie9LpO8b6KMqohUObYEV/QD7d8QhuDzg42mQjsjICPg9e7ZPbKY54OnEo54UZ4z0CVxgRSXrprftoNJj2dt8Yv2XtpGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730506112; c=relaxed/simple; bh=Rbij4r8cylGhkgGUg7WpUGdpkZboGKcsQk69ga17bxA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RMytTLlXda33BNvHH2NHMBgNmECUzDWTM27WCGtnur2SHDqFrHOe/slvIIYJBUjcvCwE2h/D+vfFnZZ07imARto/s2N+Ia/uSnexFWQwhU+r+Zizt8mCAzq1ZrqtmGClI35C9E39ODjXcXStKbND9Q+rwKtwBKhcwe6VjrQ2yUA= 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=ik1LXbrV; arc=none smtp.client-ip=209.85.210.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--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="ik1LXbrV" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7202dfaa53fso3516388b3a.0 for ; Fri, 01 Nov 2024 17:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730506110; x=1731110910; 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=9t5+hAx/Vx0CBMSZ/K4Xo8KI8HClXDiTkRfLYODx8EU=; b=ik1LXbrVNQnsgWF6rbrOsB8r1t9Gfuqn7z+m2PP7e4ivIj4Bob1HLqB21WmcEgy4jb kZvi3HBwzGIn/JZMD4iYTe3++hZbHqVhBJc42zq+88f/3ORi1SxS7lMWC1zTWtgu7HZw nMaat81114Pw545/9uP4UKOBuiiToVpWYiNWO1xH8P7wSSr5Xkr2E1zjh8SPy4ylTB+q legvHK+W2A4/BkfVRQyUH+vT78j/QK68AQK0F0YRf5dsJ1nULKirFzf37pRxKt7/AOPB QZC4iCYdy2nu/vfGBJYM8DNJvZkj0WFWXcwrJXQfF9lMivlXoweT5fQfIjejH0hTpayB B8+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730506110; x=1731110910; 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=9t5+hAx/Vx0CBMSZ/K4Xo8KI8HClXDiTkRfLYODx8EU=; b=sIg/4ffHT4QbAOLzBfcc9ts4a4t5/XP5Msn9qvX5GnQ5G58ydDb8qE9lCGNSBvmsQg SO588f7Qn0HxRhyNMOJhe4t0tltEbTYtrU4uSEQIrtewB2KYLXRS5TTK31oENxhRr0ST 9HX+mlm0w1j0n0VT7xjdjjgfLM/Xvlo7cpImMebRCy3r/nTCB5vBaX8JQ6KmygJGEbjF MiJsRXAMSbz3/90PcWU55/x7Mn5VChFuupeC158sycDz3sv/WVcz+Yl5Vpb3P9bBajEY 2wnm4lKTj1qhv34oBWB0MSIS+dD5WzmT4jPmg2LWLcNKWSlqbwvGyJnM4BWdRsEkYfHY 9uaw== X-Forwarded-Encrypted: i=1; AJvYcCULhLdtof9u8yghxZ2uKUI/V/qEKtUukf5/Z04FnMjgTcTV/SCay3+Uz/wEsg1WcduNV+c=@vger.kernel.org X-Gm-Message-State: AOJu0YykNRt28mVpqy8yk0ZEJWtgwOB4+K8UORPrPM6W4hWHZ1t8q6+9 SzqGEUks+GuPwGmJ4MVf4kKxrPzGlXUg37giZaRK5yKcPHf5tBhKX1BHG7K2efun/qk+EoLaZAn rm2Vr/3xDmxvbQ6weP4Dt5w== X-Google-Smtp-Source: AGHT+IH0e3GALuKo0D69gpU9KNL0giGzOcfcFha1VASPxW64ZNHEOxXwwBULM49bCwY2pfhwLl60b9qTFoYifUuHZQ== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a05:6a00:600f:b0:71e:5879:689d with SMTP id d2e1a72fcca58-720b9e7aaa1mr26792b3a.6.1730506110334; Fri, 01 Nov 2024 17:08:30 -0700 (PDT) Date: Sat, 2 Nov 2024 00:08:11 +0000 In-Reply-To: <20241102000818.2512612-1-dionnaglaze@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241102000818.2512612-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241102000818.2512612-2-dionnaglaze@google.com> Subject: [PATCH v3 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 , Ashish Kalra , Brijesh Singh 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 , Alexey Kardashevskiy , 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 CC: Alexey Kardashevskiy 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 Sat Nov 2 00:08:14 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: 13859838 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 A78DD1BF58 for ; Sat, 2 Nov 2024 00:08:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730506120; cv=none; b=MT9u64YsDZUs/4fjc16n1q8OXTReOQhiQTns3OgBnmNAIa0ndwnn1jFoXKz2J+CNpU7MIBx6VbXqEIot53vAxEk3/ri3NpHzjyGoxHxRs2qyrpBmBO7b4RB6ZwvGtvAiKHDjAnXbGQh+3tEhK8UWCyQvOCk9cRuOKaDvJ1CmEi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730506120; c=relaxed/simple; bh=qPFYuz9BrK2CIqbnqSJdveevoaimtQftTkcT6cnXqi0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nPRoClL4PgSnXHYLbPNtvXidi9it8BjVadmMlTx11Vv5ZKodwfp2cZFIthFxslnGEUSjcnkYZOfGzxZvNypUc+ngnjBmibj9Eu0Ui6H5n5166QJwrfec0p3jsSUMyzxqYc48PNKTs91zbnSzX2SizkQAFMenboWi+bTRkQzALew= 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=he55DuwU; arc=none smtp.client-ip=209.85.128.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--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="he55DuwU" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e3497c8eb0so33017637b3.0 for ; Fri, 01 Nov 2024 17:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730506117; x=1731110917; 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=OMflO0iOxZawpN5ZUgjewO0l15Uk7dsPv9bQCJvRKFM=; b=he55DuwUdUaFBDjvf39y10k+kx8Bksm2nGxi+fp5T2q283iHM6tE9acNq/cQDZKLd/ FDXq5cdNFd+zsez0y0hR7e8arC1zGs9Eno5voH2qYYSRd/0OJyTz2jRsWTbf/HhabItq akMlkQ8T17qttIhgQEPjDA4qazs+QTEIdTdKMP+pB/ZWmW1pZvPPzzNBCjEgXzZ1fMVs MQwW/n91QTinpaLP3xjaDOiEeiWTSvAwMUOCybeGBfCQcx+Nju7fngb6ZIMSOvqzjfOj ym05lS/8rZ8NGcyvWUygzkFHdj+b9kEaB2gCjDfQN7jPLh/jqCPE8praiegMgqPaSmdV 0Qcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730506117; x=1731110917; 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=OMflO0iOxZawpN5ZUgjewO0l15Uk7dsPv9bQCJvRKFM=; b=i2YDCcIFs/1rYwbNHFabgqRUb3f4EMBTig0h5F3w1Rk3xtNQS0A0JJMYZvhC7Cc6pT d347/2qu2/pMxeo4Ruf+nOY1YwRJf3VdH+LIsrtNFroAwWFov9BmnAAdr5nhs9Bm9f8y bKHPK2tAr0N56LBCzD0+qVy1Y3tcyKf2YpoF+PN1E56YAOhj8ocliyfsVym1zCyZZSIa daV/Kc7bD2VAHoEWa7D9qzVvScvOLNmY2tdKOuKR0aVyf1+tVaUkJ4X8efVM5sUeYhky +PlNoob68VmCyU2SWjLfooVDEnIefP2ESm2GBR2Qkl16clpfB7XTrI5DQN4tNzoX/6uk Tx5Q== X-Forwarded-Encrypted: i=1; AJvYcCXAKILQ0oPtsD8vinxrSSHd1KpMLgO/sIy3eMh3r1m5gd3SZUz4aAPtdAczakOzSomfm9I=@vger.kernel.org X-Gm-Message-State: AOJu0YwUsXVYqW0uS92fJxrT0S4RiDfOxaycJGoCeHaD9AhfytqaGjqA ZTbqUzn866pOr9Vlm2sqhJ3s1FK53qsk6JQwKBUx7Q17lYlpdrTHIMRX0nB9tNoRAjH7vsfKc3N 2Z6lr//XsGTXDQ6+Hnh7i3Q== X-Google-Smtp-Source: AGHT+IGk0DQ4lZzrHSF/msR4LceTfpO9UC2r93MoAUGhrBvpkJQaqubi60bBsN9z/YYJPlV+RQpFn5dca8i1rnQL/g== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a05:690c:6711:b0:6d9:d865:46c7 with SMTP id 00721157ae682-6ea642ec3camr940447b3.2.1730506117249; Fri, 01 Nov 2024 17:08:37 -0700 (PDT) Date: Sat, 2 Nov 2024 00:08:14 +0000 In-Reply-To: <20241102000818.2512612-1-dionnaglaze@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241102000818.2512612-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241102000818.2512612-5-dionnaglaze@google.com> Subject: [PATCH v3 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 , Alexey Kardashevskiy , 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 CC: Alexey Kardashevskiy 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;