Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp86701ybi; Mon, 15 Jul 2019 17:08:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzAnbJUrZ0Ng9TBKoeF62aWLvZMI3we1mo3Ngd+HXELiVRW85bkGTnmzqwewvOfnlNzL6w1 X-Received: by 2002:a63:db45:: with SMTP id x5mr18145245pgi.293.1563235720654; Mon, 15 Jul 2019 17:08:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563235720; cv=none; d=google.com; s=arc-20160816; b=fk3a+un2BmN95EsC01awtQo5ob818Sxpjoxlo2JzbPQ++Rl4qvsZlJxL36jGFLxLvc H0kuDh9j9j/d6e7DHYUhSy0Di7ZXveuC4jPqcA4m0gGzoG5dbpTGrH4BA8LVX3n3s5PU b642L18u69XoLnFnP7TFqYrUaxZzAV5/CEfxcWnUlU7YZ32YaVsFwcpA2h1xVp2S/Fnq UUU3D98KiaUh2xrdoEyYNcFGjp2dtbbwH2Yz9IylSgPVCDVqAiXq2uFjdXor5OvAlcPs 9i5njUmpyH6q9nss9NhLYgs3uo71YVPau/xynBmnAFiS/rSVryeO576is/5OUcCG1kLE hvGQ== 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=bM16Cxlynj/iYFnBhEVrgD674cLfvqLU43B4Z5mZd8I=; b=v+kD0Cb5LOhOPR9vNCXu8RHYkKPrly7sKZ6Ul+ywLVWXoRo0T6S11sUlRwH01NLEFF X8ev70jIHyqdGcSMNfla5pEXHEzBiDQFAi73aMW8l4mSBOoFnm2RuunGcengCNXEm8em /aU5I7PBgmbDXQwv4NgwpS3s+SUWSymkpRV/4OoDYmKS75gXvqX8+c9v9/k5+hE1xkWk CLOmPc100PMTWEsZR4HafhGphxqpHzTQ76E44d3MgEQbuRXyCJemRPdLzJOUpkYoRONA 8//f0aYY5UcrSNNQ2gfY+QeBp1UenAQYzOmHJrLBwwO32A91pvSczQXXyx8+2vB7ICEs tZzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="r/N2p4ZH"; 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 u46si17828474pgn.578.2019.07.15.17.08.08; Mon, 15 Jul 2019 17:08:40 -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="r/N2p4ZH"; 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 S1732839AbfGPAF0 (ORCPT + 99 others); Mon, 15 Jul 2019 20:05:26 -0400 Received: from mail-vk1-f202.google.com ([209.85.221.202]:54407 "EHLO mail-vk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730888AbfGPAF0 (ORCPT ); Mon, 15 Jul 2019 20:05:26 -0400 Received: by mail-vk1-f202.google.com with SMTP id w137so9105840vkd.21 for ; Mon, 15 Jul 2019 17:05:25 -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=bM16Cxlynj/iYFnBhEVrgD674cLfvqLU43B4Z5mZd8I=; b=r/N2p4ZHJhSkKWCbefj7oLG94wDUQjVPvpVsO2bZgKuDB6odzuwkhgqvbFRar5HUSM F0Uee5JIrhmDjcjHNCYqP0u8lHTYYSn3P5mPCGUqXgaEfFm0vlsGVxLj41XRkh4JassI T55j3gjAdlSg1uZ8LLEGxKrPlRyotdJfmag6H/o9kkWnFeHryKqaCuOkKEDMzD7SCS18 64inrAv4F0E2JBmU86ETFJNPwo7XAlMBkS+jTgXic46jJcC/gfZFvRu2rZuCrPBU/+DD UWyMrmLLTGyjqm4yYyaofcm9Nw3LgJzqsQ+8xMf57fKGz/XDrayl8zrfMiG8bQejHqWU TV2A== 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=bM16Cxlynj/iYFnBhEVrgD674cLfvqLU43B4Z5mZd8I=; b=q8VJ3IiCXd1OyspFgsscK+k1hP4ZtCI9n3eAKbzxhDr0fDxsximaZ9ODCoiH7E3A5T 8C23Tvlhbzg7uwAcIBQWNOMW1PD308nYOLg8df3hUGutrus3uq9KexUlMiYjGmh5yL0s Mv8tqYphUxLYqOBROPVq4dJbtJ3L8HUBZC5M00u3i8czF7sqMrZL2HFsko8pULf1q4jb CWZ9Z11x/jGBgRGmhBYJijfDHT/mcDiqiIr467AAQgRHQ2I7f8dRaHT2RPwmErfGXL1u Gyj4Eae3y7duxZI4iFECwNc1tcZ0P8FPwFPDveJiuGcIiIHsoBu/Jz/GmO9iw6x+BuXc Ab7w== X-Gm-Message-State: APjAAAXrEVqxql4P9OhdvtgsDoShbo4gRjSTxr0OiPBuuM/420KQL6Ig tI22z3iKNWLBi8OFHvZgwMCOZHMQy0Cjr/kP X-Received: by 2002:a1f:dec7:: with SMTP id v190mr11423849vkg.39.1563235525244; Mon, 15 Jul 2019 17:05:25 -0700 (PDT) Date: Mon, 15 Jul 2019 17:05:20 -0700 Message-Id: <20190716000520.230595-1-henryburns@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH v2] mm/z3fold.c: Reinitialize zhdr structs after migration From: Henry Burns To: Vitaly Vul Cc: Andrew Morton , 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 --- Changelog since v1: - Made comments explicityly refer to new_zhdr->buddy. mm/z3fold.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/z3fold.c b/mm/z3fold.c index 42ef9955117c..f4b2283b19a3 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 new_zhdr->buddy 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