Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2806540pxb; Tue, 21 Sep 2021 08:05:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcSvXD+PIvTbwpkRI1sPbnTGZ8LWaewbKx18rtUD0YeCMbjAZHlagFxpmxcV9XsMSB4TOg X-Received: by 2002:a6b:6901:: with SMTP id e1mr348599ioc.137.1632236741837; Tue, 21 Sep 2021 08:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632236741; cv=none; d=google.com; s=arc-20160816; b=kx57HhKLjUbItFj+liODo9MhJh04MX51ZhZrJ5nb44Fjmct/RBf7UH4H0DoOeZzFek anyuBvvO+004aoj2qkI6vXVoFIEG16P8sYYM9HggdQHD6PrNxwSqOf+LKXvAWAYySYcy Bd9Y2FH13ThwHVpS7lKdSL4vuWDPZyh0ucXJ5G/Pb2bMqut3L5qJ7j4F1F9KYu/ofwV1 O3hgEujkFqMYkPDZzxPX+uMFkB0ufMhpoCEb4dm9ItjBowDGIKxSJYPUEj5EBaM+AOiL CvVwfAqJPeHuMZyApMntDAjOyHIu0dEBcPjqSjAN052QeKyhU7sQhsYBRghPSAZ3U3Hm sI3w== 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:dkim-signature; bh=GIfCLH5ByXyE5OlyMkygyHkkDqaZzo0Y6ZcGzOkxcjM=; b=dBbzZVAshDbTwVSp86TO9CAG8eqdhRItYIO+rgQrJPDKbiaSJW0tpEGGogA9KARqZg L7K+fKECn9xmIxDR8nNSy5cbOU5c8gDJ+9LRyPwk/U82EHTqTeokOXMn2l3bXpaYWuGo iuGd2XvCuKlU/aFhDGJFXymj3timULdAtYVoV5r11bqdq47QvcSorxrvoqe/s2MATV1q dGCfybJF8iRqEwqEGDtYL2g1SgWaFXOxMhxPZ0xGrYBs0+dgwKlwS2LCT8VUHc5EqgqL lBRMIKQK+WY+C9Y+49xcEilADHP/9RtIHsjYmaEDe9N0YKr0Ydo7OYc2r11LR+QlWVt4 eoYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="nVhiK/Gp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 m6si8636554ion.92.2021.09.21.08.05.28; Tue, 21 Sep 2021 08:05:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=20210112 header.b="nVhiK/Gp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S233926AbhIUPFb (ORCPT + 99 others); Tue, 21 Sep 2021 11:05:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233862AbhIUPFX (ORCPT ); Tue, 21 Sep 2021 11:05:23 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57459C061574 for ; Tue, 21 Sep 2021 08:03:53 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id bi14-20020a05620a318e00b00432f0915dd6so117186667qkb.6 for ; Tue, 21 Sep 2021 08:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=GIfCLH5ByXyE5OlyMkygyHkkDqaZzo0Y6ZcGzOkxcjM=; b=nVhiK/GpBtOXB21+2y1Z5/mIgNi/PJLMHvMmYkPSJCUONZSiXYTy4R2MYYs8CZlxkW CUQwR5cFuCMVxXnfEc61HeMSySMnwFDogvYg5ie3AuBTVk+eWXupS+O5+a8MGvW4qXl0 +ASR8ngsa5zHO7kvT7V+BVRHyd6gVcP3TVX4QckPchkEq3ry+VUXeXjX+4Y+elhDi91V +72WNrD1t+y4O0xgDgvl6PjQjnHsq7TuyvC6eWBSqmMc8hlTUZw5N7UdzHVSvLInrYQF d1AQ+skxMoPxuZOqgtm+o4AZqLXq8PTEUgjjNfstsMg/RZbQr/QTu9GI+geMGFJt2GiN QIXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=GIfCLH5ByXyE5OlyMkygyHkkDqaZzo0Y6ZcGzOkxcjM=; b=udLrAlox+JGWIXYFvOZxOr1Ba3+/bkOV3/pe+WETJ+L3+Qyqw2vLXhC0lKvXd6zz3K KuVXM5Z9BGKn83p0xHQSlA8a+FvFYN32rPHz/YuyvcTX8zwLcO7/ov/TLL/zC6mJIUWA HKdIDc7OdLBsaQPoL2IFivkTYsqGjDcF0QWs2K/eumE7neE4Ai/MMyCAftFRt1wprvTp MisNNiAiqPmC2F06XsIdLeoZ/U5oVmx4TwHfxPGmCFsS5p+/l1M28O7/M8pHXLsEtAux ngW9igLSKqOlreCcEcya6itC9VWsOhD8Z8bmYKvPaX2weJ0QhkYclfB+/b8rz3p2bE1I /YuQ== X-Gm-Message-State: AOAM5305+ksemSN5Sgu5K9NeWhHv8FPvDw62SmLtS7ulIPpaDHli3RlU LviNzMesOG+XWq/Cuj+yL7ob+S3Pp/o= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:204:784b:c8dc:f1c:ecde]) (user=pgonda job=sendgmr) by 2002:a25:ae64:: with SMTP id g36mr39999087ybe.26.1632236632524; Tue, 21 Sep 2021 08:03:52 -0700 (PDT) Date: Tue, 21 Sep 2021 08:03:45 -0700 In-Reply-To: <20210921150345.2221634-1-pgonda@google.com> Message-Id: <20210921150345.2221634-3-pgonda@google.com> Mime-Version: 1.0 References: <20210921150345.2221634-1-pgonda@google.com> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog Subject: [PATCH 2/2] KVM: SEV: Allow launch vmsa from mirror VM From: Peter Gonda To: kvm@vger.kernel.org Cc: Peter Gonda , Marc Orr , Nathan Tempelman , Paolo Bonzini , Sean Christopherson , Steve Rutherford , Brijesh Singh , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A mirrored SEV-ES VM will need to call KVM_SEV_LAUNCH_UPDATE_VMSA to setup its vCPUs and add them to the SEV-ES VM. Since they need to be measured and their VMSAs encrypted. Also allow the guest status check and debugging commands since they do not change any guest state. Signed-off-by: Peter Gonda Cc: Marc Orr Cc: Nathan Tempelman Cc: Paolo Bonzini Cc: Sean Christopherson Cc: Steve Rutherford Cc: Brijesh Singh Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- arch/x86/kvm/svm/sev.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 08c53a4e060e..9cb6e30d6ae4 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1501,6 +1501,20 @@ static int sev_receive_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) return sev_issue_cmd(kvm, SEV_CMD_RECEIVE_FINISH, &data, &argp->error); } +static bool cmd_allowed_from_miror(u32 cmd_id) +{ + /* + * Allow mirrors VM to call KVM_SEV_LAUNCH_UPDATE_VMSA to enable SEV-ES + * active mirror VMs. Also allow the debugging and status commands. + */ + if (cmd_id == KVM_SEV_LAUNCH_UPDATE_VMSA || + cmd_id == KVM_SEV_GUEST_STATUS || cmd_id == KVM_SEV_DBG_DECRYPT || + cmd_id == KVM_SEV_DBG_ENCRYPT) + return true; + + return false; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1517,8 +1531,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) mutex_lock(&kvm->lock); - /* enc_context_owner handles all memory enc operations */ - if (is_mirroring_enc_context(kvm)) { + /* Only the enc_context_owner handles some memory enc operations. */ + if (is_mirroring_enc_context(kvm) && + !cmd_allowed_from_miror(sev_cmd.id)) { r = -EINVAL; goto out; } -- 2.33.0.464.g1972c5931b-goog