Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1462963pxb; Fri, 20 Nov 2020 10:03:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWmBBqknOdkmPys+rPime4+Ayhb1BygdXKJ8dLss97c0kqvwB07IhsPwH2eaMkpgkUM8Tp X-Received: by 2002:a17:906:b291:: with SMTP id q17mr33136205ejz.455.1605895423365; Fri, 20 Nov 2020 10:03:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605895423; cv=none; d=google.com; s=arc-20160816; b=ZzAhnAqM4F9awgD3okpcdntSd1vf99ZaIkvkqKBjwe4F1sCdQdLFhMwek0nLtBrSCp yb3YTC7veGsns68Z60sArtfq+bJqOo7QTW39pq2GTjUlgZbhseWT6mxaT9sBTVTKnDwc FAN110pdOvehPF5j6g33rL2n7PysoROKoD5pMB27gebBZE++gphsTnMmhjBu1bRwdh6V FFy+rvpcoWI2w6OlI1O2wKfgHRTJRvQfgdieuDGt7V1d/xJtrLuzvcK5uRlzYmkvkTtZ dZLFVNayYELDJER/VYGYihepWeV2DeLN8joy3gsNTJ8CeACtMcopmp7BH7UFFcwkLro5 dq7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=unYKej8YP+ZRl42nz0CCo6lF2anM/8H77HoEpmDKfy0=; b=zESlsHARQmhVUoCdaC9fPBxphlnn5aRLvx3cSjevW8YxAO9pin9P5hOXvg1hINW2yy QyNvUI+428Wcp2OCxgiAbbEt5irmEPk1DZefG4YqhHZJMMQdGtg0EOGOJimFtPbHq1CO WIv07AJ496ejzmFKHsKjnMV/VgVjQXlOp+8IrMCvkY0NeyxmuZqvPJ2nY/le5Csw+06r fa3eXuQxj0KPtnbeXQJUzY79JtbVwFOCzN+Ja4JThzo6/u3fnENuqtChnBtfTgn4OwLg 4O3t9ZJl0l8VCTebfLVCNkEY65XXxKyaQjP1O0GP5hsj1riuTfdBQqLQrGgY4K1TlJ06 lfMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=skW7Yyvj; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bs5si828058edb.176.2020.11.20.10.03.16; Fri, 20 Nov 2020 10:03:43 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=skW7Yyvj; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728506AbgKTR7O (ORCPT + 99 others); Fri, 20 Nov 2020 12:59:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727215AbgKTR7N (ORCPT ); Fri, 20 Nov 2020 12:59:13 -0500 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60CBDC0613CF; Fri, 20 Nov 2020 09:59:13 -0800 (PST) Received: by mail-qv1-xf42.google.com with SMTP id ec16so5110794qvb.0; Fri, 20 Nov 2020 09:59:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=unYKej8YP+ZRl42nz0CCo6lF2anM/8H77HoEpmDKfy0=; b=skW7YyvjYxSbJCJr9G6/vdoYg+vOkc9++HRhR18NcN0vJikz/7tSMWKyeGMm1G3s3m D3wxcJbfr0sy0EnoWa2HeouLy5bBPpUbEVe0KDNWEEeG4YHzq+NunKRfuKZIIapPRC+r n4NTjtfj50z7ZxSU14sBP7+pnMCR/u201SyW7NkMvfCW9SC0l6usG7qfi/qLTzbK4Yzf 1CC0TOXlHlSS53d0icvIDiTG2qNo0Ze4901D1CXTMV78yr0x8tijRloz7I58xiveqvp8 EE4cCCCnXnT1MpvYXo+Be0jJ9VpBPmrI1nK41IQ9PL/ywawAcDgQhpFCob4yJyXiiJMo WODQ== 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:references :mime-version:content-disposition:in-reply-to; bh=unYKej8YP+ZRl42nz0CCo6lF2anM/8H77HoEpmDKfy0=; b=coi1tCKcaX2K8IMwGi/UCJV0vi6jSpxeigbsw6XvWGZp4j4b+/fE+1yoTbYBcTP+Ev BMvprSWV0HMgd6rHZ6xEK51152h+nTSp8fdOfzcYSJ/Hs1o52KhHZ4gNo/70KgjYGHXQ VyaGgq3QuH5aD+HaHw7DiOdEc1TCmJwAaolB6+E2aCWVaCeXCI/zZGVwoDPw+Et3e0rc SC7sL7HGY6U/sgCkZ/7PTyA2mg6qSQsiMKTrtEig4l2YOIUz/lTF8ZyF3TgGhm5mEt5X KZGmyC54wVOhOsUDZh1DzqtaZDfXwOOwb6cs374GoGV3AHEvXOF4dMlNaj2GFMSugPFJ XLrQ== X-Gm-Message-State: AOAM533LyTPkQXxnLex+c/AbdCwdsNDmHG1Zo61t9xuDz984kLI7yILw YV9i7ok2xRW4DcT4KP4RAsU= X-Received: by 2002:a0c:a9d0:: with SMTP id c16mr17462086qvb.5.1605895152592; Fri, 20 Nov 2020 09:59:12 -0800 (PST) Received: from shinobu (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id x25sm2356146qkh.32.2020.11.20.09.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 09:59:11 -0800 (PST) Date: Fri, 20 Nov 2020 12:59:09 -0500 From: William Breathitt Gray To: Syed Nayyar Waris Cc: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, arnd@arndb.de, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/4] bitmap: Modify bitmap_set_value() to check bitmap length Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="RjWzpKsaDEwQ2xsQ" Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --RjWzpKsaDEwQ2xsQ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Nov 20, 2020 at 11:14:16PM +0530, Syed Nayyar Waris wrote: > Add explicit check to see if the value being written into the bitmap > does not fall outside the bitmap. > The situation that it is falling outside would never be possible in the > code because the boundaries are required to be correct before the function > is called. The responsibility is on the caller for ensuring the boundaries > are correct. > This is just to suppress the GCC -Wtype-limits warnings. Hi Syed, This commit message sounds a bit strange without the context of our earlier discussion thread. Would you be able to reword the commit message to explain the motivation for using __builtin_unreachable()? Thanks, William Breathitt Gray >=20 > Cc: Arnd Bergmann > Signed-off-by: Syed Nayyar Waris > Acked-by: William Breathitt Gray > --- > include/linux/bitmap.h | 35 +++++++++++++++++++++-------------- > 1 file changed, 21 insertions(+), 14 deletions(-) >=20 > diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h > index 386d08777342..efb6199ea1e7 100644 > --- a/include/linux/bitmap.h > +++ b/include/linux/bitmap.h > @@ -78,8 +78,9 @@ > * bitmap_get_value(map, start, nbits) Get bit value of size > * 'nbits' from map at start > * bitmap_set_value8(map, value, start) Set 8bit value to map at= start > - * bitmap_set_value(map, value, start, nbits) Set bit value of size 'nb= its' > - * of map at start > + * bitmap_set_value(map, nbits, value, value_width, start) > + * Set bit value of size va= lue_width > + * to map at start > * > * Note, bitmap_zero() and bitmap_fill() operate over the region of > * unsigned longs, that is, bits behind bitmap till the unsigned long > @@ -610,30 +611,36 @@ static inline void bitmap_set_value8(unsigned long = *map, unsigned long value, > } > =20 > /** > - * bitmap_set_value - set n-bit value within a memory region > + * bitmap_set_value - set value within a memory region > * @map: address to the bitmap memory region > - * @value: value of nbits > - * @start: bit offset of the n-bit value > - * @nbits: size of value in bits (must be between 1 and BITS_PER_LONG in= clusive). > + * @nbits: size of map in bits > + * @value: value of clump > + * @value_width: size of value in bits (must be between 1 and BITS_PER_L= ONG inclusive) > + * @start: bit offset of the value > */ > -static inline void bitmap_set_value(unsigned long *map, > - unsigned long value, > - unsigned long start, unsigned long nbits) > +static inline void bitmap_set_value(unsigned long *map, unsigned long nb= its, > + unsigned long value, unsigned long value_width, > + unsigned long start) > { > - const size_t index =3D BIT_WORD(start); > + const unsigned long index =3D BIT_WORD(start); > + const unsigned long length =3D BIT_WORD(nbits); > const unsigned long offset =3D start % BITS_PER_LONG; > const unsigned long ceiling =3D round_up(start + 1, BITS_PER_LONG); > const unsigned long space =3D ceiling - start; > =20 > - value &=3D GENMASK(nbits - 1, 0); > + value &=3D GENMASK(value_width - 1, 0); > =20 > - if (space >=3D nbits) { > - map[index] &=3D ~(GENMASK(nbits - 1, 0) << offset); > + if (space >=3D value_width) { > + map[index] &=3D ~(GENMASK(value_width - 1, 0) << offset); > map[index] |=3D value << offset; > } else { > map[index + 0] &=3D ~BITMAP_FIRST_WORD_MASK(start); > map[index + 0] |=3D value << offset; > - map[index + 1] &=3D ~BITMAP_LAST_WORD_MASK(start + nbits); > + > + if (index + 1 >=3D length) > + __builtin_unreachable(); > + > + map[index + 1] &=3D ~BITMAP_LAST_WORD_MASK(start + value_width); > map[index + 1] |=3D value >> space; > } > } > --=20 > 2.29.0 >=20 --RjWzpKsaDEwQ2xsQ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAl+4A9MACgkQhvpINdm7 VJLOcg//bVHY76KR7Igmki4gD1LNUL909jSCr2HZnnKLRy0/9FVuGSmB4rOAKnDu f701GsaEg4yuvJ5uVMdxtbkhoSm9SxdPMX9bwun0D5UYPp4QTg/c8gLL4sZfBl7t TG+aV/Osi+G/NaZ2X43aX/LK812ALIcb1p3gJ7+137HRxSyt/ZVl7X5gRQ6Kz1w+ 9hpkdWh+2BGFrIuV3KrtHFCmOFaww27hxfVueVag6/aNu9MtS10e+hMCmoDaX1I1 neR+x+02fFEYV3cOVVWKvEzx2aZrEc11S8en6AgOHijrwaMfHQRFHz/pT+ZInMmU EWfzhMeTPcJPms4n8E7fveuy6BC+fAvgoioVtxyz2tmhVmrnGPt+yl6E/VwDi7Mo ssuJWHbETWxDOJmADe0Qo9WX1g2QdHGmWyvkjbZOcXAhTTXhSdOczSQlzTtR8YJx cJVUbjakNFfEjitaoseYfYt75sKJ0H6YDEuI8DxZvND9UXVGCUeTBQHmtnWdnD0h dSrV7aE/kbEeWgW93AD/XV0evSYf+FPkUcEjjml7f1sD1eWj7dP1tG0OvnlYs0kQ PB4ccB4Gn8UAAIaO2iT5KdHTwqa6LY5/gqKwxICQa/ek5xuoEz6ohzLhANlS/vDy 6saVldu/0w12nDKGhaewpEArthFrzz6ayVq4vjmCoSr/uKgI9JU= =WFzE -----END PGP SIGNATURE----- --RjWzpKsaDEwQ2xsQ--