Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp268148ybi; Wed, 29 May 2019 21:02:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmFDlZYi29r0coPRGVSGuYRfI+8mZk11mqhTsQ/FkJgT54WeG5lQ7qin+fpeydnJmMfgLa X-Received: by 2002:a63:1460:: with SMTP id 32mr1829216pgu.319.1559188935490; Wed, 29 May 2019 21:02:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559188935; cv=none; d=google.com; s=arc-20160816; b=wccvzXfHXvxzHvic/EPgv1ZZ7xD+XdzN3/cOEJyDapgp71ub4hjPwS4X1j5dIagnV+ eMKT8tnAXFa3YE8ss+JiYnoZcatA/iAmNsulrOdJwZkf/RoLCBHWautEvXfMR3p8Q1zy wZOFrBUU1XJFzGClSP5oTrSxy0/kTLNqxMX9cx28uTyvB7jow3SMaBOJ4j4CkcFo6+nm VtvYPIV3/vFFksDMJT24WjHrmV4TSNQxFCXWlq4+s3rcxAPXJpNfadLJK+4LL6x9qHab u7hbRcBTyz1/h4vnb9lFyLEmCeIjQF6doMg4U44nTaj0pfogN7v1xEnoWeTIzrpeoVUR qeng== 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=lipyyEFea56X//t40VzOiKVOlZZPt74+1qzyy3FFXws=; b=jtyMuchbQgUKEngVonuNK1dWT5xa7/2m/uCIfXUA8GKoCQHgt5xyWIzjqmdLCUp3N4 JmcZRAgVY1rzzoQ0azECMslOxAjM2S6dGr3/TqkB8+LEzYIHM/gxicQmKhYAFVS2cB3q mPmFLRjl9Nv0jbeARKwJSe/xSj2ulB4hgDyaxVipX6kQToQLrAvB1He4JTBiF1srPMJb MJEtOaxV34u+VSGsYbg5Grwb3XWrLpGV73qMqbuww3SuuSU/uV1UafIcVKv5M1ltD4OQ VJar2DudqKzG0VYdHRbo0MyucNEbHbnGnPWe9H8VzveWp+VSZU4aFlVTgZTkno/kNspB GrHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="BQUAR/xq"; 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 i96si2188320plb.210.2019.05.29.21.01.59; Wed, 29 May 2019 21:02:15 -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="BQUAR/xq"; 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 S2387683AbfE3D7s (ORCPT + 99 others); Wed, 29 May 2019 23:59:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:50856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731578AbfE3DSc (ORCPT ); Wed, 29 May 2019 23:18:32 -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 74BBF24790; Thu, 30 May 2019 03:18:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186311; bh=SZYgzCSl2InSQyrNHF2tnU1aOYnCmJ61nTCrd7r9g6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BQUAR/xqK6RxP3+NV4Qk8g+1rTEZBQ+ber4m0W7tVWbUdwZd8o1tBssMQGin41ONj gJVfqoUZ+0o8Rap3t0q1P7e6ixyXCsNGjDpEAzXIe2ZAHTPiiFgBg4/sLdCxhe3jPm TuHnDV72249WK0Bk4yR+EEn3pXhuVwyc4EJW01wo= 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.14 012/193] libnvdimm/pmem: Bypass CONFIG_HARDENED_USERCOPY overhead Date: Wed, 29 May 2019 20:04:26 -0700 Message-Id: <20190530030449.639898524@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030446.953835040@linuxfoundation.org> References: <20190530030446.953835040@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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -256,10 +256,16 @@ 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 const struct dax_operations pmem_dax_ops = {