From patchwork Thu Aug 10 16:00:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 1819940 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=kCTR0kX9; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMBVv3HtDz1yYC for ; Fri, 11 Aug 2023 02:01:27 +1000 (AEST) 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=41YD/fSlwa9Yi3mQeKcVYqAsvS7ccdS7TXKTWlIfYWg=; b=kCTR0kX9pRLA04 TLJiebh/5OCPJaor9Sl/lNP45DgPTHtZC/nGMhlmhDgoe8SnqUQmRxq+c3sjQ6uiHi9jNWWpCX8mQ ZkvdK8GpK0N0APINcVxYMriRC2D/JvoVq/yrm5n8uBvf4nnyTZ7wvKiOWsE5jSUu/O5IBgtiqcvPS sezWw+Uikl1EyRp+zDxrVb+mnw5XQWLWfJ/MTmfrdk8NYUFqAVc1mcDxUMXYsOY4EUHRvIb4Cw4S0 4KtfeEFjRDNEQboAjzaIg1eY3t3Cd0asnqKct8jTrSS23qofNb3wkM4021KQ5XzrEV6ZILy8EadMi MVMvmriUlJgtj9QqTQQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU85j-0086lZ-17; Thu, 10 Aug 2023 16:00:51 +0000 Received: from lithops.sigma-star.at ([195.201.40.130]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qU85c-0086eh-0B for linux-mtd@lists.infradead.org; Thu, 10 Aug 2023 16:00:47 +0000 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id CC647635D290; Thu, 10 Aug 2023 18:00:38 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 98qcvanlYtQc; Thu, 10 Aug 2023 18:00:38 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 34314635D2A1; Thu, 10 Aug 2023 18:00:38 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xBBmf1iN98Fa; Thu, 10 Aug 2023 18:00:38 +0200 (CEST) Received: from foxxylove.corp.sigma-star.at (unknown [82.150.214.1]) by lithops.sigma-star.at (Postfix) with ESMTPSA id C5849635D290; Thu, 10 Aug 2023 18:00:37 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: Christoph Hellwig , Stephan Wurm , Richard Weinberger , stable@vger.kernel.org, Miquel Raynal , Vignesh Raghavendra , Oliver Neukum , Ali Akcaagac , Jamie Lenehan , "James E.J. Bottomley" , "Martin K. Petersen" , Ezequiel Garcia , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 1/7] ubi: block: Refactor sg list processing for highmem Date: Thu, 10 Aug 2023 18:00:12 +0200 Message-Id: <20230810160019.16977-2-richard@nod.at> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230810160019.16977-1-richard@nod.at> References: <20230810160019.16977-1-richard@nod.at> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_090044_423726_B6611162 X-CRM114-Status: GOOD ( 25.21 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Currently sg_virt() is used while filling the sg list from LEB data. This approach cannot work with highmem. Refactor ubi_eba_read_leb_sg() to use kmap_atomic() for sg list access. Since kmap_atomic() disables preempt a bounce buffer is needed. kmap_local_page() is not used to allow easy backporting of this [...] Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Currently sg_virt() is used while filling the sg list from LEB data. This approach cannot work with highmem. Refactor ubi_eba_read_leb_sg() to use kmap_atomic() for sg list access. Since kmap_atomic() disables preempt a bounce buffer is needed. kmap_local_page() is not used to allow easy backporting of this patch to older kernels. The followup patches in this series will switch to kmap_sg() and we can remove our own helper and the bounce buffer. Cc: stable@vger.kernel.org Fixes: 9ff08979e1742 ("UBI: Add initial support for scatter gather") Reported-by: Stephan Wurm Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/block.c | 11 ++--- drivers/mtd/ubi/eba.c | 95 ++++++++++++++++++++++++++++------------- include/linux/mtd/ubi.h | 12 +++--- 3 files changed, 76 insertions(+), 42 deletions(-) diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c index 437c5b83ffe51..5b2e6c74ac5a8 100644 --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c @@ -193,13 +193,10 @@ static blk_status_t ubiblock_read(struct request *req) blk_mq_start_request(req); - /* - * It is safe to ignore the return value of blk_rq_map_sg() because - * the number of sg entries is limited to UBI_MAX_SG_COUNT - * and ubi_read_sg() will check that limit. - */ ubi_sgl_init(&pdu->usgl); - blk_rq_map_sg(req->q, req, pdu->usgl.sg); + ret = blk_rq_map_sg(req->q, req, pdu->usgl.sg); + ubi_assert(ret > 0 && ret < UBI_MAX_SG_COUNT); + pdu->usgl.len = ret; while (bytes_left) { /* @@ -212,7 +209,7 @@ static blk_status_t ubiblock_read(struct request *req) ret = ubi_read_sg(dev->desc, leb, &pdu->usgl, offset, to_read); if (ret < 0) break; - + pdu->usgl.tot_offset += to_read; bytes_left -= to_read; to_read = bytes_left; leb += 1; diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c index 655ff41863e2b..82c54bf7c2067 100644 --- a/drivers/mtd/ubi/eba.c +++ b/drivers/mtd/ubi/eba.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "ubi.h" /* Number of physical eraseblocks reserved for atomic LEB change operation */ @@ -730,6 +731,44 @@ int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, return err; } +/* + * Basically a copy of scsi_kmap_atomic_sg(). + * As long scsi_kmap_atomic_sg() is not part of lib/scatterlist.c have + * our own version to avoid a dependency on CONFIG_SCSI. + */ +static void *ubi_kmap_atomic_sg(struct scatterlist *sgl, int sg_count, + size_t *offset, size_t *len) +{ + int i; + size_t sg_len = 0, len_complete = 0; + struct scatterlist *sg; + struct page *page; + + for_each_sg(sgl, sg, sg_count, i) { + len_complete = sg_len; /* Complete sg-entries */ + sg_len += sg->length; + if (sg_len > *offset) + break; + } + + if (WARN_ON_ONCE(i == sg_count)) + return NULL; + + /* Offset starting from the beginning of first page in this sg-entry */ + *offset = *offset - len_complete + sg->offset; + + /* Assumption: contiguous pages can be accessed as "page + i" */ + page = nth_page(sg_page(sg), (*offset >> PAGE_SHIFT)); + *offset &= ~PAGE_MASK; + + /* Bytes in this sg-entry from *offset to the end of the page */ + sg_len = PAGE_SIZE - *offset; + if (*len > sg_len) + *len = sg_len; + + return kmap_atomic(page); +} + /** * ubi_eba_read_leb_sg - read data into a scatter gather list. * @ubi: UBI device description object @@ -748,40 +787,38 @@ int ubi_eba_read_leb_sg(struct ubi_device *ubi, struct ubi_volume *vol, struct ubi_sgl *sgl, int lnum, int offset, int len, int check) { - int to_read; - int ret; - struct scatterlist *sg; + size_t map_len, map_offset, cur_offset; + int ret, to_read = len; + char *bounce_buf; - for (;;) { - ubi_assert(sgl->list_pos < UBI_MAX_SG_COUNT); - sg = &sgl->sg[sgl->list_pos]; - if (len < sg->length - sgl->page_pos) - to_read = len; - else - to_read = sg->length - sgl->page_pos; - - ret = ubi_eba_read_leb(ubi, vol, lnum, - sg_virt(sg) + sgl->page_pos, offset, - to_read, check); - if (ret < 0) - return ret; - - offset += to_read; - len -= to_read; - if (!len) { - sgl->page_pos += to_read; - if (sgl->page_pos == sg->length) { - sgl->list_pos++; - sgl->page_pos = 0; - } + bounce_buf = kvmalloc(to_read, GFP_KERNEL); + if (!bounce_buf) { + ret = -ENOMEM; + goto out; + } - break; - } + ret = ubi_eba_read_leb(ubi, vol, lnum, bounce_buf, offset, to_read, check); + if (ret < 0) + goto out; + + cur_offset = 0; + while (to_read > 0) { + char *dst; - sgl->list_pos++; - sgl->page_pos = 0; + map_len = to_read; + map_offset = cur_offset + sgl->tot_offset; + + dst = ubi_kmap_atomic_sg(sgl->sg, sgl->len, &map_offset, &map_len); + memcpy(dst + map_offset, bounce_buf + cur_offset, map_len); + kunmap_atomic(dst); + + cur_offset += map_len; + to_read -= map_len; } + ret = 0; +out: + kvfree(bounce_buf); return ret; } diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h index a529347fd75b2..521e0e8b3ede3 100644 --- a/include/linux/mtd/ubi.h +++ b/include/linux/mtd/ubi.h @@ -115,8 +115,8 @@ struct ubi_volume_info { /** * struct ubi_sgl - UBI scatter gather list data structure. - * @list_pos: current position in @sg[] - * @page_pos: current position in @sg[@list_pos] + * @list_len: number of elemtns in @sg[] + * @tot_offset: current position the scatter gather list * @sg: the scatter gather list itself * * ubi_sgl is a wrapper around a scatter list which keeps track of the @@ -124,8 +124,8 @@ struct ubi_volume_info { * it can be used across multiple ubi_leb_read_sg() calls. */ struct ubi_sgl { - int list_pos; - int page_pos; + int len; + int tot_offset; struct scatterlist sg[UBI_MAX_SG_COUNT]; }; @@ -138,8 +138,8 @@ struct ubi_sgl { */ static inline void ubi_sgl_init(struct ubi_sgl *usgl) { - usgl->list_pos = 0; - usgl->page_pos = 0; + usgl->len = 0; + usgl->tot_offset = 0; } /** From patchwork Thu Aug 10 16:00:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 1819937 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ze308bV/; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMBVn0ScFz1yfW for ; Fri, 11 Aug 2023 02:01:21 +1000 (AEST) 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=nKIh2qOW2eCsOQGRm9AJEShdc/wAmhpTH22XSt19MeA=; b=ze308bV/+/cqwe iCMNpAJxgHF2NWOinstcke+avyzp3A8PwvpfhNkFjzfvyVQUdd/eCW4v/5d7isSd7rlkrKOhmQA51 3Sdl5CDdSeeTd7OhPR4Pt8qI0u4SoPy+E+nWm+c5x1RPgC97fTlFZwqh0YQnEd7+mK7TSaW0D0s0o tanJACI2kZPdKCFNT6+pBrk7l4cqJRNkRWEKrPIqrnKwXSjkchVhUPDTMZGAGhl8C8bvZKh0Bswb5 pqec2gp1b32fTKjQnAD4PTjhPo56YYggoga7jckbX2zorBy6cdoHIm8aY36oBtwu8ui4vm0+3VsXN JxdWOYcdk4Ht4TfjipjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU85i-0086l8-2G; Thu, 10 Aug 2023 16:00:50 +0000 Received: from lithops.sigma-star.at ([195.201.40.130]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qU85c-0086ep-1F for linux-mtd@lists.infradead.org; Thu, 10 Aug 2023 16:00:47 +0000 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 88BAB622F562; Thu, 10 Aug 2023 18:00:40 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id EDfStOmQ8fP8; Thu, 10 Aug 2023 18:00:40 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 1C754635D2A1; Thu, 10 Aug 2023 18:00:40 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id yaVTxL2OMKCP; Thu, 10 Aug 2023 18:00:40 +0200 (CEST) Received: from foxxylove.corp.sigma-star.at (unknown [82.150.214.1]) by lithops.sigma-star.at (Postfix) with ESMTPSA id AF6E1635D295; Thu, 10 Aug 2023 18:00:39 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: Christoph Hellwig , Stephan Wurm , Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , Oliver Neukum , Ali Akcaagac , Jamie Lenehan , "James E.J. Bottomley" , "Martin K. Petersen" , Ezequiel Garcia , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 2/7] scatterlist: Add kmap helpers Date: Thu, 10 Aug 2023 18:00:13 +0200 Message-Id: <20230810160019.16977-3-richard@nod.at> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230810160019.16977-1-richard@nod.at> References: <20230810160019.16977-1-richard@nod.at> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_090044_747378_5A63D1AA X-CRM114-Status: GOOD ( 14.53 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: kmap_sg() is basically scsi_kmap_atomic_sg() but uses kmap_local() and does not enforce disabled interrupts. Signed-off-by: Richard Weinberger --- include/linux/scatterlist.h | 3 ++ lib/scatterlist.c | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org kmap_sg() is basically scsi_kmap_atomic_sg() but uses kmap_local() and does not enforce disabled interrupts. Signed-off-by: Richard Weinberger --- include/linux/scatterlist.h | 3 ++ lib/scatterlist.c | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 77df3d7b18a61..dd25a87609491 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -692,4 +692,7 @@ bool sg_miter_skip(struct sg_mapping_iter *miter, off_t offset); bool sg_miter_next(struct sg_mapping_iter *miter); void sg_miter_stop(struct sg_mapping_iter *miter); +void *kmap_sg(struct scatterlist *sgl, int sg_count, size_t *offset, size_t *len); +void kunmap_sg(void *virt); + #endif /* _LINUX_SCATTERLIST_H */ diff --git a/lib/scatterlist.c b/lib/scatterlist.c index e86231a44c3de..7428d9461711d 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -1364,3 +1364,58 @@ ssize_t extract_iter_to_sg(struct iov_iter *iter, size_t maxsize, } } EXPORT_SYMBOL_GPL(extract_iter_to_sg); + +/** + * kmap_sg - find and kmap an sg-elemnt + * @sgl: scatter-gather list + * @sg_count: number of segments in sg + * @offset: offset in bytes into sg, on return offset into the mapped area + * @len: bytes to map, on return number of bytes mapped + * + * Returns virtual address of the start of the mapped page + */ +void *kmap_sg(struct scatterlist *sgl, int sg_count, size_t *offset, size_t *len) +{ + int i; + size_t sg_len = 0, len_complete = 0; + struct scatterlist *sg; + struct page *page; + + for_each_sg(sgl, sg, sg_count, i) { + len_complete = sg_len; /* Complete sg-entries */ + sg_len += sg->length; + if (sg_len > *offset) + break; + } + + if (WARN_ON_ONCE(i == sg_count)) { + pr_err("%s: Bytes in sg: %zu, requested offset %zu, elements %d\n", + __func__, sg_len, *offset, sg_count); + return NULL; + } + + /* Offset starting from the beginning of first page in this sg-entry */ + *offset = *offset - len_complete + sg->offset; + + /* Assumption: contiguous pages can be accessed as "page + i" */ + page = nth_page(sg_page(sg), (*offset >> PAGE_SHIFT)); + *offset &= ~PAGE_MASK; + + /* Bytes in this sg-entry from *offset to the end of the page */ + sg_len = PAGE_SIZE - *offset; + if (*len > sg_len) + *len = sg_len; + + return kmap_local_page(page); +} +EXPORT_SYMBOL(kmap_sg); + +/** + * kunmap_sg - atomically unmap a virtual address, previously mapped with kmap_sg + * @virt: virtual address to be unmapped + */ +void kunmap_sg(void *virt) +{ + kunmap_local(virt); +} +EXPORT_SYMBOL(kunmap_sg); From patchwork Thu Aug 10 16:00:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 1819935 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=pWbFWizU; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMBVl7170z1yYC for ; Fri, 11 Aug 2023 02:01:19 +1000 (AEST) 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=Mma6/41E3jusOudNgoCk1JLbveSkQS+oylahfrX2sGw=; b=pWbFWizUvHMJ/a i0czaUkY8/kDWhTUkoYNX39sQtVlhCyjwaPsmEhuguR9TLVUlZk9ccFf92m70TvvNPKcx04SKtdbK PQ+eZDnpLFLdDJFHhHMXF/wo5aenHAxsnJ/QvduvEKfUgrWO20l2vJ65CBInXEvEcQzGi3PGHpSd7 JgPeP27lY4ei1Apjf+nR9p2bcgFtkTxufQ76pjGzzIbuXcdMD9awMApIPqDZb+tFonyGr/XZtMfa5 b0IyJ4LvpxSy5qdSNDosTdN/JgcFGKdkkBlIBgZsKJ2Wm9/fOxcP8O1tmPsrCqozGh4sSqkC/xhvz xCwb2zpPI3AzCURhY7tg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU85k-0086mR-0C; Thu, 10 Aug 2023 16:00:52 +0000 Received: from lithops.sigma-star.at ([195.201.40.130]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qU85d-0086et-0b for linux-mtd@lists.infradead.org; Thu, 10 Aug 2023 16:00:48 +0000 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 63D92622F56E; Thu, 10 Aug 2023 18:00:42 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id HGDQ1P6SpJc5; Thu, 10 Aug 2023 18:00:42 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id EC415622F592; Thu, 10 Aug 2023 18:00:41 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 5wGKZt-JMm6Y; Thu, 10 Aug 2023 18:00:41 +0200 (CEST) Received: from foxxylove.corp.sigma-star.at (unknown [82.150.214.1]) by lithops.sigma-star.at (Postfix) with ESMTPSA id 9000E622F56E; Thu, 10 Aug 2023 18:00:41 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: Christoph Hellwig , Stephan Wurm , Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , Oliver Neukum , Ali Akcaagac , Jamie Lenehan , "James E.J. Bottomley" , "Martin K. Petersen" , Ezequiel Garcia , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 3/7] scsi: dc395x: Switch to kmap_sg Date: Thu, 10 Aug 2023 18:00:14 +0200 Message-Id: <20230810160019.16977-4-richard@nod.at> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230810160019.16977-1-richard@nod.at> References: <20230810160019.16977-1-richard@nod.at> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_090045_562863_26BE1B53 X-CRM114-Status: GOOD ( 12.28 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Switch to our new helper from scatterlist lib. No functional change, the mapped region is still used in atomic context. Maybe local_irq_save() can be dropped, but I don't know this driver well enough. Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Switch to our new helper from scatterlist lib. No functional change, the mapped region is still used in atomic context. Maybe local_irq_save() can be dropped, but I don't know this driver well enough. Signed-off-by: Richard Weinberger --- drivers/scsi/dc395x.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c index c8e86f8a631eb..4a4e7a35328b9 100644 --- a/drivers/scsi/dc395x.c +++ b/drivers/scsi/dc395x.c @@ -2122,7 +2122,7 @@ static void data_in_phase0(struct AdapterCtlBlk *acb, struct ScsiReqBlk *srb, local_irq_save(flags); /* Assumption: it's inside one page as it's at most 4 bytes and I just assume it's on a 4-byte boundary */ - base = scsi_kmap_atomic_sg(scsi_sglist(srb->cmd), + base = kmap_sg(scsi_sglist(srb->cmd), srb->sg_count, &offset, &len); virt = base + offset; @@ -2165,7 +2165,7 @@ static void data_in_phase0(struct AdapterCtlBlk *acb, struct ScsiReqBlk *srb, DC395x_write8(acb, TRM_S1040_SCSI_CONFIG2, 0); } - scsi_kunmap_atomic_sg(base); + kunmap_sg(base); local_irq_restore(flags); } /*printk(" %08x", *(u32*)(bus_to_virt (addr))); */ @@ -2339,7 +2339,7 @@ static void data_io_transfer(struct AdapterCtlBlk *acb, local_irq_save(flags); /* Again, max 4 bytes */ - base = scsi_kmap_atomic_sg(scsi_sglist(srb->cmd), + base = kmap_sg(scsi_sglist(srb->cmd), srb->sg_count, &offset, &len); virt = base + offset; @@ -2354,7 +2354,7 @@ static void data_io_transfer(struct AdapterCtlBlk *acb, sg_subtract_one(srb); } - scsi_kunmap_atomic_sg(base); + kunmap_sg(base); local_irq_restore(flags); } if (srb->dcb->sync_period & WIDE_SYNC) { @@ -3290,7 +3290,7 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, size_t offset = 0, len = sizeof(struct ScsiInqData); local_irq_save(flags); - base = scsi_kmap_atomic_sg(sg, scsi_sg_count(cmd), &offset, &len); + base = kmap_sg(sg, scsi_sg_count(cmd), &offset, &len); ptr = (struct ScsiInqData *)(base + offset); if (!ckc_only && get_host_byte(cmd) == DID_OK @@ -3308,7 +3308,7 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, } } - scsi_kunmap_atomic_sg(base); + kunmap_sg(base); local_irq_restore(flags); } From patchwork Thu Aug 10 16:00:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 1819938 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=altAFYwM; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMBVt2tDnz1yYC for ; Fri, 11 Aug 2023 02:01:26 +1000 (AEST) 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=8bWsdri5vYjTMpPeAY19pGUO1h/EHAJflteOzxYdbkU=; b=altAFYwMXaXHI+ Kai5n2hSy7tKEHROiNHIPDTOfG2Ub3DbEs6nHywOVc/Nwngn5UdW2FIn1nHpErU90PEHvQ/vS7AYk YwWk1CmHGkz2JgFOeiq8mFSK01rb+wqkRFinRdMegJxjfgB9oElwq6qMd9yrkkLHwiIl7RzP92EiF UqyehNnM/az5Lt8IXPIok8JQlJvyg4NEExmRE6N5s8eSEcwllXr5c745j3GQ1hL6tuF9mBTffdsXn pRdBcWFJo08+BGlmOh651tF0h1tOQt38RSlOdBhmqk2MZRSB5mTOYYhSx2NjiJWUZtztIUSHox6eL xP6NIbO55gdfN46XutIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU85i-0086kq-0P; Thu, 10 Aug 2023 16:00:50 +0000 Received: from lithops.sigma-star.at ([195.201.40.130]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qU85d-0086fr-1A for linux-mtd@lists.infradead.org; Thu, 10 Aug 2023 16:00:47 +0000 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 1FC74635D2A1; Thu, 10 Aug 2023 18:00:44 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id IScXaYrAKO0A; Thu, 10 Aug 2023 18:00:43 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id C9DCB635D29F; Thu, 10 Aug 2023 18:00:43 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Xcer7PJILGKE; Thu, 10 Aug 2023 18:00:43 +0200 (CEST) Received: from foxxylove.corp.sigma-star.at (unknown [82.150.214.1]) by lithops.sigma-star.at (Postfix) with ESMTPSA id 6F83C635D296; Thu, 10 Aug 2023 18:00:43 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: Christoph Hellwig , Stephan Wurm , Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , Oliver Neukum , Ali Akcaagac , Jamie Lenehan , "James E.J. Bottomley" , "Martin K. Petersen" , Ezequiel Garcia , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 4/7] scsi: esp_scsi: Switch to kmap_sg Date: Thu, 10 Aug 2023 18:00:15 +0200 Message-Id: <20230810160019.16977-5-richard@nod.at> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230810160019.16977-1-richard@nod.at> References: <20230810160019.16977-1-richard@nod.at> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_090045_555657_848848B4 X-CRM114-Status: GOOD ( 11.15 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Switch to our new helper from scatterlist lib. No functional change, the mapped region is still used in atomic context. Signed-off-by: Richard Weinberger --- drivers/scsi/esp_scsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Switch to our new helper from scatterlist lib. No functional change, the mapped region is still used in atomic context. Signed-off-by: Richard Weinberger --- drivers/scsi/esp_scsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c index 97816a0e6240a..10d2fcf65f28a 100644 --- a/drivers/scsi/esp_scsi.c +++ b/drivers/scsi/esp_scsi.c @@ -1355,11 +1355,11 @@ static int esp_data_bytes_sent(struct esp *esp, struct esp_cmd_entry *ent, struct esp_cmd_priv *p = ESP_CMD_PRIV(cmd); u8 *ptr; - ptr = scsi_kmap_atomic_sg(p->cur_sg, p->num_sg, + ptr = kmap_sg(p->cur_sg, p->num_sg, &offset, &count); if (likely(ptr)) { *(ptr + offset) = bval; - scsi_kunmap_atomic_sg(ptr); + kunmap_sg(ptr); } } bytes_sent += fifo_cnt; From patchwork Thu Aug 10 16:00:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 1819933 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=brSDpjo9; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMBVl1ymMz1yYC for ; Fri, 11 Aug 2023 02:01:19 +1000 (AEST) 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=WEAyO5IgI10912zxbmPOLaXpMeGaJnOykN4XBQYkgZM=; b=brSDpjo9IgakSC ZeRUd3YeChvPogWiQdMahWZO5l47ryxfFDBaWCJke1eHIRcjwqfyhffE3m1aH2AKIPOt/dHzgTDkc RI86t/prz3lTckkgWzkYVqjT09buCRcQuLxX8rCZcDBtq+nYw67czYwMp21MlKJqI+4zew5RymDvp e48aHvnB+T3oyPTSxDYLaNTqiqwbzA0gEqAvQDRK498uIeJj88Kq06+D3pNA4vV4Zv8nFIcQgknCY voUOk9FwDAEtKu78k39EH1+Nzbf4iqkVaRt4btmVPvGfS2D2y0sSw0jO9+tTR2+1BI8rcl21R0QaX ZnpKd+p1i4Hlkg6YrYbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU85k-0086mt-23; Thu, 10 Aug 2023 16:00:52 +0000 Received: from lithops.sigma-star.at ([195.201.40.130]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qU85f-0086hY-1E for linux-mtd@lists.infradead.org; Thu, 10 Aug 2023 16:00:48 +0000 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 0E84B635D29A; Thu, 10 Aug 2023 18:00:46 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id i2OBkMkvY2wu; Thu, 10 Aug 2023 18:00:45 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id B1424635D2A8; Thu, 10 Aug 2023 18:00:45 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id vNycAkqY1e7l; Thu, 10 Aug 2023 18:00:45 +0200 (CEST) Received: from foxxylove.corp.sigma-star.at (unknown [82.150.214.1]) by lithops.sigma-star.at (Postfix) with ESMTPSA id 55000635D296; Thu, 10 Aug 2023 18:00:45 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: Christoph Hellwig , Stephan Wurm , Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , Oliver Neukum , Ali Akcaagac , Jamie Lenehan , "James E.J. Bottomley" , "Martin K. Petersen" , Ezequiel Garcia , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 5/7] scsi: fdomain: Switch to kmap_sg Date: Thu, 10 Aug 2023 18:00:16 +0200 Message-Id: <20230810160019.16977-6-richard@nod.at> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230810160019.16977-1-richard@nod.at> References: <20230810160019.16977-1-richard@nod.at> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_090047_589337_C0C67CB2 X-CRM114-Status: GOOD ( 10.99 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Switch to our new helper from scatterlist lib. No functional change, the mapped region is still used in atomic context. Signed-off-by: Richard Weinberger --- drivers/scsi/fdomain.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Switch to our new helper from scatterlist lib. No functional change, the mapped region is still used in atomic context. Signed-off-by: Richard Weinberger --- drivers/scsi/fdomain.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/fdomain.c b/drivers/scsi/fdomain.c index 504c4e0c5d17a..5d58a9ec1c66a 100644 --- a/drivers/scsi/fdomain.c +++ b/drivers/scsi/fdomain.c @@ -223,15 +223,14 @@ static void fdomain_read_data(struct scsi_cmnd *cmd) while ((len = inw(fd->base + REG_FIFO_COUNT)) > 0) { offset = scsi_bufflen(cmd) - scsi_get_resid(cmd); - virt = scsi_kmap_atomic_sg(scsi_sglist(cmd), scsi_sg_count(cmd), - &offset, &len); + virt = kmap_sg(scsi_sglist(cmd), scsi_sg_count(cmd), &offset, &len); ptr = virt + offset; if (len & 1) *ptr++ = inb(fd->base + REG_FIFO); if (len > 1) insw(fd->base + REG_FIFO, ptr, len >> 1); scsi_set_resid(cmd, scsi_get_resid(cmd) - len); - scsi_kunmap_atomic_sg(virt); + kunmap_sg(virt); } } @@ -250,15 +249,14 @@ static void fdomain_write_data(struct scsi_cmnd *cmd) if (len == 0) break; } - virt = scsi_kmap_atomic_sg(scsi_sglist(cmd), scsi_sg_count(cmd), - &offset, &len); + virt = kmap_sg(scsi_sglist(cmd), scsi_sg_count(cmd), &offset, &len); ptr = virt + offset; if (len & 1) outb(*ptr++, fd->base + REG_FIFO); if (len > 1) outsw(fd->base + REG_FIFO, ptr, len >> 1); scsi_set_resid(cmd, scsi_get_resid(cmd) - len); - scsi_kunmap_atomic_sg(virt); + kunmap_sg(virt); } } From patchwork Thu Aug 10 16:00:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 1819936 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=z+SNCZGV; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMBVl5zlSz1yfp for ; Fri, 11 Aug 2023 02:01:19 +1000 (AEST) 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=U+gEXbVHmV0H7q4xCoac+e0OXTEEdXFeBPJKI2ajFPU=; b=z+SNCZGVpwoZPS QI9fneZaF+ZgqR7yDFW/QDn+2F91s8nL6XpzY9WPlSJ79v2/e6/Ip6bcsf3ECT11+nhQmZqj9kE9o QiY7bbwKc7T5zByp2CTml0lR7KBTlHHVPitig+yVCwscRF9GP6A03RejffW4kRxYs2oyOBNEITl3p NQUqvNxZyOtxGk3JjUP0cIHbjWod6Pn/6tKFmYk3lLAkOCIiHEMp11oGyIgEXgLA5cvtgQXb9mQPA Xtz02M85QWA1LryjBFt6ZjsWmCzaVJXMpxT7LuKZK6JmIBOeMFwP2+Sfm6//pkud2iJ4FRqH7ftRP qvtW2g7WdiT7BlK3sGaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU85m-0086nq-1E; Thu, 10 Aug 2023 16:00:54 +0000 Received: from lithops.sigma-star.at ([195.201.40.130]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qU85h-0086jE-18 for linux-mtd@lists.infradead.org; Thu, 10 Aug 2023 16:00:50 +0000 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 13F5C635D2A4; Thu, 10 Aug 2023 18:00:48 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id bugUimCkv4m6; Thu, 10 Aug 2023 18:00:47 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 9720F635D2A2; Thu, 10 Aug 2023 18:00:47 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id NfQzJITzRPaO; Thu, 10 Aug 2023 18:00:47 +0200 (CEST) Received: from foxxylove.corp.sigma-star.at (unknown [82.150.214.1]) by lithops.sigma-star.at (Postfix) with ESMTPSA id 386F5635D296; Thu, 10 Aug 2023 18:00:47 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: Christoph Hellwig , Stephan Wurm , Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , Oliver Neukum , Ali Akcaagac , Jamie Lenehan , "James E.J. Bottomley" , "Martin K. Petersen" , Ezequiel Garcia , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 6/7] ubi: block: Switch to kmap_sg Date: Thu, 10 Aug 2023 18:00:17 +0200 Message-Id: <20230810160019.16977-7-richard@nod.at> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230810160019.16977-1-richard@nod.at> References: <20230810160019.16977-1-richard@nod.at> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_090049_693630_BE478BAD X-CRM114-Status: GOOD ( 16.17 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Remove our copy of scsi_kmap_atomic_sg() and use the new helper kmap_sg(). Since it is based on kmap_local() we can remove the bounce buffer and perform IO while we hold the mapping. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/eba.c | 59 +++++ 1 file changed, 6 insertions(+), 53 deletions(-) Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Remove our copy of scsi_kmap_atomic_sg() and use the new helper kmap_sg(). Since it is based on kmap_local() we can remove the bounce buffer and perform IO while we hold the mapping. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/eba.c | 59 +++++-------------------------------------- 1 file changed, 6 insertions(+), 53 deletions(-) diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c index 82c54bf7c2067..650eacab27f03 100644 --- a/drivers/mtd/ubi/eba.c +++ b/drivers/mtd/ubi/eba.c @@ -731,44 +731,6 @@ int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, return err; } -/* - * Basically a copy of scsi_kmap_atomic_sg(). - * As long scsi_kmap_atomic_sg() is not part of lib/scatterlist.c have - * our own version to avoid a dependency on CONFIG_SCSI. - */ -static void *ubi_kmap_atomic_sg(struct scatterlist *sgl, int sg_count, - size_t *offset, size_t *len) -{ - int i; - size_t sg_len = 0, len_complete = 0; - struct scatterlist *sg; - struct page *page; - - for_each_sg(sgl, sg, sg_count, i) { - len_complete = sg_len; /* Complete sg-entries */ - sg_len += sg->length; - if (sg_len > *offset) - break; - } - - if (WARN_ON_ONCE(i == sg_count)) - return NULL; - - /* Offset starting from the beginning of first page in this sg-entry */ - *offset = *offset - len_complete + sg->offset; - - /* Assumption: contiguous pages can be accessed as "page + i" */ - page = nth_page(sg_page(sg), (*offset >> PAGE_SHIFT)); - *offset &= ~PAGE_MASK; - - /* Bytes in this sg-entry from *offset to the end of the page */ - sg_len = PAGE_SIZE - *offset; - if (*len > sg_len) - *len = sg_len; - - return kmap_atomic(page); -} - /** * ubi_eba_read_leb_sg - read data into a scatter gather list. * @ubi: UBI device description object @@ -789,17 +751,6 @@ int ubi_eba_read_leb_sg(struct ubi_device *ubi, struct ubi_volume *vol, { size_t map_len, map_offset, cur_offset; int ret, to_read = len; - char *bounce_buf; - - bounce_buf = kvmalloc(to_read, GFP_KERNEL); - if (!bounce_buf) { - ret = -ENOMEM; - goto out; - } - - ret = ubi_eba_read_leb(ubi, vol, lnum, bounce_buf, offset, to_read, check); - if (ret < 0) - goto out; cur_offset = 0; while (to_read > 0) { @@ -808,9 +759,12 @@ int ubi_eba_read_leb_sg(struct ubi_device *ubi, struct ubi_volume *vol, map_len = to_read; map_offset = cur_offset + sgl->tot_offset; - dst = ubi_kmap_atomic_sg(sgl->sg, sgl->len, &map_offset, &map_len); - memcpy(dst + map_offset, bounce_buf + cur_offset, map_len); - kunmap_atomic(dst); + dst = kmap_sg(sgl->sg, sgl->len, &map_offset, &map_len); + ret = ubi_eba_read_leb(ubi, vol, lnum, dst + map_offset, offset + cur_offset, + map_len, check); + if (ret < 0) + goto out; + kunmap_sg(dst); cur_offset += map_len; to_read -= map_len; @@ -818,7 +772,6 @@ int ubi_eba_read_leb_sg(struct ubi_device *ubi, struct ubi_volume *vol, ret = 0; out: - kvfree(bounce_buf); return ret; } From patchwork Thu Aug 10 16:00:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 1819934 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=YOk1daYS; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMBVl2tcWz1yfW for ; Fri, 11 Aug 2023 02:01:19 +1000 (AEST) 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=3V/GqxhN8PRvj/3vok9nkpo9ZtwSg/XBQEXi1ZolPYo=; b=YOk1daYSFcadgW mDCpK1vo16DhmBtYmMRve/F5vAjjJyLYA8SWy9rItun9SLj8oV/WjausJp50bpnhA1ZW4JIXYucE0 H0FdpiL0EJACJD4FGV8U8UbApWh41dZFD85yRnmWNORfnvWaYCQzfpfhZmXpv+VRdaZ32E2yRhUdB /X/ehT8LHdedy/MOMBn2Akg9jO2M5jPlJCPTIJ/B98gwG1ujcgtXmwGkCLnzgpI0h7utqU595pJGT M3oxEZHNImw9HO+VAe7i6G0bk7TvhULcwpdyAa7At0W4do8hpQdmEmhLP3IoOmpI4sb1HUu9WuRbZ ZfTv971g7edAjrTW5Mug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU85m-0086o8-35; Thu, 10 Aug 2023 16:00:54 +0000 Received: from lithops.sigma-star.at ([195.201.40.130]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qU85j-0086kw-0P for linux-mtd@lists.infradead.org; Thu, 10 Aug 2023 16:00:52 +0000 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id D890A635D2A8; Thu, 10 Aug 2023 18:00:49 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id id0-MKyNRELX; Thu, 10 Aug 2023 18:00:49 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 7B8F6635D2A2; Thu, 10 Aug 2023 18:00:49 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id NtQ5uhq1a5o1; Thu, 10 Aug 2023 18:00:49 +0200 (CEST) Received: from foxxylove.corp.sigma-star.at (unknown [82.150.214.1]) by lithops.sigma-star.at (Postfix) with ESMTPSA id 10ECD635D29F; Thu, 10 Aug 2023 18:00:49 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: Christoph Hellwig , Stephan Wurm , Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , Oliver Neukum , Ali Akcaagac , Jamie Lenehan , "James E.J. Bottomley" , "Martin K. Petersen" , Ezequiel Garcia , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 7/7] scsi: core: Remove scsi_kmap_atomic_sg() Date: Thu, 10 Aug 2023 18:00:18 +0200 Message-Id: <20230810160019.16977-8-richard@nod.at> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230810160019.16977-1-richard@nod.at> References: <20230810160019.16977-1-richard@nod.at> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_090051_488488_D67C27BB X-CRM114-Status: GOOD ( 12.14 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: All users have been migrated to use kmap_sg(), let's kill this helper. Signed-off-by: Richard Weinberger --- drivers/scsi/scsi_lib.c | 60 include/scsi/scsi_cmnd.h | 4 --- 2 files changed, 64 deletions(-) Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org All users have been migrated to use kmap_sg(), let's kill this helper. Signed-off-by: Richard Weinberger --- drivers/scsi/scsi_lib.c | 60 ---------------------------------------- include/scsi/scsi_cmnd.h | 4 --- 2 files changed, 64 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index ad9afae49544a..70469502aeb76 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -3001,66 +3001,6 @@ scsi_host_unblock(struct Scsi_Host *shost, int new_state) } EXPORT_SYMBOL_GPL(scsi_host_unblock); -/** - * scsi_kmap_atomic_sg - find and atomically map an sg-elemnt - * @sgl: scatter-gather list - * @sg_count: number of segments in sg - * @offset: offset in bytes into sg, on return offset into the mapped area - * @len: bytes to map, on return number of bytes mapped - * - * Returns virtual address of the start of the mapped page - */ -void *scsi_kmap_atomic_sg(struct scatterlist *sgl, int sg_count, - size_t *offset, size_t *len) -{ - int i; - size_t sg_len = 0, len_complete = 0; - struct scatterlist *sg; - struct page *page; - - WARN_ON(!irqs_disabled()); - - for_each_sg(sgl, sg, sg_count, i) { - len_complete = sg_len; /* Complete sg-entries */ - sg_len += sg->length; - if (sg_len > *offset) - break; - } - - if (unlikely(i == sg_count)) { - printk(KERN_ERR "%s: Bytes in sg: %zu, requested offset %zu, " - "elements %d\n", - __func__, sg_len, *offset, sg_count); - WARN_ON(1); - return NULL; - } - - /* Offset starting from the beginning of first page in this sg-entry */ - *offset = *offset - len_complete + sg->offset; - - /* Assumption: contiguous pages can be accessed as "page + i" */ - page = nth_page(sg_page(sg), (*offset >> PAGE_SHIFT)); - *offset &= ~PAGE_MASK; - - /* Bytes in this sg-entry from *offset to the end of the page */ - sg_len = PAGE_SIZE - *offset; - if (*len > sg_len) - *len = sg_len; - - return kmap_atomic(page); -} -EXPORT_SYMBOL(scsi_kmap_atomic_sg); - -/** - * scsi_kunmap_atomic_sg - atomically unmap a virtual address, previously mapped with scsi_kmap_atomic_sg - * @virt: virtual address to be unmapped - */ -void scsi_kunmap_atomic_sg(void *virt) -{ - kunmap_atomic(virt); -} -EXPORT_SYMBOL(scsi_kunmap_atomic_sg); - void sdev_disable_disk_events(struct scsi_device *sdev) { atomic_inc(&sdev->disk_events_disable_depth); diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 526def14e7fb7..919ac97229481 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -163,10 +163,6 @@ void scsi_done_direct(struct scsi_cmnd *cmd); extern void scsi_finish_command(struct scsi_cmnd *cmd); -extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count, - size_t *offset, size_t *len); -extern void scsi_kunmap_atomic_sg(void *virt); - blk_status_t scsi_alloc_sgtables(struct scsi_cmnd *cmd); void scsi_free_sgtables(struct scsi_cmnd *cmd);