Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp51889rdb; Wed, 29 Nov 2023 19:54:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzjJ5L7sqqcrkFGGsIXwag3l4fgbrpwmq3JTkjxoeXoJeUtOA+itKQi9FUimBE+Xf5YrO1 X-Received: by 2002:a17:902:ea02:b0:1cf:c9c2:5fcb with SMTP id s2-20020a170902ea0200b001cfc9c25fcbmr14876608plg.47.1701316456568; Wed, 29 Nov 2023 19:54:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701316456; cv=none; d=google.com; s=arc-20160816; b=rlGboUjgJEf8yOMVlOdFlvX+oc0lAIGE7ZqjrBANPFS3Rs0L8hBY1jqlP6Z06TIcoh L/MwGbF30Ic4st709uXHWLX4gSzqoWmMNLervRbHH+Tnbllo08pzpxtkiOnj8v1NAX8/ 4DtL7Xok3EkaGa08bZfGGl+jBGFwHqV+1fykJ8lEa0QI5iE8b7122Vhf10171mJOthyP 66qdsplw5syW2yvBXeYaDXhjh0SGzJ4JEhWNxgXBjq7y1swYES81OP1FEmOn47KwGohg BfNbvZ2Dd98Fi1VtB1Lz2s4Fh9ROhUZbOFQWg7Uc0LOtJzxFo5+54G8WRbqiZp1Ojp3i eAmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=R25xA7WSeN9I1fjA/YwIhV538AAoqTN+faUEgZNJWBU=; fh=P6mSqkOEUCx0dWHpsNevWm8v+zObUiItWatHSCC2Xt0=; b=a+7R7KenuH0XvCNqtcMYSmJE4nE7fwB/IDbtITey4qmquofJn+2wL5eEuYgfgQhiYb jiWJ/Ayia+pZoVcLkjx0JGHH2x4S1Z35ady6OzRkq+aiD1TG8Fht2J9gy1NrqUzCArzf zM0e0DjMpGYgp+ENmsLToM1+ufXi7LKS9MqxY/oPOtz9KzaynMq3lOnwgAzTcIkohYTt kabzMvpHFxK4iuFwZMAH2B/WCHvhntkcbYZBbZMkUHVyidbm6xs4h2KUHgmwASjrQdHA dtC+z5EIww8U1Jry1GKaJ4rWaNfeYY9FIUdxt9xx8IO28V/23Xt5kUnJJp+TjrB5YBUQ aUvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GvMRCkn1; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id s22-20020a170902989600b001cc259278a5si233148plp.647.2023.11.29.19.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 19:54:16 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=GvMRCkn1; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 1F48B81FD282; Wed, 29 Nov 2023 19:54:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231640AbjK3Dx7 (ORCPT + 99 others); Wed, 29 Nov 2023 22:53:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230393AbjK3Dx6 (ORCPT ); Wed, 29 Nov 2023 22:53:58 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4F40D5C for ; Wed, 29 Nov 2023 19:54:04 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F28FC433C7; Thu, 30 Nov 2023 03:54:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701316444; bh=eqrzzX60ARPCRs9X4WWPjycQ35QvNwJsAd1XNvK8saw=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=GvMRCkn1WFSi9WF+av2EeV08oEHGzraC7gBBdTXSLBjyvYt2SQtWcQzoDvBRXOkRX EcSCe1XuhGeKNw4mFK+3a+PtBYv2DE/lAtRxKP1TkpIaR0X0N7QTUrE2PULcyzM50I 30COdUKB7E6Xn4rfhvlNEQAoW4iHWUIDf+cbbBI/k2//K5ezvdu9FT7hoNCizoS+zt CGTQ1luYqgCdMC9ZgWNcrPSsi90Gj1pDFP57PXEEqEsp519moh1LCh1hvZhQK1bZqI 0RMWGKVE9Grgoadx/opXr8GHVBkj0wm2gqYZe8hlWC943iDrXBZ5gOLff9EyMhLU9m D/KgNLvvSxAYw== Date: Wed, 29 Nov 2023 19:53:59 -0800 (PST) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: Jiqian Chen , roger.pau@citrix.com cc: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Thomas Gleixner , Boris Ostrovsky , "Rafael J . Wysocki" , Len Brown , Bjorn Helgaas , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Stefano Stabellini , Alex Deucher , Christian Koenig , Stewart Hildebrand , Xenia Ragiadakou , Honglei Huang , Julia Zhang , Huang Rui , Huang Rui Subject: Re: [RFC KERNEL PATCH v2 2/3] xen/pvh: Unmask irq for passthrough device in PVH dom0 In-Reply-To: <20231124103123.3263471-3-Jiqian.Chen@amd.com> Message-ID: References: <20231124103123.3263471-1-Jiqian.Chen@amd.com> <20231124103123.3263471-3-Jiqian.Chen@amd.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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]); Wed, 29 Nov 2023 19:54:14 -0800 (PST) On Fri, 24 Nov 2023, Jiqian Chen wrote: > This patch is to solve two problems we encountered when we try to > passthrough a device to hvm domU base on Xen PVH dom0. > > First, hvm guest will alloc a pirq and irq for a passthrough device > by using gsi, before that, the gsi must first has a mapping in dom0, > see Xen code pci_add_dm_done->xc_domain_irq_permission, it will call > into Xen and check whether dom0 has the mapping. See > XEN_DOMCTL_irq_permission->pirq_access_permitted, "current" is PVH > dom0 and it return irq is 0, and then return -EPERM. > This is because the passthrough device doesn't do PHYSDEVOP_map_pirq > when thay are enabled. > > Second, in PVH dom0, the gsi of a passthrough device doesn't get > registered, but gsi must be configured for it to be able to be > mapped into a domU. > > After searching codes, we can find map_pirq and register_gsi will be > done in function vioapic_write_redirent->vioapic_hwdom_map_gsi when > the gsi(aka ioapic's pin) is unmasked in PVH dom0. So the problems > can be conclude to that the gsi of a passthrough device doesn't be > unmasked. > > To solve the unmaske problem, this patch call the unmask_irq when we > assign a device to be passthrough. So that the gsi can get registered > and mapped in PVH dom0. Roger, this seems to be more of a Xen issue than a Linux issue. Why do we need the unmask check in Xen? Couldn't we just do: diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c index 4e40d3609a..df262a4a18 100644 --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -287,7 +287,7 @@ static void vioapic_write_redirent( hvm_dpci_eoi(d, gsi); } - if ( is_hardware_domain(d) && unmasked ) + if ( is_hardware_domain(d) ) { /* * NB: don't call vioapic_hwdom_map_gsi while holding hvm.irq_lock