Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp183954pxa; Tue, 18 Aug 2020 20:44:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOqQNVlE9yatoAbzeF3MXC77cuJAaChSHDtnwV3Sz3n+cubxppnXX/8YHGiT/WyIl2Pti+ X-Received: by 2002:a17:907:2712:: with SMTP id w18mr2294128ejk.473.1597808666460; Tue, 18 Aug 2020 20:44:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597808666; cv=none; d=google.com; s=arc-20160816; b=bF9OYWIRjooIoOMh+w3v+JOgvwhSLHluVhj+z8LBbJ2mBKAZAmEI3Vws6tr/StNkWp ly4T2ew90Qn9PUiqnp4loWSKSAm8Y/3v9CibOzMIZUMTgbSdIGpdOOez6lIp1IcL3UXI USI/1x0y5llXN2XJkGkHyWhksBWwke5mkhVnTWwpQd2BrqWO0CU4jkHlDhQr/M7yL8vi Y615mfXPzmMcMpxCHkRRzoeeRvUgnK+mj1kiIBj/8SDVijhVpHps/yhFzwiHZX5p4Njp WFPJ8v+ZKu8T+cfypbEVKzB9QSkwM4Zx1aWttZk+O9dAiEk+cIWy4ot9ShFIwPbWjnw4 BtMA== 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 :in-reply-to:references:mime-version:dkim-signature; bh=Ao/sHNcaqVhQQMi80lMo4XF+FLR+4Bj6pKAQTXaD+hQ=; b=gAVyP8nLAAkPpyFUxL82j8lHmxjC+qlAw+XLYQwICys1Gi2kzrgvWinleHGYG/HDO5 WIPLSZSJfcc69rjthW6vCJu3x0WeyZARqBL99mmzXjk29cjqrM0P7uImhxzSRaRF4z7v wqtxDM32/Sv+6/VIzv1x6+70ucVehX9EuNlXWHV5V4kSxf2oQpbItYhDe7bTIwwXzEn+ RodnChVKdx5zpwwh9ge/hQjCsWzlPjV5wa0FqQ+801WhtK1nEIeE638DIPF+108RbWqc /H/DqR2vPh464V2vLr16DEgSle9s+3OUSchIx3h160ez995rgYS/k/Y5reI5l+BZo74I q91g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=gdBMzTnB; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si8846186ejf.419.2020.08.18.20.44.03; Tue, 18 Aug 2020 20:44:26 -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=@linux-foundation.org header.s=google header.b=gdBMzTnB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726879AbgHSDdT (ORCPT + 99 others); Tue, 18 Aug 2020 23:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726627AbgHSDdT (ORCPT ); Tue, 18 Aug 2020 23:33:19 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A516EC061389 for ; Tue, 18 Aug 2020 20:33:18 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id v9so23793769ljk.6 for ; Tue, 18 Aug 2020 20:33:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ao/sHNcaqVhQQMi80lMo4XF+FLR+4Bj6pKAQTXaD+hQ=; b=gdBMzTnBa8XDbCmYcOweMIya67GSpSnewFl7/JVdiG3ga35lMroSKbu5zxClc6CsSK mC0NDYzTvugO0jZSRW+hASL5tVSnWq5b9kvVZJqOclf0htIfy1fqdDwLG7+hPVSyXtdg c9QdlMxtf3DkoyUME4EIoPQccF0B+9reRSqgA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ao/sHNcaqVhQQMi80lMo4XF+FLR+4Bj6pKAQTXaD+hQ=; b=rol2ad5keOXqGRjcRGHHvPXebyyCFnMuay0CpshZlQ2IYFSvmUqbDy1bXTmucMLgqx qewkO/VyJ4Z5CxtehmM+2iKiaVWK05V4IK5XUgtOq9LeFMIhvfmpnL5W2XcFkGphBFRe wRZ7S61d7/vks+5i5zq0CkDVAQabv6vdkQYidG2V7UJl9N8M3/x7VvOL8qEBOaqoBsa3 ScCW3qrBZ2Qv1qy5NVnPWG8VChLeN7OIqW22VrkK3K+ks2hNZOxwwAwZKkme6l+3QE8L vZsy13hkO3U+leR6iPhvkPoA5PpiNQllIlfb5wfsvQ29jYBvk6NsFah6bO3yyCkwNKUd dnEA== X-Gm-Message-State: AOAM533V6ZsEpXlm287Tw1TzsFK72Uy3qG6oqCOY3ecLQqgNFtthi5dP 7l/9a1s297jzZtDYqQfYc6iRfidI7f4O3A== X-Received: by 2002:a2e:b80b:: with SMTP id u11mr11707382ljo.286.1597807996437; Tue, 18 Aug 2020 20:33:16 -0700 (PDT) Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com. [209.85.208.181]) by smtp.gmail.com with ESMTPSA id x205sm6907898lfa.96.2020.08.18.20.33.15 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Aug 2020 20:33:15 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id v12so23767546ljc.10 for ; Tue, 18 Aug 2020 20:33:15 -0700 (PDT) X-Received: by 2002:a2e:7615:: with SMTP id r21mr10463304ljc.371.1597807994822; Tue, 18 Aug 2020 20:33:14 -0700 (PDT) MIME-Version: 1.0 References: <20200818234307.3382306-1-nivedita@alum.mit.edu> <20200819030442.GA3396810@rani.riverdale.lan> In-Reply-To: <20200819030442.GA3396810@rani.riverdale.lan> From: Linus Torvalds Date: Tue, 18 Aug 2020 20:32:58 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] lib/string.c: Disable tree-loop-distribute-patterns To: Arvind Sankar Cc: Andrew Morton , Nick Desaulniers , Linux Kernel Mailing List , clang-built-linux 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 Tue, Aug 18, 2020 at 8:04 PM Arvind Sankar wrote: > > On Tue, Aug 18, 2020 at 05:44:03PM -0700, Linus Torvalds wrote: > > Using -fno-tree-loop-distribute-patterns seems to really be a bit too > > incestuous with internal compiler knowledge. > > Fair enough -- you ok with just the -ffreestanding? That's what protects > the memset in arch/x86/boot/compressed/string.c. Yeah, I think -ffreestanding makes sense. It may not be optimal, but it doesn't smell wrong to me. > > Looking at the implementation of "strscpy()" in the same file, and > > then comparing that to the ludicrously simplisting "memcpy()", I > > really get the feeling that that memcpy() is not worth having. > > I don't think anything actually uses the generic memcpy, and I think > only c6x uses the generic memset. I do think maybe we should just remove the generic memcpy and memset and say "hey people, you really do need to implement your own". Even if you don't have this "recognize and recurse" issue, you end up having other issues like just tracing etc. Yeah, we've hopefully turned everything like that off, but considering that no major architecture uses this, I wonder how many small details we've missed with ftrace recursion etc? > Might be worth optimizing strnlen etc with the word-at-a-time thing though. Yeah, possibly. Except the kernel almost never uses strnlen for anything bigger. At least I haven't seen it very much in the profiles. The "strncpy_from_user()" stuff shows up like a sore thumb on some loads (lots and lots of strings from user space for pathnames and execve), but the kernel itself tends to seldom deal a lot with any longer strings. Stuff like device names etc, I guess, but any time I see string handling in profiles, it tends to be in user space (GNU make spends all of its time in string handling, it sometimes seems). Of course, that may be just me looking at very particular profiles, so maybe I've just not seen the loads where the kernel strnlen matters. memcpy and memset? Those matter. A lot. Linus