Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp245570pxj; Thu, 3 Jun 2021 05:47:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+EUYXdU3ugGOyvehzNVVXO2kBZkB3WOurYOU22pwXzQR8FdN4ppq0TV0zXUs0VvjKvRh6 X-Received: by 2002:a05:6402:22f9:: with SMTP id dn25mr19044049edb.241.1622724456742; Thu, 03 Jun 2021 05:47:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622724456; cv=none; d=google.com; s=arc-20160816; b=EN79PYUtWg7gb5gLXQ6zPscNJzkHb/BPTEoI+NtJVdciHQWDRMOz0t8Qk2kSYPpuo2 UWGGNMsVPOM3Mt1isENem8B99TJ+V5xICT+XKLSMrkqCcj6AIbXgyA0+RCifVV9IBO3K sizIXNdbOndkFyc7tjQp5QtswwMTyDE4RaZ92T/3s7nL9ezm3oBxx682dV/kT2b9SiSz 4nOEC/P499TG/OHCZzgZNzAX5yPNroSsn0BFF1oMEIb2S21r5YYYhxJ2bZhpcP8GdsxQ F/+3Xn7fsduXjzazn+ftEDU3Qj+TvMoL3YAUED6q7o169KF47xTKTL0aG/EPiXxbK9mA r8Iw== 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=ZcX19m7FEU1QXRE/lXUIHIQnF4aGZcVkJ8dPzSfOcoA=; b=eBDyfqGUXmkX0kN1jn5B5nk2+klJhA0Er+lg9KjaL4DHwf0CNtrrEB3bkNeaJFuw0G bmR9priJKKoCRXrySSEfi7mNyxSR0SNaIUIAMT8+3LKECud+IpwQqitMbOn5+6Btwk0/ C2KUQA9iKuf3lZc1o2c4ydeLC2DwICNvWEBlR2RVI64PWoCK2Kegr0ttm5Re9vXY+Ra0 BYcYSg0UgOEPfmE5Fatem5gSxZFDJY+C24PM4cwfdPpZ5vQPcTMYjeGHnA14RQhYHLY9 WHDFPZ6h4JlTZWlXCjknLWt50PV+u+13f93F/yFjSmlSG3c/2U2Km0672qrTQfn0fqek wfUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=jF25zSqL; 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 w5si2085748edd.540.2021.06.03.05.47.14; Thu, 03 Jun 2021 05:47:36 -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=jF25zSqL; 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 S230517AbhFCMq7 (ORCPT + 99 others); Thu, 3 Jun 2021 08:46:59 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:50326 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbhFCMq7 (ORCPT ); Thu, 3 Jun 2021 08:46:59 -0400 Received: from relay2.suse.de (unknown [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id CA0971FD3D; Thu, 3 Jun 2021 12:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1622724313; 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=ZcX19m7FEU1QXRE/lXUIHIQnF4aGZcVkJ8dPzSfOcoA=; b=jF25zSqLiEz7CRyAvUR8n7UFywd4oK2hTERgX2HjI+bp+19TdlSBAivRmnD6DQzjWbsWO8 D7d7rfSKmsUc0o8Xbam6UegpsKDsMWAUg9uYp+FcNd8KuE4upEJfYnR1ypE/zcN1PoVnqs tvwmI3DiNWHYpvh2oMb113O7oxgL6bw= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 7F635A3B8F; Thu, 3 Jun 2021 12:45:13 +0000 (UTC) Date: Thu, 3 Jun 2021 14:45:13 +0200 From: Michal Hocko To: Oscar Salvador Cc: David Hildenbrand , Andrew Morton , Dave Hansen , Anshuman Khandual , Vlastimil Babka , Pavel Tatashin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] mm,page_alloc: Use {get,put}_online_mems() to get stable zone's values Message-ID: References: <20210602091457.17772-1-osalvador@suse.de> <20210602091457.17772-2-osalvador@suse.de> <39473305-6e91-262d-bcc2-76b745a5b14a@redhat.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 Thu 03-06-21 10:38:24, Oscar Salvador wrote: > On Wed, Jun 02, 2021 at 09:45:58PM +0200, Oscar Salvador wrote: > > It was too nice and easy to be true I guess. > > Yeah, I missed the point that blocking might be an issue here, and hotplug > > operations can take really long, so not an option. > > I must have switched my brain off back there, because now it is just too > > obvious. > > > > Then I guwmess that seqlock must stay and the only thing than can go is the > > pgdat resize lock from the hotplug code. > > So, I have been looking into this again. > Of course, the approach taken here is outrageously wrong, but there are > some other things that are a bit confusing. > > As pointed out, bad_range() (the function that ends up calling > page_outside_zone_boundaries) is called from different functions via VM_BUG_ON_*. > page_outside_zone_boundaries() takes care of taking the seqlock to avoid > reading stale values that might happen if we race with memhotplug > operations. > page_outside_zone_boundaries() calls zone_spans_pfn() to check that. > > Now on the funny thing. > > We do have several places happily calling zone_spans_pfn() without > holding zone's seqlock, e.g: > > set_pageblock_migratetype > set_pfnblock_flags_mask > zone_spans_pfn > > move_freepages_block > zone_spans_pfn > > alloc_contig_pages > zone_spans_last_pfn > zone_spans_pfn > > Those places hold zone->lock, while move_pfn_range_to_zone() and > remove_pfn_range_from_zone() hold zone->seqlock, so AFAICS, those places > could read a stale value and proceed thinking the range is within the > zone while it is not. > > So I guess my question is, should we force those places to take the > seqlock reader as we do in page_outside_zone_boundaries(), (or maybe > just move the seqlock handling to zone_spans_pfn())? I believe we need to define the purpose of the locking first. The existing locking doesn't serve much purpose, does it? The state might change right after the lock is released and the caller cannot really rely on the result. So aside of the current implementation, I would argue that any locking has to be be done on the caller layer. But the primary question is whether anybody actually cares about potential races in the first place. -- Michal Hocko SUSE Labs