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 335943AFD0E for ; Mon, 8 Jun 2026 08:34:28 +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=1780907672; cv=none; b=D8KgaqLTIdvJSVA6lsWWBeywq1gdl5RmOTP6kFVVULT9Nh8a7uJXn5Dlt0eHSCGhcw21Edo3g2JV3wabMllIeyLE+K9MHf7vGyoUaYzOjGKxpsfMpRaWj9yMdz+/oPBu6IJ4nLwst6rfewe5j5VSxt7Frk0UKPuQyh2Y19jD7vA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907672; c=relaxed/simple; bh=yI1iGkmiSzMFJtnw1lJVP5u1P/QKkpQHXLglYhfy84A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PdvisSWZ61nkJR63RttRl+aYIO+lrmctZb7HwVfxpNvikByRR4dLFK2UWCuv+ccVbH+ILY+BLwuYM83h/JPGFQ9ONYaXtvnu6aCYIPqpNxdk7HbT+v/6K+tJ/hToE76PUSmDOifhH2Fg5hoTspMxsZSm9dB46THyqEphO782G14= 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=FAGS5DA2; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=I6eaH8ug; 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="FAGS5DA2"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="I6eaH8ug" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780907668; 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=315e7bSessxyz662R8s4IU7FTBDlj+mVbEZvVNtQrTU=; b=FAGS5DA2XHd3Prj76/6miRgXLK53dgOAlHzeT8idn2hg8gE/oJ4X93blTaCj28WdYwFkh9 7Ix0GBMQRDP9NwWboKxqAcXoLLDMq+VLdO1PkAHnZI86qGRKQ1yaxt5vviSqGHGaGan4LN pxXpkZihIUdifKYqWSWtzXYXQgOQugo= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-vK-HXtqYNvuIoiT2ykcWkQ-1; Mon, 08 Jun 2026 04:34:27 -0400 X-MC-Unique: vK-HXtqYNvuIoiT2ykcWkQ-1 X-Mimecast-MFC-AGG-ID: vK-HXtqYNvuIoiT2ykcWkQ_1780907666 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-490b8adf8b8so38328095e9.0 for ; Mon, 08 Jun 2026 01:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780907666; x=1781512466; 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=315e7bSessxyz662R8s4IU7FTBDlj+mVbEZvVNtQrTU=; b=I6eaH8ugbcvhTTmtioaCWe2bW5JuEPayuf3U6evSSlATOM/3eoqcYuRFseiCr+6upl JC7Jpk6dbEGZ2icwu77uMzSJwJB85Np7aAjt2fZhKHwVsBEOv9bY0DUOLMXkr/M31g2F E2Vl+DUM98ciDJ7OhAx9aLWqCp+ax8/nlJC5VN8uPTOyTwXzgJHF3hHvJyYOv9FCl7Ft RWaP5dMDACu4og4pG4Vs6YoczTEVwfhXwnB1xgCjURLKvSF9PAOcK9p3KySuViDuKFQl e0vkKVmhFfc0PZ75UJEOZ/pXS7gl7HqBBjgpp9tAJzRhYzC1B4EL61anwu0uuFitV9xB KDnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780907666; x=1781512466; 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=315e7bSessxyz662R8s4IU7FTBDlj+mVbEZvVNtQrTU=; b=osHqJPGgxnPP8lyZyjkGypii9/xgcWDrUSt3Kgun/u0eqt8iHT4pYl/k42spARSyxi qaGwHL3fZxUBldCGWlTTEPx643E0iGtgWFhhrx/7J14pVNPMvYk0kCU9xfYP5NsoJuam boQ4DSPeTQ7tRMT+5b+cbkO1JvET85mgjl6nMSEjrqtxX/PKAXZ/Hde/8eZP982zi+Sl f3FKsNgPruwvczjbxl5Zn46WpF5crYiicX91nEH3dwbKfzlkmh7THQ2WVr+R8kEyd6Jp UUqpF8HYIHbIdI+pvKmx/fvKbbRoEc3hjylJg4BXEOQ3n/v18eixvKGGJ4q0t41SIMKB gmBQ== X-Gm-Message-State: AOJu0Yxh+u5gtqIkI/2LDLCFsCjeiChzs2w8mqLEb4GV+JrrYBevp/bi 4PBfq3v4gDZvi6zfbmSrb5T6pvZSJuEy9YeLZWZlJmQvmCrX2klBJ2lGIRFb0NNgKWQW0dwYucs xknG//MOS7RGxcM7FPcRcfZE/szqoD9+Kw0XUE8gpN7HdzPjv0HXWLA2InOh2aexAiEhKh+oOE2 Hk3G2vJkYYI8CacKdiPIcPkBURmpTFFNESXeS7dC90oZE= X-Gm-Gg: Acq92OHy+bEl56cTwKY9fll6jJeVLhy/v/x2YaPibjhutgkMGvKmYDQvFGe1FLfzt/S Q/vVMJGIVNQMsde7oDeYrM+V3f9iEpX0tqBm0aP2PNZ2uyxhCYF3rOMc+uJfSxsmIhqjiQOf6qD JBYwp7+2Z7Qzrl3U4J8lnvZ2QaaZOvKC6XaeAU08sQ8wudV1Do9xbp+LkjxxIO8zBacIsLuqQJX jdUPtGNauqiYMQaavay3/I15wN1iiBvRQMI0v0HwUefdKk3KexPm28GGW7jQi9flO/VdZxFeccn w/GGzj2EZVvz5YHuss7CJrSzOdfOe5U1kMra/l+PozVUCCFlLT1iHPsl1KVWf13B+Lo5qgBy/Kg vr+vsd8PhVLGIHaaZUGAsgCc= X-Received: by 2002:a05:600c:4708:b0:490:bd66:e522 with SMTP id 5b1f17b1804b1-490c26038d2mr235216635e9.29.1780907665500; Mon, 08 Jun 2026 01:34:25 -0700 (PDT) X-Received: by 2002:a05:600c:4708:b0:490:bd66:e522 with SMTP id 5b1f17b1804b1-490c26038d2mr235213495e9.29.1780907663108; Mon, 08 Jun 2026 01:34:23 -0700 (PDT) Received: from redhat.com ([31.152.37.159]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3d66c8sm356368295e9.10.2026.06.08.01.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 01:34:22 -0700 (PDT) Date: Mon, 8 Jun 2026 04:34:06 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , 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 , Gregory Price , 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: [PATCH v10 01/37] mm: mempolicy: fix interleave index calculation Message-ID: References: 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: X-Mailer: git-send-email 2.51.2.2891.g4157995a80.dirty X-Mutt-Fcc: =sent The NUMA interleave index was computed as two separate terms: *ilx += vma->vm_pgoff >> order; *ilx += (addr - vma->vm_start) >> (PAGE_SHIFT + order); This has two problems: 1. When vm_start is not aligned to the folio size, the subtraction before the shift lets low bits affect the result via borrows. 2. For file-backed VMAs, shifting vm_pgoff and the VMA offset independently loses carries between them, giving wrong chunk indices when vm_pgoff is not aligned to order. Combine into a single expression that adds vm_pgoff and the page-granularity VMA offset first, then shifts once: *ilx += (vma->vm_pgoff + (addr >> PAGE_SHIFT) - (vma->vm_start >> PAGE_SHIFT)) >> order; For anonymous VMAs, vm_pgoff equals vm_start >> PAGE_SHIFT, so the vm_pgoff and vm_start terms cancel and the result reduces to addr >> (PAGE_SHIFT + order), same as before. For file-backed VMAs, the sum vm_pgoff + (addr >> PAGE_SHIFT) - (vm_start >> PAGE_SHIFT) gives the file page offset of addr. Shifting by order gives the correct file chunk index. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Reviewed-by: Gregory Price --- mm/mempolicy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 4e4421b22b59..d139b074a599 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2048,8 +2048,9 @@ struct mempolicy *get_vma_policy(struct vm_area_struct *vma, pol = get_task_policy(current); if (pol->mode == MPOL_INTERLEAVE || pol->mode == MPOL_WEIGHTED_INTERLEAVE) { - *ilx += vma->vm_pgoff >> order; - *ilx += (addr - vma->vm_start) >> (PAGE_SHIFT + order); + *ilx += (vma->vm_pgoff + + (addr >> PAGE_SHIFT) - + (vma->vm_start >> PAGE_SHIFT)) >> order; } return pol; } -- MST