Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10509883rwp; Thu, 20 Jul 2023 23:42:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlFna3o53xZZfA8Suh562OxJTtqqXKlE2Gn1d0TrsxP9uvI+O1x3yunOVTFuOKMT4+HhkrRf X-Received: by 2002:a05:6358:6f8c:b0:135:aed4:99b4 with SMTP id s12-20020a0563586f8c00b00135aed499b4mr1107610rwn.4.1689921719798; Thu, 20 Jul 2023 23:41:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689921719; cv=none; d=google.com; s=arc-20160816; b=I7QAVlvudmSoGZkmhoLhpmgawvIwTnIeY+YsdSnn46iMLs0ti6FoY12WEZPQHg0bFZ mqwuV/h6myBS9kylf/5wbL02VW5E39IKCDr0jNHEkN+tlfrjCF9XDAAXBCKhqVIn7Ws2 Xm4StnKpdqbmVzzsYdKnCrtJ4oH/BMaS6kXaZt+6R231D5/OCu0aofeaBAO3VHWAFXMX 2G83XrFiEPUghRwMAq1mDP6y5XxjphKFOJjsdhOztpQHZKvdlbf+YvgNrLtUdIK598pX 4sosIj3jkj9SBRwTTGCi8qcn3dVM/0x7Hstz8faJWk/XKgw2QQb/BxMQLyX22hOTl3OU sWfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=8PU+yLqgU8QTJBPsYq/TunQLzed36dffCDsGG++Ehj4=; fh=LH9453GSCtiX2JYOxYyPoonQfWyhTB6f94e57Bg7w0U=; b=fLJwFtGbQ08FkPf/97UbtRcBYgKuk1z8RZF3aY6W+c5w5jNzMYejB9+7ZbreC8xZsi ct5JCXp9HE7gBN63JJKhYPIZ0IvJR+LmBNM6OUj/nhVgAoLZTl9nYvh8bgkFcd77x5FY w2neIZuicfzlHhW3un9RkBL4swPuZcL4xHMb1TNbOg3tXXe89ENaEGROnCfccXtsRHLw TNDBMOJg1Ka3Fv+uU+cos/79HpQngDdoJ+1IIC+3t5lpUtkzM5bXMI7p3mf8Itdu3X3F wHkZqFLl32J4k+z7kar0E1pcANRKaJU5OM4tXJVQzmq/S3cE+hU77ovvQPKrcRXpwi6Q +KGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="BC6yyje/"; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s28-20020a63525c000000b005321c340960si2258108pgl.811.2023.07.20.23.41.47; Thu, 20 Jul 2023 23:41:59 -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; dkim=pass header.i=@mediatek.com header.s=dk header.b="BC6yyje/"; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230078AbjGUGiV (ORCPT + 99 others); Fri, 21 Jul 2023 02:38:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbjGUGhz (ORCPT ); Fri, 21 Jul 2023 02:37:55 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2FBD2D73 for ; Thu, 20 Jul 2023 23:37:14 -0700 (PDT) X-UUID: 04ea9c30279111ee9cb5633481061a41-20230721 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=8PU+yLqgU8QTJBPsYq/TunQLzed36dffCDsGG++Ehj4=; b=BC6yyje/DPkjGRTu+OcNYoePBzsC/1kTblnXEpQjJkrom8MJQJd+LJnxJ/Gft9iB2t7Ji2i4L9B7QzQ4wosoUuferBugCcMtZLIqxVOOrd4FYereCMegVjM52p2DaoK0w1gv8W9Jd+j/dyb5+ADnjTnN15PunAsrS8d+zXLgq2A=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.28,REQID:47b59bd3-0170-427b-a5e9-f554744b6943,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:176cd25,CLOUDID:cefef64c-06c1-468b-847d-5b62d44dbb9b,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO, DKR:0,DKP:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 04ea9c30279111ee9cb5633481061a41-20230721 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 2070794451; Fri, 21 Jul 2023 14:37:10 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 21 Jul 2023 14:37:08 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 21 Jul 2023 14:37:08 +0800 From: Andrew Yang To: Minchan Kim , Sergey Senozhatsky , Andrew Morton , Matthias Brugger , AngeloGioacchino Del Regno , Sebastian Andrzej Siewior CC: , , Andrew Yang , , , , Subject: [PATCH] zsmalloc: Fix races between modifications of fullness and isolated Date: Fri, 21 Jul 2023 14:37:01 +0800 Message-ID: <20230721063705.11455-1-andrew.yang@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,T_SCC_BODY_TEXT_LINE,T_SPF_TEMPERROR,UNPARSEABLE_RELAY, URIBL_BLOCKED autolearn=ham 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 Since fullness and isolated share the same unsigned int, modifications of them should be protected by the same lock. Signed-off-by: Andrew Yang Fixes: c4549b871102 ("zsmalloc: remove zspage isolation for migration") --- mm/zsmalloc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 32f5bc4074df..b96230402a8d 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1777,6 +1777,7 @@ static void replace_sub_page(struct size_class *class, struct zspage *zspage, static bool zs_page_isolate(struct page *page, isolate_mode_t mode) { + struct zs_pool *pool; struct zspage *zspage; /* @@ -1786,9 +1787,10 @@ static bool zs_page_isolate(struct page *page, isolate_mode_t mode) VM_BUG_ON_PAGE(PageIsolated(page), page); zspage = get_zspage(page); - migrate_write_lock(zspage); + pool = zspage->pool; + spin_lock(&pool->lock); inc_zspage_isolation(zspage); - migrate_write_unlock(zspage); + spin_unlock(&pool->lock); return true; } @@ -1858,8 +1860,8 @@ static int zs_page_migrate(struct page *newpage, struct page *page, * Since we complete the data copy and set up new zspage structure, * it's okay to release the pool's lock. */ - spin_unlock(&pool->lock); dec_zspage_isolation(zspage); + spin_unlock(&pool->lock); migrate_write_unlock(zspage); get_page(newpage); @@ -1876,14 +1878,16 @@ static int zs_page_migrate(struct page *newpage, struct page *page, static void zs_page_putback(struct page *page) { + struct zs_pool *pool; struct zspage *zspage; VM_BUG_ON_PAGE(!PageIsolated(page), page); zspage = get_zspage(page); - migrate_write_lock(zspage); + pool = zspage->pool; + spin_lock(&pool->lock); dec_zspage_isolation(zspage); - migrate_write_unlock(zspage); + spin_unlock(&pool->lock); } static const struct movable_operations zsmalloc_mops = { -- 2.18.0