Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp1295336rwl; Thu, 10 Aug 2023 09:06:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMh2rGWDd+x5xM7s7mRrMP/MITR2i8B7C56Xyxh3SaLi+5RfVGZM+dUxKLvg1oiNfNAGzt X-Received: by 2002:a17:907:2671:b0:99b:f554:1f10 with SMTP id ci17-20020a170907267100b0099bf5541f10mr2419473ejc.7.1691683567513; Thu, 10 Aug 2023 09:06:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691683567; cv=none; d=google.com; s=arc-20160816; b=TgzMWxmLVe2panzeqBvtkNYWVkfRVpQ0Es8FC7wHLP8oLbCeMqsFFlYyNscXMO8TrG 792sHKk2DnTKx91saSzdfVZ3yp6fRu52yldY9ubaEmd1pj6Zdt6891GGl1MXliqCvlNE PeFaKnJ8HsBUhOdphVQnCe/pdGX5Az15Ce3mBDfeEue3GG2lzGFWE1fcgu8HwOlXRKR3 l0DlYwIkeHWy6QzjdbIiV7Ei0WnEiZfUg9cQW3hO+JEQ2amruYTk2UwD/kWE3b7HnL4o 0uD6TE2RbWoGIaz05YYWfmmzrEUonn9YyiHRj7TWJzSXH1G3SvlmiGFTKRTip/CjBXv3 R9qQ== 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; bh=yoUiWNm1GsHnZM+VW0NT7u1lNLgOPx9wNdhc9Dmvqz4=; fh=j/1OJ/bcBNVUo7OV9c6EGYwjYba7yxMLNeRPuOJBLLs=; b=s3XYXkk2sjZ+nDYvSHJk7YBBFzSmxmGLlspF9QFPdOHgmGmxR3yQIRDPoDWCOuehU/ 3iu31FNY073UhS3LSSlekNbSJ+R/ZoedLA08Nsr/7L6kT97/K3UuK3Lm/xxgaEsUIkcu QkoW/yB3bsj1cbeo4nw2/sA4bs9HYKzY6glUYXZNoiHAdhXg+Rcp0A2dWA1NWgbf03Xy 66YLomLCauT5+nCcsuQm3Ei0GmcPQ/9d9kjKJn3dARMvq4nyOeuQD4/cvntxXa4fzEpJ rF4XX4fvmazghXeP7/GsQ/PNdxjc4q1+RanU7Z59M/pd0Mk2HJPOfj7FqtRUG1rFS2SY O0gw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 rs22-20020a170907037600b0098d2f718ac3si1691866ejb.609.2023.08.10.09.05.26; Thu, 10 Aug 2023 09:06:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236364AbjHJQBQ (ORCPT + 99 others); Thu, 10 Aug 2023 12:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236300AbjHJQBD (ORCPT ); Thu, 10 Aug 2023 12:01:03 -0400 Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D65C2713; Thu, 10 Aug 2023 09:00:49 -0700 (PDT) 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 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,T_SPF_PERMERROR 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-kernel@vger.kernel.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; } =20 -/* - * 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 =3D 0, len_complete =3D 0; - struct scatterlist *sg; - struct page *page; - - for_each_sg(sgl, sg, sg_count, i) { - len_complete =3D sg_len; /* Complete sg-entries */ - sg_len +=3D sg->length; - if (sg_len > *offset) - break; - } - - if (WARN_ON_ONCE(i =3D=3D sg_count)) - return NULL; - - /* Offset starting from the beginning of first page in this sg-entry */ - *offset =3D *offset - len_complete + sg->offset; - - /* Assumption: contiguous pages can be accessed as "page + i" */ - page =3D nth_page(sg_page(sg), (*offset >> PAGE_SHIFT)); - *offset &=3D ~PAGE_MASK; - - /* Bytes in this sg-entry from *offset to the end of the page */ - sg_len =3D PAGE_SIZE - *offset; - if (*len > sg_len) - *len =3D 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, stru= ct ubi_volume *vol, { size_t map_len, map_offset, cur_offset; int ret, to_read =3D len; - char *bounce_buf; - - bounce_buf =3D kvmalloc(to_read, GFP_KERNEL); - if (!bounce_buf) { - ret =3D -ENOMEM; - goto out; - } - - ret =3D ubi_eba_read_leb(ubi, vol, lnum, bounce_buf, offset, to_read, c= heck); - if (ret < 0) - goto out; =20 cur_offset =3D 0; while (to_read > 0) { @@ -808,9 +759,12 @@ int ubi_eba_read_leb_sg(struct ubi_device *ubi, stru= ct ubi_volume *vol, map_len =3D to_read; map_offset =3D cur_offset + sgl->tot_offset; =20 - dst =3D 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 =3D kmap_sg(sgl->sg, sgl->len, &map_offset, &map_len); + ret =3D ubi_eba_read_leb(ubi, vol, lnum, dst + map_offset, offset + cu= r_offset, + map_len, check); + if (ret < 0) + goto out; + kunmap_sg(dst); =20 cur_offset +=3D map_len; to_read -=3D map_len; @@ -818,7 +772,6 @@ int ubi_eba_read_leb_sg(struct ubi_device *ubi, struc= t ubi_volume *vol, =20 ret =3D 0; out: - kvfree(bounce_buf); return ret; } =20 --=20 2.35.3