Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1077098rdb; Mon, 19 Feb 2024 03:41:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUFyJ8n5n6fnUwvsMC6LZKHGcycCvuLHRUKyyoJzkSpKetRVgNorNowCl+HaeKAFp102ObG7VhPVruWPaNtWdJgtimq7j4cYHuVGMla5A== X-Google-Smtp-Source: AGHT+IEQp48GYWgmlzX3Xr507LJyrY7ehQ8GhvpDjMNIZ67vohdM7+L694rxMOM7xGnV4Y0q/Pas X-Received: by 2002:aa7:8218:0:b0:6e1:dbc:d05f with SMTP id k24-20020aa78218000000b006e10dbcd05fmr9645377pfi.1.1708342883156; Mon, 19 Feb 2024 03:41:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708342883; cv=pass; d=google.com; s=arc-20160816; b=Z/B+U+8UHkpEajaIxPcPLwoZfm1q2i70kKT+dmzTTYUIKy6/M3JO9pN67UpXC/5VNh yyLTz3WxpGdJBwQcsl97nJqoepfT+yPwotm7nUQEFrPCmO19F6ilu66e8/Lm1FF2i2BB isJX/ywzq7LVi5xPMPx8LR7GPpu8ITr4htsudgyBMBNtGkdrmYhGWwAVAVht6wPH8dlq ExPH9tN+fiwk7Baz6TLqtX5Yr/ZzJOXXBXkURkGujR44aTiLemS1iED17SBHWWgdJHuD +U3aF7P3oPm6hI21q6iv9q1vQ18PFCYtB5c5NBwd2460hhifyrSZxacRys3kyz92ur/+ WwXw== 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:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=1lpuCjWji/WjXDqqTuOSq4K0sMBOyDEUdQO0LIW9DLA=; fh=cyfoo4W//NOyvKeyVK9iuOt6pjOJChoMzuTMP1/Cp5A=; b=EGxfbghwyX5kovEGk8Kv+qVOW6kPLwBCu86nPPrX36eclH+gtUW9ZfTC8SH4M4G3U3 bM3KFxlmOevCpsZeON3kv4nk51W6QUCDAX1hO42D4oOlHPPCL43+mC2uteueJzM4CnLd bJtmzoHOOW25rv26geUV6XqyaptvvsyBNEpK9bXv0ieQQWshxR+LpyPZ8KEA7+DhuUOA O2GWSjbPbAAEo2G2NXiYPBwhisKmX6IPTPvU3pw9sBTK2h7IBOO7D2pHX552x5nJfI0b J3laZ65O0jl18Yem5tjW25Z7PIhksn8l/+AbH2zQZrpMmu8IUjmefFLJGFeXRFlDD7uY K3sg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fZOWkR23; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-70823-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70823-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ck19-20020a056a02091300b005dbdc98c15csi4397239pgb.709.2024.02.19.03.41.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 03:41:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70823-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fZOWkR23; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-70823-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70823-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C35A9281017 for ; Mon, 19 Feb 2024 07:24:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A38ED20B37; Mon, 19 Feb 2024 07:24:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fZOWkR23" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5622120B04 for ; Mon, 19 Feb 2024 07:24:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708327482; cv=none; b=cwwoxF5EiegQXtbAUWJ2GDkjl122Lfa/PaH05vvlNSQDUqbVV3BiTWP7T8NKuG2+mFJLTxGZJBCy59PCswAEP4G+MOEiYbY9+GmXrU/vwCF1JiiE9W//vUgf6wD6mMnnwjBTfSlZz0BZmq+Q759KsbfCJt+/DIGKeJUs9DFpsdA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708327482; c=relaxed/simple; bh=Y5OgD0gzlaPjteSizS3leXdfZRmgjidV4tkL6TXn8LA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=pMQT7MD+a13ZgkhY0Utd27meS2XejN18z1XRukRuv805fLiq/YyL2CqjSHV2pY+B1ygsFNJXv/+Bhyx4VIlru/xLAVc25kBt/7PBbEPQUPGMdY6mT39RXQSSTyj7oGmRaWqWeAxfaiQAPrziU4eOWkneoMLzi907MUcCjXw7YAk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=fZOWkR23; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708327481; x=1739863481; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=Y5OgD0gzlaPjteSizS3leXdfZRmgjidV4tkL6TXn8LA=; b=fZOWkR23WGjy5ySclCvAzQNGZ1rx3vMpCHIrLNyCSBQVlQqxMrQHOW6l pgK2+9QNsgjOCY/ZrY/5hm8ZR7oBJ8ngTxYbFV/FU3BtEtdZ2Rxd5uPa2 bkE0ArLXaDnuxDPn3z2sLMwjZ126H8JaYbT2Ov31iPswt62b34TNCSiNC DSvxn/1zx9EMxkiHe/tCwQ29ibG32PmJRvzgrKlTvEC0SsS/GliSa1rue tkwQHJpOyitUYt4WX96W+QKw3OYgH2JbsESxw7uFeBJDVQ/aveY2Jcnzc YbvQ9ZCs7RnyjpWmt3DfBbisg1U1yuBdJmQnj+GYWG2fZL76kUwGJwfvA g==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="19821119" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="19821119" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2024 23:24:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="9021525" Received: from zhaohaif-mobl.ccr.corp.intel.com (HELO [10.254.209.179]) ([10.254.209.179]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2024 23:24:38 -0800 Message-ID: Date: Mon, 19 Feb 2024 15:24:35 +0800 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: [PATCH 1/2] iommu/vt-d: Use rbtree to track iommu probed devices To: Baolu Lu , Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Huang Jiaqing , iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <20240215072249.4465-1-baolu.lu@linux.intel.com> <20240215072249.4465-2-baolu.lu@linux.intel.com> <942dd645-7475-4c43-99c6-304601fb09eb@linux.intel.com> <11a2a48f-aad9-42b0-a9a1-29ea1c0f7f45@linux.intel.com> From: Ethan Zhao In-Reply-To: <11a2a48f-aad9-42b0-a9a1-29ea1c0f7f45@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2/19/2024 2:47 PM, Baolu Lu wrote: > On 2024/2/19 13:33, Ethan Zhao wrote: >> On 2/19/2024 12:04 PM, Baolu Lu wrote: >>> On 2024/2/19 10:45, Ethan Zhao wrote: >>>>> @@ -4264,25 +4313,34 @@ static struct iommu_device >>>>> *intel_iommu_probe_device(struct device *dev) >>>>>       } >>>>>       dev_iommu_priv_set(dev, info); >>>>> +    ret = device_rbtree_insert(iommu, info); >>>>> +    if (ret) >>>>> +        goto free; >>>>>       if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) { >>>>>           ret = intel_pasid_alloc_table(dev); >>>>>           if (ret) { >>>>>               dev_err(dev, "PASID table allocation failed\n"); >>>>> -            kfree(info); >>>>> -            return ERR_PTR(ret); >>>>> +            goto clear_rbtree; >>>>>           } >>>>>       } >>>>>       intel_iommu_debugfs_create_dev(info); >>>>>       return &iommu->iommu; >>>>> +clear_rbtree: >>>>> +    device_rbtree_remove(info); >>>>> +free: >>>>> +    kfree(info); >>>>> + >>>>> +    return ERR_PTR(ret); >>>>>   } >>>>>   static void intel_iommu_release_device(struct device *dev) >>>>>   { >>>>>       struct device_domain_info *info = dev_iommu_priv_get(dev); >>>>> +    device_rbtree_remove(info); >>>> >>>> Perhpas too early here to remove dev from the rbtree, if it is >>>> wanted in >>>> devTLB invalidation steps in intel_pasid_tear_down_entry(). >>> >>> Perhaps the caller of device_rbtree_find() should not depend on the >> >> I didn't catch up here. seems have to maintain the lifecycle as PCI >> subsystem >> does, or there would be mutli instances for the same BDF(e.g. the >> device is >> removed then plugged, again and again.....in the same slot) in the >> rbtree ? > > There should not be multiple instances for a same BDF. The lifecycle of > a device is managed by the device and driver core. The iommu subsystem > registers a notification to the core and take actions on device ADD and > REMOVE events. Move device_rbtree_remove(info) to end of this REMOVED notifier callback, or such beautiful code wouldn't work :) struct device *dev = device_rbtree_find(iommu, ite_sid); if (!dev || !pci_device_is_present(to_pci_dev(dev)))   return -ETIMEDOUT; Thanks, Ethan > > Best regards, > baolu >