Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1854716pxa; Thu, 6 Aug 2020 18:26:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJza8vsZ9NkDBdX3U4OE/zHnNl00i+OAi3+7iZuU4NCK9G8TqjYO+68qNNFcA8zjxER6C90b X-Received: by 2002:a17:907:7255:: with SMTP id ds21mr7514264ejc.44.1596763608980; Thu, 06 Aug 2020 18:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596763608; cv=none; d=google.com; s=arc-20160816; b=UIXU1hECHXWVwh8YWX4+Y6t95sLTxrYZIxV7u/TB2+YlZtuSOfCIHb+gA5hHTeWz07 qJMUVKCuAwMh0BPGoOBc5viE4w2apXdQT89SCDRVPobiuR9bvLkJAtko8t4yEqWblhS5 Jovg2CvmhPZ/i4TMjLcVMEXuG9ZEGCB2zqj/ftowyvdGP+BJUw1nWffTVwKRPpVViamy 5/5y6Yq9Kp2M5sYG5xgta0cgLqcAponFCcfjCjTFPoCJQqPfFV0JnCodMyMUa0T6iF2O LS3G5m785mQc/7wZJlnnaDTO+hEMX0SUffY9aVqQ5xUKAC6t11FBLHJ/7jMbcO7+EH4G E1pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=yC5jYNAZ2LkpJAay2cVTHRBar69NJbTlP8o5uIXB6/g=; b=UXihLDWKCMyeeHeJEq4vlwFagyQYk2tXP+Qc9+OopPe/lZK0IBx59u88wX+VTsTEFZ vF57tV1cBv+mPpKh9jPVAI7tTAiWNkXAeQqofcqHYSxp/4A5m/kCzg2YQ96Cxy2szJgF zb0mp3z8oEKL24gY00tth8ryqT1O726M4XIvVfLbJNaCPHSFoQcXzw+UCgcrJ3JIw0vB 4hG/GZ2UnsED0llu9JgZUzejckuS3NEcLc4wLNH4TLtDVm5NIREzBZEJubxx9paYSEpD Fc/kEAVvHJDrjXH2bct4baUmrlYTvtLbBE0VaXVl8mysKMVILxSikEuAyUwIr0Evr815 bahg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dbhUZ4Ad; 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 q6si4211889edn.165.2020.08.06.18.26.26; Thu, 06 Aug 2020 18:26:48 -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=20161025 header.b=dbhUZ4Ad; 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 S1726256AbgHGBXZ (ORCPT + 99 others); Thu, 6 Aug 2020 21:23:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726226AbgHGBXY (ORCPT ); Thu, 6 Aug 2020 21:23:24 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB751C061575 for ; Thu, 6 Aug 2020 18:23:23 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id e24so428045pfl.13 for ; Thu, 06 Aug 2020 18:23:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=yC5jYNAZ2LkpJAay2cVTHRBar69NJbTlP8o5uIXB6/g=; b=dbhUZ4AdddRmmfM5MZeqGAPEKz9pXzfFnWWvVwOcBdaX6SgkOX4BLQ1qmjaI2Vv/RE lI810NuPrU8cba8i0YMXSkn1Ohkr+DXWdTHizneQgoirhCfkZmKKIefeuWQqwM6d5p46 5ScI/Z3lLN/VuwpppPg52ErsiS6PbguN4Kopt6kIWm0mDIDHjOFb1h27WrIDbRLRHP2v z/Nof0CVwzKkv+LKjBfCzacBwcSdazISEWZKgHJuaT4pwK6Fsdwez25g9dP4eiWSO7hC qCfmyEflLkUT16wBzHw+kRlqSt1miYrr3Hnn1UbC94AfE7oJaTUr/YGJlqf9blZYhnkg PqRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=yC5jYNAZ2LkpJAay2cVTHRBar69NJbTlP8o5uIXB6/g=; b=cI0cQyrU1oAYezGsz8lEJd8DRaEd2Fr7IEv/qTLfH3mfdMz/+HTubitvo6JfbpqGu0 LLUlkQP/0Vy68k8eDa0OeNvuWLkppcTrol3SAUMwiWgkXxpXLCiBWkD229rxKBL0Z1cE 6yZnM+DahjBNed6gzI6kdOpvkBxQB09N6Dvtfj45UvsRzxvHYwq9kggALr+bnG98b37z J20Qd0F+iWcSQov6eZjA0woW/A3HPQfDxPqH+mPVlOcqzTRNVcUeVa/M1/gprAhtsUcX gfGXW7g001GNq1WqypfkyaqWmHm+tCXOo4JgTGEpZp5C7M/+BYUXhR0Rh/zRLtbXIlQp bX2w== X-Gm-Message-State: AOAM530YWd8sBHVP8z/twnEC7gGEawRNHkMkqdNaCmPKf7aWHF1Y6ram VBJ7h0vU2J+6vj3UWQyMZm5yvbWb X-Received: by 2002:a17:90a:6343:: with SMTP id v3mr11046672pjs.163.1596763402902; Thu, 06 Aug 2020 18:23:22 -0700 (PDT) Date: Thu, 6 Aug 2020 18:23:03 -0700 Message-Id: <20200807012303.3769170-1-cfir@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.236.gb10cc79966-goog Subject: [PATCH] KVM: SVM: Mark SEV launch secret pages as dirty. From: Cfir Cohen To: "kvm @ vger . kernel . org" , Lendacky Thomas , Singh Brijesh Cc: Grimm Jon , David Rientjes , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org, Cfir Cohen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The LAUNCH_SECRET command performs encryption of the launch secret memory contents. Mark pinned pages as dirty, before unpinning them. This matches the logic in sev_launch_update(). Signed-off-by: Cfir Cohen --- arch/x86/kvm/svm/sev.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 5573a97f1520..37c47d26b9f7 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -850,7 +850,7 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp) struct kvm_sev_launch_secret params; struct page **pages; void *blob, *hdr; - unsigned long n; + unsigned long n, i; int ret, offset; if (!sev_guest(kvm)) @@ -863,6 +863,14 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp) if (!pages) return -ENOMEM; + /* + * The LAUNCH_SECRET command will perform in-place encryption of the + * memory content (i.e it will write the same memory region with C=1). + * It's possible that the cache may contain the data with C=0, i.e., + * unencrypted so invalidate it first. + */ + sev_clflush_pages(pages, n); + /* * The secret must be copied into contiguous memory region, lets verify * that userspace memory pages are contiguous before we issue command. @@ -908,6 +916,11 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp) e_free: kfree(data); e_unpin_memory: + /* content of memory is updated, mark pages dirty */ + for (i = 0; i < n; i++) { + set_page_dirty_lock(pages[i]); + mark_page_accessed(pages[i]); + } sev_unpin_memory(kvm, pages, n); return ret; } -- 2.28.0.163.g6104cc2f0b6-goog