From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EBC8C61CE7 for ; Fri, 6 Jun 2025 16:23:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACD456B0092; Fri, 6 Jun 2025 12:23:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A56DA6B0093; Fri, 6 Jun 2025 12:23:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 946646B0095; Fri, 6 Jun 2025 12:23:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 761BC6B0092 for ; Fri, 6 Jun 2025 12:23:31 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1B7C6802B0 for ; Fri, 6 Jun 2025 16:23:31 +0000 (UTC) X-FDA: 83525496222.30.C67A1E9 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf24.hostedemail.com (Postfix) with ESMTP id 27439180009 for ; Fri, 6 Jun 2025 16:23:28 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=IPKegF2F; spf=pass (imf24.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749227009; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mFpeqJEhDacu967h49T3bcYqqSd1cDscEpckxmXpo1A=; b=oAcyRyQv98NqZ79fx75v7lWuO0AM9060OEi/oUG7zv3wy11hq60Td9jY2tXW5MmN8yavoZ JepGnMGTcX3/oq78u6l0ysBYwBxps/GE+VsdtYkJk795zSvWPYeO3OBgZqxcNinB9W8hoj gHht0GaXNXHTbHzInrWEzNZ50WLuhuk= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=IPKegF2F; spf=pass (imf24.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749227009; a=rsa-sha256; cv=none; b=SkysHhYjE+1FwpMNmG+uNfye49yxttOtRIKYvBeHkhJlgSFudZS1UP6UcaqJw1EyI5rs2U iIUn3CKvJZk47gwv77zzOAj7QGbWrVZcSuaX9QXf8QaP0bDZ/+Itpov1ariBnbGtOvkvB3 mUUtTMn9tBwtqb/Tf62Z+arddmmyuS0= Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-4a5851764e1so41387681cf.2 for ; Fri, 06 Jun 2025 09:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1749227008; x=1749831808; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mFpeqJEhDacu967h49T3bcYqqSd1cDscEpckxmXpo1A=; b=IPKegF2FY7Ga8FmViB9jHxNxqfSQfC0SdG/6tfvhZeHgWdSd/wW7Spiat/QFsxF1XL qkDtBgA9I7hOtWhZwKebx/LrOP0CAjsELDvKPZppu6X6Keyn4G2pAlAYmVyO1Xovgbj3 DTpI2FavjAjCdJWhZ6LNlZP15nPgXJzYztRSD3XCfl49JQizwNZmt3Odm7tmWr1I0XCd qfHenT+d1KC5b0+86v339fg4QOtLvrsK5N9+9Potd9Hp/1uHQNzzh76Cqmrh00G3UhtJ SrifJUjLcY3OteFB4TmqDtwlAAF8QKnEmNAcxE0aVcahIqSxRM9KZ37II8Dg7X+KvEbt AMUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749227008; x=1749831808; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mFpeqJEhDacu967h49T3bcYqqSd1cDscEpckxmXpo1A=; b=OyoiGD0THIt/Wxc+swklfJ3EC2QZSL5mYry8lWVlPFmcZpXC82preYgyrO5cSIN7GF SpKUOqL+QYA3xokZvHLbZRbx8f/AKdD1Bc5Z4qwMy1ibE8LLibAxuUoRbu7kf1Rz50vg B0yDdeykvBJO2S4ZHZ/aufTAkR6VcPWiYc9pplgmA/QLQnCEbXZWBNRGMVh4QomIa+zX AGtZB/2bCjRPLB1mjGDA/XhYniJssoKx5gauVrjaE+ILj5BYaSkHzo5iKjJPAKDR0/Ac TKPmPTQugHW1gtiZoTXT+unBMkkKr+zqSAyHx6XK6PLZazOfVZNLzFAGqa6yNaDU7CWk JwIg== X-Forwarded-Encrypted: i=1; AJvYcCXEvrLmqb69xyZo39LwUMvPe9upz5j6wQYEFbE46nwoXHP6No3J7iyfJPEvZgfm/dMt3Q1zMpve4A==@kvack.org X-Gm-Message-State: AOJu0YwYk2yH55jzWpFpP878m9aVvxs0F0tDPkf9Szo0f6bYMGFODd0k Jo9oj+oXasOD4lf22hBSjI4aKN/A2NR7U8GZ+oh6YIUS0dVpxuWqiCTjSstVg1oboxrQVeg7Ahq 0b5Ciqolhn0myf5X0VVXulJMUnDqhCJzpxnNJDoNgbg== X-Gm-Gg: ASbGncs5+dB/GXcU8/uNEBjkgKUiUfEt6Igis/6tXPNkszZitnjWg6WpP3eXuCYdsGs 1uHj9PUqU53o8rRiV0KXWhFH7AawBA1IrO2UBCht4xXdfQcdTRWy7tok6I1sjfEs4O0SDahqKqE cLQfw6GAV/oneO5ti+om3WeYEfzBJI9MScPuS0cgdv X-Google-Smtp-Source: AGHT+IGPsHSaGwXVvY8YZpTqOE2qMLkHKMqQkhbImGTUUVVWXZpV4mBeVtnt3fOpZqXUHctLEMLr/kgfyV+cty9EU04= X-Received: by 2002:a05:622a:a044:b0:4a2:719b:1231 with SMTP id d75a77b69052e-4a5b9d96135mr48575531cf.35.1749227008164; Fri, 06 Jun 2025 09:23:28 -0700 (PDT) MIME-Version: 1.0 References: <20250515182322.117840-1-pasha.tatashin@soleen.com> <20250515182322.117840-4-pasha.tatashin@soleen.com> In-Reply-To: From: Pasha Tatashin Date: Fri, 6 Jun 2025 12:22:51 -0400 X-Gm-Features: AX0GCFutlDyG92JoXPnUdMDlv9OT8nRqcidR71SxEcHa0BYzPpqGY1tjEjK24Po Message-ID: Subject: Re: [RFC v2 03/16] kho: add kho_unpreserve_folio/phys To: Pratyush Yadav Cc: jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 27439180009 X-Stat-Signature: gxndx5nfusrhfdhk6ks4khpbbazscoim X-Rspam-User: X-HE-Tag: 1749227008-752530 X-HE-Meta: U2FsdGVkX18uoW1iuKytgNqKJPJQcNBFjGwSTprU5Fkx8wvef3nvTuG30x0Yuk0F+qJUqrb4x7Bfr00Lr8tlJi0mr9v3J0CsSa2Y+c4KpU/iJ7moJipU8USm87xWys8dhRX/m0uVKCyVbXeWqvDzSjnm/LsIXT/mS6oADEhLa2leGC/DHMWCe7LTLqXNVGj5ROdlbrOtm3dvrBJKby2QdaMlNg7fefYtFkCSJvXEzE7oYk5ugyCVDsFchCk3sgWA4dcZAfbfIvC9zrcHTcl+MvbKLphVXek+yR7jP8H+TEcc2yKPkJGxozP0wNwBD+GHYMQ+wiHd/VlfNl3tABwY4PvbhfhXjnYDmsiom8KffFjlxujQSjBF59o9ouszHc8EVFrbKkwg6MbpLYu1akuo2URoglQDxXaGaLwGn8M0hF2DoYFXCCZzlEG9/tXhGBN9/Ab0BBnO1Wa9f8a1HFOwf/i3X7vfDjmuh6J35RoBMkNNTmxrgM7VQDu57+bhuuDr21wjjKU/I6sAjPAAWDRLl1ibclI7/M9TCIXVPgpX5//YSzxU3HNna3uf53nx70XCg590cZLjDmF+MIxPkXqe1be+zVqMwcc9yKy1NTeEDpcya0FYbnHBk/Kfx1qdL94pFipx2YI1nJh0Sy5D2/sMEZHD2IqroThfiN+r20ETeOSaXhdXCAUx+sKLBZB2bLAPcPT6vQ47BUt8oGp24JIg6FEopEory2Cw5uLE+RytWO7NHALyKEu3ePytpizBCDY3hW2FKqPuppcvKU8EdZC51aq4kMGY0UovWdmSCjGDOz+atFKluHBtnO4t0/ZbHC1Cn26WU6hXkiXDZcTclF5GaBsMAT1sRtzTL6O/dAaae7sOJM2QaWkFWd8yClEGUQotmkw0Fa8v0ACIi4My0hWj5aZH5HhFc6sESyAjBzLA9E8BIFL38Bu41yBYvgEYuC0Pa121T/iZwCf0mP+jdCh qB4oMioj XVIrV4NgiAdAmEr+P6z/03GgzStioQrNuSX0boDocwr+NwDPVDbHsqByi3crNWxMDVcqM/J/YOVu4nbINuswc4PjsT6DVrA+olDRyghydunvsRN/uGlNJ3JqfTmbRmj3G2gDzu0te1mox9q0LCJAvZ6VwSuoKugStZ4FATtgx3mN0DGBHCB8fCUTMAfOdgKBvolovZqPjWMOA+/j2GIxgMoIvtLMPdz1mTvXYDzCaVUvvKnToe+dlrxYIsBHcMfjUsntN7ag/XOY9zmT8wXZN2a/W9byGakSICw1rkTCzbZFZ6MSLV6jXEUGlK5JRVdj7yvd+yrHBIIMJpcpS7j3+em+FK23yvvUr8N4Q4eYh430LjZDtYZc83EVaXdgYDzSGuwXx9rhcFjNsy53VwFUOKyMjfKqym1oTlPM/nZ8y9Be0yJIfzULulX02yHO6zRdhMSextqsOU8gNj6OE2COnkq5VfQ10E7O4k8Mv X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Jun 4, 2025 at 11:00=E2=80=AFAM Pratyush Yadav wrote: > > On Thu, May 15 2025, Pasha Tatashin wrote: > > > From: Changyuan Lyu > > > > Allow users of KHO to cancel the previous preservation by adding the > > necessary interfaces to unpreserve folio. > > > > Signed-off-by: Changyuan Lyu > > Co-developed-by: Pasha Tatashin > > Signed-off-by: Pasha Tatashin > > --- > > include/linux/kexec_handover.h | 12 +++++ > > kernel/kexec_handover.c | 84 ++++++++++++++++++++++++++++------ > > 2 files changed, 83 insertions(+), 13 deletions(-) > > > [...] > > diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c > > index 8ff561e36a87..eb305e7e6129 100644 > > --- a/kernel/kexec_handover.c > > +++ b/kernel/kexec_handover.c > > @@ -101,26 +101,33 @@ static void *xa_load_or_alloc(struct xarray *xa, = unsigned long index, size_t sz) > > return elm; > > } > > > > -static void __kho_unpreserve(struct kho_mem_track *track, unsigned lon= g pfn, > > - unsigned long end_pfn) > > +static void __kho_unpreserve_order(struct kho_mem_track *track, unsign= ed long pfn, > > + unsigned int order) > > { > > struct kho_mem_phys_bits *bits; > > struct kho_mem_phys *physxa; > > + const unsigned long pfn_high =3D pfn >> order; > > > > - while (pfn < end_pfn) { > > - const unsigned int order =3D > > - min(count_trailing_zeros(pfn), ilog2(end_pfn - pf= n)); > > - const unsigned long pfn_high =3D pfn >> order; > > + physxa =3D xa_load(&track->orders, order); > > + if (!physxa) > > + return; > > > > - physxa =3D xa_load(&track->orders, order); > > - if (!physxa) > > - continue; > > + bits =3D xa_load(&physxa->phys_bits, pfn_high / PRESERVE_BITS); > > + if (!bits) > > + return; > > > > - bits =3D xa_load(&physxa->phys_bits, pfn_high / PRESERVE_= BITS); > > - if (!bits) > > - continue; > > + clear_bit(pfn_high % PRESERVE_BITS, bits->preserve); > > +} > > > > - clear_bit(pfn_high % PRESERVE_BITS, bits->preserve); > > +static void __kho_unpreserve(struct kho_mem_track *track, unsigned lon= g pfn, > > + unsigned long end_pfn) > > +{ > > + unsigned int order; > > + > > + while (pfn < end_pfn) { > > + order =3D min(count_trailing_zeros(pfn), ilog2(end_pfn - = pfn)); > > This is fragile. If the preserve call spans say 4 PFNs, then it gets > preserved as a order 2 allocation, but if the PFNs are unpreserved > one-by-one, __kho_unpreserve_order() will unpreserve from the order 0 > xarray, which will end up doing nothing, leaking those pages. > > It should either look through all orders to find the PFN, or at least > have a requirement in the API that the same phys and size combination as > the preserve call must be given to unpreserve. Thank you Pratyush, this is an excellent point. I will add to the comments of these functions, that it is a requirement to unpreserve exactly the memory that was preserved, and subsections are not allowed. I do not think this is needed, but in the future, if a use case arises, we can relax this requirement. Pasha