From patchwork Fri Feb 16 04:08:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 201912 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp288636dyb; Thu, 15 Feb 2024 20:17:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWN4ehsuz14pkXyC0tSGGGfPWjNkPdgw+tagwNRxIcEfvu+3ROPdKxFIrwynv2FSe0AYkSj4RZgeFLkbNSC3JjiyNRw0w== X-Google-Smtp-Source: AGHT+IGO5bETN6PFMQ3ssN5JDKtjkK2qyQTOosZKIL5r8lOCph/V/LFP1Ir+RfqMLpFkBEY91eiT X-Received: by 2002:a0c:da82:0:b0:68f:2c72:a76a with SMTP id z2-20020a0cda82000000b0068f2c72a76amr2708786qvj.3.1708057033469; Thu, 15 Feb 2024 20:17:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708057033; cv=pass; d=google.com; s=arc-20160816; b=zeQDXDc8/jdeQa8dUWMYHrWof0b7vxzhRjNFxAhDXKhspu6pPMIVN8r66a0/gkAsn8 ssLB6ilmwArQrSY7IU+O+Oe5FKCAWHQ8bXhU2WgVdiEkqhuaKy7VJE8piAoWrgEdldT8 h0fP8rqINhu1tjA0TAuQ8amHvxKTZJfTVTn8Ey27d0KQsud2nxd10LbgLSvXhiLt15a4 qR3p6iEDi658Dz8/zIqkgioo6sGjtZjxLqlBrIDFqRbRHbYcM/HZpDrwJMQpVL2rmtt1 pIG8okVqc0GMz/JGZvjBwAUaLQuy7qHJ30TJ20JzMyTEt/yfhWyRAwDDnLNjYaDvc15p hEaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ip6H/hpmZhzyeEdQqkgVS2/3JYDDw9wfoPqTzf/YhGo=; fh=1Wtaf7mFadLcDYeqk5V/GTRC0kmDSYe3KOZyEXi+pAk=; b=NM0aqbtSoZoJTs1KI78IBl0Bnnl8y+ae6313V8/5PfFlolP5Eez5SyDztEgB3BIwPT 9qB39a2jrutXqgCBDtUNz0PU1lquGozJSTL4R2cogsrHXOVTIckQqHHnkCzfmp2lOxXb 0PDKji8rvRzIIZweC9BU2ojwwxRCmU6H9t0/Her3/nQ96Te2Uz0tWEmLJti3qTgl5sCY U7W9Guim25+Cx3VDVteHR2q9mLBmQUooF+1rlxfcIOPaS3gd6pb+vzKwjcjikP14rPdF 9kezWby8snNG7pvv3wk4HBaijIANdZwfDedmgBLKUHiLTuo3ODEa54GqLK31Rbl3uLbd cvEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="bX8Q/+hS"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-68045-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68045-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pt1-20020a056214048100b0068cc2054432si3116408qvb.495.2024.02.15.20.17.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:17:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68045-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="bX8Q/+hS"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-68045-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68045-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 334F71C21648 for ; Fri, 16 Feb 2024 04:17:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 258D3168DA; Fri, 16 Feb 2024 04:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bX8Q/+hS" Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C59014AA3; Fri, 16 Feb 2024 04:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708056541; cv=none; b=i+NSdS79WWqBkrbuDqNBDRiTjkRMXzzE+8pjV8k5p1yzI0419ZmN3V7vUHwYGpPZWdZdGIE6j1E4mbVYZ9N/xUhBuvX7fbhyL5NFNK5O/Gy+u6oPJsizdxZMPV7xnsZLOEQXa4qQWdXpxlxllHF3nilPVGhk+KVxzschB05G3gk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708056541; c=relaxed/simple; bh=dZFmMb0eUSR9kF0J/d1NN2tRjiMEitp/3HXoSB/UdT8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JF7tfInyXcL1lKAMvI2NdapTb6uWrwDHTscMJ2WpFXMD8ql91WemRjq+RTdn/DrRLJgdzFDfbrlRecXJFg68M5IpTsRYJVIT5lOHiwCgEDfyIcED5pACUfp83mdotqMUz4OAeSAqn1SRYOIPVqZnof8Wd3XgbpIloHuEVWfpLEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bX8Q/+hS; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso302285a12.3; Thu, 15 Feb 2024 20:08:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708056539; x=1708661339; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ip6H/hpmZhzyeEdQqkgVS2/3JYDDw9wfoPqTzf/YhGo=; b=bX8Q/+hSMnGLsen8mxLD4KmobJxOgUwi8oAMnRiXC5F/qDs3NlarcXXszXsItFSHmk l887Sk3nbRRXblJR9PSlg4r8ZVWq2sESPiTOyQUWBwt/jnT4188Dt3n5uxdmq7lJUnjA wJtXRpXCyOEUv5MLfQSh8/8k6D48+eHdDMisufx9kYubIqbqVXbjE6iYsCaQ7b+/1Vn+ l2PdscB38C+q9cjPAJtfIqFgQEarlweshfrHJcQIptok/+Aqvba+EUFsYNAtlkaK6DYz +DeGDVMr3vxvLszWyTgtk/3YXeatUfPbDNth9Tard80d0OVtwu6VJO4DDqZ4wpb+LpYL bpig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708056539; x=1708661339; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ip6H/hpmZhzyeEdQqkgVS2/3JYDDw9wfoPqTzf/YhGo=; b=YTgp/iOrlGVpKAcRT7U557KXi3p0Jv/X+0wrgrPkUO1H/R2myTl1HHtrWWfyghMWKA MSmuUSBH7//TuMrQIpmFr0OvGKpoloodQACb54HCEIe82GXRjKNqH1BU1g/dwzWgZN8f MixlnGH9pE5dJ2J0g7Sh1yryW7KeIkJOhBhyC8Ifoo7VxW+hZ/6Nga2QAcH1PfFuoxxf N+Ajxu0Fzi7p95WSh8o8XUlXyJk3CZLNnsp4ChaPr+6cuqZFyvMq0kZ1rRKyVRU+J87+ mUWh2BHwcq3qgLGT0+Cbi0AFoo8QkSjneB+Iu2/KuZqD73W3Mco/2d8y7FREYSq27/u1 U7jg== X-Forwarded-Encrypted: i=1; AJvYcCWAbeaIbpXz/Od8vBfKhLXKL2GI+lVmEjcTJdjVwoxRYRDF0BkZ8niG73IyVhfxV91eALemagMV0GTQe5FCJJ9OdyVK7jChcOuqdshmax6U9FIN+Pu+Z9IPjI4tzdQjiLeHaDLzfTFHQP3n X-Gm-Message-State: AOJu0YxhsZCRWxQ6FyJluUOqe+NjGa80AclqRkA6wuvkvN6ZQj6JHwZe jev8JMjSsVG942b136Z45lOVjNm0mkvPA/15F7uLhmRQ/4oZONPv X-Received: by 2002:a05:6a20:9585:b0:19e:3709:f3f9 with SMTP id iu5-20020a056a20958500b0019e3709f3f9mr5626996pzb.2.1708056538819; Thu, 15 Feb 2024 20:08:58 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:f28b:3925:777f:45d4]) by smtp.gmail.com with ESMTPSA id pt12-20020a17090b3d0c00b00298ff26e4c8sm2321393pjb.26.2024.02.15.20.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:08:58 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, davem@davemloft.net, hannes@cmpxchg.org, herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, linux-mm@kvack.org, nphamcs@gmail.com, yosryahmed@google.com, zhouchengming@bytedance.com Cc: chriscli@google.com, chrisl@kernel.org, ddstreet@ieee.org, linux-kernel@vger.kernel.org, sjenning@redhat.com, vitaly.wool@konsulko.com, Barry Song Subject: [PATCH v2 1/3] crypto: introduce acomp_is_sleepable to expose if a acomp has a scomp backend Date: Fri, 16 Feb 2024 17:08:13 +1300 Message-Id: <20240216040815.114202-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216040815.114202-1-21cnbao@gmail.com> References: <20240216040815.114202-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791027612016370082 X-GMAIL-MSGID: 1791027612016370082 From: Barry Song Almost all CPU-based compressors/decompressors are actually synchronous though they support acomp APIs. While some hardware has hardware-based accelerators to offload CPU's work such as hisilicon and intel/qat/, their drivers are working in async mode. Letting acomp's users know exactly if the acomp is really async will help users know if the compression and decompression procedure can sleep. Signed-off-by: Barry Song Tested-by: Chengming Zhou --- crypto/acompress.c | 8 ++++++++ include/crypto/acompress.h | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/crypto/acompress.c b/crypto/acompress.c index 1c682810a484..fa15df394a4c 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -152,6 +152,14 @@ struct crypto_acomp *crypto_alloc_acomp_node(const char *alg_name, u32 type, } EXPORT_SYMBOL_GPL(crypto_alloc_acomp_node); +bool acomp_is_sleepable(struct crypto_acomp *acomp) +{ + struct crypto_tfm *tfm = crypto_acomp_tfm(acomp); + + return tfm->__crt_alg->cra_type == &crypto_acomp_type; +} +EXPORT_SYMBOL_GPL(acomp_is_sleepable); + struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp) { struct crypto_tfm *tfm = crypto_acomp_tfm(acomp); diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 574cffc90730..88ca33532313 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -204,6 +204,15 @@ struct acomp_req *acomp_request_alloc(struct crypto_acomp *tfm); */ void acomp_request_free(struct acomp_req *req); +/** + * acomp_is_sleepable() -- check if an acomp is sleepable + * + * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp() + * + * Return: true if the acomp is sleepable, otherwise, false + */ +bool acomp_is_sleepable(struct crypto_acomp *tfm); + /** * acomp_request_set_callback() -- Sets an asynchronous callback * From patchwork Fri Feb 16 04:08:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 201913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp288722dyb; Thu, 15 Feb 2024 20:17:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVaig2sLTzuhSniazUtgJbd16s9VJmP4HBTNY5mvDXgmBKoFV3GDNcZWOmAmIIIE1jthbjCgh/6E23k5jMxV7K1+ctx1w== X-Google-Smtp-Source: AGHT+IFvpx+H0+Y6sHFL3AGZ30BZ4Fz+rMs3WVi4PZ8NZ/vXm1N3XRR06iMDnS03ta2SbpBWMlC0 X-Received: by 2002:a17:902:aa91:b0:1d9:a14c:eeb0 with SMTP id d17-20020a170902aa9100b001d9a14ceeb0mr3911050plr.43.1708057046246; Thu, 15 Feb 2024 20:17:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708057046; cv=pass; d=google.com; s=arc-20160816; b=cE1oS5YX7lxr+19ZASPTUU3529acvGJ2UQKFRPJuk719bN6wUbdkCFgUX4XLQ/3nD+ tAfrB3FUhz+YksVA/LXCjloE2bnrUl+szRj3s0iQxMNuI9bOSJ3AMFUFOfZLlVeLKekO AuCTPfnOzaaLjcOaS9n+5zZw528tvX0ERqmnSkpDYuI3eGroBkVO8iKs9ULYR6HRzAre ImggZMdPrYZTErRbuPynVa5HoFnK6rgqRIhtWl0Ubj9d1Fdmesh4/qAcBXbZR7o39+KD u/BvnJEadgCN+kj2ONFfvE4peVvScXn7/EYF9LNyplutWJfDKSPvAeinTcK4idks6B7H ZWtw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uQ9C4C07Lh00QdEMEtLL7F2M/Vil3VvFnVKlElC+iJU=; fh=0Vx+ghEkchbSQ0GvaNAgfnArLgMiCsox9SyyETyCi/o=; b=tC4m1/MEIpX87wmP85a6hKGRi8Lv85mr/AMdeuT7aQFFTy1Ju/IXTKmIogde7VvkeN wTIe0WKca5H+PU5Kk2e3nK6WntJdgbsAXjEOwSVf1RZdxo8E/v7yrTBBEzeYPVWnaY36 IPbJLdaP6ObFI5WNrrymc9RHG/DXuDC2v6+oHmEHCxbJnoF7sQBPO34Kg/daCOsUKtrm PUwbtJRDu47TxUOI7vB6O90HLRy9vvHfqBsPAnSxZ0riEjhkp5d5W2my9Lr9K9KrmH6+ Z71lTcLWdpvCrHRmD7GZmT4vzj+uct3kscJRlMcU+j7n+SLnQXlwFwdFv9YCTJYgoIbj lSZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mwzcx4fV; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-68046-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68046-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j9-20020a170902690900b001da22d9e810si2232390plk.219.2024.02.15.20.17.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:17:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68046-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mwzcx4fV; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-68046-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68046-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 15FC22835D0 for ; Fri, 16 Feb 2024 04:17:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7169B179B5; Fri, 16 Feb 2024 04:09:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mwzcx4fV" Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F85D17551; Fri, 16 Feb 2024 04:09:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708056546; cv=none; b=YNQE+AFeAXco/pTqfDs2vY+ArbkVMRdk2Uf30dDBEFlFqFe9mvhxd0eccIVOfojnfbOo+0lMiWQHJhSm9fd654YYhZY4pN44Ln0BTPog9QblYb+BeTrlS5G6g0xnTuShU1tHxUZOtqqfi1ruCvBfGTt7bBPTEs2ods2PLsEcGm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708056546; c=relaxed/simple; bh=PIYvWr5DMLF8+jxHRgFqYx/2Q2KnJ/Jtsvfz7TqNIu4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=t76syD5n0bnF3t8lTBwFtg4PelYeKwdWGzndjXEO8A22HvApEvPaw59dtVso5JiJ769qltZiqUiN3w9h9/s5fXsYWrpcmXW1GEqhg+/4h0hhit/Zi8rpBgFcUSWo5mcLtdVoXfWsHQbf0lU90IDT6rqgsjmrAmlHipS0Ebn1VwM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mwzcx4fV; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso302340a12.3; Thu, 15 Feb 2024 20:09:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708056545; x=1708661345; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uQ9C4C07Lh00QdEMEtLL7F2M/Vil3VvFnVKlElC+iJU=; b=mwzcx4fVqYo6YP3/p+OJBp2EqeOemf24U/B/c3aryo1z0Z5GJEgzEeYzgw/KQtMK5O 7zWALR0cg6mUqmYl7AWMQwd5PgYJM5jagyHmygWN+p1mYcWGs2lUDGIRJzZ8IlPJwe7d YHLPKyndSx5GKGRv0NABZYsk7vLqjvdH2FyPzaR1o9m4gZ+GA5dsTHm24hsXABCrSVNc JJi0MpXAGVnrYCZzbshAn6z/qJG9xp7ZkGmTd/Y8jkCB7PnS3PVzoEE/OAe1SkaeSWZA Y6XnPmGpaUWTZnNpKet9eFzHIWmrIFsZgbfeo5n4AkITX9sKJJme59v+0+O41t+pzqGn T2+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708056545; x=1708661345; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uQ9C4C07Lh00QdEMEtLL7F2M/Vil3VvFnVKlElC+iJU=; b=rr2o9ZGkeflidRPpw8/LEAdJkzucagkxZDJJvUwtfI4uxNuW0KCt2sz7WvswmQEI+v DNkuR+1S4ik73TC6Jz6Ps3eIk5wYl1ckb/wNItj/MaqDg6pfqMGM+Mz5JUq4Xsic5vTL MGjZBFWxuj67vT9F3u6MN3bQtugdxTD6SJVBvqG9TiJTs/2CVlf1lhRmVLtelYpWbbrh 4umz7Yp6QVm3RSdNp09sWpPreEmn+ZPvVy+GazVJ71Wi/uF+xaJ9hJxurw2734ifaXae ctcXtOiXG58VAkbUq/RSLxyXJ6CWpD3sIBNtV+rlhDz7xSxorUNBVSKocwHH2i4K4NQG hKww== X-Forwarded-Encrypted: i=1; AJvYcCV/LOydAloFbm2JV4la88O8Ei5Ek5gVZ/zBohoOi5sJgpQrGbBqw0pUTXufjdFUYbqWcw4ftBp1boA6WCEOzMoYWbTJTJuYcurgKY51zviZHexKYGvL5ibwo+W8HdlbYTpmX7kTctPghHbb X-Gm-Message-State: AOJu0YyXSC7P09Lvzybj5pcRieJ81/xzB/QSdAKe5f1RmtzEFAKR5Cah hneWZfRNdXqbhlaiizi4qU0s675zE90rlv50Ws/p5kEPwSYAH4vN X-Received: by 2002:a17:90b:3606:b0:299:3657:4950 with SMTP id ml6-20020a17090b360600b0029936574950mr257715pjb.2.1708056544708; Thu, 15 Feb 2024 20:09:04 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:f28b:3925:777f:45d4]) by smtp.gmail.com with ESMTPSA id pt12-20020a17090b3d0c00b00298ff26e4c8sm2321393pjb.26.2024.02.15.20.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:09:04 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, davem@davemloft.net, hannes@cmpxchg.org, herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, linux-mm@kvack.org, nphamcs@gmail.com, yosryahmed@google.com, zhouchengming@bytedance.com Cc: chriscli@google.com, chrisl@kernel.org, ddstreet@ieee.org, linux-kernel@vger.kernel.org, sjenning@redhat.com, vitaly.wool@konsulko.com, Barry Song Subject: [PATCH v2 2/3] mm/zswap: remove the memcpy if acomp is not sleepable Date: Fri, 16 Feb 2024 17:08:14 +1300 Message-Id: <20240216040815.114202-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216040815.114202-1-21cnbao@gmail.com> References: <20240216040815.114202-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791027625304209716 X-GMAIL-MSGID: 1791027625304209716 From: Barry Song Most compressors are actually CPU-based and won't sleep during compression and decompression. We should remove the redundant memcpy for them. Signed-off-by: Barry Song Tested-by: Chengming Zhou Reviewed-by: Nhat Pham Acked-by: Yosry Ahmed Reviewed-by: Chengming Zhou --- mm/zswap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 350dd2fc8159..6319d2281020 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { struct crypto_wait wait; u8 *buffer; struct mutex mutex; + bool is_sleepable; }; /* @@ -716,6 +717,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) goto acomp_fail; } acomp_ctx->acomp = acomp; + acomp_ctx->is_sleepable = acomp_is_sleepable(acomp); req = acomp_request_alloc(acomp_ctx->acomp); if (!req) { @@ -1368,7 +1370,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) mutex_lock(&acomp_ctx->mutex); src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); - if (!zpool_can_sleep_mapped(zpool)) { + if (acomp_ctx->is_sleepable && !zpool_can_sleep_mapped(zpool)) { memcpy(acomp_ctx->buffer, src, entry->length); src = acomp_ctx->buffer; zpool_unmap_handle(zpool, entry->handle); @@ -1382,7 +1384,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE); mutex_unlock(&acomp_ctx->mutex); - if (zpool_can_sleep_mapped(zpool)) + if (!acomp_ctx->is_sleepable || zpool_can_sleep_mapped(zpool)) zpool_unmap_handle(zpool, entry->handle); } From patchwork Fri Feb 16 04:08:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 201914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp288786dyb; Thu, 15 Feb 2024 20:17:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVdsX95Zsdwfh9yQ/ThvfB+5W/sHBMQPOfDsQ+tn8x7XvgzD8cXagMkNZ4AJ+5OvJEwZnTTSz4kTOH/434MMwt7xI0FQg== X-Google-Smtp-Source: AGHT+IFBnTMK/e7Slagt3kn9cnUzFemnGSv/GE82YHAgvwNKXV9lcbmTrXTz1BTG6VbJIJQCHs2S X-Received: by 2002:a05:620a:19a9:b0:785:d83f:5582 with SMTP id bm41-20020a05620a19a900b00785d83f5582mr4924923qkb.20.1708057060048; Thu, 15 Feb 2024 20:17:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708057060; cv=pass; d=google.com; s=arc-20160816; b=b96Gyozys39WH1oyM0J9cjp3xWD2OCS9ADwKKH+S7HmcSHV1OxZ78eELEdnT+jYHB4 mA2xC3zcx9BwqX2wRhbyDtY6IrI+kU7GPEJzSPhCtOUDqwxd6bCkaEWqJ/GAJ37kJ17v c4T40lU8eiKYbWGQCNca6KuF327GK4REN8ugH0y+PAdA3qr1TcHfs1vNWk9BurrtpCo2 u/6yWyqZDi06F6DjnNV7Imf6qhCnSsOK4ZPOrSlWVrBjyBziWD9pbgIOZDgIjHk+6InE Yn9Xh/CW204Xi7nnGh6Py9oTHFZUgHpuaKqasM/B6TsL6wC9IiUe/VHqC2HHLtFMkNSG gGXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; fh=VJen2ImeTraaOlPYn3iUMJLVQB0PEN2X0raidJBbHy0=; b=Ooh6QHN/g/YdQAAoOyBGHWyjQmBEfDtUug5N66BAYCwYLJuOMYiwW5YbInpQP/ecuN 8ARiNQiYZNH/j1JFXJuQkor/uex/m5Hixa6SpenZ3EvX9/kn8eNCPq0HizWR/7cw3v1P niOtLOPT7NgRKSDl37JfKldfdxFckkeOc8E1yvwUG6dDrtnIUWkek91/rcfseBCoKN72 aStOBcON/M6ku06fDa7JXb2pO241lVZow3lalf4JDtWZTtK6hQo5IAaKOuRffmTTTCZJ PLs6M/s8M1lAwCj+aV3wIDjIR9kQgXxWgTTLxHj5cSBs9d0RvxIMib06xU3fMPs9VEOa N1HQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=W9laoRfr; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-68047-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68047-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ow18-20020a05620a821200b00785d8041bd4si3033353qkn.758.2024.02.15.20.17.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:17:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68047-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=W9laoRfr; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-68047-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68047-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C89841C20FC7 for ; Fri, 16 Feb 2024 04:17:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 568D417BCC; Fri, 16 Feb 2024 04:09:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W9laoRfr" Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CB7E10788; Fri, 16 Feb 2024 04:09:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708056553; cv=none; b=ds4+6ILfTv//s4UdI/tGzrhhL5fJOY/rTrp4Yq56sm3VrRxWsmNeiw58361ByPERofQyg45ZgTMZeW4JZVbbKO+u/NOLPwG9PwIQjSGfzTUHzbs70K5dCDx9u43dow8lVk13epXkRGsrPfEpoMFsh5ArzoZ8dsDqeVKiO832kA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708056553; c=relaxed/simple; bh=OXsYoToIjgeSRYAs9X9E0bo5WCdOjPMMPVgmJGURH78=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qznwB3oiexBQtinZgQY/92Z+Mzt1VMTj3KjhU9rdwrjKv/SorVpy/9hUeA5CHZVe2jSiIA4NlmTCchawOKiypF34rtM7wbtJeAdenB6ObItRxsW1etKUK3ECldC5ssYLhWiR6nP0dDQ51wZdCBKKI8hl3vr2imO/dHx4xvJO9IQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=W9laoRfr; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-296e22f85abso1300705a91.3; Thu, 15 Feb 2024 20:09:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708056551; x=1708661351; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; b=W9laoRfrE/T09iHCVRLFbI8zka3kijD7BoRxno6o/kmTi5KhiwxvnaQS2u5W0kR0+r bWjFe0SbynejbmGc0u7uMk+uNY2apLeN2MGRsAbaUuBoHs+s2/be0wPOgum3OtKi9ZMW /pSvlZ+0z7Dmrl5Boq2Xq5pTbNdZiDeIoHj83W+2A4AQ8dUpou7EPLxesGAStGoEca5u 1oTRXuJVqAI1PymDnaKtT6y4WHfli+1dekEofu7PlIQ7fLm3MqbKfFDnlKS5pDhszCnY dTegKOKgCHdqAQ4OmPq0Kpmhkrdr7fzNJFSea2s2KhiBBej2VjO4JXgaP/u54YbVv5dk NfOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708056551; x=1708661351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; b=amcm23+UC2DIrWlqd0A9BVlBbwES5CS1z13WZPIuEtNYR5yfEMfwLlpgiW3QQD3QUc 8Z8cmPIdJ3BjULee8alGPVyub8x7KqIr4BS+u3wQUjcyMylOEbg+5YqMonHutSX2os+9 nLIcHc3Fx0NW3xB3+nATjbMLWw8MLDuyF5XUAbod9DISHXLGoUnd9QHXMWqTBz2lidsf dr2d7N2UyrnFlUXtj6KDdh3yLnHnABOdf8Vj7ciEWBLr51olAt8WToxiAxSWgF/ahZN4 huRpDDWdLdyAlBOqCy8f2gCgER1suCPl7N2lbly+J4UAURU6ZzlqJHLLE0Bl5ReOmqSp N1wg== X-Forwarded-Encrypted: i=1; AJvYcCVBd6BzBsEMbIYRqVw8bTpUa6WkuVChWD6h/a+Xv5hwdrlTzx30vOyRLV0Pw4ZtvOuPLdsIeu9mi5MPAckBG0ikuNFWwZxeH5Bl7cftSDOu8ltTR3RXv81kMyLF8Y7ac75l+KgdhEllRlh1 X-Gm-Message-State: AOJu0YzSWeuntVGnFEGf9SdF0zTzN6OOIDEaQVfJORfKBG7JI/1iJpGz 6hKU0Bvuy5ff4TYXZHP8bpPuId3yIZQBoZjd49oSlIC7I/A3/CgN X-Received: by 2002:a17:90a:eac1:b0:298:d1d3:9ef4 with SMTP id ev1-20020a17090aeac100b00298d1d39ef4mr3368864pjb.27.1708056551160; Thu, 15 Feb 2024 20:09:11 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:f28b:3925:777f:45d4]) by smtp.gmail.com with ESMTPSA id pt12-20020a17090b3d0c00b00298ff26e4c8sm2321393pjb.26.2024.02.15.20.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:09:10 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, davem@davemloft.net, hannes@cmpxchg.org, herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, linux-mm@kvack.org, nphamcs@gmail.com, yosryahmed@google.com, zhouchengming@bytedance.com Cc: chriscli@google.com, chrisl@kernel.org, ddstreet@ieee.org, linux-kernel@vger.kernel.org, sjenning@redhat.com, vitaly.wool@konsulko.com, Barry Song Subject: [PATCH v2 3/3] crypto: scompress: remove memcpy if sg_nents is 1 Date: Fri, 16 Feb 2024 17:08:15 +1300 Message-Id: <20240216040815.114202-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216040815.114202-1-21cnbao@gmail.com> References: <20240216040815.114202-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791027639849227034 X-GMAIL-MSGID: 1791027639849227034 From: Barry Song while sg_nents is 1 which is always true for the current kernel as the only user - zswap is the case, we should remove two big memcpy. Signed-off-by: Barry Song Tested-by: Chengming Zhou --- crypto/scompress.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/crypto/scompress.c b/crypto/scompress.c index b108a30a7600..50a487eac792 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -117,6 +117,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) struct crypto_scomp *scomp = *tfm_ctx; void **ctx = acomp_request_ctx(req); struct scomp_scratch *scratch; + void *src, *dst; unsigned int dlen; int ret; @@ -134,13 +135,25 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) scratch = raw_cpu_ptr(&scomp_scratch); spin_lock(&scratch->lock); - scatterwalk_map_and_copy(scratch->src, req->src, 0, req->slen, 0); + if (sg_nents(req->src) == 1) { + src = kmap_local_page(sg_page(req->src)) + req->src->offset; + } else { + scatterwalk_map_and_copy(scratch->src, req->src, 0, + req->slen, 0); + src = scratch->src; + } + + if (req->dst && sg_nents(req->dst) == 1) + dst = kmap_local_page(sg_page(req->dst)) + req->dst->offset; + else + dst = scratch->dst; + if (dir) - ret = crypto_scomp_compress(scomp, scratch->src, req->slen, - scratch->dst, &req->dlen, *ctx); + ret = crypto_scomp_compress(scomp, src, req->slen, + dst, &req->dlen, *ctx); else - ret = crypto_scomp_decompress(scomp, scratch->src, req->slen, - scratch->dst, &req->dlen, *ctx); + ret = crypto_scomp_decompress(scomp, src, req->slen, + dst, &req->dlen, *ctx); if (!ret) { if (!req->dst) { req->dst = sgl_alloc(req->dlen, GFP_ATOMIC, NULL); @@ -152,10 +165,19 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) ret = -ENOSPC; goto out; } - scatterwalk_map_and_copy(scratch->dst, req->dst, 0, req->dlen, - 1); + if (dst == scratch->dst) { + scatterwalk_map_and_copy(scratch->dst, req->dst, 0, + req->dlen, 1); + } else { + flush_dcache_page(sg_page(req->dst)); + } } out: + if (src != scratch->src) + kunmap_local(src); + if (dst != scratch->dst) + kunmap_local(dst); + spin_unlock(&scratch->lock); return ret; }