Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2079645rdb; Mon, 20 Nov 2023 00:57:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHK9KgOXnLBIO4jdO7wMl46bSOv9gV/njBgeQ2X5AHfUk5URXR/k4pHf7T/YiYYRzj9UqX X-Received: by 2002:a05:6a00:3923:b0:68e:3eab:9e18 with SMTP id fh35-20020a056a00392300b0068e3eab9e18mr5189561pfb.12.1700470663098; Mon, 20 Nov 2023 00:57:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700470663; cv=none; d=google.com; s=arc-20160816; b=p7wJlsHBRjG/u1yFZDHoqNndSSkA5yZNKMLTNhwuJzaypVczdOM5egDOQ0BlnJc1JY Evv3Lv+gPUNLFjhnJwziCuyULz5FpeDshva+aF7IZvpLPCEvVU/5PctdzmODpJLhBRFW 3snxK2ZaQQc5ELcjCsWsw82OtoEklhbj9/atzV4UE67QioI1YV5YFaazEnCpjkaWrJiB kKJoEz/cH8JeMFOSp1/cwxITdSLocrZYk2xH+BFRhlT/5gb8b9BuPiS0a0x/BUe+QlmS RO1xk3bXLHIb7OXkAkOPIuChpRhq4OqopKkMAhbRp8+Ox8tZ99IXzK0SnDldhbAa1I72 vNAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:autocrypt:from:references:cc:to:content-language :subject:user-agent:mime-version:date:message-id:dkim-signature; bh=WZmfD0upzaveFHgX3d8jsjFtFQEgU/zO1aK5XX0bmuI=; fh=X+Fedw4hCbMH4Ev0QS2iCi+1HRHPhDeMRzp+H1VGUG0=; b=zBDZAl4saoSeJE6P36jBtsEE81K8vk8dEc+YRu215reJMfbIceuMtHV5cN8yv/WwbB 4GFcAD/mqSvt595wN8wkp7RTWi84uPO0UNFds64yEvKb93BHFkyd1bBL5bJMGEOy/++1 2gKki8LnUIf/nJ51E9qGDjIKooGeyBoLQ6TpBgceUqPQ8soR10oC9HDYh/zeW9g4Mg6f zgJa4ltoef9bX4pwJoBKy2ZyARYPdOQ0/hbt2lFGJlB4kjDHShnPOCn80+YA8JB0g6xc x+FZbrjmLL+5fdN/zai2AkYki8GBFVdKVp6ws8bhsU7rjZ2GvLMRIyyB6golEhi0LJ+f 7bLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aAS9chbr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id m10-20020a056a00080a00b0069026254582si951059pfk.98.2023.11.20.00.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 00:57:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aAS9chbr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 4ECB580A056F; Mon, 20 Nov 2023 00:56:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232194AbjKTI4e (ORCPT + 99 others); Mon, 20 Nov 2023 03:56:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232139AbjKTI4c (ORCPT ); Mon, 20 Nov 2023 03:56:32 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD1D8129 for ; Mon, 20 Nov 2023 00:56:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700470583; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=WZmfD0upzaveFHgX3d8jsjFtFQEgU/zO1aK5XX0bmuI=; b=aAS9chbrz1nY7WLdiI4NRvgSxo+KXK4AZW/YLxJCNvpQ0kS5/ju2xx+QkdyJW1fojhFAgv 0JS4lpCoX/As4zl8ncfZrvKqC85QZHGxO/yZ5M3K8KvgOG+Am/p23ScPMco+BOZgeZYm2j MqNjRez5ZMc57tTl1achJ2Cr54bZq3U= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-379-g1O4imnaMAyQV-fL35-bOA-1; Mon, 20 Nov 2023 03:56:22 -0500 X-MC-Unique: g1O4imnaMAyQV-fL35-bOA-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-50aa861dcf7so1460467e87.1 for ; Mon, 20 Nov 2023 00:56:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700470580; x=1701075380; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WZmfD0upzaveFHgX3d8jsjFtFQEgU/zO1aK5XX0bmuI=; b=KP8jHn+RHjOndI4MquM3QGfPZ5QdGdNSxM6U1q620z0kpo34TiUVjJYOnpG+fZg0fL v75nA8G4lnhVZzQPyM1m8JuCYXRS8OT9SZwt/Ugh1+9G04nv/qIrGlZGHKxePecgFixk 9D5RjklcOF7VfyZsZIzhez+Kr/uv//5nPkgwm49+ywtWyl20meQA/HY7JJrPalCRA8IE RWmQX3xW04DGiVBeVBoO6KTGoG35ICFzmHpGdYQU6RRtLsHu3z3u3pVQP7YUDH38UZ4Z zMCvyMV5Cho8BZA8VWJ7iDFQmhlTSICV2Kj6XEF8c0dfnq5Btm+sbxmG2QLWHg1ciICn VBjQ== X-Gm-Message-State: AOJu0YxhxL3+Bpnu65brkJqKzfIiaYYCCYxqRruZZQkQuKeW0/rlnt+0 falm8dzmWVGcxY3yKTAjQQNQOJSxJDeAKU8So8q6Q7q3UDkJ7T9Fl1do6Ls+i6zuh2W7GJsBFvW cPF4kViTF0l5I9NhsAxCnTo06 X-Received: by 2002:ac2:53b0:0:b0:500:7c51:4684 with SMTP id j16-20020ac253b0000000b005007c514684mr4681214lfh.56.1700470580653; Mon, 20 Nov 2023 00:56:20 -0800 (PST) X-Received: by 2002:ac2:53b0:0:b0:500:7c51:4684 with SMTP id j16-20020ac253b0000000b005007c514684mr4681197lfh.56.1700470580196; Mon, 20 Nov 2023 00:56:20 -0800 (PST) Received: from ?IPV6:2003:cb:c746:7700:9885:6589:b1e3:f74c? (p200300cbc746770098856589b1e3f74c.dip0.t-ipconnect.de. [2003:cb:c746:7700:9885:6589:b1e3:f74c]) by smtp.gmail.com with ESMTPSA id b11-20020a05600010cb00b00332c0d256c5sm5558804wrx.80.2023.11.20.00.56.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Nov 2023 00:56:19 -0800 (PST) Message-ID: <20e6c1dd-a195-4b49-8723-7c94f7562b4c@redhat.com> Date: Mon, 20 Nov 2023 09:56:18 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] mm/memory_hotplug: add missing mem_hotplug_lock Content-Language: en-US To: Sumanth Korikkar , linux-mm , Andrew Morton Cc: Oscar Salvador , Michal Hocko , "Aneesh Kumar K.V" , Anshuman Khandual , Gerald Schaefer , Alexander Gordeev , Heiko Carstens , Vasily Gorbik , linux-s390 , LKML References: <20231120072317.3169630-1-sumanthk@linux.ibm.com> <20231120072317.3169630-2-sumanthk@linux.ibm.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwZgEEwEIAEICGwMGCwkIB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9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20231120072317.3169630-2-sumanthk@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 20 Nov 2023 00:56:48 -0800 (PST) On 20.11.23 08:23, Sumanth Korikkar wrote: > From Documentation/core-api/memory-hotplug.rst: > When adding/removing/onlining/offlining memory or adding/removing > heterogeneous/device memory, we should always hold the mem_hotplug_lock > in write mode to serialise memory hotplug (e.g. access to global/zone > variables). > > mhp_(de)init_memmap_on_memory() functions can change zone stats and > struct page content, but they are currently called w/o the > mem_hotplug_lock. > > When memory block is being offlined and when kmemleak goes through each > populated zone, the following theoretical race conditions could occur: > CPU 0: | CPU 1: > memory_offline() | > -> offline_pages() | > -> mem_hotplug_begin() | > ... | > -> mem_hotplug_done() | > | kmemleak_scan() > | -> get_online_mems() > | ... > -> mhp_deinit_memmap_on_memory() | > [not protected by mem_hotplug_begin/done()]| > Marks memory section as offline, | Retrieves zone_start_pfn > poisons vmemmap struct pages and updates | and struct page members. > the zone related data | > | ... > | -> put_online_mems() > > Fix this by ensuring mem_hotplug_lock is taken before performing > mhp_init_memmap_on_memory(). Also ensure that > mhp_deinit_memmap_on_memory() holds the lock. > > online/offline_pages() are currently only called from > memory_block_online/offline(), so it is safe to move the locking there. > > Fixes: a08a2ae34613 ("mm,memory_hotplug: allocate memmap from the added memory range") > Reviewed-by: Gerald Schaefer > Signed-off-by: Sumanth Korikkar > --- Acked-by: David Hildenbrand -- Cheers, David / dhildenb