Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9645256rwd; Wed, 21 Jun 2023 09:57:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4w444DmPQNyFdBGGuAVBj8uy4vX+y6mCbFdVidPKYM/9GPSQnWe/A5e8MIfyFGYtao6qdE X-Received: by 2002:a9d:7acf:0:b0:6b2:91db:37 with SMTP id m15-20020a9d7acf000000b006b291db0037mr9343230otn.1.1687366657818; Wed, 21 Jun 2023 09:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687366657; cv=none; d=google.com; s=arc-20160816; b=hOOzt83msbgMIf9xtkoc/E+nzLR8UQjh1Phayu4ptjKIYBfg3q0YT6EuQm+AdxnOrm dmF+TvE9F0kumVxco91E0zd93ajDlOQR098kklwt1xlI6B+EzOmYnVqk8yDiKqaNaPVC IDoFn5XTaVQaOK4uEgOUdnF8oK8Cmrc7YgThJXuwv63ZnNthKmgcoJwkFHEQ+kF1BnXF OBStCX+VUdMsZ8hzLkASEF07ghovCU0litm9e5Ucj8u+pD0gtk382VlRtzf0SRjYsnL4 FIQK8P4l0tYRc3mNap2jeRyJDC4dNkF4vGvd5mTacXQbpTveWBLCWq1wwjKOx19S/ubs Kq0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jTDGdnu+fG/6kslyclH2srz/sHr6MJEFetnoOEAqThE=; b=x1WnWcqoQj61PSaCsYNPevqH9QSPEeo65w3IVr8YKrLshkHZYll+4HfkXJ5SAxhG2F FZTO3DDfOlOdGuwdoeUebWcD3JpmXIgraKKJNX6G3+qBqP9tZn7ZWmKHbkwHk3Z7JpXf 46ev+Hba2PFVtDIioJx9nSFyp5hoy0cIjmUnRvX6B8wVve9yHTqai/SqXJnqPw4Q9gSM JuqorVc0iiePSq9XWoRzBtz5yDbbEVisHq7ztgArp7ccBbYX7GCrwJBF+p/zFYBDDRpG iK21/6IuLUc1RhXAfu8Ev+QmT36ClhjJw8grn6c3nTvm4lKyU7KwH4MoaFCfBPEVx/Xz JdkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=J7syLfgL; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t23-20020a63b257000000b0055339319e07si4503040pgo.755.2023.06.21.09.57.24; Wed, 21 Jun 2023 09:57:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=J7syLfgL; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230177AbjFUQqh (ORCPT + 99 others); Wed, 21 Jun 2023 12:46:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229814AbjFUQqZ (ORCPT ); Wed, 21 Jun 2023 12:46:25 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53169E9; Wed, 21 Jun 2023 09:46:15 -0700 (PDT) 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=jTDGdnu+fG/6kslyclH2srz/sHr6MJEFetnoOEAqThE=; b=J7syLfgLtqZEvF+FaGdNCpIxYK FGrBsHrwiUgwuOgUEvOX2i7PWXG/ZXhqiAhW6CpfyR4l4rDqNGULpmdUDJAIMFqrXnlWMyJuuuQew CRIwuxDz6BodPG9A2vL0dc3r9jSUjJ096kbZOKhyXbwTEF5WnPbOv35W1YxmyI5xeO3eW9SZeu6Ui elEI4SaI8VG431yTXK/Agfd1OvARTxSno98kcl4XPxpk7V8Q46NmOwcGLYx7LMoOCYaku65I0hGaM vfxZSH7R76ZxcVPpw10enxxDEKsn/iEIr1hxmLFS6RNnFgRQiKGzIC7i3HzHCE4ZskLC1FZi9nT0k 4UQzvpAA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qC0y1-00EjDk-FK; Wed, 21 Jun 2023 16:46:01 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org, Andrew Morton Cc: "Matthew Wilcox (Oracle)" , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-afs@lists.infradead.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 03/13] scatterlist: Add sg_set_folio() Date: Wed, 21 Jun 2023 17:45:47 +0100 Message-Id: <20230621164557.3510324-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230621164557.3510324-1-willy@infradead.org> References: <20230621164557.3510324-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This wrapper for sg_set_page() lets drivers add folios to a scatterlist more easily. We could, perhaps, do better by using a different page in the folio if offset is larger than UINT_MAX, but let's hope we get a better data structure than this before we need to care about such large folios. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/scatterlist.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index ec46d8e8e49d..77df3d7b18a6 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -141,6 +141,30 @@ static inline void sg_set_page(struct scatterlist *sg, struct page *page, sg->length = len; } +/** + * sg_set_folio - Set sg entry to point at given folio + * @sg: SG entry + * @folio: The folio + * @len: Length of data + * @offset: Offset into folio + * + * Description: + * Use this function to set an sg entry pointing at a folio, never assign + * the folio directly. We encode sg table information in the lower bits + * of the folio pointer. See sg_page() for looking up the page belonging + * to an sg entry. + * + **/ +static inline void sg_set_folio(struct scatterlist *sg, struct folio *folio, + size_t len, size_t offset) +{ + WARN_ON_ONCE(len > UINT_MAX); + WARN_ON_ONCE(offset > UINT_MAX); + sg_assign_page(sg, &folio->page); + sg->offset = offset; + sg->length = len; +} + static inline struct page *sg_page(struct scatterlist *sg) { #ifdef CONFIG_DEBUG_SG -- 2.39.2