From nobody Sat Nov 23 15:28:57 2024 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 DCACE21CFA4 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=1731453787; cv=none; b=AUxAJsbNs/NuJ9tO2Dg5t4s3BpH8yBksBa4qLPnLCxO/ZnFxPPFyzIn+gI/QICvBaMqDcYl9/5W5bFz4r1fCnL7JvdJJPGzIKn/IN39GxqSV/rHqpeuQ2ZeAHuBmyNVB4/j1/KqxYH/t4sVXxMRSfWL6Jve7jHQzzkxUHe6oV1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731453787; c=relaxed/simple; bh=ayby78yQOyjOz6ls+yE5cxTfghhQvc3yyzZlL7gs+bU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qDDLc7+oZTIEw0oUFkpwQBqjecUHQDldMa3L3vPdxdBW6C12/c39UvoNXy2H7AcTu2/XRdHj0Cd9EvXwnVGSx7rDvPPeeCsofirNxaSkmDJD3E8aCQnUKeS5JlymR73E7HCuUYnedwaxWf+lHJFhl1hD/71+u+qU8EzhEB3I9ho= 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=qKsxBg6K; 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="qKsxBg6K" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2e2bb354e91so6498038a91.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=1731453785; x=1732058585; 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=qKsxBg6KK1KzmbyM0Qc41DcpDFnsE0GF+9Cuu59tvTI93sVv9ldwTQ8gYUTB/lQUgN scdqqDh3wEvmDuaHzVOIvpddU+ghfl63E/8FIMrxDuR1X5iPb3oVEDLZd8s60mOTIsh5 S9LH10gSP4qPwq0olBcEx1YoV6dwVMe6f0dN3X6J3BdjT8IfRYvF8hvsN/XpVZhnftib K3CNOt/g+lPNfsPBbYgPOi6XcCY9pSKCccqyowLLfc7PRMbDN/nxdXtE+6eVkKE52g5+ 08mfOQjmYBpvAWFEPMwTMvCQM21GBLGbLRexMe2h2Kno1gPP+vt7VPv1TPJ9Y390UeFu qt4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731453785; x=1732058585; 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=L4R8qOq5Bq1b7c5CQZKwAnYQ31uMqr8JiqXKM74fe0+rIYIYjRxLbQM2TMgNabR4Dz h/yLsL+dMsdA/a9zllkcFPZcPJpRZcIfYUhmQJ758zRoYaJ4A9hQEpMK9GwzdIFM2Ckq cn4iio37+lgv7tF2WN380KuHlS/SDUT4OCDvn2JpGseC++XsJ+yYD962ot0SP8yLdpcf BGlMJsSk4L5N55Na443uWjXAWwhAfsrIAAzHVaRz3a52RgS0/Vhs/VB7BKQtBnNqR3HU wH8ZpIOAZ+P/1tFD0FV9/RCO5D27QZ+XHFkmYmhQ1HDe1kRaLlZse8eTdiqCRQop/4q4 zydg== X-Gm-Message-State: AOJu0YyiJ6G0uSbD9dfTxRqcnGncLobX9n7UdKeLCuSRuKkPwwAzpgEb HCfd+Qop1Buz2qxFfOuoSfE0BEAIgk1q+2R9/3OaY65yixOX/KrzX+9Noxq0u7m2/8G0Sozkb0S NEZQNcetip4DCLKgVpKnTSka62TtOgs5onWH2+iP+Q8tfbvaN7qJg9D08fv8kxD+Jfg1kC1A8wq bLdnwb6yr2TYCUswJMamUZqtMdXv9PNLRBN6uszhCIBy39jdJ6dv978wL1/+7kciHCnZE= 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: linux-kernel@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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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, stru= ct kvm_sev_cmd *argp) /* Allocate memory for context page */ context =3D snp_alloc_firmware_page(GFP_KERNEL_ACCOUNT); if (!context) - return NULL; + return ERR_PTR(-ENOMEM); =20 data.address =3D __psp_pa(context); rc =3D __sev_issue_cmd(argp->sev_fd, SEV_CMD_SNP_GCTX_CREATE, &data, &arg= p->error); @@ -2179,7 +2179,7 @@ static void *snp_context_create(struct kvm *kvm, stru= ct 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); } =20 return context; @@ -2227,8 +2227,8 @@ static int snp_launch_start(struct kvm *kvm, struct k= vm_sev_cmd *argp) return -EINVAL; =20 sev->snp_context =3D snp_context_create(kvm, argp); - if (!sev->snp_context) - return -ENOTTY; + if (IS_ERR(sev->snp_context)) + return PTR_ERR(sev->snp_context); =20 start.gctx_paddr =3D __psp_pa(sev->snp_context); start.policy =3D params.policy; --=20 2.47.0.277.g8800431eea-goog