Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp570040lqr; Wed, 5 Jun 2024 14:27:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWsrthSFv+9qDiMSXzVykCHw1aD/+1nAocS21TvxT87Ao4/fgiE/PwCINuVuyjuLkwc2fINlBdv87GLvBiQX62LGe5f6aHZgwoskTot3A== X-Google-Smtp-Source: AGHT+IHN1w2RSCtYE/k9NYGh+prmWLztt8BFGmOZuVoi6vbbbNIhIV5HIpO0Vh6ZQ204JFzYBe30 X-Received: by 2002:a05:6a00:178c:b0:702:6515:f755 with SMTP id d2e1a72fcca58-703e59f06a1mr4793208b3a.21.1717622873267; Wed, 05 Jun 2024 14:27:53 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c359e09a1fsi4416400a12.253.2024.06.05.14.27.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:27:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203105-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@eideticcom.onmicrosoft.com header.s=selector2-eideticcom-onmicrosoft-com header.b=wf7ytKak; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-203105-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203105-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 298EA2860B9 for ; Wed, 5 Jun 2024 19:31:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A71F815442C; Wed, 5 Jun 2024 19:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=eideticcom.onmicrosoft.com header.i=@eideticcom.onmicrosoft.com header.b="wf7ytKak" Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2119.outbound.protection.outlook.com [40.107.93.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEB7F1527BA; Wed, 5 Jun 2024 19:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.119 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717615821; cv=fail; b=YQUqR8yjge6Oi3HZxBLP4ALZyULyb0KncFBy7RtuDdhyy5Fh8yIzsZ62T+yTGpFX0YKDA9+ms9sC9X018/1idYeLgx2rCXGFUr1P+stPqWGmGWjXu13Y/VUpHOYWt3M4gVc3X1mKrWmCbliRoJQLlQ+wFCiPuyyLbPPIT0BJ7bs= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717615821; c=relaxed/simple; bh=ZUR69+qGI4LyqW9hJu3wMXvLwblhnzFCaZu6vfjKSfM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=b3ODlIbkEMxinx2VR/IYBs2BkC9hwjJXkrXn3D/f33WmRHKpRVYUJevSGH1BoMTyoG7ZKAt9+oM+izwF31swDCQ9h2IUsz+74ow78zUJrpPmPW/FGSdtVRofnd4N1M4qNV98b2XRlGXLS3qkT5gvY8fWkhnNO8vP/SeA30DlJpg= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=eideticom.com; spf=pass smtp.mailfrom=eideticom.com; dkim=pass (1024-bit key) header.d=eideticcom.onmicrosoft.com header.i=@eideticcom.onmicrosoft.com header.b=wf7ytKak; arc=fail smtp.client-ip=40.107.93.119 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=eideticom.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=eideticom.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GXzgCpABVuwAna9Jge2elVxLGwFtSqFLfc8XBst3lSbNnbTGR8LAvohBSf17vLG2/Ioy6V+W8Ela0PFnq8+IhEmckkerE69QOtaMdkS3jM32xCzu8GtGMjuHFhB3i5OtxyZIunWjSjVoPAK9gVy9I5izvgj4224NThjbdnlBocJEnSOwEYJqZM7rd/ybd+RHBu2nc4oe5qw4c4n520E1F86HrQkpzu7tL3BkoT6Ci4AzwIiXoMYPzeg7v0Jb3R9LWCZx8Z1cGXrnYnp717s2PYhfO8d7LNXYpNbhIbaeQlItDZTzfvhbUATcBtJYYb3cprhF0/6w2JTJmCXGpQ48bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iZhzkCh0YEXOsUBThTVc0p81/UyH9suxkN/Dh0CRO+k=; b=lXEoul320sVfnbDXWzUmZgepWBzL7iJ1HVpwzYFHi0Ms6rGHCfKnpqRIIoQob8IHY35joWYerii+MEY8dV3DnzjeuDAuLghytQjV4FN+W+fGj4C8yWwDh+nVp9rEWVvKol4KfzA0Elc5Q9Uy7Us9uiXmTSwOxi0TMzQvOWYcd6fDa6QJmRtcdYTYf2ToFEhE40hhu3feJwT9O4q1puZrvtOlvzPexwHfWBteatyVIMyZ4Y/TovJrHKMovrqr04kEuVjWIz59Zl5VmDRkhdUisnYmoaCU53XXEuU2z+EjOxY5UhccIHPck6rW+Bu//xWxxyF5wY7HX+lgap4HBuVQeQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=eideticom.com; dmarc=pass action=none header.from=eideticom.com; dkim=pass header.d=eideticom.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eideticcom.onmicrosoft.com; s=selector2-eideticcom-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iZhzkCh0YEXOsUBThTVc0p81/UyH9suxkN/Dh0CRO+k=; b=wf7ytKak5P41Cyst9fDP1j86RjdXX/ZpLpulOEZrqQUU0dj6G5yLMPP5PzM/O32blEAGztSJcfgLaz86APaQsfb6ozcGs/G6FDdtcp52ffSOKe7q8EVsIRBYvk9laO1eC6yPAnCb7WM9v9QTGa7mmaaegUkUkhVDkEbA6xKvypY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=eideticom.com; Received: from MW3PR19MB4250.namprd19.prod.outlook.com (2603:10b6:303:46::16) by PH8PR19MB7093.namprd19.prod.outlook.com (2603:10b6:510:223::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Wed, 5 Jun 2024 19:30:09 +0000 Received: from MW3PR19MB4250.namprd19.prod.outlook.com ([fe80::3280:d8d:de43:6376]) by MW3PR19MB4250.namprd19.prod.outlook.com ([fe80::3280:d8d:de43:6376%6]) with mapi id 15.20.7633.033; Wed, 5 Jun 2024 19:30:09 +0000 From: Martin Oliveira To: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org Cc: Jason Gunthorpe , Leon Romanovsky , Bjorn Helgaas , Logan Gunthorpe , Greg Kroah-Hartman , Tejun Heo , "Rafael J. Wysocki" , Andrew Morton , Mike Marciniszyn , Michael Guralnik , Martin Oliveira , Dan Williams , Ard Biesheuvel , Valentine Sinitsyn , Lukas Wunner Subject: [PATCH 2/6] sysfs: add mmap_allocates parameter to struct bin_attribute Date: Wed, 5 Jun 2024 13:29:30 -0600 Message-Id: <20240605192934.742369-3-martin.oliveira@eideticom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605192934.742369-1-martin.oliveira@eideticom.com> References: <20240605192934.742369-1-martin.oliveira@eideticom.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW4P222CA0007.NAMP222.PROD.OUTLOOK.COM (2603:10b6:303:114::12) To MW3PR19MB4250.namprd19.prod.outlook.com (2603:10b6:303:46::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW3PR19MB4250:EE_|PH8PR19MB7093:EE_ X-MS-Office365-Filtering-Correlation-Id: 542ddc6a-ee66-4ec9-47a3-08dc8595e7ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|52116005|7416005|376005|1800799015|366007|38350700005; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?uEGrR7D7rmRg9eQDAEdPvwX5w4x0zNjNkcfIgrUtrxzJi8cefLPcgoSXuAqM?= =?us-ascii?Q?TII0CIMx5SZkKWgtcWmtAiRSHVKej1OWJ//QOlu+dT7e5fyJV+/vWGjFFFud?= =?us-ascii?Q?h+Gn0FBKbRk4VJLYqL+D1GpaiHoXOxukZqBR8aKbqlZnv7zDBddy0vNBLinq?= =?us-ascii?Q?dP+GuwkQ4iXptm8ZVwHDDJTtwHd4BacSTuU9Fxh/Xrx6ZceUEjQuCjUTwXdG?= =?us-ascii?Q?jDF5l7GWpFr6H16liiDA2ekTWwKgrmN96qpzvk80zawuPwSFdAUlBAGAIdDH?= =?us-ascii?Q?alBfVR6XbRKr18lvn744dr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ls18HyYmtQcbchmpxaAmUgpsIl1y6aVx633fFFPg3BmW+9rVx1gT3DCYj?= =?us-ascii?Q?NIPKZsumQFQz8RHbveJnI9DbSP0VjZ4fmrENsZ/LoVGNKjhFauU5I03zOVBC?= =?us-ascii?Q?RqKPOmzhnUrd1oR429vIUHQ0RYKLM7k8H+CuIVHbx2vMswql7HBCVX1WPxw1?= =?us-ascii?Q?3XibuGE=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR19MB4250.namprd19.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(52116005)(7416005)(376005)(1800799015)(366007)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?25lmoksPC/AnTLxDIUIe1owA5WKhvq3G+5/n91gYhOwQWWr1pTu76O4zVE6s?= =?us-ascii?Q?ZiVYERu1jVFHgy7gqmadwomIooh6TYpU0UYUCANQ5+u44my4ndb1VXsPk6m1?= =?us-ascii?Q?SQShBFlFUS9hPuUbWo7KlUJ0OY2GNWbH5NuZB9zP61wawXWDOPWgPhiYPzeZ?= =?us-ascii?Q?JN0neL2iR7L8t6cuPFHMjUNuhIiYruOptRDAOJw8QdV1pDMEjrkM4kmdaIDC?= =?us-ascii?Q?t8yYBmkJNrGSo0/DJO9g49IM5kE54jvkHGcbTb86rcjGZsVThvTAi6Ache7j?= =?us-ascii?Q?IjSvciQHeiT6erVrNe1r0oIN/TcjKAS6tb3APhktuP1bzssMOQkv242xcU44?= =?us-ascii?Q?4xTmTrL/4HAoAA3ViRatyUsRpkmuCh5rdbJoRKs5G927Ek9pnKJvCPZ73UVi?= =?us-ascii?Q?Vvq45LKZewcff/O2inToDBesg9311+ZEAA0ZynhveIt9hotV3IH82+rr21SR?= =?us-ascii?Q?w+CYEg8Y73FFNrDN3fmG3EdJjdGhPDFzOq0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q?B+F/Wm+Lt57Oe4IhGhn2eTMTzhPNtt0VpRENRA9Fso6LROUdCL89rEgWRRpt?= =?us-ascii?Q?Kx/DBi5HIVvUTAeltMOFOC2oz+9PNe+sSdze0M3S7Hz8VnjUzCpMmqQFo24w?= =?us-ascii?Q?VeVScBkrYAuz3NYuIVjNXRDiDO4/D8psNihVr+7fFGS1LhdivVbRixNt5Cqq?= =?us-ascii?Q?TduhtmZWxLegVUfuxpzNBc7EVgjy4G71MACP6JZuDXyRwe+KEEAOHNAbp881?= =?us-ascii?Q?RQ=3D=3D?= X-OriginatorOrg: eideticom.com X-MS-Exchange-CrossTenant-Network-Message-Id: 542ddc6a-ee66-4ec9-47a3-08dc8595e7ce X-MS-Exchange-CrossTenant-AuthSource: MW3PR19MB4250.namprd19.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jun 2024 19:30:06.6899 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3490cd4b-0360-4377-abb1-15f8c5af8fc2 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: H3f+77+UO1EGX1JN+1QoG7pMYrqZSayMlV0Ae3NDDaY8Skp9PRiq5y7AlwCi5QxGa2uf/9pIbse3/1grg/zRBT/DhtCQGDgje48v7F0rfkg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR19MB7093 Now that a struct kernfs_ops can have an "mmap_allocates" parameter to avoid the page_mkwrite() operator, the struct bin_attribute needs a way to choose the appropriate kernfs_ops. Introduce a "mmap_allocates" boolean on struct bin_attribute to achieve that. Co-developed-by: Logan Gunthorpe Signed-off-by: Logan Gunthorpe Signed-off-by: Martin Oliveira --- fs/sysfs/file.c | 25 +++++++++++++++++++------ include/linux/sysfs.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index d1995e2d6c94..77c21009ceee 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -264,6 +264,15 @@ static const struct kernfs_ops sysfs_bin_kfops_mmap = { .llseek = sysfs_kf_bin_llseek, }; +static const struct kernfs_ops sysfs_bin_kfops_mmap_allocates = { + .read = sysfs_kf_bin_read, + .write = sysfs_kf_bin_write, + .mmap = sysfs_kf_bin_mmap, + .open = sysfs_kf_bin_open, + .llseek = sysfs_kf_bin_llseek, + .mmap_allocates = true, +}; + int sysfs_add_file_mode_ns(struct kernfs_node *parent, const struct attribute *attr, umode_t mode, kuid_t uid, kgid_t gid, const void *ns) @@ -323,16 +332,20 @@ int sysfs_add_bin_file_mode_ns(struct kernfs_node *parent, const struct kernfs_ops *ops; struct kernfs_node *kn; - if (battr->mmap) - ops = &sysfs_bin_kfops_mmap; - else if (battr->read && battr->write) + if (battr->mmap) { + if (battr->mmap_allocates) + ops = &sysfs_bin_kfops_mmap_allocates; + else + ops = &sysfs_bin_kfops_mmap; + } else if (battr->read && battr->write) { ops = &sysfs_bin_kfops_rw; - else if (battr->read) + } else if (battr->read) { ops = &sysfs_bin_kfops_ro; - else if (battr->write) + } else if (battr->write) { ops = &sysfs_bin_kfops_wo; - else + } else { ops = &sysfs_file_kfops_empty; + } #ifdef CONFIG_DEBUG_LOCK_ALLOC if (!attr->ignore_lockdep) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index a7d725fbf739..190b4b9355df 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -294,6 +294,7 @@ struct bin_attribute { struct attribute attr; size_t size; void *private; + bool mmap_allocates; struct address_space *(*f_mapping)(void); ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *, char *, loff_t, size_t); -- 2.34.1