From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (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 950873164C2 for ; Tue, 20 Jan 2026 16:44:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768927482; cv=none; b=L7cKIavY5aEzCAn4cI2R2Egq2AVLgXQGPIUYvQusA+e9ZtoAOLXfia89C788BxJv16UPWHuRIL/Bl0FFKgaOm4YX6gsAK9TemLGoTf8EZdq+y21ic8dWaGydjYkXkDihsGFaMlBe6PS+f2AQ9BofafYtNsyfgfhsiMsnxAXaqeo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768927482; c=relaxed/simple; bh=aUDhPKL0hM8JEgf53e07so1yz09QTsbUMmEPM++MMC4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dRC/FdlYBuPwhK5/rmYrKeudxsVkpjSkH+hTctZBQPEQjp2xMTo7snBD08gp5c8Np1MlXsLzQ/Dv4alRCfjMvp3bSFp9dmQUnqecR7nEdRSGuY/H7G/lHqQNdY5iXYjTImPZNGQQG/jksq1iGxntZzzGKFZfgUGaBRoVzRv/cV4= 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=enorTZHH; arc=none smtp.client-ip=209.85.222.170 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="enorTZHH" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-8c5265d06c3so650791485a.1 for ; Tue, 20 Jan 2026 08:44:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1768927479; x=1769532279; 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=byK9CbCzUXPvYH8hMBYCGjlZe3ysbsipoknrt4q5MYA=; b=enorTZHHb2rEovvaqsHlJudTAyqhy1O+b6Wb9hMirBr3bEDZcElB++EhFMTigB6DNN g/5LhzI3JIgnahlwdRTRt4XxSlT1UHF7t0P7XiGBm4w296ImJAO3juGTZH1hiWQsVERe Hs7hs0ESDrEo3XIH757I+XTnWNoN3QMlMOLXsKa110lwqqOJeojAC+9bzc15VrPQ9Bst Nt9II4GuZja6VvAjbE0pNFpsGIXcG9aQJqiii62oK/+nQ9dAMlXfPc5hhvkWEtaGDVXO IBiT40k7MZs4mDeMIIWqaqZ9CwpO/sYnK9wG52P5SoSVI89RnqLH2qCxElydmideAxh2 YGrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768927479; x=1769532279; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=byK9CbCzUXPvYH8hMBYCGjlZe3ysbsipoknrt4q5MYA=; b=rvyumj335ZBMlM05gW1S1sFdJDxFMvsafwt2ur/fFL2I85EBHXG5+TGIOMW3q7Yn/G B49et89vVk8jLC3GLlbbdtupNZ1IiTSw9n34YdpaPC/Cmdbp9mgdWUemeT1mh+mkHVz0 PYPFZbecbFoG2jz6MjH6wscEPKabrs/iUdv1258vN8XcsK9kK1/f7j2lbzlciX0nPRdk WCLQxXZcEppwfk0ntBHfPKccUgnqKKUxpG6JnOQuUeT09wppTVMWTAWKfX8WxkiyqzpT 18NZFTHDV16SnAG57ERctFOtHX0Dm40pVGrveVFJBmuhZtCcQIsEU/5Z6FuWpKDNVGVG VNmg== X-Forwarded-Encrypted: i=1; AJvYcCWZR+Y8fZo8Ec2CDHkfJ9BxG2srXQIJmH4XhutaHeXewOWeSiL4yHbmi1BtbXUWCpvI1Z7lMN4A0jjBuzg=@vger.kernel.org X-Gm-Message-State: AOJu0YyxThKOPs6kJzyiKMKb1HRKszkqFNcppswmCgoid0Y8dvJHN417 BKt7E59vLdFqhXKfrVy4I8TBR5yupYx0tlE9ewtfuP5Dy85avtZDm/gSGeR0Qs4dpBA= X-Gm-Gg: AY/fxX4HsC+XwCg1CvNTof/ewu4u2+15MwHYOuty+hJFhocHZ/G4qW/DIvWaiArQ3xa eyKczfX4qvhhAwhr1WkIbm1ECZabMmBfyEOyc1Vazk4E6gBzR6fritwnkFdtDaHgA3+KvhctWp+ NlZo1BuBqBEOy1L76Q7coOcsllCC8qG2uPQjbvoFkACbfriAPN2nNAhS6rPaqOaafHill2kRlo8 LLmVhhweVu9Mqm8FBpqSS07ao306ouG8uz36IdWP6REMjooWvX25xzeBlWUlBb/ENBqw92w4e9r FNuvrGl1vRW+1kZfqpxssqcsGgRU6hOGgLpQSvhdpiDmsrNnyaC/wHX6aZzNmPIP/5ZTDqii5Tn Yxg87Bu0hqxXcwQsWNJLKlEHiAQjGU9wF3YEfqP88R1G76hQYn6q4UIxjBYkZjkCs8mZ1wUEHFq vGercMH6gMhRCteSvPe1ZcKoaK+M9qLluv1WPAZzW5FJjkLPjaU/yT9cKSIurTpNInRaU= X-Received: by 2002:a05:620a:4011:b0:89f:cc73:386 with SMTP id af79cd13be357-8c6a6479374mr2212242085a.13.1768927479473; Tue, 20 Jan 2026 08:44:39 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8c6a72507d5sm1084693385a.32.2026.01.20.08.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jan 2026 08:44:38 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1viEqM-00000005YT2-14LN; Tue, 20 Jan 2026 12:44:38 -0400 Date: Tue, 20 Jan 2026 12:44:38 -0400 From: Jason Gunthorpe To: Edward Srouji Cc: Leon Romanovsky , Saeed Mahameed , Tariq Toukan , Mark Bloch , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, Michael Guralnik , Yishai Hadas Subject: Re: [PATCH rdma-next v2 02/11] IB/core: Introduce FRMR pools Message-ID: <20260120164438.GR961572@ziepe.ca> References: <20251222-frmr_pools-v2-0-f06a99caa538@nvidia.com> <20251222-frmr_pools-v2-2-f06a99caa538@nvidia.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: <20251222-frmr_pools-v2-2-f06a99caa538@nvidia.com> On Mon, Dec 22, 2025 at 02:40:37PM +0200, Edward Srouji wrote: > +static int compare_keys(struct ib_frmr_key *key1, struct ib_frmr_key *key2) > +{ > + int res; > + > + res = key1->ats - key2->ats; > + if (res) > + return res; > + > + res = key1->access_flags - key2->access_flags; > + if (res) > + return res; > + > + res = key1->vendor_key - key2->vendor_key; > + if (res) > + return res; > + > + res = key1->kernel_vendor_key - key2->kernel_vendor_key; > + if (res) > + return res; This stuff should be using cmp_int(). > +static struct ib_frmr_pool *ib_frmr_pool_find(struct ib_frmr_pools *pools, > + struct ib_frmr_key *key) > +{ > + struct rb_node *node = pools->rb_root.rb_node; > + struct ib_frmr_pool *pool; > + int cmp; > + > + /* find operation is done under read lock for performance reasons. > + * The case of threads failing to find the same pool and creating it > + * is handled by the create_frmr_pool function. > + */ > + read_lock(&pools->rb_lock); > + while (node) { > + pool = rb_entry(node, struct ib_frmr_pool, node); > + cmp = compare_keys(&pool->key, key); > + if (cmp < 0) { > + node = node->rb_right; > + } else if (cmp > 0) { > + node = node->rb_left; > + } else { > + read_unlock(&pools->rb_lock); > + return pool; > + } Use the rb_find() helper > +static struct ib_frmr_pool *create_frmr_pool(struct ib_device *device, > + struct ib_frmr_key *key) > +{ > + struct rb_node **new = &device->frmr_pools->rb_root.rb_node, > + *parent = NULL; > + struct ib_frmr_pools *pools = device->frmr_pools; > + struct ib_frmr_pool *pool; > + int cmp; > + > + pool = kzalloc(sizeof(*pool), GFP_KERNEL); > + if (!pool) > + return ERR_PTR(-ENOMEM); > + > + memcpy(&pool->key, key, sizeof(*key)); > + INIT_LIST_HEAD(&pool->queue.pages_list); > + spin_lock_init(&pool->lock); > + > + write_lock(&pools->rb_lock); > + while (*new) { > + parent = *new; > + cmp = compare_keys( > + &rb_entry(parent, struct ib_frmr_pool, node)->key, key); > + if (cmp < 0) > + new = &((*new)->rb_left); > + else > + new = &((*new)->rb_right); > + /* If a different thread has already created the pool, return > + * it. The insert operation is done under the write lock so we > + * are sure that the pool is not inserted twice. > + */ > + if (cmp == 0) { > + write_unlock(&pools->rb_lock); > + kfree(pool); > + return rb_entry(parent, struct ib_frmr_pool, node); > + } > + } > + > + rb_link_node(&pool->node, parent, new); I think this is rb_find_add() ? Jason