Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp253102ybe; Wed, 4 Sep 2019 19:18:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqw3sWV1PaxSBQj52CvMv53CxYakzada71/PCcnSONaRx6Vd5AnDgEgTU0EhE7xNGS9GS6lK X-Received: by 2002:a63:ed55:: with SMTP id m21mr985791pgk.343.1567649906168; Wed, 04 Sep 2019 19:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567649906; cv=none; d=google.com; s=arc-20160816; b=WntHTZuydT20txo0ZS5hJrEmkiHtYukjHilXNU1UCaVh8oFirEOTFEnBzM1vESLrYs bo6nYLrS/6izmMDPMGbFZRkEjnbsQ3arfQLw6yznTQeTjSe0FnTcu1JuUtvi7FTSMv2v cfU7mDDmNmbHP1POnXSpi4cnj7K4BXpobHlAmdQBeL0nvaCz+W/qVb0eiyvjuHeC1FvB bt1vVlgsy+FM9iAOuoFUTgIeYgIjmF+yfZPC0aQV8znvLZGbZSydUc3aDh5kT5fWTqwc 8C2/X9WqM8p3FNsVQplWfu7cAAlv2SPwxOOUKm/Pzi/AE05tzWqkVlUGnWKWv6HyEaml /zew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=gtBbVu2YuRjZxQMG+WWVEf96/N7afgxfmZK4Z/+uFWI=; b=JjlHraJS01das/+dItSjxRb1br55LvXGpYul9VQlMzHG5WGxZhmCQpQ8vrn86y2DQ6 LVVuANUFFjXjK9wIedVB90/nX91ebaJdq72cKT9gOo0Pz/h8ok7xlP4IBokPC4b6siol //4qjhScmMAKsY9jfrM7vFvqqZyvPXhsjTHwsq1NCKQyiBcl5lFf31g2XJlUMwvSh0Vf acgG1CW4Q3+pVmen/mvISRoXhYe3YLig7P/I1u6S15gVGVBmhrk8slMRYe35OGPHAP7V g9qIc9DkaRHFPEyFzTLwg0+iVuHtTQkEqPKgx3EdmW9a6Fs3eRPbb1v6gFzG96pIHn1o Jovw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="BDk/GviO"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t35si447152pgm.8.2019.09.04.19.18.10; Wed, 04 Sep 2019 19:18:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="BDk/GviO"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730707AbfIECAa (ORCPT + 99 others); Wed, 4 Sep 2019 22:00:30 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:35152 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730219AbfIECA3 (ORCPT ); Wed, 4 Sep 2019 22:00:29 -0400 Received: by mail-vs1-f66.google.com with SMTP id b11so470229vsq.2 for ; Wed, 04 Sep 2019 19:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gtBbVu2YuRjZxQMG+WWVEf96/N7afgxfmZK4Z/+uFWI=; b=BDk/GviOuG+apQ6Q/QhHTj1xqYrRLRJ/U+Vl5q95c5rnTaFT0q9vnD0FlSm+FhOZMu fT3dBm8RjTrA4gE8Cd+3Pq/OuU0LqZqI5fGoyijCmEo1OJ9YH4GJGxcVEf8Hf37u+BD3 JKtzoiTPyiQgXrUzG0AlNoYIgK56qBaMpOsakxiGkp99hGkduJGX4MlrhOmNoYzbtrzt myehfK5bh1Iz/GmYMogUXHiUhsPrJtTsuQaCcfnCGQ6ZxdIzSgf92h3Kbr14WQSM8GyK Y7yXbjI3ABUK3pplcWrvaGBY9jw2ZJkaI2Bqq6xyydd6jTSm9wxtlqXVMKEFOjexq/FK klIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gtBbVu2YuRjZxQMG+WWVEf96/N7afgxfmZK4Z/+uFWI=; b=dUjEqIyKs50EGIOBtVr9e85kHBr+qls9aHD5IM0XYMnntgD91ODbNdLPG0GPiyAB5d QOivErfakPmPRlNNa3EWyFIhe0iXXvcIkdYxqgl/9wWuERySXb4OL3Fx3fC1sMFeVr9O llVjWPndXmmW0YU4Fc+pblXM7xwhuIOsRle2ihSBBpu59Qgf6BtAQwLRmQ7zPmiH2Liv UGvU2T+LBcVX30OhXMBE3VeqDa0ZIhKONbhR30A5n2bQpQL9Sv9h+eaMBetj1JOMc/Pv NECCymIYsh3oJyrVBUJ92xNt/BiMClq2R8IFLpOmO2aFz40B9VZyaTAhxXZ0lCMt6hg8 RuKA== X-Gm-Message-State: APjAAAW4rgA0DRZ3aIJ7Tz8dqkNXLNVC1/XDFYikXRpEU6+J/bpXyqgb yWOA55WjwURFnvmo56HXUrVhtRrOK76VpoiYQ2+5bQ== X-Received: by 2002:a67:3147:: with SMTP id x68mr509652vsx.29.1567648828184; Wed, 04 Sep 2019 19:00:28 -0700 (PDT) MIME-Version: 1.0 References: <20190813224620.31005-1-dave@stgolabs.net> <20190813224620.31005-2-dave@stgolabs.net> <20190821215707.GA99147@google.com> <20190822044936.qusm5zgjdf6n5fds@linux-r8p5> <20190822181701.zhfdkjbwjh56i3ax@linux-r8p5> <20190905005234.vse4pm4mw7bogcbp@linux-r8p5> In-Reply-To: <20190905005234.vse4pm4mw7bogcbp@linux-r8p5> From: Michel Lespinasse Date: Wed, 4 Sep 2019 19:00:13 -0700 Message-ID: Subject: Re: [PATCH 1/3] x86,mm/pat: Use generic interval trees To: Davidlohr Bueso Cc: Ingo Molnar , Thomas Gleixner , Peter Zijlstra , Andrew Morton , x86@kernel.org, LKML , Davidlohr Bueso Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Davidlohr, On Wed, Sep 4, 2019 at 5:52 PM Davidlohr Bueso wrote: > Ok, so for that I've added the following helper which will make the > conversion a bit more straightforward: > > #define vma_interval_tree_foreach_stab(vma, root, start) > vma_interval_tree_foreach(vma, root, start, start) Yes, that should help with the conversion :) > I think this also makes sense as it documents the nature of the lookup. > > Now for the interval-tree conversion to [a,b[ , how does the following > look to you? Note that this should be the end result; we can discuss > how to get there later, but I wanna make sure that it was more or less > what you were picturing. I do not have time for a full review right now, but I did have a quick pass at it and it does seem to match the direction I'd like this to take. Please let me know if you'd like me to do a full review of this, or if it'll be easier to do it on the individual steps once this gets broken up. BTW are you going to plumbers ? I am and I would love to talk to you there, about this and about MM range locking, too. Things I noticed in my quick pass: > diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c > index e0ad547786e8..dc9fad8ea84a 100644 > --- a/drivers/gpu/drm/radeon/radeon_vm.c > +++ b/drivers/gpu/drm/radeon/radeon_vm.c > @@ -450,13 +450,14 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev, > { > uint64_t size = radeon_bo_size(bo_va->bo); > struct radeon_vm *vm = bo_va->vm; > - unsigned last_pfn, pt_idx; > + unsigned pt_idx; > uint64_t eoffset; > int r; > > if (soffset) { > + unsigned last_pfn; > /* make sure object fit at this offset */ > - eoffset = soffset + size - 1; > + eoffset = soffset + size; > if (soffset >= eoffset) { Should probably be if (soffset > eoffset) now (just checking for arithmetic overflow). > r = -EINVAL; > goto error_unreserve; > @@ -471,7 +472,7 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev, > } > > } else { > - eoffset = last_pfn = 0; > + eoffset = 1; /* interval trees are [a,b[ */ Looks highly suspicious to me, and doesn't jive with the eoffset /= RADEON_GPU_PAGE_SIZE below. I did not look deep enough into this to figure out what would be correct though. > } > > mutex_lock(&vm->mutex); > diff --git a/drivers/infiniband/hw/hfi1/mmu_rb.c b/drivers/infiniband/hw/hfi1/mmu_rb.c > index 14d2a90964c3..d708c45bfabf 100644 > --- a/drivers/infiniband/hw/hfi1/mmu_rb.c > +++ b/drivers/infiniband/hw/hfi1/mmu_rb.c > @@ -195,13 +195,13 @@ static struct mmu_rb_node *__mmu_rb_search(struct mmu_rb_handler *handler, > trace_hfi1_mmu_rb_search(addr, len); > if (!handler->ops->filter) { > node = __mmu_int_rb_iter_first(&handler->root, addr, > - (addr + len) - 1); > + (addr + len)); > } else { > for (node = __mmu_int_rb_iter_first(&handler->root, addr, > - (addr + len) - 1); > + (addr + len)); > node; > node = __mmu_int_rb_iter_next(node, addr, > - (addr + len) - 1)) { > + (addr + len))) { > if (handler->ops->filter(node, addr, len)) > return node; > } Weird unnecessary parentheses through this block. > @@ -787,7 +787,7 @@ static phys_addr_t viommu_iova_to_phys(struct iommu_domain *domain, > struct viommu_domain *vdomain = to_viommu_domain(domain); > > spin_lock_irqsave(&vdomain->mappings_lock, flags); > - node = interval_tree_iter_first(&vdomain->mappings, iova, iova); > + node = interval_tree_iter_first(&vdomain->mappings, iova, iova + 1); I was gonna suggest a stab iterator for the generic interval tree, but maybe not if it's only used here. > diff --git a/include/linux/interval_tree_generic.h b/include/linux/interval_tree_generic.h > index aaa8a0767aa3..e714e67ebdb5 100644 > --- a/include/linux/interval_tree_generic.h > +++ b/include/linux/interval_tree_generic.h > @@ -69,12 +69,12 @@ ITSTATIC void ITPREFIX ## _remove(ITSTRUCT *node, \ > } \ > \ > /* \ > - * Iterate over intervals intersecting [start;last] \ > + * Iterate over intervals intersecting [start;last[ \ Maybe I'm extra nitpicky, but I would suggest to use 'end' instead of 'last' when the intervals are half open: [start;end[ To me 'last' implies that it's in the interval, while 'end' doesn't imply anything (and thus the half open convention used through the kernel applies). similarly ITLAST should be changed to ITEND, etc and similarly in the various call sites (drm and others). Again, maybe it's nitpicky but I feel changing the name also helps verify that we don't leave behind any off-by-one use. That said, it's really only my preference - if you think it's too painful to change, that's OK. -- Michel "Walken" Lespinasse A program is never fully debugged until the last user dies.