Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4496465ybi; Mon, 15 Jul 2019 09:48:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjwK6Os4x+0Hz2M1j8Qhm7y11+bCG9e72GdeBWhhUplBZyMeETeuIUNA+B8Ki0jS8SofxR X-Received: by 2002:a63:6056:: with SMTP id u83mr24780231pgb.181.1563209298420; Mon, 15 Jul 2019 09:48:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563209298; cv=none; d=google.com; s=arc-20160816; b=PQAW1/UyaGwOL8LhOr1X+NtTyweYm5cjy4MLEgujAVn7AWvpO5TN0NIqTshKoe48LR IR6IfU+k/E2bmyvurVwB/TaTf1ybOR3wLWXnnesacPhs7g7lCOqxmABXY+Zk7HJBHx1j 1l4IW+yk/mUfrTvx86ZPNg7y/YYBYz1Sh3rQKh9VqdLsGydRKq4UVx0iEjQkNskhiT5S 3WC42QNfd+qIgOjG/ZJktBLVjJsKMEdtihXHE9OmzJQ0vUmQhFa2zYtDxKsalxzjwfFE ifobj+mxTiLpV6U31dYLkbWNNSDsT41KSKQZcBkE04EPK/BKQbUYOpNJP50E2MIUdujp unoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=uefiGP790QPlHmhELnOTMDg4Gfv1ldPwSxnEHTELlh4=; b=mdMeQAWoRxSYtM4yzUxxvNUAcLnPSd0xPLWYKm291j6V6KizLWvAcG5eor27dauSV2 ttYI2hkDNGUUIqyK7FXdkFccxeuePWsFuErm+45fXlScmqlciCzcNUnMAjkm/JXlP6Fc N329ePttGs9HpyTTEPqxbOXLI2/TlcEIyHQ1Jm1TQ6JhP6MvuOBCLzXsEnUoeFDTPsJR 7qKSSv8wFh8S6nwFARs6sUPYhVuI8VN+x2nCQcYox0ZCPsHw9/XcXVNzrK/m3E2jZVVv fZBlPqYJJaARhhQEhRvJ86YTOmeSx9eWWyUXbQbssZkSyxrXKZveHnoSdbXflL9munpN A0oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YeBZBrSX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 6si16870975pgb.201.2019.07.15.09.48.01; Mon, 15 Jul 2019 09:48:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YeBZBrSX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731452AbfGOQrm (ORCPT + 99 others); Mon, 15 Jul 2019 12:47:42 -0400 Received: from mail-qk1-f202.google.com ([209.85.222.202]:56149 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729941AbfGOQrm (ORCPT ); Mon, 15 Jul 2019 12:47:42 -0400 Received: by mail-qk1-f202.google.com with SMTP id m198so14146656qke.22 for ; Mon, 15 Jul 2019 09:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=uefiGP790QPlHmhELnOTMDg4Gfv1ldPwSxnEHTELlh4=; b=YeBZBrSXtK9i0HJSVVv2OwHsZlDPNrQA38z/OP0Renlqzd0x8ogg6n9oOCOxRZ/qJX 2AFyJyFpg1T1qww+sFCfX4m+DLyS53IgMyeu1hTMwdzvac1reuMswpgPAbjchx8I44XD fTWAXvuAXFBDzH4LdWpWN5jKmuC0JAYcMKLII//xrW7oz2dgVjc34ys4nbJDLcGFLFg6 hbJD7DHbO3okpeMb0YQw1fsqgya5/i7c5TpasVmFLqZuZZFs9wUa/O7K2vxk3tAXzORg +TBEy4PIZSjdM5zWz8MjB1WoK2H5ny25+wl5R6aKGS+eF9K8N/Y14yXFkgTIXR1hGUPR THYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=uefiGP790QPlHmhELnOTMDg4Gfv1ldPwSxnEHTELlh4=; b=TEyW3XY7xXyllMbruBcwMbzvt8KAE0VgRuigyD9NnemFnVvNBQWQaSSCUJHaEj0QrS wQtznCHrIUGa5fjdnTMukJAetAhnbV1iQulG02CrdDxW/f5noED6ISZJo+/NLoLKieCf p/2S3AxSWO0/2a9x470xxFOlcJcohAuL1FPoYobkPZDsgsdeHyX6P/j3dPdWkhP10ZJk z3aSrWr4Pm3wKSuZ5HN3w/deIeEzODjTnkKPOoHDpyG2MJR5hBwWNSjWRuBBlYNdRGGt 3rxh8kTsVG7qXYmH6m8JypTgXrV+0KlK7cE7PNdNc3JEr9DhzpR2rMmrxQos+eokA8Cp dsAA== X-Gm-Message-State: APjAAAXMVck8Kgd/7bayKQ+Vl/NLzQIUdsro0DcV1JUivQIYG5j6xdAp 4pxaVe6Swnl7aURTK0S8ff8wVuQU7yEEjmS2 X-Received: by 2002:a37:a343:: with SMTP id m64mr17595893qke.75.1563209261293; Mon, 15 Jul 2019 09:47:41 -0700 (PDT) Date: Mon, 15 Jul 2019 09:47:05 -0700 Message-Id: <20190715164705.220693-1-henryburns@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH] mm/z3fold.c: Reinitialize zhdr structs after migration From: Henry Burns To: Vitaly Wool , Andrew Morton Cc: Vitaly Vul , Shakeel Butt , Jonathan Adams , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Henry Burns Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org z3fold_page_migration() calls memcpy(new_zhdr, zhdr, PAGE_SIZE). However, zhdr contains fields that can't be directly coppied over (ex: list_head, a circular linked list). We only need to initialize the linked lists in new_zhdr, as z3fold_isolate_page() already ensures that these lists are empty. Additionally it is possible that zhdr->work has been placed in a workqueue. In this case we shouldn't migrate the page, as zhdr->work references zhdr as opposed to new_zhdr. Fixes: bba4c5f96ce4 ("mm/z3fold.c: support page migration") Signed-off-by: Henry Burns --- mm/z3fold.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/z3fold.c b/mm/z3fold.c index 42ef9955117c..9da471bcab93 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -1352,12 +1352,22 @@ static int z3fold_page_migrate(struct address_space *mapping, struct page *newpa z3fold_page_unlock(zhdr); return -EBUSY; } + if (work_pending(&zhdr->work)) { + z3fold_page_unlock(zhdr); + return -EAGAIN; + } new_zhdr = page_address(newpage); memcpy(new_zhdr, zhdr, PAGE_SIZE); newpage->private = page->private; page->private = 0; z3fold_page_unlock(zhdr); spin_lock_init(&new_zhdr->page_lock); + INIT_WORK(&new_zhdr->work, compact_page_work); + /* + * z3fold_page_isolate() ensures that this list is empty, so we only + * have to reinitialize it. + */ + INIT_LIST_HEAD(&new_zhdr->buddy); new_mapping = page_mapping(page); __ClearPageMovable(page); ClearPagePrivate(page); -- 2.22.0.510.g264f2c817a-goog