Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp4497482pxb; Wed, 20 Apr 2022 04:36:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtlLY08dCzURX2K8DmhtUrgV3FDNzHNcrSEQFm95uh12KzwUqdpZw24CfphrJNVQI1uqYa X-Received: by 2002:a63:901:0:b0:39d:9197:abc7 with SMTP id 1-20020a630901000000b0039d9197abc7mr18778085pgj.206.1650454588070; Wed, 20 Apr 2022 04:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650454588; cv=none; d=google.com; s=arc-20160816; b=MruQ7gHFGWIfwZ5czuXBi097mz+gr1wxKlsjWJ7Ly8acwIgixLuwZ9cnWbn9b+y/TV J5H3j11WvW7ZRlq4fZFEFHd0FTx3aj/+loz5NI5xdQWGt6VFvWxf250osAkWNvhBZzKD 48chKB+aZ4z8uubAz3848xnRv66+36arPdz5Cv58QmAGcYjlJfmlscJaITuhVXaKqWcA 6L70qBaVRAN6J4EyRq10W/fr3bJW5rLZCvTCDtqe8qjTcq1QZPaPHi4R+doUj+i9FZYw ZsHzLJtfKPyGzk37xA15mCZ+FTWQQZoEMHOkLNBka1qKf4FaUJyKtYKN/5rUbQy9Dh41 817Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=gx2u0UDEGlbJLmTjSX+0S/6XhMRFSaDMTCWYbhQAR20=; b=02rPSlKTUagomXIT0x1mqXvKxvwnQQ79AmjyaAE83VBGMtC0cj+F9yLY6+rna5pZhA /L3fAwZeTh1c0AB022iHbSpX+utq+tjyyM4fyhlK61R5CMyTLNiFGc80gQksVvtY7pMP YWl/IKQvAF4d0otdefAIFLghawpUcqLysNaqOCtFKaW0/wD2dtBtxh5ItZZKdkCFN9UP UuFzd/9KB98FUxvCySzB3YIG7Rnr8CfUF9vzLT9+/IadyAPpHrUN/x7mWW4H3QHVIPnY Xbqk27LZ4ePDcVzcWLhl+eUw7GDA3EihH3jryZUlzrNLgKPvpK4SFBNsuQM6+mvlj0sm VuZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZAgHLUuS; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p18-20020a056a000b5200b0050acaaed691si1496672pfo.268.2022.04.20.04.36.11; Wed, 20 Apr 2022 04:36:28 -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=@redhat.com header.s=mimecast20190719 header.b=ZAgHLUuS; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353230AbiDSOZQ (ORCPT + 99 others); Tue, 19 Apr 2022 10:25:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346781AbiDSOZN (ORCPT ); Tue, 19 Apr 2022 10:25:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4DABB2A27D for ; Tue, 19 Apr 2022 07:22:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650378149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=gx2u0UDEGlbJLmTjSX+0S/6XhMRFSaDMTCWYbhQAR20=; b=ZAgHLUuStRZQ86OVIarpNfLn4maSjxx2yl/hHawxCCgw2D6iV67d9XRvcwqDgx7eoWy1QP ptQH/TR6M+xTQTgHWGCiI99fKJCwgmZINDUf/IFkwsHXiWnDBn0Tf8jFVZf9xzvthcrudl Q3wjkv3E2hLJJHXd31yesNgE+lrPRa4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-502-2Ii0ajvxNeikvyfFkEhgzQ-1; Tue, 19 Apr 2022 10:22:25 -0400 X-MC-Unique: 2Ii0ajvxNeikvyfFkEhgzQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B3D86811E75; Tue, 19 Apr 2022 14:22:24 +0000 (UTC) Received: from ceranb.redhat.com (unknown [10.40.194.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAAC8145F94D; Tue, 19 Apr 2022 14:22:22 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: poros@redhat.com, mschmidt@redhat.com, Fei Liu , Jesse Brandeburg , Tony Nguyen , "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: [PATCH net v2] ice: Protect vf_state check by cfg_lock in ice_vc_process_vf_msg() Date: Tue, 19 Apr 2022 16:22:21 +0200 Message-Id: <20220419142221.2349382-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 Previous patch labelled "ice: Fix incorrect locking in ice_vc_process_vf_msg()" fixed an issue with ignored messages sent by VF driver but a small race window still left. Recently caught trace during 'ip link set ... vf 0 vlan ...' operation: [ 7332.995625] ice 0000:3b:00.0: Clearing port VLAN on VF 0 [ 7333.001023] iavf 0000:3b:01.0: Reset indication received from the PF [ 7333.007391] iavf 0000:3b:01.0: Scheduling reset task [ 7333.059575] iavf 0000:3b:01.0: PF returned error -5 (IAVF_ERR_PARAM) to our request 3 [ 7333.059626] ice 0000:3b:00.0: Invalid message from VF 0, opcode 3, len 4, error -1 Setting of VLAN for VF causes a reset of the affected VF using ice_reset_vf() function that runs with cfg_lock taken: 1. ice_notify_vf_reset() informs IAVF driver that reset is needed and IAVF schedules its own reset procedure 2. Bit ICE_VF_STATE_DIS is set in vf->vf_state 3. Misc initialization steps 4. ice_sriov_post_vsi_rebuild() -> ice_vf_set_initialized() and that clears ICE_VF_STATE_DIS in vf->vf_state Step 3 is mentioned race window because IAVF reset procedure runs in parallel and one of its step is sending of VIRTCHNL_OP_GET_VF_RESOURCES message (opcode==3). This message is handled in ice_vc_process_vf_msg() and if it is received during the mentioned race window then it's marked as invalid and error is returned to VF driver. Protect vf_state check in ice_vc_process_vf_msg() by cfg_lock to avoid this race condition. Fixes: e6ba5273d4ed ("ice: Fix race conditions between virtchnl handling and VF ndo ops") Tested-by: Fei Liu Signed-off-by: Ivan Vecera --- drivers/net/ethernet/intel/ice/ice_virtchnl.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c index 5612c032f15a..b72606c9e6d0 100644 --- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c +++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c @@ -3625,6 +3625,8 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) return; } + mutex_lock(&vf->cfg_lock); + /* Check if VF is disabled. */ if (test_bit(ICE_VF_STATE_DIS, vf->vf_states)) { err = -EPERM; @@ -3648,19 +3650,14 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) NULL, 0); dev_err(dev, "Invalid message from VF %d, opcode %d, len %d, error %d\n", vf_id, v_opcode, msglen, err); - ice_put_vf(vf); - return; + goto finish; } - 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; + goto finish; } switch (v_opcode) { @@ -3773,6 +3770,7 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) vf_id, v_opcode, err); } +finish: mutex_unlock(&vf->cfg_lock); ice_put_vf(vf); } -- 2.35.1