Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2667991lqp; Mon, 25 Mar 2024 06:12:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW17kgUbJAZ5jNUG5NWwRxzkXBNHxqrLBqPHoxOPavAEJiL4tdmG0JZG94rmlx+xbJz8ZXZUNUnMcViCiTro68/Br4VeqxUVpsQqnEPdA== X-Google-Smtp-Source: AGHT+IHcAXlcTUUeHcuHRYmX+okNgwSz6bqoXKPGoj1cg9dG/53kUEPfrF+Ewcpxkrd7mk5DjX6W X-Received: by 2002:a05:6870:9124:b0:221:6fdb:4ee7 with SMTP id o36-20020a056870912400b002216fdb4ee7mr8416893oae.54.1711372340390; Mon, 25 Mar 2024 06:12:20 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ln21-20020a056a003cd500b006ea9662e131si5258292pfb.136.2024.03.25.06.12.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 06:12:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116613-linux.lists.archive=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=neutral (body hash did not verify) header.i=@google.com header.s=20230601 header.b=cHaNVP1l; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-116613-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=REJECT sp=REJECT dis=REJECT) header.from=google.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 15A042C5F7C for ; Mon, 25 Mar 2024 13:11:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49BD8171667; Mon, 25 Mar 2024 09:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="cHaNVP1l" Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 1E12C7319A for ; Mon, 25 Mar 2024 07:06:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711350408; cv=none; b=SND2HFQlu9wnounA5WsekeWQ1//uxzxNWBiT8IPU5KgvloVORP3dA+j4km25oTx/h24xBY7rQw4i0pcR7u3FumdCoNriZ/WfxBtPa+sYZVo3Y74w4OjfLawDcXY+Xd55Nw8gY/fe3FosB3UejXYYB4cNwypyaV622xRAg5+elKU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711350408; c=relaxed/simple; bh=tYrE2VriucY8nPiNXG/tOjiZPFifK9utBHez1C3xS9k=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=KSfdVaeClHiLLfPl5MmmkPu5rB9VFRF+L9Ye9Ibf0WasyzIA5ANFSMjOtQEedy0t5cGrgbaop77eotYoqz080q8c9HQycOs3/4JSMvZWuIm3kkxlGn5vwz4iXH8ajMlFOWAeZfeuWKIMNltrFVNdrLq/wenPnTHTyLwybnXPZqY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cHaNVP1l; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-56bb22ff7baso4622049a12.3 for ; Mon, 25 Mar 2024 00:06:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711350405; x=1711955205; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bWEJsPySa8D1x2bmugQHj3Wlfs+F7dNk4IRWtijp9Bc=; b=cHaNVP1lEV5e826S6tniwuNQO4Y+21n4eFmatyOp7T5DUEkVyPhdE3jmvCCL0HnEdy DMNrIOfSeRRzAj5iRzmWoteQD/vmfEYdd/mnx2Q+RjPP7i7Lcc2vQB0OvP+XJn2wm6LR aDLKDSFkBMDU4CdPdOad2FWyjB8WwMdEpF8Kq/+A4DyCYKotmeJH4gYQB17duQAP657J Nyj4WOWIbOIEiVZEIrVZjHSonuhCAQk0aWeLy6dfb1f2neuM7ipc3u9KA+b0X7Inv+U/ rTlMWZ9Nr3faps7PfTNy9OlK2Lo82y518j9alVso5Sej4SaC5eLzOtbTM30KyecI7Hfc 55NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711350405; x=1711955205; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bWEJsPySa8D1x2bmugQHj3Wlfs+F7dNk4IRWtijp9Bc=; b=n7L1/YLANTUUlVGCbbR10JwJubBSpHKaPBIGDN7JiCH0kw7wCtjh/qNyjRLTX/QVYL 0LQigVAD9x5u4QQBDJa1Ro7KK5qXVXAqzvaseFKEeHw1vzwbA+OV5C9opjb6H5EGW7AX e+XrJ+UKNPhBJxgJ5oO/n1ZbtdCewSJJ7p33avlaV3US2jve3Mrd7g1rbOcOO5ADWLYB QzNHL1vhISU+1gAODH8TFeuv51xItZ74vfpIKcth6m8kYo11v1TEOfYVYfInOSbeUfgK RnXhRU3rcVTSp0m2EVHiJlhNn2MpjA5nR6bB1HW1ljRzh5d3vyoMTu9+1wtRuzQ8g3f2 WgUA== X-Forwarded-Encrypted: i=1; AJvYcCWc+dTTBxqftvoMdJSAAxkWoW4rFoDIgwZ+zqQgGMMVjTp1t5FjZmECsSUGziWUR4MQq5uuHo3QzBkEcyqSb/FnTJvgCm+lYfpJ/q0y X-Gm-Message-State: AOJu0YxEtww1LIAbadcF/qdPi9LJxPyUW8lGzMxikBlXZmixpXlf5IMn B9kuYd7fMpe9HNYvP/U6C4CyPC8MGH/KdDfAv0TvP2LcqWwwuGJJsu2IRLbqjDxxmJVfWIZlu1m aofwiqqubDC5OaTGM3Ij/F1toudYtxRsz7mEP X-Received: by 2002:a17:907:1002:b0:a47:35d9:2efc with SMTP id ox2-20020a170907100200b00a4735d92efcmr3804422ejb.56.1711350405144; Mon, 25 Mar 2024 00:06:45 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240324210447.956973-1-hannes@cmpxchg.org> In-Reply-To: From: Yosry Ahmed Date: Mon, 25 Mar 2024 00:06:06 -0700 Message-ID: Subject: Re: [PATCH] mm: zswap: fix data loss on SWP_SYNCHRONOUS_IO devices To: Barry Song <21cnbao@gmail.com> Cc: Johannes Weiner , Andrew Morton , Zhongkun He , Chengming Zhou , Chris Li , Nhat Pham , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kairui Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Mar 24, 2024 at 9:54=E2=80=AFPM Barry Song <21cnbao@gmail.com> wrot= e: > > On Mon, Mar 25, 2024 at 10:23=E2=80=AFAM Yosry Ahmed wrote: > > > > On Sun, Mar 24, 2024 at 2:04=E2=80=AFPM Johannes Weiner wrote: > > > > > > Zhongkun He reports data corruption when combining zswap with zram. > > > > > > The issue is the exclusive loads we're doing in zswap. They assume > > > that all reads are going into the swapcache, which can assume > > > authoritative ownership of the data and so the zswap copy can go. > > > > > > However, zram files are marked SWP_SYNCHRONOUS_IO, and faults will tr= y > > > to bypass the swapcache. This results in an optimistic read of the > > > swap data into a page that will be dismissed if the fault fails due t= o > > > races. In this case, zswap mustn't drop its authoritative copy. > > > > > > Link: https://lore.kernel.org/all/CACSyD1N+dUvsu8=3DzV9P691B9bVq33erw= OXNTmEaUbi9DrDeJzw@mail.gmail.com/ > > > Reported-by: Zhongkun He > > > Fixes: b9c91c43412f ("mm: zswap: support exclusive loads") > > > Cc: stable@vger.kernel.org [6.5+] > > > Signed-off-by: Johannes Weiner > > > Tested-by: Zhongkun He > > Acked-by: Barry Song > > > > > Do we also want to mention somewhere (commit log or comment) that > > keeping the entry in the tree is fine because we are still protected > > from concurrent loads/invalidations/writeback by swapcache_prepare() > > setting SWAP_HAS_CACHE or so? > > It seems that Kairui's patch comprehensively addresses the issue at hand. > Johannes's solution, on the other hand, appears to align zswap behavior > more closely with that of a traditional swap device, only releasing an en= try > when the corresponding swap slot is freed, particularly in the sync-io ca= se. It actually worked out quite well that Kairui's fix landed shortly before this bug was reported, as this fix wouldn't have been possible without it as far as I can tell. > > Johannes' patch has inspired me to consider whether zRAM could achieve > a comparable outcome by immediately releasing objects in swap cache > scenarios. When I have the opportunity, I plan to experiment with zRAM. That would be interesting. I am curious if it would be as straightforward in zram to just mark the folio as dirty in this case like zswap does, given its implementation as a block device.