From patchwork Mon Jun 25 08:01:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 10485213 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 125B3603B5 for ; Mon, 25 Jun 2018 08:01:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07B6B28911 for ; Mon, 25 Jun 2018 08:01:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFA272893A; Mon, 25 Jun 2018 08:01:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98FD728712 for ; Mon, 25 Jun 2018 08:01:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B7A86B0007; Mon, 25 Jun 2018 04:01:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 967636B000A; Mon, 25 Jun 2018 04:01:09 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 808836B000C; Mon, 25 Jun 2018 04:01:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id 392236B0007 for ; Mon, 25 Jun 2018 04:01:09 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id b65-v6so7851006plb.5 for ; Mon, 25 Jun 2018 01:01:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:message-id:references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=PnDNz7Z0PvWmM9oyO1IdYbl6gmaESWsuWzZ/vbL5FnM=; b=YnX/EwwWNverY/PIg8HLxQBOJZb1R574qhYUEDYCTnPybdZGLmrudRoDpjjO4kH6PR lI6HK0VYahBFv0aSnE1ybu7pMmldM8WxHEEcbjQCOQ8rHGpzbqAWZKo9ajrFDB+aNTVU 4JpaOfFLyf4Xx3Zl5i5WsTr45idT/SneqqGYVKCq8imjE7Op4sLt+Jas+zwJiKBxIHqk jRJk8sFUAv3vQapujz91P4LNYp23nkg7LWQ5VPh0LfZbVyM27gZZfCw1auMSJ9QZ7P49 DSOV8w+N4WU0OKR3RKVLe9OM3nsPjYDpsjbqqdOBlYQD1tIp943ZjHoD+4/umPObKGvZ rfHA== X-Original-Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning mhocko@kernel.org does not designate 195.135.220.15 as permitted sender) smtp.mailfrom=mhocko@kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Gm-Message-State: APt69E03JIFo+XfhwZiW5LcEfy8Kt2YKBQgO1f1HnFxfwbc1I72+qv25 sMAmipmcROJtVHCrXfZ2XsEMsAWQkpvM3XADbafgnnhNG6V5gyYHzVvfd9PF8vfeqftTsX8mhLC Ht8A5VE3gqHmBiv12aO5xgCF0ZO8A9SAkrlBur+lYBBa7UP5u4Yx6J19r9ezOaCE= X-Received: by 2002:a65:5cc5:: with SMTP id b5-v6mr1243436pgt.425.1529913668903; Mon, 25 Jun 2018 01:01:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIpQ6428djHDpF+7LZpxMhOHv3uBj8MDoXFncj/399BCYLRkSOADSdQJfkhlVwhCp2G76Mr X-Received: by 2002:a65:5cc5:: with SMTP id b5-v6mr1243381pgt.425.1529913667923; Mon, 25 Jun 2018 01:01:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529913667; cv=none; d=google.com; s=arc-20160816; b=FZQjJShOnsKX6PWDj+nMpKxt9wylIkIcX9FtZ9EzAuK6EABqApYiSxBc8VgGRKrZK0 uaLJWn1/ITQtgD9pp9OPHthtbA9k5E3lgraUXJQJmm1ODTaR+JfJsp2M2P3pkDmkNQyu 45snO7+Cb4qzuAl7tJ2qlBWwiMrg3c0boGSNM7edo6bA35xfEGQQQzCZty9NKHZ6JSqR mk8I34iBOmJ+yVN/aoGSam36UTy+pJn/6a33IHIYWbZk1l8GMehOA/gRslCF8nCMYDvx wgOxXuId13SOfL4SJgFVexM2UHB8koi20nlWmnHJ7GrHBYK3lkfK/kFsvqY7BzFKoJKA MxYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=PnDNz7Z0PvWmM9oyO1IdYbl6gmaESWsuWzZ/vbL5FnM=; b=T0GP5uFipJhIlcSv8f54NjZJ7oPbkmpURAaWofqKjDSagZFmP3kCq9jFmOY3efWXYC dLp7dCQ44Epm7J9XKDFzABKAmpAMrav/R8B0unKnLjpJbBp2fg+ak0f4G2q41wmu8mRa NjT68cfHGTI0kP8rJVu9hdafmJ5tVdO1NDYAj2xrHHgwQ9uC3ttwVPIYYYTVFuEMop8p 8N+wbORN9+erp4paDUZK3acjG7WqQpvMLLtI1DO+YQiR7SFshh+fYIYtzMH1cCF0brBO sfAV8H/uFMwHrYYhJsE1kf7xrnp5sPHM2AeRT0fHW5vwx/RV2XoFqo0PtdrP8MCcFb1o +Xbw== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning mhocko@kernel.org does not designate 195.135.220.15 as permitted sender) smtp.mailfrom=mhocko@kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mx2.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id p6-v6si14104759pfl.279.2018.06.25.01.01.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 25 Jun 2018 01:01:07 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning mhocko@kernel.org does not designate 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning mhocko@kernel.org does not designate 195.135.220.15 as permitted sender) smtp.mailfrom=mhocko@kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E9B81AF06; Mon, 25 Jun 2018 08:01:05 +0000 (UTC) Date: Mon, 25 Jun 2018 10:01:03 +0200 From: Michal Hocko To: Felix Kuehling Cc: Christian =?iso-8859-1?Q?K=F6nig?= , LKML , "David (ChunMing) Zhou" , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Alex Deucher , David Airlie , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Doug Ledford , Jason Gunthorpe , Mike Marciniszyn , Dennis Dalessandro , Sudeep Dutt , Ashutosh Dixit , Dimitri Sivanich , Boris Ostrovsky , Juergen Gross , =?iso-8859-1?B?Suly9G1l?= Glisse , Andrea Arcangeli , kvm@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-rdma@vger.kernel.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, David Rientjes Subject: Re: [RFC PATCH] mm, oom: distinguish blockable mode for mmu notifiers Message-ID: <20180625080103.GB28965@dhcp22.suse.cz> References: <20180622150242.16558-1-mhocko@kernel.org> <0aa9f695-5702-6704-9462-7779cbfdb3fd@amd.com> <20180622152444.GC10465@dhcp22.suse.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.5 (2018-04-13) 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: X-Virus-Scanned: ClamAV using ClamSMTP On Fri 22-06-18 16:09:06, Felix Kuehling wrote: > On 2018-06-22 11:24 AM, Michal Hocko wrote: > > On Fri 22-06-18 17:13:02, Christian König wrote: > >> Hi Michal, > >> > >> [Adding Felix as well] > >> > >> Well first of all you have a misconception why at least the AMD graphics > >> driver need to be able to sleep in an MMU notifier: We need to sleep because > >> we need to wait for hardware operations to finish and *NOT* because we need > >> to wait for locks. > >> > >> I'm not sure if your flag now means that you generally can't sleep in MMU > >> notifiers any more, but if that's the case at least AMD hardware will break > >> badly. In our case the approach of waiting for a short time for the process > >> to be reaped and then select another victim actually sounds like the right > >> thing to do. > > Well, I do not need to make the notifier code non blocking all the time. > > All I need is to ensure that it won't sleep if the flag says so and > > return -EAGAIN instead. > > > > So here is what I do for amdgpu: > > In the case of KFD we also need to take the DQM lock: > > amdgpu_mn_invalidate_range_start_hsa -> amdgpu_amdkfd_evict_userptr -> > kgd2kfd_quiesce_mm -> kfd_process_evict_queues -> evict_process_queues_cpsch > > So we'd need to pass the blockable parameter all the way through that > call chain. Thanks, I have missed that part. So I guess I will start with something similar to intel-gfx and back off when the current range needs some treatment. So this on top. Does it look correct? diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c index d138a526feff..e2d422b3eb0b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c @@ -266,6 +266,11 @@ static int amdgpu_mn_invalidate_range_start_hsa(struct mmu_notifier *mn, struct amdgpu_mn_node *node; struct amdgpu_bo *bo; + if (!blockable) { + amdgpu_mn_read_unlock(); + return -EAGAIN; + } + node = container_of(it, struct amdgpu_mn_node, it); it = interval_tree_iter_next(it, start, end);