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 48C0C36CC9E for ; Thu, 21 Aug 2025 20:08:15 +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=1755806898; cv=none; b=hqdfI2mNyONUrxrAeqUtl/8hqOjEGKOis/uYatC9Opctnqk87BW8LR4MGXSQIap05sVNg2vm6faXq0F90SoiRmZkURAV0cvz29K0dsnoxpsd/hMLJAuIK0Dtt0ELI2cSd27OYpSR5Drf/hLDZqP0n8qb1zylNT0ZeGxDxKLcNJk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755806898; c=relaxed/simple; bh=kURokXQjB5Kuo7a6U8usTL1aQ1tfaOTG2Bf9aj2NBoo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=gKZUcjTyJSIQpBleuaObhAWvBJ8V0/88sm6Xx+PzIY6Hi0hNotRLwzX9T5hcdFDFTw+SYlxJVxD1G688j3x4Z8Xb6jSdJQrB2g528fkoxiBJa7gcD6fntY71eFlu1l9MwmlO68gLtGl0yDI3i//LvcSF0J3KPr1RO00Hlos8CiU= 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=Asgvc2nR; 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="Asgvc2nR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755806894; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NKFS9/TuG2v9AIcAoooIJr3bGKW6zmP0XL+5izT5Y+4=; b=Asgvc2nRe+TJEI/uMByKO0brPcrRkTx89JxKNv/DzB0ld+4mIl0YJFypNHpcqTdk7x3Vbu 0xnohi5l3C7ieinDW9UAB/Y4J6Pyq6TeJ5iZ2kNUsH1yFrKBwpCY9USfDDICSpbEYpzpOf bmBgtmyzF4u/4vr9Pyaua/G5SjzFLjw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-127-T4ws0_m5MnWSFhltlmJbAA-1; Thu, 21 Aug 2025 16:08:13 -0400 X-MC-Unique: T4ws0_m5MnWSFhltlmJbAA-1 X-Mimecast-MFC-AGG-ID: T4ws0_m5MnWSFhltlmJbAA_1755806892 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-45a1b05d251so7744195e9.1 for ; Thu, 21 Aug 2025 13:08:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755806892; x=1756411692; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NKFS9/TuG2v9AIcAoooIJr3bGKW6zmP0XL+5izT5Y+4=; b=JP+kplqd76pmmff4Y3F1ag7ZstvP93vGGRmp+8r0Lx0olAYHLA6Q3hFjR8IaQYpsTL yqKWFry7tODl39jTnKdyW/6UZWkASUfymGp1f0eOwIUS7ujqt9NrZxYs9bNDLVmtjlz4 z73qaokKFWev/EOdnpzlIbS2Tt+4CNswSNn7MNEMF5wW9qKszKSZxWIKe2KZFwLV9yaU MjQ/zVeJGRVOBSA6U2hlSzfM4pJMxqTtSRyQUakOB9vExJ1Y/G95wcFDzCygI/DUqW2f tTL/vOZWROsbvZnFXPe1YXnqA5HDlPQDFCDGDfCMk41uclthS1E/bbjv6FJx+cgjM810 KBbA== X-Forwarded-Encrypted: i=1; AJvYcCU6O9sIvR7IwBj8l9MdsanX8XUozhsokctVvjTa1p6C0hEIKoU3kvyuUNHwWayL2bTkkuf2GMekNgbiz8rSFA==@lists.linux.dev X-Gm-Message-State: AOJu0Yx+EveVup8HlOaEPngpAvtB9zi3KQcRBRUh3DlfF5spq8h3j4Kc BBm3SpS8n5UBSTAl4a8vIzILGewfO73+6NF3A5YfyclNAyJjY0SVTl4N+SdWL/EQUQjTrOxiCgk 918jvGKycmIm0i9Mk4dqqk2LoHmlWlqS0O5gjOixs6bETrcx3UXbOaULsgF9OOmkph8vF X-Gm-Gg: ASbGncsFsqsLSCzbB7fbkKLcpC+o26+sAzQO89R4D9QM5+3Eo6XO4iQRxryofPwwWXV wKyCC74NU28OgSEN7J1mv3YjLKMbZShvXHNPrxopICeCIAMx4zGxuma68TQ91qn1XXta0IUb6dy jcW9mqE85XLPpl3F/kjsX+GJeXvAkQsgmRLrTRWju89pxoQDnfsGwXH3xfHZsa+Tl021QIdHNvB OuYEPE6RWNKG5OGUX14IeZynB5gNrH79EVGww7aYRJNgCUbjkYAOUXokVn5c9+vozGfFUyQ3c1k vTmxrTvGtah5aV1BaF7FyifNg/APGzUCTp60ZUp4BYzmveVZ/KdLGmA3tgE3/6uwRQHlEwvncFV rhoJBOCtYQbThxoeF5Vv5xQ== X-Received: by 2002:a05:600c:1f1a:b0:45b:43cc:e557 with SMTP id 5b1f17b1804b1-45b517cbee2mr2552905e9.34.1755806891806; Thu, 21 Aug 2025 13:08:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/z26sBz7JGLAktk/cnLNnmvA2KmHoRy5M1TseKC0NpCNohvOWfWbiwnk6fyruz4Gv4BdEig== X-Received: by 2002:a05:600c:1f1a:b0:45b:43cc:e557 with SMTP id 5b1f17b1804b1-45b517cbee2mr2552235e9.34.1755806891155; Thu, 21 Aug 2025 13:08:11 -0700 (PDT) Received: from localhost (p200300d82f26ba0008036ec5991806fd.dip0.t-ipconnect.de. [2003:d8:2f26:ba00:803:6ec5:9918:6fd]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3c0748797acsm12277591f8f.10.2025.08.21.13.08.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Aug 2025 13:08:10 -0700 (PDT) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , Alexander Potapenko , Andrew Morton , Brendan Jackman , Christoph Lameter , Dennis Zhou , Dmitry Vyukov , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux.dev, io-uring@vger.kernel.org, Jason Gunthorpe , Jens Axboe , Johannes Weiner , John Hubbard , kasan-dev@googlegroups.com, kvm@vger.kernel.org, "Liam R. Howlett" , Linus Torvalds , linux-arm-kernel@axis.com, linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-ide@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, Lorenzo Stoakes , Marco Elver , Marek Szyprowski , Michal Hocko , Mike Rapoport , Muchun Song , netdev@vger.kernel.org, Oscar Salvador , Peter Xu , Robin Murphy , Suren Baghdasaryan , Tejun Heo , virtualization@lists.linux.dev, Vlastimil Babka , wireguard@lists.zx2c4.com, x86@kernel.org, Zi Yan Subject: [PATCH RFC 23/35] scatterlist: disallow non-contigous page ranges in a single SG entry Date: Thu, 21 Aug 2025 22:06:49 +0200 Message-ID: <20250821200701.1329277-24-david@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250821200701.1329277-1-david@redhat.com> References: <20250821200701.1329277-1-david@redhat.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ObVR8t3G1z_YpK0UZRDZPmV1vzKoTeIpywKspDPdUu4_1755806892 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true The expectation is that there is currently no user that would pass in non-contigous page ranges: no allocator, not even VMA, will hand these out. The only problematic part would be if someone would provide a range obtained directly from memblock, or manually merge problematic ranges. If we find such cases, we should fix them to create separate SG entries. Let's check in sg_set_page() that this is really the case. No need to check in sg_set_folio(), as pages in a folio are guaranteed to be contiguous. We can now drop the nth_page() usage in sg_page_iter_page(). Signed-off-by: David Hildenbrand --- include/linux/scatterlist.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 6f8a4965f9b98..8196949dfc82c 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -6,6 +6,7 @@ #include #include #include +#include #include struct scatterlist { @@ -158,6 +159,7 @@ static inline void sg_assign_page(struct scatterlist *sg, struct page *page) static inline void sg_set_page(struct scatterlist *sg, struct page *page, unsigned int len, unsigned int offset) { + VM_WARN_ON_ONCE(!page_range_contiguous(page, ALIGN(len + offset, PAGE_SIZE) / PAGE_SIZE)); sg_assign_page(sg, page); sg->offset = offset; sg->length = len; @@ -600,7 +602,7 @@ void __sg_page_iter_start(struct sg_page_iter *piter, */ static inline struct page *sg_page_iter_page(struct sg_page_iter *piter) { - return nth_page(sg_page(piter->sg), piter->sg_pgoffset); + return sg_page(piter->sg) + piter->sg_pgoffset; } /** -- 2.50.1