Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1033276rdb; Sat, 7 Oct 2023 08:57:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+bX3Cr55m0ln7uZsgKdcri5eYcC6SPtcChig7ogWX8o4fPLqZ9EHPn5JgDJk3mxJyaOmw X-Received: by 2002:a05:6a20:72a2:b0:11f:4707:7365 with SMTP id o34-20020a056a2072a200b0011f47077365mr13493512pzk.38.1696694274888; Sat, 07 Oct 2023 08:57:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696694274; cv=none; d=google.com; s=arc-20160816; b=WVH3lBJD0GcZ/unM86rfx+qTU24JhkTfvwfTgQ4YPRa0PifCQT0t7iTCDNzCzcA+Sy 2Ep4WnE/1g0VIeBwf9AAZEURLssxacrbWMYTxPa05e2I/fXRSwNQxzAhQ59DJg5Ju5OI 7BQA/hiB75Df3meaAlop/kG4LfVbWOfO9RgEnmgps2DVAIJ2vL8ZL2s44mDpEhF1oNb8 cu1d6Mg+YYxJeoyspHvP36ItNLzFt12E29kjDE7ksezEXhDSLmKKbYa0eHpCKK/U9Iuh N7orThJoluaX+nKGEU43Ba7St3DUgJ7ZVHjlr1kWEKSwquI1cPiPytXRf+jnN9aAyr1L PpDw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=PNgFndDlFVBhtNC42IVT7Nxa38Ps/YRYkGLa2pSsvYw=; fh=Za5K8G/pMdhFVviCVhO0hObhNMT0VKWKi0IQ6dvdEyc=; b=lT0oFbNg3v7z9YzlYiuJgEtX9fSTl5stGPcjzWXfztxdhpOCaIO+wQtgGJRZN1PmMH AACOI7FFCC/b/rD7fB9THJ95r1MwGyDrnWbZK8fDCg4CPM9r87jYI4YQfVwZ2xCcBtJl JnNrcgdaTVHTuY8iuj76c2ARMAHRqGDmvor+PfkBfs/rCG4Qm1iOCzv9b9V7mOCJmH8U QW2hs9836ZHREoXiThQ68A6sz+OZ0raxvj4tbuxF0wSn0h5WvLaBXbUapQQRKTGLrA6f otyFvgUnY/dN8D66fjV51rMLlBfmbzLV83nn7SUQKo/4A8z7DUohQU8bfSIKTqa62JDE WftA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nBd1o104; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id y15-20020a17090322cf00b001c74d1da69csi713107plg.362.2023.10.07.08.57.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 08:57:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nBd1o104; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 6C3958042E2B; Sat, 7 Oct 2023 08:57:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344029AbjJGP5h (ORCPT + 99 others); Sat, 7 Oct 2023 11:57:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343997AbjJGP5g (ORCPT ); Sat, 7 Oct 2023 11:57:36 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B92E7BA for ; Sat, 7 Oct 2023 08:57:34 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48388C433C7; Sat, 7 Oct 2023 15:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696694254; bh=FdT0hRiVUetymc4htP5coHs/oBEZ3Uyq+kymb8Y2DpQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nBd1o104P6neQxI5O+GltjAU3rrUklfWY8d2142pc/H7mAqrbdQu02oK2QjMNS/M7 YiGP5Ro+vzKL8/E3g2d1Ctkd6QpA6WdK+uQOGn9/1JANxW8aAJZ3XULf0TmSoPAaXG r6SMq0pwVsOW/R2cr/mKSVu5UIh/ff5OzwDtbq8TbXgiwKvpUmB4zkwCkvziWzy6sp HalIoKSTqTDanMYRlnx465Cb9/xomChLFzTnAO5n2TE0CS3ukSsDcrr2FcEtoW2bRu BdNAnqdw6H7/YBba6/p4azRz70rNmkWITuxORN795qPnDm0OybnccFMMD+tu5NRePF cC6dZnQa5Fnbw== Date: Sat, 7 Oct 2023 17:57:30 +0200 From: Simon Horman To: =?utf-8?B?S8O2cnk=?= Maincent Cc: "David S. Miller" , Michal Kubecek , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Maxime Chevallier , thomas.petazzoni@bootlin.com, Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: Re: [PATCH net v2 1/1] ethtool: Fix mod state of verbose no_mask bitset Message-ID: <20231007155730.GF831234@kernel.org> References: <20231006141246.3747944-1-kory.maincent@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231006141246.3747944-1-kory.maincent@bootlin.com> X-Spam-Status: No, score=2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sat, 07 Oct 2023 08:57:52 -0700 (PDT) X-Spam-Level: ** On Fri, Oct 06, 2023 at 04:12:46PM +0200, Köry Maincent wrote: > From: Kory Maincent > > A bitset without mask in a _SET request means we want exactly the bits in > the bitset to be set. This works correctly for compact format but when > verbose format is parsed, ethnl_update_bitset32_verbose() only sets the > bits present in the request bitset but does not clear the rest. The commit > 6699170376ab fixes this issue by clearing the whole target bitmap before we > start iterating. The solution proposed brought an issue with the behavior > of the mod variable. As the bitset is always cleared the old val will > always differ to the new val. > > Fix it by adding a new temporary variable which save the state of the old > bitmap. > > Fixes: 6699170376ab ("ethtool: fix application of verbose no_mask bitset") > Signed-off-by: Kory Maincent > --- > > Changes in v2: > - Fix the allocated size. > --- > net/ethtool/bitset.c | 31 +++++++++++++++++++++++++------ > 1 file changed, 25 insertions(+), 6 deletions(-) > > diff --git a/net/ethtool/bitset.c b/net/ethtool/bitset.c > index 0515d6604b3b..8a6b35c920cd 100644 > --- a/net/ethtool/bitset.c > +++ b/net/ethtool/bitset.c > @@ -432,7 +432,9 @@ ethnl_update_bitset32_verbose(u32 *bitmap, unsigned int nbits, > struct netlink_ext_ack *extack, bool *mod) > { > struct nlattr *bit_attr; > + u32 *tmp = NULL; > bool no_mask; > + bool dummy; > int rem; > int ret; > > @@ -448,8 +450,16 @@ ethnl_update_bitset32_verbose(u32 *bitmap, unsigned int nbits, > } > > no_mask = tb[ETHTOOL_A_BITSET_NOMASK]; > - if (no_mask) > - ethnl_bitmap32_clear(bitmap, 0, nbits, mod); > + if (no_mask) { > + unsigned int nwords = DIV_ROUND_UP(nbits, 32); > + unsigned int nbytes = nwords * sizeof(u32); Hi Köry, Thanks for addressing my concerns regarding the size calculations in v1. I think that a comment is warranted describing the fact that only the map, and not the mask part, is taken into account in the size calculations above. > + > + tmp = kcalloc(nwords, sizeof(u32), GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + memcpy(tmp, bitmap, nbytes); > + ethnl_bitmap32_clear(bitmap, 0, nbits, &dummy); > + } Perhaps we could consider something line the following. Which would avoid the need for the n_mask condition in the nla_for_each_nested() loop further below. ... saved_bitmap = kcalloc(nwords, sizeof(u32), GFP_KERNEL); if (!saved_bitmap) return -ENOMEM; memcpy(saved_bitmap, bitmap, nbytes); ethnl_bitmap32_clear(bitmap, 0, nbits, &dummy); orig_bitmap = saved_bitmap; } else { orig_bitmap = bitmap; } (Choosing names for variables seems hard today.) > > nla_for_each_nested(bit_attr, tb[ETHTOOL_A_BITSET_BITS], rem) { > bool old_val, new_val; > @@ -458,13 +468,19 @@ ethnl_update_bitset32_verbose(u32 *bitmap, unsigned int nbits, > if (nla_type(bit_attr) != ETHTOOL_A_BITSET_BITS_BIT) { > NL_SET_ERR_MSG_ATTR(extack, bit_attr, > "only ETHTOOL_A_BITSET_BITS_BIT allowed in ETHTOOL_A_BITSET_BITS"); > - return -EINVAL; > + ret = -EINVAL; > + goto out; > } > ret = ethnl_parse_bit(&idx, &new_val, nbits, bit_attr, no_mask, > names, extack); > if (ret < 0) > - return ret; > - old_val = bitmap[idx / 32] & ((u32)1 << (idx % 32)); > + goto out; > + > + if (no_mask) > + old_val = tmp[idx / 32] & ((u32)1 << (idx % 32)); > + else > + old_val = bitmap[idx / 32] & ((u32)1 << (idx % 32)); > + > if (new_val != old_val) { > if (new_val) > bitmap[idx / 32] |= ((u32)1 << (idx % 32)); > @@ -474,7 +490,10 @@ ethnl_update_bitset32_verbose(u32 *bitmap, unsigned int nbits, > } > } > > - return 0; > + ret = 0; > +out: > + kfree(tmp); > + return ret; > } > > static int ethnl_compact_sanity_checks(unsigned int nbits, > -- > 2.25.1 >