Received: by 10.223.176.46 with SMTP id f43csp1836039wra; Thu, 25 Jan 2018 00:34:01 -0800 (PST) X-Google-Smtp-Source: AH8x226h6DzoDGcEHtog6xENFa4tofvYyPYDbK+t9p+B8tlEcL1Ee+P6fZN/aIklbKoqN3/8Kfog X-Received: by 10.98.236.93 with SMTP id k90mr15531188pfh.35.1516869241328; Thu, 25 Jan 2018 00:34:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516869241; cv=none; d=google.com; s=arc-20160816; b=IrtvK4gIPUNfbnyaogzEdVtC/MFYf8Oo8lx2ZhBjCqrQqTX07PODwWnK1x7AaEsNLa lI6C+ewU9OaRDqEgQ3TOr6WT06+AysDHvfVejJO19zf9u2WPMs7P88hIqPCWFa1w3pUe oE1tNLGE9/RrVfR8PcTZemwuCY735yS1vFArqIR2umafyMzJXCn6WKfwxNiaCgWwuRfN pXseeubfg4XQX/3Q6ewFQmafTew+5Y64xCAFj4s/ghUr2bfqnmp8bCC6fmFLF4L3xHwF yHNHphKUK2aZX+A12JdfQxjxGH6eDMsCmVy4e6fKwEcOkQg4KRx0XR24h8qFVcqLTp4q lfyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=QRwalO3QVr2F2IdbXATy1nnPmgQO7Dk5zNj46iZxtEo=; b=IMa8GVlCH0i8nlTh8Mg0WBFgpydbqmn3XuF2eJ65Rt7mCKyUPdS0EU08wp3G2cbZP3 7FB88WZd7vf372FjF11Bn4H1ugaCEJKLjKXpX0aKq2gwJXTe9iN59Zt0xIHBFIo++Brs xxQKmvYCIbqD0OeACwWk4GCON3ZDfqNpmUkYciypqnL6nunjM10cr8U3MdharbjOoJ60 zRmv2tNf8sVMae5EtahuIniRWDysTMFLLjZ5Z29ZYKjKbL6cpF+0/74T+Kml4gK5Mkr7 lgzi1ANIsikcnAVyEVBXLlw5j/x45suMDx32W4hwsp+Mjkm5h/Gj9rDdm7A0O+Pqywd+ TV8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jSVUTU5D; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b14si1271434pgu.764.2018.01.25.00.33.46; Thu, 25 Jan 2018 00:34:01 -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=@google.com header.s=20161025 header.b=jSVUTU5D; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751420AbeAYIdN (ORCPT + 99 others); Thu, 25 Jan 2018 03:33:13 -0500 Received: from mail-pf0-f171.google.com ([209.85.192.171]:38606 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751266AbeAYIdM (ORCPT ); Thu, 25 Jan 2018 03:33:12 -0500 Received: by mail-pf0-f171.google.com with SMTP id k19so5269837pfj.5 for ; Thu, 25 Jan 2018 00:33:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=QRwalO3QVr2F2IdbXATy1nnPmgQO7Dk5zNj46iZxtEo=; b=jSVUTU5DhXirA9VAn/AWzRqzYi3cwRUXctBYQBRMVlfuoE2GUBDI2yFSBGIJRwGBY7 nC3Iuvu8l02sb7g5QoWFfFGvSbMj0RrwGQG2QlykieueTM2zss4OSPnKBZJ2Gec33A9h dS1c5gcqNPAYloC3EkdLCgSrSqXDyGDdsuveDuVtGH0wy8pCso1Q0DeY39Jdz7+LBJ5j cRIVWkpy/MbM4KbRH7RQF77rthNP/1PND7OCJ0VkNJaAQIwPoSdp88gVcJXN7fVLhuGW D3edi69RK/0JCZLZeVsADznGG91hih7iNq8TQeqecN6tZcrkuzZhwXDRmoYqjtIY1gGp 9P8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=QRwalO3QVr2F2IdbXATy1nnPmgQO7Dk5zNj46iZxtEo=; b=UMLp4/jurvit1kQ+ujwNvFq3DjiFp1PHVwGn+rf3mccU97E4ZVMDmEfg8/dDMDtrEK 5XhIfvDOsKhg0J/fPoRvvFQpfVLS7jCHQrScG0jfIXQezxAfjVWV/nx6/ySm0qQlLDqq B5tOKSz1eR/7YQMCvcH9u0G9dzm3Bbi0c/y6/79+eOV7K7Z+UU3P6CJF6UyfGFHQIgf8 1AFV5vckj7yfgqoioVSrDNFoXbDMMupA0RwYV8l19qoXT5iSe0NLYhWlzn6k7eBHZAmv fo18TC/N9W57r+imK4zmRC5I5uN9wi/yvvFn3ooJ4/bRLhQXF/H+aLR7zl2YSF65kDhP ZuZw== X-Gm-Message-State: AKwxytdsfalq5F57Uk7V5StS2Je6gb5jZC1E2JrAFdxxdTkWAdl8mHl9 zFrAkzSFAtb0YsLMWIM39PwAVjrT/ob4/9rwOAkSnA== X-Received: by 2002:a17:902:4523:: with SMTP id m32-v6mr2058877pld.449.1516869191444; Thu, 25 Jan 2018 00:33:11 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.140.151 with HTTP; Thu, 25 Jan 2018 00:32:51 -0800 (PST) In-Reply-To: References: <20180109163745.3692-1-aryabinin@virtuozzo.com> <50fcfba8-fc16-b4a1-d117-24ebbe959c0c@virtuozzo.com> From: Dmitry Vyukov Date: Thu, 25 Jan 2018 09:32:51 +0100 Message-ID: Subject: Re: [PATCH] lib/strscpy: remove word-at-a-time optimization. To: Linus Torvalds Cc: Rasmus Villemoes , Andrey Ryabinin , Andrew Morton , Linux Kernel Mailing List , Kees Cook , Eryu Guan , Alexander Potapenko , Chris Metcalf , David Laight , stable , kasan-dev Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 24, 2018 at 6:52 PM, Linus Torvalds wrote: > On Wed, Jan 24, 2018 at 12:54 AM, Rasmus Villemoes > wrote: >> >> I see something similar, but at the 30->31 transition, and the >> branch-misses remain at 1-3% for higher values, until 42 where it drops >> back to 0%. Anyway, I highly doubt we do a lot of string copies of >> strings longer then 32. > > So I really dislike that microbenchmark, because it just has the same > length all the time. Which is very wrong, and makes the benchmark > pointless. A big part of this all is branch mispredicts, you shouldn't > just hand it the pattern on a plate. > > Anyway, the reason I really dislike the patch is not because I think > strscpy() is all that important, but I *do* think that the > word-at-a-time thing is conceptually something we do care about, and I > hate removing it just because of KASAN not understanding it. > > So I'd *much* rather have some way to tell KASAN that word-at-a-time > is going on. Because that approach definitely makes a difference in > other places. The other option was to use READ_ONCE_NOCHECK(). Not sure if the "read once" part will affect codegen here, though. But if word-at-a-time thing is conceptually something we do care about, we could also introduce something like READ_PARTIALLY_VALID(), which would check that at least first byte of the read is valid and that it does not cross heap block boundary (but outside of KASAN is a normal read).