Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5013055rwe; Tue, 18 Apr 2023 00:19:22 -0700 (PDT) X-Google-Smtp-Source: AKy350abUARgCsnD/bzqCYnpolsX66UofQV4TK15bEgG9ex2j4cNRQGrGrrCuxMxscqBTDzfIgWe X-Received: by 2002:a05:6a20:160a:b0:ee:3824:664f with SMTP id l10-20020a056a20160a00b000ee3824664fmr18006568pzj.47.1681802361809; Tue, 18 Apr 2023 00:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681802361; cv=none; d=google.com; s=arc-20160816; b=UgExj2bPCf8n8NF59CbHcc4Yxb/5ulX8Jz/t4Cz0EdM0hVmCTzQ3rH2oZaaHc9++Cv G1mIigZnFsrpBqdxAkxCNpgYi5epLmi7AZ23u6Q33PeszDlD9wvcyJ76loBmWMMCMcf8 9Cq9Kp7mSfFb5SMqxOSfk5/jSXN2doh2JwZS9e908CoE7dMf1EKxbrw16kM1hN5zd6A0 fejEOm7N6z8/gSRw1JKqwaqnTWCE8TA7R/uEN0mQPgp/zes7aNo0Eawc2g7tP77xUxD5 nYnj3uxBcrALvY5y8WLrEP4s58X/wD+11y8CJ3oXcuj5k+5n7JXTwtriX0ynYNWfER7Q DyIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=j5bhrbWxOBR5EN1s66LiAwObbO+qyqt9XYINsEitUKs=; b=CfnH3vd/kGU2GRlLNv6o8MsQyoI0uNMtyFuYZtsBWkjDMriCVNq9UkycuJCoQxBh4d 1nxM9LV3ngT28E0nHJtKe9J1ZzDcA2U51vc+pqQXiWJjJGXHNw1NI0d9GRmFLS/OdAMv 7GreDgX+b8L0mIQoCaeP1KCp7BlFq2ER8Zms6PtDF8uFwLrM5gqQSlv4lI5IfdjQNi67 7j1nXiVN+JeZO8KP0Oo8miLfTHpEUkoAFN2Pp6LgcqA8T8BTtl04+8gvcVHTMv/OBrIu jaJx18SvCvymZzDlL3guV0iJn4Varblen52QtaQoNDPS5xNQXB3UXzpjBiQyz0kq8LF4 KwPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h4-20020a635744000000b0050bd9c7bc1bsi12060304pgm.30.2023.04.18.00.19.08; Tue, 18 Apr 2023 00:19:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231247AbjDRHS7 convert rfc822-to-8bit (ORCPT + 99 others); Tue, 18 Apr 2023 03:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbjDRHS6 (ORCPT ); Tue, 18 Apr 2023 03:18:58 -0400 Received: from outpost1.zedat.fu-berlin.de (outpost1.zedat.fu-berlin.de [130.133.4.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E96401FFF; Tue, 18 Apr 2023 00:18:56 -0700 (PDT) Received: from inpost2.zedat.fu-berlin.de ([130.133.4.69]) by outpost.zedat.fu-berlin.de (Exim 4.95) with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (envelope-from ) id 1pofc2-002QcH-GH; Tue, 18 Apr 2023 09:18:50 +0200 Received: from p5b13a017.dip0.t-ipconnect.de ([91.19.160.23] helo=[192.168.178.81]) by inpost2.zedat.fu-berlin.de (Exim 4.95) with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (envelope-from ) id 1pofc2-0011uS-1N; Tue, 18 Apr 2023 09:18:50 +0200 Message-ID: Subject: Re: [PATCH RESEND] sh: sq: Use the bitmap API when applicable From: John Paul Adrian Glaubitz To: Geert Uytterhoeven Cc: Christophe JAILLET , Yoshinori Sato , Rich Felker , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-sh@vger.kernel.org Date: Tue, 18 Apr 2023 09:18:47 +0200 In-Reply-To: References: <071e9f32c19a007f4922903282c9121898641400.1681671848.git.christophe.jaillet@wanadoo.fr> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.48.0 MIME-Version: 1.0 X-Original-Sender: glaubitz@physik.fu-berlin.de X-Originating-IP: 91.19.160.23 X-ZEDAT-Hint: PO X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Geert! On Tue, 2023-04-18 at 09:14 +0200, Geert Uytterhoeven wrote: > Hi Adrian, > > On Tue, Apr 18, 2023 at 8:36 AM John Paul Adrian Glaubitz > wrote: > > Thanks for your patch. The changes look good to me. However, I have > > one question, see below. > > > > On Sun, 2023-04-16 at 21:05 +0200, Christophe JAILLET wrote: > > > Using the bitmap API is less verbose than hand writing them. > > > It also improves the semantic. > > > > > > Signed-off-by: Christophe JAILLET > > > > --- a/arch/sh/kernel/cpu/sh4/sq.c > > > +++ b/arch/sh/kernel/cpu/sh4/sq.c > > > @@ -372,7 +372,6 @@ static struct subsys_interface sq_interface = { > > > static int __init sq_api_init(void) > > > { > > > unsigned int nr_pages = 0x04000000 >> PAGE_SHIFT; > > > - unsigned int size = (nr_pages + (BITS_PER_LONG - 1)) / BITS_PER_LONG; > > > int ret = -ENOMEM; > > > > > > printk(KERN_NOTICE "sq: Registering store queue API.\n"); > > > @@ -382,7 +381,7 @@ static int __init sq_api_init(void) > > > if (unlikely(!sq_cache)) > > > return ret; > > > > > > - sq_bitmap = kzalloc(size, GFP_KERNEL); > > > + sq_bitmap = bitmap_zalloc(nr_pages, GFP_KERNEL); > > > if (unlikely(!sq_bitmap)) > > > goto out; > > > > > > > I have look through other patches where k{z,c,m}alloc() were replaced with > > bitmap_zalloc() and I noticed that in the other cases such as [1], kcalloc() > > was used instead of kzalloc() in our cases with the element size set to > > sizeof(long) while kzalloc() is using an element size equal to a byte. > > > > Wouldn't that mean that the current code in sq is allocating a buffer that is > > too small by a factor of 1/sizeof(long) or am I missing something? > > > > @Geert: Do you have any idea? > > Nice catch! > > Looking more deeply at the code, the intention is to allocate a bitmap > with nr_pages bits, so the code fater Christophe's patch is correct. > However, the old code is indeed wrong: > > (nr_pages + (BITS_PER_LONG - 1)) / BITS_PER_LONG > > The aim is to calculate the size in bytes, rounded up to an integral > number of longs, but it lacks a final multiplication by BITS_PER_BYTE, > so it's off by a factor of 4. Yeah, that's what I understood from reading the code which is why I was wondering why the factor was missing. > Fixes: d7c30c682a278abe ("sh: Store Queue API rework.") > > As we didn't have bitmap_zalloc() until commit c42b65e363ce97a8 > ("bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free()") > in v4.19, it would be good to fix the bug first in a separate patch, > not using I agree. Do you want to send a patch I can review? > BTW, interesting how this got missed when fixing the other out-of-range > bug in commit 9f650cf2b811cfb6 ("sh: Fix store queue bitmap end.", > s/marc.theaimsgroup.com/marc.info/ when following the link). Yeah. PS: Sorry for the slightly messy grammar in my previous mail, didn't have a coffee yet that early in the morning :-). Adrian -- .''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913