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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DBE6FCA0FF0 for ; Mon, 1 Sep 2025 19:50:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Osz0QgPjjPPpht/7We9TScVgwNEfVHtFqDlvy91c0HI=; b=t9Sa5gc00PM7UD /Zf+/S7kxCuwoEXLD2yMS+WUXrpTEZfnOi+IsU2ws8XRTRJ5XcKoWq0FVXuIhw9MxWdtCONsdAWMo ZEQ6nHrnlxsOHFfz0AVfvoTfAEaYT9p5fyutPMgkuNI/8J9nKzG+2mNn2hZtJVmUhcLFpBpCmLAPb g3T/xajcVRBb4mDOfR1A8+Olr2S2tEDy0UIiuIdnVAAiszmLH3w7qTK7ybCRvDqzg0hnSsa3a/fsT BfKysgh1E+uGR3kKtR0Mo6YiXIzNagsfVX0eRKXcgN5Fr+i9sifAji/NhoFm6jW9H3jQjVxFTe1IQ hXo4QH+W9AQLc1KwosAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1utAXO-0000000DgLx-2v1y; Mon, 01 Sep 2025 19:49:58 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1ut6BT-0000000D0Uf-1tVW for linux-riscv@bombadil.infradead.org; Mon, 01 Sep 2025 15:11:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=i06htfFlQWUPNnzacoxmjdCfJTHM/jIyMh7+2RAfHF4=; b=ffBlkxTI3x9hU0lbDCRkRQVUGm Nn4s83MdIVRrNZzYKcEHV3NFyG950BcFKaZsL/WowlXt6icYe967BR1YjmU002Oyn28X/FK7rdaVF JZcyj4/m+/eUb+4q7dBpXw8+Mw8rc/jAVXy9f77KAxGYXWyi4ZurGrUUouD+ZhjECI3qSEUZZkbe+ h+9dSmMzSsEAJ16jMGDCNmsyxYblic+Kv9hERa0hlvQmcprB+XI625Fwg/qd3lXRaA0HqlFTY6f5i xIf2UvJtNWgj7v3vujgxR+4Fnc/NzCm8F3J2TAOGjzw2NPWyEyjUGb/d1lDQ9W6d/qTwDwn8G9kpB X/VQZsuw==; Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by casper.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1ut6BL-00000009pCo-1k4Z for linux-riscv@lists.infradead.org; Mon, 01 Sep 2025 15:11:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756739453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i06htfFlQWUPNnzacoxmjdCfJTHM/jIyMh7+2RAfHF4=; b=Ht3aevYDWXnOQchp4ogexA7ARF1xo9E1Xln8o9oRgVUgSO+Ex86mo/LkckvH6SjNf923n3 B/xVnJN0mM6sAvQ09FeK1dRay40XZiCaT5y86nTm9zEPHv91NnOU2hh+oXZoa+BSj+AACl yS/9etZg/vzWhPo6P9pqQ/bAKoxWymI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756739454; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i06htfFlQWUPNnzacoxmjdCfJTHM/jIyMh7+2RAfHF4=; b=WKEEIx8utzjDM6TRkcunQNLv9ouLToEmE8eIwyVg4KWgP8gw7UpGq3Rq8XK7aXtqOmmGw7 U98Ja7TDxbGqSC08hJ3WxOKnkU9cxiG6xOzrPQaoQAYBOWWVbDLoZLkIqOroKYjcZjBEec sPG5pBUGmbNCRx227JBVZbciBCta7fg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756739454; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i06htfFlQWUPNnzacoxmjdCfJTHM/jIyMh7+2RAfHF4=; b=WKEEIx8utzjDM6TRkcunQNLv9ouLToEmE8eIwyVg4KWgP8gw7UpGq3Rq8XK7aXtqOmmGw7 U98Ja7TDxbGqSC08hJ3WxOKnkU9cxiG6xOzrPQaoQAYBOWWVbDLoZLkIqOroKYjcZjBEec sPG5pBUGmbNCRx227JBVZbciBCta7fg= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-137-mPsifsa5O0-R1fp0Ep7F3g-1; Mon, 01 Sep 2025 11:10:49 -0400 X-MC-Unique: mPsifsa5O0-R1fp0Ep7F3g-1 X-Mimecast-MFC-AGG-ID: mPsifsa5O0-R1fp0Ep7F3g_1756739444 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6F20F19560B2; Mon, 1 Sep 2025 15:10:44 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.88.45]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6AB8A1800280; Mon, 1 Sep 2025 15:10:29 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , Marek Szyprowski , Lorenzo Stoakes , 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, Marco Elver , 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 v2 24/37] scatterlist: disallow non-contigous page ranges in a single SG entry Date: Mon, 1 Sep 2025 17:03:45 +0200 Message-ID: <20250901150359.867252-25-david@redhat.com> In-Reply-To: <20250901150359.867252-1-david@redhat.com> References: <20250901150359.867252-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250901_161056_372080_D04ED7B4 X-CRM114-Status: GOOD ( 13.18 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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. As sg_set_page() gets inlined into modules, we have to export the page_range_contiguous() helper -- use EXPORT_SYMBOL, there is nothing special about this helper such that we would want to enforce GPL-only modules. We can now drop the nth_page() usage in sg_page_iter_page(). Acked-by: Marek Szyprowski Reviewed-by: Lorenzo Stoakes Signed-off-by: David Hildenbrand --- include/linux/scatterlist.h | 3 ++- mm/util.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 6f8a4965f9b98..29f6ceb98d74b 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -158,6 +158,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 +601,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; } /** diff --git a/mm/util.c b/mm/util.c index fbdb73aaf35fe..bb4b47cd67091 100644 --- a/mm/util.c +++ b/mm/util.c @@ -1314,5 +1314,6 @@ bool page_range_contiguous(const struct page *page, unsigned long nr_pages) return false; return true; } +EXPORT_SYMBOL(page_range_contiguous); #endif #endif /* CONFIG_MMU */ -- 2.50.1 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv