Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp558217pxw; Fri, 8 Apr 2022 14:53:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFVEzKcf8wa+8N3qYf4D92fXmJhgEHPBnS0GgTSRBOlI29UCULcFZGkh8hkyc0Z5Grv7IT X-Received: by 2002:a17:906:c54:b0:6e4:bbee:f17f with SMTP id t20-20020a1709060c5400b006e4bbeef17fmr20435961ejf.180.1649454837009; Fri, 08 Apr 2022 14:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649454837; cv=none; d=google.com; s=arc-20160816; b=rJKzlOAL7aTpFowO2hMchS3wUiubHpPPoiT7voYmVT9hkxzrIUhwPGnjeT3tXhJsPX nmQa4IO+uASByEruX4tcuYfjcWgSOxaL77GLo+ZN865jAPmloEYIINe020hvjaZz0QKq l1zpHaJ57xadbvhUvUE68G/tl6f6mRkDj7gshwc+50rEmmCJX6IOqIu24EpoVWNWk/nY CK2/8Fcpur0qcHL5Fuq92KyTrIHJK39eAByKK9HhEnGLAVlL8PlSVBWVNPwVzFoAVd3q HJ+aDsARA2NRLhIGVoLVrI6oSHyY0LFJzCR7EdzVmC1tkdjs8vjIMtklQovXEu3ILPkS qHVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Fqd9I7BOixyBVDPYdUDjWjSUGmelVlhAeRojU0V4afE=; b=RVcT8KyAPkBDf3MxuEQCR0vsUXgq8KdybnrYjFQg31YbV7mi/ur3kauMdciqbAvDvg GGtziMY0jZ3t+0JByvvN5/7o1bU9v5+zvH4viN0+9lJerdLLizHtqJnhE5dtCyplzhzJ 1TcA71a4OjTdoXyDoB/lvtCBHrQoO63g+5J8+Vs+79sKLfJ7MvtCg2OBEaHIqbjt74RT 5oukNlmYJ62Lv7u0yabMTSN8F5ENAu6anzdBHI/CLa7N2c1jRyAOoEibLqxgcEgg56an l0RXadq2FTM0y5qTVUQxu4WNHwYGGCYPufRrhhM+JHUiRH7X43g2xXTFc1llrHfOSMES Zh7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MkpuAuyr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a170906084800b006e7fe0f67d6si1728261ejd.586.2022.04.08.14.53.32; Fri, 08 Apr 2022 14:53:56 -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; dkim=pass header.i=@intel.com header.s=Intel header.b=MkpuAuyr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236537AbiDHNvb (ORCPT + 99 others); Fri, 8 Apr 2022 09:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234611AbiDHNv2 (ORCPT ); Fri, 8 Apr 2022 09:51:28 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31C0622BF6; Fri, 8 Apr 2022 06:49:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649425761; x=1680961761; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JHxUCB/6BRTe6TReGYNBtiqtMSGrnYkHBfI8LfQrgAc=; b=MkpuAuyrMLyJ1ArysSQdpCuaxLCiO6z0Sdoi/DxQ1w/mH9YZUjglsKMH ZrkSNIkanshoxM/3iMjLb/RR0nLooF2vKPMjAaLWUabNjaMR/S70uw0hY xtRkZRmpM1+T/H3lJKNiaOnpXWhdsY8eJiPgKOrIF7iNEBF7ydS6bPXWb 4BkXBD706+QKUEQVis8tuE4oimpU/i+Mplqz53h/WLng0M4Qav4T+RPyL 5yZbrKjOll54TE8eIzspyldle1MrVq6qHllQbSz6/vknpQoMQ91msjyML rfaMCw7NfEutKhEQ5f6BcxbnXjwdtUgxkpFrIA4o/Jhf4IB0OOTHWJ2F9 w==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="242189596" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="242189596" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 06:49:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="550507028" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga007.jf.intel.com with ESMTP; 08 Apr 2022 06:49:16 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 238DnFvK003958; Fri, 8 Apr 2022 14:49:15 +0100 From: Alexander Lobakin To: Tony Nguyen Cc: Alexander Lobakin , Ivan Vecera , netdev@vger.kernel.org, poros@redhat.com, mschmidt@redhat.com, jacob.e.keller@intel.com, Jesse Brandeburg , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Brett Creeley , intel-wired-lan@lists.osuosl.org (moderated list:INTEL ETHERNET DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: Re: [PATCH net v2] ice: Fix incorrect locking in ice_vc_process_vf_msg() Date: Fri, 8 Apr 2022 15:47:14 +0200 Message-Id: <20220408134714.1834349-1-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401104052.1711721-1-ivecera@redhat.com> References: <20220401104052.1711721-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,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 From: Ivan Vecera Date: Fri, 1 Apr 2022 12:40:52 +0200 > Usage of mutex_trylock() in ice_vc_process_vf_msg() is incorrect > because message sent from VF is ignored and never processed. > > Use mutex_lock() instead to fix the issue. It is safe because this > mutex is used to prevent races between VF related NDOs and > handlers processing request messages from VF and these handlers > are running in ice_service_task() context. Additionally move this > mutex lock prior ice_vc_is_opcode_allowed() call to avoid potential > races during allowlist acccess. > > Fixes: e6ba5273d4ed ("ice: Fix race conditions between virtchnl handling and VF ndo ops") > Signed-off-by: Ivan Vecera Hey Tony, I guess you missed this one due to being on a vacation previously. It's been previously reviewed IIRC, could you take it into net-queue? > --- > drivers/net/ethernet/intel/ice/ice_virtchnl.c | 21 +++++++------------ > 1 file changed, 7 insertions(+), 14 deletions(-) > > diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c > index 3f1a63815bac..a465f3743ffc 100644 > --- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c > +++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c > @@ -3642,14 +3642,6 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) > err = -EINVAL; > } > > - if (!ice_vc_is_opcode_allowed(vf, v_opcode)) { > - ice_vc_send_msg_to_vf(vf, v_opcode, > - VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL, > - 0); > - ice_put_vf(vf); > - return; > - } > - > error_handler: > if (err) { > ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM, > @@ -3660,12 +3652,13 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) > return; > } > > - /* VF is being configured in another context that triggers a VFR, so no > - * need to process this message > - */ > - if (!mutex_trylock(&vf->cfg_lock)) { > - dev_info(dev, "VF %u is being configured in another context that will trigger a VFR, so there is no need to handle this message\n", > - vf->vf_id); > + mutex_lock(&vf->cfg_lock); > + > + if (!ice_vc_is_opcode_allowed(vf, v_opcode)) { > + ice_vc_send_msg_to_vf(vf, v_opcode, > + VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL, > + 0); > + mutex_unlock(&vf->cfg_lock); > ice_put_vf(vf); > return; > } > -- > 2.35.1 Thanks, Al