Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1261254rdh; Fri, 27 Oct 2023 09:00:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHctWxhmEQGoHt5wbQPSFRCi9BWlVYfzaIpeX0V/Vsv9pay9QxoKvcCDUzyFZDn2uNqfbdK X-Received: by 2002:a67:e154:0:b0:45a:9e8c:fe4e with SMTP id o20-20020a67e154000000b0045a9e8cfe4emr3067097vsl.16.1698422442760; Fri, 27 Oct 2023 09:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698422442; cv=none; d=google.com; s=arc-20160816; b=GFEoGF8vzOcls6FoXmjS80QSgg6QgX+bnE2c2XjaQi7wOXlQyxe8N/Qti9LVYtP8jQ Ly1184si+FbIJE7p/tW989YqLSdV8qDU7gXLakmiLUQMuIAxAsWYVJswMvAg+Ia06Hn1 koNDzlOd5ZO5w6Ls0knkrLziwSdKqMtbVIVXjD/Oxyb+ENk0SzGPUWBuVJcbq4BwUmUl eucUfz+swhZJrzZvljuMBFcyQiT0XBUFDVc2SpsKhFcon4WZEJczY6TokXOY5P9ieV1D CHCjxgz0M4u2U2hvg597kRlL1J1hzR7BaUozG07utGp2Ks8Zd2XM917XWBP20+zxLVVr 6Ycw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6o4rbLFYNUp9YJOxgeaoUrnihGTZ1EBKCFaYlv7pvHU=; fh=+9qBJZg9BEyoQLsCtjyUssUsVOGEQKZCUZpNDYv38sQ=; b=sfs9bbVrE7s1qFluN75APTPGJNcoqccse/4iTpU2DRO+0v8bCC6iB1j8oDyNZsRZvg GDzimJ+lJfeQ8Ck127tyS/8wusODq74Kt6OMGtqyx+o+8e3TtbO9r4m1NQDaYJPybjm4 GbfDveIFr1u7BvLi6g9UwzZTgGUx6DgVKh8QenT5sWPtbTZC0SAvkErEgZ8G9KbpvdhV qi1GXGsS99jLbaKNC3nY8fYDF1yM3bvEzbOFd/MvtHrAfYdVJCqTedcJNZvjFYxqeNf4 +zsD1D7v7h59wkwyHUIFt9BiUUevhdjdSdzv6qNVNXJbpl05TCRtLgooauH8Gn/yOUFN VI2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LeKd3dZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id c9-20020ab02849000000b0078f5f052885si298814uaq.43.2023.10.27.09.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 09:00:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LeKd3dZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 5BAD181F39E7; Fri, 27 Oct 2023 09:00:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346033AbjJ0P74 (ORCPT + 99 others); Fri, 27 Oct 2023 11:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346247AbjJ0P7z (ORCPT ); Fri, 27 Oct 2023 11:59:55 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB14CE for ; Fri, 27 Oct 2023 08:59:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=6o4rbLFYNUp9YJOxgeaoUrnihGTZ1EBKCFaYlv7pvHU=; b=LeKd3dZSt3bfsY/3NaA8gkWnHj SeZYAPIQtkWwGBuFPrSBKrIkCsQAa8ub/tbnVKF6RFCcBsU4w7Vs6KDHOSpe4/ZjXTSRQRqMBJbAR KwGHFDyEvmUiahxUhpOMqhGdQuMCgx2ZkOY2yrLMN3lliJS2NP+fSGq3+w6BcspFeW8QDB3pW2Y9C 0KeZ3wd00h4+EFw0Ng8HsKH8m+1RGtNM58+5VRiI129jhIk+LEJWCkM6m9M+Y5fbrN2PUH2dZAnvR xTmzUQLwr26u4BtQx2Fc82EjMB+LlL8f/TkX0U18XB8u//kLq3BRxfobuVUbmQ0mrmhC2Wbd09dcI V/i9Hhwg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qwPFW-004FZK-BM; Fri, 27 Oct 2023 15:59:50 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 07CB9300392; Fri, 27 Oct 2023 17:59:50 +0200 (CEST) Date: Fri, 27 Oct 2023 17:59:49 +0200 From: Peter Zijlstra To: Jens Axboe Cc: Ingo Molnar , LKML Subject: Re: lockdep: holding locks across syscall boundaries Message-ID: <20231027155949.GA26550@noisy.programming.kicks-ass.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 27 Oct 2023 09:00:06 -0700 (PDT) On Fri, Oct 27, 2023 at 09:14:53AM -0600, Jens Axboe wrote: > Hi, > > Normally we'd expect locking state to be clean and consistent across > syscall entry and exit, as that is always the case for sync syscalls. > We currently have a work-around for holding a lock from aio, see > kiocb_start_write(), which pretends to drop the lock from lockdeps > perspective, as it's held from submission to until kiocb_end_write() is > called at completion time. I was not aware of this, the only such hack I knew about was the filesystem freezer thing. The problem with holding locks past the end of a syscall is that you'll nest whatever random lock hierarchies possibly by every other syscall under that lock. > This is a bit of an ugly work-around, and defeats the purpose of > lockdep. > > Since I've now got another case where I want to hold a resource across > syscalls, is there a better way to do this? > > This is for inode_dio_start(), which increments an inode int count, and > inode_dio_end() which decrements it. If a task is doing > inode_dio_start() and then inode_dio_wait(), I want to trigger this. I > have a hack that does this, but it disables lockdep_sys_exit() as > otherwise I just get that warning rather than the more useful one. Suppose syscall-a returns with your kiocb thing held, call it lock A Suppose syscall-b returns with your inode thing held, call it lock B Then userspace does: syscall-a syscall-b while it also does: syscall-b syscall-a and we're up a creek, no?