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=-7.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 C311BC433B4 for ; Fri, 16 Apr 2021 08:18:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 48DA9610CB for ; Fri, 16 Apr 2021 08:18:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 48DA9610CB 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 7BFC06B0036; Fri, 16 Apr 2021 04:18:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76FCB6B006C; Fri, 16 Apr 2021 04:18:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5734B6B0070; Fri, 16 Apr 2021 04:18:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id 343E76B0036 for ; Fri, 16 Apr 2021 04:18:09 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E0E6C8248D7C for ; Fri, 16 Apr 2021 08:18:08 +0000 (UTC) X-FDA: 78037527456.25.3039B1F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 9C63440002C6 for ; Fri, 16 Apr 2021 08:17:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618561088; 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=f0QRBbcT35Iu6clJTmp1UTgyC8yDllQoeXk4UU4Rwtk=; b=FemDYcvbcfME/IHHd3DoxIvg5rt1OTTE1otC/dfZFoOWQtHDco8pOSjJu9g6EThoLEABoA djW6lk/kDpAn4VYJS+mffFxn4mOTlDnsbImxeETVunmsdVa74tGnJa2bQXNBBe+WltOPv6 bd74wifttITSMzlJxCfsE2P2IBwTn1k= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-439-npljG0A5McaeOOYVN-96Lg-1; Fri, 16 Apr 2021 04:18:06 -0400 X-MC-Unique: npljG0A5McaeOOYVN-96Lg-1 Received: by mail-ed1-f70.google.com with SMTP id f9-20020a50fe090000b02903839889635cso4619610edt.14 for ; Fri, 16 Apr 2021 01:18:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=f0QRBbcT35Iu6clJTmp1UTgyC8yDllQoeXk4UU4Rwtk=; b=FCvlKX+i9+H7l1TyIumQg2LPyCeVYewl+T+mCrdRNy0jYXCLyuLeztyztXim+YugbZ 7DIafctRZOGABQ6ayjHNF49NXi6YRciDD2/9Lqr7YnrAT7WNwxpSBiqqtO3Dx0dNtn3L Ww1L4EdRdqIRd7tCSMpi25L4/mN2jHTciUs/bC8UNVAO2uWHtp0i4wf2ewOzLAfSP1no 7uz/hmnIkkxIogi1eCx5pkTMNG3pc+L2odj4xuu1UkxkTdq61JruOoEcJJdCN7O+yNws wU9n5weuy0YcZ2hUSKc3h2514E7IPien3dOT2hdUB1FFeX/r0wkD2V+k3ShU4zEih+na 0JXQ== X-Gm-Message-State: AOAM5322y/lzP2XpO+LWJkarHiOotsaHoCo+zqPZn7N19XvWj1b8XBEt 7xM9uLtRGpsaNmp34SswtfAlvFYjseI6Tqo/bR1TlZrzemlNbp4J5MOO+T5nO8PM5nu7LgNVJdX sKTQX4XPYN7Q= X-Received: by 2002:a17:906:e97:: with SMTP id p23mr5988041ejf.5.1618561085157; Fri, 16 Apr 2021 01:18:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEQDToFFHUEEo2opm0jLJTUBGGtvwpNBdE1Z7VGt/QRix5QRi/0Ktdw6vxZXSpOFAw3WghAg== X-Received: by 2002:a17:906:e97:: with SMTP id p23mr5988008ejf.5.1618561084875; Fri, 16 Apr 2021 01:18:04 -0700 (PDT) Received: from [192.168.3.132] (p5b0c64fb.dip0.t-ipconnect.de. [91.12.100.251]) by smtp.gmail.com with ESMTPSA id ho19sm3592014ejc.57.2021.04.16.01.18.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Apr 2021 01:18:03 -0700 (PDT) Subject: Re: [PATCH v4] kernel/resource: Fix locking in request_free_mem_region To: Dan Williams , Alistair Popple Cc: Andrew Morton , Linux MM , Linux Kernel Mailing List , Daniel Vetter , Greg KH , John Hubbard , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Balbir Singh , Muchun Song , kernel test robot References: <20210416025745.8698-1-apopple@nvidia.com> From: David Hildenbrand Organization: Red Hat Message-ID: <147cc510-9c00-1ffe-bd02-60042fccf2c7@redhat.com> Date: Fri, 16 Apr 2021 10:18:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 9C63440002C6 X-Stat-Signature: 93desmiy3uegg6ygutysjgeiozbeqpd9 X-Rspamd-Server: rspam02 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618561070-889906 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 16.04.21 06:19, Dan Williams wrote: > On Thu, Apr 15, 2021 at 7:58 PM 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. >> >> 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: >> >> /* >> * mm/hmm.c reserves physical addresses which then >> * become unavailable to other users. Conflicts are >> * not expected. Warn to aid debugging if encountered. >> */ >> if (conflict->desc == IORES_DESC_DEVICE_PRIVATE_MEMORY) { >> pr_warn("Unaddressable device %s %pR conflicts with %pR", >> conflict->name, conflict, res); >> >> To fix this create versions of region_intersects() and >> request_mem_region() that allow the caller to take the appropriate lock >> such that it may be held over the required calls. >> >> Instead of creating another version of devm_request_mem_region() that >> doesn't take the lock open-code it to allow the caller to pre-allocate >> the required memory prior to taking the lock. >> >> On some architectures and kernel configurations revoke_iomem() also >> calls resource code so cannot be called with the resource lock held. >> Therefore call it only after dropping the lock. > > The patch is difficult to read because too many things are being > changed at once, and the changelog seems to confirm that. Can you try > breaking this down into a set of incremental changes? Not only will > this ease review it will distribute any regressions over multiple > bisection targets. > > Something like: > > * Refactor region_intersects() to allow external locking > * Refactor __request_region() to allow external locking > * Push revoke_iomem() down into... > * Fix resource_lock usage in [devm_]request_free_mem_region() +1 -- Thanks, David / dhildenb