Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp257474ybi; Wed, 29 May 2019 20:48:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqywIoZ4sSTW09pYVmqdmLwlIwbwC/TuBWLRvBkdNC43zYH3kKwfyUDI7RH94pfCsl0Y0OZ2 X-Received: by 2002:a63:f551:: with SMTP id e17mr1770772pgk.329.1559188106705; Wed, 29 May 2019 20:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559188106; cv=none; d=google.com; s=arc-20160816; b=k4zyxLW5UeW68MMvf2B73CNzvb0EpFTGAaMykWy+dSMIS8a2dgtraU63IHeCqo9BL9 ZPA4VBYNKscaAQl49jaP3u7ramb6xdYophCPfOK/2NG5egbU1R2JHfNStTkhZ/Hu0O5z 4iTMlzMYJu4sTF5quoZQofgyafJUwY65kWOPeb/N8LM2j1yJEQg8s8DGMiDF7FliDMn7 EEzj1hxhmSUsF98IXerOM3irM69MaB0YxQr0ElSSdymnfGUZxecKsEnvRSD4xlsYwN/C rCHhyciru3TF9AZ0MOXmCgKWiDIDi8lLLnukFG3MsacVjZkajc5tHAb+cHROlq1QjB82 K7GA== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IH8YqBagRhR7JWNYtnUniqxBCXqp9HxToSrwEZ72d34=; b=gfvHygii23l786Aw8y41JTbQnOVw/tUZAmyDx/Tbmq3lCeEERJJgr5Zb8PrXGX73kG o0pcPs1atUPePeOUSvYjyefifcbU1/w1tV1xFFKPlpJV7byHzxYyBl9Y9me/s8/UyU2Y otgqe3YjatKC8BrX2PV5QOtEoP2dkr9td8M2xzStcVqWtR+99/wiMYnZldq8cndlvHSD WvjxtN6lTy9kSnYWzcCY+bJ8mL36mTreXOkJw2ZQ3JuTF0XQXVznye0C1AB07r5wc4wg GYhZFYD1EuSLdMu/EsHZSW1lrUwLsc94TKBxO7YR6ilwSvOL4jNQ4qKRcpZzQeosV/HL /05A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OCcHcFya; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k29si1990813pgl.157.2019.05.29.20.48.10; Wed, 29 May 2019 20:48:26 -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=@kernel.org header.s=default header.b=OCcHcFya; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732351AbfE3DUt (ORCPT + 99 others); Wed, 29 May 2019 23:20:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:41138 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730576AbfE3DQE (ORCPT ); Wed, 29 May 2019 23:16:04 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 765DB24595; Thu, 30 May 2019 03:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186163; bh=7RcEOH/HE3JXRnzDunkFCAZCXEfpzCP3ZZnCtC8r6qM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OCcHcFyapajxI1bQZjIwpsLhKHTl9oH/tzemVrk1z66OR+61cchTJnynY6e33ibSg gKadIq3HmsNjHwu61WKU0D2uwIddCu1/rAfi/WF6+J4EC9cSecEP3iv3HiVU8eZhZP PbL0sbayhD9UKhyrYZUr85mya3a6OHE/JDuXI8u8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeff Moyer , Ingo Molnar , Christoph Hellwig , Al Viro , Thomas Gleixner , Matthew Wilcox , Kees Cook , Jan Kara , Dan Williams , Jeff Smits Subject: [PATCH 4.19 013/276] libnvdimm/pmem: Bypass CONFIG_HARDENED_USERCOPY overhead Date: Wed, 29 May 2019 20:02:51 -0700 Message-Id: <20190530030524.620870608@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Williams commit 52f476a323f9efc959be1c890d0cdcf12e1582e0 upstream. Jeff discovered that performance improves from ~375K iops to ~519K iops on a simple psync-write fio workload when moving the location of 'struct page' from the default PMEM location to DRAM. This result is surprising because the expectation is that 'struct page' for dax is only needed for third party references to dax mappings. For example, a dax-mapped buffer passed to another system call for direct-I/O requires 'struct page' for sending the request down the driver stack and pinning the page. There is no usage of 'struct page' for first party access to a file via read(2)/write(2) and friends. However, this "no page needed" expectation is violated by CONFIG_HARDENED_USERCOPY and the check_copy_size() performed in copy_from_iter_full_nocache() and copy_to_iter_mcsafe(). The check_heap_object() helper routine assumes the buffer is backed by a slab allocator (DRAM) page and applies some checks. Those checks are invalid, dax pages do not originate from the slab, and redundant, dax_iomap_actor() has already validated that the I/O is within bounds. Specifically that routine validates that the logical file offset is within bounds of the file, then it does a sector-to-pfn translation which validates that the physical mapping is within bounds of the block device. Bypass additional hardened usercopy overhead and call the 'no check' versions of the copy_{to,from}_iter operations directly. Fixes: 0aed55af8834 ("x86, uaccess: introduce copy_from_iter_flushcache...") Cc: Cc: Jeff Moyer Cc: Ingo Molnar Cc: Christoph Hellwig Cc: Al Viro Cc: Thomas Gleixner Cc: Matthew Wilcox Reported-and-tested-by: Jeff Smits Acked-by: Kees Cook Acked-by: Jan Kara Signed-off-by: Dan Williams Signed-off-by: Greg Kroah-Hartman --- drivers/nvdimm/pmem.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -281,16 +281,22 @@ static long pmem_dax_direct_access(struc return __pmem_direct_access(pmem, pgoff, nr_pages, kaddr, pfn); } +/* + * Use the 'no check' versions of copy_from_iter_flushcache() and + * copy_to_iter_mcsafe() to bypass HARDENED_USERCOPY overhead. Bounds + * checking, both file offset and device offset, is handled by + * dax_iomap_actor() + */ static size_t pmem_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i) { - return copy_from_iter_flushcache(addr, bytes, i); + return _copy_from_iter_flushcache(addr, bytes, i); } static size_t pmem_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i) { - return copy_to_iter_mcsafe(addr, bytes, i); + return _copy_to_iter_mcsafe(addr, bytes, i); } static const struct dax_operations pmem_dax_ops = {