Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp283278pxy; Wed, 21 Apr 2021 02:57:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ2jq8fKqnPFmvnbwkPc6O4sp9e2tA+hsUZupkpC9/DU1j2HwiTmliPUjRkmXAR5tmrnkd X-Received: by 2002:a17:906:af13:: with SMTP id lx19mr31257141ejb.508.1618999028545; Wed, 21 Apr 2021 02:57:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618999028; cv=none; d=google.com; s=arc-20160816; b=ILMkW5+ZcF/NXVVVSM4sZAr1f44GwNUfuNUMRGyml7cWk6n/I/YYi7PSg2YaAz9KK5 /fw0QKMNELyE9HzMa7ZafitVUvnZ1pawMSRG2UyICqE45wlNohFCnv48rQv9E1fnpWOX ua0pNZGv7YDTZqZGB73wROsHxwpolD8sQtdZISjqUn7Hprc994xrC6fn0Himx6WMWBhF vwph+ajF/m/owRl/slDx6tJ6fQb40lgCTMI+DwWMe7fD88NyR0e0PQ3WF3bziHtG7fPa uu3rb3L6j5l8KW6ud9nYAZG0cs2d8RjQxeIwKWaIfJe9B0yY6VTMpyqzJiV/2twy2Alg qKkw== 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:dkim-signature; bh=yNLpmnjZvLgvr5Vp7qHy21lL8CBq37TPhjd9iVUM/40=; b=onQaBzQmpoMrPHXzkjbj1hmcr7S47kcaeMBAUB33eJzBI/6mgwdCU4uNnYBNzu4E0l vWuTtqaJQu8rQ7g6k2MW6wh4txIKYMDVtgTkla3aRm2kCmh1WGP6AP6ILN/roftRz3RE qvVtMjdIavGUxPt4HwRicRyMSgbJQkJ2h191WEhgDH5qY7j8yswQV+v0Tz5mCbkygSUb 1lQlepmGPavXtu/ujoTEs5BFhwi32jdWlnDdyn7boZM6OCsxHdFABb8Yya9WzNVMzF3R BwOVwv3IFG275nmV1W0+5sfCNmZYoTZ6ZJuf5YQ3387gK3pA93dXHU528fCVzUgk1V3q POkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=XYCidtr1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si1589235edb.177.2021.04.21.02.56.45; Wed, 21 Apr 2021 02:57:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=XYCidtr1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234823AbhDUI0J (ORCPT + 99 others); Wed, 21 Apr 2021 04:26:09 -0400 Received: from mx2.suse.de ([195.135.220.15]:52550 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234532AbhDUI0J (ORCPT ); Wed, 21 Apr 2021 04:26:09 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1618993535; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yNLpmnjZvLgvr5Vp7qHy21lL8CBq37TPhjd9iVUM/40=; b=XYCidtr17qgV1sCe55LfWvxlRgzQe1U/Cx3LPjFDKfuqEWPzul4cT8EdyLBpTHaAWSQyjC pitwDM/gJtkPX01GjKPb9QxzcVdw/Wp48G+BgxSa9mYCgBPkDy6L5nW+Lxi0WTA17/tM9H vttHXBO+oPkTRLtxiP16nc/4cyZvkpk= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C94D6AE85; Wed, 21 Apr 2021 08:25:35 +0000 (UTC) Date: Wed, 21 Apr 2021 10:25:35 +0200 From: Michal Hocko To: Muchun Song Cc: Mike Kravetz , Andrew Morton , Oscar Salvador , Linux Memory Management List , LKML , Naoya Horiguchi Subject: Re: [External] Re: [PATCH] mm: hugetlb: fix a race between memory-failure/soft_offline and gather_surplus_pages Message-ID: References: <20210421060259.67554-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 21-04-21 16:15:00, Muchun Song wrote: > On Wed, Apr 21, 2021 at 4:03 PM Michal Hocko wrote: > > > > [Cc Naoya] > > > > On Wed 21-04-21 14:02:59, Muchun Song wrote: > > > The possible bad scenario: > > > > > > CPU0: CPU1: > > > > > > gather_surplus_pages() > > > page = alloc_surplus_huge_page() > > > memory_failure_hugetlb() > > > get_hwpoison_page(page) > > > __get_hwpoison_page(page) > > > get_page_unless_zero(page) > > > zero = put_page_testzero(page) > > > VM_BUG_ON_PAGE(!zero, page) > > > enqueue_huge_page(h, page) > > > put_page(page) > > > > > > The refcount can possibly be increased by memory-failure or soft_offline > > > handlers, we can trigger VM_BUG_ON_PAGE and wrongly add the page to the > > > hugetlb pool list. > > > > The hwpoison side of this looks really suspicious to me. It shouldn't > > really touch the reference count of hugetlb pages without being very > > careful (and having hugetlb_lock held). What would happen if the > > reference count was increased after the page has been enqueed into the > > pool? This can just blow up later. > > If the page has been enqueued into the pool, then the page can be > allocated to other users. The page reference count will be reset to > 1 in the dequeue_huge_page_node_exact(). Then memory-failure > will free the page because of put_page(). This is wrong. Because > there is another user. Yes that is one of the scenarios but I suspect there are more lurking there. That was my point that this should be addressed at the hwpoison side. -- Michal Hocko SUSE Labs