From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 122D630ACEE for ; Mon, 11 May 2026 15:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778512540; cv=none; b=fb4yGvcwUBvA+l10oCj7aKEDDGuzNxQ/LQjKd7AK6mPliQrYvr/IcW3ftSIOWmRoaP52FqIKfwUJGzwn7zScc16cT4Hb29qby3P982D9wzpwnPe9oQh3zjbfna6mwcRjnCxLPEW5HDI9jD8C2mVg2LUwu2cYUN7AnSWISxc2udQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778512540; c=relaxed/simple; bh=nk8hE5v8+3CIaIuDoXep25HN/SD7sZy8FNF33B159Qo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nuJjxnh9MlStLwMgkQc8jKLMGLYMUX0EJGofsBt7AjU189rIpuKjfLV94IJltSn/pY1hMNKU6rHymM6pXVhbF3p+qWDG0sqNdHNjQKPaJQLjUDyFDCaHwonngyUGdvKPEQ06T4OO4sduvahJdQmFR1QBakDMP6sS0vEXBQW6dEM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=blH56WJY; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=LObj1h33; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="blH56WJY"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="LObj1h33" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778512538; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pw7Ok457RiSERsUb2kiTq/Cv9uGPdowjG2q0yMpggx4=; b=blH56WJYd/Vr62iUNyX38GUhufn75kIKHU+0QjVy7pifbJ1CXzmdTFfNRTV++nSjVFRQEt UqkJ3BMWL9irXxCZ6z7/5QdYEZ7BJ/MQOezgPzSjGvmkCWEHOtMZfHJVFlYSkC467b/vbZ moMJjaK1qptgBQxyOv9a9kiba7ccE9k= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-597-7i2qda7oNjqFfUi2w0XGAw-1; Mon, 11 May 2026 11:15:35 -0400 X-MC-Unique: 7i2qda7oNjqFfUi2w0XGAw-1 X-Mimecast-MFC-AGG-ID: 7i2qda7oNjqFfUi2w0XGAw_1778512534 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-6805f45c06dso774011a12.0 for ; Mon, 11 May 2026 08:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778512534; x=1779117334; 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=pw7Ok457RiSERsUb2kiTq/Cv9uGPdowjG2q0yMpggx4=; b=LObj1h33/0eLNePIHe4colXTNpL7ZTdgbqWXKcOs8SP9RZC+JojCsFokYf9MjfCgsX m1gLGj9oPVYed+xs85fj7L7dojKQEQK+YZ2RN/A7PRDLXG/OXdDXHp3XRyuUwAxfYXUy yZPzX1dKm5yL8O71Znmoqf/OG1owHeGYaN0V8I1LGm6I64RO1BOYHHVtRNJEebyfVIAE G7dMbWbQVNTMe1t5HR9+IMfA4aqj1X5wFWmq72lq4Cw+MkH6KTWqheZtXj7A5n81QnJg paNBJpEiZlZb8QFOLtLVZ77KBiyFDjBaK4H5joE9m8c2DEasZ7rWgiFXIMKX85ryqlI7 GPSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778512534; x=1779117334; 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=pw7Ok457RiSERsUb2kiTq/Cv9uGPdowjG2q0yMpggx4=; b=Z8qeKsahJNGKWILjOj1ztL8kkAXz0tDTmSed27b5hKkw9kHpgG3wZzpq+WXQymtC0P khUEwIkKgpzz9lbxxdNbJ993bQ6ExrZwzJLo2D3KZeEC/P5nOh+GlU8thZUv0qT/UKEN 9ziI9frgyNQRgY3hraqImbH36dHGu5eCcSbAcEC/5M4sihqNkMoOVojQ77wpaTeLeSSc WRRuEKrHFfyWHAE26bepbCtd7lU3dxW3BTEVNaPxT7bd8H2zkzG7Eq30jFS/w1qbu5SM MAJ2/cBfBTxAW07YMYJCRdmJGC2HJsmBGF8q9bjJaKLRJQ9r7RLxlwkkPdNupdzl6NHy BJ9w== X-Gm-Message-State: AOJu0Yy3GJKFTTUF26NfHXBZSVc/RBb0CFiB0EE0SHbgCQxFaFC5IEXR Eh34GpMEfJbl1P53H6crz6HerwvZtwrpvO0QmvXfeoo4x5xwhbRf4icu3w+7aoOrJhKwQWldI17 /ZXwHtsonTCRJYAOvbb+fGaDh3NKJecjLjdsSJ/lRgLUvCX+iXM8IqdsQlljitko4xKfw/n44EA Ke X-Gm-Gg: Acq92OGPsa+ymThAdqU3ETYPFrffwcxE2XTrrR0vkrYDFWsk6mt2d8Udq8ikM5MKLx6 Nv6sdFlg9ulkSvM11EyVwXAkq9IO71TmgQbtGBQSUQSHIavRXh+/O7UMoS5CE7JFk9f8I91bZjE 02Vl/oLFAB+ZgT4XtkbQ2b9wdlhFt571KfqM2ele8Vd+X4BV28tVs5duIL0ukR5pcRXkR6l2QjU /KRQoBLhhYpKwhMkvBrRD9hBPReMBy8L4Uudl3+wGv2NFgF1Y5sV8cTnFnE9igNYPy9OqrB0ph+ huVzGRH4opy7julWsTwA9Bn4AnCyshlUzA3oxB8cQ/A7supjed1fAhhl7abXmW503vaS4jNl0mq CNPL5/B6qHLrFtzb8erLdgxnE3g/i6ac6o67AjZZM X-Received: by 2002:a05:6402:3509:b0:674:37b7:227c with SMTP id 4fb4d7f45d1cf-67d63aa055amr12708553a12.2.1778512532358; Mon, 11 May 2026 08:15:32 -0700 (PDT) X-Received: by 2002:a05:6402:3509:b0:674:37b7:227c with SMTP id 4fb4d7f45d1cf-67d63aa055amr12708486a12.2.1778512531582; Mon, 11 May 2026 08:15:31 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-67ef0b6baaesm3990113a12.12.2026.05.11.08.15.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 08:15:30 -0700 (PDT) Date: Mon, 11 May 2026 11:15:24 -0400 From: "Michael S. Tsirkin" To: Gregory Price Cc: linux-kernel@vger.kernel.org, "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Muchun Song , Oscar Salvador , Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Hugh Dickins , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Ying Huang , Alistair Popple , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Axel Rasmussen , Yuanchu Xie , Wei Xu , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , virtualization@lists.linux.dev, linux-mm@kvack.org, Andrea Arcangeli Subject: Re: [PATCH resend v6 02/30] mm: mempolicy: fix interleave index for unaligned VMA start Message-ID: <20260511111417-mutt-send-email-mst@kernel.org> References: <41bd50fdaae943e1a79215ea4000322e74a823be.1778489843.git.mst@redhat.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: On Mon, May 11, 2026 at 10:59:46AM -0400, Gregory Price wrote: > On Mon, May 11, 2026 at 05:01:49AM -0400, Michael S. Tsirkin wrote: > > The NUMA interleave index formula (addr - vm_start) >> shift > > gives wrong results when vm_start is not aligned to the folio > > size: the subtraction before the shift allows low bits to > > affect the result via borrows. > > > > Use (addr >> shift) - (vm_start >> shift) instead, which > > independently aligns both values before computing the > > difference. > > > > No functional change for current callers: the fix only affects > > NUMA interleave and weighted-interleave policies. Current > > large-order callers either pre-align the address > > (vma_alloc_anon_folio_pmd) or do not use NUMA interleave > > (drm_pagemap). All other callers use order 0 where the old > > and new formulas are equivalent. However subsequent patches > > in this series add large-order callers that pass unaligned > > fault addresses, making this fix necessary. > > > > Signed-off-by: Michael S. Tsirkin > > Reviewed-by: Gregory Price > > Should this just be pulled out ahead as a fix (assuming this > set takes more time to bake)? I get it's not causing issues today, > but the interface is otherwise technicaly broken either way. Sure Andrew can pick it up if he wants. I found a bunch of unrelated other "technically broken stuff" that I deferred fixing. Will get to it once this is done. > > --- > > mm/mempolicy.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > > index 6832cc68120f..39e556e3d263 100644 > > --- a/mm/mempolicy.c > > +++ b/mm/mempolicy.c > > @@ -2049,7 +2049,8 @@ struct mempolicy *get_vma_policy(struct vm_area_struct *vma, > > if (pol->mode == MPOL_INTERLEAVE || > > pol->mode == MPOL_WEIGHTED_INTERLEAVE) { > > *ilx += vma->vm_pgoff >> order; > > - *ilx += (addr - vma->vm_start) >> (PAGE_SHIFT + order); > > + *ilx += (addr >> (PAGE_SHIFT + order)) - > > + (vma->vm_start >> (PAGE_SHIFT + order)); > > There's enough (PAGE_SHIFT + ...) spread around the kernel, i wonder if > it's worth a define or a function (not in scope, just pondering). > > ~Gregory