From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011025.outbound.protection.outlook.com [40.107.208.25]) (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 6ED06450F2 for ; Thu, 14 May 2026 14:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.25 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778768016; cv=fail; b=pwwM02Nkc4rkjGK0IifzfZ0zoi1rFxOsxJciG+i26x7s/yCdi3yoXXf+TkeVjky5ZyWx00RDI7AnIMP1r98YuKga0iRFzFZmMlm/RnS5UGORY/LUV8Pj2vcmk2JxnjFRxUkx/UBskgDvCRApZjzTlAWBVzhyBZuHftBQf1ltwGY= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778768016; c=relaxed/simple; bh=E8jFkYPcO8kco3TOAFUTdMdKpJT17CdyfTB4hgwq/lo=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=pZeTQ6raD6irt7l4bocAZItxyX+9rCBex8vOkXs5YuzoG4iKTwMxGdQbvAWGHRCBW91IvMCXwQvNGzgnsUEMJwT+RFkGih82bcqB8EP7IMLy9LDL0creyB2B5nCN/zxvQl4VifxNP9t94wD5DbsLXhnOX22/xvAxdqkmqflpSU4= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=AFlCgKMD; arc=fail smtp.client-ip=40.107.208.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="AFlCgKMD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RhUbew6C6vOjTBHA6i64Wjs/IOB/Aq0n9jbJnW+d5TrWcts5BEmXmkjz3aOkOpcG5B9jdE8sNojXnu4/C1xfDsGTfjuIqT8eeuSndD8WJYQpC4aEbIUXbIx36RiXkvp2e5G8P+kL1kT4P+rC9UnEk1xXL1Vf/6lXS5/3J+U2Cs7uoglqQG+CShLlU3DLb/MT+Fo+s+UN43YjHfL87yTY8OpFIi/g6mzNjGm628cPffNzuAfb3Sk5vfT0RBZV9HHN+9fhMVRBpRB+15sKOZj3B2nm2VixkikvtBptO6FNVLWTTyB9VCzAR/scX5xrlg7qbtpNFzJfC09T0ATKrq+fAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=tHKAxINRqfb0peObtD7HjR8gFOJrbuoc2vMZ1ba4rEA=; b=ucpPLikLWOHNjV2PZZXonUcFDzOgFgPf/AQSA0s20P9fmh/KSmJWkkoSxJn6u2+ys5atI4bfF1Jf9D2iCnwOfjQ0xK2tHmPTQrwXqF2uPPFZEMXlNfUEPLb+rS9wvPWGZ6Ba9dekpVuEbS5MoOV0cyG3NO4l8vHF79K3F4Vhya7/InlyvFSrlY1wB1RCtcbwwd2Sl/HQ1NNHE49NMX2zE+J5kafVbF8uO3eSQ75j5UGQ37EFzF4HDz1xXo9V/FNF4XIpJWkjfUiDmBKpAJQ0Dn68tPSRL+74JJPL8Rpl0CzJJ+VUQZOrZp4bMA1IxUXvvxrtyeA4kInzkxIg1Jnn7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tHKAxINRqfb0peObtD7HjR8gFOJrbuoc2vMZ1ba4rEA=; b=AFlCgKMDxrOntFWppmsL46UbjjWd/e8/UOGfLTkFcOJ5AsrF0O6cyRF6JWbblRW9PCaBXgxJ2/u9eqm5B9tnBvDFQsT/VEblC+uMBpHRGNAe8Oa/TgkEBwKSb6FW6J/mByt343v4UmYBZLGmpKjCFvP48FciG2Cb6ocMImQqzKc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from PH8PR12MB7325.namprd12.prod.outlook.com (2603:10b6:510:217::19) by PH7PR12MB6836.namprd12.prod.outlook.com (2603:10b6:510:1b6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9913.11; Thu, 14 May 2026 14:13:23 +0000 Received: from PH8PR12MB7325.namprd12.prod.outlook.com ([fe80::8024:a7ee:b29c:a4fc]) by PH8PR12MB7325.namprd12.prod.outlook.com ([fe80::8024:a7ee:b29c:a4fc%6]) with mapi id 15.21.0025.012; Thu, 14 May 2026 14:13:23 +0000 Message-ID: Date: Thu, 14 May 2026 19:43:17 +0530 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 4/7] sysfs: Add SYSFS_HUGE_BIN_FILE flag for binary attributes larger than PAGE_SIZE To: Greg KH , K Prateek Nayak Cc: Muralidhara M K , ilpo.jarvinen@linux.intel.com, rafael@kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev References: <20260427155129.545327-1-muralidhara.mk@amd.com> <20260427155129.545327-5-muralidhara.mk@amd.com> <2026051214-getaway-mammary-debb@gregkh> <47c6134b-c0ed-44af-b77e-145bfceded74@amd.com> <2026051354-succulent-acting-e006@gregkh> Content-Language: en-US From: "M K, Muralidhara" In-Reply-To: <2026051354-succulent-acting-e006@gregkh> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: MA5P287CA0292.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:221::19) To PH8PR12MB7325.namprd12.prod.outlook.com (2603:10b6:510:217::19) Precedence: bulk X-Mailing-List: driver-core@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR12MB7325:EE_|PH7PR12MB6836:EE_ X-MS-Office365-Filtering-Correlation-Id: f9e54ecb-b1df-4e38-ab05-08deb1c2f57e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|22082099003|18002099003|56012099003|4143699003|11063799003; X-Microsoft-Antispam-Message-Info: SOxS7qlsUHw7BDDE68pu1hagUdDUj5YCDAURuerZQotStvv37FAU41G8+KlmK8VyLuT5NghJ/1xdyJrdM3UpwJjdAo0nC21u8ke7z9UQS6b3/Ak9c6st9aqIdgYCnUl1WDhjbo/y30Tsdnq9MrvcAEuwSBOIxzoyKTOLDQPqUX7BqW0yds1n3pdBZpfAGFF1ejLAJ9gQuqDi53iUkw0Y8WJA5Q3ZSbaoL3X8g6e1tpxnzklx8l1miaKr5wC+GArK0bwsMXL6IZp1ReXnjpVQkhq450NopsvfY/tZsLkc8VZvc9yrvVDsVebdwfdEH7RDbSiLUkjw794XOU4IWuIZKZGacYz0U77QqaJ4v3rfh5c4u32w9unxRI4xRSiG0bOFuTDOPnBKg+54ivk85mnNGJ3Sa+j7twwB1J5o8l70qBJHNHe85FzgIvTzVCzz0k6ZPGTJ8Ze/W+X6PY8bgMpcXy9HX23u7CTKaK/SBWd2hQiUtN7LN2Uq8ec3dn1a6GqssiukDKOnGcvHOQFV6s20WawFpOPrpkyUQ5+thpRWB0WuGFOMfGkG1YOgGMWOs7nUvlXqv47/+HLJ0xLM3hnh4tK+viNYcMAPVEwkN5iGQ90WgVWG0HaOPqi3HUOuj1e5LVADtuRRVCYBC+t8g9UWSps4ogPhR1hqk7B5F137y3/s2jbm4aZXKRL3WrRqTI/x X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR12MB7325.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016)(22082099003)(18002099003)(56012099003)(4143699003)(11063799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?cFJkM21xM3g2MUF4MGpraksvZmE2aUNyVXJBa3gwem9zRG5wTkVLYmpIWU5s?= =?utf-8?B?R3RCU1pMckU5TXVVaG9mY3dGVzZGNTQybDlCNWhjRnVQQVNEdEtTSHVtWUlx?= =?utf-8?B?V2dJUzR4V3lMSW9JT1lpTThyV3BnUUcyUEx1YmhKdmpPeWNqVlNuRW5lZW9I?= =?utf-8?B?S3M0K1ZvSnVQZHAxK0VBWnVYa1dQSnFLbWJ1N2RzSDBVS1ZpQWp5eGZkN2g0?= =?utf-8?B?L0ErSlBLWXFLTEJWM3lEYW0zajg5OFZ6clA2ZUxHL1pKQ3ZsZnBVZmgvdWZa?= =?utf-8?B?Sm5HY1lWTUhybGtEUU9XMnl1UnBXdEVMQ1ZkdW90aUtGQWlhUHBRMkJOSTR6?= =?utf-8?B?ZHpCL1RzcUlLNUlhMmJXVTIwcmtPZDVhNjhnaFJxQXVXbkl5b0NvRmRveENH?= =?utf-8?B?SHl1RXB6K2RyOEg3RjVSalVpT2ZLUGJiM3lzc0hMYUZZVmxYeXI0T0lnTHU4?= =?utf-8?B?TzVXSXNhVElldHFNMXI2TUJtODRRe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f-8?B?OUVpWXJSWEZUb05aMmU2cHloQ000b25jZldoeDA5OWF3NG1xb0FrUT09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f9e54ecb-b1df-4e38-ab05-08deb1c2f57e X-MS-Exchange-CrossTenant-AuthSource: PH8PR12MB7325.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2026 14:13:23.7474 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PTqKY3LZ17z95FABAbd1izoFme8e7Pna4XxXT9BLjPrJ4di362LYcizu8iOKMfZ/aWphmxIWwVpNcztLrEuGjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6836 On 5/13/2026 11:54 AM, Greg KH wrote: > Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. > > > On Wed, May 13, 2026 at 09:43:57AM +0530, K Prateek Nayak wrote: >> Hello Greg, >> >> On 5/12/2026 5:31 PM, Greg KH wrote: >>> On Mon, Apr 27, 2026 at 09:21:26PM +0530, Muralidhara M K wrote: >>>> Historically, sysfs read buffers were allocated with get_zeroed_page(), >>>> limiting reads to PAGE_SIZE. Commit 13c589d5b0ac ("sysfs: use seq_file >>>> when reading regular files") transitioned regular (text) attribute reads >>>> to seq_file, which can dynamically grow buffers beyond PAGE_SIZE. >>>> However, the PAGE_SIZE limit was intentionally preserved for >>>> compatibility. When binary attribute handling was later unified into >>>> the same codebase, the non-seq_file read path (kernfs_file_read_iter) >>>> retained this PAGE_SIZE cap for binary files as well. >>>> >>>> Drivers that expose binary attributes larger than PAGE_SIZE — such as >>>> the AMD HSMP metric table (~13 KB) — cannot deliver the full content >>>> in a single read() call through the existing path. >>> >>> That's fine, userspace must be able to handle a "short" read, and will >>> just continue on and read everything afterward, right? You can't rely >>> on userspace always asking for more data. >> >> I think this is complicated by the HSMP driver bits that requires the >> read to issue a HSMP command to the hardware first to updates the >> table before copying from the MMIO region. > > Then you have bigger problems here :( > >> If a concurrent reader arrives, they'll refresh the table for their >> PAGE_SIZE chunk read and the prior user will see a torn value. For >> most part it shouldn't be a problem but folks try to co-relate the >> Temperature and Power data from the first chunk with the Throttle >> Indicators in the second chunk and sometimes, they don't match the >> expectations. > > Again, this is a problem, perhaps do not use sysfs for this? You can't > control userspace, and to expect it to always work properly is not going > to end well. This change isn't going to fix your problems listed above > at all. > >> The table should never have grown this big but some folks decided it >> was a good idea and we can't fix it for a while and have hit the >> PAGE_SIZE limit now. > > Just delete it and use a different interface to the kernel instead > please. If you need atomic read/writes, use an ioctl. Don't try to fix > sysfs into something that it was not designed for at all. > Thank you for the suggestion, Greg. The IOCTL interface approach works well. I'll implement this, test and send the next version for review. >> If there is a better alternate, we are all ears, and more than happy >> to try out an alternative suggestion for the described problem. > > A misc device sounds like the properly solution. > >>>> Introduce a new opt-in flag SYSFS_HUGE_BIN_FILE (040000) that drivers >>>> can OR into their bin_attribute mode. When set, sysfs selects a new >>>> kernfs_ops (sysfs_bin_kfops_huge_file_ro) whose .seq_show callback >>>> pipes the bin_attribute ->read() result through seq_file, allowing >>>> reads of arbitrary size in one shot. Existing binary attributes >>>> without the flag continue using the legacy capped path. >>> >>> If this is such a big issue, why not just do it always for binary files? >>> What is the benefit of keeping two different code paths just for this >>> "new" flag? >> >> We can do that! For bin attributes that specify .size or a size >> function, we can use a flexible buffer and for the ones that don't, we >> can enforce a PAGE_SIZE cap like today. >> >> Would that be okay? > > Overall, yes, but again, I don't think this is going to fix your > problem. > > thanks, > > greg k-h