Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp697689pxb; Tue, 2 Feb 2021 15:58:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxrWN/4UgiCH2vKZPOdxQ6u/Qg6cPCSAEluaEGm6MWTSzd8596xZQyCePPnP0p/51tA/SbO X-Received: by 2002:a17:906:17d5:: with SMTP id u21mr432514eje.541.1612310287986; Tue, 02 Feb 2021 15:58:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612310287; cv=none; d=google.com; s=arc-20160816; b=LmcDfwuXxotIz/MrhE4g1c4B10RTIzXHTWJfJP/Sixai24FkNjn/dgqCvKMOF56CUZ +e3fsTvLxIThaOQqc9Rb2sv1JvFCtcQPeQ3P+eEeVqLozrIzHoyPhS4XbtKpdh/bwhXp mUP+enNC4K/JAQwwD7hQoIeVpJeuZk86D6+VHkGyrYCRcuhvAmQyVpioT92mihs11Ebq EygjO1IDyjEuN4U0ngIdQJG3/QB840ebkR64Q+T35tZTktFFUL3SGexjwPDC3C0NXgdv cAEV7NUWOGr6BdDm20OSP+udlDl1mJfGz+H3pcuMcISBDnwf824awJgHiMdzQaOmgt+O I3uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=AxHa8gVy5I8JiheSXEMxWWe4GAPhI1nPaKd06/laDjc=; b=nEKxfr/QDDZ46SO0jxaBT0mrxI09Jj1qkdNXIQhuA1kbxdkDt4KkNLwelRFRHZ7dYM acwkYm82buzUvcWOYxP8PtKTYfjdBzNdQq2G+OcuvwwM0kRhmmGpHRJqurD8P08TE5qh TtAARbX+Rh9JZc0ZLabgWeAFPWk7cB8waxWLO2qnCjaQLVbv45ZhTjAqBWqMqnXz9Y+0 Tlz9Lwvg9ck6Q+pvAPdBUVw8RFMLSAeXvJTqj92gm8fBnz1p2l6OpCHbCgRSurs8usXa CyyW0ba+cah83G3rjRTNdOu1V8lsN/5fNZWCAkpbz86YUaY+LAKrXpjQbpkhSp0OYOdb +5Kw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h24si262631ejt.167.2021.02.02.15.57.42; Tue, 02 Feb 2021 15:58:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237593AbhBBRfG (ORCPT + 99 others); Tue, 2 Feb 2021 12:35:06 -0500 Received: from mail-wm1-f51.google.com ([209.85.128.51]:52535 "EHLO mail-wm1-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236422AbhBBRcg (ORCPT ); Tue, 2 Feb 2021 12:32:36 -0500 Received: by mail-wm1-f51.google.com with SMTP id l12so2164360wmq.2; Tue, 02 Feb 2021 09:32:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=AxHa8gVy5I8JiheSXEMxWWe4GAPhI1nPaKd06/laDjc=; b=XG4rjlGEVQwBFRztp83ZOkNVJI60AQYsPXRLAk23PWfQG9c67AuMMK/qq6hLsQR04u LBCen1n3Wq9H51hQbLmUDBGmWfEp9ey/y41hIxfxhvDqCZgvZJBR9IMChz9p2OEsnrz5 PkU8ySiO0RooO+EhMf8H6A3LZtvvkMt7PTatn8F0RmYfK7fK9cl2hzQF3E1OeUGAQwpW L6HbpEnLzu4aZYQAUfWVcXzj9QDizwZyNnKNXhYNWM+gH2zbduBgiXiY1O6pzTlApc0t rPACRfL/tK87CUv7OCjlyzSg07gz9TUP7gynXBBy3iWBJY5a/UMxO31QZ5vONWP1Mpys GFNA== X-Gm-Message-State: AOAM533F2qAZ0EPW/b4hbPZWKPrn2KwY+fxfNAsQX94mdcY5RgyJKTUL P3g3NAy5QfDyRke5zgo1x7Y= X-Received: by 2002:a1c:25c2:: with SMTP id l185mr4649522wml.62.1612287115021; Tue, 02 Feb 2021 09:31:55 -0800 (PST) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id r124sm4166233wmr.16.2021.02.02.09.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 09:31:54 -0800 (PST) Date: Tue, 2 Feb 2021 17:31:53 +0000 From: Wei Liu To: Michael Kelley Cc: Wei Liu , Linux on Hyper-V List , "virtualization@lists.linux-foundation.org" , Linux Kernel List , Vineeth Pillai , Sunil Muthuswamy , Nuno Das Neves , "pasha.tatashin@soleen.com" , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" Subject: Re: [PATCH v5 15/16] x86/hyperv: implement an MSI domain for root partition Message-ID: <20210202173153.jkbvwck2vsjlbjbz@liuwe-devbox-debian-v2> References: <20210120120058.29138-1-wei.liu@kernel.org> <20210120120058.29138-16-wei.liu@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 27, 2021 at 05:47:04AM +0000, Michael Kelley wrote: > From: Wei Liu Sent: Wednesday, January 20, 2021 4:01 AM > > > > When Linux runs as the root partition on Microsoft Hypervisor, its > > interrupts are remapped. Linux will need to explicitly map and unmap > > interrupts for hardware. > > > > Implement an MSI domain to issue the correct hypercalls. And initialize > > this irqdomain as the default MSI irq domain. > > > > Signed-off-by: Sunil Muthuswamy > > Co-Developed-by: Sunil Muthuswamy > > Signed-off-by: Wei Liu > > --- > > v4: Fix compilation issue when CONFIG_PCI_MSI is not set. > > v3: build irqdomain.o for 32bit as well. > > I'm not clear on the intent for 32-bit builds. Given that hv_proc.c is built > only for 64-bit, I'm assuming running Linux in the root partition > is only functional for 64-bit builds. So is the goal simply that 32-bit > builds will compile correctly? Seems like maybe there should be > a CONFIG option for running Linux in the root partition, and that > option would force 64-bit. To ensure 32 bit kernel builds and 32 bit guests still work. The config option ROOT_API is to be introduced by Nuno's /dev/mshv series. We can use that option to gate some objects when that's available. > [...] > > diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c > > new file mode 100644 > > index 000000000000..19637cd60231 > > --- /dev/null > > +++ b/arch/x86/hyperv/irqdomain.c > > @@ -0,0 +1,332 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +// > > +// Irqdomain for Linux to run as the root partition on Microsoft Hypervisor. > > +// > > +// Authors: > > +// Sunil Muthuswamy > > +// Wei Liu > > I think the // comment style should only be used for the SPDX line. Fixed. > > > + > > +#include > > +#include > > +#include > > + [...] > > +static int hv_map_msi_interrupt(struct pci_dev *dev, int vcpu, int vector, > > + struct hv_interrupt_entry *entry) > > +{ > > + struct hv_input_map_device_interrupt *input; > > + struct hv_output_map_device_interrupt *output; > > + struct hv_device_interrupt_descriptor *intr_desc; > > + unsigned long flags; > > + u16 status; > > + > > + local_irq_save(flags); > > + > > + input = *this_cpu_ptr(hyperv_pcpu_input_arg); > > + output = *this_cpu_ptr(hyperv_pcpu_output_arg); > > + > > + intr_desc = &input->interrupt_descriptor; > > + memset(input, 0, sizeof(*input)); > > + input->partition_id = hv_current_partition_id; > > + input->device_id = hv_build_pci_dev_id(dev).as_uint64; > > + intr_desc->interrupt_type = HV_X64_INTERRUPT_TYPE_FIXED; > > + intr_desc->trigger_mode = HV_INTERRUPT_TRIGGER_MODE_EDGE; > > + intr_desc->vector_count = 1; > > + intr_desc->target.vector = vector; > > + __set_bit(vcpu, (unsigned long*)&intr_desc->target.vp_mask); > > This is using the CPU bitmap format that supports up to 64 vCPUs. Any reason not > to use the format that supports a larger number of CPUs? In either case, perhaps > a check for the value of vcpu against the max of 64 (or the larger number if you > change the bitmap format) would be appropriate. > This is mostly due to we didn't have a suitably large machine during development. I will see if this can use vpset instead. > > + > > + status = hv_do_rep_hypercall(HVCALL_MAP_DEVICE_INTERRUPT, 0, 0, input, output) & > > + HV_HYPERCALL_RESULT_MASK; > > + *entry = output->interrupt_entry; > > + > > + local_irq_restore(flags); > > + > > + if (status != HV_STATUS_SUCCESS) > > + pr_err("%s: hypercall failed, status %d\n", __func__, status); > > + > > + return status; > > +} > > + [...] > > +static int hv_unmap_msi_interrupt(struct pci_dev *dev, struct hv_interrupt_entry > > *old_entry) > > +{ > > + return hv_unmap_interrupt(hv_build_pci_dev_id(dev).as_uint64, old_entry) > > + & HV_HYPERCALL_RESULT_MASK; > > The masking with HV_HYPERCALL_RESULT_MASK is already done in > hv_unmap_interrupt(). > Fixed. Wei.