Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3505209rdb; Sun, 10 Dec 2023 08:16:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4jEMpGlAkZmJ1yv1iau+ocnSKby7C05AG7ngxeM8rtpOMY3cdecZdboSX+aQktbtAgbyI X-Received: by 2002:a17:902:e54a:b0:1d0:6ffe:1e8b with SMTP id n10-20020a170902e54a00b001d06ffe1e8bmr1697244plf.110.1702224986489; Sun, 10 Dec 2023 08:16:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702224986; cv=pass; d=google.com; s=arc-20160816; b=vL50w8jxYv+7KvdPa7tJxsxT01ALPB9KaX9EmSojUuexV3iYzqOLmFs2uJaMCIeTq/ F0N3dI5Mh5KRRabpNxacWVliBjrzR4QfJ0PLiCHW2pqRqAnYdwUdsTqhnLToQ/E9Ouus UYNcTQ53zZYoyg9hovUZXuu6dO6b90a4JpxisbqCGefY/MYuIkENO3iyFR250GRTwMwi 5u07p5GYAMlv8oHzixBF7Yce2eF2xVSqj0RrnIA30zPPBSieCe1X6hyWipOdLw7rSv+P azgC3+EAEej0WkfkqAtUnWvEJtW3+P1Jb6T+Xj+Rh5UukPKY0wz603UCHjMvvzs5bkpE PqEg== ARC-Message-Signature: i=2; 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:date:subject:cc:to:from :dkim-signature; bh=e0cVJClnKI0t+S5tf/NWGenaSQY7dTKBr3BxoBA+0yg=; fh=uWO6//hgPrW3Meqg4qnmbc4K1FUzMStQqD7a14tzn2o=; b=vPiLz2INNXPY9hvsxH3QIYd9IseH7p7YI5IuFA3pn8ktsBaSe9gat9PxwlXq21jGHq 7Fxj7UHVCSp8QOSLqRoKGZ1xnH3VoJ0fqZ23t5DhoCs9fIVOOsef4gEDoE3ZPGuyvQxi EI97CdpGWEsa4ruiRnKPtAvc7D69pWpAbiEnV16l+mNyQfmePJZe3/8REoYs1Im1kjB1 5t50Qu7LfOre3HWWH5XOJWpGAQOX1l6Ml5uUBULqNujqa2dyRDwH8T0h7AlirNQnY4cE 2avtim9alR3woNgNsY8zj2Mgutra0clx/FNmcQHmFHz2zlN7papnbKrOMFe8Sg88grKC wbmw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=WugWokQl; 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:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id v7-20020a170902b7c700b001d08f193477si4707313plz.202.2023.12.10.08.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 08:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=WugWokQl; 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:8 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 fry.vger.email (Postfix) with ESMTP id A875D807C75E; Sun, 10 Dec 2023 08:16:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232000AbjLJQPs (ORCPT + 99 others); Sun, 10 Dec 2023 11:15:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231927AbjLJQPr (ORCPT ); Sun, 10 Dec 2023 11:15:47 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2085.outbound.protection.outlook.com [40.107.237.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36DE1F9; Sun, 10 Dec 2023 08:15:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MUWM0qutTMMeenq1MAyWuVl2Ac5ZfWwhPASMMvE2GSw+WDK+mVtuvTmI1FqK9Tv844TlloXulWGi0GM+Wbozm227Icaa8EarXa7EymGB59jS2uQRkhFMlYEYy2EznTURuH5mhoPv4KHuQay8Sz74nQrDaXltiUlUSsEkPfF4I0cywXVw8L8idCCnwVyKbua+Z7amVSSU2n4nmdcivo31jSW+r/VETyi8lv9aY0EfrS4IWK49UBv6gEdEtbM9myavz7Zgp4tDnWpWUHdC1ZMZBlvOmryqyvdTsCRIbip37uqBEBaGlgljPgJ17eMvRGwj4EVBWxhIf62gr8XUjx91pg== 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=e0cVJClnKI0t+S5tf/NWGenaSQY7dTKBr3BxoBA+0yg=; b=UGztRtYOB+Q+UbXi1c1mBnPetxV6zNQBSEpx14ozt2mYiVEcHsNm6kXEgpYnoHP1ir1uB5FzMd6/H0ZdmhvPxt+3qPfPv2/8FdkMz+ihTc3E52daGSxTF2SePhEO+64i0Of0/QNKwNpBq3tKrf/UwDOFjfXA7yLg/zFcxiQ2VpKNvxKgK2QtXLLEqMhCSTEQ5syHHAvrEFSiY2S/C2LOeaQYIUd9iFmoFSZUzC5Dva1Q6hr/lTTr+4OC3jD5pRz/K78VhZknx2FYp72nKXpoPBvaiAt97UkMBNPQQoeBaJUPNsz7tQyVqo3toqmy4hv2EKHOkLdhdVQejx9ek9AxuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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=e0cVJClnKI0t+S5tf/NWGenaSQY7dTKBr3BxoBA+0yg=; b=WugWokQlCzKNdd4LZfCYgc+CgdEVr30USTES9WYlFrNv0avtgUNI3BLKYEstMgOs8j3ZJi8rZetjo4RCoYmNy6/stV0D3ymRkhGwI93bHS84nrvy2Y9O6df739q6UtYQT82XKys/IfhlBDvPwcLMSqji9theFdFLwSeYF3IIIe4= Received: from CY5PR17CA0058.namprd17.prod.outlook.com (2603:10b6:930:12::20) by CH2PR12MB4216.namprd12.prod.outlook.com (2603:10b6:610:a8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.32; Sun, 10 Dec 2023 16:15:45 +0000 Received: from CY4PEPF0000E9D3.namprd03.prod.outlook.com (2603:10b6:930:12:cafe::55) by CY5PR17CA0058.outlook.office365.com (2603:10b6:930:12::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.32 via Frontend Transport; Sun, 10 Dec 2023 16:15:44 +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 CY4PEPF0000E9D3.mail.protection.outlook.com (10.167.241.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7091.18 via Frontend Transport; Sun, 10 Dec 2023 16:15:44 +0000 Received: from cjq-desktop.amd.com (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.34; Sun, 10 Dec 2023 10:15:38 -0600 From: Jiqian Chen To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , "Rafael J . Wysocki" , Len Brown , Bjorn Helgaas , "Thomas Gleixner" , Boris Ostrovsky , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= CC: , , , , Alex Deucher , Christian Koenig , Stewart Hildebrand , Xenia Ragiadakou , Honglei Huang , "Julia Zhang" , Huang Rui , Jiqian Chen , Huang Rui Subject: [RFC KERNEL PATCH v3 1/3] xen/pci: Add xen_reset_device_state function Date: Mon, 11 Dec 2023 00:15:17 +0800 Message-ID: <20231210161519.1550860-2-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231210161519.1550860-1-Jiqian.Chen@amd.com> References: <20231210161519.1550860-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D3:EE_|CH2PR12MB4216:EE_ X-MS-Office365-Filtering-Correlation-Id: c1ff42dc-c1c3-4b41-b08a-08dbf99b42f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sjxsHOhfjm4BdqjLcc6/A0HrcK0KDCJsgTUEjobA6Pvj1fuXPvL4dSftfmoeOMf2UhVA6hfZyw9uVwKZj4Vw2uOm0oaA5K+HCXjGTXIu4M2kX/mcvCF7Aq4B64EVGrGo3jcuEAAL8l2rbWzms14he+qH1D8ORQ0ZwCE+WpCEUxUxuMeMmn8iMd67jyx3k58xXMe7PDrm4rtnhfeRh+CmY7A2crE03Z8EsjCmmWqouYzyO8VxsJnR9RtQg6Ht2RKyOrU9pwyhGvkTKLy4X77UV6U4XGSk56m+ueiIl2kgtAscsusRP3O4emgXv9jsPmNuXNRnQR0Yr1Lg5pAdx/rmGy/sXFN8NAISB4d4fbReLDTLgXTo9R1tBTfz8EhcYdbegFcDV+7b8gAJ0wTZq9ENjRsWtllmkvMBl2QT0bgD0o9dmvjNT6B5SBMw85ldmFL4BNNQ8nNdCjswyvzo25JHaT19C4Z3xZOF8WAedafYzqZ7kiTPY296Gw6d56jpepby+mjgyas/uRvFE0kxLQ+d25jMxJ39zjkf6T/ezvjE0ksXT70NrcYSC2x637hrYThr7db489RheqQ9U2W8ckGKJSOYvKD6nSl8+vVZ9ZZ6lOqkKT0wGU8HMxAjC0beus8YD9Bj/kY8NaDokaXSK+hQG3bPmnkkysOMc59R6woEcbrM7VCxCPAmo1nSBlq+ZpAGNAotujG/dujiql/ieHqAGEXiFEMT2cRKo35gcuC58EykX7QHDXV1XPSUIsprn5KkyerRYfNecvW6Vc0Bhw4YNg== 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)(136003)(39860400002)(376002)(396003)(346002)(230922051799003)(451199024)(1800799012)(186009)(82310400011)(64100799003)(46966006)(36840700001)(40470700004)(41300700001)(5660300002)(7416002)(2906002)(2616005)(1076003)(6666004)(7696005)(36756003)(478600001)(36860700001)(47076005)(81166007)(82740400003)(356005)(426003)(83380400001)(336012)(40480700001)(26005)(16526019)(8936002)(40460700003)(8676002)(4326008)(86362001)(54906003)(110136005)(316002)(70206006)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2023 16:15:44.0477 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c1ff42dc-c1c3-4b41-b08a-08dbf99b42f3 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: CY4PEPF0000E9D3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4216 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Sun, 10 Dec 2023 08:16:23 -0800 (PST) When device on dom0 side has been reset, the vpci on Xen side won't get notification, so that the cached state in vpci is all out of date with the real device state. To solve that problem, add a new function to clear all vpci device state when device is reset on dom0 side. And call that function in pcistub_init_device. Because when using "pci-assignable-add" to assign a passthrough device in Xen, it will reset passthrough device and the vpci state will out of date, and then device will fail to restore bar state. Co-developed-by: Huang Rui Signed-off-by: Jiqian Chen --- drivers/xen/pci.c | 12 ++++++++++++ drivers/xen/xen-pciback/pci_stub.c | 4 ++++ include/xen/interface/physdev.h | 8 ++++++++ include/xen/pci.h | 6 ++++++ 4 files changed, 30 insertions(+) diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c index 72d4e3f193af..e9b30bc09139 100644 --- a/drivers/xen/pci.c +++ b/drivers/xen/pci.c @@ -177,6 +177,18 @@ static int xen_remove_device(struct device *dev) return r; } +int xen_reset_device_state(const struct pci_dev *dev) +{ + struct physdev_pci_device device = { + .seg = pci_domain_nr(dev->bus), + .bus = dev->bus->number, + .devfn = dev->devfn + }; + + return HYPERVISOR_physdev_op(PHYSDEVOP_pci_device_state_reset, &device); +} +EXPORT_SYMBOL_GPL(xen_reset_device_state); + static int xen_pci_notifier(struct notifier_block *nb, unsigned long action, void *data) { diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c index e34b623e4b41..24f599eaec14 100644 --- a/drivers/xen/xen-pciback/pci_stub.c +++ b/drivers/xen/xen-pciback/pci_stub.c @@ -421,6 +421,10 @@ static int pcistub_init_device(struct pci_dev *dev) else { dev_dbg(&dev->dev, "resetting (FLR, D3, etc) the device\n"); __pci_reset_function_locked(dev); + if (!xen_pv_domain()) + err = xen_reset_device_state(dev); + if (err) + goto config_release; pci_restore_state(dev); } /* Now disable the device (this also ensures some private device diff --git a/include/xen/interface/physdev.h b/include/xen/interface/physdev.h index a237af867873..bed53afc4c52 100644 --- a/include/xen/interface/physdev.h +++ b/include/xen/interface/physdev.h @@ -256,6 +256,14 @@ struct physdev_pci_device_add { */ #define PHYSDEVOP_prepare_msix 30 #define PHYSDEVOP_release_msix 31 +/* + * On PVH dom0, when device is reset, the vpci on Xen side + * won't get notification, so that the cached state in vpci is + * all out of date with the real device state. Use this to reset + * the vpci state of device. + */ +#define PHYSDEVOP_pci_device_state_reset 32 + struct physdev_pci_device { /* IN */ uint16_t seg; diff --git a/include/xen/pci.h b/include/xen/pci.h index b8337cf85fd1..b2e2e856efd6 100644 --- a/include/xen/pci.h +++ b/include/xen/pci.h @@ -4,10 +4,16 @@ #define __XEN_PCI_H__ #if defined(CONFIG_XEN_DOM0) +int xen_reset_device_state(const struct pci_dev *dev); int xen_find_device_domain_owner(struct pci_dev *dev); int xen_register_device_domain_owner(struct pci_dev *dev, uint16_t domain); int xen_unregister_device_domain_owner(struct pci_dev *dev); #else +static inline int xen_reset_device_state(const struct pci_dev *dev) +{ + return -1; +} + static inline int xen_find_device_domain_owner(struct pci_dev *dev) { return -1; -- 2.34.1