From patchwork Fri Jun 19 16:50:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 1313200 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49pPxm1p36zB4Cq; Sat, 20 Jun 2020 02:53:00 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jmKG7-0000Rf-Pr; Fri, 19 Jun 2020 16:52:55 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jmKEb-0007UO-5t for kernel-team@lists.ubuntu.com; Fri, 19 Jun 2020 16:51:21 +0000 Received: from mail-il1-f197.google.com ([209.85.166.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jmKEZ-0006S1-7i for kernel-team@lists.ubuntu.com; Fri, 19 Jun 2020 16:51:19 +0000 Received: by mail-il1-f197.google.com with SMTP id k13so6823201ilh.23 for ; Fri, 19 Jun 2020 09:51:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XzwOXmbfK6RgJET7yluQITNNBvpNYT1x45HKFsZumcM=; b=p3dbRHMEEB8hkeRsJ4zK+XYqjx5UwA4VdRVrSAQDf1VyP5JLRqR3q6jmzaPJctOx7p kYaBPTy18Mx0Nf2AlPQVDhxJpRzN5BrmhASGWYTCTS1h0IErylNRau3l4IqNyIAvg4nL 7RAR5un1a1twgT5lrNvEb0wqyA2HJZR27pIMrmh1BCHX6Baj5IiRS+JIHy065D9Lxisr Okussx2o9eIa1j5k/BWs2OMB/aATgoVLK0zmQCmbCuBUmqdAJwhomKtkIESNO1Wjz5Uk e8QQ3sH21w9rvk1uXthA3SvT3B9iKaGZMkjIbnpNzx0ZGr8wN6n0veiWRI8W+2oD3Whn 31mw== X-Gm-Message-State: AOAM531K1EnZbj8KN3qiRUHakIUY7XAe+V72eIXnAPEWc6b7sBho+1AD RpVmCkloU5M84e9nB20f/E/iRuc2qpoxCO0kl9ta1FUjceHVqyzLMkvH7mNhrv//AREus1tso6Z va+wi/XDEF5Pe1+YYXb2YpjHE3QVW2VX5//lazXvPJg== X-Received: by 2002:a05:6602:2c8f:: with SMTP id i15mr5309606iow.45.1592585478046; Fri, 19 Jun 2020 09:51:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeBn1jTVXsMx+aMh2dBm10cFRAvo2MDdkk66CL/SFgOmAIU0yDrTFAc3IkbNjTIlopr/F8RQ== X-Received: by 2002:a05:6602:2c8f:: with SMTP id i15mr5309590iow.45.1592585477811; Fri, 19 Jun 2020 09:51:17 -0700 (PDT) Received: from localhost ([2605:a601:ac0f:820:f090:1573:c2fc:6389]) by smtp.gmail.com with ESMTPSA id k18sm3587305ioj.54.2020.06.19.09.51.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 09:51:17 -0700 (PDT) From: Seth Forshee To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 53/57][X] debugfs: unproxify files created through debugfs_create_blob() Date: Fri, 19 Jun 2020 11:50:06 -0500 Message-Id: <20200619165010.645925-54-seth.forshee@canonical.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619165010.645925-1-seth.forshee@canonical.com> References: <20200619165010.645925-1-seth.forshee@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Nicolai Stange BugLink: https://bugs.launchpad.net/bugs/1884159 Currently, the struct file_operations fops_blob associated with files created through the debugfs_create_blob() helpers are not file lifetime aware. Thus, a lifetime managing proxy is created around fops_blob each time such a file is opened which is an unnecessary waste of resources. Implement file lifetime management for the fops_bool file_operations. Namely, make read_file_blob() safe gainst file removals by means of debugfs_use_file_start() and debugfs_use_file_finish(). Make debugfs_create_blob() create its files in non-proxying operation mode by means of debugfs_create_file_unsafe(). Signed-off-by: Nicolai Stange Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 83b711cbf4ff42a9996c5f092762b3967d307d73) Signed-off-by: Seth Forshee --- fs/debugfs/file.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 8a548bee1b3d..2e86d66f7850 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -842,8 +842,15 @@ static ssize_t read_file_blob(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct debugfs_blob_wrapper *blob = file->private_data; - return simple_read_from_buffer(user_buf, count, ppos, blob->data, - blob->size); + ssize_t r; + int srcu_idx; + + r = debugfs_use_file_start(F_DENTRY(file), &srcu_idx); + if (likely(!r)) + r = simple_read_from_buffer(user_buf, count, ppos, blob->data, + blob->size); + debugfs_use_file_finish(srcu_idx); + return r; } static const struct file_operations fops_blob = { @@ -880,7 +887,7 @@ struct dentry *debugfs_create_blob(const char *name, umode_t mode, struct dentry *parent, struct debugfs_blob_wrapper *blob) { - return debugfs_create_file(name, mode, parent, blob, &fops_blob); + return debugfs_create_file_unsafe(name, mode, parent, blob, &fops_blob); } EXPORT_SYMBOL_GPL(debugfs_create_blob);