From patchwork Tue Nov 5 01:05:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dionna Glaze X-Patchwork-Id: 13862235 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 804991862A for ; Tue, 5 Nov 2024 01:06:14 +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=1730768776; cv=none; b=prpPPLpq7+S1ogKW/l44XMsc0Or9LLEv2+PEBJwhoYqAVDrD5SLs+kPONOc6dJNyv8TKfFeCKu8Lj6M9PJlMfjt9HVbj8ViwBct7OgpOfwpGnq4969vzWraIpxp39I5xz/QK1vks7yuCz+Wdqf92NQjJ6b1K9Z+RfirUnjMS4h4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730768776; c=relaxed/simple; bh=Kzdi0RzTuVT4R4Dg9LFcvCPoh0zzneOm7NKP09EYwSU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Dm75CJmwKyxhOn+jFuVdD3MBZfrFQP+f2DpSkyzUNZaep+PNvmYuWMnNu9s5YejycI6xgjukuI3geVqCDFVuSHTjmWIPxCAjCK5y7WpF/NBEqs/TkcdnPw1bwT/F/DJdJOlB7OiWlNb+9vaXN3zaVxKhSmcYu9oLqm4TN76EtAM= 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=EfbKMEEW; 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--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="EfbKMEEW" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e292dbfd834so8329018276.3 for ; Mon, 04 Nov 2024 17:06:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730768773; x=1731373573; 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=qpDF7a5A3aTccPubMOlN8ORp4a2Anb2LX7mvFNgWFxg=; b=EfbKMEEWcow6Jvv5mrxOBXcLAZ6aoaGeoGn+baLceRIAlgpoXYGT8AGglxvq+IPePy WmsrVJBak1eLT0yO87SntPZ7GFbb94c9S313Jx9zr9bqq/Hfg1OSFOnSGyLhf+AeT1uj SnxnrtDgKa0ffH0lH3qqGSC1PZXEV3JwzsDD+UlO54XwhlgRXNKT8ACcmQ4fPJVSSN5r j2ypsf/upID7pMiezDWBfqK/mCNVPtKsQCN+f/Bze1JhWd++tnMlaxAThGNz27JqG+zi 7apyfTXQfWV1qTFuz4ZyV7kUBwjyKHciyzymtFQout1+t5wpO0V/HtIvKIRREdpGoqGB at8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730768773; x=1731373573; 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=qpDF7a5A3aTccPubMOlN8ORp4a2Anb2LX7mvFNgWFxg=; b=H5IqaIuAR4/sSDxApahculzg7dD2wIpk6o8bagAa6gYTpCnPOizJc9ltMehdoptYRH GkGOAVqcujipgbRoiQCCbUxMQY5KKuyyMKde1T+nfynZArgNxG6xvL8ZuH3v80Odyo2B 91psXVdd/FGyARXepqmHc4D0vGRJt3vCSAvqbQFNSaWFSJFZBuaZ7At/z9/THcGeHUrw 2710biNTwUwgVYadZrjDZNQcSxbtjhOOmCx+27eVEf4LqkS90GPJlpybIVpmnV5FmW/A /KH8lPifitNNS9apOzT8ppXZ5OrbgsLz7bA+HCttFgbd+UVa3E/zmyx1+H44pYkmeWEg gYqg== X-Forwarded-Encrypted: i=1; AJvYcCUAWMb9f0PJgLS7X+zz0sreC7JWNWsSTUoSdsehpN9p9XDeWiAD33L2pWQw31Lb5nUwbos=@vger.kernel.org X-Gm-Message-State: AOJu0YyPg0p2xJgbhdXe9UOi7WQ37Lc6plFsIl8PsweWD0pGHxIUHSZs iZpS8udKpVwlwU4Y1F8AWCXK6LqSpL4CUakD1dSA7/73Ffz/yqL2fGkHIPi32SVeQWoDUAxT/qp LlRgeWYvxfE5RDB0yQlvYtQ== X-Google-Smtp-Source: AGHT+IEQ3QoZttD5CvPaZEByw/wYbzenHWOgazcrDI8nLp1Wph7OSasa8It4OvkgM6y0uzeLKTxOeD9HcmMY9/BBsA== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a25:d695:0:b0:e2b:d28f:bf28 with SMTP id 3f1490d57ef6-e3302537c7dmr18862276.2.1730768772981; Mon, 04 Nov 2024 17:06:12 -0800 (PST) Date: Tue, 5 Nov 2024 01:05:48 +0000 In-Reply-To: <20241105010558.1266699-1-dionnaglaze@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241105010558.1266699-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105010558.1266699-2-dionnaglaze@google.com> Subject: [PATCH v4 1/6] kvm: svm: Fix gctx page leak on invalid inputs From: Dionna Glaze To: x86@kernel.org, linux-kernel@vger.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 , 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 Tue Nov 5 01:05:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dionna Glaze X-Patchwork-Id: 13862236 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 BF99052F71 for ; Tue, 5 Nov 2024 01:06:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730768788; cv=none; b=ACOWVs2cLlD/CNGnRlQxst2e6Ib/v/7fGkwI+Lxs1TQY4y8qwX/vXxfzFqQ8lMoPv97E0FiQwBm4EaMYuFqiea6b4rOH22dzpQ0yVedLn62ihtWAfwpk0FnNquD1hhq1Gyg887D0P+iDwMaHZwPaHLsyMjP6RKTGFfyoSa4Acm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730768788; c=relaxed/simple; bh=PrkZM6Xy8UF0mEloWiv1/ygTi//WCDu6vFaQAcQxgaY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VBDv2dwMN8ClT8VFuhR2dlndCT7UrA+ZksEZ8sSLARij6AbsfnU8pvMGND6+G0Q+6uJ5GDyIn8hyQzKzqCZSdhfkLTdz3Kdvebdcb/yvgupB8jZWzO9eh+tdUNj30THxH4hDmZvWrvCfh0Yp8DotCQHUOctFTBPFZQLKMNDbIsE= 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=O+dDM6zL; arc=none smtp.client-ip=209.85.128.201 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="O+dDM6zL" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea8a5e83a3so41125557b3.2 for ; Mon, 04 Nov 2024 17:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730768786; x=1731373586; 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=JS3XxluJTES3Wiur3lmc4TEkrd8MuXF3kmtmu8pwE5Y=; b=O+dDM6zLw62e/tcs6Q7rF+NuDoPAnnY/2Vhfa9sUZQnZFrEx1tZTg7OjYSmGPvmwfw 44Q+9fdXv4I+kzh4ipsZ/mxRWwUMD6fvwFZ0bb9zIPypP2C7gqmfpRoab5ooLcR3xXZP vIaCaTeg1EPLv0ssuMoiL/C0n0CtBL/tNbdNdvXEBLQ1SfDA9pwdBRSBhTS3+jE5iKue kmx3o3f6EBrjXOrdbQ3Z4D8nuxy0XCbvOg9L9Kt8k71+f+MYcRkb1IyhvClDfPaSxbRG gTVZFTCAO3JLi0dbGhbTvKTQv0v9o9zDTjFz43bTzsBj6dRAXmi88JmOJdeeU2mfedsy zDKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730768786; x=1731373586; 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=JS3XxluJTES3Wiur3lmc4TEkrd8MuXF3kmtmu8pwE5Y=; b=O1cKUSrRTJcC3vS3QSEKub0rsw7OJbyMfdWTa7kK2D5CI+iKD2Orv4oG7LUoHeOkwR 5ffW6VB/0lleW88GbtU7s47M/+LLuwkhGPNSdr9G8+oIoqCKWu7mBzE7MYEKsrs6V2wN 5WHwdYNiIUqxiOEtWN6OewYsPysZp4SYcZO5LCCqNmQtP09vHJYmlJt+kFovS6hu1dVS jaYgoKzKIs+LgHIKM5cPdSCNdouzBkdquOAgCcaN8VdmVl/FgJVHZetcMOS7/oPuFHBI x8PdXE+SfEFtDDw+jK1ZoDM4Ck6pE/YtquuFzoKmxpylZB9mzv5lOZY1xaOF9+zYXkhU aqQQ== X-Forwarded-Encrypted: i=1; AJvYcCUAGL4Zng/sxEWIeYQrxMAKJCsGfpW2GMp4Pr/8fXAs6nuuOy9hfbhKAmT1boCP0M4eWWQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0IWP+OBkdd4sRr3mhBB0q5+ZNg9Ak1DZxYp7PHSFrrpGAmavn ttmn1EIy+LwXrJlzKHFDN1sp5Q7HcmjNMT9KIXN55Gj7L+UgylsDUh9aFI5ZN3JPep2PbrMEV+8 JQLxNkT9DpLB6LIPh3BxNBA== X-Google-Smtp-Source: AGHT+IFO2JgTdSt2JVSAlE6aLJiAl18hccyke07Vi/GlLOEcPNFzRu1IUPbLnPUPUc1RIzAgyPoMizpEQTsA/tZYFg== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a81:a8c6:0:b0:6ea:7c90:41f2 with SMTP id 00721157ae682-6ea7c904377mr279887b3.6.1730768785769; Mon, 04 Nov 2024 17:06:25 -0800 (PST) Date: Tue, 5 Nov 2024 01:05:53 +0000 In-Reply-To: <20241105010558.1266699-1-dionnaglaze@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241105010558.1266699-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105010558.1266699-7-dionnaglaze@google.com> Subject: [PATCH v4 6/6] KVM: SVM: Delay legacy platform initialization on SNP From: Dionna Glaze To: x86@kernel.org, linux-kernel@vger.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, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index f6e96ec0a5caa..3c2079ba7c76f 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -444,7 +444,7 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp, if (ret) goto e_no_asid; - init_args.probe = false; + init_args.probe = vm_type != KVM_X86_SEV_VM && vm_type != KVM_X86_SEV_ES_VM; ret = sev_platform_init(&init_args); if (ret) goto e_free;