Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4219152pxf; Tue, 30 Mar 2021 02:15:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgOviAfDV+QpvmbnE3ZT8gcng657WY5zSIwUso4HcvWcFhVzKOFE+ODEjl9l10t1Qz3SSG X-Received: by 2002:a05:6402:3592:: with SMTP id y18mr27255494edc.360.1617095730123; Tue, 30 Mar 2021 02:15:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617095730; cv=none; d=google.com; s=arc-20160816; b=dd97l3vL4TsCxBsX9oDd0+DnuORkbNKt+1ycvB2Pilu+faWOwz2T9dmIGxNptF9L6H kDOwTnncTz7AQufh88JKrURYRTTpPAI7q/OOUt7NL26LbK8E6fXi5FlS2aAKb8A/JAWA 2hduXj9+GCAtj9UASUBLj4PLDX61n1ILWPfK/0mexclORUwyktSYPICdnkSL5XEfDA4R vt+Ph3setW9L3QOB0nhgdvK5ur3Zu7rAIVpoUkZ+ESQGHjyaQZAh0xr41WpxWGNCah1i q8YVnx5jobFVp4Vacw1dW10r98LBPQWk3RTJFTE14CWawQH+dZtRddEa/bniezlpr5Qx OFKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject :organization:from:references:cc:to:dkim-signature; bh=Wb1xwTXO+Z1eRBnmRJEtGYdnn0qi6F4dPoEkpoQRveo=; b=nGQNkn4RXoMpqGxqhUvAZ01z1qqhVnzyTTMiz85IPDSxXc9I+9/TXP3UkOQbmE/p9O /y87ibwKX3frhKLA9F6U3ZTKfy4Nsi2DkeBfaPlBssSnxyI52mXLuSynLQ0nXXvEjzX4 MWKUKQqftsr30A3CcHiPax3FDGN6u6ySNYh7tkxJ22FU3CUYdghoCeiCl1poeBrEVJPG 1r81pytygkwAguJZRMdpaWqlvSBTA7ICa0Ha1iSsrfxopyYIr16p14zyJJNoKAMgHMxk Glg0e9AmGCWdqa7T8B2VQGYBq7kE8EeoahwrW/TiBKsrhM9tJIim86qpOcz9JOKzQJJh iCqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VFqJRJIt; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j22si14471939ejb.269.2021.03.30.02.15.06; Tue, 30 Mar 2021 02:15:30 -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=@redhat.com header.s=mimecast20190719 header.b=VFqJRJIt; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230224AbhC3JOL (ORCPT + 99 others); Tue, 30 Mar 2021 05:14:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40212 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229816AbhC3JNn (ORCPT ); Tue, 30 Mar 2021 05:13:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617095622; 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; bh=Wb1xwTXO+Z1eRBnmRJEtGYdnn0qi6F4dPoEkpoQRveo=; b=VFqJRJItgHdLxQEoYaagKJ4+dtSKq8JE9OH+A6WEIZofNh7xwmpeM5pCK9FSPwJbAqX3KY iwPLm7IMNDpdHoyZWcJcp2j8/uN7VtHjl9Jn3npo9jStbx7zG5AWcOH4HRnqIWK5U5jOJk je/Nva0BWAFV7M2+8dsCX75ix55/qXo= 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-535-JcCj9s0CM46WVe9KeVsZuQ-1; Tue, 30 Mar 2021 05:13:38 -0400 X-MC-Unique: JcCj9s0CM46WVe9KeVsZuQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42BFF1009458; Tue, 30 Mar 2021 09:13:36 +0000 (UTC) Received: from [10.36.114.210] (ovpn-114-210.ams2.redhat.com [10.36.114.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 953E66F978; Tue, 30 Mar 2021 09:13:33 +0000 (UTC) To: Alistair Popple Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, daniel.vetter@ffwll.ch, dan.j.williams@intel.com, gregkh@linuxfoundation.org, jhubbard@nvidia.com, jglisse@redhat.com, linux-mm@kvack.org References: <20210326012035.3853-1-apopple@nvidia.com> <9eef1283-28a3-845e-0e3e-80b763c9ec59@redhat.com> <3158185.bARUjMUeyn@nvdebian> From: David Hildenbrand Organization: Red Hat GmbH Subject: Re: [PATCH v2] kernel/resource: Fix locking in request_free_mem_region Message-ID: Date: Tue, 30 Mar 2021 11:13:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <3158185.bARUjMUeyn@nvdebian> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29.03.21 03:37, Alistair Popple wrote: > On Friday, 26 March 2021 7:57:51 PM AEDT David Hildenbrand wrote: >> On 26.03.21 02:20, Alistair Popple wrote: >>> request_free_mem_region() is used to find an empty range of physical >>> addresses for hotplugging ZONE_DEVICE memory. It does this by iterating >>> over the range of possible addresses using region_intersects() to see if >>> the range is free. >> >> Just a high-level question: how does this iteract with memory >> hot(un)plug? IOW, how defines and manages the "range of possible >> addresses" ? > > Both the driver and the maximum physical address bits available define the > range of possible addresses for device private memory. From > __request_free_mem_region(): > > end = min_t(unsigned long, base->end, (1UL << MAX_PHYSMEM_BITS) - 1); > addr = end - size + 1UL; > > There is no lower address range bound here so it is effectively zero. The code > will try to allocate the highest possible physical address first and continue > searching down for a free block. Does that answer your question? Oh, sorry, the fist time I had a look I got it wrong - I thought (1UL << MAX_PHYSMEM_BITS) would be the lower address limit. That looks indeed problematic to me. You might end up reserving an iomem region that could be used e.g., by memory hotplug code later. If someone plugs a DIMM or adds memory via different approaches (virtio-mem), memory hotplug (via add_memory()) would fail. You never should be touching physical memory area reserved for memory hotplug, i.e., via SRAT. What is the expectation here? -- Thanks, David / dhildenb