Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp466626imm; Fri, 17 Aug 2018 00:47:26 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyJBmoX0sGOgu/NwuuPlMIvSQ0V6g0Jg7+XHUcUWx7RjKutlYKm8ieMH8YbnScDgcbcjWK8 X-Received: by 2002:a17:902:820e:: with SMTP id x14-v6mr32440230pln.218.1534492046645; Fri, 17 Aug 2018 00:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534492046; cv=none; d=google.com; s=arc-20160816; b=h/gE1i5vgj+YS5nIsvtAo7p9wv8rvfxNZcvd5Sp6TNhmu/cauZNqcZoybkvFG9W55B CcMPgMULC/14Qe2AoofJQWx7CYBcGlisFBrXC9C96aZZFUtSIUXelRPKxpBTAFBfzRRH xIw7eKYqmHVrWo5u62NQeCClfyRUBjX2uMHp6sJvnEcKTQXBidSKXVVKM6SvgPGrCKUs Ugh10NLJH56NpjfGl+vSDtV3noTdbvnw/mc5E3w0JKJ12xmkL5dhFUh5fEXl5iOqu4iv LI+540CRNS7NqDD6giGIhLsTmu4NBn5oXvCPv4+w3G7ED55/fRRLYbUH9dO5sz35aa+G lbIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=r0J0M6yOOz10vtJb1ELqdHvXPHAMM8Y569KvVMT7atc=; b=zh4cLpHiGaNp4Rq2VuAmTyJ4xuwjJ4lycKuqPEZ4U/UHrKuGi+Nm92maTu1MsEzIdH g8xE0DJtYj2YgCD5sajK3G5hr7c65KwkrU5iXScmCv+8BeqvdHZEwS6VBL/7I7SOJuSI 3pmdUQ/Wlp8x8jyl5DUN96JmngqBFCnMQruT+dh6i9kymWFtfZPRFjjbY57NRgADQVcB 7xpIYQ047Ct66w6WDr4CbP0HlMWHD2TqCw2JqookwC7KNY2RBSnxXIyUI6VW2EbPJHYu OAuQZ5aT5BaUL3shVSetPILK5ZNvNyekc14ld4T2tvqgfp6CVz7KxnDCCwEm8sqollDC STdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=S3ldox4S; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j8-v6si1387078pgp.548.2018.08.17.00.47.09; Fri, 17 Aug 2018 00:47:26 -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=@rasmusvillemoes.dk header.s=google header.b=S3ldox4S; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726583AbeHQKsU (ORCPT + 99 others); Fri, 17 Aug 2018 06:48:20 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:39935 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726041AbeHQKsU (ORCPT ); Fri, 17 Aug 2018 06:48:20 -0400 Received: by mail-lj1-f193.google.com with SMTP id l15-v6so5656140lji.6 for ; Fri, 17 Aug 2018 00:45:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=r0J0M6yOOz10vtJb1ELqdHvXPHAMM8Y569KvVMT7atc=; b=S3ldox4S3Dvm5JKpN3/CZL1ZCIn5G+1QrTqG/YkZv/wMtvDVzdMoIfECXgWofTkISO ygpR2jysHCoHnSy2aI/KxMvQQgtnhnvFYWfWSvPtERAd4ALVNaB9+81cCzfcFwuGrcug GmVAO3enSoGVjVzY+tb5vRMxeZrtnUjFCnQ2Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=r0J0M6yOOz10vtJb1ELqdHvXPHAMM8Y569KvVMT7atc=; b=rj9KwNffkLSIwCXgXdy7/sMqIuHL1NDyPVHiVnBe5MMF9b8FiRF9RenTYTaFfKTKsl aAIaPthik1Kivlokpvrn3Mx7hBG2jNiViOzirZ+cq9hyjlhvavRSLyNc6VG3RpHsGQ4n MDIub+x3Hf9wOOepwBrVYcsh9qLA7OQAC0nwODjzXwl1Ve6JNahbWOT9bYKNACP8l27G Gy3XNMMEhWOFSsT9hAoZFRFGQ1LzTE6HhwZqNLdXbJEByWPZFQ7tYCrNuZ9OzbV/0Eu+ lUx//kVczwLM6yB1t7yiEl7FnHhGqZXYvF1Uj02t3gFH0bnQxt/dLttLobCjJS1M8gpH TaSw== X-Gm-Message-State: AOUpUlHuD/k0zk3CkSudFI/pZ8MPLVDHzmro20n7w3KYkXU1YkSiDOtI rs6n/QIqfAX4Pj15uEncHVzJ0A== X-Received: by 2002:a2e:6304:: with SMTP id x4-v6mr24821602ljb.9.1534491958194; Fri, 17 Aug 2018 00:45:58 -0700 (PDT) Received: from [172.16.11.40] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id w8-v6sm265988lfe.67.2018.08.17.00.45.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Aug 2018 00:45:57 -0700 (PDT) Subject: Re: [PATCH] linux/bitmap.h: (buildbot-only) check if we have any compile-time zero-size bitmaps To: Yury Norov Cc: linux-kernel@vger.kernel.org, Matthew Wilcox , akpm@linux-foundation.org, Andy Shevchenko References: <20180815085539.27485-1-linux@rasmusvillemoes.dk> <20180816232125.GA6119@yury-thinkpad> From: Rasmus Villemoes Message-ID: Date: Fri, 17 Aug 2018 09:45:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180816232125.GA6119@yury-thinkpad> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-08-17 01:21, Yury Norov wrote: > Hi Rasmus, > > On Wed, Aug 15, 2018 at 10:55:39AM +0200, Rasmus Villemoes wrote: >> Most of the inline bitmap functions are buggy if passed a compile-time >> constant nbits==0. > > I think it's bad wording. Functions are OK. The problem is in users. Why shouldn't we handle a zero-size bitmap gracefully? In any case, if you believe nbits==0 is an implicit violation of the API, all the more reason to detect if we have such users. > Also, run-time nbits==0 is buggy as well. No, not according to my reading of lib/bitmap.c. Can you point out any function in there that doesn't behave correctly when passed nbits==0? On the other hand, we have a rule > in include/linux/bitmap.h: > * Note that nbits should be always a compile time evaluable constant. > * Otherwise many inlines will generate horrible code. > So runtime-defined nbits is bad thing by itself. Yeah, that ship has sailed long ago. We have lots of users where for whatever reason nbits is not constant and/or is bigger than BITS_PER_LONG, and a function call isn't really that horrible. Probably that piece of doc should be removed or relaxed. I have a small series that removes another piece of wrong doc, I'll tweak this as well. One thing that might be worth looking into is to see if we have some places where nbits is not compile-time const, but is compile-time known to be in 1 <= nbits <= BITS_PER_LONG, and use the inline branches in those cases as well. Matthew already did something like that with 2c6deb01525, where we use the inline case when nbits are known to be a multiple of 8. >> >> Not-really-signed-off-by: Rasmus Villemoes >> --- >> >> +int const_zero_size_bitmaps_are_buggy(void); > > It introduces undefined symbol and uses it in pretty unusual way. I think > it worth to add comment about it. So I thought the subject and the not-really-signed-off made it clear enough: I don't mean for this patch to get upstream, it was only for the buildbot to chew on and send me a build error report if we did indeed have any such users. The real fix(es) I'm planning to send is in https://github.com/Villemoes/linux/tree/4.18_bitmap-zero-fix , but I'm still waiting for the buildbot to send a report for the fake patch. >> #define small_const_nbits(nbits) \ >> - (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) >> + (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && \ >> + ((nbits) > 0 || const_zero_size_bitmaps_are_buggy())) > > Some functions in bitmap API has signed type for nbits. (This is wrong > by itself. I think I'll write patch for it.) I thought I fixed that years ago, but looking again, it seems 2fbad29917c98 failed to update bitmap_shift_right properly. There may be other extern functions with signed nbits, but I think bitmap_shift_right is the only inline that passes a signed nbits to small_const_nbits(). I'll include a fix in the above series. So in fact you check here > that nbits is not negative as well. Would it be better name like > const_nonpositive_size_bitmaps_are_buggy? The name of the undefined function is irrelevant per the above. Rasmus