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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1F651C3DA7F for ; Wed, 31 Jul 2024 08:42:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.768358.1179129 (Exim 4.92) (envelope-from ) id 1sZ4uh-0003EJ-5d; Wed, 31 Jul 2024 08:42:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 768358.1179129; Wed, 31 Jul 2024 08:42:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sZ4uh-0003EC-2W; Wed, 31 Jul 2024 08:42:27 +0000 Received: by outflank-mailman (input) for mailman id 768358; Wed, 31 Jul 2024 08:42:26 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sZ4ug-0003E6-8l for xen-devel@lists.xenproject.org; Wed, 31 Jul 2024 08:42:26 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cee095a1-4f18-11ef-8776-851b0ebba9a2; Wed, 31 Jul 2024 10:42:24 +0200 (CEST) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a7ac449a0e6so432702366b.1 for ; Wed, 31 Jul 2024 01:42:24 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acad92cd7sm751377066b.179.2024.07.31.01.42.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jul 2024 01:42:23 -0700 (PDT) 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: cee095a1-4f18-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1722415344; x=1723020144; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=VQ4db3DPtRbnbT66oPVaHUGVueoF1qyqImupOtp+U7s=; b=HNcdfbQWyVxpk+5MjehWI3kGsKOPb1QB1zx/zqjWIcYG6NJndPIBdnrI32hE0UApST ry007EBhUPejiXE7jMDuFjBPQgqcos/xK+M7vM/0JB59ulp0jWhukcpoNfhhm+T4n6UL C7F7Q4p0o/6VaAtKFWXh0wS62DW6MkKVtrMTKRdxowi2MRiErMcpDpFcspAy4unbVzTv fUzHZoyQefLAKObyC5iZ+i7ojqLBdQvJtYUN6TITVGDsvVmu/5YpYhynpTktDaionY9W 9L07aS28W3A6YMreq8AjhEx8oOIzjy/od3q5IHmEXYvgXC4QADIEF4s9GqFkVS87lzAl Mf3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722415344; x=1723020144; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=VQ4db3DPtRbnbT66oPVaHUGVueoF1qyqImupOtp+U7s=; b=M6gSYYWTDjldF0/znDCykiC7H/oKLcDOMsOwPyxCVh2KFyGe3pxcXo6MsEsgz4A+Es CUDdJnUS1aJd482oy74V4z59PsK601XjUbDZhlTs1UABycE4wzpoN8wWGTkZJgqxTjx9 pfcC/nb7FpQBTD08MQVd92Cu0zKn1vXMgPBJCBmxb6Bt825+frvYX8IkNxxXDpj68ZPS 8pzBJnabQvcfCQ+mNzbmy5F//Q8/tcbQVgLLrGTvlT2RPa060KITlZDhtT1R8Oj17Yz1 Gc4ERKtNfX8HwWbnyhMeaKaw+O0mdMRuP1invE8QalTP7mUwC6Q2qqjtUE8mITEiMTDk hIGA== X-Gm-Message-State: AOJu0YyZCBR8TQcCjujjtXNHVl4+ucV+6P7KF4BlbvB8iYh0ZLpGmehl m2oei+XLzwOEbVFV7p6LjbwHrKa+M0Kmz+gujVlrY5QBjztw6naF8jBRuuWeOw== X-Google-Smtp-Source: AGHT+IFWP5G163EGfjSDIl+FfE0bi8BJnVghsI/q5Vhm3J5F9tpmtTzNJH+Uvm+3gZ89twWWPQW2eQ== X-Received: by 2002:a17:907:c00f:b0:a77:c827:2cb2 with SMTP id a640c23a62f3a-a7d40138f7emr604305966b.44.1722415343434; Wed, 31 Jul 2024 01:42:23 -0700 (PDT) Message-ID: Date: Wed, 31 Jul 2024 10:42:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [XEN PATCH v12 2/7] x86/pvh: Allow (un)map_pirq when dom0 is PVH To: "Chen, Jiqian" Cc: "xen-devel@lists.xenproject.org" , Wei Liu , Julien Grall , Stefano Stabellini , Anthony PERARD , Juergen Gross , "Daniel P . Smith" , "Hildebrand, Stewart" , "Huang, Ray" , Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: <20240708114124.407797-1-Jiqian.Chen@amd.com> <20240708114124.407797-3-Jiqian.Chen@amd.com> Content-Language: en-US From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4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0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 31.07.2024 10:31, Chen, Jiqian wrote: > On 2024/7/30 21:09, Andrew Cooper wrote: >> On 08/07/2024 12:41 pm, Jiqian Chen wrote: >>> If run Xen with PVH dom0 and hvm domU, hvm will map a pirq for >>> a passthrough device by using gsi, see qemu code >>> xen_pt_realize->xc_physdev_map_pirq and libxl code >>> pci_add_dm_done->xc_physdev_map_pirq. Then xc_physdev_map_pirq >>> will call into Xen, but in hvm_physdev_op, PHYSDEVOP_map_pirq >>> is not allowed because currd is PVH dom0 and PVH has no >>> X86_EMU_USE_PIRQ flag, it will fail at has_pirq check. >>> >>> So, allow PHYSDEVOP_map_pirq when dom0 is PVH and also allow >>> PHYSDEVOP_unmap_pirq for the removal device path to unmap pirq. >>> And add a new check to prevent (un)map when the subject domain >>> doesn't have a notion of PIRQ. >>> >>> So that the interrupt of a passthrough device can be >>> successfully mapped to pirq for domU with a notion of PIRQ >>> when dom0 is PVH >>> >>> Signed-off-by: Jiqian Chen >>> Signed-off-by: Huang Rui >>> Signed-off-by: Jiqian Chen >>> --- >>> xen/arch/x86/hvm/hypercall.c | 6 ++++++ >>> xen/arch/x86/physdev.c | 12 ++++++++++-- >>> 2 files changed, 16 insertions(+), 2 deletions(-) >>> >>> diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c >>> index 0fab670a4871..03ada3c880bd 100644 >>> --- a/xen/arch/x86/hvm/hypercall.c >>> +++ b/xen/arch/x86/hvm/hypercall.c >>> @@ -71,8 +71,14 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) >>> >>> switch ( cmd ) >>> { >>> + /* >>> + * Only being permitted for management of other domains. >>> + * Further restrictions are enforced in do_physdev_op. >>> + */ >>> case PHYSDEVOP_map_pirq: >>> case PHYSDEVOP_unmap_pirq: >>> + break; >>> + >>> case PHYSDEVOP_eoi: >>> case PHYSDEVOP_irq_status_query: >>> case PHYSDEVOP_get_free_pirq: >>> diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c >>> index d6dd622952a9..9f30a8c63a06 100644 >>> --- a/xen/arch/x86/physdev.c >>> +++ b/xen/arch/x86/physdev.c >>> @@ -323,7 +323,11 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) >>> if ( !d ) >>> break; >>> >>> - ret = physdev_map_pirq(d, map.type, &map.index, &map.pirq, &msi); >>> + /* Only mapping when the subject domain has a notion of PIRQ */ >>> + if ( !is_hvm_domain(d) || has_pirq(d) ) >>> + ret = physdev_map_pirq(d, map.type, &map.index, &map.pirq, &msi); >>> + else >>> + ret = -EOPNOTSUPP; >>> >>> rcu_unlock_domain(d); >>> >>> @@ -346,7 +350,11 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) >>> if ( !d ) >>> break; >>> >>> - ret = physdev_unmap_pirq(d, unmap.pirq); >>> + /* Only unmapping when the subject domain has a notion of PIRQ */ >>> + if ( !is_hvm_domain(d) || has_pirq(d) ) >>> + ret = physdev_unmap_pirq(d, unmap.pirq); >>> + else >>> + ret = -EOPNOTSUPP; >>> >>> rcu_unlock_domain(d); >>> >> >> Gitlab is displeased with your offering. >> >> https://gitlab.com/xen-project/xen/-/pipelines/1393459622 >> >> This breaks both {adl,zen3p}-pci-hvm-x86-64-gcc-debug, and given the: >> >> (XEN) [    8.150305] HVM restore d1: CPU 0 >> libxl: error: libxl_pci.c:1491:pci_add_dm_done: Domain >> 1:xc_physdev_map_pirq irq=18 (error=-1): Not supported >> libxl: error: libxl_pci.c:1809:device_pci_add_done: Domain >> 1:libxl__device_pci_add failed for PCI device 0:3:0.0 (rc -3) >> libxl: error: libxl_create.c:1962:domcreate_attach_devices: Domain >> 1:unable to add pci devices >> libxl: error: libxl_xshelp.c:206:libxl__xs_read_mandatory: xenstore read >> failed: `/libxl/1/type': No such file or directory >> libxl: warning: libxl_dom.c:49:libxl__domain_type: unable to get domain >> type for domid=1, assuming HVM >> libxl: error: libxl_domain.c:1616:domain_destroy_domid_cb: Domain >> 1:xc_domain_destroy failed: No such process > > Sorry to forget to validate the scenario of "hvm_pirq=0" for HVM guest since V10->V11(remove the self-check "d == currd"). > > V10 version: > + /* Prevent self-map when currd has no X86_EMU_USE_PIRQ flag */ > + if ( is_hvm_domain(d) && !has_pirq(d) && d == currd ) > + { > + rcu_unlock_domain(d); > + return -EOPNOTSUPP; > + } > > V11 version: > + /* Prevent mapping when the subject domain has no X86_EMU_USE_PIRQ */ > + if ( is_hvm_domain(d) && !has_pirq(d) ) > + { > + rcu_unlock_domain(d); > + return -EOPNOTSUPP; > + } > > V10 is fine for when hvm_pirq is enable or disable. > This issue is from V11, the cause is that when pass "hvm_pirq=0" to HVM guest, then has_pirq() is false, but it still uses the pirq to route the interrupt of passthrough devices. > So, it still does xc_physdev_(un)map_pirq, then fails at the has_pirq() check. > > Hi Jan, > Should I need to change to V10 to only prevent the self-mapping when the subject domain has no PIRQ? > So that it can allow PHYSDEVOP_map_pirq for foreign mapping, no matter the dom0 or the domU has PIRQ or not? No, my position there hasn't changed. I continue to view it as wrong to have any d == currd checks here. Jan