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 EFABBC433EF for ; Thu, 18 Nov 2021 13:26:14 +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 98D6161401 for ; Thu, 18 Nov 2021 13:26:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 98D6161401 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.227420.393330 (Exim 4.92) (envelope-from ) id 1mnhQK-0003Jn-07; Thu, 18 Nov 2021 13:25:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 227420.393330; Thu, 18 Nov 2021 13:25:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mnhQJ-0003Jg-SZ; Thu, 18 Nov 2021 13:25:55 +0000 Received: by outflank-mailman (input) for mailman id 227420; Thu, 18 Nov 2021 13:25:54 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mnhQI-0003JZ-Fy for xen-devel@lists.xenproject.org; Thu, 18 Nov 2021 13:25:54 +0000 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.109.102]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0dae80be-4873-11ec-9787-a32c541c8605; Thu, 18 Nov 2021 14:25:53 +0100 (CET) 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-21-8edaqIXlOhKUwRT9e_EATg-1; Thu, 18 Nov 2021 14:25:51 +0100 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VI1PR04MB5168.eurprd04.prod.outlook.com (2603:10a6:803:56::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.27; Thu, 18 Nov 2021 13:25:47 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::8062:d7cb:ca45:1898]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::8062:d7cb:ca45:1898%3]) with mapi id 15.20.4713.019; Thu, 18 Nov 2021 13:25:47 +0000 Received: from [10.156.60.236] (37.24.206.209) by AM6P192CA0021.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.20 via Frontend Transport; Thu, 18 Nov 2021 13:25:46 +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: 0dae80be-4873-11ec-9787-a32c541c8605 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1637241952; 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=Edk/7tlPwAHfMTQGjYz4puhyORycPzNtUVWTYTkXBc0=; b=dFcuGhXrrT7Uu5cpBCAYEgiF7BqAbz2qvJpVtWWyrss/pGEtlta5yYU7MtzHFDwJe/NPdz AqB1yMFeF51TZcHshM7/UP0RF86uLyDqRsopHDIILnLrN988g9CtQxqSI3lrI+qZvqoeBd nifjyRvVzQqCQe3mkvMSUXyURMyfFVI= X-MC-Unique: 8edaqIXlOhKUwRT9e_EATg-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jl59DAnDYYv6qlM/Q0mIz33G8XQ7WeTR3MGAgyeyt3z5E7Ez2Gu7n7KSZp2rWdHdsE5G/Ala7aPH6GTL/3PChOfa7KepsUYeCKZGSGrN+1XA//lD88zpMmfkvSzT2tiC8V7tGta/luL6B5WEU28Y8DnJ6ujrUOQ9Qtd0f8F58A22NqEcRk4tS6k04nPa4eRgPvlC6Wn2OuztVO9abzFiZr7dRLOCV/Sl7SPpu5iFaT7a3a76iyo3MwLM0hzUYjpYL8HDm4n09nBjW3Rq+L1KYZTNEHSennQsvnXC6ih6pgg6wGujuImNUbNxFvcjnXHvQe4COiVN+PiJfuOjer9kbA== 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=Edk/7tlPwAHfMTQGjYz4puhyORycPzNtUVWTYTkXBc0=; b=eJzHB4DPrdl8XGHliaYZxHfGxWujOTYCb/jtYp7/CLLbEI/0kltooA94c7iowWiKmlR12tpY/zE5B22eyVdiec4xCvF1GY5WJbN/ooZ7wV9IDvoKjPDqr4R0pkyV8nsI8Fc3zoWiEE4EjYRcxz3sbyplasK+5Fec1GTGK+7ZYe7nVS2+RecDDCJLIrfr6uff0zbIXWz6YcFgTagZ8Fi629dHokukwPUV0idVja5as+jLrf2D6CmIwDPYqMMI+jy76pmWT0Unoh0YtCpvB16OseLKiRdyz9xlWI0LYkZrqXZXdLVE4t9FzXt6ccbDAGG31vYyplNBE5uQ3I0gplxC4g== 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: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Thu, 18 Nov 2021 14:25:46 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH v4 02/11] vpci: cancel pending map/unmap on vpci removal Content-Language: en-US To: Oleksandr Andrushchenko , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Cc: "julien@xen.org" , "sstabellini@kernel.org" , Oleksandr Tyshchenko , Volodymyr Babchuk , Artem Mygaiev , "andrew.cooper3@citrix.com" , "george.dunlap@citrix.com" , "paul@xen.org" , Bertrand Marquis , Rahul Singh , "xen-devel@lists.xenproject.org" References: <20211105065629.940943-1-andr2000@gmail.com> <20211105065629.940943-3-andr2000@gmail.com> From: Jan Beulich In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM6P192CA0021.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::34) 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: f29923d2-5ebf-4db2-7b6d-08d9aa96eeb6 X-MS-TrafficTypeDiagnostic: VI1PR04MB5168: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h/w5/lr2XNay/vW2azere6kaZrBN2Knrm3N5g5boz0ez65lDTjr5y9E2Cx2Iy/U4Q+yzpsj9dT5XqvPCzYH2mVJr7VcNWNG1i1lLO5Q0CyFj1IHJKWxc211dtOmhFEMsf9H4wXFthZc4yHZeG/XVo6+2Xj4OSvbU0OzjICHY1fAnuB5c3762/GwCQ5PijPoBqCZNoL0fRrjABJ58zte9U5H5ytb7GyRsKAj+XjhY/Z6bvM1tEoMz5l7ltOd70PsC4R0w+6Uil+n3DmuSftYg3hErqjgbyhs6pQnTRzW6Ps4EeePbyAT799oujj1Ezv5t3u/cwv+wK4ZKAD6VO/7XKgVBlJcpK4QiadlSw467dp+9XpzKZ7f4zSwuqtrKxBbFCdfg03SHTzAyUN59XwJ0/ZKp0GZO6QTp4g4UaaIDbXa2vJIkEwhMMS2LNQ6xhIM9025hTAjHxQDxpTP7zuBkN8CO/SZtg2xPZ5CAKRdUsQreSzKfnyow2qcpeVbBDuv0CWcqf1w7cT6KsMlQdq2xSzKH5iB9M1Rzi9JCLUBKkio2Ew1vuSnGZEofLATcy9ne+Im7DsUzG1UJbkwlxjtsoJGsdF4XmpwioujTNpVBAI2ulIfn/BUlFLUqexmPJmzzDRygaynXLiwFml53peBd//cGKbr5ZgLcqojSxFm/KFI4hSqLPadd4WK0PzJSrWmMihk7PbBMn5lWxApa6g0UBmLQbUbRImAmwFFDZMibfJPMZZqW1Vj8wxzVSw/fTxE9 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)(86362001)(956004)(16576012)(83380400001)(508600001)(31686004)(2906002)(66556008)(186003)(66476007)(6486002)(2616005)(7416002)(53546011)(26005)(54906003)(38100700002)(8676002)(31696002)(110136005)(5660300002)(4326008)(8936002)(66946007)(316002)(36756003)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?TFFJOENBcEtqRjhhWm5iM1BHT05USjBEZm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8?B?RFdweE5ZVFlGUERScHpDOUU2d1R6UzlsSUt5aHZabm9sSDlSazlPVjd2ZmpG?= =?utf-8?B?WUhwaWlnVnZ6TUd6T3U1bHYwbEJVZ3l5K2VGZUl2N3BqSTJyeTh5d1hNZjM1?= =?utf-8?B?Y1d0UXdTSnF4RWlWUHZiTGE4TGdXMWtyTHRsN25DWVdCaFJHLzFPMkV1N1pp?= =?utf-8?B?VkM5SXVJZDNFSll0bUZMU0tVY1JiTHB2dEdaZU82c1hzTWtudTdKNUNqZ0lj?= =?utf-8?B?THA2Q25VU21SbE1SelZKU3R1aCtiZFZyRmdhbjdydTZmTEtBWFZJbTcybWVY?= =?utf-8?B?NlMvM0lVbjArUVhqTk9mTm5LclgzTlJkVkMrWmVGS3RucStER1RPQkNnVEZJ?= =?utf-8?Q?g4d7QmtH3hNPzGzkWW+4hEI=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: f29923d2-5ebf-4db2-7b6d-08d9aa96eeb6 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 13:25:47.7667 (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: b/aZsNmfgCmRaZ7OVlFJSBrYg7Tjj10bkeuCS/PPqQMgZdnJiqisOjEK2p4NWIzqbIWUkhrmvq5EY7nR74G+Mg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5168 On 18.11.2021 10:32, Oleksandr Andrushchenko wrote: > > > On 18.11.21 11:15, Jan Beulich wrote: >> On 18.11.2021 09:54, Oleksandr Andrushchenko wrote: >>> On 18.11.21 10:36, Jan Beulich wrote: >>>> On 18.11.2021 08:49, Oleksandr Andrushchenko wrote: >>>>> On 17.11.21 10:28, Jan Beulich wrote: >>>>>> On 05.11.2021 07:56, Oleksandr Andrushchenko wrote: >>>>>>> From: Oleksandr Andrushchenko >>>>>>> >>>>>>> When a vPCI is removed for a PCI device it is possible that we have >>>>>>> scheduled a delayed work for map/unmap operations for that device. >>>>>>> For example, the following scenario can illustrate the problem: >>>>>>> >>>>>>> pci_physdev_op >>>>>>> pci_add_device >>>>>>> init_bars -> modify_bars -> defer_map -> raise_softirq(SCHEDULE_SOFTIRQ) >>>>>>> iommu_add_device <- FAILS >>>>>>> vpci_remove_device -> xfree(pdev->vpci) >>>>>>> >>>>>>> leave_hypervisor_to_guest >>>>>>> vpci_process_pending: v->vpci.mem != NULL; v->vpci.pdev->vpci == NULL >>>>>>> >>>>>>> For the hardware domain we continue execution as the worse that >>>>>>> could happen is that MMIO mappings are left in place when the >>>>>>> device has been deassigned >>>>>>> >>>>>>> For unprivileged domains that get a failure in the middle of a vPCI >>>>>>> {un}map operation we need to destroy them, as we don't know in which >>>>>>> state the p2m is. This can only happen in vpci_process_pending for >>>>>>> DomUs as they won't be allowed to call pci_add_device. >>>>>>> >>>>>>> Signed-off-by: Oleksandr Andrushchenko >>>>>> Thinking about it some more, I'm not convinced any of this is really >>>>>> needed in the presented form. >>>>> The intention of this patch was to handle error conditions which are >>>>> abnormal, e.g. when iommu_add_device fails and we are in the middle >>>>> of initialization. So, I am trying to cancel all pending work which might >>>>> already be there and not to crash. >>>> Only Dom0 may be able to prematurely access the device during "add". >>>> Yet unlike for DomU-s we generally expect Dom0 to be well-behaved. >>>> Hence I'm not sure I see the need for dealing with these. >>> Probably I don't follow you here. The issue I am facing is Dom0 >>> related, e.g. Xen was not able to initialize during "add" and thus >>> wanted to clean up the leftovers. As the result the already >>> scheduled work crashes as it was not neither canceled nor interrupted >>> in some safe manner. So, this sounds like something we need to take >>> care of, thus this patch. >> But my point was the question of why there would be any pending work >> in the first place in this case, when we expect Dom0 to be well-behaved. > I am not saying Dom0 misbehaves here. This is my real use-case > (as in the commit message): > > pci_physdev_op > pci_add_device > init_bars -> modify_bars -> defer_map -> raise_softirq(SCHEDULE_SOFTIRQ) > iommu_add_device <- FAILS > vpci_remove_device -> xfree(pdev->vpci) > > leave_hypervisor_to_guest > vpci_process_pending: v->vpci.mem != NULL; v->vpci.pdev->vpci == NULL First of all I'm sorry for having lost track of that particular case in the course of the discussion. I wonder though whether that's something we really need to take care of. At boot (on x86) modify_bars() wouldn't call defer_map() anyway, but use apply_map() instead. I wonder whether this wouldn't be appropriate generally in the context of init_bars() when used for Dom0 (not sure whether init_bars() would find some form of use for DomU-s as well). This is even more so as it would better be the exception that devices discovered post-boot start out with memory decoding enabled (which is a prereq for modify_bars() to be called in the first place). Jan