From patchwork Wed Feb 28 00:32:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brett Creeley X-Patchwork-Id: 207554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3051717dyb; Tue, 27 Feb 2024 16:33:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW0JFvOkSX0YOchFLz088F887HoZzFlfDQ4uLOSqM0+2DRLAEcdjHYUx3LKgEIkmnJFStKxmywmOczTE2cf1ArI6+yr3Q== X-Google-Smtp-Source: AGHT+IF07HcnAanpW6kBdIE6h7RSJaXU+9lLK0rCR/wF5vWE9Tnx9zZweGKDbWtzXg+/ZjZgKvF3 X-Received: by 2002:ac2:5212:0:b0:513:13e6:75d9 with SMTP id a18-20020ac25212000000b0051313e675d9mr1441111lfl.25.1709080403529; Tue, 27 Feb 2024 16:33:23 -0800 (PST) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q3-20020a170906388300b00a4367fec51esi1166517ejd.122.2024.02.27.16.33.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:33:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84278-ouuuleilei=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=@amd.com header.s=selector1 header.b=Vwoby5bU; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-84278-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84278-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com 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 EEA7C1F2BD08 for ; Wed, 28 Feb 2024 00:33:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 250EF4A2A; Wed, 28 Feb 2024 00:32:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Vwoby5bU" Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2068.outbound.protection.outlook.com [40.107.220.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31B3B36D; Wed, 28 Feb 2024 00:32:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709080348; cv=fail; b=mIBhReghhUR0sE2vPQcifCh+stTM1l20PiuqwIgNlh5WCpZ3gLsxvS13wW/xM2aCkpnN+jFwVnkl5/FhvWtYuz2X6dpAvajUyBW05dJyVslCI9GRVEOKDVkWDk8ImVmfciWKlxgYVoJMPCYnlfOSSzN0LdiLQQRO3DRBYuxM3sE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709080348; c=relaxed/simple; bh=04crYxxA8yx0KXUQq9CPGUsc2Rb/B4CN3Yh36ZOy6V0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A/E/WluctLGtbCTVKdSyEE9Nr4uoHPxP75OTDtHxaIt6Gfoyhda4/R7OnRppd7crlYlTOun0XpBFSxWwi8715GzsnIGtO4t+LiplKtNMJbsDRjvwkWstfm2glGnsTGTehnJi7x92yLbML9U89x/FTL25hatgyveecRPRfwjLA4Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Vwoby5bU; arc=fail smtp.client-ip=40.107.220.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ki3c1KRH0x3s0vgK8dgBPJVJ3SyuQ4ilxm2A9Gu883kzVIKnODb6CeFsVYBbhl2af5xfRF4L26eGQgvZA7X5aaWjqcDTVtz6DsxKc90GiaPreTdmfc509qTKMUFeYug8NTc0Y/geX16nfEvqJ5trgDBV7CZhvqhTUY0A1NrbASgeXKih0ID9wjcXwXz1Dc5JqQgikmRWBulHoXE3YmW3fFyeIX0T/w23/z6KdMAakDiCrO682kA6Cm5LdjsRFWNHSknoLtMj5keIiuRNMYXAeHEw72GiX1AIRjaCOBNtGJ1NZsiE+Ln0aNLw5mcIECmfU2wgx0trqukRcSWWPGWwIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YFTi1v3imxhCyek6/WfUKUpku6ct66CU+XUsMrHwZMM=; b=cVeVboID2579P86P1F4JQskGkk8VRYy4ztWzueF9q6MKs3lSWAQ7hX0+0G3vdcvotWm5/kzA9W/W2VqZUYLd41lI29kn9bOTwDS1wixVWQRUGvT7p5lyqkazpWrsWECuJi8+tdCHVc3ZG7Fvq4zBTImyoAwW47WlUqe6CG5Dv3v7VF8h9wh0eFVlH8icS/RDrgCrtrdU+ABvfyW5loWyaXKoXd92yvZzpGSlwp8a/hECfgpsv3lMRUrFD0NODXqYUauH5Ow9FgjxAXky4ndrB9FVe2F9VrF96+3pkoGM+ImdawUgc5x3fq/olg77p9dJXURGiRflaWwkYwIB+2wJuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=ziepe.ca smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YFTi1v3imxhCyek6/WfUKUpku6ct66CU+XUsMrHwZMM=; b=Vwoby5bUWZZ4xbbtqlNDgUqBfA7UV38havHR5Bejm6mgWERctOKJz8vwMBDiMvuVrjZM22ePmpoT34gWPM07l6k0zB3OAiC0uOZ/wJGCZ/sHHIgX7TA/w7tP/+roX8pUuXF3PE2f3E37TbHcCTWMgyZLpnwq+gjc578biinQ248= Received: from SJ0PR05CA0031.namprd05.prod.outlook.com (2603:10b6:a03:33f::6) by CY8PR12MB7364.namprd12.prod.outlook.com (2603:10b6:930:50::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.36; Wed, 28 Feb 2024 00:32:24 +0000 Received: from CO1PEPF000044EE.namprd05.prod.outlook.com (2603:10b6:a03:33f:cafe::52) by SJ0PR05CA0031.outlook.office365.com (2603:10b6:a03:33f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.27 via Frontend Transport; Wed, 28 Feb 2024 00:32:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044EE.mail.protection.outlook.com (10.167.241.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7292.25 via Frontend Transport; Wed, 28 Feb 2024 00:32:23 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 27 Feb 2024 18:32:22 -0600 From: Brett Creeley To: , , , , , , CC: , , Subject: [PATCH v2 vfio 1/2] vfio/pds: Always clear the save/restore FDs on reset Date: Tue, 27 Feb 2024 16:32:04 -0800 Message-ID: <20240228003205.47311-2-brett.creeley@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240228003205.47311-1-brett.creeley@amd.com> References: <20240228003205.47311-1-brett.creeley@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044EE:EE_|CY8PR12MB7364:EE_ X-MS-Office365-Filtering-Correlation-Id: d5a8086e-6f0c-4490-d1ed-08dc37f4bb8c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F+TbxPeKXbJFTgjH1S+H+Fb9w7rZflP1KXE9sq9kR/QtbCqG56K00x482YDUytj23BmwdNaHKm3eEcYtheTfY5a1PNzagvWasEFSoA7ScwRAHFx1J6QUaPvLZjZdQqYMCm3U3YyjHueV8V896oYPJsbPjZlxsJLSFuw6wfE+BIpH/q2rt+izwd6nM5t7oGPUWiW0mAfEGNL7ftfzkj6QA3R9LqcKstWQcuxurBK63bTWFw+sHPbIk80ECzciKd3PNE53lmo0LHsTJcXlZxPU43gDRRWjcbYKqfK1rGeuVg/o0O/Qeiz7iqz4w3MhkuBPNlb2bJwjHnJ4UD11l+TldDLCf12LQktdIK+lc3QtTqMHEp3dTZlHpcg9bsjzq39rxsHNlKtEH0I2dNZkmO9CQ5WmAOgX/ddnB1KyarCs+/Slzr7eY8zvVzytnHroylKI9QLUYd4JzCwzuTfYcPQ1dSfeTdCRp/ol0ZpHi61TSyJ9wkCc5x+LkWSCi7Y2Zg7fkCcwFoFI7j0RjnwNULRlJn8G4OlZnphOhdN8HoVyOD0h7wvw6QJJzmUbQAEGnlaozHJMMCA+pbv0UZC8ZXPdLGNwARrtl4yhk4+KuvQPi1m/JPE9dl4CzCMi5MEuz7o2RJ+RhRO7SCeQALEexr79N83ameFvP2NWA3jNe6OHtPuRwrbbBHMMTLm9yw8Oetud9X8DGy5i9BQellbdpW0xhzj85nTWaHhDAJlUxy7QN0zF/slfU5B6BGOukJtZWrhc X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 00:32:23.6165 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d5a8086e-6f0c-4490-d1ed-08dc37f4bb8c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044EE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7364 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792100693418774293 X-GMAIL-MSGID: 1792100693418774293 After reset the VFIO device state will always be put in VFIO_DEVICE_STATE_RUNNING, but the save/restore files will only be cleared if the previous state was VFIO_DEVICE_STATE_ERROR. This can/will cause the restore/save files to be leaked if/when the migration state machine transitions through the states that re-allocates these files. Fix this by always clearing the restore/save files for resets. Fixes: 7dabb1bcd177 ("vfio/pds: Add support for firmware recovery") Cc: stable@vger.kernel.org Signed-off-by: Brett Creeley Reviewed-by: Shannon Nelson Reviewed-by: Kevin Tian --- drivers/vfio/pci/pds/vfio_dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c index 4c351c59d05a..a286ebcc7112 100644 --- a/drivers/vfio/pci/pds/vfio_dev.c +++ b/drivers/vfio/pci/pds/vfio_dev.c @@ -32,9 +32,9 @@ void pds_vfio_state_mutex_unlock(struct pds_vfio_pci_device *pds_vfio) mutex_lock(&pds_vfio->reset_mutex); if (pds_vfio->deferred_reset) { pds_vfio->deferred_reset = false; + pds_vfio_put_restore_file(pds_vfio); + pds_vfio_put_save_file(pds_vfio); if (pds_vfio->state == VFIO_DEVICE_STATE_ERROR) { - pds_vfio_put_restore_file(pds_vfio); - pds_vfio_put_save_file(pds_vfio); pds_vfio_dirty_disable(pds_vfio, false); } pds_vfio->state = pds_vfio->deferred_reset_state; From patchwork Wed Feb 28 00:32:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brett Creeley X-Patchwork-Id: 207555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3051780dyb; Tue, 27 Feb 2024 16:33:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV5YNNjv4VOP5S6BRQmEQUBzaPCsiqxM1DCuDlp3N3aeDzTKsmR6kNMZcywvnhv3btny0CM7MYmvWdgXXJ7+7iy8+Avfw== X-Google-Smtp-Source: AGHT+IH2sPKctXdjyTwcypYi0sSQhLP2UPtWtixCg3MmLIHFZXjGBvq3K5PeHP4s70igBA4A9bie X-Received: by 2002:a17:906:1396:b0:a3f:c736:526d with SMTP id f22-20020a170906139600b00a3fc736526dmr861273ejc.31.1709080413710; Tue, 27 Feb 2024 16:33:33 -0800 (PST) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gt1-20020a170906f20100b00a43195a854esi1191364ejb.45.2024.02.27.16.33.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:33:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84280-ouuuleilei=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=@amd.com header.s=selector1 header.b=G17SRz60; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-84280-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84280-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com 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 9920D1F2190D for ; Wed, 28 Feb 2024 00:33:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3AE419BDC; Wed, 28 Feb 2024 00:32:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="G17SRz60" Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2057.outbound.protection.outlook.com [40.107.244.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E14D579E5; Wed, 28 Feb 2024 00:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709080355; cv=fail; b=QIZ4KoywndPINjHVOe8+xPPJnTnIvnmj16TkRSfObsAQvjNT2GKI4nPJY+PMrjoWD+A+7feMDMz25IaQJ0McgaOGIyHgms00gJ0YwxS1iOkQcwMExTpAL3UvHd4nDpo7Kx4gAyJrZgXfMo8PGGfIDCFVUbS3mgsLcTW2HKFYM/A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709080355; c=relaxed/simple; bh=nZ+eQdgS5SXO1P0UoXwfHFI1Lne+ke6IhtGbHEKYQnM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oAD/6keqDxKxITLacl2EKWiBJCWldUfL3U8Pw4dMbCXLQS5R8dh3oA8fkFT72nHamJ0U8klcIRZGWdhkNQEXKgH6Fp6U0Sij9An3JUBTKCrWm7Izh0YNfG+dY1PhL5JO4U+UzWyjJ6T6bRAKds+1Jt5oWsDW1/hrh7lUC+y4a7g= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=G17SRz60; arc=fail smtp.client-ip=40.107.244.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mFcffwQ8UY8ZKgQl/MG8gatgJDFlAVcFWgccRVdwSPIGXfgv29qPJXSmuxli1nN6Iegu77GfFF+qd+1Fj0O266gEcNe/Oawb/3TN3QqvZcaY4fZ4B5fAS0D1eoW7CgLTvLFxsmU9H6UETvL9WGEl6yMwlP/HRCLFITnPC1tiRiksTh848hctNe76H649P26rw79QS471fcP75NyfI9BoVOoECWK5KaeGViHadiTXgdK1MEF2aNw7ynHMKNMYEi7hdYP1vsbl3CvbiV42aJEjDLhdq4gGQMz0cr+ENBrTF76ngfWMI9esnmWjdQP32M2LtnP+UrDCiX28opPVNa3Icw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ws91NiYtg4bM+b9Kg5rN+YdWJ+f7mRFZ+d6ixZOP/rI=; b=njHIxZBaybt5tewWugxUvf+x2GGMuIWDdjhTpZl4bzwvVQBee4Y0RRjeELKA45TD9FR4saih1jr4ypdIhEE/vsY4+OmIcUM1+CBDu/8QU9LCku0Dn9C4hmD+U0siocx6ecmoV19jWySBek9D4q0Ge2w0YvUNz+Hj7mSQiSA3ggYRToVExgNVQ2ZaMr7WE+7aASpSh3Z9tLn89YXz0oA+Ljv1GaQ0uF9Q+V7xLYhJT5PF23EPv8ssWT4EP0FiXqB9XYn0krjMX+3qfrSV3KjvtT3xeQWJCMYC6y3eRFklYsaChmH8Q0ft8zwTaXXVzP05rYrm7i6DGTBUvDyVvhs2Dw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=ziepe.ca smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ws91NiYtg4bM+b9Kg5rN+YdWJ+f7mRFZ+d6ixZOP/rI=; b=G17SRz60tjGEvVqtay+VTJ4kS1tW2L4g9WBA9ijbJDWRvOTp7UJAkZfuJvuGjyhoTmyD6yrql1lpgyJCzv0A4GXEZkFpRwIMIVs1uif8Q+BrCQdxO30C+T6rXZUSNh0hYWWbYzlfjTcFkKxH2pKvsoipZvUUhjToQ9ObxvPk+2k= Received: from SJ0PR03CA0031.namprd03.prod.outlook.com (2603:10b6:a03:33e::6) by CH3PR12MB9432.namprd12.prod.outlook.com (2603:10b6:610:1c7::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 00:32:25 +0000 Received: from CO1PEPF000044F1.namprd05.prod.outlook.com (2603:10b6:a03:33e:cafe::90) by SJ0PR03CA0031.outlook.office365.com (2603:10b6:a03:33e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.50 via Frontend Transport; Wed, 28 Feb 2024 00:32:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044F1.mail.protection.outlook.com (10.167.241.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7292.25 via Frontend Transport; Wed, 28 Feb 2024 00:32:25 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 27 Feb 2024 18:32:23 -0600 From: Brett Creeley To: , , , , , , CC: , Subject: [PATCH v2 vfio 2/2] vfio/pds: Refactor/simplify reset logic Date: Tue, 27 Feb 2024 16:32:05 -0800 Message-ID: <20240228003205.47311-3-brett.creeley@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240228003205.47311-1-brett.creeley@amd.com> References: <20240228003205.47311-1-brett.creeley@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F1:EE_|CH3PR12MB9432:EE_ X-MS-Office365-Filtering-Correlation-Id: e0c8b115-d7c4-4244-7324-08dc37f4bc5f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8X/Gf+OeuLAwFsIQUYFvQMpUP1lWsnGGHp0omQr3TyXNlSD6yWi9y9aUBAEtet+bIV0lAzX5zehtao4Z32i6OGYihyfHpd/PKLR5C/xespIfLwxxEOrEx93C0JkhRw31xy/r8ajRUYbeQtvnteEcGUrbgez803W/5GlNKhTgLhJLK422C9hjMklNC+5dJqbckPsLToDeKHIQibO/60DzlVL2Og+cUI6tQJ28ghNFHXATVNtM5G/qBVZE6FGTXwu1xp5vtTsw3/+QbTpjYK5qyxRariZSNdBR5bxktdthtsadjzEWFSvHbCIxtauc1yjJipj9vBE3U4v2X6UDkVP6mdS8Es1ziFmGXhIYNWKaATANjz7capnjMMaN55ET6PQoM+q2f1H/7GZ0lD5jgUwFAMbdbZxrHjMBzHce7IKOd7hkW+43g0/P+nGqkXwvup/39DLdMx1xzMiCNpkWIxP9forenbGE/C0oHEzcdGUuXl5S7bbN94gIyPLYUAyWusTJDrW/l5Iu8LkSqDdj/0491E9stCE1hlqhEXEMXxrJ9nZTKToQXt+3IunWPaX83gXOk4KHpADJDKasz+dvnxStlkLAA0sBL73H5qPI/BKIg5PeE8XVb5GQCjCg7fmkFmaXI+Gnt6nk6SSCxy+dtgh+7+4HPDWxSE2/IEYx1nGdkaFx6vpNaX1IhzakWoKVs7hrGTDGmxKAu7AvLBzBAf84XVlAg+6z20/F3pwVGoWi9jau4O1peKKNzgp89AN9B7iE X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 00:32:25.0125 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e0c8b115-d7c4-4244-7324-08dc37f4bc5f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044F1.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9432 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792100703932994929 X-GMAIL-MSGID: 1792100703932994929 The current logic for handling resets is more complicated than it needs to be. The deferred_reset flag is used to indicate a reset is needed and the deferred_reset_state is the requested, post-reset, state. The source of the requested reset isn't immediately obvious. Improve readability by replacing deferred_reset_state with deferred_reset_type, which can be either PDS_VFIO_DEVICE_RESET (initiated/requested by the DSC) or PDS_VFIO_HOST_RESET (initiated/requested by the VMM). Signed-off-by: Brett Creeley Reviewed-by: Shannon Nelson Reviewed-by: Kevin Tian --- drivers/vfio/pci/pds/pci_drv.c | 2 +- drivers/vfio/pci/pds/vfio_dev.c | 10 +++++----- drivers/vfio/pci/pds/vfio_dev.h | 7 ++++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/pci/pds/pci_drv.c b/drivers/vfio/pci/pds/pci_drv.c index a34dda516629..4ac3da7abd32 100644 --- a/drivers/vfio/pci/pds/pci_drv.c +++ b/drivers/vfio/pci/pds/pci_drv.c @@ -57,7 +57,7 @@ static void pds_vfio_recovery(struct pds_vfio_pci_device *pds_vfio) if (deferred_reset_needed) { mutex_lock(&pds_vfio->reset_mutex); pds_vfio->deferred_reset = true; - pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_ERROR; + pds_vfio->deferred_reset_type = PDS_VFIO_DEVICE_RESET; mutex_unlock(&pds_vfio->reset_mutex); } } diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c index a286ebcc7112..1a791bef5de1 100644 --- a/drivers/vfio/pci/pds/vfio_dev.c +++ b/drivers/vfio/pci/pds/vfio_dev.c @@ -34,11 +34,12 @@ void pds_vfio_state_mutex_unlock(struct pds_vfio_pci_device *pds_vfio) pds_vfio->deferred_reset = false; pds_vfio_put_restore_file(pds_vfio); pds_vfio_put_save_file(pds_vfio); - if (pds_vfio->state == VFIO_DEVICE_STATE_ERROR) { + if (pds_vfio->deferred_reset_type == PDS_VFIO_DEVICE_RESET) { pds_vfio_dirty_disable(pds_vfio, false); + pds_vfio->state = VFIO_DEVICE_STATE_ERROR; + } else { + pds_vfio->state = VFIO_DEVICE_STATE_RUNNING; } - pds_vfio->state = pds_vfio->deferred_reset_state; - pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING; mutex_unlock(&pds_vfio->reset_mutex); goto again; } @@ -50,7 +51,7 @@ void pds_vfio_reset(struct pds_vfio_pci_device *pds_vfio) { mutex_lock(&pds_vfio->reset_mutex); pds_vfio->deferred_reset = true; - pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING; + pds_vfio->deferred_reset_type = PDS_VFIO_HOST_RESET; if (!mutex_trylock(&pds_vfio->state_mutex)) { mutex_unlock(&pds_vfio->reset_mutex); return; @@ -194,7 +195,6 @@ static int pds_vfio_open_device(struct vfio_device *vdev) return err; pds_vfio->state = VFIO_DEVICE_STATE_RUNNING; - pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING; vfio_pci_core_finish_enable(&pds_vfio->vfio_coredev); diff --git a/drivers/vfio/pci/pds/vfio_dev.h b/drivers/vfio/pci/pds/vfio_dev.h index e7b01080a1ec..19547fd8e956 100644 --- a/drivers/vfio/pci/pds/vfio_dev.h +++ b/drivers/vfio/pci/pds/vfio_dev.h @@ -10,6 +10,11 @@ #include "dirty.h" #include "lm.h" +enum pds_vfio_reset_type { + PDS_VFIO_HOST_RESET = 0, + PDS_VFIO_DEVICE_RESET = 1, +}; + struct pds_vfio_pci_device { struct vfio_pci_core_device vfio_coredev; @@ -20,7 +25,7 @@ struct pds_vfio_pci_device { enum vfio_device_mig_state state; struct mutex reset_mutex; /* protect reset_done flow */ u8 deferred_reset; - enum vfio_device_mig_state deferred_reset_state; + enum pds_vfio_reset_type deferred_reset_type; struct notifier_block nb; int vf_id;