From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (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 6B7D813B7A3 for ; Mon, 11 May 2026 14:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778511592; cv=none; b=kTFfNXtMn+UIFRPxKktQLbEVW1lzktnekD8LFxDretaIcjvD8XzFobLQn1rRpw0OpgXyP+ZkubYraosAND7/a8Acrv/UajgWyarqD0ypDm5fKdD+rsc2dXs4JAd7Yhqg2ENsQTsrwOheSlmkjq9YqWVh+/8Hg+hzuJcUGLX3H60= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778511592; c=relaxed/simple; bh=wpi1AMcW2tPPmZcxQdUUPjQAl76NDRV9zcdDLvVS+oU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HLyMi8CaETIdAEbRD7cT3t3DlJUfR5akBYhW5P6CiTeUPRHGmZZxnJV+aYsVmqt9qeOUTFmGxberHJL0xLn9w8232W59huyy/RXuapRPM2bcbOPnkztmhUVYWGiDsZdvNM7E76zldpNZCkcDcwJNu/bXkCTl6SXiiFLVQJkNzIc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=SY0vbLX1; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="SY0vbLX1" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-8ee62a19730so505264185a.3 for ; Mon, 11 May 2026 07:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1778511589; x=1779116389; 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=7h6hiVH0/NZ6Qfi9mJnbfpbwuzxv04Y7rZxb6Vb37aU=; b=SY0vbLX1H+et4lvAz9F8x6s6VeBUjujSmO8fV2L1d827NUj2kaMVwCfT+q29hCMsPa aDMYfOAl+cxA8HO/Z9C/zc390JaXSJ/D8QEqr6oxBRxD4eD49tQnfrsnRYWfblUKfPYQ FK+YyOW77sBZlCJF+iBU+uu2HuqYYZNBTgK/mukU/96rcGB7eFw6nsXQGWSb2bMllsBA 4pvDVltYOacKluC1amXaO8puWAasv/zxBZkPcCmra3I4COySsdRnBxal6oGMabGJw75t MD5+w+YGosrfcBmdrMjlxaYsyFFONxGoYhTh7Xx4aM6tyE3KW6ngwL4LVY4jCON1RqFL CDvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778511589; x=1779116389; 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=7h6hiVH0/NZ6Qfi9mJnbfpbwuzxv04Y7rZxb6Vb37aU=; b=jjcyAsbhuI3AWfah2QlgXfxOTvs/7ki/pk2YojJvjGIBpF7ldLpdAIY2BEMZ0tLMQY o7Eid2OFjgr6utdxOFgywSMcmAp2UzQlW51GYrSYU6jp9OZfVC1ZFJ/Wxl23jWxpeNxI Cfo5zNooD6jEntaZtv/z+rvOOx8lAKUg8rIDtL/GruyGgVXzj1HeHy71amOzydtuFGUi 2ZUnF4D8n1XSaCMAoPP9wlO8C53YrAEu0oiqk1TV2qs7s7eppdPtpb/WLyXkKkTigbw2 4avmJpcoI0r6Ey9eiob2lzKLiK+l0SpojhUbzVi4pFIpH3+geePn1KYmeZ3bD1QyVLEM Cw/Q== X-Gm-Message-State: AOJu0YyzrbJlhmmfC6Z5jnQXZNMO4mD/987WwULyI5CkRyHbQpf7iBFW zvVs6UKkiqbJOJjr1Ok4gnYINJHNtxkCL0W/2XzgjQNHYsBYOSnMFutb6hWtJ1Bj/ME= X-Gm-Gg: Acq92OEhJpBcb3PpnTNEbvSwZqmD+S3wHKY1rM8no3WzPlQxuyoshyzQmGf9mOOuPvN Szk++5bizNZBG6DbcEdUvAv5On/df73VfxdPHvB/apnyDSjNH4LhJnLKymXdiRAdHmMR9Ju88c+ ltUaN95KKxVy6UO0iXPUnYhNoaAKj8gJYCl1CNNQgM93KHH0dyc0fJegM3uFf2eKNJj05pRNJJq +VSU/Xofc+cegURE/ZN7ianuH/vkyF8fCseIh30UK9xIwmAmSrFkVDbACagIPgv3U8EZy3PvXq2 cFsKK7/ImcoMP0lMTBn+sxYK6ESibudKAquMFLeMxe5Hvs2+QNrmLt2PzQe53MiEqS7qqXgzgNb pDatMJ7VkXog06Ze5LCnW/JRclQrbOiWAkEHvBr2nZHLU5U12DPueFn0JseDpuPxzeGAXDhg7Cy vHVl+bCKTtJs/B+rkVL0R94poSl3ZTjMGMQWlNGWnncle/TBieD/I3GByKol7Ts+JiZxT5Yinnt EZAzLoYnyWLYO6ZA1LxGfM= X-Received: by 2002:a05:620a:1788:b0:902:afae:fd39 with SMTP id af79cd13be357-904d70c4754mr3575981085a.57.1778511589271; Mon, 11 May 2026 07:59:49 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F (pool-100-36-248-188.washdc.fios.verizon.net. [100.36.248.188]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8fc2c91c813sm3112985985a.33.2026.05.11.07.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 07:59:48 -0700 (PDT) Date: Mon, 11 May 2026 10:59:46 -0400 From: Gregory Price To: "Michael S. Tsirkin" 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: 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: <41bd50fdaae943e1a79215ea4000322e74a823be.1778489843.git.mst@redhat.com> 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. > --- > 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