Received: by 2002:a17:90a:9307:0:0:0:0 with SMTP id p7csp2842320pjo; Mon, 16 Mar 2020 05:44:29 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv0UJPZbpH/TfJVNc2FC2pmmtQOZ7A8ox6HMH8qVi9onb/oyIxDi7+wZOK1qbwNIWokWqn6 X-Received: by 2002:a9d:3b76:: with SMTP id z109mr16726621otb.335.1584362669436; Mon, 16 Mar 2020 05:44:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584362669; cv=none; d=google.com; s=arc-20160816; b=w3R6h1mAwn/zrylx1VudFFhQ2zJSpRoVsltfRbdxcupN6B/EdJC7tP1xtIeqMO9XQY ROxfTuWH0XVPMJpTaMb5d8lMaiy9ppwO+d6ZRqG3odD0ybGtvnnMd1sXM433iWBUD3Cr 3CzEA/vwuN8EXsx20TRIcMa9TVWGNxCyHiAvfJsQOWmyZBpvgiNpEx5KbsGvL+Q76KV4 w11wMM8oQXlYRJJns5BWRuG/OwYRUNV79MEWhGmljKm9B0RCBEfkKmyf9wrHtUnctWoa DbHfmbEZoXmyNlWK4kt+lh4qPJugh2Zj3tI3Dh0JGM68NED8gXrGAklR8kbMlCDiiNfV HZaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :dkim-signature; bh=r9YDKn186v5PcAidKm/YhcqNEqeEGZWA5hyeyXBLnWM=; b=S9oexfxrH+TbHJm/Y1aZMj2uuKQQxj6ZOKNBrCytbrPcM1jPW9Elj1itnpBjB3LPgE Kg8WQ6yCSwbYxZvE9L5RCFKe5yUobJuDmuyMzs/ZOjC1esUc/9HCSDhrz9YAUeVqbK+1 17xkrxU9UghofMYB+psBU2YM9fRCd7JPzLo0NP1ArDKJ/Z4XCNbvbsUOrv7/uHxGAXfU lahg13KdCTme9vyglUAHRDRnJx6WV7MfjJ7srzAmJHLCHdzKUa9s8ATtfvUEEQSOH6EH 8Ts6DCT17d+BrjRi64xoNjRpo05YVhZNJ5fl9+J7PMeQUhsVxSBKW5WEPwTT6FZEe8kF nQEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@shipmail.org header.s=mail header.b=IjrFgoI2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si9228477oij.97.2020.03.16.05.44.16; Mon, 16 Mar 2020 05:44:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@shipmail.org header.s=mail header.b=IjrFgoI2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731032AbgCPMm4 (ORCPT + 99 others); Mon, 16 Mar 2020 08:42:56 -0400 Received: from pio-pvt-msa2.bahnhof.se ([79.136.2.41]:60938 "EHLO pio-pvt-msa2.bahnhof.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730987AbgCPMm4 (ORCPT ); Mon, 16 Mar 2020 08:42:56 -0400 Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTP id 465C43F386; Mon, 16 Mar 2020 13:42:54 +0100 (CET) Authentication-Results: pio-pvt-msa2.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=shipmail.org header.i=@shipmail.org header.b=IjrFgoI2; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at bahnhof.se X-Spam-Flag: NO X-Spam-Score: -2.099 X-Spam-Level: X-Spam-Status: No, score=-2.099 tagged_above=-999 required=6.31 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no Received: from pio-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (pio-pvt-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XBjVuI07NOqJ; Mon, 16 Mar 2020 13:42:53 +0100 (CET) Received: from mail1.shipmail.org (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) (Authenticated sender: mb878879) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id 992493F36B; Mon, 16 Mar 2020 13:42:41 +0100 (CET) Received: from linlap1.host.shipmail.org (unknown [94.191.152.149]) by mail1.shipmail.org (Postfix) with ESMTPSA id 67AD536044C; Mon, 16 Mar 2020 13:42:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1584362561; bh=ZjAJmGnE4Gu0kwPsPeYsYEjxTOlAy6I1FJmDkbKZfHM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=IjrFgoI2d5OMHejM/JpIJrK0hTa46nkc9UfGIFkaTXaFhQBse6QPHnI8zFXyCAVJ3 i//lde2KmH3M7Ke21lTKJO1mN2hvP3urm9x3R0ztk0lwjTJtfU3xyIDm1LI+HHpVnu 0iovg0B4Jt7p0UwqRGZrBAn+/4PhwS0khHrlnEMM= Subject: Re: [PATCH v4 0/2] Fix SEV user-space mapping of unencrypted coherent memory To: x86@kernel.org, Dave Hansen , Ingo Molnar Cc: Christoph Hellwig , linux-kernel@vger.kernel.org, Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , =?UTF-8?Q?Christian_K=c3=b6nig?= , Marek Szyprowski , Tom Lendacky References: <20200304114527.3636-1-thomas_os@shipmail.org> From: =?UTF-8?Q?Thomas_Hellstr=c3=b6m_=28VMware=29?= Organization: VMware Inc. Message-ID: Date: Mon, 16 Mar 2020 13:42:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20200304114527.3636-1-thomas_os@shipmail.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dave, Ingo On 3/4/20 12:45 PM, Thomas Hellström (VMware) wrote: > This patchset fixes dma_mmap_coherent() mapping of unencrypted memory in > otherwise encrypted environments, where it would incorrectly map that memory as > encrypted. > > With SEV and sometimes with SME encryption, The dma api coherent memory is > typically unencrypted, meaning the linear kernel map has the encryption > bit cleared. However, default page protection returned from vm_get_page_prot() > has the encryption bit set. So to compute the correct page protection we need > to clear the encryption bit. > > Also, in order for the encryption bit setting to survive across do_mmap() and > mprotect_fixup(), We need to make pgprot_modify() aware of it and not touch it. > Therefore make sme_me_mask part of _PAGE_CHG_MASK and make sure > pgprot_modify() preserves also cleared bits that are part of _PAGE_CHG_MASK, > not just set bits. The use of pgprot_modify() is currently quite limited and > easy to audit. > > (Note that the encryption status is not logically encoded in the pfn but in > the page protection even if an address line in the physical address is used). > > The patchset has seen some sanity testing by exporting dma_pgprot() and > using it in the vmwgfx mmap handler with SEV enabled. > > As far as I can tell there are no current users of dma_mmap_coherent() with > SEV or SME encryption which means that there is no need to CC stable. > > Changes since: > RFC: > - Make sme_me_mask port of _PAGE_CHG_MASK rather than using it by its own in > pgprot_modify(). > v1: > - Clarify which use-cases this patchset actually fixes. > v2: > - Use _PAGE_ENC instead of sme_me_mask in the definition of _PAGE_CHG_MASK > v3: > - Added RB from Dave Hansen. > > Cc: Dave Hansen > Cc: Andy Lutomirski > Cc: Peter Zijlstra > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: "H. Peter Anvin" > Cc: Christoph Hellwig > Cc: Christian König > Cc: Marek Szyprowski > Cc: Tom Lendacky Could we merge this small series through x86? Patch 2/2 has a Reviewed-by: Christoph Hellwig Please let me know if you want me to resend with that RB added. Thanks, Thomas