From patchwork Tue Nov 12 23:22:41 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: 13873024 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 5DC7B21C167 for ; Tue, 12 Nov 2024 23:23:05 +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=1731453786; cv=none; b=tL0Tg0gfOC69oDxPFGdIlci2YnalbhFKjrpx4DII6aXLZoMvtBj2hdm1dRjTj49MzDeyTZTpSsJL7BYRi386t1w03EECAQ18UHIIGrotTaf91KQDFeE8vzTEsfCukyi7Ays23wkUlTT/b0PuW+IVS7rbcQyop3+Rh07J7mrjxvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731453786; c=relaxed/simple; bh=ayby78yQOyjOz6ls+yE5cxTfghhQvc3yyzZlL7gs+bU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BDtXmX326h82vlHRFk+en9FU9HqYq2Hwv/U7x99zaxTKRDVXOXwjrxDeXPsN+2Lnb849sIH2Tk2rJTyRaIH/AJq1gNRpGAlJvX3YkKNipkPjCuUoqyFc268HskQ0KC0yJPX3Xd8gI8bsVkiF7aj6sxSq03cnfXgYmIn6h5ydO2M= 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=vhSGDvqb; 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="vhSGDvqb" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2e2bb354e91so6498026a91.2 for ; Tue, 12 Nov 2024 15:23:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731453784; x=1732058584; 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=WmL++hD8fgHMSusvyHDFwqq57StgWysj/njcEHmccMk=; b=vhSGDvqb1dkZp23maJjOm0aVpI8AuAJy8zaOHGi1Ce2dLhI1Eboz1WTOohRMcP0xMS FpYWPLcJk8aZIKnmsjL3Y+Idv3Jwg4msGh++kQhDx1XRFcdbVsVDZA5oN+/zflE1UCiX wWJ74ulIO5b6b/NL/1E4UbVqHWAxkCRBllUGzNRfAjZQusRUKUCVAhsThbQJaG8Yo2C8 ebrQvVtea9tkmGTmNmFldRS+4bEjf3n8AHZZ5dVaM4W5zFfD1K52Q8CHa/uezxcLaUUR 0Q9S9jn3KpYAtPnc3H9qzU6X1eU2KMdSV1fsJXObLopapE/XjucGHhLY61A1yWwFFKiV g2TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731453784; x=1732058584; 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=WmL++hD8fgHMSusvyHDFwqq57StgWysj/njcEHmccMk=; b=ViJAk6bPjqjV4l1GEu6XYxWtccUP1NC12RTsJjsfeGbaROBS4Qi9gKssdM6DcZVUwl jAXJDPUDsiWJzT3RZd2ZXSHglE3EyHveRr0xCibvUeHM4zEuLv6VN6WQZ9l7dIM+daR7 KSnSW71Yej5rNTTONK2ifSJUFWH2X9SxRUS+DR7nhFGp0Gdp7zOjrO0a+opgZK+Yl/NJ d5776G2LhYTuz0Jngf9ht92dY1J8itQG1DqmMNBZqh6v58RsP7RPuKnNbIOMl3w1ytNV Y9/tWNCJ4wBhjHjoc8HDSW3j0bK2jkD+GB3mYPHvb8s7VFntCisLjzV6QSU5FOcLcFLn Pgyg== X-Forwarded-Encrypted: i=1; AJvYcCUPOBGhOjGfhaRTip2XHy6faKlNtJzhLnlRx3DHWB+Bwza0Y7vYkqWkwK6Ct7XiNvrU9XY=@vger.kernel.org X-Gm-Message-State: AOJu0YxkPnf2+kOh4ci6p5A4zQb+8IAAUKBcU8C8/4XAGh7tGdPBxplf +vSVhU6+MLEQFmZEXNBhZ8RMDEuYHoJwbUsVd2hxbkfRBMTO34hOsatyfSQxm+WxcG+YnoXp/RM n2jwdN06/SP23W0Ar4L3m6w== X-Google-Smtp-Source: AGHT+IEKIx/zzlZD9qfrCEEtWDHbsmZlYa32pBSY0nOxUmKrJ4QniZXwOwxKWzCDaGQhHEeyreWYnDeyUdJT3VYCwQ== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a17:90b:2ec3:b0:2e2:bb49:1052 with SMTP id 98e67ed59e1d1-2e9e4c7f1aamr70975a91.4.1731453784634; Tue, 12 Nov 2024 15:23:04 -0800 (PST) Date: Tue, 12 Nov 2024 23:22:41 +0000 In-Reply-To: <20241112232253.3379178-1-dionnaglaze@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241112232253.3379178-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241112232253.3379178-3-dionnaglaze@google.com> Subject: [PATCH v6 2/8] KVM: SVM: Fix snp_context_create error reporting 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: linux-coco@lists.linux.dev, 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 , stable@vger.kernel.org, kvm@vger.kernel.org Failure to allocate should not return -ENOTTY. Command failure has multiple possible error modes. 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 CC: stable@vger.kernel.org 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 357906375ec59..d0e0152aefb32 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2171,7 +2171,7 @@ static void *snp_context_create(struct kvm *kvm, struct kvm_sev_cmd *argp) /* Allocate memory for context page */ context = snp_alloc_firmware_page(GFP_KERNEL_ACCOUNT); if (!context) - return NULL; + return ERR_PTR(-ENOMEM); data.address = __psp_pa(context); rc = __sev_issue_cmd(argp->sev_fd, SEV_CMD_SNP_GCTX_CREATE, &data, &argp->error); @@ -2179,7 +2179,7 @@ static void *snp_context_create(struct kvm *kvm, struct kvm_sev_cmd *argp) pr_warn("Failed to create SEV-SNP context, rc %d fw_error %d", rc, argp->error); snp_free_firmware_page(context); - return NULL; + return ERR_PTR(rc); } return context; @@ -2227,8 +2227,8 @@ static int snp_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp) return -EINVAL; sev->snp_context = snp_context_create(kvm, argp); - if (!sev->snp_context) - return -ENOTTY; + if (IS_ERR(sev->snp_context)) + return PTR_ERR(sev->snp_context); start.gctx_paddr = __psp_pa(sev->snp_context); start.policy = params.policy;