Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp57689rwb; Wed, 7 Dec 2022 14:24:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5/Undbr5AoWyIrq0ru8XiEL+PBPhYojgK5jkYtXfve1+nJHmtrrinW/ps1qZOpyU/OfDkO X-Received: by 2002:a63:fd01:0:b0:478:c026:d059 with SMTP id d1-20020a63fd01000000b00478c026d059mr13770495pgh.447.1670451881912; Wed, 07 Dec 2022 14:24:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670451881; cv=none; d=google.com; s=arc-20160816; b=dAsgU60Tw0HW3rIp50FKjTXX/wLc1ET4S/01wGm3Ybcn8+WQ3Y9ryKLb2D+THuJPrI AIyUQAQL5kD1MdTzQRzWSNaE90gQH2P+M/nAYMynx5Z7x8zvx/mSDkdea9Y0FCwP0022 TeFJgV6Pdp7ZJmrKdlC7/REWJ8gUqRlC4Nr31pVvbOLab4moPisd0LwRZ61nbqO/XgWj KGzBM1dvpDJakC8i+d6pZCgrOAcruqquEemoZStpZmqCm/GuMaDAZSohhHLBm3DFHDBW HzQ1mNwB0F+2/Vw61idbrN4WOZoMlxz7Bt5LlClXMT2mRFqCixQEuePtLUoQ7DLMINTO 08cA== 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; bh=3n3e7QoZxxrxCGpHckHg3FjhNH84Fq7qXpcP+j+jG2E=; b=uimRzhxRATgGGYWeLjatuyxwq1vxe7F9/lTyM/x0h5EPMsZVfivo4kcHZ/4eKo6IHG A1qNbGupn6F2ZlXWea4yNESRMYP1mP6+w/+vPwwfLnGv6tEz3ORH2fT8L4o0nJIXoGGj PKh3W5d04ptDGQhP6fdiLZXV3tDtdl59wG2rLDUalUWtDBrJc4Ff8HyxD5F0Pc9J70Ko LxdW8VtIebcsrnQq//ZabhEaPn18oeGxRcYRi/3o4oSfu39kBFiQw2kgnOKcr1xURklu AeE9KkOQRaMewyQpPZy4hSG95C6alDv9fJa8IK+Qalgf6On32xomkG+eK/ObAHuBl1NY IrVw== 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 my5-20020a17090b4c8500b0021942473a5fsi2773887pjb.122.2022.12.07.14.24.23; Wed, 07 Dec 2022 14:24:41 -0800 (PST) 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 S229951AbiLGWGC (ORCPT + 74 others); Wed, 7 Dec 2022 17:06:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229530AbiLGWFa (ORCPT ); Wed, 7 Dec 2022 17:05:30 -0500 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF7F0B7C1 for ; Wed, 7 Dec 2022 14:05:03 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-6-yD5IPmD2O_KCeTqYwEMREw-1; Wed, 07 Dec 2022 17:04:51 -0500 X-MC-Unique: yD5IPmD2O_KCeTqYwEMREw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 87D0A29AA2ED; Wed, 7 Dec 2022 22:04:50 +0000 (UTC) Received: from hog (unknown [10.39.192.162]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ACF0439D7C; Wed, 7 Dec 2022 22:04:48 +0000 (UTC) Date: Wed, 7 Dec 2022 23:03:45 +0100 From: Sabrina Dubroca To: Emeel Hakim Cc: "linux-kernel@vger.kernel.org" , Raed Salem , "davem@davemloft.net" , "edumazet@google.com" , "kuba@kernel.org" , "pabeni@redhat.com" , "netdev@vger.kernel.org" , "atenart@kernel.org" , "jiri@resnulli.us" Subject: Re: [PATCH net-next v3 1/2] macsec: add support for IFLA_MACSEC_OFFLOAD in macsec_changelink Message-ID: References: <20221207101017.533-1-ehakim@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE 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 2022-12-07, 15:52:15 +0000, Emeel Hakim wrote: > > > > -----Original Message----- > > From: Sabrina Dubroca > > Sent: Wednesday, 7 December 2022 17:46 > > To: Emeel Hakim > > Cc: linux-kernel@vger.kernel.org; Raed Salem ; > > davem@davemloft.net; edumazet@google.com; kuba@kernel.org; > > pabeni@redhat.com; netdev@vger.kernel.org; atenart@kernel.org; jiri@resnulli.us > > Subject: Re: [PATCH net-next v3 1/2] macsec: add support for > > IFLA_MACSEC_OFFLOAD in macsec_changelink > > > > External email: Use caution opening links or attachments > > > > > > 2022-12-07, 12:10:16 +0200, ehakim@nvidia.com wrote: > > [...] > > > +static int macsec_changelink_upd_offload(struct net_device *dev, > > > +struct nlattr *data[]) { > > > + enum macsec_offload offload; > > > + struct macsec_dev *macsec; > > > + > > > + macsec = macsec_priv(dev); > > > + offload = nla_get_u8(data[IFLA_MACSEC_OFFLOAD]); > > > > All those checks are also present in macsec_upd_offload, why not move them into > > macsec_update_offload as well? (and then you don't really need > > macsec_changelink_upd_offload anymore) > > > > Right, I thought about it , but I realized that those checks are done before holding the lock in macsec_upd_offload > and if I move them to macsec_update_offload I will hold the lock for a longer time , I want to minimize the time > of holding the lock. Those couple of tests are probably lost in the noise compared to what mdo_add_secy ends up doing. It also looks like a race condition between the "macsec->offload == offload" test in macsec_upd_offload (outside rtnl_lock) and updating macsec->offload via macsec_changelink is possible. (Currently we can only change it with macsec_upd_offload (called under genl_lock) so there's no issue until we add this patch) > > > + if (macsec->offload == offload) > > > + return 0; > > > + > > > + /* Check if the offloading mode is supported by the underlying layers */ > > > + if (offload != MACSEC_OFFLOAD_OFF && > > > + !macsec_check_offload(offload, macsec)) > > > + return -EOPNOTSUPP; > > > + > > > + /* Check if the net device is busy. */ > > > + if (netif_running(dev)) > > > + return -EBUSY; > > > + > > > + return macsec_update_offload(macsec, offload); } > > > + > > > > -- > > Sabrina > -- Sabrina