Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp614206rdb; Thu, 15 Feb 2024 09:48:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVbmqIQ/nZ7vjx+2WCzoh0Bi9MEl3iePRh5TufcNOGX/W7YVIb9l+sIR7RcWeOeNC2lMq8C+4UQ0UzIUv9WW+4Nj4JpBxFDbznw8FWwDQ== X-Google-Smtp-Source: AGHT+IGrkEfDztAoak4lpC3YM+PSBDuBpq0xnAI2s5E0Om54bvTroxN5XlV6Zmo390U8gi2dHSFD X-Received: by 2002:a05:620a:9c2:b0:787:28bb:c804 with SMTP id y2-20020a05620a09c200b0078728bbc804mr9457050qky.2.1708019297960; Thu, 15 Feb 2024 09:48:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708019297; cv=pass; d=google.com; s=arc-20160816; b=Sg6kCO04Z5ItYqqRx4+LGnMaLlAWp+3wTH4GgjYEO/5Yz7BIb1mwrHVCGrF1NmTBoU H8Ciq2NdKGpgLc7BfzjnYqNKYIvC3DV241ouFDIIdibm6HeXWt4AGKBJpPGkdnDVZvxv ew4fqWSN0kHSsUBtomJsFON+Q0zIssKqtWMYe2FZ0HCJ8wSErocxQkJc+aaFn6bogSOO Rr6qk8/3322p2OXgoeGw37Tqd0uikP5H3icMpW3CisCt9CHEy3tVExqAd9tFavMRd11n +QPZ8S8l3H2MWP6t55sPL4YDg0oRCy8sNVRxm3QmvQkaaDuqtyfpbXKpVODOym0/91Jx uaFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gwxKYOTTfsVxRUkOMJlptUV0ZFZUoBorwA6GkU+MTmM=; fh=4R5ARkya9dUnf1+AYtzEwsTSToAn4OySynNF7VNUG/s=; b=gqH9aO1c4pehFfPLfDHsoCwl462ec/KvqI6YW2e3fFIq5FhHVVsBK5W+wMlMQgT8+d OtYLg+OD9kX0yxRI0OGwhpa6C1PaFnBIL1cy06L5kVyHid3TeuGEYM8A3/PeZUojQEi3 s+Mhl/LjDUx2oxCGGO2v4XcewVZEYZ6xRNLD7htYTvttWq5X8DSX/NY7TUuvCdLcbHOu SO5XJvkvWMnQlU3VWKflatkohLPL3TOGutcnxbQBKbDGD+egR2oED7CT2x3w0mDXH7aX 6NHReo4SUTb915PENDY1Yxt8Sej/m6uNMz0umrXoMVmuOhdNLmNytVh8vAtn0l6Yl7C7 2SHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=N6MkM24f; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-67435-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67435-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z21-20020a05620a101500b007858a85f87asi1845668qkj.569.2024.02.15.09.48.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 09:48:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67435-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=N6MkM24f; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-67435-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67435-linux.lists.archive=gmail.com@vger.kernel.org" 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B2A8A1C23654 for ; Thu, 15 Feb 2024 17:48:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0B601386D1; Thu, 15 Feb 2024 17:47:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="N6MkM24f" Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 2CED41386C5 for ; Thu, 15 Feb 2024 17:47:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708019232; cv=none; b=hw2irPFAUKczz5cdUsCW/1dqHphqImxFFBcEnqhxZndB6FuOrMfVl58xgAWC7aGJK9j1leGjYJjr2PEHc1tZ1HcFVozy0xOgRlzVPM5X8xOOQ7KiCWcKYad6I3WoPXDfIUHG0fPHYkxI2skZ6k978Bs6YwRUEwKhi0lFkOODFmk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708019232; c=relaxed/simple; bh=+dXm83v4lzGGGWoMkrAhpsoKvqPYYTZkbg+SCOnXjxY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=e6pGrOBdLy+L7Zt0tADy7UGkQ34UgFCF3amxEtCMs6gK/I0KyHzUT9SWYxs2e7JlKVbp3VLihOcZ0aotJ+1AugEgkf9DHt5PpZO5paUjIvCm0K8bJUhbUlzoLiuTZONHUq5eja+gpP7qrwK53IgIhWiWKE/JZDBtkJy0gR15VR0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=N6MkM24f; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-783f553fdabso75486685a.0 for ; Thu, 15 Feb 2024 09:47:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1708019230; x=1708624030; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=gwxKYOTTfsVxRUkOMJlptUV0ZFZUoBorwA6GkU+MTmM=; b=N6MkM24fIlXRxa3OTszGz5z1eTHNELNLwud5JwW4/R8XpbeAdBp1Ur/9uU97Dy2W7D +amqpJWJrvWf8SaDTy/0VUPYz+eWv0tG0DlA67QC0LxOeBjzgVAoWD1U24JvrluLtI1X H9f8k0Bhb/fF0tsfInxHFANscZzf+w4GfgKJgfME9NYy4bPRDZ8NfKC4+fgraqNhHrgS tRCTej7KduBp51W4F1tNThAUpEduFCcxBtUnQfgZ2EqT2gPXqJCJ12yIJwTDAZzNscHt KlJdCAbUofoMgmHnUFt3rZIaXR/ZzYPs8K8+GFrWK6Has6zZNqNkPxgdpcCUPqZBYsU0 LrOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708019230; x=1708624030; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gwxKYOTTfsVxRUkOMJlptUV0ZFZUoBorwA6GkU+MTmM=; b=rawvDZLvCheAwst5L1BOXz2fkJO+rMtL/PsgbmrJovuOetcdF3M396eCvL+31kFra6 7mrqg9bjNxF4rZqacdrsLLaxtoAAvfrwDVvuWx1cx3VQKgQclr8124ZuZWkSPsso6gCT +FKGvzqE1QGzAeBiCOBhU3L3OzNBGt+YiEWripa5khprg0mRrdYSsxCrBuVqnlzauUxa cVRDCaGHB0rbVCeMrFh1TH1L/99OfXHXbOzE93PRL5xykTy0zA8A3Hlc2xyeYVy0ERK5 qiVk73xkn0sPcmVtXJQo94sOqAO4dp6uCD2COa4naTj2Gzfm1+e8HAuJh+RqHkCOBPT3 rtQg== X-Forwarded-Encrypted: i=1; AJvYcCUk0Z4SSOrOLJ2GB/Nabsb+7XM3Asc0IKRDFLsrEDejql+esBIrTHRH9S0GANuNLTXbdCBmy2L2m1TLzxOP9VsP0t2woB2SAsXvxECv X-Gm-Message-State: AOJu0YxdZhcBupkG4odQ039DLIj6lFQYlOJSGpbIjNn8g1oJB7Zi1riP 9H5VFy1U9eCcfXN7kIKvUnrNnL052O/S/XCLsMDcMzjhkdZmcC37nnpnOyVAz2Y= X-Received: by 2002:a05:620a:372a:b0:787:2d4a:e91 with SMTP id de42-20020a05620a372a00b007872d4a0e91mr9362184qkb.12.1708019229933; Thu, 15 Feb 2024 09:47:09 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-68-80-239.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.80.239]) by smtp.gmail.com with ESMTPSA id bj27-20020a05620a191b00b007873df5a625sm182249qkb.97.2024.02.15.09.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 09:47:09 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1rafpE-001DT3-Rz; Thu, 15 Feb 2024 13:47:08 -0400 Date: Thu, 15 Feb 2024 13:47:08 -0400 From: Jason Gunthorpe To: Lu Baolu Cc: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Huang Jiaqing , Ethan Zhao , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] iommu/vt-d: Use rbtree to track iommu probed devices Message-ID: <20240215174708.GC1299735@ziepe.ca> References: <20240215072249.4465-1-baolu.lu@linux.intel.com> <20240215072249.4465-2-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240215072249.4465-2-baolu.lu@linux.intel.com> On Thu, Feb 15, 2024 at 03:22:48PM +0800, Lu Baolu wrote: > Use a red-black tree(rbtree) to track devices probed by the driver's > probe_device callback. These devices need to be looked up quickly by > a source ID when the hardware reports a fault, either recoverable or > unrecoverable. > > Fault reporting paths are critical. Searching a list in this scenario > is inefficient, with an algorithm complexity of O(n). An rbtree is a > self-balancing binary search tree, offering an average search time > complexity of O(log(n)). This significant performance improvement > makes rbtrees a better choice. > > Furthermore, rbtrees are implemented on a per-iommu basis, eliminating > the need for global searches and further enhancing efficiency in > critical fault paths. The rbtree is protected by a spin lock with > interrupts disabled to ensure thread-safe access even within interrupt > contexts. > > Co-developed-by: Huang Jiaqing > Signed-off-by: Huang Jiaqing > Signed-off-by: Lu Baolu > --- > drivers/iommu/intel/iommu.h | 7 +++++ > drivers/iommu/intel/dmar.c | 3 +- > drivers/iommu/intel/iommu.c | 62 +++++++++++++++++++++++++++++++++++-- > 3 files changed, 69 insertions(+), 3 deletions(-) Reviewed-by: Jason Gunthorpe > +static int device_rbtree_insert(struct intel_iommu *iommu, > + struct device_domain_info *info) > +{ > + struct rb_node *curr; > + unsigned long flags; > + > + spin_lock_irqsave(&iommu->device_rbtree_lock, flags); > + curr = rb_find_add(&info->node, &iommu->device_rbtree, device_rid_cmp); > + spin_unlock_irqrestore(&iommu->device_rbtree_lock, flags); > + if (curr) > + dev_warn(info->dev, "device already in rbtree\n"); I would suggest WARN_ON(curr); Something has gone really wonky at this point, right? Jason