Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3205542pxb; Mon, 9 Nov 2020 05:34:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJynslvsK//2JZR48N0DnETB0MuOeiiRrd+qKobmyoXT2Sfy331olDWlWmQnhuvaAyI9t9MM X-Received: by 2002:aa7:d514:: with SMTP id y20mr14926254edq.384.1604928853342; Mon, 09 Nov 2020 05:34:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604928853; cv=none; d=google.com; s=arc-20160816; b=0rcysZ23v/gKI5KuAF2pYiNNlt3KDMgkGh3jwJMNA+aWSia3b0hNi8oA/zCOB18NeU 5ogm63SuODO4Kd2MERzoB7htRzWmtwv3k9IDih4miTDJEF65gK0LFFsdfdYmFOeBp+ok 5ImSeJbprvKs6rujIqZqGv7Blp7unpeQXMJSgVKzE+boSNrvcLKLq47Sm/bGM4vXlpkI DWYB8r7lOd5SlB8lumeqKBKztKB392DJXp9nNe8lZHgywEym53b6ZjvTEhpQfQkKeV3g 9jM36tXyirR+HQ0xKeqf48WjZHciYcS7xVx+e8/WaXBz/x3pQMqcLigS8Gkp/5p/g5y0 laoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WMcZa/E8rmMTdw7eVTYjFHfoMdg5gMPxkvzxLcRhEUs=; b=sRjLX7gTWr0MG/capfYQpUNZ1KtdNuC0yOR6I2J9h/8B85KCJzi0FjQcxEzJPoUeKr aiFy5sYWRgRfzYSU6DXcUMIfOkKHMfSmZL82/pWql9Op9NALIVSPTqfYYozHYriRZQT1 qZRAiKTmUHpmtHFfBAnogENCasWR1+ZDX2riaBB79gFd7udlkUDTO/CAbe47EqMLfvk/ 3F0MoqU0+AEaGZ59AI7E/rm7+HsfTtNYzUpYdMaGHHW6iUPNo9ZiAXojmEM5uir9j8LC t4j99xww308ecj8JqTKGF5dFhNBq9btVWGBClSy1n9b2zqbD47auxxW8mCw3d9QwfQSI W90w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tM9upgeD; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w13si7272717edv.50.2020.11.09.05.33.49; Mon, 09 Nov 2020 05:34:13 -0800 (PST) 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=@kernel.org header.s=default header.b=tM9upgeD; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732242AbgKINa1 (ORCPT + 99 others); Mon, 9 Nov 2020 08:30:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:36584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731172AbgKINLI (ORCPT ); Mon, 9 Nov 2020 08:11:08 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BB1412083B; Mon, 9 Nov 2020 13:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927467; bh=JjnGyfOU+bbL945u0KT2+6VtCgEeYRNzkIyX7bBv24c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tM9upgeDFcY+iTTjQGELDGjvhfmYIHNUD08kLqb6DSJFCBby+G17+xYtwK8oXM6AO houwqTRm1OY6+/h2HK16tfKyvOCoovlqSH0OvgOrrueYiRgYjQy5OAKq26avH1ISRF yWdiRAIR+GEKA8EiW4oVUDPhDufGdGPWDj7XeJrQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jason Gunthorpe , Andrew Morton , Arnd Bergmann , Tom Lendacky , Thomas Gleixner , Andrey Ryabinin , Borislav Petkov , Brijesh Singh , Jonathan Corbet , Dmitry Vyukov , "Dave Young" , Alexander Potapenko , Konrad Rzeszutek Wilk , Andy Lutomirski , Larry Woodman , Matt Fleming , Ingo Molnar , "Michael S. Tsirkin" , Paolo Bonzini , Peter Zijlstra , Rik van Riel , Toshimitsu Kani , Linus Torvalds Subject: [PATCH 4.19 39/71] mm: always have io_remap_pfn_range() set pgprot_decrypted() Date: Mon, 9 Nov 2020 13:55:33 +0100 Message-Id: <20201109125021.750404211@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125019.906191744@linuxfoundation.org> References: <20201109125019.906191744@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gunthorpe commit f8f6ae5d077a9bdaf5cbf2ac960a5d1a04b47482 upstream. The purpose of io_remap_pfn_range() is to map IO memory, such as a memory mapped IO exposed through a PCI BAR. IO devices do not understand encryption, so this memory must always be decrypted. Automatically call pgprot_decrypted() as part of the generic implementation. This fixes a bug where enabling AMD SME causes subsystems, such as RDMA, using io_remap_pfn_range() to expose BAR pages to user space to fail. The CPU will encrypt access to those BAR pages instead of passing unencrypted IO directly to the device. Places not mapping IO should use remap_pfn_range(). Fixes: aca20d546214 ("x86/mm: Add support to make use of Secure Memory Encryption") Signed-off-by: Jason Gunthorpe Signed-off-by: Andrew Morton Cc: Arnd Bergmann Cc: Tom Lendacky Cc: Thomas Gleixner Cc: Andrey Ryabinin Cc: Borislav Petkov Cc: Brijesh Singh Cc: Jonathan Corbet Cc: Dmitry Vyukov Cc: "Dave Young" Cc: Alexander Potapenko Cc: Konrad Rzeszutek Wilk Cc: Andy Lutomirski Cc: Larry Woodman Cc: Matt Fleming Cc: Ingo Molnar Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Peter Zijlstra Cc: Rik van Riel Cc: Toshimitsu Kani Cc: Link: https://lkml.kernel.org/r/0-v1-025d64bdf6c4+e-amd_sme_fix_jgg@nvidia.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/asm-generic/pgtable.h | 4 ---- include/linux/mm.h | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -1115,10 +1115,6 @@ static inline bool arch_has_pfn_modify_c #endif /* !__ASSEMBLY__ */ -#ifndef io_remap_pfn_range -#define io_remap_pfn_range remap_pfn_range -#endif - #ifndef has_transparent_hugepage #ifdef CONFIG_TRANSPARENT_HUGEPAGE #define has_transparent_hugepage() 1 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2561,6 +2561,15 @@ static inline vm_fault_t vmf_insert_pfn( return VM_FAULT_NOPAGE; } +#ifndef io_remap_pfn_range +static inline int io_remap_pfn_range(struct vm_area_struct *vma, + unsigned long addr, unsigned long pfn, + unsigned long size, pgprot_t prot) +{ + return remap_pfn_range(vma, addr, pfn, size, pgprot_decrypted(prot)); +} +#endif + static inline vm_fault_t vmf_error(int err) { if (err == -ENOMEM)