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=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 12912C433FE for ; Wed, 8 Sep 2021 14:44:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E075361158 for ; Wed, 8 Sep 2021 14:43:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232842AbhIHOpG (ORCPT ); Wed, 8 Sep 2021 10:45:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229968AbhIHOpG (ORCPT ); Wed, 8 Sep 2021 10:45:06 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48923C061575 for ; Wed, 8 Sep 2021 07:43:58 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id t19so4688473ejr.8 for ; Wed, 08 Sep 2021 07:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Uabt4pKuf2kBSNv+i0qvyQ7gGTLuhCK/E/pLJaOpcUI=; b=led/LN2yMve9BoUBIhjG1AHu8ACK+rW3hw3Oy1SqXgFlTum0aLIn44Ifb94ULoUILi /Ap+SMj84d9jHlUHsmU3N/jEJnRo3r4LujzdvhLMfNv9EuMvXo1U/cjibCcKzgxTG8Xo ETBTWXFNAXQfMufWeNSNmqLfOXVrLl58/DN1jVyXZCIgRFnBsQUEVYR5HzAlplPCkyaY w/1Yaj1LBm1YT5+4UNem7fMi93GV2RMOnTOCEJuY85zy3SqERXhm54SHzuvKe9KZ8Rtz HN7Zq4kIGs/Cpx969P0qpx3DsZfxCJK48FZt5+M0SU3LAymtvVV+KB663T8+DDMaQ83f 5SRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Uabt4pKuf2kBSNv+i0qvyQ7gGTLuhCK/E/pLJaOpcUI=; b=22u5PDl/DCyk3+2oWbq2rBwvEPxuiMUVmfqPGj7Ux/5stC685zyhX8AWV6fhMOqFZE MTRAYbJkpVXFZJtL91agZPp6fI9ph3B5ZQfQCO63+uEe6C4DahRs2PSXUaMOoKiF1ave YeBk/pSkY9/wzGnOqnNp8yXxNqVLVihzNR7RFB+b/u6P9ywZZqbSBzal6U3xOJc/YORN 8hMxf5zHOmQHb6a7Z4mVTVEgKDL2aDJ9S8xnO8dL2XRIt8efc8YP4uxqTsxsdpKBDDei avujsP+t5iqVkE+7czjDCyhVUzczK0K0YpHskujd+mvr8IoaLfui9SyDhlg8jkLpPXqD BFXw== X-Gm-Message-State: AOAM5320jEeuu54Fx8PIEC/wPodT5kTr+WngqaXpoEmWKHvG5C61vUMv eUR3gwR1cK3zegKoqRv4Fft1FvLZIKoR9NWm2FnVIA== X-Google-Smtp-Source: ABdhPJwsIEqxGFffEBu189b/kMWOmdnA7n6KsndujfJWWNRveBZQSPJvlyjTExPZGsFlfiO7K/AhKS/FBYW3YXZXQA8= X-Received: by 2002:a17:906:584b:: with SMTP id h11mr197985ejs.209.1631112235567; Wed, 08 Sep 2021 07:43:55 -0700 (PDT) MIME-Version: 1.0 References: <20210908044427.3632119-1-yhs@fb.com> <20210908135326.GZ1200268@ziepe.ca> In-Reply-To: From: Luigi Rizzo Date: Wed, 8 Sep 2021 16:43:43 +0200 Message-ID: Subject: Re: [PATCH mm/bpf v2] mm: bpf: add find_vma_no_check() without lockdep_assert on mm->mmap_lock To: Peter Zijlstra Cc: Jason Gunthorpe , Daniel Borkmann , Michel Lespinasse , Yonghong Song , bpf , linux-mm@kvack.org, Alexei Starovoitov , Andrii Nakryiko , kernel-team@fb.com, Liam Howlett , Andrew Morton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Wed, Sep 8, 2021 at 4:16 PM Peter Zijlstra wrote: > > On Wed, Sep 08, 2021 at 10:53:26AM -0300, Jason Gunthorpe wrote: > > On Wed, Sep 08, 2021 at 02:20:17PM +0200, Daniel Borkmann wrote: > > > > > > The warning is due to commit 5b78ed24e8ec("mm/pagemap: add mmap_assert_locked() annotations to find_vma*()") > > > > which added mmap_assert_locked() in find_vma() function. The mmap_assert_locked() function > > > > asserts that mm->mmap_lock needs to be held. But this is not the case for > > > > bpf_get_stack() or bpf_get_stackid() helper (kernel/bpf/stackmap.c), which > > > > uses mmap_read_trylock_non_owner() instead. Since mm->mmap_lock is not held > > > > in bpf_get_stack[id]() use case, the above warning is emitted during test run. ... > > > Luigi / Liam / Andrew, if the below looks reasonable to you, any objections to route the > > > fix with your ACKs via bpf tree to Linus (or strong preference via -mm fixes)? > > > > Michel added this remark along with the mmap_read_trylock_non_owner: > > > > It's still not ideal that bpf/stackmap subverts the lock ownership in this > > way. Thanks to Peter Zijlstra for suggesting this API as the least-ugly > > way of addressing this in the short term. > > > > Subverting lockdep and then adding more and more core MM APIs to > > support this seems quite a bit more ugly than originally expected. > > > > Michel's original idea to split out the lockdep abuse and put it only > > in BPF is probably better. Obtain the mmap_read_trylock normally as > > owner and then release ownership only before triggering the work. At > > least lockdep will continue to work properly for the find_vma. > > The only right solution to all of this is the below. That function > downright subverts all the locking rules we have. Spreading the hacks > any further than that one function is absolutely unacceptable. I'd be inclined to agree that we should not introduce hacks around locking rules. I don't know enough about the constraints of bpf/stackmap, how much of a performance penalty do we pay with Peter's patch, and ow often one is expected to call this function ? cheers luigi 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=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 10708C433EF for ; Wed, 8 Sep 2021 14:44:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 991BE61163 for ; Wed, 8 Sep 2021 14:43:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 991BE61163 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id CFEC06B006C; Wed, 8 Sep 2021 10:43:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C8703900002; Wed, 8 Sep 2021 10:43:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B27C86B0072; Wed, 8 Sep 2021 10:43:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id 9CA9E6B006C for ; Wed, 8 Sep 2021 10:43:58 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4551182499B9 for ; Wed, 8 Sep 2021 14:43:58 +0000 (UTC) X-FDA: 78564675756.23.D39AA36 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by imf18.hostedemail.com (Postfix) with ESMTP id 0A46C4002087 for ; Wed, 8 Sep 2021 14:43:57 +0000 (UTC) Received: by mail-ej1-f50.google.com with SMTP id i21so4730042ejd.2 for ; Wed, 08 Sep 2021 07:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Uabt4pKuf2kBSNv+i0qvyQ7gGTLuhCK/E/pLJaOpcUI=; b=led/LN2yMve9BoUBIhjG1AHu8ACK+rW3hw3Oy1SqXgFlTum0aLIn44Ifb94ULoUILi /Ap+SMj84d9jHlUHsmU3N/jEJnRo3r4LujzdvhLMfNv9EuMvXo1U/cjibCcKzgxTG8Xo ETBTWXFNAXQfMufWeNSNmqLfOXVrLl58/DN1jVyXZCIgRFnBsQUEVYR5HzAlplPCkyaY w/1Yaj1LBm1YT5+4UNem7fMi93GV2RMOnTOCEJuY85zy3SqERXhm54SHzuvKe9KZ8Rtz HN7Zq4kIGs/Cpx969P0qpx3DsZfxCJK48FZt5+M0SU3LAymtvVV+KB663T8+DDMaQ83f 5SRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Uabt4pKuf2kBSNv+i0qvyQ7gGTLuhCK/E/pLJaOpcUI=; b=pLb9J3UMXT/MAGJBJ5Hp19b61rjJwBW5j6LbsR/lufvXZ0GsYa3LPH/14oAscArfOn CWy12L4QwbnbncsAfRGdg4QAQRaXWPA/j+NmQvHCF6KpoKUlFBl2rG96n7ur57phNWke ZuDwAuhhOn/xkm4eLwuPUVa1Rm7AtRVKIt45+/iEG+pqkVg/Cp4wKd2h7x26J5w0E1cy Tp7mYhCP+vclpJ9c8eOGA/brpgC5GZLRicXARQbjkWTLheC36giUzYiwzOZK6OE+l6ZA 2qnENpAD5QyGd2TJgWjWhQxEdNkLrQxJ7Yf9F7qWysyWP3NHQ5WVtlqHsjDG5rgiifMD VipQ== X-Gm-Message-State: AOAM530DlHpRBgrYNVWfU0Xx5UPNuvbuMF0qaSo3QxEi3wSO1eZIErMj fnidugA1Q4BprUQsYkQwKmnhkQ0EgRUbxfFiSLV2YFmqwZQ= X-Google-Smtp-Source: ABdhPJwsIEqxGFffEBu189b/kMWOmdnA7n6KsndujfJWWNRveBZQSPJvlyjTExPZGsFlfiO7K/AhKS/FBYW3YXZXQA8= X-Received: by 2002:a17:906:584b:: with SMTP id h11mr197985ejs.209.1631112235567; Wed, 08 Sep 2021 07:43:55 -0700 (PDT) MIME-Version: 1.0 References: <20210908044427.3632119-1-yhs@fb.com> <20210908135326.GZ1200268@ziepe.ca> In-Reply-To: From: Luigi Rizzo Date: Wed, 8 Sep 2021 16:43:43 +0200 Message-ID: Subject: Re: [PATCH mm/bpf v2] mm: bpf: add find_vma_no_check() without lockdep_assert on mm->mmap_lock To: Peter Zijlstra Cc: Jason Gunthorpe , Daniel Borkmann , Michel Lespinasse , Yonghong Song , bpf , linux-mm@kvack.org, Alexei Starovoitov , Andrii Nakryiko , kernel-team@fb.com, Liam Howlett , Andrew Morton Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="led/LN2y"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of lrizzo@google.com designates 209.85.218.50 as permitted sender) smtp.mailfrom=lrizzo@google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0A46C4002087 X-Stat-Signature: umwp46ct5ksfwunoz6kjbpg14kuh6wto X-HE-Tag: 1631112237-672803 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 Wed, Sep 8, 2021 at 4:16 PM Peter Zijlstra wrote: > > On Wed, Sep 08, 2021 at 10:53:26AM -0300, Jason Gunthorpe wrote: > > On Wed, Sep 08, 2021 at 02:20:17PM +0200, Daniel Borkmann wrote: > > > > > > The warning is due to commit 5b78ed24e8ec("mm/pagemap: add mmap_assert_locked() annotations to find_vma*()") > > > > which added mmap_assert_locked() in find_vma() function. The mmap_assert_locked() function > > > > asserts that mm->mmap_lock needs to be held. But this is not the case for > > > > bpf_get_stack() or bpf_get_stackid() helper (kernel/bpf/stackmap.c), which > > > > uses mmap_read_trylock_non_owner() instead. Since mm->mmap_lock is not held > > > > in bpf_get_stack[id]() use case, the above warning is emitted during test run. ... > > > Luigi / Liam / Andrew, if the below looks reasonable to you, any objections to route the > > > fix with your ACKs via bpf tree to Linus (or strong preference via -mm fixes)? > > > > Michel added this remark along with the mmap_read_trylock_non_owner: > > > > It's still not ideal that bpf/stackmap subverts the lock ownership in this > > way. Thanks to Peter Zijlstra for suggesting this API as the least-ugly > > way of addressing this in the short term. > > > > Subverting lockdep and then adding more and more core MM APIs to > > support this seems quite a bit more ugly than originally expected. > > > > Michel's original idea to split out the lockdep abuse and put it only > > in BPF is probably better. Obtain the mmap_read_trylock normally as > > owner and then release ownership only before triggering the work. At > > least lockdep will continue to work properly for the find_vma. > > The only right solution to all of this is the below. That function > downright subverts all the locking rules we have. Spreading the hacks > any further than that one function is absolutely unacceptable. I'd be inclined to agree that we should not introduce hacks around locking rules. I don't know enough about the constraints of bpf/stackmap, how much of a performance penalty do we pay with Peter's patch, and ow often one is expected to call this function ? cheers luigi