Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9981812pxu; Tue, 29 Dec 2020 10:12:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdg1oujbn/nHzcpheWawiciQ2x4lpKXTH4kKYmcsf1llyZFj0Yr1pde+JtEBZ8pvlJwdpx X-Received: by 2002:a17:907:204b:: with SMTP id pg11mr48023103ejb.192.1609265532848; Tue, 29 Dec 2020 10:12:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609265532; cv=none; d=google.com; s=arc-20160816; b=du9uRlAv8H/jQcoWQ7jqIkLo44v0jB53zTg1zuJhmW6rhl3M6yg7uAI0ZlQTH+Fkl0 +8pzCxQayWslcSm4RPzeCXRgHosbHfg3ylDNKs9RTh7QWnnrIHScmjx+zv4fUwbaNa4T hzWG5QX9OCtIAyYxVPIrWspd6+64rn2tEc8gYjodaB2Yonx8wt84Sh2vOIroS34k1AkA nSwma2L67NwB9VwLeE8BcezKdU6clxt0S+e0CpYydmhk3hrHoxYzVmu/QY8A/13+Qqmk lQE5KMMXWMz2PLLwF0cSCc672dpTDloGtJ5fNY2ZAdlqArrMaCZn4muVgszzKFsjwJrX qr2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=8hFSHegvRni/zcx/EwJER4O39x8vyJVRb/CCLReg+FQ=; b=tMXxWp11bTblUtc8O37ztRHUPLpH3BEDqMWrfmJBGLByySUhvYRgfpKf1Jd+9dl1E4 f/U1pap4MmEPpPhRdSZfn0DItG9J2ocy2ZXRhMEXOo4Sro0eDAzSEru7Kjk3HRZcMFxz O6yyE+yVEzIvq7B69Qux1U5Y+i7gMlkX0GL5iDS7Ge/AlDLoR/2RetQeA+eaHSVa2JDq v0hi+vq8Q+pWJt9tmRZrCyNNoN74YhrVjU7MHhLEPWSG57b9KVnvy7F+Qq6pj+MnF3aa CiI+1ZORG3hUleYnSdjvC0w2Qz4aCNKqrk7yrA4YsNTj9ePVwiqN9cnBRrtksyHXcjKH vURQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sEBLIbfc; 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 o12si20089321ejg.407.2020.12.29.10.11.50; Tue, 29 Dec 2020 10:12:12 -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=sEBLIbfc; 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 S1726178AbgL2SKQ (ORCPT + 99 others); Tue, 29 Dec 2020 13:10:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726111AbgL2SKP (ORCPT ); Tue, 29 Dec 2020 13:10:15 -0500 Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4025CC061574 for ; Tue, 29 Dec 2020 10:09:35 -0800 (PST) Received: by mail-il1-x12b.google.com with SMTP id v3so12834970ilo.5 for ; Tue, 29 Dec 2020 10:09:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=8hFSHegvRni/zcx/EwJER4O39x8vyJVRb/CCLReg+FQ=; b=sEBLIbfcAHCT57zAtk0W1cjOsFTzU03sdXzqyOKtDY5fNAc7NVhvTbaGJDQwRl1T5/ /+JeGXwXEUfN/BGDpiJbjqMw9BU6LzS0zAm9mFRaNMRgdMB47JcXAx33R6Wv0vZHOoHk N9Pp7wVBdXBLpY+cIkOcpIgaV0bfBLk7IYxsYKc9W2CF1Wz1KBQuVG96dm57W2/Y1HJA 9Qr4IMJmcNzjbt93MsBi5PnhMK6EstlWDJwc8wiS1CinzIDHKH7z2BJe9qkbydP3oyX/ qnu0hnqHI4x/d85cV/TATZm56qECcLEbE8jdVSKoFRJNUlvd2DXFXH6BLq4uc3Axmx4V cdyw== 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:content-transfer-encoding; bh=8hFSHegvRni/zcx/EwJER4O39x8vyJVRb/CCLReg+FQ=; b=lo1/Y6vrGKLSlahUyoejT5zTlr173fP2jay1x7VKBRB1TFPQ5p90XCebag9nr79E1c GfpNcd/IDcOVfRPu4jp5Xev3E/1bUW6uRQ1ybBhN5nuD/bTtXembQqMhW1ncIszVeBQi M0hU5ILEFAuhAYV5dKpiSgOoTIr5q62o+9lYYJSRv7S60jgAC9h68Mp2poSXM149E53A e344r3bvDrqGtRUTQOdOwVEvsNoEGU96QQegH2ljZA7j+Q28m2MqOfiPFxyOz3HPrZHu +S2RsuzjgjwX+EKO5WDEbed8ue9JqX7/ODgXsOrHfu/Ebm925ua+7q74YM+esUtwsE6O Gq7g== X-Gm-Message-State: AOAM531xHRiJRbQSyye4zXooPleTeYRJrKMu3nKZVYT6CGLeu1H6r/qS y0BE6s/R+CFw+/gu1EFyBE9sotONXnvs0inhx3E= X-Received: by 2002:a92:418d:: with SMTP id o135mr50150808ila.213.1609265373448; Tue, 29 Dec 2020 10:09:33 -0800 (PST) MIME-Version: 1.0 References: <20201228194343.88880-1-yury.norov@gmail.com> <20201228195016.GD4077@smile.fi.intel.com> <808b7555-5ba2-f1fe-3800-1d5f59c47b52@arm.com> In-Reply-To: From: Yury Norov Date: Tue, 29 Dec 2020 10:09:21 -0800 Message-ID: Subject: Re: [PATCH] drm/komeda: use bitmap API to convert U32 to bitmap To: Andy Shevchenko Cc: Carsten Haitzler , Andy Shevchenko , Liviu Dudau , Linux Kernel Mailing List , Andrew Morton , Rasmus Villemoes Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 29, 2020 at 5:50 AM Andy Shevchenko wrote: > > On Tue, Dec 29, 2020 at 2:24 PM Carsten Haitzler > wrote: > > > > On 12/28/20 8:10 PM, Yury Norov wrote: > > > On Mon, Dec 28, 2020 at 11:49 AM Andy Shevchenko > > > wrote: > > >> On Mon, Dec 28, 2020 at 11:43:43AM -0800, Yury Norov wrote: > > >>> The commit be3e477effba636ad25 ("drm/komeda: Fix bit > > >>> check to import to value of proper type") fixes possible > > >>> out-of-bound issue related to find_first_bit() usage, but > > >>> does not address the endianness problem. > > >> Hmm... Can you elaborate? > > >> > > >> ... > > >> > > >>> u32 comp_mask) > > >>> - unsigned long comp_mask_local =3D (unsigned long)comp_mask; > > >> Here we convert u32 to unsigned long (LSB is kept LSB since it happe= ns in > > >> native endianess). > > >> > > >>> - id =3D find_first_bit(&comp_mask_local, 32); > > >> Here it takes an address to unsigned long and tries only lower 32 bi= ts. > > >> > > >> Are you telling that find_first_bit() has an issue? > > > It seems you're right, there's no issue with endianness in existing c= ode. > > > In fact, the line > > > > Indeed Andy covered this. Take LSB32 with the cast to "local on-stack > > long" and possible extend upper 32bits with 0's if needed (64bit longs)= . > > > > >>> - unsigned long comp_mask_local =3D (unsigned long)comp_mask; > > > is an opencoded version of bitmap_from_arr32(dst, src, 32). > > > > > > Maybe it would be better to use the bitmap API here, but existing cod= e is > > > correct. Sorry for the noise. > > While your code is seemingly also valid (I can check to be sure with > > KASAN if you want still), it does seem a little less "nice to read" wit= h > > more lines of code for the same work. Is it worth making the code a > > little longer here as it's not actually fixing anything to do it this > > other way? DECLARE_BITMAP() is a bit of an obscure way to declare a > > single unsigned long (in this case) where the compiler does the right > > thing anyway with a simple assign+cast making it easier to read/follow = IMHO. > > What we can do is to declare BITS_PER_U32. > Also we can pay attention on these definitions: > https://elixir.bootlin.com/linux/latest/source/kernel/bpf/btf.c#L168 > https://elixir.bootlin.com/linux/latest/source/security/selinux/ss/ebitma= p.c#L27 > And define BITMAP_FROM_U32() macro. > > Then It would be written like > > DECLARE_BITMAP(comp_mask_local, BITS_PER_U32) =3D BITMAP_FROM_U32(comp_ma= sk); > > But this is a bit verbose. > > Also, it can be something like DECLARE_BITMAP_U32(...) =3D BITMAP_FROM_U3= 2(...); > > > IMPORTANT NOTICE: The contents of this email and any attachments are co= nfidential and may also be privileged. If you are not the intended recipien= t, please notify the sender immediately and do not disclose the contents to= any other person, use it for any purpose, or store or copy the information= in any medium. Thank you. > > Hmm... you probably have to get rid of this footer. > > -- > With Best Regards, > Andy Shevchenko