From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 524F9C433EF for ; Mon, 27 Sep 2021 13:51:34 +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 040996023B for ; Mon, 27 Sep 2021 13:51:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 040996023B 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.196890.349781 (Exim 4.92) (envelope-from ) id 1mUr2M-0005Su-Kc; Mon, 27 Sep 2021 13:51:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 196890.349781; Mon, 27 Sep 2021 13:51:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mUr2M-0005Sn-H9; Mon, 27 Sep 2021 13:51:18 +0000 Received: by outflank-mailman (input) for mailman id 196890; Mon, 27 Sep 2021 13:51:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mUr2L-0005Sh-QN for xen-devel@lists.xenproject.org; Mon, 27 Sep 2021 13:51:17 +0000 Received: from de-smtp-delivery-102.mimecast.com (unknown [194.104.109.102]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a845716c-7828-469a-b96a-de1177f1bb8c; Mon, 27 Sep 2021 13:51:16 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2109.outbound.protection.outlook.com [104.47.17.109]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-1-_HjOz0EHM1afHNvivzdOjw-1; Mon, 27 Sep 2021 15:51:14 +0200 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VI1PR04MB6304.eurprd04.prod.outlook.com (2603:10a6:803:fd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.14; Mon, 27 Sep 2021 13:51:11 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::4d37:ec64:4e90:b16b]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::4d37:ec64:4e90:b16b%7]) with mapi id 15.20.4544.021; Mon, 27 Sep 2021 13:51:11 +0000 Received: from [10.156.60.236] (37.24.206.209) by PR0P264CA0137.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.15 via Frontend Transport; Mon, 27 Sep 2021 13:51:11 +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: a845716c-7828-469a-b96a-de1177f1bb8c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1632750675; 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=650pWNflc7v9BmVAoh8M7oE4XQqDtjRwLgovh2s6xyg=; b=aei6EDuoFb3OaimAFTaPgLY0jAcSSTJqyKueK+c5MwDIrBgcjZx/7VloyVxsJqgEnpkDAl B1zVfBFzCcnvbgtZvGY0/A2ffY+L6KDCwjoYowJcygC7YtlEf1EOjU1yxpjd5uDcW1AQ4K CB417w6NIYQbjNPauFQTvOan1r/4Yvw= X-MC-Unique: _HjOz0EHM1afHNvivzdOjw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K64kJVS5L5vbCSHy3wOP7OXL7/WxmokPGUTnZL4CQ4WJokljym5oPWHGUAcSzrieJIL0LR1Y8wEXDinIbTkf4E1kvqE2xo4dHgkr3I+gzI/czz98gz1TI2oRXDq5PIyk6ZkUQ5m3YBWCpij6l8CTK4wsoAAH6jJ0RvwFB0OovTQuNXCqerXSTWbD52OFcarI6VQiNYjOHxpgl7854M0Co2Em6niIHgOav46kIjktqzwR6z+j+v/JfFOflL2wKtyGlwUWWgYIUs5sHXaJ/a8l0FTOsW4YAUkfaxji1Nv6zuNB6kyEIktXi9jTeA0WGyD3e56rYGCfBsdghlLhW7TR8g== 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; bh=650pWNflc7v9BmVAoh8M7oE4XQqDtjRwLgovh2s6xyg=; b=To/56KLj4XrD3IZXaGA02wcfq4n/sdLXi/vpXYysiTSl/iyUD8Z2uW7MDoUFhjs0V/QVBi6421gX76RBFL2S8sIiHula2r/4wrMc1MHsjK02Zghxk2jU2g2Ru8dVYpTHM3a09GqXAjrh05Y44Yu4TTWRs/er5VDIDah3vvHNZ83dDKGsxl/LXZMLNc9JKIEjCHsfTn98i7kgCnjECMBQRx/k/Yl1b2Jb54d2EL/9JovgFOIyb0TR1C+MwCO3rDEv6ThPBbmF+BYkOTU8BgDwNPWYbMWH2HfWJ0e+MRO+pJFuUjAI6X/Fa1dZ/YdDvI1e++tjUTjIkZBnPG6MDVS5gA== 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 v2 11/11] xen/arm: Translate virtual PCI bus topology for guests To: Oleksandr Andrushchenko Cc: "julien@xen.org" , "sstabellini@kernel.org" , Oleksandr Tyshchenko , Volodymyr Babchuk , Artem Mygaiev , "roger.pau@citrix.com" , Bertrand Marquis , Rahul Singh , "xen-devel@lists.xenproject.org" References: <20210923125501.234252-1-andr2000@gmail.com> <20210923125501.234252-12-andr2000@gmail.com> <3dcba7a0-6984-a9bf-6121-5003bbc2ccaa@suse.com> <27378eb1-7dad-29a4-a136-c9e5e55a2067@epam.com> From: Jan Beulich Message-ID: <299f330a-3a99-e87a-d182-762247371e3d@suse.com> Date: Mon, 27 Sep 2021 15:51:09 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 In-Reply-To: <27378eb1-7dad-29a4-a136-c9e5e55a2067@epam.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: PR0P264CA0137.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1a::29) To VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9dcf8030-5861-4014-ee50-08d981bddd9f X-MS-TrafficTypeDiagnostic: VI1PR04MB6304: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iRVin2oAlnarjt16F4WbVF0fN4mSzVmO618DPVKMqCmOdkPTuQ2unu883L3Mj7ovdj84e96v8pZ1+NxwV8EafI+ubBQt15m6CaKZpDd+TuUJqaeFqwNKU23PZQ5vVClEruXlnRISBJv4gRfTivQXMBuc2Ofb/7F+RRdWiWFFFH8nN7wKBhnzRLsViEJCi7w3LYM94PpxoMNm80olVg1sCXeqFTT63IeCZsHbO7EFx2MJ40ZfwcZBgNnXbFMMH7RK1jUPgPTDVx0Sk7XLt2S7q9fFIjiep9WTzrv23HaiJtO50o1n4J7DRu8d5my8eTU/VrkAfU6/wA9oIqjm6lKuUSbvnAIyVr7PpBAG7XSNIW8GG0kLuK+3etGdelC1xbF8c3XnRMo2lX59lSq/PYd91WUj4tbZR68fMDhetuSX3C0jy/GBwyhm531mQuu32W+jLkJTL/A0Y0j2wXTXPloTOkn5eYy081JB1AAd4IGFtXU+qJv8yPXzfS3hsov4XB5sM0V/UXwB2NZvCkVgc4IYm9C8lDd9D9oitDMvFdXDTk9OaUBVkKroBoVxbXnIsNYRTNlrBpd3aS/jEpkUw2ZZELSIKfh4RlNo6zaRUwNkYn9BTAjdbOdu3ZWX/sMUdd0UWuUhxNx9q+ZyGK7pn/hYkheaJch6ANZE5zIoOxPpfVjEpi03ccPRF5MdfGIG+nMfGBBGONi+aeuxYblMjrpJiND/KdiBVAyOzOcUrqsbzhEY7CEw2j3Kli28169xud0G 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:(366004)(31696002)(83380400001)(2906002)(6916009)(53546011)(26005)(8676002)(8936002)(316002)(16576012)(38100700002)(4326008)(54906003)(86362001)(7416002)(31686004)(2616005)(5660300002)(66556008)(36756003)(66476007)(6486002)(186003)(956004)(508600001)(66946007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?eFBQVjV5NDI5UFdCY2k2Rk9mSmxwS1oxRkgzUn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-Id: 9dcf8030-5861-4014-ee50-08d981bddd9f X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2021 13:51:11.7733 (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: 9LGQhk/VDynsbg2d7bs1BbO7zU+EAqY4sZxrGuqEG75VKrABaaBFJQw+H88Axw1Cp8q3jFU7XHsCa3kxBKaCyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6304 On 27.09.2021 15:43, Oleksandr Andrushchenko wrote: > > On 27.09.21 16:34, Jan Beulich wrote: >> On 27.09.2021 14:08, Oleksandr Andrushchenko wrote: >>> On 27.09.21 14:31, Jan Beulich wrote: >>>> On 23.09.2021 14:55, Oleksandr Andrushchenko wrote: >>>>> --- a/xen/drivers/passthrough/pci.c >>>>> +++ b/xen/drivers/passthrough/pci.c >>>>> @@ -890,6 +890,31 @@ int pci_remove_virtual_device(struct domain *d, const struct pci_dev *pdev) >>>>> return 0; >>>>> } >>>>> >>>>> +/* >>>>> + * Find the physical device which is mapped to the virtual device >>>>> + * and translate virtual SBDF to the physical one. >>>>> + */ >>>>> +bool pci_translate_virtual_device(struct vcpu *v, pci_sbdf_t *sbdf) >>>> Why struct vcpu, when you only need ... >>>> >>>>> +{ >>>>> + struct domain *d = v->domain; >>>> ... this? It's also not really logical for this function to take a >>>> struct vcpu, as the translation should be uniform within a domain. >>> Agree, struct domain is just enough >>>> Also - const please (as said elsewhere before, ideally wherever possible >>>> and sensible). >>> Ok >>>>> + struct vpci_dev *vdev; >>>>> + bool found = false; >>>>> + >>>>> + pcidevs_lock(); >>>>> + list_for_each_entry ( vdev, &d->vdev_list, list ) >>>>> + { >>>>> + if ( vdev->sbdf.sbdf == sbdf->sbdf ) >>>>> + { >>>>> + /* Replace virtual SBDF with the physical one. */ >>>>> + *sbdf = vdev->pdev->sbdf; >>>>> + found = true; >>>>> + break; >>>>> + } >>>>> + } >>>> For a DomU with just one or at most a couple of devices, such a brute >>>> force lookup may be fine. What about Dom0 though? The physical topology >>>> gets split at the segment level, so maybe this would by a reasonable >>>> granularity here as well? >>> Not sure I am following why topology matters here. We are just trying to >>> match one SBDF (as seen by the guest) to other SBDF (physical, >>> as seen by Dom0), so we can proxy DomU's configuration space access >>> to the proper device in Dom0. >> Topology here matters only in so far as I've suggested to have separate >> lists per segment, to reduce look times. Other methods of avoiding a >> fully linear search are of course possible as well. > > Ah, with that that respect then of course. But let's be realistic. > How many PCI devices are normally passed through to a guest? > I can assume this is probably less than 10 most of the time. > By assuming that the number of devices is small I see no profit, > but unneeded complexity in accounting virtual devices per segment > and performing the relevant lookup. So, I would go with a single list > and "brute force lookup" unless it is clearly seen that this needs to be > optimized. Just to repeat my initial reply: "For a DomU with just one or at most a couple of devices, such a brute force lookup may be fine. What about Dom0 though?" If the code uses the simpler form because it's only going to be used for DomU, then that's fine for now. But such latent issues will want recording - e.g. by TODO comments or at the very least suitable pointing out in the description. Jan