Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3098344pxk; Mon, 7 Sep 2020 03:11:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvDE9OixXZjw9ReOILLou1Tg9x32JzNAWSYnpGBbhLqfubBXmaEz4Aco8+thqMpj6a1Srk X-Received: by 2002:a17:906:aecb:: with SMTP id me11mr13842917ejb.217.1599473476508; Mon, 07 Sep 2020 03:11:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599473476; cv=none; d=google.com; s=arc-20160816; b=QZOdh9Eg2F+EB7xAtuQ95jsnQQq2AWVXIs9BgsJGzyKcoaMSGnoLKuOYBPI37gqt8j CEry9KsZA22Qm/PFdWm5irN57XztXX3DRWcjgE16pHCxszsGWvUyv7C1H4UZ3LYrRCHQ vKw/1zbfYDzB8+nt9lI9y4DvfNI/EqhrPiR1inmpncwfqL4HxT5IAG0Qh96VaS0XKnK6 l8b6X/AsxQBAk2vvwHADuYLztb67zGHYVSaQJKNSlQBTO5Vtc1/hI2/8FNbcA8SAksAj UK23MoGMBM/Yq24RNnytr4M2XBZSbHQja+zelBYSr5Ti9dPXWM2rJnOLqu+35FsO8qJl 1aTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Vtl+A0qx36dIZ5gAbOvsPuPdPzUYN1nzw9jx7enAr58=; b=kV5zQyrgxmXBAZa34SCfxHGTOK//icXgxqym7V4VUJJLSAK2naD104AmuabgZaihDL 8/3Ob1wUzf7OLyI17jwDU9IFg6dNyACUTx/F8n2kcFIUnQAyP/WoPyM3LaNcyZEcgNkA EcdkAeA9MpmDCUYpDj1Z1Om7Oul9aWn/2nXvnmVjv4JIUNpajYcgtLhJd6gUDTcFGwA8 OYY39m5gQMVa1iiy7dCc7Gwuxku9u584s9flklhwmj+dUdabR7KsiBUkcgNDuBIYxNgr ijKgF27NAHBCzX5keev1l2L9fAszWZo2s0pA5mQvXc8acyXsnkcvq9di67P7AtThw6RZ s6pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wTjARGHH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x43si11284803ede.268.2020.09.07.03.10.53; Mon, 07 Sep 2020 03:11:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wTjARGHH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728456AbgIGKKJ (ORCPT + 99 others); Mon, 7 Sep 2020 06:10:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:50180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728317AbgIGKKJ (ORCPT ); Mon, 7 Sep 2020 06:10:09 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (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 E7856207C3; Mon, 7 Sep 2020 10:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599473408; bh=DdyKvDduyIm5+OD9DDXx1sFF7tQydimT+2MR9Bk8azY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=wTjARGHH8jiZcyHd46LUsbd3HkMbc5+QZspww7sL89c1XY8KxDrHWUE5ViYX7oj2E OBv5Mub8sM2uw46ba0922NnR6v8cSmKALYTVlgj8OeYRYVEA5XEt3IvsjQWWctgs+O WnsE2DOQr+M+9a6IY2uBULDHSPtTT7hXIP7bNPv0= Date: Mon, 7 Sep 2020 11:10:03 +0100 From: Will Deacon To: Oli Swede Cc: Catalin Marinas , Robin Murphy , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 00/14] arm64: Optimise and update memcpy, user copy and string routines Message-ID: <20200907101003.GA11970@willie-the-truck> References: <20200630194822.1082-1-oli.swede@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Oli, Thanks for this. Just a few high-level comments below. On Wed, Jul 01, 2020 at 09:12:49AM +0100, Oli Swede wrote: > > Version 3 addressed this but I later found some issues with the fixup > > correctness after further testing, and have partially re-written them > > here, and addressed some other behaviours of the copy algorithm. [...] > I am waiting on access to the relevant machine before posting the benchmark > results for this optimized memcpy, but Sam reported the following with the > similar (but now slightly older) cortex-strings version: > * copy_from_user: 13.17% > * copy_to_user: 4.8% > * memcpy: 27.88% > * copy_in_user: Didn't appear in the test results. > This machine will also be used to check the fixups are accurate on a system > with UAO - they appear to be exact on a non-UAO system with PAN that I've > been working on locally. I'm inclined to say that cortex-strings is probably not a good basis for our uaccess routines. The code needs to be adapted in a non-straightforward way so that we lose pretty much all of the benefits we'd usually get from adopted an existing implementation; we can't pull in fixes or improvements without a lot of manual effort, we can't reuse existing testing infrastructure (see below) and we end up being a "second-class" user of the routines because of the discrepancies in implementation. So why don't we use cortex-strings as a basis for the in-kernel routines only, preferably in a form where the code can be used directly and updated with a script (e.g. similar to how we pull in arch/arm64/crypto routines from OpenSSL). We can then roll our own uaccess routines, using a slightly more straight-forward implementation which is more amenable to handling user faults and doesn't do things like over copying. > I should also mention that the correctness of these routines were tested > using a selftest test module akin to lib/test_user_copy.c (whose usercopy > functionality checks these patches do pass) but which is more specific to > the fixup accuracy, in that it compares the return value with the true > number of bytes remaining in the destination buffer at the point of a fault. Can we put this test module into the kernel source tree, please, maybe as part of lkdtm? Given the control flow of these optimised functions, I think we absolutely need targetted testing to make sure we're getting complete coverage. Will