From patchwork Wed May 24 21:42:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 9747065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 29F2A60388 for ; Wed, 24 May 2017 21:44:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C8EF26E1A for ; Wed, 24 May 2017 21:44:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1143326E4E; Wed, 24 May 2017 21:44:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88BA726E4D for ; Wed, 24 May 2017 21:44:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031382AbdEXVop (ORCPT ); Wed, 24 May 2017 17:44:45 -0400 Received: from ale.deltatee.com ([207.54.116.67]:37003 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033572AbdEXVnV (ORCPT ); Wed, 24 May 2017 17:43:21 -0400 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1dDe3j-0007Gx-6s; Wed, 24 May 2017 15:43:15 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.84_2) (envelope-from ) id 1dDe3f-0004mt-FO; Wed, 24 May 2017 15:43:07 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-nvdimm@lists.01.org, linux-nvme@lists.infradead.org, linux-rdma@vger.kernel.org Cc: Christoph Hellwig , Jason Gunthorpe , Jens Axboe , Dan Williams , Ross Zwisler , Matthew Wilcox , Andrew Morton , Ming Lei , Johannes Berg , Stephen Bates , Sagi Grimberg , Keith Busch , =?UTF-8?q?Christian=20K=C3=B6nig?= , Benjamin Herrenschmidt , Jerome Glisse , Logan Gunthorpe Date: Wed, 24 May 2017 15:42:26 -0600 Message-Id: <1495662147-18277-16-git-send-email-logang@deltatee.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1495662147-18277-1-git-send-email-logang@deltatee.com> References: <1495662147-18277-1-git-send-email-logang@deltatee.com> X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-nvdimm@lists.01.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-rdma@vger.kernel.org, hch@lst.de, jgunthorpe@obsidianresearch.com, axboe@kernel.dk, ross.zwisler@linux.intel.com, mawilcox@microsoft.com, akpm@linux-foundation.org, ming.lei@canonical.com, sbates@raithlin.com, sagi@grimberg.me, dan.j.williams@intel.com, johannes.berg@intel.com, keith.busch@intel.com, christian.koenig@amd.com, benh@kernel.crashing.org, jglisse@redhat.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [RFC PATCH 15/16] dma-mapping: introduce and use unmappable safe sg_virt call X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce sg_try_virt which is safe to call with a potentially unmappable sgl. sg_try_virt returns NULL in cases that the sgl doesn't have an accessible virtual address to return. Then, in dma_map_sg_attrs, we use the new function instead of sg_virt when marking memory as initialized. Signed-off-by: Logan Gunthorpe Signed-off-by: Stephen Bates --- include/linux/dma-mapping.h | 9 +++++++-- include/linux/scatterlist.h | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 4f3eece..5ef1ab5 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -241,8 +241,13 @@ static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg, int i, ents; struct scatterlist *s; - for_each_sg(sg, s, nents, i) - kmemcheck_mark_initialized(sg_virt(s), s->length); + for_each_sg(sg, s, nents, i) { + void *addr = sg_try_virt(sg); + + if (addr) + kmemcheck_mark_initialized(addr, s->length); + } + BUG_ON(!valid_dma_direction(dir)); ents = ops->map_sg(dev, sg, nents, dir, attrs); BUG_ON(ents < 0); diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 2c54c6c..1e11af9 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -298,6 +298,22 @@ static inline void *sg_virt(struct scatterlist *sg) return page_address(sg_page(sg)) + sg->offset; } +/** + * sg_try_virt - Return virtual address of an sg entry or NULL if it is + * unmappable + * @sg: SG entry + * + * Description: + * This is the same as sg_virt but is safe to call with unmappable + * memory. This function will return NULL in case the sg is is + * unmappable. + * + **/ +static inline void *sg_try_virt(struct scatterlist *sg) +{ + return pfn_t_to_virt(sg->__pfn); +} + int sg_nents(struct scatterlist *sg); int sg_nents_for_len(struct scatterlist *sg, u64 len); struct scatterlist *sg_next(struct scatterlist *);