From patchwork Thu Jan 26 10:33:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13116851 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 04605C05027 for ; Thu, 26 Jan 2023 10:34:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 378F56B0071; Thu, 26 Jan 2023 05:34:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3294B6B0072; Thu, 26 Jan 2023 05:34:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CA388E0001; Thu, 26 Jan 2023 05:34:00 -0500 (EST) 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 0E76C6B0071 for ; Thu, 26 Jan 2023 05:34:00 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C9267120705 for ; Thu, 26 Jan 2023 10:33:59 +0000 (UTC) X-FDA: 80396589798.04.DBB6145 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 048AA40021 for ; Thu, 26 Jan 2023 10:33:57 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=R4FxSqQW; spf=pass (imf04.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674729238; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rqDrgvW0/XSyvREeFRhVWr1s+J3PuS70wJQAmFfHvFE=; b=3qxKQD0AfX7w82cm1trXJJujVm0fv17/oYvMZg0KRnnXazzLX3U0i6gmRLJMQy+pI+vvVG pjuaq1x2A1oRcJoJxYTRFFm0G8aOUjHedOXobSQUX1yMNsQSoCADhB8DE8ndWpPCGo/aqI iWuvDr55JjCDAnvaQUiBLOApYLS6MyA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=R4FxSqQW; spf=pass (imf04.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674729238; a=rsa-sha256; cv=none; b=7Q+pFoYtS4QJq1FLcEFdN3O3gd34UlAnMRZD4MA1MW5AUypn6YZ3NVzbQ+GZauXqJqgpYP 7kE4F91jreU+ldX57imZHkG2gMLTjY3O3vU+neQYtuTkWBSWx/RzjlezEd3dX3syiRJO/T ayio3xUWuueLxqKsfKYFNG8v0RJdliM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674729237; 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=rqDrgvW0/XSyvREeFRhVWr1s+J3PuS70wJQAmFfHvFE=; b=R4FxSqQWCsFBvPgbbQtfJXrT3L5M5Nkia4zmkjECTJcxfLjRUkR10h4rZrZTA0IoZYaDeE jM4Si5JYJuVUNB7KrI5yvRs1Ho1IqILbalmk7RfUp1omqMMkDYPfqVUYeiO5k27wMSFLUL NOR1IxYA/jZd2MrMKazlnmKp4QJ5bAo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-vC3dEYFRPuSe4qxu2tWBmA-1; Thu, 26 Jan 2023 05:33:54 -0500 X-MC-Unique: vC3dEYFRPuSe4qxu2tWBmA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5DD55801779; Thu, 26 Jan 2023 10:33:53 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E2E2492C14; Thu, 26 Jan 2023 10:33:51 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: References: <20230125210657.2335748-1-dhowells@redhat.com> <20230125210657.2335748-2-dhowells@redhat.com> <2613249.1674726566@warthog.procyon.org.uk> To: David Hildenbrand Cc: dhowells@redhat.com, Al Viro , Christoph Hellwig , Matthew Wilcox , Jens Axboe , Jan Kara , Jeff Layton , Jason Gunthorpe , Logan Gunthorpe , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH] iov_iter: Use __bitwise with the extraction_flags MIME-Version: 1.0 Content-ID: <2638927.1674729230.1@warthog.procyon.org.uk> Date: Thu, 26 Jan 2023 10:33:50 +0000 Message-ID: <2638928.1674729230@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Queue-Id: 048AA40021 X-Stat-Signature: tyge81xra6d14jbe8da8rayma9889wtz X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1674729237-815123 X-HE-Meta: U2FsdGVkX195RZWbFn45CzSJnKjiw938QGF+sUJ+KtkfZYRB1pDpHwqKajPuUccfRk6CRCedLekVSUowsVVZXaj5BWwZPnspIN18msaGtbV2k8Ms0jzNbkjtc6X+Fqf2g+CaNErMKTo+xqRM7SKm1UkShg8VeD0gPIuVEp4gqp63VOhJrsqxJVROmfekVNjC3+1CwIiOodgXSFoEMp7lfTjnAPKU8yr9hRS6W5YCcUKEhEmSakdbGorVtmCFQhndlo4LytjiQ9SORY+G2tMHefkZzriRrehK6ABFPTyjq4dbaNQQKeQetkJ+bCcVN9VQMhjPSPIjyJdDud89nVSl6g+W8NSmqQ90rJ5472Jb39pjAmgWwelSdfLnqMETDeC+DQVa+Kd2HMi3jtASRDlPW3gWm8E8+e44UPJjxaSx9X4kbO9q9j8mIEgyx86cUTe54GWwgd1A343cNxxjSwOY2ijOwmHV0cdrc51kN1uVds/NDwt2XxRgj6egfszM96CjQcpiSDkYqBQNgRnk/UGEtbaDIbor/NKg+1U1ly/AnGdCglnUltdV8Pd262EtWd//x8iRZWtT8wbRPPONxl9NUJhWPTZSVJ9fkobLQRaJYKSokEFSYKILW61do5mX1Xw4Cfa93ESl3l1jntghoo+a8SiNgmc6WEFloG19CG7kWCgTvsNWb85fP5oIt6cBAzt+p/IsVWaIysVQ3uIgbiL+UfyUYIlHrKFUr7bsrLV2PhLn9rMEM5nVz6G8qaCVIBezRmTzz3BJNiv0q0hcFnJHnz4UBDcNOjqMM1cIunsuDWk0tXpVrtMMTPZBg4kB2L7veqDlzkWvhLA5VweAMyy7vLnaZQQpot7hialOest5BZHyH0WXwj12jTrj9xo73AiCH/OiqrtBaXJrsipoOh3hgsU6RrV1+yAEf1nIWSkemFNofR5k/gNYm2XcLfeFRgqoj6G1GaZfTbwDSUb22qc sBJWNLpQ 2kdLRdAsX3LO7cAa1iLYdih4Bob6ewtxK5WCqaVaVSy5YwWAMoJcsjGlAiXhcwVu+Dyg5MStqTdgHK8dAPjI2AYAtUK9Fxdu4axLPphr5p7R68DnYmAMRZHjLAFjYVddpNSFuI0bBW7mMgM4sJ77uFeH3tveeLkXQxwnoaxyTb4o4AMPfrmdr6eMF3/Z1B+K8Zt2qsfFa2gU+xuAbLTqW5nJKiyi0g/sMuC/ktaRSzRsOc46jQHs8qAGEZw== 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: X-Mailer: MH-E 8.6+git; nmh 1.7.1; GNU Emacs 28.2 -------- David Hildenbrand wrote: > >> Just a note that the usage of new __bitwise types instead of "unsigned" is > >> encouraged for flags. Something like the attached? > $ git grep "typedef int" | grep __bitwise | wc -l > 27 > $ git grep "typedef unsigned" | grep __bitwise | wc -l > 23 git grep __bitwise | grep typedef | grep __u | wc -l 62 *shrug* Interestingly, things like __be32 are __bitwise. I wonder if that actually makes sense or if it was just convenient so stop people doing arithmetic on them. I guess doing AND/OR/XOR on them isn't a problem provided both arguments are appropriately byte-swapped. David --- block/bio.c | 2 +- block/blk-map.c | 2 +- include/linux/uio.h | 13 ++++++++----- lib/iov_iter.c | 14 +++++++------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/block/bio.c b/block/bio.c index 466956779d2c..fc57f0aa098e 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1244,11 +1244,11 @@ static int bio_iov_add_zone_append_page(struct bio *bio, struct page *page, */ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) { + iov_iter_extraction_t extraction_flags = 0; unsigned short nr_pages = bio->bi_max_vecs - bio->bi_vcnt; unsigned short entries_left = bio->bi_max_vecs - bio->bi_vcnt; struct bio_vec *bv = bio->bi_io_vec + bio->bi_vcnt; struct page **pages = (struct page **)bv; - unsigned int extraction_flags = 0; ssize_t size, left; unsigned len, i = 0; size_t offset, trim; diff --git a/block/blk-map.c b/block/blk-map.c index 9c7ccea3f334..0f1593e144da 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -265,9 +265,9 @@ static struct bio *blk_rq_map_bio_alloc(struct request *rq, static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, gfp_t gfp_mask) { + iov_iter_extraction_t extraction_flags = 0; unsigned int max_sectors = queue_max_hw_sectors(rq->q); unsigned int nr_vecs = iov_iter_npages(iter, BIO_MAX_VECS); - unsigned int extraction_flags = 0; struct bio *bio; int ret; int j; diff --git a/include/linux/uio.h b/include/linux/uio.h index 47ebb59a0202..b1be128bb2fa 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -13,6 +13,8 @@ struct page; struct pipe_inode_info; +typedef unsigned int iov_iter_extraction_t; + struct kvec { void *iov_base; /* and that should *never* hold a userland pointer */ size_t iov_len; @@ -252,12 +254,12 @@ void iov_iter_xarray(struct iov_iter *i, unsigned int direction, struct xarray * loff_t start, size_t count); ssize_t iov_iter_get_pages(struct iov_iter *i, struct page **pages, size_t maxsize, unsigned maxpages, size_t *start, - unsigned extraction_flags); + iov_iter_extraction_t extraction_flags); ssize_t iov_iter_get_pages2(struct iov_iter *i, struct page **pages, size_t maxsize, unsigned maxpages, size_t *start); ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, struct page ***pages, size_t maxsize, size_t *start, - unsigned extraction_flags); + iov_iter_extraction_t extraction_flags); ssize_t iov_iter_get_pages_alloc2(struct iov_iter *i, struct page ***pages, size_t maxsize, size_t *start); int iov_iter_npages(const struct iov_iter *i, int maxpages); @@ -359,13 +361,14 @@ static inline void iov_iter_ubuf(struct iov_iter *i, unsigned int direction, .count = count }; } - /* Flags for iov_iter_get/extract_pages*() */ -#define ITER_ALLOW_P2PDMA 0x01 /* Allow P2PDMA on the extracted pages */ +/* Allow P2PDMA on the extracted pages */ +#define ITER_ALLOW_P2PDMA ((__force iov_iter_extraction_t)0x01) ssize_t iov_iter_extract_pages(struct iov_iter *i, struct page ***pages, size_t maxsize, unsigned int maxpages, - unsigned int extraction_flags, size_t *offset0); + iov_iter_extraction_t extraction_flags, + size_t *offset0); /** * iov_iter_extract_will_pin - Indicate how pages from the iterator will be retained diff --git a/lib/iov_iter.c b/lib/iov_iter.c index cea503b2ec30..d70496019b1d 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1432,7 +1432,7 @@ static struct page *first_bvec_segment(const struct iov_iter *i, static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i, struct page ***pages, size_t maxsize, unsigned int maxpages, size_t *start, - unsigned int extraction_flags) + iov_iter_extraction_t extraction_flags) { unsigned int n, gup_flags = 0; @@ -1929,7 +1929,7 @@ void iov_iter_restore(struct iov_iter *i, struct iov_iter_state *state) static ssize_t iov_iter_extract_pipe_pages(struct iov_iter *i, struct page ***pages, size_t maxsize, unsigned int maxpages, - unsigned int extraction_flags, + iov_iter_extraction_t extraction_flags, size_t *offset0) { unsigned int nr, offset, chunk, j; @@ -1971,7 +1971,7 @@ static ssize_t iov_iter_extract_pipe_pages(struct iov_iter *i, static ssize_t iov_iter_extract_xarray_pages(struct iov_iter *i, struct page ***pages, size_t maxsize, unsigned int maxpages, - unsigned int extraction_flags, + iov_iter_extraction_t extraction_flags, size_t *offset0) { struct page *page, **p; @@ -2017,7 +2017,7 @@ static ssize_t iov_iter_extract_xarray_pages(struct iov_iter *i, static ssize_t iov_iter_extract_bvec_pages(struct iov_iter *i, struct page ***pages, size_t maxsize, unsigned int maxpages, - unsigned int extraction_flags, + iov_iter_extraction_t extraction_flags, size_t *offset0) { struct page **p, *page; @@ -2060,7 +2060,7 @@ static ssize_t iov_iter_extract_bvec_pages(struct iov_iter *i, static ssize_t iov_iter_extract_kvec_pages(struct iov_iter *i, struct page ***pages, size_t maxsize, unsigned int maxpages, - unsigned int extraction_flags, + iov_iter_extraction_t extraction_flags, size_t *offset0) { struct page **p, *page; @@ -2125,7 +2125,7 @@ static ssize_t iov_iter_extract_user_pages(struct iov_iter *i, struct page ***pages, size_t maxsize, unsigned int maxpages, - unsigned int extraction_flags, + iov_iter_extraction_t extraction_flags, size_t *offset0) { unsigned long addr; @@ -2207,7 +2207,7 @@ ssize_t iov_iter_extract_pages(struct iov_iter *i, struct page ***pages, size_t maxsize, unsigned int maxpages, - unsigned int extraction_flags, + iov_iter_extraction_t extraction_flags, size_t *offset0) { maxsize = min_t(size_t, min_t(size_t, maxsize, i->count), MAX_RW_COUNT);