Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2701762pxa; Mon, 17 Aug 2020 17:09:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ8MUIGZY+2qS8L6iDG7DhN7V4+joptTCIZwRN/LOafZykrB/EGVbdAjGB40y32E26eaJU X-Received: by 2002:a17:906:1cd4:: with SMTP id i20mr17267798ejh.480.1597709387173; Mon, 17 Aug 2020 17:09:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597709387; cv=none; d=google.com; s=arc-20160816; b=uYUiHBZ4u4GaR5obMKetCofg6KbRcV6zukpXpUJnFGwaflOKVznG36g+JOfv9z85Gs piOMOXZeS3VtzUjLI9QdHq7cY4S9WWJj4ie8hRTIp+Ch+Oti/ioxGWsgZ2EHVBcloYWm ZuaWwuYabcG4L8FrNtOcCdY/X3wVDndcJzcbj8iO9rDwWlRE4BH4MLE5AtrNbUQhpSSL j01dPL6dX/Nv5ji87u2Ngk5YZFmMqHT3EfbXtxAp+DdAD0ReL+KymdBGdPwG1zdIBzfy 2RzP4+qLog1eO8DyZWUDRPEl2DewU0d2xpA1LyYjzllm8eiix3mCDKh3CIc/g50y3bnO Np8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7PUubmKG0qCUbLC0lny1sEZMsh6oDctj94eQbjDTgwk=; b=voa+0ExlkiMkhlKVwt09hhvBDEdpaIb5RqLugEpCdIoeHsxC3FBH//HJk9OvbcMCvb 3YRApCUCFAcZ+sfcC3L42gRsgtkf1nxNZN8zK4xri1Sz1+PDZhsN8F+cLWeTPR2zsDV0 gabcsmc1ADgQHJkP/nH/KWOZnHJ+LvB4YIepHIMU1bACT55w+5w2N2j/FPZXgCL/F4S+ j+A10dxKgafti1pa5VaBVD9evTPfwBg0im6/sDA5Ny8s666pwMUgkmkfHF/I04GDa3yn whpqb5OYbN9GCcs0amPra4ECsK7A30LfjORNVhrm2WoR4Rw02h7H1z3lKhN1KA2R4Qcu CVIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Cc93yVMb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l25si12007714edv.47.2020.08.17.17.09.19; Mon, 17 Aug 2020 17:09:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Cc93yVMb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726624AbgHRAIu (ORCPT + 99 others); Mon, 17 Aug 2020 20:08:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726473AbgHRAIt (ORCPT ); Mon, 17 Aug 2020 20:08:49 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30D57C061342 for ; Mon, 17 Aug 2020 17:08:47 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id h8so9279455lfp.9 for ; Mon, 17 Aug 2020 17:08:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7PUubmKG0qCUbLC0lny1sEZMsh6oDctj94eQbjDTgwk=; b=Cc93yVMbx3RvLnq5PLotBg+roGGu69+/Dx9uDZdnFaQvTrkIzdLU5lhrEDOPiq2+fN 5E+MIu8qQiaA07jjpGceLS5/FUXItwiiQf3jrnqL+6nxCyP1OYWmoOUBc1tR+82IoQ3t pB1HfO6+D8i21tTtZuIWUIjxWkjP3RCPMcq/k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7PUubmKG0qCUbLC0lny1sEZMsh6oDctj94eQbjDTgwk=; b=jIs1r9evR+44RAbAZ8/VyQYNpS6JutRgWqqx3Q7SwD4BUFmfFVH2yqRL9iGvLopPTX lwR45qlcpt+vFiafg3OqhT9BPgnN2AGfoX/8aPz6GlX5en4o4pRUlPQNeOIYbeL8hifp ULPix16z4WHNWOp4oksFqqpOcFOnB3hhiygT3MOl0AZ8YUZWHTILmwKV78PiXke6oI/s NguOz7QKfi9wVmzFDPKt9Jkb4Nc2CM7CVsAHAMCI82dzE0D+FvlOv1Akf7XMSvQ8a40N f8cbxL2bI5u+7nSvtr21P/kM3eW44j4AmcpooY8LES+au6ehkMfcVxiZiTBwsaTeOxxm 4wig== X-Gm-Message-State: AOAM530A7ODozDBko8TSNiSdkLOC/tmnEB5Y9TEfzgx5p3UTauGQYtVQ 5xzrMOMxHxr6PnPM3mtejIBYtHa3uDKe6w== X-Received: by 2002:a19:c197:: with SMTP id r145mr8436276lff.41.1597709325512; Mon, 17 Aug 2020 17:08:45 -0700 (PDT) Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com. [209.85.167.46]) by smtp.gmail.com with ESMTPSA id h23sm5153153lji.139.2020.08.17.17.08.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Aug 2020 17:08:44 -0700 (PDT) Received: by mail-lf1-f46.google.com with SMTP id v15so9259331lfg.6 for ; Mon, 17 Aug 2020 17:08:43 -0700 (PDT) X-Received: by 2002:a05:6512:3b7:: with SMTP id v23mr8518837lfp.10.1597709323252; Mon, 17 Aug 2020 17:08:43 -0700 (PDT) MIME-Version: 1.0 References: <87ft8l6ic3.fsf@x220.int.ebiederm.org> <20200817220425.9389-12-ebiederm@xmission.com> In-Reply-To: <20200817220425.9389-12-ebiederm@xmission.com> From: Linus Torvalds Date: Mon, 17 Aug 2020 17:08:27 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 12/17] proc/fd: In fdinfo seq_show don't use get_files_struct To: "Eric W. Biederman" Cc: Linux Kernel Mailing List , linux-fsdevel , criu@openvz.org, bpf , Alexander Viro , Christian Brauner , Oleg Nesterov , Cyrill Gorcunov , Jann Horn , Kees Cook , =?UTF-8?Q?Daniel_P=2E_Berrang=C3=A9?= , Jeff Layton , Miklos Szeredi , Matthew Wilcox , "J. Bruce Fields" , Matthew Wilcox , Trond Myklebust , Chris Wright , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 17, 2020 at 3:11 PM Eric W. Biederman wrote: > > Instead hold task_lock for the duration that task->files needs to be > stable in seq_show. The task_lock was already taken in > get_files_struct, and so skipping get_files_struct performs less work > overall, and avoids the problems with the files_struct reference > count. Hmm. Do we even need that task_lock() at all? Couldn't we do this all with just the RCU lock held for reading? As far as I can tell, we don't really need the task lock. We don't even need the get/pid_task_struct(). Can't we just do rcu_read_lock(); task = pid_task(proc_pid(inode), PIDTYPE_PID); if (task) { unsigned int fd = proc_fd(m->private); struct file *file = fcheck_task(task, fd); if (file) .. do the seq_printf .. and do it all with no refcount games or task locking at all? Anyway, I don't dislike your patch per se, I just get the feeling that you could go a bit further in that cleanup.. And it's quite possible that I'm wrong, and you can't just use the RCU lock, but as far as I can tell, both the task lookup and the file lookup *already* really both depend on the RCU lock anyway, so the other locking and reference counting games really do seem superfluous. Please just send me a belittling email telling me what a nincompoop I am if I have missed something. Linus