Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp168518pxb; Tue, 17 Aug 2021 22:39:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5kiF0UChAv4sAEDgjD3W2WOrjZg08U2WZm8vK5MX77PE+oYC9SnmV6ppCUIQcILOtD3oo X-Received: by 2002:a17:906:89a3:: with SMTP id gg35mr8111442ejc.476.1629265189833; Tue, 17 Aug 2021 22:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629265189; cv=none; d=google.com; s=arc-20160816; b=w+lVzsACLMajie/cADXlRoXkYFVKtxwXnwmGd2dCynPDxwKsxH7p5nJrhNXIYRvycL 3Vk0bGu4hiGM0hQi7hnSVWsGa62WGs+VJHoudLBzR9NqRuSq/uFh7om/N++twP8w4F6P CX2hn2/sP9C6Iu246mE1fAKPOF+ZtdZmoevGdu85mwLULFBbL7xvNOzlpp8CzFIVqSym 0aqml7CaIrMprrlI8jIk4+v4q2VbbK0Vx0k18KCF8pdePY38Fr2LjwjQh2TgacZdy/v8 Kr78amlJQHp3JlHcenthowAEBMP93yVBs8xESQ5bl6r/5hAdeHEyZCR7u17LTFFwR45Q MWfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=WiP9HgfFffnWMWhcvdLBuLUWs2FAICpYV6zjCSodstc=; b=zjHdTQ9xLkucA9h9ANqYFeqWMiKa6onzxuqtXPPQZoynw7bLdDRndLsR43tNRWKxSz 6X4iFMjQc0lIP/nj42qj1XrMwdgMMsADoQJfsMpoDBMNMt5EK2Fyrh4D2betLC+nuubh BDySk2LUPihTxWiO5ZScw+iJ23BeULN8T81EJPfHmmwHV39mdErlVDN6hBwRK4ERjr5e MME8LKNSUZGmyOIWCUH/oIvl7e1mJpcYKq4F4eslQEWDuaa9gp8xbMrb3X7LUa20W+VV YdWRxjCmCvXv++G2h5tD+/pGFdpSvRqBhqmYx/6uFJ8dKJYb9oVDgCpKtefsl6LbEvYa 63dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=P5d31hh5; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si4715654ejj.54.2021.08.17.22.39.26; Tue, 17 Aug 2021 22:39:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=P5d31hh5; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237618AbhHRFjx (ORCPT + 99 others); Wed, 18 Aug 2021 01:39:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237809AbhHRFjv (ORCPT ); Wed, 18 Aug 2021 01:39:51 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FAC5C0613CF for ; Tue, 17 Aug 2021 22:39:17 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id f64-20020a2538430000b0290593bfc4b046so1703138yba.9 for ; Tue, 17 Aug 2021 22:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=WiP9HgfFffnWMWhcvdLBuLUWs2FAICpYV6zjCSodstc=; b=P5d31hh5vOF8UCVyLfij5pHCgatyTEnprnjz48lUR/QQ2E7SfxSMCwblt2FHfkDfo+ QSTLLUyH2TsfavUcqw89bJCByn9dSp8QrIJxkxVd/lwTZKdD+Y7rjveCSbf4fztCUgca npdHNANe1QbR/obju31jRjMyELrgc+v+IVAcgLdFrOwN6l7zLtgE1GNTuzzf05W1bvDF fY0P4AHor6om6MtzOJuA8e9uQXFTQ8nkXU8FDTfNz7TLrUR9tSUNc6HmgsAiJiEwXxco FUPgbFeE5chpzWIuA+rznzFGsXVr1DdfILy3hnU6fUj3oehSHDHqN0nxyiH5Phmx2WSN oC0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=WiP9HgfFffnWMWhcvdLBuLUWs2FAICpYV6zjCSodstc=; b=TDdGpDQmsQSky68o1Gy/c9G74SR1+LgVpOPDcXKK/MqbpiKn5B90icyZu157G6+l7M fqfuFQHd+AkpHm+hAU292yKEFsAtFCtL4yE67Hyskrg4GIwLb10Ps9zEfCBhwipZfyZB u3QxsQrO2beTkgpuCvOyePNt1wsdgJUq6ktQPU+ghAO96LjfQFk86LRQ8Lfug8q0O98V VLV9EqxTSfr7eJQIC2vNn7ULhgUqZVISW5HN2cXEr/QjvbAyuT4XWw0nerIvBRtH7D4J 1Culj8gj21X5/oVQ5Kh1I4w2E6VCfKpmvrrpqGhEPXPxXDeMYJfgtzK7n9geytetzApU CSuw== X-Gm-Message-State: AOAM530NxWLPl63yGUVre1CeKbHLe4z6uN+5N2woE6afdpi3cxDGj58D TT1wdA6S1nrMbE3qlL068Rgdttkr3Y+m X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a5b:7c4:: with SMTP id t4mr9212584ybq.509.1629265156833; Tue, 17 Aug 2021 22:39:16 -0700 (PDT) Reply-To: Mingwei Zhang Date: Wed, 18 Aug 2021 05:39:05 +0000 In-Reply-To: <20210818053908.1907051-1-mizhang@google.com> Message-Id: <20210818053908.1907051-2-mizhang@google.com> Mime-Version: 1.0 References: <20210818053908.1907051-1-mizhang@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH v2 1/4] KVM: SVM: fix missing sev_decommission in sev_receive_start From: Mingwei Zhang To: Paolo Bonzini , Brijesh Singh , Tom Lendacky , John Allen Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Alper Gun , Borislav Petkov , David Rienjes , Marc Orr , Peter Gonda , Vipin Sharma , Mingwei Zhang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org sev_decommission is needed in the error path of sev_bind_asid. The purpose of this function is to clear the firmware context. Missing this step may cause subsequent SEV launch failures. Although missing sev_decommission issue has previously been found and was fixed in sev_launch_start function. It is supposed to be fixed on all scenarios where a firmware context needs to be freed. According to the AMD SEV API v0.24 Section 1.3.3: "The RECEIVE_START command is the only command other than the LAUNCH_START command that generates a new guest context and guest handle." The above indicates that RECEIVE_START command also requires calling sev_decommission if ASID binding fails after RECEIVE_START succeeds. So add the sev_decommission function in sev_receive_start. Cc: Alper Gun Cc: Borislav Petkov Cc: Brijesh Singh Cc: David Rienjes Cc: Marc Orr Cc: John Allen Cc: Peter Gonda Cc: Sean Christopherson Cc: Tom Lendacky Cc: Vipin Sharma Fixes: af43cbbf954b ("KVM: SVM: Add support for KVM_SEV_RECEIVE_START command") Signed-off-by: Mingwei Zhang --- arch/x86/kvm/svm/sev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 75e0b21ad07c..55d8b9c933c3 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1397,8 +1397,10 @@ static int sev_receive_start(struct kvm *kvm, struct kvm_sev_cmd *argp) /* Bind ASID to this guest */ ret = sev_bind_asid(kvm, start.handle, error); - if (ret) + if (ret) { + sev_decommission(start.handle); goto e_free_session; + } params.handle = start.handle; if (copy_to_user((void __user *)(uintptr_t)argp->data, -- 2.33.0.rc1.237.g0d66db33f3-goog