From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (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 9BD6A35E948 for ; Wed, 24 Jun 2026 08:36:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782290192; cv=none; b=AW3AwO5iQoxHs8J5WQRn/+M2SML+1BslEjEoA5yXaoMOmYjHQTeCHAiFcqDI5PMdBz36I8OOvihmEed7bbWP5gQKF0h2Le4rjAFyFdj0qQBXg0AeXTWYMO+N528TQfEKlra2QWZpt2/cD4Kog5FQz+BCVcRRYwfLnEALim1XQAY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782290192; c=relaxed/simple; bh=IC96SJpon10vJpky3Egz7KbIXsoKr7uotQi+Mi3bWy4=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VAZIeuISZT0UDX9Te8E3zaFMaXSEwJhrbkNeJJA7Ixtw7F8UbEJHpy4Wh+n2DPAQGJe7fpxg9usdg4m0l6jbfP7cFlKtzu/nV/yuWpMdYG/ZbMJL2F1UjO/PvFMyVAGMalF9RBW5U/Dc6rQRgs2YlwlG1FFjTJuU7ZshZu3/SPU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=tMogCuSj; arc=none smtp.client-ip=74.125.82.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tMogCuSj" Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-30c6040aa54so1043567eec.1 for ; Wed, 24 Jun 2026 01:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782290189; x=1782894989; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:from:to :cc:subject:date:message-id:reply-to; bh=i6loG2kbuu3buyD+OMfDQDJAMGaTd6c5fL/hshLRcTg=; b=tMogCuSjDvveW3L5eqfsApWiu/ogl36KpFw2EBTGe3DFaFd7nMxNF6VrlC6kh2ipBj 68bkT7l+ZFNboTrHq2b8WYGeoFnTd08+VhyyJOnbnYav0C7DPSj6z3Z4F0wkB2x4db3f 2Uv7JPlE7GmlgfvHZVz4erQMnPcfrR418v1eNtW7D1lNb9gMZDTA0pog4pY0upwvC8t5 1ikuUnnh4EMDqq4StjYPipPZmcSDhUek8rV4u/ny9F9lGFs6MBk9cjZD6ZZTEpnTF3R5 DbIQCAuxpJF3Yqk5XcUmsWeT/x3HWnxSeqJTM7hsPaAMiH6AjYsHsZk+w8FykmvXe1uk 9b7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782290189; x=1782894989; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=i6loG2kbuu3buyD+OMfDQDJAMGaTd6c5fL/hshLRcTg=; b=fdi29pVvwCkYE8Jb4FMGrEHHUTQy9tSwNBxG+sUnojs00FIU5pQxUkmSINQ74vTHL/ Xtb2V/DlQuX7d/kpdFCsQuiXylZlkq2BI18po3NZMFGd0mH8YWa4oqffZLI5EofiRrru F8bNxcx6mo1bg4eY2Wkg9g3Te1/JaAYjT0jGIaBGvE5qTGyvwQaoC0msMzjd+RR1ISlg +J2y0c/ZSRdWZ7nSiNVQuMDQghmmRSonTrYQKww/cQORvRmIMZDr47XBR27PL56wKqSk Mr5NQcqytbXCbseMaPPH4JsLR32H1bfxsL5RZKNkoNsY/pDyHORTZQkGfKcqg38O9Dif xnKA== X-Forwarded-Encrypted: i=1; AHgh+RrI0NQL+rOdSVbjZ3qhKVUAh9wu87wzEKsWRLnxnxDc6rCr1Ic+w0oOnrDuZ2I+VVmcSVuKa2DXUFNiDwM=@vger.kernel.org X-Gm-Message-State: AOJu0YzqGY+g0M+896yNXbf8tx0pcaii2BVcJRL9jvFToHlAKd+kz+8x uL07x8dh8FaFqItHQkde/5mqRnUNfPT5FGUsO0/R/1BcrrU2WZ54+FCF X-Gm-Gg: AfdE7cm6kzwzBF+63Up/OuiRhTKahxiB2dfQ+a8RKskpu3fbD7OZwDsT5QQ1nPu0nNo zwP8KeG8q/ghyTI4EBmAa769dAmdzIIKdj2zn3Jc/LHlnBBWgEYiJ9yfusw1KYh+AT+slpCxtqa z/6XGP9x7lkiFKYPGs9YOvXJ0xCBdyTzVFOPgvcE5dTeGMEdlt5WzGtrriIAcsCBTcS5fLGiFoT YtKvSCPaidW9lBwyx69V/eVw/VkH9wzkJspM9IB2UN0pKfGJLBiVoywGqcGnPu/9SLvt4HBO2tb oJs1L93KWMmKRmw6eNpRRrmo9ySG2sYR+EOpCQRI6OHDUGceHvZz2ND3nxCr7PuKFOA88u5l4gL gVh4wiAUfuDfmtxuhiVdt4kgs7/3yDrClHXF8SJ5X9tEiI92ug3ddg8WY010DgCThmM/6P2Cug7 YMIytoVlL0rYHiDArgVAk4TmEc/oCDhtfUdvoJtDhHeWYrKOBRgEz7IFJXnHVH/y8T8Zft69k66 dT3GJs= X-Received: by 2002:a05:7300:506:b0:30b:c502:23e8 with SMTP id 5a478bee46e88-30c692f8c53mr2440312eec.21.1782290188564; Wed, 24 Jun 2026 01:36:28 -0700 (PDT) Received: from AnisaLaptop.localdomain (c-73-170-217-179.hsd1.ca.comcast.net. [73.170.217.179]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30c6d5717a2sm2764659eec.0.2026.06.24.01.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 01:36:27 -0700 (PDT) From: Anisa Su X-Google-Original-From: Anisa Su Date: Wed, 24 Jun 2026 01:36:26 -0700 To: Anisa Su Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, Dan Williams , Jonathan Cameron , Davidlohr Bueso , Dave Jiang , Vishal Verma , Ira Weiny , Alison Schofield , John Groves , Gregory Price , Ira Weiny , Jonathan Cameron Subject: Re: [PATCH v10 23/31] dax/bus: Factor out dev dax resize logic Message-ID: References: <29393afa419cdffdd5d299cdc323262f5c20c036.1779528761.git.anisa.su@samsung.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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <29393afa419cdffdd5d299cdc323262f5c20c036.1779528761.git.anisa.su@samsung.com> On Sat, May 23, 2026 at 02:43:17AM -0700, Anisa Su wrote: > From: Ira Weiny > > Dynamic Capacity (DC) DAX regions back their dax devices with per-extent > resource children of the region, rather than carving from a single > contiguous dax_region->res. Allocating space for a DC dax device — on > initial uuid claim of its backing extents and on shrink-to-0 during > destroy — needs the same allocator the static case uses, but pointed at > a different parent resource. > > Factor the body of dev_dax_resize() into __dev_dax_resize(parent, ...) > and add a dev_dax_resize_static() wrapper that passes dax_region->res > for static (non-DC) regions. alloc_dev_dax_range() gains the same > parent parameter so it can operate under either kind of parent. > Stale commit message :( __dev_dax_resize is introduced in a subsequent commit. Updated commit message to reflect actual state. > No functional change. > > Reviewed-by: Jonathan Cameron > Reviewed-by: Dave Jiang > Signed-off-by: Ira Weiny > [snip] > + > +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); > + resource_size_t dev_size = dev_dax_size(dev_dax); > + struct device *dev = &dev_dax->dev; > + resource_size_t to_alloc; > + resource_size_t alloc; > + > + if (dev->driver) > + return -EBUSY; > + if (size == dev_size) > + return 0; > + if (size > dev_size && size - dev_size > avail) > + return -ENOSPC; > + if (size < dev_size) > + return dev_dax_shrink(dev_dax, size); > + > + to_alloc = size - dev_size; > + if (dev_WARN_ONCE(dev, !alloc_is_aligned(dev_dax, to_alloc), > + "resize of %pa misaligned\n", &to_alloc)) > + return -ENXIO; > + > +retry: > + alloc = dev_dax_resize_static(&dax_region->res, dev_dax, to_alloc); >From Sashiko: https://sashiko.dev/#/patchset/cover.1779528761.git.anisa.su%40samsung.com?part=23 alloc is declared as unsigned resource_size_t. A negative errno isn't returned correctly. Instead, the below line to_alloc -= alloc underflows and the goto retry loops forever. Fix: declare ssize_t alloc. > + if (alloc <= 0) > + return alloc; > to_alloc -= alloc; > if (to_alloc) > goto retry; > @@ -1367,7 +1396,8 @@ static ssize_t mapping_store(struct device *dev, struct device_attribute *attr, > > to_alloc = range_len(&r); > if (alloc_is_aligned(dev_dax, to_alloc)) > - rc = alloc_dev_dax_range(dev_dax, r.start, to_alloc, NULL); > + rc = alloc_dev_dax_range(&dax_region->res, dev_dax, r.start, > + to_alloc, NULL); > up_write(&dax_dev_rwsem); > up_write(&dax_region_rwsem); > > @@ -1659,7 +1689,8 @@ static struct dev_dax *__devm_create_dev_dax(struct dev_dax_data *data) > device_initialize(dev); > dev_set_name(dev, "dax%d.%d", dax_region->id, dev_dax->id); > > - rc = alloc_dev_dax_range(dev_dax, dax_region->res.start, data->size, NULL); > + rc = alloc_dev_dax_range(&dax_region->res, dev_dax, dax_region->res.start, > + data->size, NULL); > if (rc) > goto err_range; > > -- > 2.43.0 >