Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2409782imu; Thu, 10 Jan 2019 13:46:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN5aK5BrPrAGiMQhKpmsOpmnz87LsBsZ4TTSA+NBC+zv6L+A5SQclkkr6Tjb/UTZoT0I/gjg X-Received: by 2002:a17:902:aa4c:: with SMTP id c12mr11930850plr.48.1547156801879; Thu, 10 Jan 2019 13:46:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547156801; cv=none; d=google.com; s=arc-20160816; b=Mc6PeCwciZYVAaPCO29wkxSAvxplAFmNqw51yj0n7j2N4cPgcbhJlQ87WfNvvPDdvB 9BCR3Ecf5CXOHnjE4SLWpuvhENDGJBIwIxak2GZoZmqEqhVrP1LJr60+hHDaZWsAZx0Q +iRmYc6C88Tskt6Zk0Z1pSm4NNiU/Mr7zDQII1oLaFSBeP5NLFAUMYP+5IKR6mc3K/Pe eEaUUYGIu2Jzc3CrjfVb9N0FwyS82Y/9GmjLFKXG57weqzMfRxXYMItF2TARujRWd049 SLyAxTuvXSoMuP9iptEIgLfARLAqRt/RUdcS+hAEDs7aFyokzdGkiT1pqcAU6lzaA9CK RweA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=65bJHm+xMDUqKLWlJszEVdy7uVRxf98qoGoZGFoK+HQ=; b=AEBgfA4JuLCLUtftIvg+0BVmF1ooOxVB3tsQuseGEaaWLbR21yjM9UArbn8I1udKB9 YrPWWaygG2+OHalDkrtw1x6QB56gakSR54YQRs+lk+UGdJ9GrzSI4S8udny5ycv5lNoM DmwPVkRNTDmM0iACxuMmwmou5KC1NAb4H7UqS45rBYUAjLkcYp/CK2CXunjRQFOo2M0N 2UmglhKit7I2NPLnZbA/fWbyCrK1E4bRQtdjlkPOSgAulBJRXaLz/kRbJoviyTvr9zpz SSA7gR8Dd3jmhINoDEiKwPKT0P9VJdArzuZizJCcRYaXnOAnR56x12T4+jvH5LFcY1QH O5kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=QOSqm8Zv; 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 b5si9601035plr.355.2019.01.10.13.46.25; Thu, 10 Jan 2019 13:46:41 -0800 (PST) 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=QOSqm8Zv; 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 S1731059AbfAJVLJ (ORCPT + 99 others); Thu, 10 Jan 2019 16:11:09 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:56926 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729343AbfAJVLH (ORCPT ); Thu, 10 Jan 2019 16:11:07 -0500 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 x0AL8vZq041442; Thu, 10 Jan 2019 21:10:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2018-07-02; bh=65bJHm+xMDUqKLWlJszEVdy7uVRxf98qoGoZGFoK+HQ=; b=QOSqm8Zv7K4bMlhX/bbVjgLCNRTn/vGcgXRjPQDdCQ2rFWjC1jE5LPhpr0gENIIpwgu4 sz7a/UkbO23yDajdO+GXR034Mh5eIOQRKEWxMBO/MAWFMXDnD44/asxTyfBHnplQOl0/ xM03rfATk55d2MsnRnzeazoyMfZVlBG4lqi/QcaOe1G7JZs0hWiPGt4/F0RYcVJehdPd uFq1W6pfDY2BTLS1yXN5jW84mKURQytSbef5qWfTdzHCQRpyD5+DDzP6AlTYUpdvzBB5 J6YveHf8bzwo5ZZ7E9OElu46qdWTWUcuaaJLnoelH74Dj/mMvWz23RVaHcEkpd6Hf45P yg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2ptm0uhnu3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Jan 2019 21:10:22 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0ALALtI011630 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Jan 2019 21:10:21 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x0ALAK3i021200; Thu, 10 Jan 2019 21:10:20 GMT Received: from concerto.internal (/24.9.64.241) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 10 Jan 2019 13:10:20 -0800 From: Khalid Aziz To: juergh@gmail.com, tycho@tycho.ws, jsteckli@amazon.de, ak@linux.intel.com, torvalds@linux-foundation.org, liran.alon@oracle.com, keescook@google.com, konrad.wilk@oracle.com Cc: Juerg Haefliger , deepa.srinivasan@oracle.com, chris.hyser@oracle.com, tyhicks@canonical.com, dwmw@amazon.co.uk, andrew.cooper3@citrix.com, jcm@redhat.com, boris.ostrovsky@oracle.com, kanth.ghatraju@oracle.com, joao.m.martins@oracle.com, jmattson@google.com, pradeep.vincent@oracle.com, john.haxby@oracle.com, tglx@linutronix.de, kirill.shutemov@linux.intel.com, hch@lst.de, steven.sistare@oracle.com, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Tycho Andersen , Khalid Aziz Subject: [RFC PATCH v7 04/16] swiotlb: Map the buffer if it was unmapped by XPFO Date: Thu, 10 Jan 2019 14:09:36 -0700 Message-Id: <98f9b9be522d694d5a52640dd1dfbdd14ca6f8e5.1547153058.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9132 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=868 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901100164 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juerg Haefliger v6: * guard against lookup_xpfo() returning NULL CC: Konrad Rzeszutek Wilk Signed-off-by: Juerg Haefliger Signed-off-by: Tycho Andersen Signed-off-by: Khalid Aziz --- include/linux/xpfo.h | 4 ++++ kernel/dma/swiotlb.c | 3 ++- mm/xpfo.c | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/linux/xpfo.h b/include/linux/xpfo.h index a39259ce0174..e38b823f44e3 100644 --- a/include/linux/xpfo.h +++ b/include/linux/xpfo.h @@ -35,6 +35,8 @@ void xpfo_kunmap(void *kaddr, struct page *page); void xpfo_alloc_pages(struct page *page, int order, gfp_t gfp); void xpfo_free_pages(struct page *page, int order); +bool xpfo_page_is_unmapped(struct page *page); + #else /* !CONFIG_XPFO */ static inline void xpfo_kmap(void *kaddr, struct page *page) { } @@ -42,6 +44,8 @@ static inline void xpfo_kunmap(void *kaddr, struct page *page) { } static inline void xpfo_alloc_pages(struct page *page, int order, gfp_t gfp) { } static inline void xpfo_free_pages(struct page *page, int order) { } +static inline bool xpfo_page_is_unmapped(struct page *page) { return false; } + #endif /* CONFIG_XPFO */ #endif /* _LINUX_XPFO_H */ diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 045930e32c0e..820a54b57491 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -396,8 +396,9 @@ static void swiotlb_bounce(phys_addr_t orig_addr, phys_addr_t tlb_addr, { unsigned long pfn = PFN_DOWN(orig_addr); unsigned char *vaddr = phys_to_virt(tlb_addr); + struct page *page = pfn_to_page(pfn); - if (PageHighMem(pfn_to_page(pfn))) { + if (PageHighMem(page) || xpfo_page_is_unmapped(page)) { /* The buffer does not have a mapping. Map it in and copy */ unsigned int offset = orig_addr & ~PAGE_MASK; char *buffer; diff --git a/mm/xpfo.c b/mm/xpfo.c index bff24afcaa2e..cdbcbac582d5 100644 --- a/mm/xpfo.c +++ b/mm/xpfo.c @@ -220,3 +220,18 @@ void xpfo_kunmap(void *kaddr, struct page *page) spin_unlock(&xpfo->maplock); } EXPORT_SYMBOL(xpfo_kunmap); + +bool xpfo_page_is_unmapped(struct page *page) +{ + struct xpfo *xpfo; + + if (!static_branch_unlikely(&xpfo_inited)) + return false; + + xpfo = lookup_xpfo(page); + if (unlikely(!xpfo) && !xpfo->inited) + return false; + + return test_bit(XPFO_PAGE_UNMAPPED, &xpfo->flags); +} +EXPORT_SYMBOL(xpfo_page_is_unmapped); -- 2.17.1