From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6FBEC433FE for ; Tue, 14 Sep 2021 21:10:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB49B61214 for ; Tue, 14 Sep 2021 21:10:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234503AbhINVLT (ORCPT ); Tue, 14 Sep 2021 17:11:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234349AbhINVLQ (ORCPT ); Tue, 14 Sep 2021 17:11:16 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2F78C061762 for ; Tue, 14 Sep 2021 14:09:58 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id v66-20020a25abc8000000b0059ef57c3386so680383ybi.1 for ; Tue, 14 Sep 2021 14:09:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=BGyteJrFicXpaz74Co+W4m7Ybp8XG6rNqdJoL5bS1T4=; b=U+U/3xkfAShm5h0uHb24Ei1JfmtrGD7T27mgc4dZgabR0Vz+CNil/Yg7P5ERLL3lJS bIiy2UgvXXlur83sCXzMuggHZCa9yN9Tn93ZzQYwhNeNtl9327v01zLA2KuxOc15Dnt/ GOqIX/AoCA4OuYZ5STtiVENxgK5CFCsqiFI+oQdG54SSiKLiGqdYOewhmj5QtvzpR6jj vGvHh+kD84MMapKXVlidFX9dlHM6HPNShacEhQXv9r0r2oFn2MNwxpodU6/fKLz3Cosr Gn4tIrHBiUvpAuuwk4n5UZOd0Uaq8SaBotLqfiQNoeqEQuXki8N4WNS3h+ConEjurMP2 6SWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=BGyteJrFicXpaz74Co+W4m7Ybp8XG6rNqdJoL5bS1T4=; b=dqX1t1+Qg55RK4TnjngrO6G4riu68Yhr6kWW6bhfynyOqHYjoG1a70aLXZiyh0m/bs yJEjyGn20VBw3r2+zPTkVl8zty0+9TDjgKKNDGnGi8gciVK0goDUHP6Zn4i8E+S4Sv/7 sE/0Z0HFhrHmgza/yEZ1t6QCMiOZo7fyXJ48Mau4xRvH35nglvYeLLtN4tnI6z2Gq8bO LUfkzadis59HCm4USDq6Nqnq3Vj5KylbARlcrilqjVRdG/BCUplTgFjNULNh80fkVZkC bZcIgv8ZPhjlZ9b2I7iZAN8YcJjeRhWl04F0NdffeQpTr8zDVjYLpIJxz/Nk6plBYSnl Ju+Q== X-Gm-Message-State: AOAM532qQEpvGuBK88Hix8oSQ1plmjdVQV4vYmXaN4wMUsgB0h3mT1Ti xyyhlpOFy7XWQfDwTEIEj/uBFqdN6wY= X-Google-Smtp-Source: ABdhPJxbqjts/xW1dOXcBXGREypdE4NrY0Usn/jaJuwFFaekrMb+YSrDJodJUp3RZJ91lCUZbBEE/WCIORY= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:d59f:9874:e5e5:256b]) (user=seanjc job=sendgmr) by 2002:a05:6902:102e:: with SMTP id x14mr1711176ybt.410.1631653797888; Tue, 14 Sep 2021 14:09:57 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Sep 2021 14:09:51 -0700 In-Reply-To: <20210914210951.2994260-1-seanjc@google.com> Message-Id: <20210914210951.2994260-3-seanjc@google.com> Mime-Version: 1.0 References: <20210914210951.2994260-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH 2/2] KVM: SEV: Flush cache on non-coherent systems before RECEIVE_UPDATE_DATA From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Gonda , Marc Orr , Tom Lendacky , Brijesh Singh , Masahiro Kozuka Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masahiro Kozuka Flush the destination page before invoking RECEIVE_UPDATE_DATA, as the PSP encrypts the data with the guest's key when writing to guest memory. If the target memory was not previously encrypted, the cache may contain dirty, unecrypted data that will persist on non-coherent systems. Fixes: 15fb7de1a7f5 ("KVM: SVM: Add KVM_SEV_RECEIVE_UPDATE_DATA command") Cc: stable@vger.kernel.org Cc: Peter Gonda Cc: Marc Orr Cc: Tom Lendacky Cc: Brijesh Singh Signed-off-by: Masahiro Kozuka [sean: converted bug report to changelog] Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/sev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 95228ba3cd8f..f5edc67b261b 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1470,6 +1470,13 @@ static int sev_receive_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) goto e_free_trans; } + /* + * Flush (on non-coherent CPUs) before RECEIVE_UPDATE_DATA, the PSP + * encrypts the written data with the guest's key, and the cache may + * contain dirty, unencrypted data. + */ + sev_clflush_pages(guest_page, n); + /* The RECEIVE_UPDATE_DATA command requires C-bit to be always set. */ data.guest_address = (page_to_pfn(guest_page[0]) << PAGE_SHIFT) + offset; data.guest_address |= sev_me_mask; -- 2.33.0.309.g3052b89438-goog From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5A68C433FE for ; Wed, 20 Oct 2021 22:59:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC4976112D for ; Wed, 20 Oct 2021 22:59:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231278AbhJTXBX (ORCPT ); Wed, 20 Oct 2021 19:01:23 -0400 Received: from mail-mw2nam12on2060.outbound.protection.outlook.com ([40.107.244.60]:21504 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229842AbhJTXBW (ORCPT ); Wed, 20 Oct 2021 19:01:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eHAiUohTSEaEhmjzDqb5n71XoH1quwwpFZ+jRM3sGmlCrkiqZoNm4zB3T/1lij+oe3oM0urnv2yVR5NSB9FVFWVd+DgaL79J1cYHmjftwxT9kMgJRnz4vgsYbmglbEGc1y5b0TymuJ7bWChBz82GGiihGw0s+kpKs/mmLL2UbwYwKJlk9hlhvkdbmnnyjBYAfZu5tp+ARqyVjXfa8R0KnJ/j3T7Dyh5FVRio8Cg9t5VegICxikfDpmRDWY7H6JzfL0mp1T7KZ5dN6kYW1uOa06vH9cZlTfjKYL1wHSp+QMwwJzwlE6McBFabB1pZ6PW9dEQbVuhVA0tW6X0xy+fz9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=j+VucUUc6QyYgXDe1gLQiAAn2bMcBp5yBVb5NIEOnDs=; b=jDUTBaKs4I+W4OmVJo9H8VyCTzmKWLTr06QKc8w1Vn1C9SeGMgp0jyZQugD9j63lUHoDTQH2zDMOssZU3byo/bBnkUqeLjXhsijgZc64wWlBwxchbUeH9slRDL1Nmes5ZUO5iEc6LyHHGHFi0G1rms/wJT7hYm5ZVfBmX80MUFKlJVJp7DmDRZVLTkVNoQuvLakfvDYJsSoGsgvyInd4rqbyLuHX4VhdytvppbAcRU0opVLSgv5l/qRthxhVzIW5geISD64zmXaGxVrxeu/cZHGK+gyRoRqGwjRYYWtzigpp+tYejXprQ2h4/fb1S+Y0wkzngBDLTtSRZTQLyFkxTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j+VucUUc6QyYgXDe1gLQiAAn2bMcBp5yBVb5NIEOnDs=; b=ZqmOgBrEvW3jS+beeRdKoHrCgYmKA76B31MBgFT5m36nD+1rzCwH+I6W4WJqjYRo97KZlhH7VPi9xHbunadhLAi5WBk/uHv/IO9jYGmxnkq/KwrVx/ydEfcGFHva93OGxyI4FlVhET4CJ5sj4mn4xbFhf3/tglabkXPj3cLBKKs= Received: from MWHPR20CA0036.namprd20.prod.outlook.com (2603:10b6:300:ed::22) by DM5PR12MB1641.namprd12.prod.outlook.com (2603:10b6:4:10::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.18; Wed, 20 Oct 2021 22:59:04 +0000 Received: from CO1NAM11FT024.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ed:cafe::33) by MWHPR20CA0036.outlook.office365.com (2603:10b6:300:ed::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Wed, 20 Oct 2021 22:59:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; google.com; dkim=none (message not signed) header.d=none;google.com; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT024.mail.protection.outlook.com (10.13.174.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4628.16 via Frontend Transport; Wed, 20 Oct 2021 22:59:01 +0000 Received: from ashkalra_ubuntu_server.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Wed, 20 Oct 2021 17:59:00 -0500 From: Ashish Kalra To: , Paolo Bonzini CC: , , , , , , , , , , Subject: [PATCH 2/2] KVM: SEV: Flush cache on non-coherent systems before RECEIVE_UPDATE_DATA Date: Wed, 20 Oct 2021 22:58:48 +0000 Message-ID: <20210914210951.2994260-3-seanjc@google.com> (raw) X-Mailer: git-send-email 2.17.1 References: <20210914210951.2994260-3-seanjc@google.com> In-Reply-To: <20210914210951.2994260-1-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 49f63be8-9b5f-487c-75a0-08d9941d350f X-MS-TrafficTypeDiagnostic: DM5PR12MB1641: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8Q517ttm8mjJGeGqC5XbCwYvuuRTQ6M77Jru3ZTFi7qQ0iURpCS04w4lljGiDaCTK6sT+kAEzihbcR5uRcOqFFLPO9NruR85WTiOcifugBnATgmnQDx6BrL1elcGiTCKYxKCBHj9k77o0vOMu5lwqIPu/yU3REKAZ4pYQ/1p3n49kyY5blz7Q2bwSAuEJWi3LFTtLdBZu/RcOQP6Uphp5sPbEuq+cNzXbu0M43K236kxgWkqIm9v2D74VQPW+IM5pmwD/5c4K8bgTHikEuhR8ZLheqMcgBXAWtdN1XFQ+kv5O8IhYHAju5hHrOs7USpCEVIwshWiFZqb+b5GiMA+w54PXDnWtw8o8fTwBaXXe349pXWZXol7YSQW81bQ6ivIoVqcvKexkATIBjZRzdKvNScUyZtlMxxV/B+NPgPaCdazOXfJJ6MBrnhpRXmVeXudbq/HJeDwgPLUppge8Av8caerul0/XzB5HeHZHRpBcCHh83ZzD/fGRA4qDrJ1k9S2Q7XYx4uCO4N3ILKD4EUQKR8/wHp+0EsXlEQQwB/i8CyGZdES9gnjTY3wCSjm2NCq/G3TIF8EO7JWO+eS0xom0swN2YGNXy1pWVLKGTJwSBMJ9bmQhFgDf5OPhZ4wZUgviLz4lMCHcxk9zrK980j26Lejkx2ndnS2i+A8euejurGjQTh/1CHqapwag4v5+Cuwm993vINkEwDATXURVkHRMR++2xbqk9D9Xs1I1PPGwaI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(83380400001)(186003)(6666004)(7416002)(16526019)(54906003)(55446002)(8936002)(86362001)(110136005)(4326008)(508600001)(36860700001)(9686003)(426003)(1076003)(336012)(82310400003)(356005)(316002)(26005)(61793004)(70206006)(47076005)(5660300002)(81166007)(70586007)(2906002)(8676002)(4744005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2021 22:59:01.3224 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 49f63be8-9b5f-487c-75a0-08d9941d350f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT024.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1641 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Message-ID: <20211020225848.eDKZIsX3mNNYgasHleUen3h3CDp3ujJpt_nb3TecCCc@z> From: Sean Christopherson Hello Paolo, I am adding a SEV migration test as part of the KVM SEV selftests. And while testing SEV migration with this selftest, i observed cache coherency issues causing migration test failures, so really need this patch to be added. Tested-by: Ashish Kalra