Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1243443imm; Thu, 4 Oct 2018 10:18:29 -0700 (PDT) X-Google-Smtp-Source: ACcGV61oHxSMfzK28SlHUTc4m25pHyTj3Jqm9YAYVYFq0aLLuFeAHkqz7XunuRfuD6YKBHHvW4dH X-Received: by 2002:a62:ac15:: with SMTP id v21-v6mr7801277pfe.126.1538673509238; Thu, 04 Oct 2018 10:18:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538673509; cv=none; d=google.com; s=arc-20160816; b=J1ddP5X8dGO1fcjoQbNI+WorFZlQfNd+p6yMFVfl5OByXDyrCynglEFCfHLrA1rMi3 agufFn56n6RUoE5mjPd3Rp+6yG8gEmoiqNcCsgfqGCd3w/kQ7/eERTMtjNbWMFe188eh Mml/+QRyM7FWabYUIf/mdOyI6rnSahVe2bQhvCzDtTXmzbeLQevJk1vZ791FBS3Wg+vL nQezKenUkrl949ECt7lxo4t6im23+KaAV+0hN+o1s/ZL0AbhDyEsPFQ23GfBOqQFCjCp /uz1d7Zk0yLn3tXuw7DqZ6cfMvcJh6Br7LfKhxAnvK20uzyjmvc6uQNmPwJcwmzd5xT2 k/Hg== 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 :content-language:mime-version:user-agent:date:message-id:subject :from:cc:to:dkim-signature; bh=oo7jFiHcdzxADLMPn/9lwDjBHVOhycYpZbjFcA/Avc4=; b=vOGAK4S0PaYNMCelwuLzZzK60vEsLoWakc//zen4Rz9Py6y091rWQQBKnUVoDIcSS5 oTjS6i8rUQfAy+Iz2Qd+fehwN1fQOz946RzAlz6jYw2i1RfkeLWKgnhHts4NpwErH+Tc s24pyA9ZOo2A86CwpMuM2YeguzLNeXdlZRArwNB22aBl92qziN855OEjmaCyY+qS8NID YWr47IAzfUufiNoLyscjOed5XVERPQ+fMtjh26/VFjSc5t+fCvLuNpO5eiDgHep9qLcc iOArPzPrFnA7UUmWKGzH1RjymIfzP78evTpDEi/QSlaDzUYanQISphmhppgffNEgXaFw BN5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=vDgHsprl; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e21-v6si4740811pgk.311.2018.10.04.10.18.13; Thu, 04 Oct 2018 10:18: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=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=vDgHsprl; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727959AbeJEALu (ORCPT + 99 others); Thu, 4 Oct 2018 20:11:50 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:51690 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727489AbeJEALu (ORCPT ); Thu, 4 Oct 2018 20:11:50 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w94H9Tbo043457; Thu, 4 Oct 2018 17:17:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=oo7jFiHcdzxADLMPn/9lwDjBHVOhycYpZbjFcA/Avc4=; b=vDgHsprllu3IQ3mPujLpmdIZE5+iFORsdrOcjESj7g+8Txk4x599g0yOuJcC+hs1BXtT YuOykJKjdnVpGL8iphWcRNVuxWVjGWye+8HBzJ/25q9OCLKbz/jGn+QRK5kWRMPHNX1j g3YP/OtKjIbLQ58xjl4woexGhMhDv7H7euSbnRSRxF6bFubsrEp57pBHRpgIM/Wzkybb 38QfFU6/6DM+nhnG4RIjtDl5jboO6HZt2qAQfCm+8AVeub7WYh5FqrUBEC6Y9p461YuL e6j0TwnLPG4JJQAyKYPbcEdB3gttYZIJsS1g/W0OESmDnPKonBhZx8/TbB2X3LGCXcoN /A== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2mt0tu5rbc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 04 Oct 2018 17:17:35 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w94HHYGi002704 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 4 Oct 2018 17:17:34 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w94HHX20010944; Thu, 4 Oct 2018 17:17:33 GMT Received: from anastasis.us.oracle.com (/10.152.36.80) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 04 Oct 2018 17:17:33 +0000 To: "Lendacky, Thomas" , "Singh, Brijesh" Cc: gregkh@linuxfoundation.org, Linux Kernel Mailing List From: James Puthukattukaran Subject: [PATCH 0/1] drivers/char/mem.c: Disable encryption bit in page tables for MMIO access Message-ID: <671c6651-71b3-0e0d-8e87-191ca14fed50@oracle.com> Date: Thu, 4 Oct 2018 13:17:26 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9036 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=615 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810040159 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On AMD based systems, mmap'ing a PCI MMIO region does not return proper values. This is because the mmap_mem function does not consider the fact that IO regions are not to be encrypted. In the failing kernel, here's the output -- [root@foo]# ./memaccess 0xd0000000 -t pmem -l 32 0 (0 ) : ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 10 (16 ) : ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff I instrumented the kernel to print out the PTE value -- Jun 20 11:46:35 bur-e1-2l-303 kernel: pfn = 0xfffffff80f0866b2, vma->pgoff = 0xd 0000, flags = 0x5044471, prot = 0x8000800000000025 Jun 20 11:46:35 bur-e1-2l-303 kernel: pte = 0x80008000d0000235, pfn = 0xd0000 Note that 0x8000800000000025 -- bit 47 is set. It should not be set for a MMIO region. When I disable memory encryption (mem_encrypt=off command line), things work as they should. [root@foo]# ./memaccess 0xd0000000 -t pmem -l 32 0 (0 ) : 20 00 00 01 40 08 00 04 f1 00 00 14 0a 00 ff 07 10 (16 ) : 65 f6 70 02 c0 05 00 00 a0 04 00 00 0b 00 00 00 James Puthukattukaran(1): drivers/char/mem.c: Disable encryption bit in page tables for MMIO access drivers/char/mem.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)