Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D8E2C4338F for ; Thu, 5 Aug 2021 15:39:12 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E31F61078 for ; Thu, 5 Aug 2021 15:39:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4E31F61078 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.164435.300732 (Exim 4.92) (envelope-from ) id 1mBfSV-0004GW-5d; Thu, 05 Aug 2021 15:38:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 164435.300732; Thu, 05 Aug 2021 15:38:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mBfSV-0004GP-2Q; Thu, 05 Aug 2021 15:38:59 +0000 Received: by outflank-mailman (input) for mailman id 164435; Thu, 05 Aug 2021 15:38:58 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mBfSU-0004GJ-5C for xen-devel@lists.xenproject.org; Thu, 05 Aug 2021 15:38:58 +0000 Received: from de-smtp-delivery-102.mimecast.com (unknown [194.104.109.102]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3eb07262-f603-11eb-9c36-12813bfff9fa; Thu, 05 Aug 2021 15:38:56 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2058.outbound.protection.outlook.com [104.47.13.58]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-9-HCl8urOQM8-hPYaCRA7GDQ-1; Thu, 05 Aug 2021 17:38:54 +0200 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VI1PR04MB4847.eurprd04.prod.outlook.com (2603:10a6:803:54::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.17; Thu, 5 Aug 2021 15:38:52 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::99d3:99cd:8adf:3eea]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::99d3:99cd:8adf:3eea%5]) with mapi id 15.20.4373.027; Thu, 5 Aug 2021 15:38:52 +0000 Received: from [10.156.60.236] (37.24.206.209) by AM0PR04CA0068.eurprd04.prod.outlook.com (2603:10a6:208:1::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.15 via Frontend Transport; Thu, 5 Aug 2021 15:38:51 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3eb07262-f603-11eb-9c36-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1628177936; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u9WK7Uny8iP6bvLYMQuGW8UNEeilR7najs7REoLXaWk=; b=f7XQM1XlDGTvjW0QdpE6KURuPD1l7wQ+Gx9bHmy014ZeLyCRFME8VuPAirts/U+z8C83FA Io6108UnjaKHKprbqW5tEURze7by2GRkKMMFzb4m1qrO5O6BfClSloqyH6K9QlYpuoYhFC gc6rDVsTT+2gf6OSJ8sj5mxfcRMrj1Y= X-MC-Unique: HCl8urOQM8-hPYaCRA7GDQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=McJMRMhzq3ehLyYJscO6HPhDcefRuo6VSegKgOQJ3siQeATw3rK9nbfo40H09kTo8e08SEdngO2qyYLjw6u3O7OBOJxcEb/OUVlBxr38JZ5OBtqtQrsLrI2/SBxw3Ger+ScRj5A/4p8s/KLRVceOii/3KQk+n++Znawq+Vmpjq2OGeJBQQzO4pjend85buB+nI1ffNqoSIPji1br3qWFyqNFHYCPc5IJTuFI99Uzqk89O1gxXo/GX7Md0+t7xCCEgiZt9jNwZwrmVD6dplSnOQnvyaUWlLCnbG/3gtJ7J87OBsxJCMAU+QRIe/vRPlVkOSBvSZWXBSC9LqS1XCA8Pw== 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-SenderADCheck; bh=u9WK7Uny8iP6bvLYMQuGW8UNEeilR7najs7REoLXaWk=; b=cc5mKoCFepW1j7TPhWqFuXOXy8TTAHdx2UYdgyHiRvIuwzoToWuV9JoO1iouQDDY5gyfGIqrMm0i5FAKvNpe0hnneesmxgUFW0fnflp4F/VaLPZ2SRdp2dCw9UiD8NEfy5lrzACLxjmsmmY0nDwkdh0Zoi/10aIvQm50tIAbtaA1vjpAV8L6nhAFSCblZL4bKktSpC33GCl+l7ihM7BP2b2aFZwl884c4BhWXkrx59fMicbQByz1kRvckk7nTGdnYpsIGvULuwyfuBrKYRy+wZ6FCKMPL7EwFL+a6pjlWgMv2GihIcVAx7ylY7aDRJLBxXKsrrGjcnMWfmVIHKaubQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=none action=none header.from=suse.com; Subject: Re: [PATCH] libxl: Fix stubdom PCI passthrough To: Jason Andryuk Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD , Juergen Gross , xen-devel References: <20210804221749.56320-1-jandryuk@gmail.com> From: Jan Beulich Message-ID: Date: Thu, 5 Aug 2021 17:38:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM0PR04CA0068.eurprd04.prod.outlook.com (2603:10a6:208:1::45) To VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ddffe3e4-866f-42c1-41c3-08d958272051 X-MS-TrafficTypeDiagnostic: VI1PR04MB4847: X-LD-Processed: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba,ExtFwd X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q9dTrZcGr9u8a8x9UAH/PLEuJ8guBdQruwR/a9JV8zs4P8vO7yELI1/cr6glUJ7gvhVfoADWLq/39csgBs29srMX37TX/W2Moaw5/3DQDJBzvKKdXSkhs3CBqVCgg0RVdAgBv7FkPUz098LsI8McbJR1YLjluaAC6CZAR4LGNzM3/B4/Pl4nyEsSUa/S5fef2P6ScaMZeAxSJpLa5GAG1/dZdCGNb8xVx/jtY+cCiHLKBi1UL6KS4j5iBr4blPLUJkycV0bF8lyh5/Q7kTXzCbIIwh4mOyQ1uUyUcAlFc3NxZ/oCw84waOaRuoPYKDmNIdmJv4hDs/YjwjajGaXWuxGEVkW1yCscQuX+2I3R1tPUUbCLsBEKScaCgjIvLV8RD5S/46bP9a1doxhfbuQT+89Bek1dI7mKu7R6oHabHYoKMGco4xpf9i70tRhavQ/RLsF2Wh3UdGi/D8SZmA0yuACB5X+xJsU7BaYjFk6Z3PlAxTZirVRCP39wSocyTn0f9+ioyWSrR3LGaZ7WPqEAkVRISfcObgl6nwR6Y6oNBkzg3qQLR9eM4CFzH12IokYNUhWsHrHXWDNrVmYwMvfKgn9vAd3h1IhqPXnS+EY5gGFvea+U/pgRQ1GYLxkWQrd3hiEtdM9cidohfm606mINnUniD4hxoncAmGaX+GxmzUB8nYNX8tw0pZV7oQKTbS52DWTB1BYZUgGRTtEP1Y5Z2vnSbFemiqVyTqequQTh7t4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5600.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(346002)(39860400002)(376002)(396003)(53546011)(86362001)(478600001)(26005)(956004)(38100700002)(5660300002)(2616005)(36756003)(31696002)(4326008)(54906003)(83380400001)(31686004)(186003)(8936002)(316002)(16576012)(66476007)(66556008)(66946007)(8676002)(6486002)(2906002)(6916009)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =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bjkf/WxxT6?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ddffe3e4-866f-42c1-41c3-08d958272051 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2021 15:38:52.0140 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1dcu+DwzNVD0S4UWKbhB4z2Xw7Eg/3jT6LYrWaCDove/3mOwO9GrGxxQJqu4FBSIYQMpKpv3xrUkIh+9wCl6AQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4847 On 05.08.2021 16:57, Jason Andryuk wrote: > On Thu, Aug 5, 2021 at 2:20 AM Jan Beulich wrote: >> >> On 05.08.2021 00:17, Jason Andryuk wrote: >>> commit 0fdb48ffe7a1 "libxl: Make sure devices added by pci-attach are >>> reflected in the config" >> >> This should be in a Fixes: tag; whether you fully spell out the >> reference here or instead refer to that tag would by up to you. > > Yes, you are correct. Thanks. > >>> broken stubdom PCI passthrough when it moved >>> libxl__create_pci_backend later in the function. xl pci-attach for a >>> running PV domain may also have been broken, but that was not verified. >>> >>> The stubdomain is running (!starting) and PV, so it calls >>> libxl__wait_for_backend. With the new placement of >>> libxl__create_pci_backend, the path does not exist and the call >>> immediately fails. >>> libxl: error: libxl_device.c:1388:libxl__wait_for_backend: Backend /local/domain/0/backend/pci/43/0 does not exist >>> libxl: error: libxl_pci.c:1764:device_pci_add_done: Domain 42:libxl__device_pci_add failed for PCI device 0:2:0.0 (rc -3) >>> libxl: error: libxl_create.c:1857:domcreate_attach_devices: Domain 42:unable to add pci devices >>> >>> The wait is only relevant when the backend is already present. Use the >>> read on num_devs to decide whether the backend exists and therefore the >>> wait is needed. >> >> But the presence of the node is not an indication of the backend existing, >> is it? libxl__device_pci_add_xenstore() itself writes the node a few lines >> down from your change, so upon processing a 2nd device the function would >> still behave as it does now. > > The way this code is written, num_devs is an indicator. As you say, > it's used to control if the overall backend is created. When the > backend is created without num_devs, Linux xen-pciback closes the > front/back with "Error reading number of devices". I also tried > adding a new libxl__create_pci_backend() call which wrote num_devs > "0", but that failed with some error I did not write down. Although I > may have messed that up by not executing the transaction. > > When libxl__device_pci_add_xenstore() runs a second time, the wait is > fine because the backend exists. Ah yes, now I recall, because I stumbled over this unhelpful behavior a couple of months ago. As mentioned back then I think it is wrong to create the backend after adding just the first device; it would better be created once all devices have got populated to xenstore. At the time I did submit a kernel side patch to deal with the odd behavior. This has gone in upstream in the meantime, but I would have preferred if the issue would (also) have been addressed in libxl. > I just tested to confirm. Testing > `xl create` for HVM w/ Linux stubdom and 2 PCI devices shows the > wait's watch trigger for Reconfiguring and Reconfigured before it > settles back to Connected. > > The point of the wait is to let the front/back finish any > Reconfiguring for a running domain before a new attachment is > initiated. If we have to create the backend, then the wait is > unnecessary - a non-existant backend cannot be Reconfiguring. The > function already changes behavior depending on the num_devs node. > When num_devs doesn't exist, it creates the backend. That is why I > went with an additional parameter and comment. > > Would you like an expansion of the commit message with something like: > """ > The wait is only relevant when the backend is already present. > num_devs is already used to determine if the backend needs to be > created. Re-use num_devs to determine if the backend wait is > necessary. The wait is necessary to avoid racing with another PCI > attachment reconfiguring the front/back. If we are creating the > backend, then we don't have to worry about a racing reconfigure. > """ Might help, yes. Jan