Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2658395pxa; Fri, 7 Aug 2020 17:38:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOL2E4jFLgoxHHYtgRpcupY6E4GjKhbJnn63xYpjzJVawUZo9WAuXsNa3jr/G/nxNp8RC2 X-Received: by 2002:a17:906:b5a:: with SMTP id v26mr12539224ejg.515.1596847130107; Fri, 07 Aug 2020 17:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596847130; cv=none; d=google.com; s=arc-20160816; b=VvaWznzxQ23nIjSAGX2yRjoAJHcdZYy31dTX7znR7zT1jWxSnAcv2cXAIcgTQtrYZL JNjlElkqtI039kHM5xyAjMDV1Udu0sNHbJ/r9MIqDB1YgW8DMCwUGSNiz89pxoSuVzKr /w91SouPuphHwUXi1gQGXWAOayhAN6NsYE4VQuDg26yUc4saRK7NUxUSII7l/Wv1u0Qs GhI+Zk78O6shUqXv82mTKIYbCjah+sgAnjrQlmFL/3mirS+BAV3rdyxYMmA9XoknsYBV nYP91NZQP6xwFophUyZkwQHbQ4r4aVedtUt6UABbPaSpsseAtEa0itW5S36YbxjSBloK Ja0g== 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:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=qAWBHy/YDwId+EQliujOzvzt7GbHETyF7ZMnV7H8r4I=; b=qaRRlNiwmUo8AzkUszuxs63vbA+8NsqGd4kfHP3gg3CB8dSBCA+z166c/UXkeH7X24 xqBMIPaT+sv5ww706NUIZARWMP8/0HXaec6GSU24rAlRwAI4Nqn0RCIBAqXNKOII8iST oSyPnJhn2ieac5ETT0H6y0mcSfE3DTyJpRkmDdQN6QZVM769rVO4oCBEkS5uyZ/VHseT DdO7BSQFk9sA8CX+f3PqzsXV264FajX+mZZ16BzGn9QvpUY30A2+jr7s6INQbHppurnO VjiTyPdDHFts8OgkJQts94kUN+cqI5eMjlmisjwavtLuyxQPG9boypttqSIplFrg55cn zoGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZbCKesn1; 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 q19si6054715eja.613.2020.08.07.17.38.26; Fri, 07 Aug 2020 17:38:50 -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=ZbCKesn1; 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 S1726204AbgHHAhv (ORCPT + 99 others); Fri, 7 Aug 2020 20:37:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726131AbgHHAhv (ORCPT ); Fri, 7 Aug 2020 20:37:51 -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 02F48C061756 for ; Fri, 7 Aug 2020 17:37:51 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d3so3121701pfh.17 for ; Fri, 07 Aug 2020 17:37:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=qAWBHy/YDwId+EQliujOzvzt7GbHETyF7ZMnV7H8r4I=; b=ZbCKesn1vTPY1aHBijollqglxQcxq5k+YuhetvBKh0GklCvIt4ThY4Rk5dGH5baAd9 bwda8nPqy9p8Zq4zs2JhLSHt5LBithwKbXS5HtyfG2yGdghjNPUkP98CDX9/Q1rAmhCZ q1c4WyB2E+9DTAKUwKSmL+PgduqDo50uVJiULU5t2dPkXaCkcSVxDRBpz5YDO4Q2oCPH kYkrjOg2SzYtL58uL4bRhc3Z0Amf+NDPgv5ZfAvxBGMV/MiXOeL8aWfsKGV815Mt0Vjj FCIH2gRlXfn+MtVJKxhcrk65rxyNGDkJ3UepUyryM5VSrtZKAGiSB/CM0PjWqUzXWfB3 wXfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=qAWBHy/YDwId+EQliujOzvzt7GbHETyF7ZMnV7H8r4I=; b=EkuGADG/7RVm+e+C/jXwx64CvRseReD5md9kBT7sNkooLJIiVr6+Ucjpe+QF+b8OU/ ZFWlMvYPFsUZU1nAdwHUdLmKUjHx0owQ7g5l/9ztvph3A9MuT+44qkNmBOdP0gtQAEI0 iwhRLaAANJQbDW++CmcmZMWLS0BfLCTdK+2A3ETTobhBTTrB6rTKl5JrKjCZXxEv4drp hpgomukLQSz0RoXEJZo8txpw7JAP4vWL6SXPgT0bH3vUsHNSHfa9+IymzLqcPbWnknzE ihaUzAPsH7k2ASwRrtichoYsECuJ1TavnoPUSAARc9VtJgpcEqVs26l/VIAY8dD4Teow MnVw== X-Gm-Message-State: AOAM532ewfj0Dft1PtIXLdYpNCI+PaHfXoxst8uOOfnD/U0fAEfpDD2E OPOHA143bPJrVnluchNHJdd8TPJo X-Received: by 2002:a17:90b:4a0a:: with SMTP id kk10mr15916872pjb.30.1596847070432; Fri, 07 Aug 2020 17:37:50 -0700 (PDT) Date: Fri, 7 Aug 2020 17:37:46 -0700 In-Reply-To: <20200807012303.3769170-1-cfir@google.com> Message-Id: <20200808003746.66687-1-cfir@google.com> Mime-Version: 1.0 References: <20200807012303.3769170-1-cfir@google.com> X-Mailer: git-send-email 2.28.0.236.gb10cc79966-goog Subject: [PATCH v2] 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_data(). Signed-off-by: Cfir Cohen --- Changelog since v1: - Updated commit message. 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.236.gb10cc79966-goog