Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1885831lqo; Mon, 13 May 2024 00:59:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWfmm82QvYTCTBCqc5jLPlLb0IuJFwM0vn6JUYrWAxaoF8VNs3/w1ykmCLLL5M0owZG0MI8U3AfHWD+2r7bWiYcZGm3Qf2cInlgblAhKg== X-Google-Smtp-Source: AGHT+IE6FSm6vqikkTD3YtyeBmbcrZFMErPtNpyGRn/vrpH+NZ5czWsJ660BaEzYLezG9gm11ARa X-Received: by 2002:a17:906:1401:b0:a59:b136:e40f with SMTP id a640c23a62f3a-a5a2d5d08e0mr557175166b.38.1715587188317; Mon, 13 May 2024 00:59:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715587188; cv=pass; d=google.com; s=arc-20160816; b=StCU1FIPib8urzF0HNtb9ztpVfDbVNxdrmjzdwRtTaC1PM+Tf8QhtvRzz8B2d3ODix BYUEMR9aGzuvgovlOx+uGy8XvJKmpWr6HmGixBdfDOLdfFuuo4vIrpmSKNjWsyunx/EE NdVlu62cODLWqJbPIGCZnwNI9LpbvBGuWJ1TshbfjFKyWOuCCzVvz7Wwiv8n8Ira5I1k HhCqsjzlnRlt6BzyhBpKJwFaSAOJmqUWzE04nzYbU+5E4GZ0ftv0ehJupHEryOGzhy0t hABL0fUy6pSfvBWotMUjO8uQ3kuG2e0y7u56P8kU2STOkpd8NlMLJy1VrEEhkCgya6/w w6sw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=O5smVEjR/VVS0e2yObdThJN4tCbUbbAC8XLh8Tbaot0=; fh=6j3IH5FsdO4ZZ7LcudJhGjTkpIq+z1yzOIcad7r2L94=; b=ojPKh2nV5cD80N/er5cl0GoqxhRDOokHEkHlZK5eRng9yIAFUDp/4ztz+Dzq4yOpjC Mkcp1BttUPkDD9IxYQlQZCgNOXwhHc98ysr5Vi7vmIYcYcX8GYmyr1x8nISGLlXBWehE Xm+hn6p+Zlas/zunEMzC3/rzRq1KHvGouEBFzL7NJWfpu3OplVDHcC5BDoGrRQJwurY7 pjhZfmmAxV3D02GmAq1Faor0M2xsqNNb8HNEYog8IuY/HKdzyXFeq3ej8S3/Oi4Dg0yK RZuQ56wwrwQttHkJV4CKs0wZ0Wo0mkEn075WGFROODTOkYA+o+DjCVrgJjSQ1Lujw2Ug 2HxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=KTdARBuR; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-177313-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177313-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17ba3aebsi485403166b.512.2024.05.13.00.59.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 00:59:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177313-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=KTdARBuR; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-177313-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177313-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DBAF01F242CF for ; Mon, 13 May 2024 07:59:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C30BA146D7D; Mon, 13 May 2024 07:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="KTdARBuR" Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E52BB146A9D for ; Mon, 13 May 2024 07:59:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715587179; cv=none; b=Ha2mBiy6sD8Y8smZShWGwOhC7hPiFBM2ObLdataHq+PE9qCLixZkVzQQTGc3CvqbzCnXZCfgrDTDQJ/L7mH0ZriEJInSwT0wVsPvtFvKdzuJFyZPANrSqaPuOLXXLCfPYVTrKjY/m8O46DBn2/aCZ61uuAVVAAye6qW/1gHi23k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715587179; c=relaxed/simple; bh=GFPwfFMhe5sT4S61UgnPsXXaA0PJ4X/HHal5OzoKZx8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=i6Gk2VgoAu2Y3p0IxC8YlsB5pPfDFjMnVy6zwXvn0RrWutS1s88dH8iBWM47QERrhF9kqwz32+NAVLG4uisU470Rp0GZg8qGdbSvtfyIkTIT8/V3iYmu5SdFRnFxA9Vp00xONaMPTVjgQPJQrMNPb8Xy77sVg2PUjpPzHmubo/8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=KTdARBuR; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a599eedc8eeso971819566b.1 for ; Mon, 13 May 2024 00:59:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1715587175; x=1716191975; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=O5smVEjR/VVS0e2yObdThJN4tCbUbbAC8XLh8Tbaot0=; b=KTdARBuR4AJkUzxsvx9ava5l6GhoNdIseaOa1swFbFjBuXaGIMaYZFu7baYzBvKU/K y2RzUOOJnaK0i/rSxEd4u5oMJ79wBQMlEpNaX/SRDUL4CWwiISjhthGwLMQMmD3WmAa1 WBY6pC4SXdxeCIZTFjr03NrZjSGl2rBnz5GNzI1NEhpVE2TN3nLStMM03JBuR68ZvdBP vNYgmAk1zs2HcWYm5lUiV0U83E5GcjS/RM3WFmN1TJ5bY26BZrsOMOXWZk72KhbDr6Xy Lc494kVioiz6ZtRgvnasSSM1FIDiEqYLcproSQb84sX4t8qPBU98avLviFiKZZRJbHHi FiTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715587175; x=1716191975; h=content-transfer-encoding:in-reply-to: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=O5smVEjR/VVS0e2yObdThJN4tCbUbbAC8XLh8Tbaot0=; b=iDe0lZWYNJodDoUmOkHcw/5Ej5AMtCZZI0omgyK0+M/WNfpuLA0byntVFjj2hGE442 1m0BIog9vvWNyieoW5WjcmYnR7fcfAVdv1lL3PtxKFA078cgpk2g+vPdKJkd7v+ysKeS uRMJ9WMka2qdR6XlI7nNbOMevj19XS2OD08iX/eVkIZDmTUGyiUN6Zu5JLMZaGsFLnyQ dbx/DFpErQtwF94JhAmvHD1VX2DDul1/XNiOai8zWYv5DUdDHHR1rFlK9vfqHGm5nxul H4TSnIte76h4LZESJeMfCyaMI9wlxis/liYxYnxRGDIvMOYo2SckVSRQ09C7Ps3whTaf rIEw== X-Forwarded-Encrypted: i=1; AJvYcCXFxAkuG43vnIXHE1aXOl6usIFRgh7V/40GTqhDcbOlijAmGfDiBwhRvKSzhPX4d4FharH4c0RpvpE282VjnYq6TrPosGL2NMgn85CW X-Gm-Message-State: AOJu0YxvcdaSfUc8Rp8yRq9mv2BdxeRV9iJ1k3XYmj4uID3vX3xjTAcj vZX52lDwUP3B7m9vcMWeWWu6yB5GMhRt6uspQ2VVVSksq5qRBhbTYntKIi3WuqA= X-Received: by 2002:a17:906:f111:b0:a5a:28cc:ff85 with SMTP id a640c23a62f3a-a5a2d58545amr563789566b.28.1715587175252; Mon, 13 May 2024 00:59:35 -0700 (PDT) Received: from ?IPV6:2003:e5:873c:a500:6aaf:b7a7:7c29:ae5c? (p200300e5873ca5006aafb7a77c29ae5c.dip0.t-ipconnect.de. [2003:e5:873c:a500:6aaf:b7a7:7c29:ae5c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b18110sm561472766b.225.2024.05.13.00.59.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 May 2024 00:59:34 -0700 (PDT) Message-ID: <55bbd23b-d851-4274-9511-c5a7af938a07@suse.com> Date: Mon, 13 May 2024 09:59:34 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC KERNEL PATCH v6 3/3] xen/privcmd: Add new syscall to get gsi from irq To: "Chen, Jiqian" , Stefano Stabellini Cc: Bjorn Helgaas , "Rafael J . Wysocki" , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , "xen-devel@lists.xenproject.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-acpi@vger.kernel.org" , "Huang, Ray" References: <20240419033616.607889-1-Jiqian.Chen@amd.com> <20240419033616.607889-4-Jiqian.Chen@amd.com> <79666084-fc2f-4637-8f0b-3846285601b8@suse.com> Content-Language: en-US From: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 13.05.24 09:47, Chen, Jiqian wrote: > Hi, > On 2024/5/10 17:06, Chen, Jiqian wrote: >> Hi, >> >> On 2024/5/10 14:46, Jürgen Groß wrote: >>> On 19.04.24 05:36, Jiqian Chen wrote: >>>> In PVH dom0, it uses the linux local interrupt mechanism, >>>> when it allocs irq for a gsi, it is dynamic, and follow >>>> the principle of applying first, distributing first. And >>>> the irq number is alloced from small to large, but the >>>> applying gsi number is not, may gsi 38 comes before gsi 28, >>>> it causes the irq number is not equal with the gsi number. >>>> And when passthrough a device, QEMU will use device's gsi >>>> number to do pirq mapping, but the gsi number is got from >>>> file /sys/bus/pci/devices//irq, irq!= gsi, so it will >>>> fail when mapping. >>>> And in current linux codes, there is no method to translate >>>> irq to gsi for userspace. >>>> >>>> For above purpose, record the relationship of gsi and irq >>>> when PVH dom0 do acpi_register_gsi_ioapic for devices and >>>> adds a new syscall into privcmd to let userspace can get >>>> that translation when they have a need. >>>> >>>> Co-developed-by: Huang Rui >>>> Signed-off-by: Jiqian Chen >>>> --- >>>>   arch/x86/include/asm/apic.h      |  8 +++++++ >>>>   arch/x86/include/asm/xen/pci.h   |  5 ++++ >>>>   arch/x86/kernel/acpi/boot.c      |  2 +- >>>>   arch/x86/pci/xen.c               | 21 +++++++++++++++++ >>>>   drivers/xen/events/events_base.c | 39 ++++++++++++++++++++++++++++++++ >>>>   drivers/xen/privcmd.c            | 19 ++++++++++++++++ >>>>   include/uapi/xen/privcmd.h       |  7 ++++++ >>>>   include/xen/events.h             |  5 ++++ >>>>   8 files changed, 105 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h >>>> index 9d159b771dc8..dd4139250895 100644 >>>> --- a/arch/x86/include/asm/apic.h >>>> +++ b/arch/x86/include/asm/apic.h >>>> @@ -169,6 +169,9 @@ extern bool apic_needs_pit(void); >>>>     extern void apic_send_IPI_allbutself(unsigned int vector); >>>>   +extern int acpi_register_gsi_ioapic(struct device *dev, u32 gsi, >>>> +                    int trigger, int polarity); >>>> + >>>>   #else /* !CONFIG_X86_LOCAL_APIC */ >>>>   static inline void lapic_shutdown(void) { } >>>>   #define local_apic_timer_c2_ok        1 >>>> @@ -183,6 +186,11 @@ static inline void apic_intr_mode_init(void) { } >>>>   static inline void lapic_assign_system_vectors(void) { } >>>>   static inline void lapic_assign_legacy_vector(unsigned int i, bool r) { } >>>>   static inline bool apic_needs_pit(void) { return true; } >>>> +static inline int acpi_register_gsi_ioapic(struct device *dev, u32 gsi, >>>> +                    int trigger, int polarity) >>>> +{ >>>> +    return (int)gsi; >>>> +} >>>>   #endif /* !CONFIG_X86_LOCAL_APIC */ >>>>     #ifdef CONFIG_X86_X2APIC >>>> diff --git a/arch/x86/include/asm/xen/pci.h b/arch/x86/include/asm/xen/pci.h >>>> index 9015b888edd6..aa8ded61fc2d 100644 >>>> --- a/arch/x86/include/asm/xen/pci.h >>>> +++ b/arch/x86/include/asm/xen/pci.h >>>> @@ -5,6 +5,7 @@ >>>>   #if defined(CONFIG_PCI_XEN) >>>>   extern int __init pci_xen_init(void); >>>>   extern int __init pci_xen_hvm_init(void); >>>> +extern int __init pci_xen_pvh_init(void); >>>>   #define pci_xen 1 >>>>   #else >>>>   #define pci_xen 0 >>>> @@ -13,6 +14,10 @@ static inline int pci_xen_hvm_init(void) >>>>   { >>>>       return -1; >>>>   } >>>> +static inline int pci_xen_pvh_init(void) >>>> +{ >>>> +    return -1; >>>> +} >>>>   #endif >>>>   #ifdef CONFIG_XEN_PV_DOM0 >>>>   int __init pci_xen_initial_domain(void); >>>> diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c >>>> index 85a3ce2a3666..72c73458c083 100644 >>>> --- a/arch/x86/kernel/acpi/boot.c >>>> +++ b/arch/x86/kernel/acpi/boot.c >>>> @@ -749,7 +749,7 @@ static int acpi_register_gsi_pic(struct device *dev, u32 gsi, >>>>   } >>>>     #ifdef CONFIG_X86_LOCAL_APIC >>>> -static int acpi_register_gsi_ioapic(struct device *dev, u32 gsi, >>>> +int acpi_register_gsi_ioapic(struct device *dev, u32 gsi, >>>>                       int trigger, int polarity) >>>>   { >>>>       int irq = gsi; >>>> diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c >>>> index 652cd53e77f6..f056ab5c0a06 100644 >>>> --- a/arch/x86/pci/xen.c >>>> +++ b/arch/x86/pci/xen.c >>>> @@ -114,6 +114,21 @@ static int acpi_register_gsi_xen_hvm(struct device *dev, u32 gsi, >>>>                    false /* no mapping of GSI to PIRQ */); >>>>   } >>>>   +static int acpi_register_gsi_xen_pvh(struct device *dev, u32 gsi, >>>> +                    int trigger, int polarity) >>>> +{ >>>> +    int irq; >>>> + >>>> +    irq = acpi_register_gsi_ioapic(dev, gsi, trigger, polarity); >>>> +    if (irq < 0) >>>> +        return irq; >>>> + >>>> +    if (xen_pvh_add_gsi_irq_map(gsi, irq) == -EEXIST) >>>> +        printk(KERN_INFO "Already map the GSI :%u and IRQ: %d\n", gsi, irq); >>>> + >>>> +    return irq; >>>> +} >>>> + >>>>   #ifdef CONFIG_XEN_PV_DOM0 >>>>   static int xen_register_gsi(u32 gsi, int triggering, int polarity) >>>>   { >>>> @@ -558,6 +573,12 @@ int __init pci_xen_hvm_init(void) >>>>       return 0; >>>>   } >>>>   +int __init pci_xen_pvh_init(void) >>>> +{ >>>> +    __acpi_register_gsi = acpi_register_gsi_xen_pvh; >>> >>> No support for unregistering the gsi again? >> __acpi_unregister_gsi is set in function acpi_set_irq_model_ioapic. >> Maybe I need to use a new function to call acpi_unregister_gsi_ioapic and remove the mapping of irq and gsi from xen_irq_list_head ? > When I tried to support unregistering the gsi and removing the mapping during disable device, > I encountered that after running "xl pci-assignable-add 03:00.0", callstack pcistub_init_device->xen_pcibk_reset_device->pci_disable_device->pcibios_disable_device->acpi_pci_irq_disable->__acpi_unregister_gsi > removed the mapping, after that when user space called xen_gsi_from_irq to get gsi, it failed. > > To cover above case, I want to change the implementation of xen_gsi_from_irq to pass sbdf to get the gsi instead of passing irq, > Because the sbdf and gsi of a device is unique and wiil not be changed even device is disabled or re-enabled. > > Do you think this kind of change is acceptable? Yes, I think so. Juergen