Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp646646ybe; Thu, 5 Sep 2019 03:47:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyvjA0WhRX8010Fmle1Av6/e6RjEXG98st0NUSsqVbrtoSpGnTdsNg2h317nwoqvUfJiLrO X-Received: by 2002:a17:902:e506:: with SMTP id ck6mr2750066plb.132.1567680441743; Thu, 05 Sep 2019 03:47:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567680441; cv=none; d=google.com; s=arc-20160816; b=R9Q0SesNJHQ+ewuX/N4AOmb+yP/JhSsdTK830KbHpPQMAZ8M8mLdVEqVix1qMwqYi9 ipZyucgdonTIUcwvL5TZIbUaumvlKWSG5ZhVzyxc2hWZuY4eGCwSA+pS0NtBMlYWGKFP fQGHG/Z7E6+vgJBcvHCjiU75+CHOzbp130qT0c+gvlzYybhxY9QRLEAGuteAONtYmOPK hjH2DqGjDKru2iA1WDSTdxZMrEgVRPc9MEfjVsRgqDkPGxpM3Vge30UjorYeC/jA/tHc 32UZvrlKTKVEbeHkLEINMqQ407seaDu0BHzPbbvcr/LCmwpA84nm1hmR/H1zh4kH3l6v yhcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0YvQbhz9gmuSBv9oWKLPBjQZiexEBvys9rvuPO1dwXc=; b=mMhxcFwjTu3KFWcvC5aHlnbeKQBlNPSyJo4hcJ18ORIUgV3Xs0SZCJ/x8dn310PNUW QfxnQ1R4yTwX65XbWhzGKBsWlZSNs1K3ryKrm8gJevLj7c/IVoFZWjNWT84PQ2AtSVV1 tLt2lOitDUuck/H0CQsak/jrVQqNtS9fINQP+KaaXmfGJEA7AnbHjlsV+Mnzv8Qz4Pan DRcxGlm9IBZ4G95/NnrQtRgnpgmLMBKVjBoMs6rOK72TGQBd7w06GE7BQgKa/Rh1faeX h3VNZezcZBGDY5eiBfaOzQZ5XQJ7zhuqDp7yLb6nRiECIdCEEoLDTcO9CJRg9g3hcwIN 6a8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@shipmail.org header.s=mail header.b=Q3K9Demm; 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 w7si1665507ply.279.2019.09.05.03.47.06; Thu, 05 Sep 2019 03:47:21 -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=Q3K9Demm; 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 S2387812AbfIEKgK (ORCPT + 99 others); Thu, 5 Sep 2019 06:36:10 -0400 Received: from pio-pvt-msa2.bahnhof.se ([79.136.2.41]:57340 "EHLO pio-pvt-msa2.bahnhof.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726137AbfIEKgJ (ORCPT ); Thu, 5 Sep 2019 06:36:09 -0400 Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTP id 8AA2547A11; Thu, 5 Sep 2019 12:36:02 +0200 (CEST) Authentication-Results: pio-pvt-msa2.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=shipmail.org header.i=@shipmail.org header.b=Q3K9Demm; 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 r6jqe6qZm8uf; Thu, 5 Sep 2019 12:35:52 +0200 (CEST) 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 1EC3F45577; Thu, 5 Sep 2019 12:35:50 +0200 (CEST) Received: from localhost.localdomain.localdomain (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) by mail1.shipmail.org (Postfix) with ESMTPSA id 8655D360184; Thu, 5 Sep 2019 12:35:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1567679750; bh=sF5pnRh1Bornwr1LEDE7ZQPyi6P6aD1IIefxVqdkCnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q3K9DemmI3/xHZebTO2C1r24nQUPkpAM4rTmfzJQI4wualZhcb/hsTtvclulUE7K1 egQ3kVwV4T8ozRIGk4cA4o+qbAgRhv4CIu5z3sa2byHlWtA5KAj8q+1nyOSxeER/Fy NF0JOKa8Y82Jjs5XZQw4Mx8rDj2Cot/VHEefV6rM= From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m=20=28VMware=29?= To: linux-kernel@vger.kernel.org, x86@kernel.org, pv-drivers@vmware.com Cc: Thomas Hellstrom , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Christoph Hellwig , =?UTF-8?q?Christian=20K=C3=B6nig?= , Marek Szyprowski , Tom Lendacky Subject: [RFC PATCH 1/2] x86: Don't let pgprot_modify() change the page encryption bit Date: Thu, 5 Sep 2019 12:35:40 +0200 Message-Id: <20190905103541.4161-2-thomas_os@shipmail.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190905103541.4161-1-thomas_os@shipmail.org> References: <20190905103541.4161-1-thomas_os@shipmail.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) typically unintentionally sets encrypted page protection even on mmap'd coherent memory where the mmap callback has cleared the bit. 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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 0bc530c4eb13..8e507169fd90 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -624,12 +624,16 @@ 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 preservebits = pgprot_val(oldprot) & + (_PAGE_CHG_MASK | sme_me_mask); + pgprotval_t addbits = pgprot_val(newprot) & ~sme_me_mask; return __pgprot(preservebits | addbits); } -- 2.20.1