From patchwork Wed Jun 21 16:45:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13287672 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AE16EB64DD for ; Wed, 21 Jun 2023 16:46:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C5348D000F; Wed, 21 Jun 2023 12:46:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 979258D000D; Wed, 21 Jun 2023 12:46:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EE888D000F; Wed, 21 Jun 2023 12:46:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 67A828D000D for ; Wed, 21 Jun 2023 12:46:14 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0B7A51607C3 for ; Wed, 21 Jun 2023 16:46:14 +0000 (UTC) X-FDA: 80927332668.15.AA3D997 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf18.hostedemail.com (Postfix) with ESMTP id 334441C0020 for ; Wed, 21 Jun 2023 16:46:11 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=J7syLfgL; dmarc=none; spf=none (imf18.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687365972; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jTDGdnu+fG/6kslyclH2srz/sHr6MJEFetnoOEAqThE=; b=cqT+fgG5OoCVYK6iR424EeBqD5H9XuiBbHAScf9d/p5MAGSqL+0+7DP80r/E86g6h711C7 9Qy/NE8D3p3fYV8/6gBgVm79vJZ46/Nj0Y6stFqjo776byCQD4OtTjr1lUpTzT0KpL7+Ue bTWk2fnQx59gWu05nNKZjq1+EW3k06c= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=J7syLfgL; dmarc=none; spf=none (imf18.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687365972; a=rsa-sha256; cv=none; b=c7DUP4jGdJhlC4xen6SGFc/cEtws+RxceUJGsUE/7b9TFtJj8A5LtGHz5gJAe9kNg7FxnO MpRxAnoLP/mJdCBbziuAgIzQAmqt7SR9CKshiaMz4yghdXZ/yMeCUJSflSZLZ7YOpyN5pm Pi0mWDJk4LP0LZYXi4BpMBBANWoaQZY= 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 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 334441C0020 X-Stat-Signature: jfq96gtdkf5hdufee9n4jectcz11fark X-Rspam-User: X-HE-Tag: 1687365971-647013 X-HE-Meta: U2FsdGVkX19W7CDOmaVHOgH3OUnJo0B1fAjMOT9D5sD1+N5y41uO137QioUmfJ3lvaZVTvCukjQnU+Fhn5YcRw9hbEduXSzLECi078Hb+GOq9jAl6TzBoe54rjxl1qhwmKx1wRweX4M9rWVxjdrYQMxcTVFGD5gV2As+yirNYJLF6/dvikoh8fPX1ECcGAFRZ8vzYmws3Ffkwhxwlns4+oTPXo/wlN+qpwYNEpiToXUxCUjy5rrlHS+JLu03EzupZA1gCsv+fSZEiKdsiGV0H+9viFR9P8WZ75aPS1OBpe8knXtxaM4Uy11JJLEVPXBKku34+FpNWdIoBWz+iiw54btualC27bQq5uaWHbf1vQ4vmpMcHoV3918DIM72T/RnrfYsIlEq7UhxrVMyLKF5vE55YNcuo1m112hQwgwjFNgFttBIaeQfqxV7AWsAJhW1J0CyPc+/0D4GZPaaVn9zDpN4njoIC/Li8GfN3lotOxuVVE5frL+t49pC/Au5g0NdmHdnE+2ZWpc+MHRhN2sHqorSt79oa6+TfFhZmkyeQW41k0/2VuSEm7+P4xnPfl+UW35/2Ik9QE1yYQQfxVDneblRDtEpxli9pkpupwhTQ8eYPRkca/DMhW0K9CZsfUxaSp/jgtDcH0oPYD+jwefvy/lC8esJGzaVbtXO2MHx52WPWrfJ0rolCrs3zCm+eci11b5cZPHXs5cU9zVBQ+bNJQ55XlCaBOXTKGYwQthPDUOJwu4FllbG4XL6eZFLF8lbj65R8nqOxlMySccsXMZpeddnFlhbO4HWZA9vweulhCSwGhpXFSr6Xu5ZwxHwzPfKeH/GWp6X2VGqB/fY62NP6Hvd21LX6i+a0+drmly9I4zY9SCJer2870k5rEEuSHnStg93V7hPyf5+nHmyDEfGZR0Nc6mimJcDQdIy/VpTKeyeuO0RnHxD8ONphki0CjsHU4pBh3VJHGhlcaNM7tH 7SJCe6KF yrznih33oK8j1QQefgo7d7gBE+C5EEnYMDJPp3pY5cGW+o1oszAn0ske1E26quWRobKjlKz3so4R5aSLVV6ghCQAHfQAF3pS272G/7myZToGgalQtbzNffzkwe6m8n8gmXEp/sOP0nek2f0p6mzj5qCN0ODRznu0oRXD6/RpWYKq4szgnJ5dD0cLiqHAMyCDMfQoOpCtzeYvGZZa+7JKsE8uRXlg075Te7TeS X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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