From patchwork Tue Oct 29 18:39:01 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: 13855293 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 2E550205ACA for ; Tue, 29 Oct 2024 18:39:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730227166; cv=none; b=QeZKXF35Wp55/YUCl5UiDTpd4Lh+Y/6/MG3pt2P+DzHk/d+MZOmFF2iJGXKw7GxS1VkyehVnfVVXMk5AGxZH39jlyrUuyHBybhc9HDqhEcR4S8WvV928NoAJpE3KfOXMu/ymMn1Phs7iL5JbuP+W0569diVxL5sb/mlOmHCWtaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730227166; c=relaxed/simple; bh=QIBlHzKCzpo0A0kJ+Ne7rtACUMRu45enr6WWGFjIwAk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=q7AV9rp/pYcbjUBNx9EMSDzhsf0fRpwU2SYtx+WqKcdI55a4wmAlq5bI7yIJsO9tz9J6hZ87P+VLBWzjWRg9ZrbIH/6JkhLpmrSXQIXNIw2KQqND6PoOYwYmb/78UAbtrEEaNY0Yi/RtIn/+DhssUho8Kc/WXUGJh1spLOE3A7E= 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=SqTi43EB; arc=none smtp.client-ip=209.85.215.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="SqTi43EB" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7eb0a32fc5aso4821668a12.2 for ; Tue, 29 Oct 2024 11:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730227163; x=1730831963; 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=VFCC0Ppe61h9DsEPIrRB8kBdqdokYkAqWCjQxVIFEok=; b=SqTi43EBzhbBEaikAKhXAWIi92erJVOUziaMhvdfklP6BU8s6toluwp8qzFzoVUpXI BIvjyJGxAi/13Zcycgc3uc44yBtGZetzVn+TwNEhFTHwRxHfu5NSfH6S16IBcu2AlIZv O8JSFb4MpK7mzUCdauto9UDmnAWPUt4IJtC8/sdXvSG5HX5nzsoP4qmNDeKK1GjmeK7g AzkX6YxyE8tOZ+1SmI+B77Tz0I8CxJgFF0pw2TZayKzrWSoFy+UjwV/P40vP8aHbXCs7 xFM2vKewXkns2FZG6IwHfPbmgz6W4mPtIC8QNsjr5n7ROFHpjcm2Q1wQBbaZcDGGa1gk 9PMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730227163; x=1730831963; 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=VFCC0Ppe61h9DsEPIrRB8kBdqdokYkAqWCjQxVIFEok=; b=aS/2e87Ia0oLal2or0vyCjw7PJOTg/qjYC46CZSiqMjFGVD5/nAyA9iYWLgbItmuSz M3H8n5ZlTS8y7WGRDGq1vraDeA54jQCPRtNRt14zhJb4bV7vJKLnM0PSQw5k0MEdGERM 4iuGxDzRkZ8WJQcy49K17quP93P/B3flatkqLG/KrBvraXyEg7Tx83J9BfmK+zVhM2hj uHmwCQPNu3oO4Sg4HxmiAX1iQSezRuvrnHwVQQ60MX5ZBGww2tW4VbPlz5i4V3W3EAj0 eDXcxB7UI74O1c6rW6rMgK6Hovp5fLrHQjPDwNPA/sr8ALv35YD7nXauKJ6UZiWqWrJY stlA== X-Forwarded-Encrypted: i=1; AJvYcCWMlGVzZnBPXRHSTJtcvbkcTfBXLXUNCwrBmhK6Wpby7NG0fgHDyJ8RNtGbSvuQWQxF61s=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9KWHf+hNrRFr9kvZHAD3Ia/ZxVzaSVpzxa6CG/icx/OYaPQGc 4XK+ZEHPpVCo0dqHKiJ+i1CshL0SQO9HcT3nfvgdUBkTOusA3OCmXulXqe+5IilWRNINteQ5hDe QTPBfEIufX/xt2GOTVsASOw== X-Google-Smtp-Source: AGHT+IHX5lwAS9LIgoFFUtnChrdz7z7B7bwmI4NPfhehjIuR/74lymdkTB0KkRffRLZp83XLD8FH6uu+JFCbE/BFSA== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a63:4f62:0:b0:6d4:4eea:bd22 with SMTP id 41be03b00d2f7-7edd7b857bfmr21710a12.4.1730227163130; Tue, 29 Oct 2024 11:39:23 -0700 (PDT) Date: Tue, 29 Oct 2024 18:39:01 +0000 In-Reply-To: <20241029183907.3536683-1-dionnaglaze@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029183907.3536683-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241029183907.3536683-2-dionnaglaze@google.com> Subject: [PATCH 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" , Brijesh Singh , Michael Roth , Ashish Kalra Cc: Dionna Glaze , kvm@vger.kernel.org Ensure that snp gctx page allocation is adequately deallocated on failure during snp_launch_start. Fixes: 136d8bc931c84f ("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 Change-Id: Ief6e728d0c859c24a286d8a7e49f9ad2eb47b889 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 Oct 29 18:39:04 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: 13855294 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 E4D0020513C for ; Tue, 29 Oct 2024 18:39:34 +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=1730227176; cv=none; b=af9tWVY08ndCnN0ACd8PYrMIfe+V6A42JIBbiDb6YtgrvZGOP9SCJNXsamh7ccrWhaBOu9r6Iqii0jst8o3GLPbBztEKrJukhpIVzO3Q+x/zc46kZMaud4rvXCGnkb5i3NrnR0Pz2RF7MqjqBqU5wUxI1LJEMBQjjBXK+FgGd8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730227176; c=relaxed/simple; bh=vT6UGaJCAHZQdweFlVmqsA0PbWlxvJ3lJa2y/UVhQX8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LWGvV1fgJS81fL2k/WlH8V0lJQhSqq88OGxnElk8p8iJzOZvy6LMcIjgX3PNpXhNHrjvvyJTvoWEl2e3RA79gWPU660RfaDw7McDA05G+dykB0xKzQu7rfj0gTtxCbm8zwwbLG95SiUTgiFuxghUZPTRhFBlQ7EITM2r2tc6dhE= 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=naLAa5bg; 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="naLAa5bg" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e30cf48435fso379239276.0 for ; Tue, 29 Oct 2024 11:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730227173; x=1730831973; 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=nIzbr7zBh90Qk+4L+ha95UM8CI0cs/ioObBQO0IhCVc=; b=naLAa5bgLcbKMaCyxJL+Nk58kSjrpEZB55UkCPYiUF0D3oTEukNrBNOk9kbbDSik5W oMrNqoP3Kgv/PbihZNb9efcHZ1dhM4CBiSzFvNlaAXwBMbzucCU7jD4h2esMX//n1Shp jPZwXQe1Tnh5muCk4nFBzG2XGiANcXsv76LPoGqc0hJOPm66AFvEP+fUJ8vK0TW6HVkT OFad+j7/lcjqQ5oB6owpaJX2G9L763ptvvtBzla4TGTrW8kS+zrXiJw7xDu0mf1v/5YT 0Rwz2xQre9yXStaPPM9w/frQyqx0z67xrVXyxz4Lf5qMcAWI1Yenqwdd8nK1423BbsIo wLbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730227173; x=1730831973; 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=nIzbr7zBh90Qk+4L+ha95UM8CI0cs/ioObBQO0IhCVc=; b=LMeF7Iyw3K2tPYmTGv/YESQUjQZt9fCOOaYhWelmhGjeIT8WNaIvSQ9Nag5Dd+G7aU 91Oe59mRnid496ZPeIaoMFKACG5miHpkF/Xvfb9O13KoYH1iZP6uPnC1OiurWW62nCbX h+ogfIvY2crlZvU9spcKVHM7LQcqCCNDXLBTXe8SYmdazxUOJAzaaXVe2VzQUD122l0l STxIbD+tuJxJR4QI9YgImg36/uDUqi7ZwjIbOS6B54CTAqfflwtdS5apCgTWr4zDhboi Kob2h5su0SXZN1Gdd8ntsvIl5q5TJKh48ZvKFZIhiPna6VviiZFv7OzraZwCLuY4mt1p ekfQ== X-Forwarded-Encrypted: i=1; AJvYcCW0Qx+ED1TMuaojVphBGY2yuInFa0+AMfg9JL9ql4Qmi9SeejALM2rwKSNGdtaFWdYDkn0=@vger.kernel.org X-Gm-Message-State: AOJu0YzljERLeD4qhn80TKGw2ipxkPhvapAAUeDJ6lOQG97hOrKqiB8d /FaA5PLtVHnGDGpsMzInEIxMk/R13JtD4s/9hX/w+/CbCTtqADFTgmcdIwHGYWLi7WMyEKSF7io cxyYWgAlkTaZSN9jF7df9yg== X-Google-Smtp-Source: AGHT+IHSZ9z1gKFuoLjow1B8gxL4DLpvVpticofCNjquLeMSvisfqXyLo4Rn8guu4cbEwZ/Xr0RyrrNg9xIAoplbLg== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a25:18b:0:b0:e20:2502:be14 with SMTP id 3f1490d57ef6-e30cf49aefcmr320276.7.1730227173530; Tue, 29 Oct 2024 11:39:33 -0700 (PDT) Date: Tue, 29 Oct 2024 18:39:04 +0000 In-Reply-To: <20241029183907.3536683-1-dionnaglaze@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029183907.3536683-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241029183907.3536683-5-dionnaglaze@google.com> Subject: [PATCH 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 , 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 Co-authored-by: Ashish Kalra Change-Id: I3efb5fbbd0da05ab29f85504a86693f5cdf49050 Signed-off-by: Dionna Glaze Reviewed-by: Ashish Kalra --- 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;