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=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS autolearn=ham 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 E2B64C4321D for ; Fri, 24 Aug 2018 11:57:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71ABB2159F for ; Fri, 24 Aug 2018 11:57:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bmudtbit" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71ABB2159F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727626AbeHXPcR (ORCPT ); Fri, 24 Aug 2018 11:32:17 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34763 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbeHXPcQ (ORCPT ); Fri, 24 Aug 2018 11:32:16 -0400 Received: by mail-wm0-f68.google.com with SMTP id m199-v6so4121474wma.1; Fri, 24 Aug 2018 04:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=reply-to:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=7Tgnc12QIQxSq82jQ3lR1SJaq7jw2S1sY/VMy2KAqAc=; b=bmudtbitOhFna6vfzwUoCneFSpsDT6Qu/DrpkDTsh0ZZFUo+fthBYSs3E/mArrVUPb gbiD3xjgqI4ykFjqd5qe5ErviliVHQ9Fbmcur87Kvnp1g1cZkz1MeT+sc1+7UEhTMMzH NFp6xyez+ZttgMbIsaNhEj8cUPRPR5jXyVxjjSArUbFraCsTfMiU3g8iiOSMJou5A9N0 DwMb+NNzSCa8H86GhHOF7H7OaOlBeboHX3TccEw+bpcmXWuoLB6r38Xc6GCg/JqchtQt HaqGJtmDz5sRnaY9U1V49hGpNPRQ+VFMgqXrCXi9EhFBrkuCt+jnq260WwEE+ib3MhQL lKOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:cc:references:from :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=7Tgnc12QIQxSq82jQ3lR1SJaq7jw2S1sY/VMy2KAqAc=; b=PDXCDdJ8FEjYFw0/chf1J0dJLsDCTtB1cRFdT8Qvi+XZXpEEW6nyHxem4oHWnOC0Id 0UM8mL3s5epxCjPOZpXsjsCt0WEoghGxIP7DP0rUgPzvWrkXr4ou2XAjUJms/8hSTD94 CywXk7GX9XH7W/wdkaICWl6GB0JnZtHAfDBHpthZl+ATxaD+Yz6q0z6D9/UijkpFH+TN QFQmFhdTJaH9JeGH7wIGkpC9Olae6SpiMP/phBRWfflPcMkjMPHq7y1s5wl/zV63LHVK sn5wfasxE1tSjMqRAQRRttqbk+yzr6cKxat20yi1KppC+jGBkMF1YO8V3LdmBpc6TGJq Lg+A== X-Gm-Message-State: APzg51CFpswKFHc/wOK6hNshLJtNrC8U8bdkXesavo7d7NcFp8w0GYKE 1z7WNaX4pvzuScxwmMs7tao= X-Google-Smtp-Source: ANB0Vdaf6XF8GBSBXWoWwjxuhY0L/JCOuGKb5u104MH4WBEHWKLmWfARgqovCUwtS4XVDxs5bH8drw== X-Received: by 2002:a1c:888e:: with SMTP id k136-v6mr1258867wmd.6.1535111874638; Fri, 24 Aug 2018 04:57:54 -0700 (PDT) Received: from ?IPv6:2a02:908:1257:4460:1ab8:55c1:a639:6740? ([2a02:908:1257:4460:1ab8:55c1:a639:6740]) by smtp.gmail.com with ESMTPSA id c15-v6sm888113wmb.2.2018.08.24.04.57.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Aug 2018 04:57:54 -0700 (PDT) Reply-To: christian.koenig@amd.com Subject: Re: [PATCH] mm, oom: distinguish blockable mode for mmu notifiers To: Michal Hocko , christian.koenig@amd.com Cc: kvm@vger.kernel.org, =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Tetsuo Handa , Joonas Lahtinen , Sudeep Dutt , dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Andrea Arcangeli , "David (ChunMing) Zhou" , Dimitri Sivanich , Jason Gunthorpe , linux-rdma@vger.kernel.org, amd-gfx@lists.freedesktop.org, David Airlie , Doug Ledford , David Rientjes , xen-devel@lists.xenproject.org, intel-gfx@lists.freedesktop.org, Jani Nikula , Leon Romanovsky , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Rodrigo Vivi , Boris Ostrovsky , Juergen Gross , Mike Marciniszyn , Dennis Dalessandro , LKML , Ashutosh Dixit , Alex Deucher , Paolo Bonzini , Andrew Morton , Felix Kuehling References: <20180716115058.5559-1-mhocko@kernel.org> <8cbfb09f-0c5a-8d43-1f5e-f3ff7612e289@I-love.SAKURA.ne.jp> <20180824113248.GH29735@dhcp22.suse.cz> <20180824115226.GK29735@dhcp22.suse.cz> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: Date: Fri, 24 Aug 2018 13:57:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180824115226.GK29735@dhcp22.suse.cz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 24.08.2018 um 13:52 schrieb Michal Hocko: > On Fri 24-08-18 13:43:16, Christian König wrote: >> Am 24.08.2018 um 13:32 schrieb Michal Hocko: >>> On Fri 24-08-18 19:54:19, Tetsuo Handa wrote: >>>> Two more worries for this patch. >>>> >>>> >>>> >>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c >>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c >>>>> @@ -178,12 +178,18 @@ void amdgpu_mn_unlock(struct amdgpu_mn *mn) >>>>> * >>>>> * @amn: our notifier >>>>> */ >>>>> -static void amdgpu_mn_read_lock(struct amdgpu_mn *amn) >>>>> +static int amdgpu_mn_read_lock(struct amdgpu_mn *amn, bool blockable) >>>>> { >>>>> - mutex_lock(&amn->read_lock); >>>>> + if (blockable) >>>>> + mutex_lock(&amn->read_lock); >>>>> + else if (!mutex_trylock(&amn->read_lock)) >>>>> + return -EAGAIN; >>>>> + >>>>> if (atomic_inc_return(&amn->recursion) == 1) >>>>> down_read_non_owner(&amn->lock); >>>> Why don't we need to use trylock here if blockable == false ? >>>> Want comment why it is safe to use blocking lock here. >>> Hmm, I am pretty sure I have checked the code but it was quite confusing >>> so I might have missed something. Double checking now, it seems that >>> this read_lock is not used anywhere else and it is not _the_ lock we are >>> interested about. It is the amn->lock (amdgpu_mn_lock) which matters as >>> it is taken in exclusive mode for expensive operations. >> The write side of the lock is only taken in the command submission IOCTL. >> >> So you actually don't need to change anything here (even the proposed >> changes are overkill) since we can't tear down the struct_mm while an IOCTL >> is still using. > I am not so sure. We are not in the mm destruction phase yet. This is > mostly about the oom context which might fire right during the IOCTL. If > any of the path which is holding the write lock blocks for unbound > amount of time or even worse allocates a memory then we are screwed. So > we need to back of when blockable = false. Oh, yeah good point. Haven't thought about that possibility. > >>> Is that correct Christian? If this is correct then we need to update the >>> locking here. I am struggling to grasp the ref counting part. Why cannot >>> all readers simply take the lock rather than rely on somebody else to >>> take it? 1ed3d2567c800 didn't really help me to understand the locking >>> scheme here so any help would be appreciated. >> That won't work like this there might be multiple >> invalidate_range_start()/invalidate_range_end() pairs open at the same time. >> E.g. the lock might be taken recursively and that is illegal for a >> rw_semaphore. > I am not sure I follow. Are you saying that one invalidate_range might > trigger another one from the same path? No, but what can happen is: invalidate_range_start(A,B); invalidate_range_start(C,D); ... invalidate_range_end(C,D); invalidate_range_end(A,B); Grabbing the read lock twice would be illegal in this case. Regards, Christian.