Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1703007pxb; Sat, 23 Apr 2022 14:44:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5YCvzo0o7/iIF05i4ii9GmfzFW5MJy0oNGPfuqt1xMlb0U/7enqU4vti28jJXlX77AH13 X-Received: by 2002:a17:906:99c1:b0:6db:f0cf:e38c with SMTP id s1-20020a17090699c100b006dbf0cfe38cmr9820945ejn.692.1650750271826; Sat, 23 Apr 2022 14:44:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650750271; cv=none; d=google.com; s=arc-20160816; b=SgiY757dfLaRDPuFGfDJoJ145Ry/Zb8nDLu/ZllL6DP6NkYe+RS8I3VU+kOQHVJzQv kNID0UeaKYbSfnAO9LG2hGjK2e0Gay4XIxlvrwNJUX0Vwdli/EEOQ2yQUz29A/cBpVcd +dDCPNF1pIUPY/GNqUBKY3VZgMQAqdmlK6HrVa9vCmaqDWuH1zq2444ZTY6BTs+H6CfY KrFMSOcSrIio6t4Jcj0YHJyBQjw9RKTJ8jJACaTAa8wpSHqz56Qjn/soEUkEwDmsjRw1 WhC2KsnjmgYRr+tAvHmZsIPDtMilBQXzCSPr3rofcJJ9cCh+YLB07vkt6VxXW88EpiVw oPxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=+rvO3lXO8HxP85tOVRy3q+ikDUfF1ZExe4fCdIuEH2I=; b=YaiwXkw9jkVnSTHb7Tnvo58xApAlpfUETIltJNDB06y/SFZpQHodRB4Uw5u02UsNoU TccIOT83QFjYIFnlDzXpk8rl3g+B4fRImKG46j6yDLUH01QHZplgZ0Ypq4zm9vaQ9/Vr c/mBhgrFX2Y0ZhdKsonnK3rMPcJV4nMOt01XDXZKgIk2z48Cb+YC/ohTnJb+dBDNtbiN AOes4iqmy6iLjXVCXiCWQAGMUPB+Mt0we34/z+LNo39F49+qDCRJCt0RePXzeaFKhujO wxHA6fIkodbNh27cbjl5YCihRt22kkkAGbX+vGNwW2Iqb364JkdRFCyxaBOtyRQxhyQL x5OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=M6stsgui; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v6-20020a17090690c600b006ec0aaff9cfsi9818967ejw.932.2022.04.23.14.43.58; Sat, 23 Apr 2022 14:44:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=M6stsgui; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234368AbiDWJoP (ORCPT + 99 others); Sat, 23 Apr 2022 05:44:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231976AbiDWJoF (ORCPT ); Sat, 23 Apr 2022 05:44:05 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7208B2AD6 for ; Sat, 23 Apr 2022 02:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650706868; x=1682242868; h=message-id:date:mime-version:subject:from:to:cc: references:in-reply-to:content-transfer-encoding; bh=hBODXYIZdwIa4pvC2+O751g19pA25+K1CDHEV6UNNiU=; b=M6stsgui2dew1hu0cZMCjQqdkIM6SrQ5kpR2rocsyv1OA3G5WVh1Xupi LXO/cz3JabmRjwA6a/YLpGNkhVaQyrV9few5MlUlaIvOYfao6pnheaMm8 Bz7SKWX4Id1Wa/nuWzuzkjL8kg6nsuEolWRXk9eyZWJOLwqaWeU+56LF8 /I1xJ/iDJwxR2jzp2bHDY0xPtbeNVvHxo9ioQ+eeGYqdJLAuafDIxdZh4 DEZA/e+5Rpel00A3UPrg0RrLWytO/xkwtLhGkC+FeypvTV+n3/9yEN6P0 ZYn6T2I4N8UEEcTGdaOr4aNa0pD0XnczubRP2lcsoR8TaCfMGtnjrGE1n g==; X-IronPort-AV: E=McAfee;i="6400,9594,10324"; a="351323826" X-IronPort-AV: E=Sophos;i="5.90,284,1643702400"; d="scan'208";a="351323826" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2022 02:41:08 -0700 X-IronPort-AV: E=Sophos;i="5.90,284,1643702400"; d="scan'208";a="578340638" Received: from yjsun1-mobl.ccr.corp.intel.com (HELO [10.255.31.217]) ([10.255.31.217]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2022 02:41:05 -0700 Message-ID: <48744abf-bd9b-927d-9ca3-a3e4bdc07fbb@linux.intel.com> Date: Sat, 23 Apr 2022 17:41:05 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH 02/13] iommu: Move bus setup to IOMMU device registration Content-Language: en-US From: Lu Baolu To: Robin Murphy , joro@8bytes.org, will@kernel.org Cc: jean-philippe@linaro.org, zhang.lyra@gmail.com, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, thierry.reding@gmail.com, gerald.schaefer@linux.ibm.com, linux-arm-kernel@lists.infradead.org References: <1d9a2146-9e48-ba97-d049-5d2332ebbd3a@arm.com> <7f693a3a-bbab-237a-af9a-4395e501a5b2@arm.com> <36764562-ad54-b192-4084-842fee8fca78@linux.intel.com> <8cd04084-54d0-9e10-f16f-99541e42d7eb@arm.com> <60d6a35e-5d12-b8c2-b0d2-7155965a10e5@linux.intel.com> In-Reply-To: <60d6a35e-5d12-b8c2-b0d2-7155965a10e5@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/4/23 17:00, Lu Baolu wrote: > On 2022/4/23 16:51, Lu Baolu wrote: >> On 2022/4/23 16:37, Robin Murphy wrote: >>> On 2022-04-23 09:01, Lu Baolu wrote: >>>> Hi Robin, >>>> >>>> On 2022/4/19 15:20, Robin Murphy wrote: >>>>> On 2022-04-19 00:37, Lu Baolu wrote: >>>>>> On 2022/4/19 6:09, Robin Murphy wrote: >>>>>>> On 2022-04-16 01:04, Lu Baolu wrote: >>>>>>>> On 2022/4/14 20:42, Robin Murphy wrote: >>>>>>>>> @@ -1883,27 +1900,12 @@ static int iommu_bus_init(struct >>>>>>>>> bus_type *bus) >>>>>>>>>    */ >>>>>>>>>   int bus_set_iommu(struct bus_type *bus, const struct >>>>>>>>> iommu_ops *ops) >>>>>>>>>   { >>>>>>>>> -    int err; >>>>>>>>> - >>>>>>>>> -    if (ops == NULL) { >>>>>>>>> -        bus->iommu_ops = NULL; >>>>>>>>> -        return 0; >>>>>>>>> -    } >>>>>>>>> - >>>>>>>>> -    if (bus->iommu_ops != NULL) >>>>>>>>> +    if (bus->iommu_ops && ops && bus->iommu_ops != ops) >>>>>>>>>           return -EBUSY; >>>>>>>>>       bus->iommu_ops = ops; >>>>>>>> >>>>>>>> Do we still need to keep above lines in bus_set_iommu()? >>>>>>> >>>>>>> It preserves the existing behaviour until each callsite and its >>>>>>> associated error handling are removed later on, which seems like >>>>>>> as good a thing to do as any. Since I'm already relaxing >>>>>>> iommu_device_register() to a warn-but-continue behaviour while it >>>>>>> keeps the bus ops on life-support internally, I figured not >>>>>>> changing too much at once would make it easier to bisect any >>>>>>> potential issues arising from this first step. >>>>>> >>>>>> Fair enough. Thank you for the explanation. >>>>>> >>>>>> Do you have a public tree that I could pull these patches and try >>>>>> them >>>>>> on an Intel hardware? Or perhaps you have done this? I like the whole >>>>>> idea of this series, but it's better to try it with a real hardware. >>>>> >>>>> I haven't bothered with separate branches since there's so many >>>>> different pieces in-flight, but my complete (unstable) development >>>>> branch can be found here: >>>>> >>>>> https://gitlab.arm.com/linux-arm/linux-rm/-/commits/iommu/bus >>>>> >>>>> For now I'd recommend winding the head back to "iommu: Clean up >>>>> bus_set_iommu()" for testing - some of the patches above that have >>>>> already been posted and picked up by their respective subsystems, >>>>> but others are incomplete and barely compile-tested. I'll probably >>>>> rearrange it later this week to better reflect what's happened so far. >>>> >>>> I wound the head back to "iommu: Clean up bus_set_iommu" and tested it >>>> on an Intel machine. It got stuck during boot. This test was on a >>>> remote >>>> machine and I have no means to access it physically. So I can't get any >>>> kernel debugging messages. (I have to work from home these days. :-() >>>> >>>> I guess it's due to the fact that intel_iommu_probe_device() callback >>>> only works for the pci devices. The issue occurs when probing a device >>>> other than a PCI one. >>> >>> Yeah, I was wondering if that would be significant, since it's the >>> only driver that never registered itself for platform_bus_type so >>> won't have actually seen those calls before. I'm inclined to bodge >>> that as below for now, as long as it then works OK in terms of the >>> rest of the changes. >>> >>> Thanks, >>> Robin. >>> >>> ----->8----- >>> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c >>> index 9fa1b98186a3..6e359f92ec00 100644 >>> --- a/drivers/iommu/intel/iommu.c >>> +++ b/drivers/iommu/intel/iommu.c >>> @@ -4565,6 +4565,10 @@ static struct iommu_device >>> *intel_iommu_probe_device(struct device *dev) >>>       unsigned long flags; >>>       u8 bus, devfn; >>> >>> +    /* ANDD platform device support needs fixing */ >>> +    if (!pdev) >>> +        return ERR_PTR(-ENODEV); >>> + >>>       iommu = device_to_iommu(dev, &bus, &devfn); >>>       if (!iommu) >>>           return ERR_PTR(-ENODEV); >> >> I haven't seen any real ANDD platform devices, hence this works for me. > > Or more precisely, return NULL when @dev goes through device_to_iommu()? > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > index df5c62ecf942..0d447739e076 100644 > --- a/drivers/iommu/intel/iommu.c > +++ b/drivers/iommu/intel/iommu.c > @@ -797,8 +797,11 @@ struct intel_iommu *device_to_iommu(struct device > *dev, u8 *bus, u8 *devfn) >                 pf_pdev = pci_physfn(pdev); >                 dev = &pf_pdev->dev; >                 segment = pci_domain_nr(pdev->bus); > -       } else if (has_acpi_companion(dev)) > +       } else if (has_acpi_companion(dev)) { >                 dev = &ACPI_COMPANION(dev)->dev; > +       } else { > +               return NULL; > +       } > >         rcu_read_lock(); >         for_each_iommu(iommu, drhd) { Robin, please ignore this. "has_acpi_companion(dev)" isn't equal to an ANDD device. Please use yours. Sorry for the noise. Best regards, baolu