Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3194914pxb; Mon, 9 Nov 2020 05:19:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlmkOdgGzRz21/uepIP8tpGQ+8lkktx1ZAwRg2oevsclhNuLrghf3YFZ5uQvAaSVZz1EGZ X-Received: by 2002:aa7:cb4a:: with SMTP id w10mr15531888edt.343.1604927958143; Mon, 09 Nov 2020 05:19:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604927958; cv=none; d=google.com; s=arc-20160816; b=PIdDqProJe4tKvRHkbJlY8K6L0Pmz0x2SRmbyVnTTy0hNGb8qrPeYmzQTNPnGdFxtI z7NUFmqmczStkIxgYHj8Sb+dLWMumcsv2z/7xJsur0D6tw4M9BkGXu/LrnB9ghQeh75z T8a6qdUntEf9izKrLQXGhS5U+C9wp4NE/7TAd8DGmsRzp6g+zCFzYB6m4+blfc3PTK1R CBdpA9eQJ3uCs1mhZPSRMhLYVrOQvhKcd9mzzKBWcDpdGKQ2DAUpcP1Y9SkpbyCkeC8p HcYFRbPGWaksBXqJgoVcTIKH6hF1mR8kXosUZ/KMkQXmy4LI/ya1DBK2iertQn1Yk5Nj tP2w== 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=KpmSc/R5TmQSIPbY9yfghJugDGnsuRhOyi7h6UOuwMk=; b=xrKTj4nl0ShNWNboVAuEfnE83TrwOErN9yjzHH3wn0QrHU4FF38tqjhxWfpalV4kXM eTnzOpMs+I2OkNTQoSOcZp8c9JF8+aUzgU09jpmKPIVxclgsNruCvOGivk2hPjyJQtid DSISRjVtSLHNpRGMTsw8qmnghfkN1S66W3MRhC62ophAikbsoc9ipipvMq0YlRvg2wMs uiaDlhdGU2a34bRHUeLCPhOK7rFOqL2yIXkAHuY6ad83eH6wmoz6o4A0phtuLmmbtqkV ZPdv5PMhnzIbEjF/iEHD818PLRVVLEQIiyoxU2SYoQqGxhqOtjOK6cg3O3XrWqlVglEZ hzCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2QBP159T; 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 bt25si7438020ejb.507.2020.11.09.05.18.55; Mon, 09 Nov 2020 05:19:18 -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=2QBP159T; 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 S1733113AbgKINOT (ORCPT + 99 others); Mon, 9 Nov 2020 08:14:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:40490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733081AbgKINOR (ORCPT ); Mon, 9 Nov 2020 08:14:17 -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 5E07F20789; Mon, 9 Nov 2020 13:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927656; bh=bK0eA8aSpbq9muPoWFg3cufloAyog7Fgs0x//VCAWwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2QBP159TmzVO+4Bh2rbooAVgzuEg31nJJGvXrRVHM5T4GHm5haAUwvamzV+CON6OT 6EJmuSZv9pyY7iylJ61njWr0IiRnS8NVTSzpGONol0hHYEtMIIJaZCZPhh0wv5xgwh /bIj3A8MlQIRQoUANdQ1URCjRfDqeGHSevmI7Ui8= 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 5.4 32/85] mm: always have io_remap_pfn_range() set pgprot_decrypted() Date: Mon, 9 Nov 2020 13:55:29 +0100 Message-Id: <20201109125024.129102104@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125022.614792961@linuxfoundation.org> References: <20201109125022.614792961@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 @@ -1159,10 +1159,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 @@ -2572,6 +2572,15 @@ static inline vm_fault_t vmf_insert_page 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)