From patchwork Wed May 3 18:38:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 679070 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F360C77B78 for ; Wed, 3 May 2023 18:40:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230019AbjECSka (ORCPT ); Wed, 3 May 2023 14:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229816AbjECSkQ (ORCPT ); Wed, 3 May 2023 14:40:16 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01FB972B2; Wed, 3 May 2023 11:40:11 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343Hov9l000710; Wed, 3 May 2023 18:39:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=gHtHW+WeteJIlgj4ex5EPdvIGvjZ35NFrZOauH7vYkQ=; b=IfxaRcA0eZOIKYbGdRRZQngHUnao7rOOh039rXVbwl7dlm6n+5svHEg0IMpAkcEng9U0 cosx7HJbmds7Y52bIr9wd+b+iBRIli5jUZbfYG068lQpOrak8SnZhZWUlcJtYNpGkAtM cCv2LNRqueWWLjQ568TRa8I6LvsmRNteiH5Uh8f6zCd2Zk1d/LDjmIh5MSxcNvUFjbrn sIl/Ly+wP95BNIDpiqM7crlJoIMahAU23L4KOM+oHPsb7DV/awQleZiGLiaWw1eNrdS0 zj4NsuaGUsC7qnnn+GcMXuDFgxKXfz8NQ/NhXDA20aB592mfvFgvLzKWrN0KmeV65rq2 7w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8usv0181-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:40 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343Hsbt8020802; Wed, 3 May 2023 18:39:39 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2171.outbound.protection.outlook.com [104.47.59.171]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp7g9r0-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k+ETxxoL8csbeywetRr1epfwDnQJXoYXwVKKt77+L2ctWT221q/Mfp5TUzrh4BwldaaUOu/ws1KGfwA3TAI7bQCZLzhJN8jvdDZMgqX02kLrXyYCW2TMl3Ca6Wku5z7VZMwquvVb0inQQFKJsDivQKovUTbM/Uux7eWyqydveBPI8w3I6RyBchBKOGkMrgqI593qtcNuD/gVMyNkg5NYMxIjDS9FPJsCcuFoRbFm8IppZyArdf/7Nk0lQMYV1+GZZLUqXI1qlxRDD4Yg38oz8ZAeQ8LhFB5EWcNZUIX1ABUnZauBv1eLsYq+6bIO2pGWZ2y3Bw2qI568BZWkjJp0Bw== 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=gHtHW+WeteJIlgj4ex5EPdvIGvjZ35NFrZOauH7vYkQ=; b=GnH9XzlHWDJxxnjPoMrX/F5FgWX1B5huBn3vR6ICb50kxsInFOPIfOFhMAq1DXCIhQhWduHWWwGc4/9qXyjQDf7u9s079gl+dlWUoAKL/061gzRfsoeiJjJysH98F925a/b00V8keAFpqklPczRWvJvle4IA8YgqJVGSHKrY8X5Zxu4/yEmyxkvBEU4BezjQ4vGMjNkwEjBiRPaElpAN06aJw7tolZGVBvCOU3ThxpMURi5kzD2RSHyhYNJRK4AhB0qp6Z9ApWIX8jHjM7C8B1wFXiqLOt0Zkm+yT6hzqkaOVasueklfoFB3pwU8wjXB7gpnxe26KaxK1zTd3xoH5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gHtHW+WeteJIlgj4ex5EPdvIGvjZ35NFrZOauH7vYkQ=; b=Br32S/FIEoTH4q2ht7GYg7oGK220kLQzz0dzeF2Ow8S+UsnnAtR77uMDJGhvFHuxMeRYaRjjMGTvxafaB0SMTMGuGXurERWmLbCvBnIe5qkejZQk07OqFRW74DKUSRn4JGmzZBJNe8/pWnp0lNYRc2RNaYQEuU0iLQtc0DLhVrY= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by IA1PR10MB6171.namprd10.prod.outlook.com (2603:10b6:208:3a5::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.22; Wed, 3 May 2023 18:39:37 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::8456:ba59:80ec:d804]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::8456:ba59:80ec:d804%7]) with mapi id 15.20.6340.031; Wed, 3 May 2023 18:39:37 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jejb@linux.ibm.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, John Garry Subject: [PATCH RFC 07/16] block: Add bdev_find_max_atomic_write_alignment() Date: Wed, 3 May 2023 18:38:12 +0000 Message-Id: <20230503183821.1473305-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230503183821.1473305-1-john.g.garry@oracle.com> References: <20230503183821.1473305-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR10CA0014.namprd10.prod.outlook.com (2603:10b6:5:60::27) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|IA1PR10MB6171:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b6cbf23-da9f-4a2b-c71f-08db4c05bf5a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pUCHT0D961ajXUprjinzOtqpAieZfG9tyngLvyn8XLT3jStVvmXmpiKOI6FMZkZp01VkMKr+PAwAixccKM/+CTl5f9xs7Og3tSkTGgumQIay5/WLMYFY8DRmtUE6nuE0ThrJMfNMX1LZwmMNqhKL2pOm5nSmkZHI8zWWRyW+9fJvHxxy2MT6SN1t7Y+7ZoErut/ccmZRIuKISKwH84GIVdQX+/PHLi/x/nrYFGIHnNrpVWdqiRc4uCKqQifiR+qa3JBYaAxzK8MK1GyZ51SiKa60ESmWQTLiL81T0PLIXUT1NLeYfiKQWJOY/KwhR5eeS/ZtcBLT385fOu5P+OYoGLDLIK7/GjFZAbayhVeacbbfB60xfyqax5R9HpOicLcIZGiGxC9cnG+Uo52rJgTV9ox4A8a/gZciEVEpW6EOO69QGiYMhsuwlbpaTdztx/NZxdOn8IifEJqJKZh0/RsE1Ug8fp1nRXIAqqiY2jP+336ko/3+iAUSvDXLM0GC6jJ5nyhqNlmrLPwUcRBX5MK1ekMFYLUwJRY5L5/LW7zGkrvDjUXYhAV78mQZ9TpC+pKqOUFzc05Zfw2L/o52gk/uKeYsKQcy9nhxeGnPugaq8wE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB4313.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(346002)(136003)(376002)(396003)(39860400002)(366004)(451199021)(2616005)(186003)(4326008)(103116003)(921005)(36756003)(38100700002)(83380400001)(66556008)(7416002)(66476007)(86362001)(41300700001)(8676002)(2906002)(107886003)(5660300002)(6666004)(478600001)(8936002)(6486002)(6506007)(316002)(26005)(6512007)(1076003)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YTAnYK72ellEkFpSkF5jjjtmXcUtGuzTuddaohnCHbi3MGDYSSURjt6jcYEeuWCqeIu9Gq0NVxjKs6KhFYV9X8WFba/n2ZEDyX2jaNJKVz/4LE0x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j5zERbiy9iuWqC5dPNuzLUI3jJny+NhvtCfnqHB0+2l9lanZSf73BWuW1OEsMGCyzFByiOEaGaqpKceSvMDZ8tuc2UDTgrRYsEOXWRHVA4UQpNsaWtEBZJfwZ+C+4DIQdSsWJiUzSHjT+BWsKHSnU5l4R/ZaOHk4mZQ2nKC8jc6xUOFEbKtanhl6C4e4nRjjdPfGJrHomsgFkmuuf4JfvB3ZACMHH4QEandJNnp3Z+xM3hLsOO6KpBrbKdPTOfHXF9x1HlQL0Mn+5eNXVIcods1F2zcotqsD5n0Yh/Xok1lCcBljplfMSQU0Z7ELYdY7uJTVyYHpBp4XJNil3MN0qQWoCRBhn/BExNZIhZVd63g4RAlSoZS6i1Z3j8Ec3Rt+9i/807xeFHDP2xk8tcr/aUCXEZsL/eegA4i4/UAq2J39CzJhjLkCzO9OEraTy8Xvwp6axeImQiEJHzqOBJESyBWkca+b275GmITZvgSWkGrp8n4wv3pQDGJ0txy6457a3TvQJUs7vws+vldURlfd1CYDbdyWNfgHgdJ7ZIPCQ X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b6cbf23-da9f-4a2b-c71f-08db4c05bf5a X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 18:39:37.3242 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Cb/jAGYKV/fxepLOOkOZLK+MJ6n979X6iBV1O/i0WqNDYE6B49Mf+lLbDjQk49GBp2xqPM6GHAgHwAHRa8Dskg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB6171 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_13,2023-05-03_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-ORIG-GUID: ilWJuQGNZW_kcmJvPVFEtRAR-7nNxk_f X-Proofpoint-GUID: ilWJuQGNZW_kcmJvPVFEtRAR-7nNxk_f Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to find the max alignment of an atomic write for a bdev when provided with an offset and length. We should be able to optimise this function later, most especially since the values involved are powers-of-2. Signed-off-by: John Garry --- block/bdev.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 9 +++++++++ 2 files changed, 48 insertions(+) diff --git a/block/bdev.c b/block/bdev.c index 6a5fd5abaadc..3373f0d5cad9 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -46,6 +46,45 @@ struct block_device *I_BDEV(struct inode *inode) } EXPORT_SYMBOL(I_BDEV); +unsigned int bdev_find_max_atomic_write_alignment(struct block_device *bdev, + loff_t pos, unsigned int len) +{ + struct request_queue *bd_queue = bdev->bd_queue; + struct queue_limits *limits = &bd_queue->limits; + unsigned int atomic_write_unit_min = limits->atomic_write_unit_min; + unsigned int atomic_write_unit_max = limits->atomic_write_unit_max; + unsigned int max_align; + + pos /= SECTOR_SIZE; + len /= SECTOR_SIZE; + + max_align = min_not_zero(len, atomic_write_unit_max); + + if (len <= 1) + return atomic_write_unit_min * SECTOR_SIZE; + + max_align = rounddown_pow_of_two(max_align); + while (1) { + unsigned int mod1, mod2; + + if (max_align == 0) + return atomic_write_unit_min * SECTOR_SIZE; + + /* This should not happen */ + if (!is_power_of_2(max_align)) + goto end; + + mod1 = len % max_align; + mod2 = pos % max_align; + if (!mod1 && !mod2) + break; +end: + max_align /= 2; + } + + return max_align * SECTOR_SIZE; +} + static void bdev_write_inode(struct block_device *bdev) { struct inode *inode = bdev->bd_inode; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 19d33b2897b2..96138550928c 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1529,6 +1529,8 @@ void sync_bdevs(bool wait); void bdev_statx_dioalign(struct inode *inode, struct kstat *stat); void bdev_statx_atomic(struct inode *inode, struct kstat *stat); void printk_all_partitions(void); +unsigned int bdev_find_max_atomic_write_alignment(struct block_device *bdev, + loff_t pos, unsigned int len); #else static inline void invalidate_bdev(struct block_device *bdev) { @@ -1553,6 +1555,13 @@ static inline void bdev_statx_atomic(struct inode *inode, struct kstat *stat) static inline void printk_all_partitions(void) { } +static inline unsigned int bdev_find_max_atomic_write_alignment( + struct block_device *bdev, + loff_t pos, unsigned int len) +{ + return 0; +} + #endif /* CONFIG_BLOCK */ int fsync_bdev(struct block_device *bdev);