Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5691166iob; Tue, 10 May 2022 01:05:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7EkTtgfAGlbnWR1Ms5pw6AsaG1E2YlNcc8K37TzAqdTeBFITJ90dbUvbcEx3e1VquADwR X-Received: by 2002:a17:906:7944:b0:6da:b834:2f3e with SMTP id l4-20020a170906794400b006dab8342f3emr19100981ejo.353.1652169903668; Tue, 10 May 2022 01:05:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652169903; cv=none; d=google.com; s=arc-20160816; b=FPWz6e2RNRUkNxuje985JoKbWMviXAZfERUF5aAa1dLn4WB/mUklO+dxFwX5SrSM/h CtYPIh5mPJnIqOlrFBG3WgfZx2Hgsh1ulF6T6NpM8aF9n7Byw35HXhxYzQvGWMVPPvuG O/ryxGBelHtzCklbYt87Kb+UIRWIg7bvDkWMan5dem/tvZVRTd3Io4rD/6Jvt2Rg2hkS 34s1uvCW9w9Y72wxp7/3LBXwQLm/d7Y0TIfEC4SjzGr5GUNC5TFritslGF5ZGWiH3kkO xQlQtD6/ROqBXr5L49fu5ZqxjfunoLBC4f0Cq5G6mjS+8/nGHODv02InZlEUHBjJxe3h A9fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=UbbErnk4URiyhDcgHPYh2QePDGVMcd5mePLEmIA+Vog=; b=r/HZdgl4iiLMW91cKq/72HJJ9SEgwhgrGDlYIGIoFaio3oYLOmVIf2U7zLdsb6gYOm CNjGmwRqWwo3yG5Ez9mqlCO4TFT/bp0f9XyXABz0oFbPV75/rLAGcLwVaoTz3HNbDYld 5MqW+sN36fCpeb7lV2baIo7svFLyrykBKfrvs6igx96xwjk4x7BToOn30mZbtHdniIzm iu60WVa0uNlVqkWNm/OL7aeWsD3CK/4fO5ga1nZroLQY6GPjngTbvENKEmhOIOA2ckh9 K7N1LZTDrhNYxP+KISSyowUdCHlbp9jwSnFTvnHpVtUcNoXqVXi1D6hbbRqxrRtRbzum HonA== 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 z21-20020a056402275500b00425c9e23d04si19883326edd.295.2022.05.10.01.04.39; Tue, 10 May 2022 01:05:03 -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 S234246AbiEJB0N (ORCPT + 99 others); Mon, 9 May 2022 21:26:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234153AbiEJB0A (ORCPT ); Mon, 9 May 2022 21:26:00 -0400 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4A3525E9; Mon, 9 May 2022 18:22:04 -0700 (PDT) Received: by mail-pj1-f54.google.com with SMTP id qe3-20020a17090b4f8300b001dc24e4da73so740257pjb.1; Mon, 09 May 2022 18:22:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=UbbErnk4URiyhDcgHPYh2QePDGVMcd5mePLEmIA+Vog=; b=Iu2i349IulMWOLGqOZSiPtzMZi3jl8ufOkn//nui20VHCRcD/4O7hMPG6+2RMQqMkp ZV3OEjN8kDuAm6bfbzvclSZ0wRNAIwqBm/K5Tkt6tXDKfgA9uQO2iwJqxtE782uIb3UB gmuNkg2SXoE+Mu8asZ/lf4kWc3Iajp2TmALTJEqKLyWpvo1i1v+pYMujIarElkxsNe6r uTYT3u4otIV9UZYCsX1eCDenHa1qGdFrAoP3PtJngueGCbPAcwgOOFtQy/P9mZhCQdKC SGP3dBumnr/wzKwD+eVICgwBPBJTbvjKeFfdYy5mkAKjv3ItNLIr051E8UaeR1iV1nOQ J92w== X-Gm-Message-State: AOAM533x9yBY61/QkVFr1P6hRBjj/VGqX5KCx8wDi8RDXMMPf4ScFYcJ 0wYJGIYYAjtX/nzQDtx+Ncw= X-Received: by 2002:a17:90b:3b81:b0:1dc:32ac:a66b with SMTP id pc1-20020a17090b3b8100b001dc32aca66bmr20577182pjb.49.1652145724182; Mon, 09 May 2022 18:22:04 -0700 (PDT) Received: from sultan-box.localdomain ([204.152.216.102]) by smtp.gmail.com with ESMTPSA id be12-20020a056a001f0c00b0050dc76281basm9376105pfb.148.2022.05.09.18.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 18:22:03 -0700 (PDT) Date: Mon, 9 May 2022 18:22:01 -0700 From: Sultan Alsawaf To: Andrew Morton Cc: stable@vger.kernel.org, Minchan Kim , Nitin Gupta , Sergey Senozhatsky , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] zsmalloc: Fix races between asynchronous zspage free and page migration Message-ID: References: <20220509024703.243847-1-sultan@kerneltoast.com> <20220509170632.fec2f56ad9f640329330b9de@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220509170632.fec2f56ad9f640329330b9de@linux-foundation.org> X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Mon, May 09, 2022 at 05:06:32PM -0700, Andrew Morton wrote: > Why not simply lock_page() here? The get_page() alone won't protect > from all the dire consequences which you have identified? Hi, My reasoning is that if the page migrated, then we've got the last reference to it anyway and there's no point in locking. But more importantly, we'd still need to take migrate_read_lock() again in order to verify whether or not the page migrated because of data races stemming from replace_sub_page(), so I don't think there's much to gain by using lock_page(). When any of the pages in the zspage migrates, the entire page list is reconstructed and every page's private storage is rewritten. I had drafted another change that fixes the data races by trimming out all of that redundant work done in replace_sub_page(), but I wanted to keep this patch small to make it easier to review and easier to backport. Sultan