Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1944471ybv; Fri, 14 Feb 2020 08:38:49 -0800 (PST) X-Google-Smtp-Source: APXvYqy3Er7QtNDXn0brU4KmynlwHBGkYE4Sq5sw/gFDluOv2cCBKxd/Gsqp+5VbVGDLkT9FBYMu X-Received: by 2002:a05:6830:1d5b:: with SMTP id p27mr2865629oth.263.1581698329699; Fri, 14 Feb 2020 08:38:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581698329; cv=none; d=google.com; s=arc-20160816; b=Sm9qHdtK4+wy+qav6fOg3EIvNe96dbJq+XKMXZL1tzAcBW4yXh+UHJkucxRjinHv08 nsTB86A6nSEwYGfmumbEq+5MIpAgc7Ku+tHI4hFoSsAp4gUMJ1FJj2ICm/yUERiPQIoW 1CFkZFjqBX+KHpl72EcEo2vFdT1Za7CgitZ3C09vFHfpcUapgeCD4qNCz/TgfGHcHYz2 +qkAVSoJL1eCl7YvMRBGXr80jhQE77Kx/chiTnscsgfGg8WAmc1ZYxsgdK69AHfaZLeB xOb+mv+lWRjzAn1afC91qLe4I/mMHd3wlA1DJ08Y/Ns6hxkHvPSNdQtCG9ZITnTBKhVl 7U8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AM7qa/+LeQRIkrI4Jdv9StmQG0mHFzKB5pq7AuL0OzI=; b=Jz0CbA7FH06hNxOu9lbjfj9Qax/yx0JvQrbjPxLksMUCE9ZgrOJepU7vXZvOSOaEaU kM2iudbUwhN31jR2ljbt6dB5p/LgpCRelo0joGhIVSFpOLqUxj1VVyahRsoNvvA0EWyU KsaBkyAZrc0em4eWaH+0v78ZxSew8fO5wMs6928AYp4gSk09f7CtMKCBYGQtiheurznR nwf/pi+PcnUalAP7Hrer8kOE6WEIp9hiU7AU3fFJEE5ZR3oMyftj8vJf0N9/2VHL3uWk mCOUFOcQoziHLMIRgTlIs1AFhCPAz4nuA9ifGKhOtvBnfyMlCj6S4DG3PVwPjFanXxJc P2Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZLp0K6hG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 25si2909369oiz.230.2020.02.14.08.38.37; Fri, 14 Feb 2020 08:38:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZLp0K6hG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393695AbgBNQh7 (ORCPT + 99 others); Fri, 14 Feb 2020 11:37:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:60268 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405710AbgBNQXp (ORCPT ); Fri, 14 Feb 2020 11:23:45 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A3C4624779; Fri, 14 Feb 2020 16:23:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697425; bh=V+Ce6ZOwPdQjcoMItnjmu+Ljkq7PcR3PpGh153vbJNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZLp0K6hGpnrhgDd1jOfRt9a9wO3ylzYyDgx0gohVdbbD6wXjSMIWea2wAwSsqlbZC Bh7Zp3N6TgF3F3KeiqNF8MmjbMT+k18ulmXba37mTAa/I7iGF/tz5xLSWnMUGRgKuj ffYCb59jVn/xFE00d6y832A6AAhLiILl5WcFI6RQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Oliver O'Halloran , Sam Bobroff , Michael Ellerman , Sasha Levin , linuxppc-dev@lists.ozlabs.org Subject: [PATCH AUTOSEL 4.9 114/141] powerpc/sriov: Remove VF eeh_dev state when disabling SR-IOV Date: Fri, 14 Feb 2020 11:20:54 -0500 Message-Id: <20200214162122.19794-114-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oliver O'Halloran [ Upstream commit 1fb4124ca9d456656a324f1ee29b7bf942f59ac8 ] When disabling virtual functions on an SR-IOV adapter we currently do not correctly remove the EEH state for the now-dead virtual functions. When removing the pci_dn that was created for the VF when SR-IOV was enabled we free the corresponding eeh_dev without removing it from the child device list of the eeh_pe that contained it. This can result in crashes due to the use-after-free. Signed-off-by: Oliver O'Halloran Reviewed-by: Sam Bobroff Tested-by: Sam Bobroff Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20190821062655.19735-1-oohall@gmail.com Signed-off-by: Sasha Levin --- arch/powerpc/kernel/pci_dn.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c index 5926934370702..c8f1b78fbd0e2 100644 --- a/arch/powerpc/kernel/pci_dn.c +++ b/arch/powerpc/kernel/pci_dn.c @@ -271,9 +271,22 @@ void remove_dev_pci_data(struct pci_dev *pdev) continue; #ifdef CONFIG_EEH - /* Release EEH device for the VF */ + /* + * Release EEH state for this VF. The PCI core + * has already torn down the pci_dev for this VF, but + * we're responsible to removing the eeh_dev since it + * has the same lifetime as the pci_dn that spawned it. + */ edev = pdn_to_eeh_dev(pdn); if (edev) { + /* + * We allocate pci_dn's for the totalvfs count, + * but only only the vfs that were activated + * have a configured PE. + */ + if (edev->pe) + eeh_rmv_from_parent_pe(edev); + pdn->edev = NULL; kfree(edev); } -- 2.20.1