Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4081743pxb; Tue, 17 Nov 2020 10:45:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFBqgUM/9ertL2fdVZtvC0dwoyhdOB18q5uWGm4YO8oIWsMsG5HIWUW8+VF2EaJ+YZ1PHH X-Received: by 2002:aa7:c358:: with SMTP id j24mr22472016edr.265.1605638705293; Tue, 17 Nov 2020 10:45:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605638705; cv=none; d=google.com; s=arc-20160816; b=twNiso3IQ7B3iButftSoE/fb9olQ2yErzS+iDdZzttA8e5twsTaZMmAKxI3JP10Uvs 3gzgTChLveUxMY2TRv1i5TN4rnpwf/q7MnPkmcBdpV36jXFK5t6oyFuFMqTuN2WYVlpB H79ieatIi8QJlmafgxrwEDasBEAVIWUJ50lkWsJoGwDThQXHOIACOHG5BTvQTKCoEXZz RkNFYM/yGqbCMrTSXSWC/kEU4C/YQ1f+XloX4gRhUS7sNk8W8oSdyGVgK4wkY1CT1Q1O 3oAnwMsSyuxALNZsy5UxxXppZiWRQhCq9HSVJ6fxs8+UU8jeB0sODf3YU8W0iUHlHdId h5OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Dhi1m3//X8SxGtM0lCmEC658ax9lzIuWRwWWHXdJagA=; b=do4yfDM07aAbCD9guFhw6VJzLScFxS1ZuJBxDmOjoKnOIxFaAd2INxfE6zxwtCavCk Ab23rHVaOJga5ceUES1JOJaxsAdyx5jPLDmjmKEjskTlqVjLjtRM4lNiI9rzSF9IqeSD Qg6NT7LkUXf5eQ9oY+IhdSCHaB6AcfzF/ltRx6ToGJ63zpGh1aSujAmOviopXBacvLED 0BEGHsywQmZ5MsSCxnyziPGNve1NyFrJnr/KkvzE42WIDOYyWtokLtqn5NYNg8fizhkF KN/5LoN5ioh+0JAjCutHhgEMjmZYCEk2g4zKs3cFLjb2rD7Y7s5q/uHwJYCaWe1GdNss fRDQ== ARC-Authentication-Results: i=1; mx.google.com; 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 d11si7221779ejt.527.2020.11.17.10.44.41; Tue, 17 Nov 2020 10:45:05 -0800 (PST) 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; 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 S1729168AbgKQSlL (ORCPT + 99 others); Tue, 17 Nov 2020 13:41:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727007AbgKQSlK (ORCPT ); Tue, 17 Nov 2020 13:41:10 -0500 X-Greylist: delayed 1127 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 17 Nov 2020 10:41:10 PST Received: from mail.rc.ru (mail.rc.ru [IPv6:2a01:7e00:e000:1bf::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7113C0613CF; Tue, 17 Nov 2020 10:41:10 -0800 (PST) Received: from mail.rc.ru ([2a01:7e00:e000:1bf::1]:57724) by mail.rc.ru with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kf5cO-0004JI-KT; Tue, 17 Nov 2020 18:22:16 +0000 Date: Tue, 17 Nov 2020 18:22:15 +0000 From: Ivan Kokshaysky To: Linus Torvalds Cc: Daniel Xu , Matt Turner , Richard Henderson , bpf , Linux Kernel Mailing List , Alexei Starovoitov , Daniel Borkmann , Song Liu , andrii.nakryiko@gmail.com, kernel-team@fb.com Subject: Re: [PATCH bpf v6 1/2] lib/strncpy_from_user.c: Don't overcopy bytes after NUL terminator Message-ID: <20201117182215.GA15956@mail.rc.ru> References: <470ffc3c76414443fc359b884080a5394dcccec3.1605560917.git.dxu@dxuuu.xyz> 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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 16, 2020 at 02:44:56PM -0800, Linus Torvalds wrote: > On Mon, Nov 16, 2020 at 2:15 PM Linus Torvalds > wrote: > > > > So I've verified that at least on x86-64, this doesn't really make > > code generation any worse, and I'm ok with the patch from that > > standpoint. > > .. looking closer, it will generate extra code on big-endian > architectures and on alpha, because of the added "zero_bytemask()". > But on the usual LE machines, zero_bytemask() will already be the same > as "mask", so all it adds is that "and" operation with values it > already had access to. > > I don't think anybody cares about alpha and BE - traditional BE > architectures have moved to LE anyway. And looking at the alpha > word-at-a-time code, I don't even understand how it works at all. > > Adding matt/rth/ivan to the cc, just so that maybe one of them can > educate me on how that odd alpha zero_bytemask() could possibly work. > The "2ul << .." part confuses me, I think it should be "1ul << ...". > > I get the feeling that the alpha "2ul" constant might have come from > the tile version, but in the tile version, the " __builtin_ctzl()" > counts the leading zeroes to the top bit of any bytes in 'mask'. But > the alpha version actually uses "find_zero(mask) * 8", so rather than > have values of 7/15/23/... (for zero byte in byte 0/1/2/.. > respectively), it has values 0/8/16/.... > > But it's entirely possible that I'm completely confused, and alpha > does it right, and I'm just not understanding the code. No, you are right, it should be "1ul". Indeed, seems like it came from the tile version which looks incorrect either, BTW. The tile-gx ISA (https://studylib.net/doc/18755547/tile-gx-instruction-set-architecture) says that clz/ctz instructions count up to the first "1", not to the last "0", so the shift values in tile's zero_bytemask() are 0/8/16/... as well. > It's also possible that the "2ul" vs "1ul" case doesn't matter. > because the extra bit is always going to mask the byte that is > actually zero, so being one bit off in the result is a non-event. I > think that is what may actually be going on. Yes, looks like that. Ivan.