From patchwork Fri Oct 27 22:36:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brett Creeley X-Patchwork-Id: 159191 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp923523vqb; Fri, 27 Oct 2023 15:37:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGLajh6luIA6OC3Xyt/vfqGqLOxxmEgJ7JbLzxPuHKWIlEXWf9CV0dSbVZSadLdyB0RzG5 X-Received: by 2002:a25:b11c:0:b0:d9b:351:6657 with SMTP id g28-20020a25b11c000000b00d9b03516657mr3974995ybj.23.1698446261629; Fri, 27 Oct 2023 15:37:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698446261; cv=pass; d=google.com; s=arc-20160816; b=xkdWUfWvDeVI6ZQZTthmGAG3yN8+k18ACcofl3w2HqiQo+tviPQQgNxpfJ5X+TU2TX YeWV01nqxgEezFwu9teOFeuhS4mTKxbIfwF46tjhXiYHtXxhLxqjZXNBniE5mH1n0oVL f+SBFU9Cw1Gvh5J2UZbiZkcbQuKyT2PTeS0yfYjULHlmzx77bGCauPe3krRua89oJF0L ekxnpZ+bv1rw7SBSNvHqfHzxW+dJe6iCt9PBO64rI1fbrPsqchG+xybyb2XfpFOG0YSf 6iyqkb3+JVv06YkAU/WeETysLvvRBTyvFvlUFUfFvuiAOnU7R8JeEvv/LErSFL8NnE/z zyVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=K43OMtLi3SL2eBNzFpi18AFLkQEj3+mlb2T7C6faEBM=; fh=GbNd0iuihik10v4ZTZpqkH2SVSESc+5QskJdSEY04s4=; b=pEGaniO9aB64xdKddfB+bn9CWwmjtw7AV4NJmHL2xcreeGgX/gYHudyjIE6CJRcihj vkD3F/8kF83tm7pWE9UxvEqk6wL3nn8srQcbZQrdK0Tkcm3ofI2YTrWisiQ5ZI/JNiq3 HgjTbYSGMJXyh0z1mAI7s11xlZRcPpyM46Etr/x2WKpnrROdEGE4fJMxHYDmEPqcyjEa ONac2D3BFFUgk0AYhGdI5ksxX30rolttieqxir2zhx7+2Tdoa+Tqu0Avib0XrFpZrxU8 p0Urn7WuEPZRE2BLnvQHuQ9GkySHlYuxqKudErvtuSB+eT97pL6chnA14KrLNz1II/HA uo5A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Chwzfaf3; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id o194-20020a2541cb000000b00d9cb78a4cd2si3917091yba.243.2023.10.27.15.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 15:37:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Chwzfaf3; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 4A3D38325235; Fri, 27 Oct 2023 15:37:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346653AbjJ0WhR (ORCPT + 27 others); Fri, 27 Oct 2023 18:37:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235085AbjJ0WhP (ORCPT ); Fri, 27 Oct 2023 18:37:15 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2046.outbound.protection.outlook.com [40.107.93.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4CB71A5; Fri, 27 Oct 2023 15:37:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Om9Rvjj1/cWYaeM9fjxFcc3kyxhxEGbc/HiORJDi42ZpNr7lYtwMOMwj6yE3Z5uwUaC8mvZzN6IHTed9GlRbFEWqT8ehSuzdtkLls124S/8G9nyegb51sp+fKbhd1xFQyWgpAPD5evMrH1d6hV/oa9wlg9QWGKoadonKpDJtqRyqu636bCjW1R5fOYzUruPEiT0K66jbSJ3vUV6IXjMJXOoGnkdKbradteoLcd11CREarKjFwdd+TBvRS2CrAOOtnpQ+DhQhgoe+uzgBNsogGb3FXkJ0SirNQUL9RhiQkbkdqN4qDFvpxzQwQ0ebbSvQEkcl6lJMnHJY1ysFuD+3eg== 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=K43OMtLi3SL2eBNzFpi18AFLkQEj3+mlb2T7C6faEBM=; b=j7JB1p6rjmzpzkSd7UTAWJsjnKaniTQhjzBjpvRWQ3gKshUVbTnTbTZ9SZUKdiKjGlXXYlF7gm015HcwYnd3edOlPWfXx1DzzWZ4dHxHT5fZ78eY4trkC6CG88qLbB+EzBuW0L3YRJ/w6Sm7hSjljA7OO0QwRtcPGFyfZxHsTWlA4w/eGv55jl+snJaoo/Pz71gHyF6bl2DYYVXvQdDqAUQmAyRvikWVrkus7uttDaP0tF5VYYAZxAuCPnjuYz1CB8ivkOqV01fiPyqk0HJP3D9eCRQnhBqV++QLPu8jI5ZxaIssMg8PHacWv3MRV3JmmBAs87AaCOo77BesLe7JKA== 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=K43OMtLi3SL2eBNzFpi18AFLkQEj3+mlb2T7C6faEBM=; b=Chwzfaf3EeT1hwkN4obBxMlsULdHKjsSysDZj3MTGJb4hLbErKu6zW1RdZ66YKDjFG6N8+nYIhMq+MyOYMMd0ySpgRTeRe5lkGOnGurVLmbGuVvwr3ES2GoUOjtesl0mSwkCE9Zo5Zb9sCgU3bBtBTKOTKGydkSTkaN5GrmaU9I= Received: from BL6PEPF00016413.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1004:0:b) by SA3PR12MB8762.namprd12.prod.outlook.com (2603:10b6:806:31f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.23; Fri, 27 Oct 2023 22:37:10 +0000 Received: from BL6PEPF0001AB4E.namprd04.prod.outlook.com (2a01:111:f403:f902::) by BL6PEPF00016413.outlook.office365.com (2603:1036:903:4::a) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19 via Frontend Transport; Fri, 27 Oct 2023 22:37:09 +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 BL6PEPF0001AB4E.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6933.15 via Frontend Transport; Fri, 27 Oct 2023 22:37:09 +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.32; Fri, 27 Oct 2023 17:37:07 -0500 From: Brett Creeley To: , , , , , CC: , , , Subject: [PATCH v3 vfio 1/3] pds/vfio: Fix spinlock bad magic BUG Date: Fri, 27 Oct 2023 15:36:49 -0700 Message-ID: <20231027223651.36047-2-brett.creeley@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231027223651.36047-1-brett.creeley@amd.com> References: <20231027223651.36047-1-brett.creeley@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BL6PEPF0001AB4E:EE_|SA3PR12MB8762:EE_ X-MS-Office365-Filtering-Correlation-Id: ad323e1c-30ee-42c4-9f8d-08dbd73d4197 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ryhICwS61JYI1qEe2XhS9qzlz4ANszou5iabraJYBDVQYhPtsmq9irfQRtPUIY1Ue9Hnjhhsx5cYYCQZgAlABeRDnbgyFfugbw2q7EP1+BxnrriIe/kl2/M0kqfQXfT/Y7f7e51WzW97QWNyaHqOmGJ23J43thcMVJr4gYhA5gbaK+EcFdtESLTuNW/QLJJF+8twU8+Aq69yK5PykNmVCKPLNIHbsPLJ9NVIKNKd4dkr/gNsEV2xG5trPYR+2ynpkxkcXUp8k9JSnbSuxXUVLG3+QAfiFWNWXy+4X2lwVeCOAHkxNBXQHdKekYMyp0nPd+gIcSSjYkG6qF1L4JK/s6hz/fwpKniHSuNqp+Hc8Y8sWqaZYC/+B11DadyzMvDnJflYCTKb+NpgshdZYchzwZy0C3n/FShXTmjXdTHO61OKKTZVAK05Vb1d0JcBRp1HP7ln0c8YqEplR1ppDvUjT7QS7h7Z02/rjSUJ8ZSH3qXtHo9FkzTo4OXvJ5nndHoG39hCHLwh1RwPoTQ4e/ODiJuusCb0t4D+I8GXP09q3+BgelZWs9rhSgdetv0ktLdcctofBIrIoMNTkISoTGOvcSrCmCMaPZBdakM+1IY9TO34vzmh5c6igpBDbmbvnOx+aQvTBM3UhJk9qOVi8Bs21kc7B5oSKZmw5beAdBH1kunekAmevgGrIoSljJk/E3vGunRvoWD6Iy5uXvPAEuVI458OgNYX3QJJ7HmccIAJT56TnI9qXpRddBh7xEZeF3FoHTEBx7yhVUgACF4FXVHJqA== 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)(4636009)(396003)(136003)(346002)(376002)(39860400002)(230922051799003)(186009)(451199024)(64100799003)(1800799009)(82310400011)(40470700004)(46966006)(36840700001)(83380400001)(4326008)(40460700003)(40480700001)(82740400003)(1076003)(2616005)(316002)(86362001)(6666004)(54906003)(2906002)(41300700001)(44832011)(8936002)(8676002)(110136005)(5660300002)(70206006)(70586007)(426003)(36756003)(336012)(478600001)(356005)(16526019)(26005)(36860700001)(81166007)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2023 22:37:09.6021 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ad323e1c-30ee-42c4-9f8d-08dbd73d4197 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: BL6PEPF0001AB4E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB8762 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 27 Oct 2023 15:37:39 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780949987236428541 X-GMAIL-MSGID: 1780949987236428541 The following BUG was found when running on a kernel with CONFIG_DEBUG_SPINLOCK=y set: BUG: spinlock bad magic on CPU#2, bash/2481 lock: 0xffff8d6052a88f50, .magic: 00000000, .owner: /-1, .owner_cpu: 0 Call Trace: dump_stack_lvl+0x36/0x50 do_raw_spin_lock+0x79/0xc0 pds_vfio_reset+0x1d/0x60 [pds_vfio_pci] pci_reset_function+0x4b/0x70 reset_store+0x5b/0xa0 kernfs_fop_write_iter+0x137/0x1d0 vfs_write+0x2de/0x410 ksys_write+0x5d/0xd0 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x6e/0xd8 As shown, the .magic: 00000000, does not match the expected value. This is because spin_lock_init() is never called for the reset_lock. Fix this by calling spin_lock_init(&pds_vfio->reset_lock) when initializing the device. Signed-off-by: Brett Creeley Reviewed-by: Shannon Nelson --- drivers/vfio/pci/pds/vfio_dev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c index 649b18ee394b..c351f588fa13 100644 --- a/drivers/vfio/pci/pds/vfio_dev.c +++ b/drivers/vfio/pci/pds/vfio_dev.c @@ -155,6 +155,8 @@ static int pds_vfio_init_device(struct vfio_device *vdev) pds_vfio->vf_id = vf_id; + spin_lock_init(&pds_vfio->reset_lock); + vdev->migration_flags = VFIO_MIGRATION_STOP_COPY | VFIO_MIGRATION_P2P; vdev->mig_ops = &pds_vfio_lm_ops; vdev->log_ops = &pds_vfio_log_ops; From patchwork Fri Oct 27 22:36:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brett Creeley X-Patchwork-Id: 159194 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp923684vqb; Fri, 27 Oct 2023 15:38:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5gtAmr0LMVGqwQS4cSL3qihtOuOSMUfz4zkiIhmllhjCC1hx4SP60iUf2Da3cuE1SYNX4 X-Received: by 2002:a05:6870:cb81:b0:1e9:af81:54b6 with SMTP id ov1-20020a056870cb8100b001e9af8154b6mr5900658oab.55.1698446292827; Fri, 27 Oct 2023 15:38:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698446292; cv=pass; d=google.com; s=arc-20160816; b=qcrdXxJfP5TNpuWmN1oqMyFNZKTjaMBfqoiO8A/em+SjQWuyaVRBP4q/vgl12R5INg Jdf6ACJ4F3AVgx80cbWGul6RbgT8Ed8pUdsDgmLaU0FDK3Zxwv2DgDgyymsYXt+j9O/g hYSeQaNhsTSBUG9PethF37PyzVfQF3KA+MfXKTZAx1MTeDL4MY5BAF3rfCmMBwhreXRL X6oP9QaBRNFeBE44BIXmtUp0zMW9VBjp7vNP4lhLBzFQL2yC85KVFqdpOL/UkhVBts/q scxgr/5U7lpqqq1MqIY39vjn3RDybBWmeczjZMAsLSAiOX0jglbzYyXh26YNxZVt92gV 4qLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=/lV4lyDxKEyVexv4om1bfCyS3zqujBEjXmB9A1ox1lQ=; fh=GbNd0iuihik10v4ZTZpqkH2SVSESc+5QskJdSEY04s4=; b=Gr9vCrJdKbg3wHK1jhiE9OUeEUa3WG8z2cueddTPyTCLkVLvy738Pyat6inOLbCxCL 2lgmX3Yy6xAMxMLyJtNLZK2wqYmZfQwWWhfP1EBs7aa62r8xY25IRE2q4MqqXWSFMwTY sClxziU1dERCvklSEoPS3bM8ODqpNgK1ViNn7nGLroOxN7/H+23/PYPR3xsiKw+HpPdF QGFc5YcFvPoBdqAGsqmgryg0l/ubetjzGfSh/M5gMP2IH6ZamYRBhOWickkYtBGgSym+ J6QzpZmWAwqYoZFyJ7SLGEV7mXyqGfYJSVtPP34oFpytn01bPrE2Be0ge4e5pNMXgrrP LbyQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Tpsoeg3m; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id l191-20020a6388c8000000b005b8dd557b38si1652102pgd.14.2023.10.27.15.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 15:38:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Tpsoeg3m; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id EF64485C77AA; Fri, 27 Oct 2023 15:38:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346675AbjJ0WhX (ORCPT + 27 others); Fri, 27 Oct 2023 18:37:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346668AbjJ0WhV (ORCPT ); Fri, 27 Oct 2023 18:37:21 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2045.outbound.protection.outlook.com [40.107.93.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C9D11B5; Fri, 27 Oct 2023 15:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BAtC45ITxTF7EqSpUhsenO6ikFMntxXMGbAbRXxpPHD7Z7KY5XPsKARD73YcWJlfOU7L5GhqQwjUxM/9UJr+PR1kCQuZOSliURDE2JrNPKzebfoXyDUWhSvCSukEYfepLc9HoBA5pNa5pJ78jZHGTg3pl/7Mrjm8j2qgPatPijAq40Z7gg7EHfWVkyZLaPjlxjdplz+SChMrq7Igg/TtZPV6M/7auGXCADbTsmWZ7O5jvOW/bf7D7Fotn5TSYyjnkn4nNhsr9QQkj5Yn30puYTVm9JD9IBNghgEgfjqre2ePGynoy7RrqiYZKLBoAKVA6Hwb5ugwxP2pWAGFpZrtmg== 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=/lV4lyDxKEyVexv4om1bfCyS3zqujBEjXmB9A1ox1lQ=; b=lJU4O0Xppcz3eKQz457nOsQJb0T6lxBbwdaxs0wRGdcAg/eCuPXVcuVvqc94qKfKMnFOnxeu8bLF3BD9hqDG8inkofzBi3Ufl4tZO1cnu3WJm5JO8/QrYn5lZ6aNoJjUgZVgfTaf3WzeXT5n4hIkgVPoQMX1kksnuQnpHGmRWIeZIpcbzjdpftmSj094CgrWbWL03okhfnJEE1B+QXM1VogVimmeOVgoQc7jVFXcPsU9OErkLanI6jkBmvN5jsqo6tXQ12JeEIOxA9iyNinxA4hSwe9PxYWgMyLxjpda6S8TtltWvje4y5gicZKCyQs4llXAOYNIWWmo+Lg/RpC3VA== 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=/lV4lyDxKEyVexv4om1bfCyS3zqujBEjXmB9A1ox1lQ=; b=Tpsoeg3mQwdRiq2WfCIsWLLQZvUFWajKtcWdoG1/OsFK50NIpmdL/DbKaDTWAWI3+w6N8Ylv2tPuUWYDTc6kwvYZ1hvVQSETDYu7JEQs2p9R2urRm3NvIcPE3uUACSyivDdlIl2Hjs47k1AqgM4NyswE4UveDcjxvkw5JDB+w7w= Received: from BLAPR03CA0178.namprd03.prod.outlook.com (2603:10b6:208:32f::32) by SJ2PR12MB8112.namprd12.prod.outlook.com (2603:10b6:a03:4f8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Fri, 27 Oct 2023 22:37:14 +0000 Received: from BL6PEPF0001AB4E.namprd04.prod.outlook.com (2603:10b6:208:32f:cafe::72) by BLAPR03CA0178.outlook.office365.com (2603:10b6:208:32f::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.24 via Frontend Transport; Fri, 27 Oct 2023 22:37:14 +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 BL6PEPF0001AB4E.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6933.15 via Frontend Transport; Fri, 27 Oct 2023 22:37:14 +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.32; Fri, 27 Oct 2023 17:37:09 -0500 From: Brett Creeley To: , , , , , CC: , , , Subject: [PATCH v3 vfio 2/3] pds/vfio: Fix mutex lock->magic != lock warning Date: Fri, 27 Oct 2023 15:36:50 -0700 Message-ID: <20231027223651.36047-3-brett.creeley@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231027223651.36047-1-brett.creeley@amd.com> References: <20231027223651.36047-1-brett.creeley@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BL6PEPF0001AB4E:EE_|SJ2PR12MB8112:EE_ X-MS-Office365-Filtering-Correlation-Id: 39fc8e2c-2b7b-4663-57f2-08dbd73d4459 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sW5sKWSikGHczdFrkCAAudL0XqJ3p/yT2YAhKf2KcTES+7FTw0zxDjmpgCD8S7rRPtk6dC41BIpFKERNrpFpS7tux438szso2qJ4Cvxf7O5t8htyrLcTAc6iXvVRbOmZGFXRL3T131yM76tdpxnjcmJA4ecEgunZ/N8yeZ06zdD45qeeqbDblmJGeVfkqK9L33DpInF712hDuX4kO9FvRu3Vm8WSC4I6Mg8NT09k8tuycNEaaHdDBdI/rETFGIZBkCsLazgJWSl5i3wUuF4LXJGSoYXFER9MfJmVfq+tqh35RcSFun6rNVa80u05+vq05ad+8/98i5FZuJ9cOpvyi1CC58Zbg7BEhC6Tu7OnFHBzQ0CG+Ce+nDQmF8vL/XT6hV68rcJnJUvgSgEeWpsPv67O7f0xHT38JzPWUPzzzoadWzWKPDQ4+CxDSLMDJGE0ZwRaU3pCzcc48x3KOfENmS4dFQA7bUdO9qIUirMH2qxpuNRHngaY4w8DzMHQqZQeOruMBWCZw5GFYusynR46hrU4MiYKK36GBvRG9jCgbAZdOMF0qrYLMMozNgvBmik9k9w6Un0P9ZyyyuEYBfE9aXIvq1hfpILpkZTgsz/qJptxGFuZJxZk2x/OXbzdP5qd7/7vKCijDZD7iBiM0u6g3atqA6al57NCV6VDsAwDCuAaduKLraZkYXQiPpqLDmQdoxi+bUnQ7xZWuy8YXw8AtMAVl/Ngkgfr+GP0jO07kOigxAsNQKFwkcPGQ0haM9xgl2uYYzJQE6/83ZNH6vgUJA== 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)(4636009)(396003)(376002)(39860400002)(136003)(346002)(230922051799003)(186009)(64100799003)(1800799009)(82310400011)(451199024)(36840700001)(40470700004)(46966006)(41300700001)(86362001)(44832011)(2906002)(54906003)(110136005)(70586007)(81166007)(316002)(6666004)(356005)(1076003)(478600001)(70206006)(426003)(47076005)(82740400003)(83380400001)(40480700001)(336012)(36756003)(40460700003)(5660300002)(36860700001)(2616005)(4326008)(8676002)(8936002)(16526019)(26005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2023 22:37:14.2271 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 39fc8e2c-2b7b-4663-57f2-08dbd73d4459 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: BL6PEPF0001AB4E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8112 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 27 Oct 2023 15:38:10 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780950019996091759 X-GMAIL-MSGID: 1780950019996091759 The following BUG was found when running on a kernel with CONFIG_DEBUG_MUTEXES=y set: DEBUG_LOCKS_WARN_ON(lock->magic != lock) RIP: 0010:mutex_trylock+0x10d/0x120 Call Trace: ? __warn+0x85/0x140 ? mutex_trylock+0x10d/0x120 ? report_bug+0xfc/0x1e0 ? handle_bug+0x3f/0x70 ? exc_invalid_op+0x17/0x70 ? asm_exc_invalid_op+0x1a/0x20 ? mutex_trylock+0x10d/0x120 ? mutex_trylock+0x10d/0x120 pds_vfio_reset+0x3a/0x60 [pds_vfio_pci] pci_reset_function+0x4b/0x70 reset_store+0x5b/0xa0 kernfs_fop_write_iter+0x137/0x1d0 vfs_write+0x2de/0x410 ksys_write+0x5d/0xd0 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x6e/0xd8 As shown, lock->magic != lock. This is because mutex_init(&pds_vfio->state_mutex) is called in the VFIO open path. So, if a reset is initiated before the VFIO device is opened the mutex will have never been initialized. Fix this by calling mutex_init(&pds_vfio->state_mutex) in the VFIO init path. Also, don't destroy the mutex on close because the device may be re-opened, which would cause mutex to be uninitialized. Fix this by implementing a driver specific vfio_device_ops.release callback that destroys the mutex before calling vfio_pci_core_release_dev(). Signed-off-by: Brett Creeley Reviewed-by: Shannon Nelson --- drivers/vfio/pci/pds/vfio_dev.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c index c351f588fa13..306b1c25f016 100644 --- a/drivers/vfio/pci/pds/vfio_dev.c +++ b/drivers/vfio/pci/pds/vfio_dev.c @@ -155,6 +155,7 @@ static int pds_vfio_init_device(struct vfio_device *vdev) pds_vfio->vf_id = vf_id; + mutex_init(&pds_vfio->state_mutex); spin_lock_init(&pds_vfio->reset_lock); vdev->migration_flags = VFIO_MIGRATION_STOP_COPY | VFIO_MIGRATION_P2P; @@ -170,6 +171,16 @@ static int pds_vfio_init_device(struct vfio_device *vdev) return 0; } +static void pds_vfio_release_device(struct vfio_device *vdev) +{ + struct pds_vfio_pci_device *pds_vfio = + container_of(vdev, struct pds_vfio_pci_device, + vfio_coredev.vdev); + + mutex_destroy(&pds_vfio->state_mutex); + vfio_pci_core_release_dev(vdev); +} + static int pds_vfio_open_device(struct vfio_device *vdev) { struct pds_vfio_pci_device *pds_vfio = @@ -181,7 +192,6 @@ static int pds_vfio_open_device(struct vfio_device *vdev) if (err) return err; - mutex_init(&pds_vfio->state_mutex); pds_vfio->state = VFIO_DEVICE_STATE_RUNNING; pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING; @@ -201,14 +211,13 @@ static void pds_vfio_close_device(struct vfio_device *vdev) pds_vfio_put_save_file(pds_vfio); pds_vfio_dirty_disable(pds_vfio, true); mutex_unlock(&pds_vfio->state_mutex); - mutex_destroy(&pds_vfio->state_mutex); vfio_pci_core_close_device(vdev); } static const struct vfio_device_ops pds_vfio_ops = { .name = "pds-vfio", .init = pds_vfio_init_device, - .release = vfio_pci_core_release_dev, + .release = pds_vfio_release_device, .open_device = pds_vfio_open_device, .close_device = pds_vfio_close_device, .ioctl = vfio_pci_core_ioctl, From patchwork Fri Oct 27 22:36:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brett Creeley X-Patchwork-Id: 159192 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp923625vqb; Fri, 27 Oct 2023 15:38:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3Zpk7GsSNaSgrmRUEN4daoCSLZu9nBX3BXXvbAVIAj9PLK/X7UOZfnPc6/UQb3ECuErW/ X-Received: by 2002:a25:f828:0:b0:d9a:4f29:866d with SMTP id u40-20020a25f828000000b00d9a4f29866dmr4054038ybd.60.1698446283818; Fri, 27 Oct 2023 15:38:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698446283; cv=pass; d=google.com; s=arc-20160816; b=dDQjTo3jtox/EZjgro0pAcQBWCs5lgbJ1pOePs/SI4QgsjIOObKnm+DO938L0QE+aa kb9Bk43JgB31mF5fE6X7fw4tfWfONlArfwuAhdccL6/Pusaz+MqtIXx25BYGrFV0pE4F BryAsuN9Y705EagF2o4SmvObnkrMdNPVtuIwlXzlTsiHaQHRovBxqvUCMCDvcNoLgUd+ gWe4xBlQQ6ZiuEQ+kCzQy3ZcA6eMFCY3vRsseNFuU1ZA6emw4T+IRCWSGHmaw5jSd1CO 6NeYmC6r500at0lPsR40LJeNaW6A5k89aMPnt3kUgJrjXi0XbbWhT1hAiArwv6koIOCE 6Dww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EN71fTh2dXtXpXyjwz92agvLN/VbKrupxTEAZxyx2/s=; fh=GbNd0iuihik10v4ZTZpqkH2SVSESc+5QskJdSEY04s4=; b=YQD6OS1+ThwkspBi/D+Q/Cyd0ezmsWjKqvhAW8FtWd02O2j5A4dRzno0SyUrmecvUK l2Ti0dXEsp7kyVCnwyA1TSAm/F0A0hr4uMxKBkUxwxIiReb0Vv5Y2yleIByum7OYtIfo jEXuBtgmlUF3Y9Unwqd+4BCCIkY+VQuP52RLVm8+L8Rvh91uKYK2WeOH9+imMenasOB4 gHM597eEkU7pGCyYaFJ8u9Qug7UBiKR48ZCX3+pSBlbYY4Bcp/jyVt8GP09o12NPU7OD P5mvoCiWnI/rNBOjZBlXahnYHEYlFEQHZ8jKzueGSFYseftjR0dTH/jLsaxc3wXYoPSJ eQPQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=NrtiiY0U; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id d14-20020a25360e000000b00d747c6cb360si4155918yba.623.2023.10.27.15.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 15:38:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=NrtiiY0U; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id E53C1806380E; Fri, 27 Oct 2023 15:38:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346695AbjJ0Wh0 (ORCPT + 27 others); Fri, 27 Oct 2023 18:37:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346679AbjJ0WhW (ORCPT ); Fri, 27 Oct 2023 18:37:22 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2072.outbound.protection.outlook.com [40.107.220.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 212D1D5A; Fri, 27 Oct 2023 15:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gfa3StTcB0wllZcxF0RTWea1a1jlTOYuMINAlLKSM8CXkxDvfhtnYfDqwusJQi8MZryzRPhioFaf2o0bytR7hEpSStOrh2wMhqCeV7+TmouzvcAXJT6t8t2fhMsOas2Jnuqikrgctky+Yp87g5acFubRudeosH3xubRORRdBSr4TCZ0soeVZXaX01syUZx5q4y1QonfA20fZyhw0uZk1ZQC+JecR4Emv3lBNiTacyzkgaHQo/1g1Ys3K/qD9yWtXPZtkMkioSkZHezwr2DVT1JREQv6SnyAg/Yhdf8WNWti8L19WkjL8Kd0vgJgwAP4YX4dJV6ST+zyinCtL/e1qWw== 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=EN71fTh2dXtXpXyjwz92agvLN/VbKrupxTEAZxyx2/s=; b=Ptrheumnrgle6/nC6t373GxGr9mV68eSxzNoBjYI6UWhIUYGU3XiU49tdbbtms/hL3XBuxVKM3heIf9sMEQeYc12yNq8j3RtwTTJnTpvFMeP23jyqz0oS96hQAH2CYd5Cg0ej/JmMmIZ2dFVsErqtpamBrSRRsfx7DoNjYaGaPLR1HqSeFWZEfvT3FQII0ibAtcMho4G7V8boyI6YAXv+zRnpdNJvzpRSGRTnb/j8VSV3sXyCgjW06/ExC4ewuG0A2z+hS1qLbRCsYgfryvxterINKbbOTcqRiycTq8SeQDGImKQ3e+1gIJN+EmXpQLNqkL6lJtfwre5u2+8hH9Mzg== 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=EN71fTh2dXtXpXyjwz92agvLN/VbKrupxTEAZxyx2/s=; b=NrtiiY0Ub04ofHORadL0S1MgRwDCjTW5rZyc+U0erY+S/nX3S0KTQyOX3ZzXz9Dw8BOFdKKOtNAf4oUgXR2tqMVRJ41mebdUnCCW8jJ4Al1Aq6p2BJLAV2jiEypNKqP3A4dxYYr6GHOEDH88RrplJNvJdZKjfvP4FKhkvbyLiiA= Received: from BLAPR03CA0169.namprd03.prod.outlook.com (2603:10b6:208:32f::21) by SA0PR12MB4544.namprd12.prod.outlook.com (2603:10b6:806:70::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19; Fri, 27 Oct 2023 22:37:15 +0000 Received: from BL6PEPF0001AB4E.namprd04.prod.outlook.com (2603:10b6:208:32f:cafe::7f) by BLAPR03CA0169.outlook.office365.com (2603:10b6:208:32f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.22 via Frontend Transport; Fri, 27 Oct 2023 22:37:14 +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 BL6PEPF0001AB4E.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6933.15 via Frontend Transport; Fri, 27 Oct 2023 22:37:14 +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.32; Fri, 27 Oct 2023 17:37:11 -0500 From: Brett Creeley To: , , , , , CC: , , , Subject: [PATCH v3 vfio 3/3] pds/vfio: Fix possible sleep while in atomic context Date: Fri, 27 Oct 2023 15:36:51 -0700 Message-ID: <20231027223651.36047-4-brett.creeley@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231027223651.36047-1-brett.creeley@amd.com> References: <20231027223651.36047-1-brett.creeley@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BL6PEPF0001AB4E:EE_|SA0PR12MB4544:EE_ X-MS-Office365-Filtering-Correlation-Id: 077bb8db-83f4-4e1d-8f4a-08dbd73d44b1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vRaASS9oNSz46FSUPAU0HtJA91OXOyNix1JJDJSG7lryMhpGqZdwDma78ko8H1rcRJZyVjxprS1iI/SNp1zrsk1agOrkAroQVVpetNLr8dtVuQ/nzZIOkwnQNcQD/a4vdpGtGLBammUIQCVOLb2dsg2Hjc/Idiu55V/c7HqW1mZ9OL43lW5eafxnPtC8quONmf0YaJeYSD5ScvVOqFR0TIkwTsa5lQZtdubJA1W7X9Hczx6L7Up/++gxNN3CsnsR7N6P3UuBVlxV8iqvZEu7ATVPTWyk74UDNpJQJA43UjESe6hXPEtuAkBAdOKjstiU2awmQ52HiABtvhN8+JlusDLyLD4Gmyrnqj2yr0pXjCXFVo0JPSVv+kIYblyfNR2SOMLsIvuCnyjlYTu4t+4ccBFBkEoLg1hIZms2drkWSG+u+zMPYQhuj4nE9I4FsyBWh+LSGRPARXKXRrJ14xzD6JH8iSpkHcar4HDp3sZ9mkB73p8FdMYOasNgJEEnqsvebP227JbLOytzLosVr/NhmezLGGy8KMdr9cM25kfJZfcBG+M+F1YW+7lVvUmK64FhrneqrwA4Ie1Jb1UVgvKvngNCadtFs0fJgXppl3LxSaADfo564xnVweKFP1IsiZxUoF1/lFe1P8j4jvUfBYGjVjMBkG871n858bjj0aLER8EoA2SdrmE+tz1mc2wQ9vI4GH4mYt39ts3dbtI7m3BOcwVKuN6XArzpSSR4ahlqs7EsfjwPoJg9p22uxpF3/+cU 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)(4636009)(39860400002)(396003)(136003)(346002)(376002)(230922051799003)(186009)(64100799003)(1800799009)(451199024)(82310400011)(40470700004)(46966006)(36840700001)(40480700001)(5660300002)(356005)(6666004)(44832011)(41300700001)(40460700003)(26005)(16526019)(1076003)(83380400001)(336012)(426003)(36756003)(2616005)(81166007)(47076005)(82740400003)(36860700001)(2906002)(86362001)(966005)(478600001)(110136005)(70586007)(316002)(70206006)(54906003)(4326008)(8936002)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2023 22:37:14.8052 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 077bb8db-83f4-4e1d-8f4a-08dbd73d44b1 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: BL6PEPF0001AB4E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4544 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 27 Oct 2023 15:38:00 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780950010693306275 X-GMAIL-MSGID: 1780950010693306275 The driver could possibly sleep while in atomic context resulting in the following call trace while CONFIG_DEBUG_ATOMIC_SLEEP=y is set: BUG: sleeping function called from invalid context at kernel/locking/mutex.c:283 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 2817, name: bash preempt_count: 1, expected: 0 RCU nest depth: 0, expected: 0 Call Trace: dump_stack_lvl+0x36/0x50 __might_resched+0x123/0x170 mutex_lock+0x1e/0x50 pds_vfio_put_lm_file+0x1e/0xa0 [pds_vfio_pci] pds_vfio_put_save_file+0x19/0x30 [pds_vfio_pci] pds_vfio_state_mutex_unlock+0x2e/0x80 [pds_vfio_pci] pci_reset_function+0x4b/0x70 reset_store+0x5b/0xa0 kernfs_fop_write_iter+0x137/0x1d0 vfs_write+0x2de/0x410 ksys_write+0x5d/0xd0 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x6e/0xd8 This can happen if pds_vfio_put_restore_file() and/or pds_vfio_put_save_file() grab the mutex_lock(&lm_file->lock) while the spin_lock(&pds_vfio->reset_lock) is held, which can happen during while calling pds_vfio_state_mutex_unlock(). Fix this by changing the reset_lock to reset_mutex so there are no such conerns. Also, make sure to destroy the reset_mutex in the driver specific VFIO device release function. Reported-by: Dan Carpenter Closes: https://lore.kernel.org/kvm/1f9bc27b-3de9-4891-9687-ba2820c1b390@moroto.mountain/ Signed-off-by: Brett Creeley Reviewed-by: Shannon Nelson --- drivers/vfio/pci/pds/pci_drv.c | 4 ++-- drivers/vfio/pci/pds/vfio_dev.c | 15 ++++++++------- drivers/vfio/pci/pds/vfio_dev.h | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/vfio/pci/pds/pci_drv.c b/drivers/vfio/pci/pds/pci_drv.c index ab4b5958e413..caffa1a2cf59 100644 --- a/drivers/vfio/pci/pds/pci_drv.c +++ b/drivers/vfio/pci/pds/pci_drv.c @@ -55,10 +55,10 @@ static void pds_vfio_recovery(struct pds_vfio_pci_device *pds_vfio) * VFIO_DEVICE_STATE_RUNNING. */ if (deferred_reset_needed) { - spin_lock(&pds_vfio->reset_lock); + mutex_lock(&pds_vfio->reset_mutex); pds_vfio->deferred_reset = true; pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_ERROR; - spin_unlock(&pds_vfio->reset_lock); + 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 306b1c25f016..4c351c59d05a 100644 --- a/drivers/vfio/pci/pds/vfio_dev.c +++ b/drivers/vfio/pci/pds/vfio_dev.c @@ -29,7 +29,7 @@ struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev) void pds_vfio_state_mutex_unlock(struct pds_vfio_pci_device *pds_vfio) { again: - spin_lock(&pds_vfio->reset_lock); + mutex_lock(&pds_vfio->reset_mutex); if (pds_vfio->deferred_reset) { pds_vfio->deferred_reset = false; if (pds_vfio->state == VFIO_DEVICE_STATE_ERROR) { @@ -39,23 +39,23 @@ void pds_vfio_state_mutex_unlock(struct pds_vfio_pci_device *pds_vfio) } pds_vfio->state = pds_vfio->deferred_reset_state; pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING; - spin_unlock(&pds_vfio->reset_lock); + mutex_unlock(&pds_vfio->reset_mutex); goto again; } mutex_unlock(&pds_vfio->state_mutex); - spin_unlock(&pds_vfio->reset_lock); + mutex_unlock(&pds_vfio->reset_mutex); } void pds_vfio_reset(struct pds_vfio_pci_device *pds_vfio) { - spin_lock(&pds_vfio->reset_lock); + mutex_lock(&pds_vfio->reset_mutex); pds_vfio->deferred_reset = true; pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING; if (!mutex_trylock(&pds_vfio->state_mutex)) { - spin_unlock(&pds_vfio->reset_lock); + mutex_unlock(&pds_vfio->reset_mutex); return; } - spin_unlock(&pds_vfio->reset_lock); + mutex_unlock(&pds_vfio->reset_mutex); pds_vfio_state_mutex_unlock(pds_vfio); } @@ -156,7 +156,7 @@ static int pds_vfio_init_device(struct vfio_device *vdev) pds_vfio->vf_id = vf_id; mutex_init(&pds_vfio->state_mutex); - spin_lock_init(&pds_vfio->reset_lock); + mutex_init(&pds_vfio->reset_mutex); vdev->migration_flags = VFIO_MIGRATION_STOP_COPY | VFIO_MIGRATION_P2P; vdev->mig_ops = &pds_vfio_lm_ops; @@ -178,6 +178,7 @@ static void pds_vfio_release_device(struct vfio_device *vdev) vfio_coredev.vdev); mutex_destroy(&pds_vfio->state_mutex); + mutex_destroy(&pds_vfio->reset_mutex); vfio_pci_core_release_dev(vdev); } diff --git a/drivers/vfio/pci/pds/vfio_dev.h b/drivers/vfio/pci/pds/vfio_dev.h index b8f2d667608f..e7b01080a1ec 100644 --- a/drivers/vfio/pci/pds/vfio_dev.h +++ b/drivers/vfio/pci/pds/vfio_dev.h @@ -18,7 +18,7 @@ struct pds_vfio_pci_device { struct pds_vfio_dirty dirty; struct mutex state_mutex; /* protect migration state */ enum vfio_device_mig_state state; - spinlock_t reset_lock; /* protect reset_done flow */ + struct mutex reset_mutex; /* protect reset_done flow */ u8 deferred_reset; enum vfio_device_mig_state deferred_reset_state; struct notifier_block nb;