Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp622809pxv; Fri, 9 Jul 2021 05:48:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEmDhyImJxn01TV+oJhfn3KgwqLZfj8KS4Q1XKZ7MJCMtDOw6cAfOtUOi/gZ7jKxc99IKd X-Received: by 2002:a17:907:7294:: with SMTP id dt20mr32020777ejc.369.1625834885406; Fri, 09 Jul 2021 05:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625834885; cv=none; d=google.com; s=arc-20160816; b=egRAd8n4t0Op2DO/rD2x7LZf9hlR4juXzwr3T2XIxG7yafwt1OQyIC+Rq7Omssimgm jhQWtQEBJTLrJqgUxSbcIua19SpRIFawVOAGSbRRZOPo57fHHiN0T+CIKBbcioyNM6df pCthXA9AEszC1YqsA1BYX/WxKvrTKhB1NJzfgvHIhnQ/yz4cEFWHj/oJhYkll18HyU1o 5yd3LpBQu/WnfosDJ/Nnz2d8fyV9ETYEfSWs4guT7GpxAzpgT+iDCcsFOmlN8GYhA7gP ymy72mRUNOGBNtMm9p6y1jABUYitmfO/KNjiYVgwL3PFU4YnbQ5LjxZ2locmyNgvOcPN +0lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=MCgsQatHGZHYEzm+RJmNvx0cjzQ0+GI9nOXAYC2UcII=; b=prjKwA1JDQg/gRThqh5x3VA375uqD4tn15qTI7NGsHZIOdVf3Dwq7+cRTWMGzs2W39 B2v0pI4t8PuswkjBXTkOcDFSCfSHKccfBu5ROB5H4URnEdbxdw1flONQ7B0HDMDl8SiS lDDyR/pYroJevlLx08Lvl99HLaQsraPPhsaxsVSimCcerNUZg302Zqwn+cb23mFZX/3d acVRSaNEmF/26+u2053BL3DH7tLGzRMDol8WmPvcVraeaD2zO7T3a6cWq5CQTkz6SnDS c1pASeWg+IBoMYSmEKLJf0/VIW1B9nwy1EyMqUfZKK8qVTw587BYy9Mkcbqcgf+IglU8 C4zg== 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w1si7493936edd.443.2021.07.09.05.47.35; Fri, 09 Jul 2021 05:48:05 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231342AbhGIMtL (ORCPT + 99 others); Fri, 9 Jul 2021 08:49:11 -0400 Received: from foss.arm.com ([217.140.110.172]:52168 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231467AbhGIMtK (ORCPT ); Fri, 9 Jul 2021 08:49:10 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E6C9FED1; Fri, 9 Jul 2021 05:46:26 -0700 (PDT) Received: from [10.57.35.192] (unknown [10.57.35.192]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8C00C3F66F; Fri, 9 Jul 2021 05:46:24 -0700 (PDT) Subject: Re: [RFC v1 6/8] mshv: command line option to skip devices in PV-IOMMU To: Wei Liu , Linux on Hyper-V List Cc: "K. Y. Srinivasan" , Stephen Hemminger , pasha.tatashin@soleen.com, kumarpraveen@linux.microsoft.com, Will Deacon , Haiyang Zhang , Dexuan Cui , Linux Kernel List , Michael Kelley , "open list:IOMMU DRIVERS" , Nuno Das Neves , Sunil Muthuswamy , virtualization@lists.linux-foundation.org, Vineeth Pillai References: <20210709114339.3467637-1-wei.liu@kernel.org> <20210709114339.3467637-7-wei.liu@kernel.org> From: Robin Murphy Message-ID: <1c839a00-0f5f-fdfa-cfb3-f345bef9f849@arm.com> Date: Fri, 9 Jul 2021 13:46:19 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210709114339.3467637-7-wei.liu@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-07-09 12:43, Wei Liu wrote: > Some devices may have been claimed by the hypervisor already. One such > example is a user can assign a NIC for debugging purpose. > > Ideally Linux should be able to tell retrieve that information, but > there is no way to do that yet. And designing that new mechanism is > going to take time. > > Provide a command line option for skipping devices. This is a stopgap > solution, so it is intentionally undocumented. Hopefully we can retire > it in the future. Huh? If the host is using a device, why the heck is it exposing any knowledge of that device to the guest at all, let alone allowing the guest to do anything that could affect its operation!? Robin. > Signed-off-by: Wei Liu > --- > drivers/iommu/hyperv-iommu.c | 45 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 45 insertions(+) > > diff --git a/drivers/iommu/hyperv-iommu.c b/drivers/iommu/hyperv-iommu.c > index 043dcff06511..353da5036387 100644 > --- a/drivers/iommu/hyperv-iommu.c > +++ b/drivers/iommu/hyperv-iommu.c > @@ -349,6 +349,16 @@ static const struct irq_domain_ops hyperv_root_ir_domain_ops = { > > #ifdef CONFIG_HYPERV_ROOT_PVIOMMU > > +/* The IOMMU will not claim these PCI devices. */ > +static char *pci_devs_to_skip; > +static int __init mshv_iommu_setup_skip(char *str) { > + pci_devs_to_skip = str; > + > + return 0; > +} > +/* mshv_iommu_skip=(SSSS:BB:DD.F)(SSSS:BB:DD.F) */ > +__setup("mshv_iommu_skip=", mshv_iommu_setup_skip); > + > /* DMA remapping support */ > struct hv_iommu_domain { > struct iommu_domain domain; > @@ -774,6 +784,41 @@ static struct iommu_device *hv_iommu_probe_device(struct device *dev) > if (!dev_is_pci(dev)) > return ERR_PTR(-ENODEV); > > + /* > + * Skip the PCI device specified in `pci_devs_to_skip`. This is a > + * temporary solution until we figure out a way to extract information > + * from the hypervisor what devices it is already using. > + */ > + if (pci_devs_to_skip && *pci_devs_to_skip) { > + int pos = 0; > + int parsed; > + int segment, bus, slot, func; > + struct pci_dev *pdev = to_pci_dev(dev); > + > + do { > + parsed = 0; > + > + sscanf(pci_devs_to_skip + pos, > + " (%x:%x:%x.%x) %n", > + &segment, &bus, &slot, &func, &parsed); > + > + if (parsed <= 0) > + break; > + > + if (pci_domain_nr(pdev->bus) == segment && > + pdev->bus->number == bus && > + PCI_SLOT(pdev->devfn) == slot && > + PCI_FUNC(pdev->devfn) == func) > + { > + dev_info(dev, "skipped by MSHV IOMMU\n"); > + return ERR_PTR(-ENODEV); > + } > + > + pos += parsed; > + > + } while (pci_devs_to_skip[pos]); > + } > + > vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); > if (!vdev) > return ERR_PTR(-ENOMEM); >