From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65DFAC54FD0 for ; Wed, 25 Mar 2020 08:36:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2639F206F6 for ; Wed, 25 Mar 2020 08:36:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="S5JjwHA3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2639F206F6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9E5526B006C; Wed, 25 Mar 2020 04:36:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 996076B006E; Wed, 25 Mar 2020 04:36:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8852B6B0070; Wed, 25 Mar 2020 04:36:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id 6F6FE6B006C for ; Wed, 25 Mar 2020 04:36:52 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D88F68249980 for ; Wed, 25 Mar 2020 08:36:51 +0000 (UTC) X-FDA: 76633229022.12.clock60_3bd8b928a973e X-HE-Tag: clock60_3bd8b928a973e X-Filterd-Recvd-Size: 5010 Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Wed, 25 Mar 2020 08:36:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585125410; h=from:from:reply-to:subject:subject: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=sdYIddxfgLwXOGvGXxs8sWbwIPBrEhwforhRRHvBbFw=; b=S5JjwHA3gBfAyHFrjGb/vVyJfsP3kchTC7CGoU0W4y1lj0AqRKGv0KLOpGSZ1lLcF5B91c Q1PzQwtUa373xl00AzfBrr+AGlZm9VcYqIi25vTaKB0/pZxb2d+XzvS38GVVBWFo7eW+Pt oB09AZmd56oKdnLuET6QbPqt1L8WEjU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-332-XhB42Jt9P6iZjwf7I6OJXQ-1; Wed, 25 Mar 2020 04:36:49 -0400 X-MC-Unique: XhB42Jt9P6iZjwf7I6OJXQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10349190B2A1; Wed, 25 Mar 2020 08:36:47 +0000 (UTC) Received: from localhost (ovpn-12-88.pek2.redhat.com [10.72.12.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6544A7F1; Wed, 25 Mar 2020 08:36:40 +0000 (UTC) Date: Wed, 25 Mar 2020 16:36:37 +0800 From: Baoquan He To: "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, Sachin Sant , dan.j.williams@intel.com, mhocko@kernel.org, david@redhat.com Subject: Re: [PATCH] mm/sparse: Fix kernel crash with pfn_section_valid check Message-ID: <20200325083637.GJ3039@MiWiFi-R3L-srv> References: <20200325031914.107660-1-aneesh.kumar@linux.ibm.com> <20200325070643.GH3039@MiWiFi-R3L-srv> <20200325073707.GI3039@MiWiFi-R3L-srv> <5cdf5334-7fbb-8427-1918-ed67d5f23834@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5cdf5334-7fbb-8427-1918-ed67d5f23834@linux.ibm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 03/25/20 at 01:42pm, Aneesh Kumar K.V wrote: > On 3/25/20 1:07 PM, Baoquan He wrote: > > On 03/25/20 at 03:06pm, Baoquan He wrote: > > > On 03/25/20 at 08:49am, Aneesh Kumar K.V wrote: > > > > > > mm/sparse.c | 2 ++ > > > > 1 file changed, 2 insertions(+) > > > > > > > > diff --git a/mm/sparse.c b/mm/sparse.c > > > > index aadb7298dcef..3012d1f3771a 100644 > > > > --- a/mm/sparse.c > > > > +++ b/mm/sparse.c > > > > @@ -781,6 +781,8 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, > > > > ms->usage = NULL; > > > > } > > > > memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr); > > > > + /* Mark the section invalid */ > > > > + ms->section_mem_map &= ~SECTION_HAS_MEM_MAP; > > > > > > Not sure if we should add checking in valid_section() or pfn_valid(), > > > e.g check ms->usage validation too. Otherwise, this fix looks good to > > > me. > > > > With SPASEMEM_VMEMAP enabled, we should do validation check on ms->usage > > before checking any subsection is valid. Since now we do have case > > in which ms->usage is released, people still try to check it. > > > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > > index f0a2c184eb9a..d79bd938852e 100644 > > --- a/include/linux/mmzone.h > > +++ b/include/linux/mmzone.h > > @@ -1306,6 +1306,8 @@ static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn) > > { > > int idx = subsection_map_index(pfn); > > + if (!ms->usage) > > + return 0; > > return test_bit(idx, ms->usage->subsection_map); > > } > > #else > > > > We always check for section valid, before we check if pfn_section_valid(). > > static inline int pfn_valid(unsigned long pfn) > > struct mem_section *ms; > > if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) > return 0; > ms = __nr_to_section(pfn_to_section_nr(pfn)); > if (!valid_section(ms)) > return 0; > /* > * Traditionally early sections always returned pfn_valid() for > * the entire section-sized span. > */ > return early_section(ms) || pfn_section_valid(ms, pfn); > } > > > IMHO adding that if (!ms->usage) is redundant. Yeah, I tend to agree. Consider this happens in the only small window between ms->usage releasing and ms->section_mem_map releasing when removing a section. Just thought adding this check to enhance it even though we have had your fix, because we only check ms->section_mem_map in valid_section(). Anyway, your fix looks good to me, see if other people have any comment. Thanks Baoquan