Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1267196rdh; Fri, 27 Oct 2023 09:06:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGk7yDIxUUAOWTOO9t96DQuv3HUE3CWMy4wDhM44Q+ThOoQCQC7y5Wn4J8sECOWQaKchpuG X-Received: by 2002:a67:e0cd:0:b0:457:c5e3:3b8b with SMTP id m13-20020a67e0cd000000b00457c5e33b8bmr2974892vsl.6.1698422809507; Fri, 27 Oct 2023 09:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698422809; cv=none; d=google.com; s=arc-20160816; b=pm+PUGzTQMFBScAZ5Naox8lDO2N+pKDbE60w029wMIurTxc/pTRbuSQP19MbydN3aU LUQeMsJyQV8zHxKij2R6cPvdQGj6TpYY7f1V207d96aOtAqEAPg0vFbregHwPe8MESjP gbmny4pVZ1R3NPLAcB60Ld5WkY/aQFbptgBTOCuDggWGTOLoQcOVHY3fvPwqgkBH59o4 d0ulpqJcn1uXLEtpw6nB6Lr+xBkEigapfFFG4YPbLrHJaJOsz9NWoton6SqmmJwuA/yV kvZItzAWxiazJGYYsLAOECwM6zHSHrhKhIviDysiDPY3Hype/7FDMEGGQXyxIWDH5wLM oUSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=EPlo4x7yobsVXsYN+X/3Ftss4isqLA61+zu/I1aWQ0U=; fh=7b5HtM4dqHKY3upnYCU/oC9psLVrytqrzMg44+YHxu0=; b=hRyZevTYzvbgEw4i+wGrmHjUCo9I0zzdx1zjO14mf/rFnEQZf76tU1gpWBHPC/f7tX 7mJxk7ECMTZPUggTyzebjrICtfsImk7xNMOs38+6w/TEfINVqJ0NwZOuJXJx2k43ckEg 3hsdxvMAxzUJJTuw1/SvYzg8S/1HO9kj/p/jK+/WDomT1D0KB2hsi7Nloy2ADMuOWW6l IRitDq2zSqhr7ThWwzRxThAyTHOdCIwFp23Bw6qy5+26RqKH3O1KU89uW/3auMmwLkIv kG+TZUcvyP9NvcHoHROk3i5+ZF5AhjfCMDNfOAqP2T7LXyJsSYGftUqz4E3SmJfROy8E VOfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=q2Jd8zEC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id n1-20020a67a401000000b00457898177b4si295550vse.446.2023.10.27.09.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 09:06:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=q2Jd8zEC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id DA4B98227416; Fri, 27 Oct 2023 09:06:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231722AbjJ0QGk (ORCPT + 99 others); Fri, 27 Oct 2023 12:06:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230440AbjJ0QGi (ORCPT ); Fri, 27 Oct 2023 12:06:38 -0400 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38960CE for ; Fri, 27 Oct 2023 09:06:36 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-7a950f1451fso26253939f.1 for ; Fri, 27 Oct 2023 09:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1698422795; x=1699027595; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=EPlo4x7yobsVXsYN+X/3Ftss4isqLA61+zu/I1aWQ0U=; b=q2Jd8zEC8gPh9qXAhJwpF+7swBvR2VAtYiMdnAEsyULSEHHqaR0DNGpxUwvky5OrHA XOaxKZQVWFvvUKIX95fAfrq66Xl0OjgQQBnSG3CGC6D/kTeTuRUKW0LMyX0Fjpc88U4D CoikvhzbkJJcCVWyfRmvzlr2RXWzhBSGwErcOl73y62ZTRwYsabjNQGV6PF/nqJc6VTa Qz2/7zMoNW4mnZIB8r4mTqWatt+HwrNy0DKEjBHvutnLRCDk6rUmozMbqNaZh1itlpEU DzdHmegxAkrcldfG/7jNzeOiyMng3bkyoG3z16GWTSM2S9Yzw1JLEHEYX0dt6S6mdqMH 3KnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698422795; x=1699027595; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EPlo4x7yobsVXsYN+X/3Ftss4isqLA61+zu/I1aWQ0U=; b=AyXZMk+to8P4zEerRnWHiV0yOQQVEBm8KwIfRqMTRBHhBMjsbxzS6EWv6LSnPqcaH8 JEq4DJsZCvfHRdc3urNUtmr2C/Sqt02+wDYL4BdX+oqPMIuNmAIB8Im254SxXJM9Ts6F eIWDur4gptHLfmnwpW3R9fuMbw6nUnV1B2e3J8XhwGfWN/CDhV8VEbI2B+NE+G/0vX3y t3psXbbMuDNaNpEjE94wkA/7XHE6mYZMmRkXLgawpKG+xvCPpeXtHKzlnwxMf/HjbScN qy+iRuTf4KN5rahAIQH2s+UMutMlLrn3u0ulOmOpher93ZtZEpUMBgUSlnQH0DM1Nzwq oABg== X-Gm-Message-State: AOJu0Yw8a5gP3Ipe31nRHfA8yabwMEQgz4gshFNqQx4kNuykCWgALpMe 4S5OFWAIQqODdb6lXyPHk02D5feEZARAtkqdFV6xFQ== X-Received: by 2002:a05:6e02:1d1c:b0:358:a6e:71b7 with SMTP id i28-20020a056e021d1c00b003580a6e71b7mr4939454ila.0.1698422795405; Fri, 27 Oct 2023 09:06:35 -0700 (PDT) Received: from [192.168.1.116] ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id l14-20020a056e021c0e00b0034e2572bb50sm567844ilh.13.2023.10.27.09.06.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Oct 2023 09:06:34 -0700 (PDT) Message-ID: Date: Fri, 27 Oct 2023 10:06:33 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: lockdep: holding locks across syscall boundaries Content-Language: en-US To: Peter Zijlstra Cc: Ingo Molnar , LKML References: <20231027155949.GA26550@noisy.programming.kicks-ass.net> From: Jens Axboe In-Reply-To: <20231027155949.GA26550@noisy.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 27 Oct 2023 09:06:46 -0700 (PDT) On 10/27/23 9:59 AM, Peter Zijlstra wrote: > 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. Can you expand on that bit, not quite sure I follow. Do we reset the locking dependencies between syscalls? >> 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? Should this not get caught by the usual lock ordering rules? Because that is obviously a bug, ordering would have to be consistent, just like if we have: syscall-a lock(a); lock(b); syscall-b lock(b); lock(a) -- Jens Axboe