Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp964094ybt; Fri, 10 Jul 2020 17:50:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPJQUjy3rxc7OvmBoDPW6YCgMJ2FDTD1SJlkMawZvgAYPeqX5SCYDbO6SB6KcAv8m6xnml X-Received: by 2002:a17:906:364a:: with SMTP id r10mr62537424ejb.122.1594428631803; Fri, 10 Jul 2020 17:50:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594428631; cv=none; d=google.com; s=arc-20160816; b=MrR2vRrYn7jwGcRLviUsCJgg6pUkPVJoyp5i6Cy6yOPJNYVkd9CP9mvAKawPIeqypY FMF2WV5bqHWZr/TsE+5NT/JGnFug2VcLLnzJ9VioiW3TvsTmO7T0X8JfMOeV+L57T2wM JuB2p20Uw0lqMlLTmPMRAzVQM1Y4rGzyWshfpEbvvDosVje5KEwWWflJdYxIlY81jZbz Eq3iu/thLFrGGeBhxA1Zi2qWPqRsqQ0wHcSbhFqjTPEq5r/eXNXEGIji4CesVudk7gjp nrAQofFOrKFmXX3z6KvVHN0ZMh8u495IJCwFXyeg5Jz9FdzAEIIekpUYb96ra/WSh3ZW IWOA== 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=st0YQO+9N+wj1Bpy5FgTMDvwfrDYYhxnz84DaeIYHvE=; b=qvFyYmIBWTjZRmzNMJtu19TCSkgHdVQ0DXJlNGEUis75P/ZfO/yvY+GTv3dGGakNQz +doHnEJZ59Xx3pMfXquU9XghFpkYo8nx+bsOpiyHvyeu/EBW0DEMuIKRhQsubhKJ0XXO J7dtTXZ4gmumT9G4vJVNxOJyS/WCj1tPd8k1I3KQap7e9zCeYu1w+dcVUQrOESwFn0Ha ZnkjXFbacSxuJ6/L8wjBiQ2BKTtHMsdUYra+igtIx7BaaJTxa5Uek1G7abp5aUX+HAkV QMUoIMVNdh/BVo1a/jLAiQ0OKArPd/vzNawo1oCaKRolCS7yGISUVIRTQCQs/5HT+bq3 YHZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b="kf/GijOp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w1si4864347ejv.375.2020.07.10.17.50.07; Fri, 10 Jul 2020 17:50:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b="kf/GijOp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbgGKAra (ORCPT + 99 others); Fri, 10 Jul 2020 20:47:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726588AbgGKAr3 (ORCPT ); Fri, 10 Jul 2020 20:47:29 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B896C08C5DC for ; Fri, 10 Jul 2020 17:47:29 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id dp18so7854460ejc.8 for ; Fri, 10 Jul 2020 17:47:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=st0YQO+9N+wj1Bpy5FgTMDvwfrDYYhxnz84DaeIYHvE=; b=kf/GijOp8+5lWxfksRaWtI/aKDLLu2C+Ep5A8Zd+Wwap17OxVtPlB7kKxMuBYdHZ56 1vq9LulHSmENIqlaXFPDdeH3UxCrk9JfnP1zJseaq4tgF0iV2i6jHck+Oee77DpfLhhz uZ0ZXokKtNSLsjNyx7s6Ry4SbImB82FRvLQyPfU19WFTXKXoLn7Eie/0jEOrSJDsTrFt JnXSoWvT2Kr6IRlk63GWt7W3tLbbsto2BkLE/yDmuKjWIPgJ70M6DQWmLafIsc26e/1c VcSMX3uadaPJpPekovYYiousunCLedzS6bZB65zkyg2Sc6aaWdrgHMiIlLhv81TdM7bL oW2w== 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=st0YQO+9N+wj1Bpy5FgTMDvwfrDYYhxnz84DaeIYHvE=; b=B2KZ1AzjAft2CHTA9ikk8FM8Kjd6g1AtjtDKt2zKRbFUzTawZ1lWTH83BWPDkC+G3p B3K42Eb6Q2NRXgyPSriTimVOoEj4zKaTTfEDbPN/jwedNOaR8AfgiWNGRIU8gg3PHUsX KtuqT2s8ACDWL+O9z9iAAXjSmG/MT6PnCYnOtgYYja6uL1p4tsmTXfdS5UZjmsgHx2Fo 2mZ1kwm58F7MyMB4rhTWfgxjgml81J+kPL/YbAYqI1ZL8b9H88KNAtkqx83ilkdIanGj ZgF7rTErZvYwd8+FuEfGolMh0zyhmsXj5558JLf3Q3TWt8XacdU4YfdUh3qZN9lSLpao Vutw== X-Gm-Message-State: AOAM530XQjVsnkBxZ5Yr6ebome/ijpZ4gdv8DLuERlCXQy3dbIwLLtZ0 lt4qotCM+bwunflWliC7ruOBe7MVs3oXfu1rKg6GQHIi X-Received: by 2002:a17:907:20af:: with SMTP id pw15mr66148379ejb.204.1594428447936; Fri, 10 Jul 2020 17:47:27 -0700 (PDT) MIME-Version: 1.0 References: <158500767138.2088294.17131646259803932461.stgit@dwillia2-desk3.amr.corp.intel.com> <158500773552.2088294.8756587190550753100.stgit@dwillia2-desk3.amr.corp.intel.com> <23742bb8-831f-29ff-1463-75427eec57c7@oracle.com> In-Reply-To: From: Dan Williams Date: Fri, 10 Jul 2020 17:47:17 -0700 Message-ID: Subject: Re: [PATCH 11/12] device-dax: Add dis-contiguous resource support To: Joao Martins Cc: Linux MM , Dave Hansen , Christoph Hellwig , linux-nvdimm , Linux Kernel Mailing List 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 On Mon, Apr 6, 2020 at 1:22 PM Dan Williams wrote: > > On Mon, Apr 6, 2020 at 3:46 AM Joao Martins wrote: > > > > On 3/23/20 11:55 PM, Dan Williams wrote: > > > > [...] > > > > > static ssize_t dev_dax_resize(struct dax_region *dax_region, > > > struct dev_dax *dev_dax, resource_size_t size) > > > { > > > resource_size_t avail = dax_region_avail_size(dax_region), to_alloc; > > > - resource_size_t dev_size = range_len(&dev_dax->range); > > > + resource_size_t dev_size = dev_dax_size(dev_dax); > > > struct resource *region_res = &dax_region->res; > > > struct device *dev = &dev_dax->dev; > > > - const char *name = dev_name(dev); > > > struct resource *res, *first; > > > + resource_size_t alloc = 0; > > > + int rc; > > > > > > if (dev->driver) > > > return -EBUSY; > > > @@ -684,38 +766,47 @@ static ssize_t dev_dax_resize(struct dax_region *dax_region, > > > * allocating a new resource. > > > */ > > > first = region_res->child; > > > - if (!first) > > > - return __alloc_dev_dax_range(dev_dax, dax_region->res.start, > > > - to_alloc); > > > - for (res = first; to_alloc && res; res = res->sibling) { > > > +retry: > > > + rc = -ENOSPC; > > > + for (res = first; res; res = res->sibling) { > > > struct resource *next = res->sibling; > > > - resource_size_t free; > > > > > > /* space at the beginning of the region */ > > > - free = 0; > > > - if (res == first && res->start > dax_region->res.start) > > > - free = res->start - dax_region->res.start; > > > - if (free >= to_alloc && dev_size == 0) > > > - return __alloc_dev_dax_range(dev_dax, > > > - dax_region->res.start, to_alloc); > > > - > > > - free = 0; > > > + if (res == first && res->start > dax_region->res.start) { > > > + alloc = min(res->start - dax_region->res.start, > > > + to_alloc); > > > + rc = __alloc_dev_dax_range(dev_dax, > > > + dax_region->res.start, alloc); > > > > You might be missing: > > > > first = region_res->child; > > > > (...) right after returning from __alloc_dev_dax_range(). Alternatively, perhaps > > even moving the 'retry' label to right before the @first initialization. > > > > In the case that you pick space from the beginning, the child resource of the > > dax region will point to first occupied region, and that changes after you pick > > this space. So, IIUC, you want to adjust where you start searching free space > > otherwise you end up wrongly picking that same space twice. > > > > If it helps, the bug can be reproduced in this unit test below, see > > daxctl_test3() test: > > It definitely will, thanks. I'll be circling back to this now that > I've settled my tree for the v5.7 window. s/v5.7/v5.9/ whats a couple of kernel release cycles between friends? I went ahead and moved the retry loop above the assignment of first as you suggested.