Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9809290pxu; Tue, 29 Dec 2020 05:53:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3F9RuTVPmf8TlrAfb4W3KM5X1Ok7fiTUNy8rv0Ua431J6yNti6ke1bGSNYh7erVkAwjbs X-Received: by 2002:a17:906:6b88:: with SMTP id l8mr45593309ejr.482.1609250010496; Tue, 29 Dec 2020 05:53:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609250010; cv=none; d=google.com; s=arc-20160816; b=wnBjj8ftfCShXswWs8+fuUS6yoNySrx1SQMn+ylP031Y4bQhtsd0NLaRhvY52pKN+6 bpvt/tEHOUUw9u7f7a4S41f6KSfNGVfQQa1pSvxyCqAhH+nmhW9mysas22nPV/HBn0tD z6pXX2BDGG4eOiV/3/Ul9kGDXYYHzB4x4ye8QeDxS8CG+mpZ9/e4bkj2sMLxWOSL4AP6 CQTr9zBJyxcCpKxSHGGciYjdQQQK/8Yk/9QI3y0XyvEmDle5eVJMfn14EfLIp7k1AQBu KioqOc/LbS52hN7mxzwok9k2wu9x/ChhlKlDc16SqPngwe2zuSmLZ2MERN+3SXEAGtja tRfg== 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=E1q/oK503CaRe+t2sMH527xi1I29YuRwcOvvSeEj3U8=; b=Q8eF1KbC9WHlTHjUEVCBa3XVEEb45i2GX3QO/h6uXog73W+sPDFmwB5vsw4M5EvG+B qgC4vxZ4vo9QmTC1GZSYM/+uC2sFT118ZuSMIBWoD4FZB0qzWOQMsA/yTytdpx4iC++L 67p/dj2HKEVhDbDDP2gLX2NjqcVV9ukmmHoGsgDdCAr9RoIzs9xSP/yYaZdFxIKm8T5W nhMZiVQO0Rpse1f1Cf5nVX9F6HumcK7WPRyuLhjwNz5fWJXg6Ns3tYYYZTbKng7gIPW6 TzOEmFpEvDd0lOcggM1rKvKO+3tOaNWN6IJ7ZypocgKUBq0L/PKOknG191NyZFwDgP8U Nchw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GMQ8wfXy; 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 gf2si14297208ejb.154.2020.12.29.05.53.07; Tue, 29 Dec 2020 05:53:30 -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=GMQ8wfXy; 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 S1726811AbgL2Nvb (ORCPT + 99 others); Tue, 29 Dec 2020 08:51:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbgL2Nva (ORCPT ); Tue, 29 Dec 2020 08:51:30 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C768CC0613D6 for ; Tue, 29 Dec 2020 05:50:49 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id l23so1533940pjg.1 for ; Tue, 29 Dec 2020 05:50:49 -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=E1q/oK503CaRe+t2sMH527xi1I29YuRwcOvvSeEj3U8=; b=GMQ8wfXyGQ7e6cz1xTPc9LqGtJtVrN8xZnzn+3SuQ+vH7Lu2VkV5MCAJcL9qY887Df 4gOMDA8WByOxUvR2qstq5k68le/8MOlFROEL5rBWoCehBsFGY1lHKcsmghyx+ms0aSFb p9VK2bwsODLqjNSA03fUVzQgcBAUWcRp3wuzPuihjvpFIuMzawm8amjn9tzRZ9csh8VW CK19r9Va2loH0JLNqCizK94EwrDO/7uDXGykeeaM5HuTZAudQg4PCaxDazb8ct6UTaPl g3BxTA0hsYNzdzAUssDQHCKbw+rfdSm8v2Jdok1+tp4Q3f8IxDFpKcO5zW5//m8e4EY3 z+mg== 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=E1q/oK503CaRe+t2sMH527xi1I29YuRwcOvvSeEj3U8=; b=SuddPjNRBlS+BtERm2ZGaCNJVpm2xRCfWU18a0HzKtg/M1rDYamreu3fxPtwvEMIA1 a7bk8rqwmzY4fyKyP97y90pyBvj6A4n4FiY04XUPwx7LqeuNEGx8qPv/Jx0uq47MZ1y4 qADmReFCRq///szNjsHS0SzNr2ddh/1NcIUBR6bauOSh1rjUNwTjISNyxtBmPFMgfuUQ M2KIBXqx133xC/eSGd1FONmO3nkIsZ0uU8HTzJ5zorkVT3pi+ZfueMWCa85u6+p0Aa6O befK+IxseqMO+TweQ3gq/Dgf649yH0cVxlG0h2ksqFnRS5k1jRs6V0BnPTXpSo8TE9RG 8SAg== X-Gm-Message-State: AOAM530GVAyNfF+UzMLK0XeYQv1NvpTZlzVET+IjTELhfgglgt5qy1B3 QS/jrCwMCCD6cDE49uhXOLR729BmzkzgbFHdbbk= X-Received: by 2002:a17:90a:c592:: with SMTP id l18mr4116917pjt.228.1609249849298; Tue, 29 Dec 2020 05:50:49 -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: <808b7555-5ba2-f1fe-3800-1d5f59c47b52@arm.com> From: Andy Shevchenko Date: Tue, 29 Dec 2020 15:50:32 +0200 Message-ID: Subject: Re: [PATCH] drm/komeda: use bitmap API to convert U32 to bitmap To: Carsten Haitzler Cc: Yury Norov , 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 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 happens= 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 bits= . > >> > >> Are you telling that find_first_bit() has an issue? > > It seems you're right, there's no issue with endianness in existing cod= e. > > 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 code = 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" with > 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 IM= HO. 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/ebitmap.= 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_mask= ); But this is a bit verbose. Also, it can be something like DECLARE_BITMAP_U32(...) =3D BITMAP_FROM_U32(= ...); > IMPORTANT NOTICE: The contents of this email and any attachments are conf= idential and may also be privileged. If you are not the intended recipient,= please notify the sender immediately and do not disclose the contents to a= ny other person, use it for any purpose, or store or copy the information i= n any medium. Thank you. Hmm... you probably have to get rid of this footer. --=20 With Best Regards, Andy Shevchenko