Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp794798lqt; Tue, 19 Mar 2024 04:18:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUcriTZ2e3rxw6twGWhpflx7ihcFq2M60JJUmlkS5cF8IbWemilF1ipJz+EuX+aBnfTR2Nh7h4c20vf8QOs81nyJ72Nlq++D/BnuNDDNQ== X-Google-Smtp-Source: AGHT+IFGBjCae95mWBRPIYw9Kd8Rtf5hXgnNNqAm1Vz6lO7O5XXVgF7BBl6S2AjxwKTwcT3nAgwL X-Received: by 2002:a05:6402:ea7:b0:568:3362:ccd1 with SMTP id h39-20020a0564020ea700b005683362ccd1mr8285444eda.1.1710847091146; Tue, 19 Mar 2024 04:18:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710847091; cv=pass; d=google.com; s=arc-20160816; b=f93Or6x+qEDC86tDj+/kb8BPo0JPUWLWiTc8VOWk6CLmjx6HcJM5xjYPHDdPC5ugsD mj729n9svzZrhBDOM7G3pRIX3rb0Dmy+FaDazmCkkWu0HthzQWMjs7gZx8c/TbaPVjRK 8aqly/v5sut3uEqs+gw0lxVEUAYVEVZdm1Yw5J5QmsrTsRiVljGY4VkSaavlWIH3Gyeb dPHgmIH8Y6ySsdSnJhPjbGK9Tu83cc5vQRk8OfPwm6GdjPSp6uZejAy8Ts0k6JTTfd3x tUg8eSX+OD8MumCrk4AJt+OLPFWeIbtDbgV1zMk4td1FeVmh9QpOxHVCSUgUDxFF14fZ a5yQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=kcvCGlMHRwj9k6ByHHyaeay4OtVn7NmyScS9HG65Uco=; fh=WsrmuoI6JlDBXHw4hut1nzvC6r9ngP9Z4b2VsKts8vs=; b=mDZRf0xJ5f7cgtdBxdOIz9h+mSHjPOQ/fRj4BgsBa//cIghmOnhwOmNmPFyWRW/xew fmCPfzZKPFkBGyNVUeAw3mCENac3uMX9ZgbYLj4uD+mobwcsZhD+Z0LJNH84XznRjzt/ mr82Wzp34fHe8FeICsShvcQzw6JvgJd4Qlr237rgfv+GLJgtJ7vtHXeNx16EgPfzTjNL S/XA8dkWZ0HJZ7xWCQiuFdL6pVxmyg/a4HvwJlIsFBPKky5bOuwbj824cSlkgkWf0z32 EILpf8ZYuP3L04oWF8hvJSemkx0kvbK5m2GM7SHn76ruMCV2wGqxReothFbYxA83HYVp ESzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@resnulli-us.20230601.gappssmtp.com header.s=20230601 header.b=R2lHCizn; arc=pass (i=1 dkim=pass dkdomain=resnulli-us.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-107449-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107449-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ds2-20020a0564021cc200b0056b9ae7fb1esi390902edb.667.2024.03.19.04.18.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 04:18:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107449-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@resnulli-us.20230601.gappssmtp.com header.s=20230601 header.b=R2lHCizn; arc=pass (i=1 dkim=pass dkdomain=resnulli-us.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-107449-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107449-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DBBAF1F22E1E for ; Tue, 19 Mar 2024 11:18:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 274425810A; Tue, 19 Mar 2024 11:18:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="R2lHCizn" Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1379E54BF6 for ; Tue, 19 Mar 2024 11:17:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710847079; cv=none; b=SpugGnpdm3mVhntE00wPw2movglc/xpNnrUZcjl7OYDPXlLxH+ZJ62HVfABmujAyxuB2b65nkd8zwScz7ts0EmVlQmmR3ng8tS/8VCCF6SIPW/S1k1lgu+KVbNKYefnopSjnjvQWK+mTfxQwd3UyGGmS/IgNaO85sdgG9R2FEuM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710847079; c=relaxed/simple; bh=qbS/Fq6/ZtBC6Ftwa7pn2jPBmoaqXs1RyTvJMpw3UQc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ek03O7/A4IIKefvR8CdtWgHsjnUvz7xGfIcLMCkW8oZp0qcxF8SvAhbjQ+tfgp5DX77tBkxOT1ZlWVMQsZ9oQFowaybmFDwtj/ShAKwdfMyfmvLW0UvhRMyn+vlD0IzdfOeWTuoVBak6I6dTuMQmbqZggzmEyEd6ATauA9mM+gc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us; spf=none smtp.mailfrom=resnulli.us; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b=R2lHCizn; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=resnulli.us Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4146172fb7eso10885555e9.1 for ; Tue, 19 Mar 2024 04:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1710847075; x=1711451875; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=kcvCGlMHRwj9k6ByHHyaeay4OtVn7NmyScS9HG65Uco=; b=R2lHCizneRB+LKYuLEQfSKd6olc5CnyhRIx8n8NRaba+xTEup6yMpkvwRsAIhY44rA 6BRgwTEkeHNp1ZUFx6Wk9x6nTqT0FXhC/UvJSMJE8vyIUtTTuL9GDy1qJrpoBwTaD1r5 Rx4ruZR07vVF99oIFV/o45tVb+UPQfYrKfxNeELy5z187biUT99KXuQQomZiPtvNY0Fd xA0RiLsdlcN0odBR75YnU2qKVa7KWMZCv89mDdHhsVDOz6tjPsK66j3/fh85FpADghEL XRRvH+7P1UsrzFMjsrrPhVi7oJeOa9EGCIkIouAY0vsKaadmxHjhL4sYN5tIDIiy3joe /ryw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710847075; x=1711451875; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kcvCGlMHRwj9k6ByHHyaeay4OtVn7NmyScS9HG65Uco=; b=lRad9BJ6iR8PrMr0iOpEsb/TiQUihqEWXGOATijnM6QaPj7K6zI3LDc5bS9MVuxq8t vGBxuLcvbIKQvNeCOsZSEemWIn4aNQEfqzWFGuzYAPk/EVvDJFUWiJvcbW5ZAChXtWXo FBbMUQ/5PJVLJtHk7nRbEZWYYJfuFEJQIqDztmSf8bFIX9kE5jj7fQHNMeLchqHBxsVo P0HrKL8VciUbaKVCOA3HVJSiz5ybmXclBOzyY+hqi+COkPBX8H7CzMW+DSF5wLD+fr6A Rit+vZvSMqwn5rAkHsyjJc0CgnhbJ67SLzsRrFmc1bRRFosEupZUFM0gJoRWaM9Wr9MR rRqA== X-Forwarded-Encrypted: i=1; AJvYcCXf5htrNEqJAhtHZShQxaPexEbf5pgueDDfUPyYb+CjrW9QQPiEMclQMonSTf3fNRYwWf1pRM2M3TMDGpz2GQThDXMPzIGYSut8aTSH X-Gm-Message-State: AOJu0YzHTOvbGiTL7Vc0S/CagOWSK7pO+adEdioOlfnkRUZI9Pjj5ZNo svNVld8GqK5DY4FB6WzEq7/gfSVF5u4vFJ0ZAO1QnHFXukLHJsdX8NLLgjIs4Hs= X-Received: by 2002:a05:600c:3556:b0:412:beee:36b3 with SMTP id i22-20020a05600c355600b00412beee36b3mr10520229wmq.7.1710847075115; Tue, 19 Mar 2024 04:17:55 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id d20-20020a05600c34d400b0041466d8e33bsm1183307wmq.27.2024.03.19.04.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 04:17:54 -0700 (PDT) Date: Tue, 19 Mar 2024 12:17:51 +0100 From: Jiri Pirko To: Jijie Shao Cc: yisen.zhuang@huawei.com, salil.mehta@huawei.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, michal.kubiak@intel.com, rkannoth@marvell.com, shenjian15@huawei.com, wangjie125@huawei.com, liuyonglong@huawei.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V3 net 2/3] net: hns3: fix kernel crash when devlink reload during pf initialization Message-ID: References: <20240318132948.3624333-1-shaojijie@huawei.com> <20240318132948.3624333-3-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240318132948.3624333-3-shaojijie@huawei.com> Mon, Mar 18, 2024 at 02:29:47PM CET, shaojijie@huawei.com wrote: >From: Yonglong Liu > >The devlink reload process will access the hardware resources, >but the register operation is done before the hardware is initialized. >so, if process the devlink reload during initialization, may lead to kernel >crash. This patch fixes this by checking whether the NIC is initialized. Fix your locking, you should take devl_lock during your init. That would disallow reload to race with it. pw-bot: cr > >Fixes: b741269b2759 ("net: hns3: add support for registering devlink for PF") >Signed-off-by: Yonglong Liu >Signed-off-by: Jijie Shao >--- > drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > >diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c >index 9a939c0b217f..80db4f7b05f6 100644 >--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c >+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c >@@ -40,8 +40,9 @@ static int hclge_devlink_reload_down(struct devlink *devlink, bool netns_change, > struct pci_dev *pdev = hdev->pdev; > int ret; > >- if (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state)) { >- dev_err(&pdev->dev, "reset is handling\n"); >+ if (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state) || >+ !test_bit(HCLGE_STATE_NIC_REGISTERED, &hdev->state)) { >+ dev_err(&pdev->dev, "reset is handling or driver removed\n"); > return -EBUSY; > } > >-- >2.30.0 > >