Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1146995pxf; Fri, 26 Mar 2021 01:59:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVHnFG0lo1Xa/rSHpCkGlBBS82xs0X1MZYf7mc+VGLBE9sbW7FBo4nvwNuJzdxHHyhqN87 X-Received: by 2002:a17:906:314f:: with SMTP id e15mr14033060eje.30.1616749181410; Fri, 26 Mar 2021 01:59:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616749181; cv=none; d=google.com; s=arc-20160816; b=Ge+MM+bgUIYqdRVtaHAVknjaAlVNGOe5m7vriA+7RYfdiqXQQaLXKB+SlW/jWz+It9 b1DvZP5B09peNMZ2kjtG0y2LoAnoW0Fk+hjWegKTFPDsMuJ0aC915h7KhHzEuTBeWlBA hsmeEG4O5ufaUaZg2FxAKeRmhWrI5lfkZ05Gg7jmgZ1A74nAFwtNz1UIpYDfp62wgg+C piQCJjg4IPqmTP1+a1QpETaYrXrVCQ7LQO/NOi/xEU/o1L01tUAvf7+8SOsD8mU0tKXw PwNbTfVostsYFOWaxsFSQI2pD2LcLKqH9MibU3ccyE7VUsyyRJEkJHO2ft5oXiFxlqaj 6uLg== 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:organization :from:references:cc:to:subject:dkim-signature; bh=xL+hmA+1dMAwVs4hHRMU+2pFBDMDHNw6rI7EfiN366c=; b=DIVHfC4Gg4rrxjMiCmkMYn53twf5fqoBHociJ0PTUVbsUMAs3mk5zpdEF0nl//I6kk i+fbLx9foCqhLuWXQzuIGet0fA5IE79J5IHdgoyaPqGNZuBO+G4BN4aSTdI/6OT/J1UK HbQDSDKeOPJ5Xzm8FrmzvKbaKAUDTKOp/9yEA5gYG0WmpcUo09jircD8lh+70b8b5+1T itLMD9hXcaf21lVmjzHc55au3fo6zgC4CTO8ZVXE/u80PBRTYhRV0+rafY/u23BSyLG1 RI4U/lBOhw91Q40tjEqSB/LEtyA+H4RB+9ihZ3HCe7NxfS133Vama2sVNgH8mLd2b5db qBtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WfaO1OSI; 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 h15si6181757edw.371.2021.03.26.01.59.18; Fri, 26 Mar 2021 01:59:41 -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=WfaO1OSI; 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 S229890AbhCZI6N (ORCPT + 99 others); Fri, 26 Mar 2021 04:58:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38515 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbhCZI6A (ORCPT ); Fri, 26 Mar 2021 04:58:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616749080; 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=xL+hmA+1dMAwVs4hHRMU+2pFBDMDHNw6rI7EfiN366c=; b=WfaO1OSIpY1txJRHWv08huEoFn1N/vgFJhNIegKrUUYjSnxgYCGirzJjDI0NCDEr2zBj0O ZGPKlSe4CYrRNMKnJRvuiWr6WkL3yLmpGuDijUVBBXevd/dxIJOvAK/UN8hRlx7m3we5vc 7R2TLW7UHlBbneyqeBqBxjm2yb9zu1Q= 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-339-QI9WO7IHPYmX_fsr6UJNjw-1; Fri, 26 Mar 2021 04:57:56 -0400 X-MC-Unique: QI9WO7IHPYmX_fsr6UJNjw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6696018C89CC; Fri, 26 Mar 2021 08:57:54 +0000 (UTC) Received: from [10.36.114.167] (ovpn-114-167.ams2.redhat.com [10.36.114.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 255B388F0E; Fri, 26 Mar 2021 08:57:51 +0000 (UTC) Subject: Re: [PATCH v2] kernel/resource: Fix locking in request_free_mem_region To: Alistair Popple , linux-kernel@vger.kernel.org Cc: 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> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <9eef1283-28a3-845e-0e3e-80b763c9ec59@redhat.com> Date: Fri, 26 Mar 2021 09:57:51 +0100 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: <20210326012035.3853-1-apopple@nvidia.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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" ? > > region_intersects() obtains a read lock before walking the resource tree > to protect against concurrent changes. However it drops the lock prior > to returning. This means by the time request_mem_region() is called in > request_free_mem_region() another thread may have already reserved the > requested region resulting in unexpected failures and a message in the > kernel log from hitting this condition: I am confused. Why can't we return an error to the caller and let the caller continue searching? This feels much simpler than what you propose here. What am I missing? -- Thanks, David / dhildenb