From patchwork Fri Sep 18 05:19:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 7212961 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 23F5BBEEC1 for ; Fri, 18 Sep 2015 05:20:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B08820710 for ; Fri, 18 Sep 2015 05:20:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3393204EC for ; Fri, 18 Sep 2015 05:20:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752559AbbIRFUP (ORCPT ); Fri, 18 Sep 2015 01:20:15 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:36843 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752529AbbIRFUL (ORCPT ); Fri, 18 Sep 2015 01:20:11 -0400 Received: by padhk3 with SMTP id hk3so40142137pad.3; Thu, 17 Sep 2015 22:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oR6dGuoOQQuchxpbIwjI9SGGQRSWLXiEwdIY4lAiWOs=; b=Q/yNlPXaN8YLPPv1dFLvv60RR99Vcgg4wMEyyz6II22ajvHRRrCS8jx6Z8+ET0VWIX JlCTbgukBjj64VPskl4Dwx2/XQ0931yW+FDA3Pvqt8tWoh+sGrS4ThlPnfhF6TJ2zxro xdBu3hVG0ug8heDrSvExzQIaP3MJf5VP90CWSfbTDM/Coyrxg0+g4bWoJIxClgMD1Cem Urb/RSQvJQa8+z5gO9RRmAXmCqeEG/19bEsK3xdER3ZtBchj5O08hkQ9OvTOyBR1v8lb 9nFj+3j8NYlrY8tXT96wIM4aTOanst5iYGgmWwWeK15OH1/FV6RYWSNOJTfvXX3dm8aO yDdA== X-Received: by 10.68.108.101 with SMTP id hj5mr4967303pbb.156.1442553610542; Thu, 17 Sep 2015 22:20:10 -0700 (PDT) Received: from localhost.localdomain ([119.69.155.252]) by smtp.gmail.com with ESMTPSA id bi2sm6443526pbb.45.2015.09.17.22.20.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Sep 2015 22:20:10 -0700 (PDT) From: Joonsoo Kim X-Google-Original-From: Joonsoo Kim To: Andrew Morton Cc: Minchan Kim , Nitin Gupta , Sergey Senozhatsky , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Herbert Xu , "David S. Miller" , Stephan Mueller , Sergey Senozhatsky , Joonsoo Kim Subject: [PATCH v3 7/9] zram: pass zstrm down to decompression path Date: Fri, 18 Sep 2015 14:19:22 +0900 Message-Id: <1442553564-3476-8-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442553564-3476-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1442553564-3476-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sergey Senozhatsky Introduce zcomp_decompress_begin()/zcomp_decompress_end() as a preparation for crypto API-powered zcomp. Change zcomp_decompress() signature to require zstrm parameter. Unlike zcomp_compress_begin(), zcomp_decompress_begin() may return zstrm if currently selected compression backend require zstrm for decompression or NULL if it does not. Signed-off-by: Sergey Senozhatsky Signed-off-by: Joonsoo Kim Acked-by: Minchan Kim --- drivers/block/zram/zcomp.c | 3 ++- drivers/block/zram/zcomp.h | 3 ++- drivers/block/zram/zram_drv.c | 20 ++++++++++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index fc13bf2..3456d5a 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -336,7 +336,8 @@ int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, zstrm->private); } -int zcomp_decompress(struct zcomp *comp, const unsigned char *src, +int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm, + const unsigned char *src, size_t src_len, unsigned char *dst) { return comp->backend->decompress(src, src_len, dst); diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h index 616e013..4c09c01 100644 --- a/drivers/block/zram/zcomp.h +++ b/drivers/block/zram/zcomp.h @@ -66,7 +66,8 @@ int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, struct zcomp_strm *zcomp_decompress_begin(struct zcomp *comp); void zcomp_decompress_end(struct zcomp *comp, struct zcomp_strm *zstrm); -int zcomp_decompress(struct zcomp *comp, const unsigned char *src, +int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm, + const unsigned char *src, size_t src_len, unsigned char *dst); bool zcomp_set_max_streams(struct zcomp *comp, int num_strm); diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 20c41ed..55e09db1 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -560,7 +560,8 @@ static void zram_free_page(struct zram *zram, size_t index) zram_set_obj_size(meta, index, 0); } -static int zram_decompress_page(struct zram *zram, char *mem, u32 index) +static int zram_decompress_page(struct zram *zram, struct zcomp_strm *zstrm, + char *mem, u32 index) { int ret = 0; unsigned char *cmem; @@ -582,7 +583,7 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index) if (size == PAGE_SIZE) copy_page(mem, cmem); else - ret = zcomp_decompress(zram->comp, cmem, size, mem); + ret = zcomp_decompress(zram->comp, zstrm, cmem, size, mem); zs_unmap_object(meta->mem_pool, handle); bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value); @@ -602,6 +603,7 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, struct page *page; unsigned char *user_mem, *uncmem = NULL; struct zram_meta *meta = zram->meta; + struct zcomp_strm *zstrm = NULL; page = bvec->bv_page; bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value); @@ -617,6 +619,7 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, /* Use a temporary buffer to decompress the page */ uncmem = kmalloc(PAGE_SIZE, GFP_NOIO); + zstrm = zcomp_decompress_begin(zram->comp); user_mem = kmap_atomic(page); if (!is_partial_io(bvec)) uncmem = user_mem; @@ -627,7 +630,7 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, goto out_cleanup; } - ret = zram_decompress_page(zram, uncmem, index); + ret = zram_decompress_page(zram, zstrm, uncmem, index); /* Should NEVER happen. Return bio error if it does. */ if (unlikely(ret)) goto out_cleanup; @@ -636,10 +639,14 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, memcpy(user_mem + bvec->bv_offset, uncmem + offset, bvec->bv_len); + zcomp_decompress_end(zram->comp, zstrm); + zstrm = NULL; + flush_dcache_page(page); ret = 0; out_cleanup: kunmap_atomic(user_mem); + zcomp_decompress_end(zram->comp, zstrm); if (is_partial_io(bvec)) kfree(uncmem); return ret; @@ -659,6 +666,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, page = bvec->bv_page; if (is_partial_io(bvec)) { + struct zcomp_strm *zstrm; /* * This is a partial IO. We need to read the full page * before to write the changes. @@ -668,7 +676,11 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, ret = -ENOMEM; goto out; } - ret = zram_decompress_page(zram, uncmem, index); + + zstrm = zcomp_decompress_begin(zram->comp); + ret = zram_decompress_page(zram, zstrm, uncmem, index); + zcomp_decompress_end(zram->comp, zstrm); + if (ret) goto out; }