Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2748691ybi; Mon, 1 Jul 2019 18:17:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzm1ERtkY9yTQmUt9B9fdm+JJdxLYMzewmBQIWCFcyt7CHY7P6RkeqDxDc0P/g/uMd7k+wK X-Received: by 2002:a17:90a:8d86:: with SMTP id d6mr2453259pjo.94.1562030267455; Mon, 01 Jul 2019 18:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562030267; cv=none; d=google.com; s=arc-20160816; b=SIPQUtQ63fQ28n88dA+g8vPTkoykh+1vYkPa93owOSCBAPWtEob0gwIM+LrF/KEDbw nFzLHcO/J4DZw9NYNJDT2aDK8ZB9VYdH6Tp50BFPGmqc3228rouFA94DFTDb/DSrq7PC diwBklH4X8Nh7Aj6pwPtc6xgDfZ9MaV84Q/8bylKfrEujnydoGIGSYNRPN7QU+2ohh07 RkgLoVktAbDYUvcF5iG6zieSTIn9a+vXentipjhhiQDXCX7sxLa95m1FH3OLAxzqsaaf aHN4UzcMeucyBk+uyavsoOBGenEQkHyxxNb2uhOlCOD80IJpg3Bl+md9it+kpAfUAwDG ZbXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bGcgCNZM2Fneaix4f2ZBOZNpZLRiuOjV16Tk5yHyGgI=; b=yvyJY3a4Ds3O3ajPEU+dzTKv9nHhhq4BwS5fAeigxr709D/9VfJB4dADhI/x2jsheK kO/XtYwuqdD6KeJc1bCW/pktTehW44yJovJXJ8F0hckc1H8xyCZg85INmBLz9bJRoaDA T7JTYbywq7m1hFJegRC+hhnbnu/wPIoSCOOxlhQMRu4pBG9ZTubnt0j0OLaRvqjhTh/K H/yB4rhoZy4vOUv9lgK7NcogAroPh9efzNzC/XvSdXaUM84xJ8ZRLwRjJjZT78sm6hR5 TamNThBb5y7Es89A8Si7stuKodzEsi8bJDMe6izfPZdkzikK/qqFp8Cm3Oc6ne5zc+Us nJGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=E+IhI3EF; 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 o6si1009214pje.1.2019.07.01.18.17.32; Mon, 01 Jul 2019 18:17:47 -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=E+IhI3EF; 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 S1727108AbfGBBRH (ORCPT + 99 others); Mon, 1 Jul 2019 21:17:07 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:32812 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbfGBBRH (ORCPT ); Mon, 1 Jul 2019 21:17:07 -0400 Received: by mail-io1-f68.google.com with SMTP id u13so33303198iop.0 for ; Mon, 01 Jul 2019 18:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bGcgCNZM2Fneaix4f2ZBOZNpZLRiuOjV16Tk5yHyGgI=; b=E+IhI3EFrprAxwYz5XL+dCV+y22CzQKMuhlzlsky6+02t5cScdlAo3mb1JWWpTE8JK qOiH8sX9JUtanurv+qeY6OyoQdYIumvOrbXWbMONgeUsy3svK67NSEEVHLTUEnq3T93Z WjZDPGzT/Sm2ne1EOi9XJQs5bBTlLyY4StGuUgRBRl43AIlvqC//mFi9EXC7VsIo0Kh3 jrQZCZJrfABLTciTv3tMxTQGTBUVHUWqVv938g1y0Q16KV5JwOslf+zytRH6fcmtncNz r6/n3C1dVWSPxwTP7ZDAaOUFkZcs4oCQFhYFOT3zAF2OLakwlo+vH3fKStApBz3cwpI7 acHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bGcgCNZM2Fneaix4f2ZBOZNpZLRiuOjV16Tk5yHyGgI=; b=uXp9f3FoTrpWEVgzkMNb/mW6hZjFzxw9cIXJf6NtEVr6VkyHZpCtuQl0KlFdFqIPA6 xg/cAePAmHkJC3KHgoZbSnGE1TvBZaouK1Lbdvj6xapvUthwYQiJ/nGmIaJ84s4XYoKv bN0iut18ulYIzlrano/JJEGQ3BDj3bWmEmavCTZlf207SbuCW1ydX+COqK44YnZ3lGNB gRNDcAIqZpbzik97tyIumUSQhVHXLA9YC/bKeGo7xTvd4yiCfh3JqVVHj9pP6KZ3AgTp bVEf8GGdePr1NFqZano6rGgJQxWXUqQqjUowNP7Mb8bGNe1e6E87RIMeSJcA+DJHOS0E wiXA== X-Gm-Message-State: APjAAAWe4zYWx/suB06aLxVO+D3ab614Gk54nfJc+fd9Vm6LNd44eDv+ YhEno+J1xkzbUx+6pIrpBvKPQ5Xm68luCA2s76E3Hw== X-Received: by 2002:a05:6638:3d6:: with SMTP id r22mr31783750jaq.71.1562030226625; Mon, 01 Jul 2019 18:17:06 -0700 (PDT) MIME-Version: 1.0 References: <20190702005122.41036-1-henryburns@google.com> In-Reply-To: From: Henry Burns Date: Mon, 1 Jul 2019 18:16:30 -0700 Message-ID: Subject: Re: [PATCH v2] mm/z3fold.c: Lock z3fold page before __SetPageMovable() To: Shakeel Butt Cc: Vitaly Wool , Andrew Morton , Vitaly Vul , Mike Rapoport , Xidong Wang , Jonathan Adams , Linux MM , LKML 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 On Mon, Jul 1, 2019 at 6:00 PM Shakeel Butt wrote: > > On Mon, Jul 1, 2019 at 5:51 PM Henry Burns wrote: > > > > __SetPageMovable() expects it's page to be locked, but z3fold.c doesn't > > lock the page. Following zsmalloc.c's example we call trylock_page() and > > unlock_page(). Also makes z3fold_page_migrate() assert that newpage is > > passed in locked, as documentation. > > > > Signed-off-by: Henry Burns > > Suggested-by: Vitaly Wool > > --- > > Changelog since v1: > > - Added an if statement around WARN_ON(trylock_page(page)) to avoid > > unlocking a page locked by a someone else. > > > > mm/z3fold.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/mm/z3fold.c b/mm/z3fold.c > > index e174d1549734..6341435b9610 100644 > > --- a/mm/z3fold.c > > +++ b/mm/z3fold.c > > @@ -918,7 +918,10 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp, > > set_bit(PAGE_HEADLESS, &page->private); > > goto headless; > > } > > - __SetPageMovable(page, pool->inode->i_mapping); > > + if (!WARN_ON(!trylock_page(page))) { > > + __SetPageMovable(page, pool->inode->i_mapping); > > + unlock_page(page); > > + } > > Can you please comment why lock_page() is not used here? Since z3fold_alloc can be called in atomic or non atomic context, calling lock_page() could trigger a number of warnings about might_sleep() being called in atomic context. WARN_ON should avoid the problem described above as well, and in any weird condition where someone else has the page lock, we can avoid calling __SetPageMovable(). > > > z3fold_page_lock(zhdr); > > > > found: > > @@ -1325,6 +1328,7 @@ static int z3fold_page_migrate(struct address_space *mapping, struct page *newpa > > > > VM_BUG_ON_PAGE(!PageMovable(page), page); > > VM_BUG_ON_PAGE(!PageIsolated(page), page); > > + VM_BUG_ON_PAGE(!PageLocked(newpage), newpage); > > > > zhdr = page_address(page); > > pool = zhdr_to_pool(zhdr); > > -- > > 2.22.0.410.gd8fdbe21b5-goog > >