Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1016671pxb; Fri, 15 Apr 2022 18:28:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY1DW8gYq9Wr1YMPA6vaLBYxt6jcZcCrsm3PA4YkWhhBuPzZH+EumI4vdgbyLMMFK5IdWT X-Received: by 2002:a17:902:9a0a:b0:158:a22a:5448 with SMTP id v10-20020a1709029a0a00b00158a22a5448mr1641992plp.20.1650072481730; Fri, 15 Apr 2022 18:28:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650072481; cv=none; d=google.com; s=arc-20160816; b=mHY6rzJMjeX3gnyyF5OPz7gMvV+y2I6Zl5FexTWZhDTDRyeoyjwT2JPjUuxLMtJSyC Xg72hk9euafQ5Z/NDLWKqDgCklxsBd5G9Po0IwkLG7MTNUk9dhzFckHQkkZcuUUxbgC3 ZI+g01UXHvdrJEFHM5Qd6jAF9ly/MIz6tLdFbC4ZQ29Vje5THgkz3uqUQtu2ZYwPeCvk lF6/6I2APazJGMYWaqyu/M7oeq64iG5uE+zzl/CFAkq/oBv2gZWn3FUEebvl3ROJp/LW Zo5pi3deigVNCiydPr0hFle42R/w0MZp089ScK7ad5WVvNKN9Kzs1rMYqaofLKIBs/jN HARw== 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:subject:cc:to:from:date :dkim-signature; bh=xuws84Z0jp4NihhTFNZTBNeED6UNObMvI7eL6H7Gs80=; b=wE+RCpEIIJ5NBVKACUC8yjVt/DJoInCWKBIKwLvzzCn9Iwl9HyPvoTJd5VJ5a8eQdS j2HmWVRhZsxmizmz+YE/BmNMPSw1jfH9eFHv7UBvvQmyIwbNNEpqqya0G8gSyrMNy/Jv 5AajjezqSjyXIf8koQlk1EKVf4n5KwMDjx81sbzFLZj1q4zIqhJBk7zTd5fwTwAsdMrr IdaTxqVWznWq47Ul0h1i5pP0sKBuV2qMuG/lQpHhOIAEpuyBioecyRz0o7hbUrssseyj /qYa4wB4HiI72dko/SCVWzTm/S+fQA4D/EPysn7xuqI02YCc1o/CAbsxtYpk4Y8T6eZp KmuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q62qY+jF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c8-20020aa78e08000000b004fa8a73c6ecsi2635874pfr.180.2022.04.15.18.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 18:28:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q62qY+jF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 67564EA742; Fri, 15 Apr 2022 17:58:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355655AbiDOPwP (ORCPT + 99 others); Fri, 15 Apr 2022 11:52:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344499AbiDOPwL (ORCPT ); Fri, 15 Apr 2022 11:52:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6423E17A87 for ; Fri, 15 Apr 2022 08:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650037781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xuws84Z0jp4NihhTFNZTBNeED6UNObMvI7eL6H7Gs80=; b=Q62qY+jFPSM29dBPtHmf4OiQev367SUIPEqcK3De4JL9ESVJuCXrzTCS2/AYfKqxWn0wld VYs/w9O6TjciqZK8gf6WxlxNv8UvPCBXcDTPNylIPw0g1VY429cvw03IwDuP7Q+5gFYfaz biuhNKlTeHk5HPqLM9/NhtbZSmWZ58M= 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-203-IMKEHtUKOHa8JFhxqrqjmA-1; Fri, 15 Apr 2022 11:49:36 -0400 X-MC-Unique: IMKEHtUKOHa8JFhxqrqjmA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 965C51014A61; Fri, 15 Apr 2022 15:49:35 +0000 (UTC) Received: from ceranb (unknown [10.40.194.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0114404E4B0; Fri, 15 Apr 2022 15:49:33 +0000 (UTC) Date: Fri, 15 Apr 2022 17:49:32 +0200 From: Ivan Vecera To: Michal Schmidt Cc: netdev@vger.kernel.org, Petr Oros , Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Shiraz Saleem , Dave Ertman , "moderated list:INTEL ETHERNET DRIVERS" , open list Subject: Re: [PATCH net] ice: Fix race during aux device (un)plugging Message-ID: <20220415174932.6c85d5ab@ceranb> In-Reply-To: References: <20220414163907.1456925-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Fri, 15 Apr 2022 13:12:03 +0200 Michal Schmidt wrote: > On Thu, Apr 14, 2022 at 6:39 PM Ivan Vecera wrote: > > > Function ice_plug_aux_dev() assigns pf->adev field too early prior > > aux device initialization and on other side ice_unplug_aux_dev() > > starts aux device deinit and at the end assigns NULL to pf->adev. > > This is wrong and can causes a crash when ice_send_event_to_aux() > > call occurs during these operations because that function depends > > on non-NULL value of pf->adev and does not assume that aux device > > is half-initialized or half-destroyed. > > > > Modify affected functions so pf->adev field is set after aux device > > init and prior aux device destroy. > > > [...] > > > @@ -320,12 +319,14 @@ int ice_plug_aux_dev(struct ice_pf *pf) > > */ > > void ice_unplug_aux_dev(struct ice_pf *pf) > > { > > - if (!pf->adev) > > + struct auxiliary_device *adev = pf->adev; > > + > > + if (!adev) > > return; > > > > - auxiliary_device_delete(pf->adev); > > - auxiliary_device_uninit(pf->adev); > > pf->adev = NULL; > > + auxiliary_device_delete(adev); > > + auxiliary_device_uninit(adev); > > } > > > > Hi Ivan, > What prevents ice_unplug_aux_dev() from running immediately after > ice_send_event_to_aux() gets past its "if (!pf->adev)" test ? > Michal ice_send_event_to_aux() takes aux device lock. ice_unplug_aux_dev() calls auxiliary_device_delete() that calls device_del(). device_del() takes device_lock() prior kill_device(). So if ice_send_event_to_aux() is in progress then device_del() waits for its completion. Thanks, Ivan