Received: by 10.192.165.148 with SMTP id m20csp871736imm; Thu, 10 May 2018 01:54:21 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqOgHY3ozeUW9Vc/85YGl/kbnrE5B5I5FNcTjEhdSCUTHSEqBab2af8WqoYlylStrAOjAMU X-Received: by 2002:a17:902:3225:: with SMTP id y34-v6mr571371plb.180.1525942461426; Thu, 10 May 2018 01:54:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525942461; cv=none; d=google.com; s=arc-20160816; b=zUX4zXdCbny/b4xy8fKVpBBVO5IpkIIgPTYF169Z1/pIk8d6cxknBtFlUaDaaUU2BU m30RvroEbCQ0osgPQFACy517jT3cWKvFNQsW97v+MILLIJp9QBaE4bB3gC8u72cxm8k4 YW5+vgfXHaRK2BFB7G6TmiRJ/ZFaimKXd076T0ptgZcJhu7K9Oip4LOg0SCl3H1Is8qQ +rA1KyptWJjwJV35hmv7QAUGQtl9Vpba0ijuOc5O+riFAZqG7+02eiJr6GNpXF7+txEf a59fiRVkaBSKIPaqZBb96u0kFOt4DodUX+ZnRZVrGYac+6LGqIx/qRglvSJ9SBLPKF3j qA8g== 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:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=WoxOc7L5BBIxXaBUemUpbcEdk1ZlvCXrdpxYv8JHSj4=; b=b+gWJZI3JtMFCMPOwW4jHo4jbP/YMms8vWa5fH0zRz7zPCu2yACYW9AYgzYmqB+ptr QRsgP2UN8VUUe4JyY2xdSSM7qFsRVK3vTV4z3RLeBbLo4NHTtU9K+W8lvz77s3Ys/T9r nYndtWm3RG3VYgLyQqOYal7op5AJ0o3n50vB3afPqhuFB9j890wN6my1YE10PipyJt+l nnNuHdW9Yocq5RcK9HzSwUe5qcE2Yfv1Uj9gfaGrY3j132+ol7xOiXhPeAz5eixRz1Oy /+QiqxTdXvedky7h/GBSGpn9NkRV9KF9TW5LelsMlA5eF3Jns80XGGpaK+Sugjx+Oy5q VySQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mapgIz35; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3-v6si348030plt.298.2018.05.10.01.53.56; Thu, 10 May 2018 01:54:21 -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=@gmail.com header.s=20161025 header.b=mapgIz35; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756929AbeEJIw0 (ORCPT + 99 others); Thu, 10 May 2018 04:52:26 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:46249 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756379AbeEJIwX (ORCPT ); Thu, 10 May 2018 04:52:23 -0400 Received: by mail-pf0-f195.google.com with SMTP id p12-v6so739949pff.13 for ; Thu, 10 May 2018 01:52:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=WoxOc7L5BBIxXaBUemUpbcEdk1ZlvCXrdpxYv8JHSj4=; b=mapgIz35+szJqbSldpSmWokzjLYWHVXzrZj9q5q73ngYDblUsxNnRT2ce/RyaJBgCn 4EyP0vygZcFU26WxasHKXkAv7jcRfzb8KCNuwFgrx1l5DxbFdL6QngvhfhWYp9g8pydp Ojj/Qy4Ga44JFqRxhDLV510GbXIFTTfBgRIrL1tc2B/G1GgdympXUzOf27Vcf11V9RuO I2G1iT6O0UMB4qhVDCY+XYDpcKkkV7gDV3dGQeFhPiVWm+LeY7IyRBUZ6R0Z/wIh2kgT 5R651DiXiXQR7xdHbvs4Bj7f4RxPApa9lGTihGso+k2+gnHQ7mnKMSm/HPoB1116lw9G MYuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=WoxOc7L5BBIxXaBUemUpbcEdk1ZlvCXrdpxYv8JHSj4=; b=DcFasnhMWNmmo3VwOlVRLZI6BRQssEuR6VgAm2PsgulVvcOjYBsTni3GYiiXz3AY6D yeOM66SJFJXhq6AxOoKKnuE5HXp/Y60OWu5MNJDpM9MfbuswihKXbu62JNDMD3cqViXC adIYlFoKI8SPCeAQA2VtCNaAqXaBbrQyZtq3wOm0odEkxW3Hda1fiaZlbVJt1mjSJJef Dt4NRjsGiJXd8gw+Qyvycv0ZHqA+MBF/pJaxC8uPpbVUufR4+7PrvK2oRrZ6Tqf6RDJ0 Ym6hARo5ObkAfYLQaAwbOPYtmYp9NUpFuVxMO0GuQTWyt+16TJF6NZtdUvyS3mpDEi0N O+vA== X-Gm-Message-State: ALKqPweiMG87mMzksxPsZXLteObyzfFKqfOVcgLyitPpygg/hQBILo5q T8MMtuAHFtaLgoeW00kiCTw= X-Received: by 2002:a62:c2c7:: with SMTP id w68-v6mr539883pfk.174.1525942343264; Thu, 10 May 2018 01:52:23 -0700 (PDT) Received: from udknight.localhost ([183.90.36.235]) by smtp.gmail.com with ESMTPSA id s189-v6sm867184pgc.39.2018.05.10.01.50.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 May 2018 01:52:22 -0700 (PDT) Received: from udknight.localhost (localhost [127.0.0.1]) by udknight.localhost (8.14.9/8.14.9) with ESMTP id w4A8oJAt031403; Thu, 10 May 2018 16:50:19 +0800 Received: (from root@localhost) by udknight.localhost (8.14.9/8.14.9/Submit) id w4A8mVaD031374; Thu, 10 May 2018 16:48:31 +0800 Date: Thu, 10 May 2018 16:48:31 +0800 From: Wang YanQing To: Russell King - ARM Linux Cc: illusionist.neo@gmail.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, daniel@iogearbox.net, ast@fb.com Subject: Re: [PATCH] bpf, arm32: Correct check_imm24 Message-ID: <20180510084831.GA31194@udknight> Mail-Followup-To: Wang YanQing , Russell King - ARM Linux , illusionist.neo@gmail.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, daniel@iogearbox.net, ast@fb.com References: <20180510032013.GB26016@udknight> <20180510075656.GS16141@n2100.armlinux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180510075656.GS16141@n2100.armlinux.org.uk> User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 10, 2018 at 08:56:57AM +0100, Russell King - ARM Linux wrote: > On Thu, May 10, 2018 at 11:20:13AM +0800, Wang YanQing wrote: > > imm24 is signed, so the right range is: > > [-(2<<(24 - 1)), (2<<(24 - 1)) - 1] > > 2 << (24 - 1) is the same as 1 << 24. > > > -#define check_imm(bits, imm) do { \ > > - if ((((imm) > 0) && ((imm) >> (bits))) || \ > > - (((imm) < 0) && (~(imm) >> (bits)))) { \ > > - pr_info("[%2d] imm=%d(0x%x) out of range\n", \ > > - i, imm, imm); \ > > +#define check_imm_range(min, max, imm) do { \ > > + if (imm < min || imm > max) { \ > > + pr_info("[%2d] imm=%d is out of range\n", \ > > + i, imm); \ > > return -EINVAL; \ > > } \ > > } while (0) > > -#define check_imm24(imm) check_imm(24, imm) > > +#define check_imm24(imm) check_imm_range(-16777216, 16777215, imm) > > How is this any different? > > If imm is 16777216, then "imm > max" in your version is true. > In the original version, "imm > 0" is true, so we then test for > "16777216 >> 24" being non-zero. That's also true, so the test > condition fires. > > If imm is 16777215, then "imm > max" is false in your version. > In the original version, the conditions also evaluate to false. > > For the -16777217 case, "imm < min" in your version is true. > In the original version, "imm < 0" is true, so we then test for > "~(-16777217) >> 24" being non-zero. This is the same as > "16777216 >> 24" being non-zero, which is true so the condition > fires. > > With -16777216, the same thing happens, both end up evaluating > to false. > > So, the two cases end up producing identical results, and there > is no actual effect from this change. > > However, your commit message is correct - there is a bug here. > That's obvious when you mask the "imm" value with 0x00ffffff, > and realise that an imm value of -16777216 ends up having the > same value in the instruction as an imm value of 0. So, the > range of "imm" is _half_ that. > > #define check_imm(bits, imm) do { \ > - if ((((imm) > 0) && ((imm) >> (bits))) || \ > - (((imm) < 0) && (~(imm) >> (bits)))) { \ > + if ((((imm) > 0) && ((imm) >> (bits - 1))) || \ > + (((imm) < 0) && (~(imm) >> (bits - 1)))) { \ > pr_info("[%2d] imm=%d(0x%x) out of range\n", \ > i, imm, imm); \ > > would fix it. Alternatively: > > #define check_imm(bits, imm) do { \ > - if ((((imm) > 0) && ((imm) >> (bits))) || \ > - (((imm) < 0) && (~(imm) >> (bits)))) { \ > + if ((imm) >= (1 << ((bits) - 1)) || \ > + (imm) < -(1 << ((bits) - 1))) { \ > pr_info("[%2d] imm=%d(0x%x) out of range\n", \ > i, imm, imm); \ > > would also fix it. Hi! Sorry for confusion, I make a mistake here, the real fix I want to submit is [8388607, -8388608], this range has the same effect as your suggestion. Will you fix it? or I resend another version? Thanks.