[v2] mm: zswap: increase reject_compress_poor but not reject_compress_fail if compression returns ENOSPC
Message ID | 20240217053642.79558-1-21cnbao@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-69692-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp160822dyc; Fri, 16 Feb 2024 21:37:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUsseiMXz1qqAr/QMkUA2wyCL6hQORk6dNBi7leHngsVLiAW5S/egz0j4GPLKaVlFzpo9U5/Ptxi9L2xUX8CGhnIeq0FQ== X-Google-Smtp-Source: AGHT+IEhb/tn9OmEfFyA2AKzZjQmtSSI1qe/V5QcPwfdZ3G1rzMmy3ixb5Po1y9Zw4LoiGrqklvl X-Received: by 2002:a05:6a21:918a:b0:1a0:776c:f442 with SMTP id tp10-20020a056a21918a00b001a0776cf442mr7844452pzb.10.1708148241807; Fri, 16 Feb 2024 21:37:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708148241; cv=pass; d=google.com; s=arc-20160816; b=e7AdOnWe7Nps2WZ7NZqkb532RjU75Ubdhu4rgJenHwjLi5Zp3fRqp/5ifphlUkC9n3 moaqJwOzdQTPkNZ678A4ZRzycO1ZnnjBgR3gIOSFqfw90+Ene6u9LSFtvvhNap6KaG6b Uqjk8NNzqe41WT71Jm7c5bk7/PChLKxWkRVlIN6QC8hxLJ5WCQ7MwTcze2CykM+0bcYT kQepgUTYlizInD3Xy5jJ1c91STRgagfAq5IURHP84yk/1UvPU2Rx3YyY7XCUKezZGt4g 6YDrt1kHfdFnCGQS/i6plgTsp2h8hQ4jfojXmVwNA7GjH+Tasksf+WGJC/TkM65K496P noRw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=lCLVx9kxWQaFnG1OpMOPtJ5A7Khl6+OxNkxfvJDWGlc=; fh=tgzX6x1jywIkyoK4Hg8IrjnlkW+rWVB4/ljBJHnY48Y=; b=ViyxNquY9ScQd6LhchWVzvXuPNKOurAPYbsRo3Oi3ja94GCAlsTWj8qqqhoJXLqi6C 7jQOSMzlINXyx+wVb/IOEBfbglGoJzgLnc7GCzJSLhfQvMpFGNhtmUSQNlw+WUPTW2Wu NFC0phdGLNlGhHT2VJPJEEPpLOuSCUNkI+8/zxab+i7Hbb2H7veRjce5+/wSTb3jAgEp j+cdXn77kIzfQ8yYi1aS88+BnbE9NYzfwwzEigESJgr3FArbXxBzaFoy8SnRa3oU81y9 kkIAxwZ02qQVq9vBIoM1k0GUuPrg6b97iw2T2Y32RYYCb25i9Erea8qk0n9x52/n3slk vcag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hhJj8n1O; 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-69692-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69692-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id pm4-20020a17090b3c4400b0029961c8e354si150205pjb.133.2024.02.16.21.37.21 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 21:37:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69692-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hhJj8n1O; 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-69692-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69692-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C4381B211E3 for <ouuuleilei@gmail.com>; Sat, 17 Feb 2024 05:37:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AFE201CAAA; Sat, 17 Feb 2024 05:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hhJj8n1O" Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 822E5149E0B for <linux-kernel@vger.kernel.org>; Sat, 17 Feb 2024 05:36:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708148219; cv=none; b=d1VhydrRfkSMblgaJeywGLFqpJCk2YubEAfea9r6yPl+I8g+hU93KvietIEBYn+G/A3j3WkbcPBtZfXFJdQRjFBRMi7Ximfq7RDmirKHgAobhpf51g+t0brCCjF1BwYIVXXsmD0VB3nn8fjhbZ2ljhzdTYzDCmcU2L7qAeutJIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708148219; c=relaxed/simple; bh=I0rH/AzGKnIIcT7lLmWH05RQnkNtY+vk5eDC9ZMYQDg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=JIxN2egilL9oJvXBFvsAkaIU7CWahIsG5Dwhr0t2w6kdbL85t9LbgRlekg/cIy6sSIo2UjfwO3rDNemSLaj0zDcfLo2qVdmdiUXSpiBh21vFH1aUY/lQNEEqMkNHXLWWvdf3F3yx2PAPUqdUbONuiHGR+IyC4ayh46+VBKwnDWY= 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=hhJj8n1O; arc=none smtp.client-ip=209.85.214.181 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-pl1-f181.google.com with SMTP id d9443c01a7336-1d918008b99so23430195ad.3 for <linux-kernel@vger.kernel.org>; Fri, 16 Feb 2024 21:36:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708148217; x=1708753017; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lCLVx9kxWQaFnG1OpMOPtJ5A7Khl6+OxNkxfvJDWGlc=; b=hhJj8n1OMced4nuv98oo3BOejI91EY6ZgM+H92sHlPsrRZPsXlnyuv1ZJNpDHnmFcH BtBQq3HUZ5VCeiVKLsURAhRYKiMNpBicN0crLEJ3PQBezgW98b4tPyoY3T+bmztFz0uk k0OCyePxqaawTtF+h+rLs08rSFuEAPk/+WHqWVhp+t8pGcBsaGsoSfBQ6Erzoqe27IBo OFan16T1kn9PgUHK96Tqf3zjdYw9sHd6zHpRQKdl0kZwFN+nw8TYAhyzhmLsaupOnseT nSpucO0g4KP7tSC+Opx2S6kzm3A/sx8IcJ+ygkKbvOtmhQSmBuYdjjYUKqVltKVsDJX+ +SAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708148217; x=1708753017; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lCLVx9kxWQaFnG1OpMOPtJ5A7Khl6+OxNkxfvJDWGlc=; b=mnZnSqr8kRYzJQjw8HJhqDmuhmkIt6kSAlgwjD1bfbv00s2YtXLC15T58aboYYYWtw IuksAFLeKcCU3hheSccDCuyi3VvBIEXrGRQY3huBZrqFppNvBWdLQTXiVNJmEoEAvmuj cDs0Hsw9imfYDZIxpb648SfOHWv20+4LXJBHblpmVX+XaOyCkyXTV26WFI7iEr+iCL6a d0g3fYxeGV0LdutCvL/e/S3ThOHQ3gkFIpteBXF1htN5vbYLmfDKmoThtWMPDR+6B9Ma lzdb4Mn3swT77qDdIRUK/SLBjw1EJA2KYrH8xNudz4RnupymQzETEsE5OXrLBT0RoEuJ UyZA== X-Forwarded-Encrypted: i=1; AJvYcCV9LOhFXp9V/QPoJ7kWAWPwBaXXSC4d99CUsLvlzaV4zs35jLcXZEmNyWvW3d2KwjCNmXynKpJebzzc5cQAumycRQ4ae6mokrmpvLFo X-Gm-Message-State: AOJu0Yyti3yOzbf8le0B87GxvxxVZ/+/iQWVslpmn2NlXY/SdH9LIw/S evYbBnXxQ0HZaDnZN86VqY3kauRU9bJ5ZpZTA92cA5jduc8syWno X-Received: by 2002:a17:902:ea0d:b0:1d9:5f11:d018 with SMTP id s13-20020a170902ea0d00b001d95f11d018mr8459194plg.1.1708148216595; Fri, 16 Feb 2024 21:36:56 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:e82e:22f2:1bdb:989f]) by smtp.gmail.com with ESMTPSA id w3-20020a170903310300b001db3d365082sm694251plc.265.2024.02.16.21.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 21:36:56 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, hannes@cmpxchg.org, linux-mm@kvack.org Cc: nphamcs@gmail.com, zhouchengming@bytedance.com, senozhatsky@chromium.org, linux-kernel@vger.kernel.org, Barry Song <v-songbaohua@oppo.com> Subject: [PATCH v2] mm: zswap: increase reject_compress_poor but not reject_compress_fail if compression returns ENOSPC Date: Sat, 17 Feb 2024 18:36:42 +1300 Message-Id: <20240217053642.79558-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791123250712022568 X-GMAIL-MSGID: 1791123250712022568 |
Series |
[v2] mm: zswap: increase reject_compress_poor but not reject_compress_fail if compression returns ENOSPC
|
|
Commit Message
Barry Song
Feb. 17, 2024, 5:36 a.m. UTC
From: Barry Song <v-songbaohua@oppo.com> We used to rely on the returned -ENOSPC of zpool_malloc() to increase reject_compress_poor. But the code wouldn't get to there after commit 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") as the new code will goto out immediately after the special compression case happens. So there might be no longer a chance to execute zpool_malloc now. We are incorrectly increasing zswap_reject_compress_fail instead. Thus, we need to fix the counters handling right after compressions return ENOSPC. This patch also centralizes the counters handling for all of compress_poor, compress_fail and alloc_fail. Fixes: 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") Cc: Chengming Zhou <zhouchengming@bytedance.com> Cc: Nhat Pham <nphamcs@gmail.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> Signed-off-by: Barry Song <v-songbaohua@oppo.com> --- -v2: * correct the fixes target according to Yosry, Chengming, Nhat's comments; * centralize the counters handling according to Yosry's comment mm/zswap.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
Comments
On Sat, Feb 17, 2024 at 12:36 PM Barry Song <21cnbao@gmail.com> wrote: > > From: Barry Song <v-songbaohua@oppo.com> > > We used to rely on the returned -ENOSPC of zpool_malloc() to increase > reject_compress_poor. But the code wouldn't get to there after commit > 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") as the > new code will goto out immediately after the special compression case > happens. So there might be no longer a chance to execute zpool_malloc > now. We are incorrectly increasing zswap_reject_compress_fail instead. > Thus, we need to fix the counters handling right after compressions > return ENOSPC. This patch also centralizes the counters handling for > all of compress_poor, compress_fail and alloc_fail. > > Fixes: 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") > Cc: Chengming Zhou <zhouchengming@bytedance.com> > Cc: Nhat Pham <nphamcs@gmail.com> > Cc: Sergey Senozhatsky <senozhatsky@chromium.org> > Signed-off-by: Barry Song <v-songbaohua@oppo.com> LGTM. Reviewed-by: Nhat Pham <nphamcs@gmail.com>
On Sat, Feb 17, 2024 at 06:36:42PM +1300, Barry Song wrote: > From: Barry Song <v-songbaohua@oppo.com> > > We used to rely on the returned -ENOSPC of zpool_malloc() to increase > reject_compress_poor. But the code wouldn't get to there after commit > 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") as the > new code will goto out immediately after the special compression case > happens. So there might be no longer a chance to execute zpool_malloc > now. We are incorrectly increasing zswap_reject_compress_fail instead. > Thus, we need to fix the counters handling right after compressions > return ENOSPC. This patch also centralizes the counters handling for > all of compress_poor, compress_fail and alloc_fail. > > Fixes: 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") > Cc: Chengming Zhou <zhouchengming@bytedance.com> > Cc: Nhat Pham <nphamcs@gmail.com> > Cc: Sergey Senozhatsky <senozhatsky@chromium.org> > Signed-off-by: Barry Song <v-songbaohua@oppo.com> > --- > -v2: > * correct the fixes target according to Yosry, Chengming, Nhat's > comments; > * centralize the counters handling according to Yosry's comment Yet Yosry is not CC'd :P The patch LGTM, but it won't apply on top of mm-unstable given the amount of zswap refactoring there. I would rebase on top of mm-unstable if I were you (and if you did, add mm-unstable in the subject prefix). Acked-by: Yosry Ahmed <yosryahmed@google.com> Thanks!
On Sat, Feb 17, 2024 at 4:57 PM Yosry Ahmed <yosryahmed@google.com> wrote: > > On Sat, Feb 17, 2024 at 06:36:42PM +1300, Barry Song wrote: > > From: Barry Song <v-songbaohua@oppo.com> > > > > We used to rely on the returned -ENOSPC of zpool_malloc() to increase > > reject_compress_poor. But the code wouldn't get to there after commit > > 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") as the > > new code will goto out immediately after the special compression case > > happens. So there might be no longer a chance to execute zpool_malloc > > now. We are incorrectly increasing zswap_reject_compress_fail instead. > > Thus, we need to fix the counters handling right after compressions > > return ENOSPC. This patch also centralizes the counters handling for > > all of compress_poor, compress_fail and alloc_fail. > > > > Fixes: 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") > > Cc: Chengming Zhou <zhouchengming@bytedance.com> > > Cc: Nhat Pham <nphamcs@gmail.com> > > Cc: Sergey Senozhatsky <senozhatsky@chromium.org> > > Signed-off-by: Barry Song <v-songbaohua@oppo.com> > > --- > > -v2: > > * correct the fixes target according to Yosry, Chengming, Nhat's > > comments; > > * centralize the counters handling according to Yosry's comment > > Yet Yosry is not CC'd :P terribly sorry. I thought you were in my git send-email list ... but you were not... > > The patch LGTM, but it won't apply on top of mm-unstable given the > amount of zswap refactoring there. I would rebase on top of mm-unstable > if I were you (and if you did, add mm-unstable in the subject prefix). This patch has a "fixes" tag, so I assume it should be also in 6.8? > > Acked-by: Yosry Ahmed <yosryahmed@google.com> thanks! > > Thanks!
On 2024/2/17 13:36, Barry Song wrote: > From: Barry Song <v-songbaohua@oppo.com> > > We used to rely on the returned -ENOSPC of zpool_malloc() to increase > reject_compress_poor. But the code wouldn't get to there after commit > 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") as the > new code will goto out immediately after the special compression case > happens. So there might be no longer a chance to execute zpool_malloc > now. We are incorrectly increasing zswap_reject_compress_fail instead. > Thus, we need to fix the counters handling right after compressions > return ENOSPC. This patch also centralizes the counters handling for > all of compress_poor, compress_fail and alloc_fail. > > Fixes: 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") > Cc: Chengming Zhou <zhouchengming@bytedance.com> > Cc: Nhat Pham <nphamcs@gmail.com> > Cc: Sergey Senozhatsky <senozhatsky@chromium.org> > Signed-off-by: Barry Song <v-songbaohua@oppo.com> LGTM, thanks! Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com> > --- > -v2: > * correct the fixes target according to Yosry, Chengming, Nhat's > comments; > * centralize the counters handling according to Yosry's comment > > mm/zswap.c | 25 ++++++++++++------------- > 1 file changed, 12 insertions(+), 13 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 350dd2fc8159..47cf07d56362 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1498,6 +1498,7 @@ bool zswap_store(struct folio *folio) > struct zswap_tree *tree = zswap_trees[type]; > struct zswap_entry *entry, *dupentry; > struct scatterlist input, output; > + int comp_ret = 0, alloc_ret = 0; > struct crypto_acomp_ctx *acomp_ctx; > struct obj_cgroup *objcg = NULL; > struct mem_cgroup *memcg = NULL; > @@ -1508,7 +1509,6 @@ bool zswap_store(struct folio *folio) > char *buf; > u8 *src, *dst; > gfp_t gfp; > - int ret; > > VM_WARN_ON_ONCE(!folio_test_locked(folio)); > VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); > @@ -1621,28 +1621,20 @@ bool zswap_store(struct folio *folio) > * but in different threads running on different cpu, we have different > * acomp instance, so multiple threads can do (de)compression in parallel. > */ > - ret = crypto_wait_req(crypto_acomp_compress(acomp_ctx->req), &acomp_ctx->wait); > + comp_ret = crypto_wait_req(crypto_acomp_compress(acomp_ctx->req), &acomp_ctx->wait); > dlen = acomp_ctx->req->dlen; > > - if (ret) { > - zswap_reject_compress_fail++; > + if (comp_ret) > goto put_dstmem; > - } > > /* store */ > zpool = zswap_find_zpool(entry); > gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM; > if (zpool_malloc_support_movable(zpool)) > gfp |= __GFP_HIGHMEM | __GFP_MOVABLE; > - ret = zpool_malloc(zpool, dlen, gfp, &handle); > - if (ret == -ENOSPC) { > - zswap_reject_compress_poor++; > - goto put_dstmem; > - } > - if (ret) { > - zswap_reject_alloc_fail++; > + alloc_ret = zpool_malloc(zpool, dlen, gfp, &handle); > + if (alloc_ret) > goto put_dstmem; > - } > buf = zpool_map_handle(zpool, handle, ZPOOL_MM_WO); > memcpy(buf, dst, dlen); > zpool_unmap_handle(zpool, handle); > @@ -1689,6 +1681,13 @@ bool zswap_store(struct folio *folio) > return true; > > put_dstmem: > + if (comp_ret == -ENOSPC || alloc_ret == -ENOSPC) > + zswap_reject_compress_poor++; > + else if (comp_ret) > + zswap_reject_compress_fail++; > + else if (alloc_ret) > + zswap_reject_alloc_fail++; > + > mutex_unlock(&acomp_ctx->mutex); > put_pool: > zswap_pool_put(entry->pool);
On Sat, Feb 17, 2024 at 2:19 AM Barry Song <21cnbao@gmail.com> wrote: > > On Sat, Feb 17, 2024 at 4:57 PM Yosry Ahmed <yosryahmed@google.com> wrote: > > > > On Sat, Feb 17, 2024 at 06:36:42PM +1300, Barry Song wrote: > > > From: Barry Song <v-songbaohua@oppo.com> > > > > > > We used to rely on the returned -ENOSPC of zpool_malloc() to increase > > > reject_compress_poor. But the code wouldn't get to there after commit > > > 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") as the > > > new code will goto out immediately after the special compression case > > > happens. So there might be no longer a chance to execute zpool_malloc > > > now. We are incorrectly increasing zswap_reject_compress_fail instead. > > > Thus, we need to fix the counters handling right after compressions > > > return ENOSPC. This patch also centralizes the counters handling for > > > all of compress_poor, compress_fail and alloc_fail. > > > > > > Fixes: 744e1885922a ("crypto: scomp - fix req->dst buffer overflow") > > > Cc: Chengming Zhou <zhouchengming@bytedance.com> > > > Cc: Nhat Pham <nphamcs@gmail.com> > > > Cc: Sergey Senozhatsky <senozhatsky@chromium.org> > > > Signed-off-by: Barry Song <v-songbaohua@oppo.com> > > > --- > > > -v2: > > > * correct the fixes target according to Yosry, Chengming, Nhat's > > > comments; > > > * centralize the counters handling according to Yosry's comment > > > > Yet Yosry is not CC'd :P > > terribly sorry. I thought you were in my git send-email list ... but you > were not... No problem, I caught it on linux-mm anyway :) > > > > > The patch LGTM, but it won't apply on top of mm-unstable given the > > amount of zswap refactoring there. I would rebase on top of mm-unstable > > if I were you (and if you did, add mm-unstable in the subject prefix). > > This patch has a "fixes" tag, so I assume it should be also in 6.8? Hmm that's up to Andrew. This fixes debug counters so it's not critical. On the other hand, it will conflict with the cleanup series in his tree and he'll have to rebase and fix the conflicts (which aren't a lot, but could still be annoying). Personally I think this can wait till v6.9, but if Andrew doesn't have a problem taking it for v6.8 that's fine too.
On Sat, 17 Feb 2024 15:14:34 -0800 Yosry Ahmed <yosryahmed@google.com> wrote: > > > > > > > > The patch LGTM, but it won't apply on top of mm-unstable given the > > > amount of zswap refactoring there. I would rebase on top of mm-unstable > > > if I were you (and if you did, add mm-unstable in the subject prefix). > > > > This patch has a "fixes" tag, so I assume it should be also in 6.8? > > Hmm that's up to Andrew. This fixes debug counters so it's not > critical. On the other hand, it will conflict with the cleanup series > in his tree and he'll have to rebase and fix the conflicts (which > aren't a lot, but could still be annoying). Personally I think this > can wait till v6.9, but if Andrew doesn't have a problem taking it for > v6.8 that's fine too. Yes, there are some pretty extensive repairs needed after this change. I'd prefer not to because lazy, and there are risks involved. So against mm-unstable would be preferred please.
diff --git a/mm/zswap.c b/mm/zswap.c index 350dd2fc8159..47cf07d56362 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1498,6 +1498,7 @@ bool zswap_store(struct folio *folio) struct zswap_tree *tree = zswap_trees[type]; struct zswap_entry *entry, *dupentry; struct scatterlist input, output; + int comp_ret = 0, alloc_ret = 0; struct crypto_acomp_ctx *acomp_ctx; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; @@ -1508,7 +1509,6 @@ bool zswap_store(struct folio *folio) char *buf; u8 *src, *dst; gfp_t gfp; - int ret; VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1621,28 +1621,20 @@ bool zswap_store(struct folio *folio) * but in different threads running on different cpu, we have different * acomp instance, so multiple threads can do (de)compression in parallel. */ - ret = crypto_wait_req(crypto_acomp_compress(acomp_ctx->req), &acomp_ctx->wait); + comp_ret = crypto_wait_req(crypto_acomp_compress(acomp_ctx->req), &acomp_ctx->wait); dlen = acomp_ctx->req->dlen; - if (ret) { - zswap_reject_compress_fail++; + if (comp_ret) goto put_dstmem; - } /* store */ zpool = zswap_find_zpool(entry); gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM; if (zpool_malloc_support_movable(zpool)) gfp |= __GFP_HIGHMEM | __GFP_MOVABLE; - ret = zpool_malloc(zpool, dlen, gfp, &handle); - if (ret == -ENOSPC) { - zswap_reject_compress_poor++; - goto put_dstmem; - } - if (ret) { - zswap_reject_alloc_fail++; + alloc_ret = zpool_malloc(zpool, dlen, gfp, &handle); + if (alloc_ret) goto put_dstmem; - } buf = zpool_map_handle(zpool, handle, ZPOOL_MM_WO); memcpy(buf, dst, dlen); zpool_unmap_handle(zpool, handle); @@ -1689,6 +1681,13 @@ bool zswap_store(struct folio *folio) return true; put_dstmem: + if (comp_ret == -ENOSPC || alloc_ret == -ENOSPC) + zswap_reject_compress_poor++; + else if (comp_ret) + zswap_reject_compress_fail++; + else if (alloc_ret) + zswap_reject_alloc_fail++; + mutex_unlock(&acomp_ctx->mutex); put_pool: zswap_pool_put(entry->pool);