Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp910189ybe; Wed, 11 Sep 2019 06:39:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyniW3HFbZG54VYDq56MPf930zm+cKYlwrLXcRh992+H9iYrUBBsmN2JrRQjkKkGql4ZxnF X-Received: by 2002:a17:906:57cc:: with SMTP id u12mr22432931ejr.170.1568209185178; Wed, 11 Sep 2019 06:39:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568209185; cv=none; d=google.com; s=arc-20160816; b=W8EIqXtcshaWHai0TUAdWLJ2/2BS0HoWr6TYnWe6RWJg9/Gqchal/pARZLkKj2JWFZ k+pBoh+TctfPPZ/aPurWEmknJRKt4LuVnB6Pgw10sSc+NCyYe+24xssmt8yrXT8FUWrK /kWwuSRVrMtpcNs/IN3q2Se3BvdDCS/+GF5OoOXD/AUXdh5qYDGEVu8Ih/pP9jFhSLJ3 AiImFopPBN9Xj5TfHNZsVXqRNCqgtstu0wD2iuUZVWYq06qV+EjehDRiyheHsihD4OrC uJC2SF/nYSYfyfAwG0TwEmQQa2EtyrghDZXSvMf5IBd13zyLL/BWyPkI8p+1urNdOIXC Aj+A== 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=DvjCND1ir5bFaLhc0hG8yYoV66pcRDgM4KG4VD/AKQk=; b=AxC1flLwvbOIChIgyXyUoHVly0D/maWMxcqp2MyBQ663waV8utOwqtX69tJiNqb/GW sax23a96K0V+sxSjceaZ1+dr4qqLGCn44KzNte9NtLbnE2207xg6pehCrpe9p1WW4FZl NlIeYUhL58If46LibQeE2zl9cTS4BtNefcamK4kKZwGeRRzfSs41enNTWJOxj0MsSBJZ 5b0Md9joZIwyc4wovfuWlLnWyCAKnsvlcC6uOA1w1Txvv6eh2gWqcG78exmNBO/DRvJX 1xraW0k0fOXnnJjTEw+oy1plJ27FjRUQkHn+CTyL6x5U/NOXT+/f/979viP/LE5RFfzJ 5VjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@shipmail.org header.s=mail header.b=OcLNUXkS; 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 l7si820781ejg.377.2019.09.11.06.39.21; Wed, 11 Sep 2019 06:39:45 -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=OcLNUXkS; 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 S1727940AbfIKNh2 (ORCPT + 99 others); Wed, 11 Sep 2019 09:37:28 -0400 Received: from ste-pvt-msa2.bahnhof.se ([213.80.101.71]:1606 "EHLO ste-pvt-msa2.bahnhof.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726954AbfIKNh2 (ORCPT ); Wed, 11 Sep 2019 09:37:28 -0400 Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTP id 7097D3F738; Wed, 11 Sep 2019 15:37:20 +0200 (CEST) Authentication-Results: ste-pvt-msa2.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=shipmail.org header.i=@shipmail.org header.b=OcLNUXkS; 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 Authentication-Results: ste-ftg-msa2.bahnhof.se (amavisd-new); dkim=pass (1024-bit key) header.d=shipmail.org Received: from ste-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (ste-ftg-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IHW01YaWejTE; Wed, 11 Sep 2019 15:37:16 +0200 (CEST) Received: from mail1.shipmail.org (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) (Authenticated sender: mb878879) by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id 184183F734; Wed, 11 Sep 2019 15:37:13 +0200 (CEST) Received: from localhost.localdomain (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) by mail1.shipmail.org (Postfix) with ESMTPSA id 7EE4F3601AA; Wed, 11 Sep 2019 15:37:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1568209033; bh=3PG6dFlWy4tEZtyh5/983yf4ihrAZIfnFudxICqTBHc=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=OcLNUXkSt2k+0/N++IkRpPqmWylBGN+sIwbM85W0AEJhGtK1DqkhvjvWXRDUafbqP nPrUbSVRyJHkmOjRfhAbgcrHhViBbxkqfz6BlnPKtdY52+yY4NBfzBncHi8zwQaSUf Ww8v/qSNU815lB0Ku2OZPgTZivBbeb3/7X6rl96g= Subject: Re: [PATCH v2 1/2] x86: Don't let pgprot_modify() change the page encryption bit To: "Lendacky, Thomas" , "linux-kernel@vger.kernel.org" Cc: "pv-drivers@vmware.com" , "linux-graphics-maintainer@vmware.com" , "x86@kernel.org" , Thomas Hellstrom , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Christoph Hellwig , "Koenig, Christian" , Marek Szyprowski References: <20190911124022.22423-1-thomas_os@shipmail.org> <20190911124022.22423-2-thomas_os@shipmail.org> From: =?UTF-8?Q?Thomas_Hellstr=c3=b6m_=28VMware=29?= Organization: VMware Inc. Message-ID: Date: Wed, 11 Sep 2019 15:37:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: 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 On 9/11/19 3:27 PM, Lendacky, Thomas wrote: > On 9/11/19 7:40 AM, Thomas Hellström (VMware) wrote: >> From: Thomas Hellstrom >> >> When SEV or SME is enabled and active, vm_get_page_prot() typically >> returns with the encryption bit set. This means that users of >> pgprot_modify(, vm_get_page_prot()) (mprotect_fixup, do_mmap) end up with >> a value of vma->vm_pg_prot that is not consistent with the intended >> protection of the PTEs. This is also important for fault handlers that >> rely on the VMA vm_page_prot to set the page protection. Fix this by >> not allowing pgprot_modify() to change the encryption bit, similar to >> how it's done for PAT bits. >> >> 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 >> Signed-off-by: Thomas Hellstrom >> --- >> arch/x86/include/asm/pgtable.h | 7 +++++-- >> arch/x86/include/asm/pgtable_types.h | 2 +- >> 2 files changed, 6 insertions(+), 3 deletions(-) >> >> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h >> index 0bc530c4eb13..1e6bb4c25334 100644 >> --- a/arch/x86/include/asm/pgtable.h >> +++ b/arch/x86/include/asm/pgtable.h >> @@ -624,12 +624,15 @@ static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot) >> return __pmd(val); >> } >> >> -/* mprotect needs to preserve PAT bits when updating vm_page_prot */ >> +/* >> + * mprotect needs to preserve PAT and encryption bits when updating >> + * vm_page_prot >> + */ >> #define pgprot_modify pgprot_modify >> static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot) >> { >> pgprotval_t preservebits = pgprot_val(oldprot) & _PAGE_CHG_MASK; >> - pgprotval_t addbits = pgprot_val(newprot); >> + pgprotval_t addbits = pgprot_val(newprot) & ~_PAGE_CHG_MASK; >> return __pgprot(preservebits | addbits); >> } >> >> diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h >> index b5e49e6bac63..e13084b3d6cb 100644 >> --- a/arch/x86/include/asm/pgtable_types.h >> +++ b/arch/x86/include/asm/pgtable_types.h >> @@ -123,7 +123,7 @@ >> */ >> #define _PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \ >> _PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY | \ >> - _PAGE_SOFT_DIRTY | _PAGE_DEVMAP) >> + _PAGE_SOFT_DIRTY | _PAGE_DEVMAP | sme_me_mask) > There is a _PAGE_ENC definition that you could use to make this more > consistent with the current definition. Ah yes. I'll wait a bit to see if there are more concerns and include this in the next version. Thanks, Thomas > > Thanks, > Tom > >> #define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE) >> >> /* >>