From patchwork Wed May 3 18:38:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230463 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 C3552C77B7F for ; Wed, 3 May 2023 18:40:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229803AbjECSkm (ORCPT ); Wed, 3 May 2023 14:40:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229900AbjECSk3 (ORCPT ); Wed, 3 May 2023 14:40:29 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA1237A85; Wed, 3 May 2023 11:40:14 -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 343Howef000742; Wed, 3 May 2023 18:39:32 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=AQvDg1liQbNOtuYUZl4IaQQMOjhe/UlgPCUM5z64+z4=; b=N0caaX22K3+PVDb9bbTCfmDP7XlCiJU4cEbQVXzaT/Wgbydq+o3FIxX2N4fWuLXl9e+H e7vutHiTlIe4pPkd7swYJhEzGYw1nvrOMOEvjs7CazFh9vubejp/pE7JUR48cRAuigYw I3lwHKnrkwztsM4fZO4oG4toQTtkwRe+29UhHMLIcV1V+CqaS1Y3SjfjOoD8z0jwNq3Z X5wrMJqcv+gr5VPcvrkS4UB2Ym0CjqDvqpM0rS06dKcq3VxhIE9E8y4smU7KOtTjEjnl XOjYyVOA1wcoDpjUyoe5wUXjr8ah8dGM534c3bAcaJSEvubSxUrMdwgPOSK5ASTLgOHm LQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8usv017t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:32 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343HSegC009977; Wed, 3 May 2023 18:39:31 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2045.outbound.protection.outlook.com [104.47.66.45]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp805ch-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R6wvXOaWlIosgzyJkzsd6UsbrZ/lI4fT6X8/Gw5nqxdT3OQ0WMLnL6tp2B9QpZm7P0vasHUuL0nQyxFT8Vw360isHBd0MOULt3ONc15UuM4McSOAR93ZO0tmLH33R2qFgue1h4ypqqWyAkb8Iw4TkXkk9QprkHIYIw9NGq2VcCz5iZng1U2L201dJdBqhVT+5S73LtNv7iXppVi5K6y9oJ3Dsm7bcU5HbaVGvqom+a7b2MWTheQQ4YnoSK7xawyYPjShMqHPXRqI9Zep4zzCmK0i5P1QgnwJYqY0ej3Mz3U4cxZDcMxNOu3gj5J6VU7zcWYh9m8MMPlr0d3XBa14bw== 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=AQvDg1liQbNOtuYUZl4IaQQMOjhe/UlgPCUM5z64+z4=; b=aWbdOXyH60FctabYFIZ9MOUjfxlmnaDxKz4PIgi7L3+SqseyGMXbExmsiwrb+wPSTbkljSF1+eg83JSoHN7V+d0I+BbqZGntZGxgiFQjSGHL04Hnf7rm/sQ5kP1kjGweFdon5FDNKeOE+goB61VjKTq/dz26j4hMpplZHgCdIjF8qivUCjTlXEbhbNbvtICmTugTdVKj0FPh4uqOPl5b696NfChc3snnWu6xGHCs3WMjmjsyArr0z+fW4VJicvurn/vF9l7qIIOb7lFwpZO5Uf8JP4olUrIOj8zsiG/bkS+GWzyFrbHMSR6TNykKl+ng3u/c+E5qnZ3Wr3I9NaBwug== 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=AQvDg1liQbNOtuYUZl4IaQQMOjhe/UlgPCUM5z64+z4=; b=KPGVUwtLogpeBjbCe8WYa2fKgH2iTEO9M8P8EHp7QrnnrHGcXLoERvDdjvX4rqGrzHoBMu16EcKZSltSaczfQvsRTwQA0pvjNyleMQgMpgIQk2z4UXqGGuRafHf78U0YVa+MtSl+3VODQ+cghdsH1/pzlYoUcB9TamtYJVnJ9+U= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB5677.namprd10.prod.outlook.com (2603:10b6:303:18b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 18:39:29 +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:29 +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, Himanshu Madhani , John Garry Subject: [PATCH RFC 01/16] block: Add atomic write operations to request_queue limits Date: Wed, 3 May 2023 18:38:06 +0000 Message-Id: <20230503183821.1473305-2-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: LO4P265CA0159.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c7::9) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB5677:EE_ X-MS-Office365-Filtering-Correlation-Id: e1c5b909-9843-47f8-a187-08db4c05ba47 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OkFv0iPlU7XDHKcW7YN6dVKZhGW1nag2lNVtoNuaJ/fvoOUU16sz8YM8Hca6/5ikep5eRZv3ZL1fRUG7HYJoMq9nrVTnQOeTcm+B+6SbmEOba16mSfxeVRcJ0CKcxivtWBrRIHDm2oxZcUzzauF/aV/o7kwwh0o5MsKBeGe2zu+2dbXbgPkpZfvMhhJyM03Rxu5jiWd9QFWRgUt+RmsBEx8se5GqwjNmam7ozLVMdC33l19N6RwWrLLHU5hf+Pf7Gkuwj8ITK4BpYTVcb8wfxWpmQx7wzHvzG3Iu+biLPfICjVJHRH42wQL+agpyB+RFJyKflgbB0C6G1BrxYSilLeH+iXBo6MKlhfurmzSCBtG0dLRfiTMI6kex7KbJrVvPZfV9I0FOcEa5cvV3xsNMMioBeJXu8uiIA6pBrZMu3USBs+cEfy3y5hXWmpRyGfT9jnXxjbB/6Z0ix/nG+ks2onIsRti5ICSWD9E2tFLYvXpdZuyBzYzVjkz41D9tEu674f7A6hoUFKckung16kMTyN3015LkkZxcK3EK0+GLSeQfkRfB8HL95gm1xZJpWi3NVXHv2Zs6wcRw/nH+VHSXeaLqJ4tZre6cxScimFsQ3wc= 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)(376002)(366004)(396003)(39860400002)(136003)(451199021)(2616005)(6506007)(1076003)(107886003)(6512007)(26005)(41300700001)(38100700002)(6666004)(83380400001)(186003)(6486002)(478600001)(54906003)(66556008)(921005)(4326008)(316002)(66476007)(5660300002)(66946007)(2906002)(7416002)(8676002)(36756003)(86362001)(103116003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zgXp/2vZaUzJDJSZU76KLXptBRHgM/UWwId6dFZoFxJKRHwj7sb+WOoKazn0FyAJAXP4k02EXFdLRn0n6cVj1+kQB6Xu90di5plT7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rnV/pVDHpnr1Wy/vdABeyymSs2ONsDAS+FQt/lcEPOYIjSrG6PmQPqO5GpF9LbE+0+ynR2c4TvBrmRZt0T3j1W1+NhI3TjE5pKHMmQ4K0L/wNSPLtXyO2jK3BV6D5s9FPVlaIlyPhTFAhRQ3IeL7IMWrEdr2tq1hfY1h4JKPWFESLXSRIY9F/E8BOKoDJvbA+tCgWIqq69dZqexTMG/V0kYqcaqvBSvEAtKg5QgfJBtfTdonU34opsgAg5CyYxZz4w4s08rvIJVODpgeO8V18pkPKZkQ6p09kYfaNTEG+gU18ILSlNHDhzr1JDA/g1iTbQKycKWvULhNtEEyfuFAZx/z++Xsx0N3ZaQc5CNi9F62NU5imtDQhWFDxxEssWJo3zH+jJvj8oH8jCWeT3Mbss76jqcO3uwrYbVK4E85IAAMvDv0oqtu6RRZxFT1YSEL7QsoEEshobfW+BgW4zHphn9hcJhZaVDNPNmluXf5C03SryrdobmAND5nImt8Ryoa7yzQr4Ed19mM4MGV7a7DVkPcPGWDT+nZMcjEiqB2TrGsSVOVYGI6X3T9unVATiHAcmyH5mQ7BnU9XWNtGxgEY1nnc/oHvTw X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1c5b909-9843-47f8-a187-08db4c05ba47 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:28.9082 (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: zwpIBmjXhT5Z69Mz9kOIDaNUoO8fnsAKB/928zTy1hBdFtpZ6tbBBlFdi9fFxi2shPXTscaqvxLpDCX/gFmapA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB5677 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 adultscore=0 phishscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-ORIG-GUID: p7XqqkWTccMA7iPMXgI6LSfRrlJFliuW X-Proofpoint-GUID: p7XqqkWTccMA7iPMXgI6LSfRrlJFliuW Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Himanshu Madhani Add the following limits: - atomic_write_boundary - atomic_write_max_bytes - atomic_write_unit_max - atomic_write_unit_min Signed-off-by: Himanshu Madhani Signed-off-by: John Garry --- Documentation/ABI/stable/sysfs-block | 42 +++++++++++++++++++++ block/blk-settings.c | 56 ++++++++++++++++++++++++++++ block/blk-sysfs.c | 33 ++++++++++++++++ include/linux/blkdev.h | 23 ++++++++++++ 4 files changed, 154 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index 282de3680367..f3ed9890e03b 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -21,6 +21,48 @@ Description: device is offset from the internal allocation unit's natural alignment. +What: /sys/block//atomic_write_max_bytes +Date: May 2023 +Contact: Himanshu Madhani +Description: + [RO] This parameter specifies the maximum atomic write + size reported by the device. An atomic write operation + must not exceed this number of bytes. + + +What: /sys/block//atomic_write_unit_min +Date: May 2023 +Contact: Himanshu Madhani +Description: + [RO] This parameter specifies the smallest block which can + be written atomically with an atomic write operation. All + atomic write operations must begin at a + atomic_write_unit_min boundary and must be multiples of + atomic_write_unit_min. This value must be a power-of-two. + + +What: /sys/block//atomic_write_unit_max +Date: January 2023 +Contact: Himanshu Madhani +Description: + [RO] This parameter defines the largest block which can be + written atomically with an atomic write operation. This + value must be a multiple of atomic_write_unit_min and must + be a power-of-two. + + +What: /sys/block//atomic_write_boundary +Date: May 2023 +Contact: Himanshu Madhani +Description: + [RO] A device may need to internally split I/Os which + straddle a given logical block address boundary. In that + case a single atomic write operation will be processed as + one of more sub-operations which each complete atomically. + This parameter specifies the size in bytes of the atomic + boundary if one is reported by the device. This value must + be a power-of-two. + What: /sys/block//diskseq Date: February 2021 diff --git a/block/blk-settings.c b/block/blk-settings.c index 896b4654ab00..e21731715a12 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -59,6 +59,9 @@ void blk_set_default_limits(struct queue_limits *lim) lim->zoned = BLK_ZONED_NONE; lim->zone_write_granularity = 0; lim->dma_alignment = 511; + lim->atomic_write_unit_min = lim->atomic_write_unit_max = 1; + lim->atomic_write_max_bytes = 512; + lim->atomic_write_boundary = 0; } /** @@ -183,6 +186,59 @@ void blk_queue_max_discard_sectors(struct request_queue *q, } EXPORT_SYMBOL(blk_queue_max_discard_sectors); +/** + * blk_queue_atomic_write_max_bytes - set max bytes supported by + * the device for atomic write operations. + * @q: the request queue for the device + * @size: maximum bytes supported + */ +void blk_queue_atomic_write_max_bytes(struct request_queue *q, + unsigned int size) +{ + q->limits.atomic_write_max_bytes = size; +} +EXPORT_SYMBOL(blk_queue_atomic_write_max_bytes); + +/** + * blk_queue_atomic_write_boundary - Device's logical block address space + * which an atomic write should not cross. + * @q: the request queue for the device + * @size: size in bytes. Must be a power-of-two. + */ +void blk_queue_atomic_write_boundary(struct request_queue *q, + unsigned int size) +{ + q->limits.atomic_write_boundary = size; +} +EXPORT_SYMBOL(blk_queue_atomic_write_boundary); + +/** + * blk_queue_atomic_write_unit_min - smallest unit that can be written + * atomically to the device. + * @q: the request queue for the device + * @sectors: must be a power-of-two. + */ +void blk_queue_atomic_write_unit_min(struct request_queue *q, + unsigned int sectors) +{ + q->limits.atomic_write_unit_min = sectors; +} +EXPORT_SYMBOL(blk_queue_atomic_write_unit_min); + +/* + * blk_queue_atomic_write_unit_max - largest unit that can be written + * atomically to the device. + * @q: the reqeust queue for the device + * @sectors: must be a power-of-two. + */ +void blk_queue_atomic_write_unit_max(struct request_queue *q, + unsigned int sectors) +{ + struct queue_limits *limits = &q->limits; + limits->atomic_write_unit_max = sectors; +} +EXPORT_SYMBOL(blk_queue_atomic_write_unit_max); + /** * blk_queue_max_secure_erase_sectors - set max sectors for a secure erase * @q: the request queue for the device diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index f1fce1c7fa44..1025beff2281 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -132,6 +132,30 @@ static ssize_t queue_max_discard_segments_show(struct request_queue *q, return queue_var_show(queue_max_discard_segments(q), page); } +static ssize_t queue_atomic_write_max_bytes_show(struct request_queue *q, + char *page) +{ + return queue_var_show(q->limits.atomic_write_max_bytes, page); +} + +static ssize_t queue_atomic_write_boundary_show(struct request_queue *q, + char *page) +{ + return queue_var_show(q->limits.atomic_write_boundary, page); +} + +static ssize_t queue_atomic_write_unit_min_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_unit_min(q), page); +} + +static ssize_t queue_atomic_write_unit_max_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_unit_max(q), page); +} + static ssize_t queue_max_integrity_segments_show(struct request_queue *q, char *page) { return queue_var_show(q->limits.max_integrity_segments, page); @@ -604,6 +628,11 @@ QUEUE_RO_ENTRY(queue_discard_max_hw, "discard_max_hw_bytes"); QUEUE_RW_ENTRY(queue_discard_max, "discard_max_bytes"); QUEUE_RO_ENTRY(queue_discard_zeroes_data, "discard_zeroes_data"); +QUEUE_RO_ENTRY(queue_atomic_write_max_bytes, "atomic_write_max_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_boundary, "atomic_write_boundary"); +QUEUE_RO_ENTRY(queue_atomic_write_unit_max, "atomic_write_unit_max"); +QUEUE_RO_ENTRY(queue_atomic_write_unit_min, "atomic_write_unit_min"); + QUEUE_RO_ENTRY(queue_write_same_max, "write_same_max_bytes"); QUEUE_RO_ENTRY(queue_write_zeroes_max, "write_zeroes_max_bytes"); QUEUE_RO_ENTRY(queue_zone_append_max, "zone_append_max_bytes"); @@ -661,6 +690,10 @@ static struct attribute *queue_attrs[] = { &queue_discard_max_entry.attr, &queue_discard_max_hw_entry.attr, &queue_discard_zeroes_data_entry.attr, + &queue_atomic_write_max_bytes_entry.attr, + &queue_atomic_write_boundary_entry.attr, + &queue_atomic_write_unit_min_entry.attr, + &queue_atomic_write_unit_max_entry.attr, &queue_write_same_max_entry.attr, &queue_write_zeroes_max_entry.attr, &queue_zone_append_max_entry.attr, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 941304f17492..6b6f2992338c 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -304,6 +304,11 @@ struct queue_limits { unsigned int discard_alignment; unsigned int zone_write_granularity; + unsigned int atomic_write_boundary; + unsigned int atomic_write_max_bytes; + unsigned int atomic_write_unit_min; + unsigned int atomic_write_unit_max; + unsigned short max_segments; unsigned short max_integrity_segments; unsigned short max_discard_segments; @@ -929,6 +934,14 @@ void blk_queue_zone_write_granularity(struct request_queue *q, unsigned int size); extern void blk_queue_alignment_offset(struct request_queue *q, unsigned int alignment); +extern void blk_queue_atomic_write_max_bytes(struct request_queue *q, + unsigned int size); +extern void blk_queue_atomic_write_unit_max(struct request_queue *q, + unsigned int sectors); +extern void blk_queue_atomic_write_unit_min(struct request_queue *q, + unsigned int sectors); +extern void blk_queue_atomic_write_boundary(struct request_queue *q, + unsigned int size); void disk_update_readahead(struct gendisk *disk); extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min); extern void blk_queue_io_min(struct request_queue *q, unsigned int min); @@ -1331,6 +1344,16 @@ static inline int queue_dma_alignment(const struct request_queue *q) return q ? q->limits.dma_alignment : 511; } +static inline unsigned int queue_atomic_write_unit_max(const struct request_queue *q) +{ + return q->limits.atomic_write_unit_max << SECTOR_SHIFT; +} + +static inline unsigned int queue_atomic_write_unit_min(const struct request_queue *q) +{ + return q->limits.atomic_write_unit_min << SECTOR_SHIFT; +} + static inline unsigned int bdev_dma_alignment(struct block_device *bdev) { return queue_dma_alignment(bdev_get_queue(bdev)); From patchwork Wed May 3 18:38:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230458 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 1E6FFC7EE21 for ; Wed, 3 May 2023 18:40:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229864AbjECSk2 (ORCPT ); Wed, 3 May 2023 14:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbjECSkQ (ORCPT ); Wed, 3 May 2023 14:40:16 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4C92526B; Wed, 3 May 2023 11:40:11 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HpCg3009519; Wed, 3 May 2023 18:39:34 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=XgtMElOSqEBdxUjAqAlOSvt9wkZcvJU1MNOymN72JhE=; b=VGwv5DVAs/nHpIVn3wrddsQEx/URi04m1kuU7e3UkXSfa368QFyuPlxnoxRQyCMsxS5h 623WQ+zuSvl3yTYUYN8t0nU8k9wZsAItQkB4ct6cvhCfXWvTRRWyWHrWihtXr1d/d9Ls G9IiRu7Y/JHhjY9dcnxxByQgJotdrTW8Y5xxbPp0yGZecgWjKXjwJvjK6YAgcnqBdy2L GeOE73nfybfH0iYZfFuSmYwAvZqRlmAl/D00hFReF0Jg84DLxr1HyL0wJkR4MMSAybXE dikdaVt2DwQ7l/eOei7LCfW/dtIvv857rcM8mmfcft8pT9lVmFg4AFgqkrmO/DilwFs5 oA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qburg869n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:34 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343HXUgp027022; Wed, 3 May 2023 18:39:33 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2170.outbound.protection.outlook.com [104.47.59.170]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8spdscfj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CR0ET8K4DMfkD2B7JhETag5SIWHDSaMNLgUJ/5OnMuuIAFxY3hSks2FLZ1WURrK1O94g6krNJFCeJMPFQ5z+XQXqVg52HjdWjpc7bRJY5OxQMYGqwjxL3FN66H31vDQSPZ69b6tnHbuwDREMErFdUFTWGWdRz8d3Esyu7raHbbDKP7o4ZGMUdfpo87itLcNKkeEFEHoXoHaMx32/IkJD7LL1a0XmtjqStqPzem4WZ0dWxr78pgosGf/kX/uHZC9q66cqabH+/w3Y+fCNa6YSV/UvieiwEqllDsAU6l4LVaq6MaxNL9qcH/Kn8/4M3dbXf45723vVK1OD4wxc4P/n3g== 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=XgtMElOSqEBdxUjAqAlOSvt9wkZcvJU1MNOymN72JhE=; b=ZmdB4PnVJwFo1/H00FCovyS4O25bumQ1Y+q6+iuiEB7R0Dg8OYch4/ohgpezGKttWZhhmK53HVDiPw4qDYr+Dl2qZZgEXJLuf+QRpdbSCqH+rHvz+SRBOY4MqBeb/nLH1BR3KYBelnPp+arYxGRod1U2D1dq/AiwJTKorcRK0KPqMicN/dYAZgATQbTMREyiJB/M9w5Yx+7W6zXZy2sfuiNkIZbtrFltwgqz49RCRfYI6VKH2qH6oSA7IIw0BizsfPVvHigS9NT34GVVjmqZiGxPJ0RLWobwsCDN9yNNIhWiOUNMcElx0Xzwwzr0JMPHXw4MvpXWOIy/eP8DnzXQnw== 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=XgtMElOSqEBdxUjAqAlOSvt9wkZcvJU1MNOymN72JhE=; b=0KuYzJItN3zCN80yRcGIkzQ5C5T2BqDC14/vKNQGQ0nkg3WcF+xsGKJ1/2iFf6bflsFBFoTqZMrS0lzF4UPRCCMR/BT3ACOX26c3Ikp/vWiFMgiSgcbaJuzGeHB5uocE0p92691W5MKOrPJbAYUhIxfBRQ0BZlu1HWEoUeot11w= 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:31 +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:31 +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, Prasad Singamsetty , John Garry Subject: [PATCH RFC 02/16] fs/bdev: Add atomic write support info to statx Date: Wed, 3 May 2023 18:38:07 +0000 Message-Id: <20230503183821.1473305-3-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: DS7PR05CA0106.namprd05.prod.outlook.com (2603:10b6:8:56::24) 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: 77e0a29a-5755-4916-9500-08db4c05bb90 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: msn8JTpMI37mPGavQkmuzfKtLe/ErSM82GOEjNtQw6DSA5n5Jj1OLLN7IAATHjvS7gJksV7K1P2jb5nPjSoVAqZoKlT6Z77jM8SSqH5sVYGIZ1Ikwi1T5j7draf5YS3mE1VHDRK7omjxr+2E8gDXdVe0EVcTyGrKbWPJb9KAC9L9Dge+wwyM6UZ88+AzIXsyjdJLzmQPt9p388cST59ap0T2IqY9yLaYSbDyCEbBCJAylGbnEl4bhXMxPrC4d3V/NKuNmKp8MgTEavySXVIdecXJRBP+GfXLvzMNAvJvo+RhK8VvFfCByEyWWiLB03KE3DPyxOddqKnyV/kV7kMnOE0Wowq9r+jSUwXKFeKsTU6y7bH6Y1gaMTDcaB2BesWeJmgHgViCQ8qA57rRMd2oSdr4VMcELYwlTCyouoCzIVdP7LUJhC/0h6EA9SCzs36QGraYKaLeyGheTNH+VYeOeHG2ifZVSQrNsNuhKsSq6OlWyMsJB6t6NlTA993Zi4lUZ4NNf7FydQaftKhn0z8BLoha3rya07Nq9BxQJwNGhM20waGXeVpi4lWlVUURvvSPjX4rfc3v+IMPGIotPlerYOdYAPVtnR9z5irB/4jUgVg= 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)(54906003)(5660300002)(6666004)(478600001)(8936002)(6486002)(6506007)(316002)(26005)(6512007)(1076003)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-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YVANw8WEj78JviiwPyCu4W7/u5h70ZN0e3oODadPp146AHRfTgaMDKKWa2kzBpDizdxjC3iIE3VkekkGv36S5oygsXvsLNtkEFi88MkH70wv9JZzxPOJ4eTCkglImbU9z8SfZCGQcPLrGOM8RnWCzkWOzxYSNPfCR0e4SHLRX94q2KkeMYTunzM7ZFo2ErSVUKqV6QshBRCIid/JnQKlxGXw72vvq5b/OvpA69r3nS8y4tTo61zFcp+RmOabaSvWaPUvG++ZUasfYURtYANSB3fV/Lm7i0N8EAKfkjEW2G/thFZrKeDJz+cRXLr3btzAIs+mIgrki9RHFsR+mO32lChaIZviTINa0GzuiC06ZIWXakVGR59pMs7r1hFnt4LgLv0M7Ccdni/H5AJba0ssRabfb7NAc2c5AMCwyPAchGxC3uQXLNqYq9Hh1xuzCpXSt8t5z8/DVoP+kAip3GAqmyus40mJ29KBOFpOiD8zbxv7qdLcDc3i2EsRmA6O1U1ifvHXDM4MLAboxz+UrJvVMR5dGEdCm+lMPjW08c0wEicbU9QgOdqPP8rHR50LAX1CN9ZDDWT3JFqx4kQ9EL3u44ppNtmjxy5S86FcmfLXKz/ekAyBmIuW7GNRaWY6Ipc+y8nzsAvQzCtWz0MFq73X0faRQYU7JTcvNQBUITfvr2OrAkLl7eRtj/ags9UKoCtxSs/KLpUTQiqbVQrDwMhyCKCou X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77e0a29a-5755-4916-9500-08db4c05bb90 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:30.9917 (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: 8SQ0UYKfpvth7JE8pX/l6Izk3Um5HwZ6cF0FP9hidA+aFYc08+iBf0OquNSDPqBWWFeZFmvVpdfbaOi6l/mPUg== 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 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-GUID: ni2Fet1Pq0gaFvSxaD5rQsQlvtFNb6Gi X-Proofpoint-ORIG-GUID: ni2Fet1Pq0gaFvSxaD5rQsQlvtFNb6Gi Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Prasad Singamsetty Extend statx system call to return additional info for atomic write support support if the specified file is a block device. Add initial support for a block device. Signed-off-by: Prasad Singamsetty Signed-off-by: John Garry --- block/bdev.c | 21 +++++++++++++++++++++ fs/stat.c | 10 ++++++++++ include/linux/blkdev.h | 4 ++++ include/linux/stat.h | 2 ++ include/uapi/linux/stat.h | 7 ++++++- 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/block/bdev.c b/block/bdev.c index 1795c7d4b99e..6a5fd5abaadc 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1014,3 +1014,24 @@ void bdev_statx_dioalign(struct inode *inode, struct kstat *stat) blkdev_put_no_open(bdev); } + +/* + * Handle statx for block devices to get properties of WRITE ATOMIC + * feature support. + */ +void bdev_statx_atomic(struct inode *inode, struct kstat *stat) +{ + struct block_device *bdev; + + bdev = blkdev_get_no_open(inode->i_rdev); + if (!bdev) + return; + + stat->atomic_write_unit_min = queue_atomic_write_unit_min(bdev->bd_queue); + stat->atomic_write_unit_max = queue_atomic_write_unit_max(bdev->bd_queue); + stat->attributes |= STATX_ATTR_WRITE_ATOMIC; + stat->attributes_mask |= STATX_ATTR_WRITE_ATOMIC; + stat->result_mask |= STATX_WRITE_ATOMIC; + + blkdev_put_no_open(bdev); +} diff --git a/fs/stat.c b/fs/stat.c index 7c238da22ef0..d20334a0e9ae 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -256,6 +256,14 @@ static int vfs_statx(int dfd, struct filename *filename, int flags, bdev_statx_dioalign(inode, stat); } + /* Handle STATX_WRITE_ATOMIC for block devices */ + if (request_mask & STATX_WRITE_ATOMIC) { + struct inode *inode = d_backing_inode(path.dentry); + + if (S_ISBLK(inode->i_mode)) + bdev_statx_atomic(inode, stat); + } + path_put(&path); if (retry_estale(error, lookup_flags)) { lookup_flags |= LOOKUP_REVAL; @@ -636,6 +644,8 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer) tmp.stx_mnt_id = stat->mnt_id; tmp.stx_dio_mem_align = stat->dio_mem_align; tmp.stx_dio_offset_align = stat->dio_offset_align; + tmp.stx_atomic_write_unit_min = stat->atomic_write_unit_min; + tmp.stx_atomic_write_unit_max = stat->atomic_write_unit_max; return copy_to_user(buffer, &tmp, sizeof(tmp)) ? -EFAULT : 0; } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 6b6f2992338c..19d33b2897b2 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1527,6 +1527,7 @@ int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend); int sync_blockdev_nowait(struct block_device *bdev); 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); #else static inline void invalidate_bdev(struct block_device *bdev) @@ -1546,6 +1547,9 @@ static inline void sync_bdevs(bool wait) static inline void bdev_statx_dioalign(struct inode *inode, struct kstat *stat) { } +static inline void bdev_statx_atomic(struct inode *inode, struct kstat *stat) +{ +} static inline void printk_all_partitions(void) { } diff --git a/include/linux/stat.h b/include/linux/stat.h index 52150570d37a..dfa69ecfaacf 100644 --- a/include/linux/stat.h +++ b/include/linux/stat.h @@ -53,6 +53,8 @@ struct kstat { u32 dio_mem_align; u32 dio_offset_align; u64 change_cookie; + u32 atomic_write_unit_max; + u32 atomic_write_unit_min; }; /* These definitions are internal to the kernel for now. Mainly used by nfsd. */ diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h index 7cab2c65d3d7..c99d7cac2aa6 100644 --- a/include/uapi/linux/stat.h +++ b/include/uapi/linux/stat.h @@ -127,7 +127,10 @@ struct statx { __u32 stx_dio_mem_align; /* Memory buffer alignment for direct I/O */ __u32 stx_dio_offset_align; /* File offset alignment for direct I/O */ /* 0xa0 */ - __u64 __spare3[12]; /* Spare space for future expansion */ + __u32 stx_atomic_write_unit_max; + __u32 stx_atomic_write_unit_min; + /* 0xb0 */ + __u64 __spare3[11]; /* Spare space for future expansion */ /* 0x100 */ }; @@ -154,6 +157,7 @@ struct statx { #define STATX_BTIME 0x00000800U /* Want/got stx_btime */ #define STATX_MNT_ID 0x00001000U /* Got stx_mnt_id */ #define STATX_DIOALIGN 0x00002000U /* Want/got direct I/O alignment info */ +#define STATX_WRITE_ATOMIC 0x00004000U /* Want/got atomic_write_* fields */ #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ @@ -189,6 +193,7 @@ struct statx { #define STATX_ATTR_MOUNT_ROOT 0x00002000 /* Root of a mount */ #define STATX_ATTR_VERITY 0x00100000 /* [I] Verity protected file */ #define STATX_ATTR_DAX 0x00200000 /* File is currently in DAX state */ +#define STATX_ATTR_WRITE_ATOMIC 0x00400000 /* File supports atomic write operations */ #endif /* _UAPI_LINUX_STAT_H */ From patchwork Wed May 3 18:38:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230502 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 D3CAAC7EE26 for ; Wed, 3 May 2023 18:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230092AbjECSp2 (ORCPT ); Wed, 3 May 2023 14:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230015AbjECSpG (ORCPT ); Wed, 3 May 2023 14:45:06 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B77518A4F; Wed, 3 May 2023 11:44:02 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HpiBh015206; Wed, 3 May 2023 18:39:35 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=fu8QPAY0g7iFXP4WhzCoh6qJJsySH/11LcV54M/u8sE=; b=1eGxo0WLSoeg3+C29obV/6jxXbh2qpyWtgV5xo1I7zAO8q5SzQdnjVGKywb8lZBplyb5 R0zXDJAWrldmSR/HupVA7ZakQaJE2VAWvzAE65i5FHy8HH8TH9RXaSJQq6iEzM/cBx2R +aVLsQSvAoTbJ7WK8BnNAD258Cc16N28kp7fzlq0ZWowxN4JP3FWziP0Zy3JAIphwR/4 YYR5ld2Y7hY9ZaF/n97vaNwrNplfWpmIFKfpc1/VZS0CBOex0baUPMKlOCkhxLVQW0HL c+P2NsLp2MWQS/MyAZtWqH8n227gtLUEqTzrj8r+G+yzXkYCBaSmfSdWatqa9KkqE1Dm Mw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8t14063k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:35 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343HXUgq027022; Wed, 3 May 2023 18:39:34 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2170.outbound.protection.outlook.com [104.47.59.170]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8spdscfj-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B8H3v/RMX1M4iQ4T29YbgJsOHfiNNIcBx91dU3hV0+aYAOkfLT6+b8Ph64O2k9EgLX0VyHblAGaQ9IpkVKPNxiIPeYzn8QDFlW/HEnsd/QV5FSvSPpyFXAYe/eq154iiKH2f70zJhaqLLo6oxXAtR5gveMXSbd45FqxEgj5nxKU3th8LhKIcmc0s8M+AdWp0+qi9ttef2gaLLcMLE3wCZyXyXbqgEyCmt5n+JKUkPaIiNJ9plCtJXCiiQ/OsF4gwoudwlx/bxbmBdZkuHT31PbFg2mGkjtaudxy3u0haKnk4D5e0inDoYkFPzx/PV62NMwe0z9m5TECucxe0tt0zUA== 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=fu8QPAY0g7iFXP4WhzCoh6qJJsySH/11LcV54M/u8sE=; b=inIDFHW4COolU1wQAKBW5QWZJifWJNb0j/wdORRcCyFvtnQ87glgkzalfH7f6jtdyrIIVDhZeXdTbar7oFD2Wv4MFTe9+AVyeMETIA/92fe499YGBzOBIj7om1uwo3HFY0DW9FG+raR+lzGgrycfQaW9ruR8YrMF/4WOifqHu+KgKgJYpKoUxspEa+5RulIZDPn2wyFnubueEwu4W7Eb3xA/FVPvKmNrxICLo412tH1CTsVpQx0Zaf9CpgNogWJ1kYe2QfJIMFDBLBTH/q2j+UYFe08rdRjkhh/Pj7CAP9isgj1K1/sV6GDPIt36hpYLIytjmQ9shmzU8fQ6OSIjng== 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=fu8QPAY0g7iFXP4WhzCoh6qJJsySH/11LcV54M/u8sE=; b=nUuvf4x0BdT4XW8x67BS3X57+nZhVdKvlNi5dvFrQMs0PFwNsMHRQibqzUYMl4avKVR2zrLNTlHfn62C0hk+XSdERKN8g61sTMohgLpIMrgHlLKBCk5tXMmiinzyFjkOS+/uHiaHXG922DR+oyeGLLVJK9yFBbvkm+614Y65PtM= 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:32 +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:32 +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 03/16] xfs: Support atomic write for statx Date: Wed, 3 May 2023 18:38:08 +0000 Message-Id: <20230503183821.1473305-4-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: DS7PR05CA0096.namprd05.prod.outlook.com (2603:10b6:8:56::28) 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: 0402ffc9-e9d1-489e-0f70-08db4c05bc35 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jOUXNbw74GqLiIMZ16a58pJ3tzG2QBOxEjGQFgnSJVdyQFfL+QmjoYXHg8G7nWklX6WT1PbfpLHRp8/l/g7J6Pqk3aW/78RNrPrWoJvLWWhtAkk6q9ZTCdz2x/MAjov8vo6Q8Aj/QmghrYeBUdW7CBf8HiD1TwqpFa0iLg6us+8YdpigzOiI8oN1kJb0ix7TjUkZ1v8EfT9AZsGTzqkWU0+92gCk36vhXM+bDQuir1tuo0m5rF2T9VejXDyPQ6IbV5vKkyO5H9tUbdnuqQEFIlsBEicT3byKOUYH2IHvaQm4spffhr9AyNGyZprG8hVdzyvLXKf8NoVZoxmEK4+fUVpcZweUsj5Z47jICH/QrSfBqwJzX5gBXiSRuEQa1lewHFcwaYZSHaHTEq/TaQSfVqjvMT6b4jUQbU7qUoCj+zozCKErTacCN/E1AVvstPykY2cH1OczZkrmNQ7zv4sfOqMDPN1DxnJylG7YwYkvtxIma1qI/t77ntDF4snbMoC1GyVKXbthyucaDihEJKX/cb3kmhUP7Z0GE4K3OBH3aiBVe9WIMmkGaNgy5ZwzSV5HilMh7W3d/AKcItnwRkguQhUqap5TyUcCzMGfdb1XAbk= 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: X2eCAWFYAIQ6DyFPfOltN8kWZZ1aE4DNxybztIy7Sr2E2cXy/GwiIreTr55dHJEI8TVSYcCnVfuDoLEPyCdTR8xBQD3mboH9VehYUrjovL5VsR03OnVTkB3p/r5nUEWn+5RlWoorkOABF2FNrGS6wzAkXmclpMXL1RdGAQPtvStCz1zZ13f2fvIK24x0ioFDTTBJI9K8y15wq/oq5LBWkGXIyFl655LGJVXzwZaVIAhRRt7LYJoRp4LkHRAjNIWMA9MfXw4Znhwi9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z+o5eigiaW103xkHXv8WXiQB0EjLKevGxFcPU934mj0cSP36yj2nqJImnDwgX1ZybW0PImfa/F1fQKNmBkTw6lPzLwo+I65TyujCjsdHPqpmDavzOtVhr+dALHVITyIpuUWh0h+hE9sfRR131LbVCYdZVLiSnSyFsiaYT2tRVB+zRDHgjxHBKpjHN6Z7jMm/5lKIqgqWv2txneHFwGzYcx7GUeUD2tAhPSzo9uSuP0USlIkT4ZDqyh7/3V3B1o780YanXSbmnjJGx13l0uGg65DsD3NxAVUXGri3GwJXsEMIopalLyWHNCoIYL2XV/3xDJLRGjMIJfiSW+GEif4AHd0HIeAK4ptGbX4VMhIm1ulhr1+te1wKtusRgXIHBpULCkKpAXcDT7tw5orUVT5sdzeFXeKBFebDA X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0402ffc9-e9d1-489e-0f70-08db4c05bc35 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:32.0432 (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: MqvcAysLVjjI9nC1zAtSqtpYAfL26fxRNNYjBBDb9NueV7UuPfXzF1UioUk08HboMLMLOqXfaoMzMLggB2HUkQ== 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 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-GUID: XS2DdTNHYUWUBlfQk_oz1cvgpYwuSfNO X-Proofpoint-ORIG-GUID: XS2DdTNHYUWUBlfQk_oz1cvgpYwuSfNO Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Support providing info on atomic write unit min and max. Darrick Wong originally authored this change. Signed-off-by: John Garry --- fs/xfs/xfs_iops.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 24718adb3c16..e542077704aa 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -614,6 +614,16 @@ xfs_vn_getattr( stat->dio_mem_align = bdev_dma_alignment(bdev) + 1; stat->dio_offset_align = bdev_logical_block_size(bdev); } + if (request_mask & STATX_WRITE_ATOMIC) { + struct xfs_buftarg *target = xfs_inode_buftarg(ip); + struct block_device *bdev = target->bt_bdev; + + stat->atomic_write_unit_min = queue_atomic_write_unit_min(bdev->bd_queue); + stat->atomic_write_unit_max = queue_atomic_write_unit_max(bdev->bd_queue); + stat->attributes |= STATX_ATTR_WRITE_ATOMIC; + stat->attributes_mask |= STATX_ATTR_WRITE_ATOMIC; + stat->result_mask |= STATX_WRITE_ATOMIC; + } fallthrough; default: stat->blksize = xfs_stat_blksize(ip); From patchwork Wed May 3 18:38:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230503 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 DF167C77B7F for ; Wed, 3 May 2023 18:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbjECSpb (ORCPT ); Wed, 3 May 2023 14:45:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbjECSpK (ORCPT ); Wed, 3 May 2023 14:45:10 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E2EF868B; Wed, 3 May 2023 11:44:05 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HpE0o003856; Wed, 3 May 2023 18:39:35 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=4DYb5f4tfGMfn/L//pFMHs/h/jLe1B1NA9TqsvJerZI=; b=oSz20PMsOGTOgfl8CLBizYxBG8/Jc7DyAHlmt0PbyF4Wo1GcMjZ41zkwX+0Vv/P5Q1cO juZyOX+aHjWBcC3FpDnXzWTjRr3M5zn1sW47JkRgepFCWsvLkONI+yrzB3lc2du4cQ4K 7uA4n0exMnRKRElj1ic/CTrnl8SM8gfcPaagilwi8AVQKW+agKSOtP8yfdeNC0sAtVha Rd3FOm65ATGheE4vkrD57YrMZQOfwIKlvIEFspn0MZsEVu4icRxJiK5aaLYdBylOKHGZ Ps/eGJF7RZEZFUJGqcAnZdoqXLG4yrpYOMNHdObo8KRgYGRrqqyRxQnPQH8xqYUoY7V2 FA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8u9d07ne-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:35 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343HXUgr027022; Wed, 3 May 2023 18:39:35 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2170.outbound.protection.outlook.com [104.47.59.170]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8spdscfj-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XeBzmUxZcisHFXcDhrYcQ9oQpVqret+L8MHTWX6Ovp05lsAN+Ovr5YN2puW7nYUiSH+eQ3NkRbxxU8QSajEW+qqbOq8wz33hEO0zat97FfYJhgxBVZ1rIF9C8hDKJ67XKIobjWz/nDkRNywchD5kmrHjzALBox54zDVdrI+Gt6uOl9rIcc4zLS1EnU2BZfbpgAlJoMf/qKvRIxfTwMb7jrGlUA4iMn8Sbv2xjtdBjGT1OzvBbJgWYeweYT14wI0Mnmgs8tRJ3FlJrJ43tv0Nx8U3GyzKNtTxql/nPvKkU7VUfVZXQIcPAJL8t6vT0K7qYGzN1FU7ACFGfkRFYNqQXQ== 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=4DYb5f4tfGMfn/L//pFMHs/h/jLe1B1NA9TqsvJerZI=; b=NHvPcUySNqnXVQh0wk5KzmmwQTwX/KEK6SCeeRIVJCbRhF8JV+iT/+h1htd62JvuO4GMg2e3DAr2pVdNYk2SHIAqXhgtg/OMjsgPMHdIGoRfrHYCdYqe2C4nDZpbnwkO4L4JOwJmPgaxS7Zw9JQnVQd+rr7pJV5u/NDd3gCkgLf5oqvbj+2aKpRO7DGUbk6wzzWvBVgEYHYYYWvhH3AGbMXQQIetOX4xZ9EO/61zW1gKnimHf3FPYVlVqr3E6mHxKRixBmSjeaxyxVcjju76WlZcb3RrTkhYuKfsPd5Cnd/ZboZA4SrGp5xFBB7QPmIGGnWVEE60dPeX5iNiNZA5Hg== 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=4DYb5f4tfGMfn/L//pFMHs/h/jLe1B1NA9TqsvJerZI=; b=iXYN+sGd9ZrG4SKYOD8UCcM4vknKdbmLtBdCbCDz2zSxoSTaLHA+S4NOnM/4IOvNktbu9XVzM7zH3uLhMOTNjUco0p/6mGceG9bV9vd5gHdtNFqBDjgC8zPS0ctJdbu+xNjJ8UVkpkThvCClTB8xTPz2z3RN1MJVDj0Qluj5L5c= 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:33 +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:33 +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, Prasad Singamsetty , John Garry Subject: [PATCH RFC 04/16] fs: Add RWF_ATOMIC and IOCB_ATOMIC flags for atomic write support Date: Wed, 3 May 2023 18:38:09 +0000 Message-Id: <20230503183821.1473305-5-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: DM6PR06CA0031.namprd06.prod.outlook.com (2603:10b6:5:120::44) 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: be985954-fff4-4aa4-4b8a-08db4c05bcfd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f2p3GElFhzlzkAXc/lG/jY3F1+9W2o0JlFVOdeHYKF+eXyrtm66YUrIIvUOShZdJR5sFZ2SmaJSB1fnks8qQ/vmlxS2aFFXv/YU2iO7+mFmGAhhRU5s2XWNlLIEKsaWNWgVlovhrH0jS5swKrSXeSzp1kUIK1dAgbJxgx9TVvkKUPOMGd/CGXjZHiCpVbM/qzPgMFB/Qb20u4yOvKfvkLxyHZg6JfdGKaQzFGtEtUoqQ1vZ1fyZfbTSjyvKvECCThX2qSFyBVHnFMC99dIbIoDx2CmWRD0l5huNj0CTO+zxssMhFEsVmYXAvd/cdVNUu2VGIgbBqNdDp/ZqdF9oUrkZSjNNU3pD9T/hO2xgXa0L5esWuO5bkUgr25Py7FbM75lN8S3M0TuJwercbVVIzdfVobPXoW3sl2rHT48IHgD0a2uScAQTPwTnogU0FYe+fJ/AuTlCnwnMUmuh3rCVmYCZwxCNE0A4gswfF4tPqIXznSBBvk0IG/h8BSvDiCjARw4bwejkM1xOMPn5xh9PtYV1m3uMK7dLxbftZbSp+nkD8CKsCNad176IF5OQ2EAIbciso1PdUDTc/K3xgCQIE34dcfHDmCXURWgkFm5E9Qz4= 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)(54906003)(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: 5j7PKchICnuvK0ligDia+eqkpzmpBWRmj52fHS4k1LPg/3p9ja7OwhyUF5ZAxAV+XWIo6Nrm5xTYD1YaCzDSDyzJb+i6oNfLeISjDogSJ0ex+ILXLksdtOFlNfqiquxG+C6wtOpfM1VkAn9XuGVWrsoJY0XhZZUFDB3EgbBUNmFy85n8MJs4P4KdpoVhV59PImhDk3f89hZpmtDDVD7IQrfzTb8RLIbmjvC0s1Sxnlefa0VgT10zv0uwyU732FVNj/HK796ghL0yqLz530fGmFfJfR7qt+ftSl0EmvAcvNBtN9c8J+hc7nsUco6vGqmINjYt6Zo5D2rWDxFnCL+/Y0Zsy/vi0TvCwukDT3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/FPOKBMQiiFxF61GNrbaUj/+9wqdVU0Lua20fixNMGfFhFBRmmWG3tlqh16Oh5zD1Zm7qzZWqxmDupB0+PKOa5IedlgW9fxJbvhN32UcPgZqz3tmpBxngNE5oKFx1Pes6BEz3mIb4oG/uuF6wBTWonuZ61hX/579/tOURDDg2tpqlV2qNI1hlWl4wL8TN+gjqgypG2DATc6dnKM/0MYml4xdfPaUBY+B1xHKOAj0XO2ZtUeGZvH5IKoUW+sLv1tpF7nTso6S7b0ZITDK8625+juOxPN5+cya+dL1C4q1lcJuxXKrD475q3/Q4xIr6BQe4fX8YoZ70/dL/s1dlYs5CcEDzwmUAGM4e+jMROw0GfW X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: be985954-fff4-4aa4-4b8a-08db4c05bcfd 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:33.3991 (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: mCHkaZgSZZeV54ASjledjUovjpeCs32Cl9+YR+g8aHz+95YjwRNdtTxmMGC9ck65No/HPNwLvDCnfKEC66MjqQ== 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 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-GUID: foCq1xZxgWAl753UefztYKakycNPUUAJ X-Proofpoint-ORIG-GUID: foCq1xZxgWAl753UefztYKakycNPUUAJ Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Prasad Singamsetty Userspace may add flag RWF_ATOMIC to pwritev2() to indicate that the write is to be issued atomically, according to special alignment and length rules. For any syscall interface utilizing struct iocb, add IOCB_ATOMIC for iocb->ki_flags field to indicate the same. A call to statx will give the relevant atomic write info: - atomic_write_unit_min - atomic_write_unit_max Both values are a power-of-2. Applications can avail of atomic write feature by ensuring that its data blocks are a power-of-2 in size and also sized between atomic_write_unit_min and atomic_write_unit_max, inclusive. Applications must ensure that data blocks are naturally aligned also. If these rules are followed then the kernel will guarantee to write each data block atomically. Not following these rules mean that there is no guarantee that data will be written atomically. Signed-off-by: Prasad Singamsetty Signed-off-by: John Garry --- include/linux/fs.h | 1 + include/uapi/linux/fs.h | 5 ++++- tools/include/uapi/linux/fs.h | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index c85916e9f7db..5bace817c041 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -329,6 +329,7 @@ enum rw_hint { #define IOCB_SYNC (__force int) RWF_SYNC #define IOCB_NOWAIT (__force int) RWF_NOWAIT #define IOCB_APPEND (__force int) RWF_APPEND +#define IOCB_ATOMIC (__force int) RWF_ATOMIC /* non-RWF related bits - start at 16 */ #define IOCB_EVENTFD (1 << 16) diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index b7b56871029c..e3b4f5bc6860 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -301,8 +301,11 @@ typedef int __bitwise __kernel_rwf_t; /* per-IO O_APPEND */ #define RWF_APPEND ((__force __kernel_rwf_t)0x00000010) +/* Atomic Write */ +#define RWF_ATOMIC ((__force __kernel_rwf_t)0x00000020) + /* mask of flags supported by the kernel */ #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ - RWF_APPEND) + RWF_APPEND | RWF_ATOMIC) #endif /* _UAPI_LINUX_FS_H */ diff --git a/tools/include/uapi/linux/fs.h b/tools/include/uapi/linux/fs.h index b7b56871029c..e3b4f5bc6860 100644 --- a/tools/include/uapi/linux/fs.h +++ b/tools/include/uapi/linux/fs.h @@ -301,8 +301,11 @@ typedef int __bitwise __kernel_rwf_t; /* per-IO O_APPEND */ #define RWF_APPEND ((__force __kernel_rwf_t)0x00000010) +/* Atomic Write */ +#define RWF_ATOMIC ((__force __kernel_rwf_t)0x00000020) + /* mask of flags supported by the kernel */ #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ - RWF_APPEND) + RWF_APPEND | RWF_ATOMIC) #endif /* _UAPI_LINUX_FS_H */ From patchwork Wed May 3 18:38:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230461 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 7EA69C7EE31 for ; Wed, 3 May 2023 18:40:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbjECSke (ORCPT ); Wed, 3 May 2023 14:40:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229810AbjECSk2 (ORCPT ); Wed, 3 May 2023 14:40:28 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C43C7693; Wed, 3 May 2023 11:40:14 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HpiBi015206; Wed, 3 May 2023 18:39:37 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=JD8hDPJ5N3T9bs5alGxEwJJ3mTs1CCPcdSsiBHkOmXo=; b=usIYbrPJbpCO9YdkaJukaG4dhB5S3aI+ws7mWwGLAUNaEQ8tc+utGSmyAKntZi+ZT5Cr TUWmEsK7tE6VkFMHaeWJQPpqgl3sVCyilj5QWHH2VA8OPTEcZUohGA6Fn6iMk5PtZWlG ZLY4J/uh+sLXfcnzMffij1fzNWJpX+3t6uylxhZa92uOTxOoieMp2OeXTdWE/6jwd+Be 21Vu7OEMtYLX8yC3wFJJOmlOt6F5G5xW8+Oh4Ns86bEz6yuS3/0Xl1thcLLmAXa0g5uZ /GYqyvjkQnXukRUYaZB18mVcnp+I9NW8bWnhS2ZYlX34Dfsa+Y70EfPrQCJarQlowR/x Yw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8t14063p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:37 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343IP8PL026971; Wed, 3 May 2023 18:39:37 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2174.outbound.protection.outlook.com [104.47.59.174]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8spdschs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eks9BUPPSyjIYxlJz/T5Oi6004AsEhajxbVDJTEUQ3aWgXWTVO21dpn0O74ZW0jgVyh9WBz9UbOC+9Tab74OYjFN2rKuto2xD8FqAt4RfS9Nf165ZYzKRHAFqhIZqmFjvAItVWKzSxLxGtFAe0rH2Kn8kKMRqo+wiqAAXV4sKb6QuY60Gxsi1LN2q7/K/i5mGWScMO6fT5NwiZRKSHBeLtk6HvB44A31r1RtX1PkPwSFVg6RE8BYdlrPYnWChmQbsTrwxqANGhU2paiVMu8rq2VWA2FsdNsHOespSAlC3ad3XidQa4mdYFWzAactmgVklcrWCEPFrVnfk/PH0Z3gzA== 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=JD8hDPJ5N3T9bs5alGxEwJJ3mTs1CCPcdSsiBHkOmXo=; b=RY7T7UbxJc6UkMDr6z1GuETS5gUEcVfEHR3Ovxr4erJ7hiQPpOSF9qzn/3G6UE81QWsDXgVyR0ZdgmHnQ4IgrDvNpXKSAhSw4gRbeh3kKmOA1kBJIPxYOQaoWJhnXmbSkP4+hK4gpnlLC7a4NyjYNUr4vgq/t6mQ3fleH2wAQRw0j753smWMZayfp1PfZEusURZnum0Ko98RtrGXSodZrsytI8k78tXkitGvSR3YJ6UuJbNnH/JZg2LMwoLPZ6I6yjxi5wICDkK3moXo3gd+5uuafILkpoNQzS9YAjgVAYzqge92sBIusnWtuhcTHfBkcZYy+9J8FH0AzJKXal+jgA== 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=JD8hDPJ5N3T9bs5alGxEwJJ3mTs1CCPcdSsiBHkOmXo=; b=Uw4B707ApRW9cAL13GZ88jyLy1lP86+cxWcqTBrRkMymM6guo+ayCCYdRA+ExZHkY9tp4GlZxmLLwZmBawD5RYWUOaqdLZto9llwPKxEznMblpGnDqPrKy48P52ZttZjcQBzs7HsM7weNprKAJAD+aLmjA8kSlj7mykhrerUBtU= 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:34 +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:34 +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, Himanshu Madhani , John Garry Subject: [PATCH RFC 05/16] block: Add REQ_ATOMIC flag Date: Wed, 3 May 2023 18:38:10 +0000 Message-Id: <20230503183821.1473305-6-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: DM6PR03CA0079.namprd03.prod.outlook.com (2603:10b6:5:333::12) 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: 5da3b65e-784f-41b9-ee34-08db4c05bdc7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VOLOwMw6o9syHDWiwV5piKeQQ6uGaYg0pptleuH/ahMYK2PHkcyJASF6JVV327sVSB6v7q2B2tqWmq7qmmhYQR9yadvbA49zW0AZGkP58GXcyVVsT/Y1+OG6oeYHJ08isJeVDuK0p4vSw5frdqxPy3TSQvMCPS9/Lqp18/OMViy1xeK8lC7fh/j1mveMCk/IrQfzwEiPITdkBwpLegWrwsqZ+gN9kYGBaxR0wWLzTtt+PnoegXw9AR9a1Yq//uazQ5RWfB15gMJZhulVsNJYkVsEOxd+pJCD/BVyc24FVPEcYvPDCTwZMrMryAarkV7uSl0K7/rU71LeI1teY3+W2MyZcaaIRpMgQNyILFxo6IVr+RpqCri5hPI4tCisZUaRZJuKb69m0lDw5kImgQHF5G/dtpjkhEifWskDG31E5rkLdy/9EDaS+Zr0aPcklbFyxhgUSiZGHMMpcHsvBDOfvf/ZpL0iMWJyUGRmA0f5iyeaSKLdF9ApNaZMNIjTkXy+k33HG5dGz4BRZKthOQSIHx4icY9ZBEyyrnTiZc71Cma6a5ozDF+RaglidM/8JcvwWpN7XR8edq0xMuaEqL1ksDlahZU907vHic+95nPkCIY= 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)(54906003)(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: P2SOJHUSoc7NncY3s5kHAk24mrVYgtWKQ8UiMEmZfHRdJ7GPTKwjPgJ01DHey/nYNGrPE8xXqEk40z4Lik8CYIhETMDrg8yg+857fSGfz97Jvi2t27EXKsQwA/Le9znagywJifhQmpH0iYK3CBTc7BHdgOkluUpgiftaturYKSQ86+ZiZyKP0Nie3vlJv52xaZCBYmn2DhLUJms4bAD9iRwgOtMqGOjlPEsy2HUv+PjUJnqtlP2o9sMDn8txNz2qMQcQsBYa9pqIbFuKEoSxFMmcPiN9geN5yzSfT9FHUEWuw6V0EoSQ/hLg9fQzpJd9eV1cLGOl4lgbA1X3R+bL5PSH3EOqrDe3iKt52al0URU11TJ+oEfylbLELJtTztqqzlXwZPjo2Jhif8K05C43G+OwZhfS7FSwkXyDg9DKatx2IIqVIH2RRupqu5hjFE8sQXd2XdOrX9EnLLC3vD7WcMMRRvqayPppyX+wvQ797snZ+6HPrnRkTRJmYfAUZBWp1JSVhGoMpWsvPn9N0nEi00aGuSiFzA/dW0X8mIzms0IDIg9qhLg+URw5STrCuOlCZxqLkn7W9vvGyqWu4727IGGl1QxgtWHp5Upq7yDQMXAtT+029VIwTP7LsuBEHrwqYMvMaeaq0QWPHwNQiiprC8zFyrORHy3Em4OAVGAoQeHqul4dazHugXhCD1jtC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change-CrossTenant-Network-Message-Id: 5da3b65e-784f-41b9-ee34-08db4c05bdc7 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:34.7152 (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: AG3T+SVADAE06zQS65hG7BjpRs+fSk4muUft8owmd6MgbTIjUYuEXa73FV6Qsiz0g7DGankoIdbQDXrOjpSPMQ== 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 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-GUID: UNqPpLQl5I0zLaHqhDDJJW4stVOGM4AZ X-Proofpoint-ORIG-GUID: UNqPpLQl5I0zLaHqhDDJJW4stVOGM4AZ Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Himanshu Madhani Add flag REQ_ATOMIC, meaning an atomic operation. This should only be used in conjunction with REQ_OP_WRITE. We will not add a special "request atomic write" operation, as to try to avoid maintenance effort for an operation which is almost the same as REQ_OP_WRITE. This flag was originally proposed by Chris Mason for an atomic writes proposal some time ago. Signed-off-by: Himanshu Madhani Signed-off-by: John Garry --- include/linux/blk_types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 99be590f952f..347b52e00322 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -417,6 +417,7 @@ enum req_flag_bits { __REQ_SWAP, /* swap I/O */ __REQ_DRV, /* for driver use */ + __REQ_ATOMIC, /* for atomic write operations */ /* * Command specific flags, keep last: */ @@ -444,6 +445,7 @@ enum req_flag_bits { #define REQ_BACKGROUND (__force blk_opf_t)(1ULL << __REQ_BACKGROUND) #define REQ_NOWAIT (__force blk_opf_t)(1ULL << __REQ_NOWAIT) #define REQ_CGROUP_PUNT (__force blk_opf_t)(1ULL << __REQ_CGROUP_PUNT) +#define REQ_ATOMIC (__force blk_opf_t)(1ULL << __REQ_ATOMIC) #define REQ_NOUNMAP (__force blk_opf_t)(1ULL << __REQ_NOUNMAP) #define REQ_POLLED (__force blk_opf_t)(1ULL << __REQ_POLLED) From patchwork Wed May 3 18:38:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230460 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 637A1C7EE29 for ; Wed, 3 May 2023 18:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229983AbjECSkc (ORCPT ); Wed, 3 May 2023 14:40:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbjECSkR (ORCPT ); Wed, 3 May 2023 14:40:17 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 412417687; Wed, 3 May 2023 11:40:12 -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 343HowRA000715; 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=s6U4SHv03DQbibGnwYMMTvVbf59+f2S7TduJtgmTuyY=; b=gQKbVFMRu1AZ9Pe+pMxETxT3Rk9/0aCNVSAsElrs4QGEVmSIIJQFCCFkHXWxezcgZIUB goGqFT6mUtGeNng8hs/mCeWjmgp1NExzXkw+gUgkYLm9ZGl3mzJSQv+D65w5Jw+X1M0a 4reYeYS7tOaaXZ65lHSL7mCVxCWM6c20FUYPzNWzmaAJQNRHn/AGzVafvCXNE+Csplxc nJzeDQMGsSJ4PAkyIxXCtSh6rDaaT8xnLIeeZIxQpHF72Af7TkvuC1/jWqfrNNr1+a6r +aPcLLDloZ7Yu28TNwXVpuxVyOvxr/qtFerx40suHs8iAAVCj7g359p4GegEPTjUFKc6 cA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8usv0180-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:39 +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 343Hsbt7020802; 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-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Az7d/87b6B2taDNLZOM90GTQTjR1xLlMLg4rnopRC+Z1tYPAQGpdNN4ytCi7sVOxYVSDLxpIPkVWPxdDM4W4m/5YWoAZjBOOVTlve1KygqX0mU3p4EIDrvC5AXFShvOKdUjEU3rE7qfJNntg6khSCQrTdur78h/kneD2FayFd0K/s6X9Bzui4dn8P7sO71SO6CrsNjH1IbnjTKWFiCLtJDImaJo+Uur3JNnVEvviUwmhVan0XRk45LrIK52czGzb6rpEfkPu4h4Z5V/03MWu8oA2B8nZjm75voe8jw6rV3uL/eC8F1O0c72Yt/A6KnQCVaY5umcmVKzE91Wyt1vLTg== 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=s6U4SHv03DQbibGnwYMMTvVbf59+f2S7TduJtgmTuyY=; b=AgYDlc8im8Msb+qKOpoeaqO32vfDutsBgNi1lPnMRxn0AJKX3H5E3CEbkB+SbhCUrukK7OvRR7FfApYvn+c4xVpe8luyFV16avNvDFiy71+mjJ5AkMJI04uQDZayxqGDokv2xwgoe/JNROxH2P9T8UYXD1KMoNhEtDwV+gLebw/nv9LUT2XiN2NshOxT/KHcAU/N7XEagvMK+l154r5qz56TCa/IkvB9uZbItkzinkDBiekWXJUQ0k1O6Nlp8+jiiiPLWKYu+fBXBIDCe+c18A068EpykdzdqIQeqijzeWY2cluW+MCPC2BeyzHkhnBVZIDBJNM2H7Z61DCzRdl8Hg== 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=s6U4SHv03DQbibGnwYMMTvVbf59+f2S7TduJtgmTuyY=; b=Cflh1UoFefnWiXme7EMLAtKg5+Q6qCrwTdv1FTv0CXcmolAogUBgUKuwQxZcfautv3Qw8YIWXtHN3F0qlHawT8vPvecjAtsjFAmZEmhEOqShMcvlM/AWrcOvHarie3+dxSmAD+KUw/wXQjShWW/TTVnkQuwtzL8v+0hMnypKbA8= 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:36 +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:36 +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 06/16] block: Limit atomic writes according to bio and queue limits Date: Wed, 3 May 2023 18:38:11 +0000 Message-Id: <20230503183821.1473305-7-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: DM6PR03CA0073.namprd03.prod.outlook.com (2603:10b6:5:333::6) 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: 30c698cc-1647-4b87-82a9-08db4c05bed0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Mzccw/Hf4KsaJ7Ln7emlcioAs0UNCUms3UyMJkg+aSxBWpzWd5WmatkRkaDk+UHxdTQWaxF9fPc3ycuZlHZTUlyB/pRbub1iuupazAAFF9r6ByfP228v5wJHE3BNs9fPi6tCRfwZQD615pXi0Rlu/CebVYgQGruYjqkUcQYtZK8yAnGd5evbrBstW0XS3c59ruYxjgkd4DD4tWadWB5QfSE3e7Et3QiOLcHeCtxuHt+GDKMi1P1Rd9ihhddSULFr04KtJ7QKu45KjcbMwovFYvf8fEs6aSrRTt+12UAwlpyUallzaFOyBUP+EADuEAgIsUCW1yI0Yvh9iER4R7F/8j9xdlpQMImvYHcbgzYUBvm2aMEkp4xFdaqYur7O72OfZ1ZrsxRb8evi+daQRboQ8mveDP0VmJm+cEQvNs+JoO/WKZagshWw0AUDbCJYyzmqBYKp28wjWVU4BA5UWuqqM+pQcRzR5QiBz86yzz/uRuG83rNye9ovrnDQ5b7Ny3ugmKYMgP8RCe0Dxo56ZqR2TtvTBIAq8nY/Cb8a6AORNapYP4Vm3L4IUtqB/1yadbz42sKARGnDCYB3XfQGQSc8zl/2niaYw/XIaFte0U8/0AU= 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: JBJm/hXM6t61z+qlOEvAwkt1lNIK1s5F8MNEhR5YSt8nGyXQMmhbF9HbmryrcOAZJnqRvfqAnuuyQW1qdMQcNj1gol9fhiJpk+SYcoBY58h+oNg3o2S7HqT+1t2/ajmPR8mKWp8ui2erIZF1duhji3g+RfF2N9Xz3uagEtS4MXYE/4+wYNVUpS5l0aQ5ZL833CM8hKFA/KJP0MFfhaG8QyGKNLpFfNGNjDJitEMvg9e7PZfATBbbddtpJyXInpGkW3o3ARzscPUvq5S+DtVbtRDzGGgPdrVft5+06yMJIjRPWE7Wteqx9DpVLRGLTs2MwsMMDXialtKk4qQTIRsTgBLWzf7dacCdhc7qyJUDmJSjj4QNKALCCa0txfLaNFpFjsUiDuptgB/Hgmb5m8othVbAT9S8dzpoLRubxJRyU+vSGDPpE7jntwypVMugKcCm747RVU0ro5pnAWozL/nFM+pFnJgdKTCY3Tua7iNc9F8Nv83qHsfNMywwEqnkmT7G5NzZ8UlVRf0D/+7dy1DUvQTFRDI+Jz0dUuWk/qlIEJqCZS5k6v0uYlrvt89wP2tZV/K7MoOc1UnOaETu1dhr5Cj58UZSmGQb7BBykIxSaPV8qd52mqQg6tiDyly+JWCfWAycuDDBciW+b6ScsoCNM9/rhJ8M8vlwBiK/BwfHGXVupaPeRmm2Wj6Oif2vkzLycyiFfSLBTrFRFqtm0AqpvA7xv+N680CYnkU+LbvxryRWZ9N+o1gP3RF45pzrB1kVLVfefztMmGB1jGAgbMeFW0bMFeSVZg/XP2BhQatXc2o3GzaYdu39TAgIvB6MmWKH5brR17OKKjQdcbGEWkdfgRvaILMoWVFl4wuaiDVoU57dP57CTQvtraLPd89DoingjEzq/07KBj5qTFKPWNtZpglnJtwfq4AOJlQ0nfCsgSRpWNo0yeO85ynuwRdxvD5NWcLESsKMkxJpHGytAULwkFzZRriROT/SM5e1JpjRtdtmFjKMOlG5LVLohr/zMsgtvXZd3xj7zanR7YA/lOf6qdxQGCWF6615VR9uH0S9d00a9SDR7Ht84KIAc0SP0LRHANcog7L8ztPATBYKA5nFuN1IdzS+bGNU1fpvraN7vaDX3LtoPWcJSLTa2krSePXaL93NUuy7PRYKsug6Pf620KVjoJeRJBgwXxRsBeKXVgCxrphCUc1DEYWvAVCm+bc51HKhztIOSiQ33qGInH2WSoetHcYKrJ4Jo8KmH+fNq9yIVYkEElB1gqOT1IODELRmC+sn7RTVNr44o7ZcHlkHY/0o9syOBgwC+ocSkZW9j2dYRjE7SjoH5mxkggyiV1ee+dlOJ/GBmnhmbPHK/LKANul1SJOR9E+rkOiYJs23Rd5U1CbFDhKxB9h1gFSeamGIGsJxlYM+wuesGFuW2ju+1sOfkIKRl4HUbelQEB9ay2zipj2b/Oizd1uItmiQxaCtW8yu3o6RXY238MdVqhxCJ7H79haCxi0Q65QHBnjumtndNMZvkgJnECuwpE9hqk3QcbyU8p1+inTkI0FBrPFW9LuVDUwHs/gUMZeC1atwsZCLfFes5xLC/WhFVdjKiAzkPHWBJIHAEEvq0ZOT/KukXg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: cYcXWVdXfCZ8eEMYdrWGHTSmZF20E01NWk7bG0boNpzo5vpi+MOAzBYzCkVX3k28kX8sKggNVynOPSI9PvW0yh6ErNK90eNs39/6zJkwkt7gcbqswE8HLqHGNn5X9xN9JteXxSw2JY2WCzBL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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:36.4561 (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: +S1mi8fcufsc/9TyEn/8RrmSrD1LDoSvKA09spg3OnpBxDUIA6Nz0D36TYZaGOIx47O6PZslPRPgA3/UpJZGfQ== 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: aFpDXZhtBuvKp7b7t86_EsgeTppz6-yG X-Proofpoint-GUID: aFpDXZhtBuvKp7b7t86_EsgeTppz6-yG Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org We rely the block layer always being able to send a bio of size atomic_write_unit_max without being required to split it due to request queue or other bio limits. We already know at any bio should have an alignment of atomic_write_unit_max or lower. A bio may contain min(BIO_MAX_VECS, limits->max_segments) vectors, and each vector of at least PAGE_SIZE, except for if start address may not be PAGE aligned; for this case, subtract 1 to give the max guaranteed count of pages which we may store in a bio, and limit both atomic_write_unit_min and atomic_write_unit_max to this value. Signed-off-by: John Garry --- block/blk-settings.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index e21731715a12..f64a2f736cb8 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -212,6 +212,18 @@ void blk_queue_atomic_write_boundary(struct request_queue *q, } EXPORT_SYMBOL(blk_queue_atomic_write_boundary); +static unsigned int blk_queue_max_guaranteed_bio_size(struct queue_limits *limits) +{ + unsigned int max_segments = limits->max_segments; + unsigned int atomic_write_max_segments = + min(BIO_MAX_VECS, max_segments); + /* subtract 1 to assume PAGE-misaligned IOV start address */ + unsigned int size = (atomic_write_max_segments - 1) * + (PAGE_SIZE / SECTOR_SIZE); + + return rounddown_pow_of_two(size); +} + /** * blk_queue_atomic_write_unit_min - smallest unit that can be written * atomically to the device. @@ -221,7 +233,10 @@ EXPORT_SYMBOL(blk_queue_atomic_write_boundary); void blk_queue_atomic_write_unit_min(struct request_queue *q, unsigned int sectors) { - q->limits.atomic_write_unit_min = sectors; + struct queue_limits *limits= &q->limits; + unsigned int guaranteed = blk_queue_max_guaranteed_bio_size(limits); + + limits->atomic_write_unit_min = min(guaranteed, sectors); } EXPORT_SYMBOL(blk_queue_atomic_write_unit_min); @@ -234,8 +249,10 @@ EXPORT_SYMBOL(blk_queue_atomic_write_unit_min); void blk_queue_atomic_write_unit_max(struct request_queue *q, unsigned int sectors) { - struct queue_limits *limits = &q->limits; - limits->atomic_write_unit_max = sectors; + struct queue_limits *limits= &q->limits; + unsigned int guaranteed = blk_queue_max_guaranteed_bio_size(limits); + + limits->atomic_write_unit_max = min(guaranteed, sectors); } EXPORT_SYMBOL(blk_queue_atomic_write_unit_max); 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: 13230459 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 BF5CAC77B7F for ; Wed, 3 May 2023 18:40:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229965AbjECSka (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/4LE0xXBaqf9gHuMS/c0RhErJXOLPGFXVWgldmLnPNcO1U9xeBibiyAQmgNUTfPXYfTq63IylovDUHNxbkqV4vMqCs0LGfpzKeEsFitE4hO9wEMysGR+9Rh7x5BSzkCt9nmIXeNxTkCEgmCT6x0D7aZCVKoflieZyOPKzdhIKjN2Y7tDr7wU8rc1wKd0sNcPxRPiuvLHDdkRpdVE9ip7aFtfmoNu21Jh9gGm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MHH4QEandJNnp3Z+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-block@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); From patchwork Wed May 3 18:38:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230462 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 EA659C7EE2D for ; Wed, 3 May 2023 18:40:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230157AbjECSke (ORCPT ); Wed, 3 May 2023 14:40:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbjECSk1 (ORCPT ); Wed, 3 May 2023 14:40:27 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EC477690; Wed, 3 May 2023 11:40:12 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HomQY017456; Wed, 3 May 2023 18:39:43 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=Oi2uyE8N2356UVchRvEhKFqT4hAg+6Q96AYvmiDM6Cs=; b=L65ooSaCQkAjCikP4s2ejqM9+SKS/MBniX7yKWPp7M4j21hkzqSPONVfbFV0lMSVNPGz pRItQbyYJG5LiakyaME0zUAPHiyaxhk5T0uA5jW+lex6zI0zJJtkrpS7YsGAfB9tV4WC OOSpi9cY+Sph/WyrD24FssYfPO8A03lbdgAJK41BCgHRZcKSNF0WrO8oiMxe6r6oJnh+ f7odJEL0aXrKG5EDk4QfWBFupgT1ORQJ0EYCUfP/aTawmF4VA/xSiI9UZYbKIL99/Nil G4cp2Q83BRSAPNEk6pm2XOzwd4ew3XXNngUdDzUwAndXPvg/VlRe9mnSzCbg6RXa3zWo yw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8u4aqyg5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:42 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343HEbSG027489; Wed, 3 May 2023 18:39:41 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8spdsj4e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a1nDuP+iSPcd0EB/wPOwHZBI1SBNo5F+JeIma/JEXRi4Yx7lEM8+nlOmGLXwkKieiWsk6mRt3gd4+L5Kg8ZFihM0LQKH5cJMS4MALZ/ZvGuNZy6iwMG+RIA65LSrNuHO+MmPUjCifDYSbDVyBhGIotiZDWjBjDYcDPvaXO6rK5srfM2g92SoAWaFn+/m5OWELSt8H2Y7cq6jCEONPl/RAVrf8stVkmmwlV1mu7GPkcQxExuE1LJdElb3/F09FJenxsxbMtBUFshqXqTaNRLJEvDXwMa3xfV6m2n4yXfM4dc99o/zzNuqyOhFDRLreR9jSVd11DnOSdcrt/cZa5gkQw== 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=Oi2uyE8N2356UVchRvEhKFqT4hAg+6Q96AYvmiDM6Cs=; b=NKtC3AZWcesgAMRH5PVDiQNUA7CuffzeKORLVyOq9V3yirgDMAMDBc8uiPQdi8+au9w3xVZAWt07gaXNpmoZp0CGvffFdkZ2PJYeSWaiYpmilhOv1L9opa6wU8thCQnFAYK64cawh0n8HRqvXjFzuiXn7qm3YAa+914xcKi84VJwVGpehr4c2g9c8d1+zyjN0IUSJK2JQGyu2vrGluxavy/diKj6n+Twc+cMcGutDrdJtHiTeCxl4n81FagkZH4GhudAIxwcCWFJGQLYCtNChlMu+lBSoOB1kl0Fh3QJy0a3RCcnL7LVnpHBC5sbD4cHV1Pzcp4zwo1yHd3Cgk3Ypg== 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=Oi2uyE8N2356UVchRvEhKFqT4hAg+6Q96AYvmiDM6Cs=; b=U7ESK5agJ4Ri7EX/lFPJc+SrLORKylmD2/LJN8jV/nDM2WF56+qpheGq9gwFI0Gkx29s1XkskcB3sjSSpbFbTFmyq/942w/G/2bIdqVFgDivx0Tq2jI9p1SvUsjrFQvcQ2ci/1fAVzL0l6qUHeHdh7amu8u5ov9NJh8BNo2rxtc= 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:38 +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:38 +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 08/16] block: Add support for atomic_write_unit Date: Wed, 3 May 2023 18:38:13 +0000 Message-Id: <20230503183821.1473305-9-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: DM6PR06CA0010.namprd06.prod.outlook.com (2603:10b6:5:120::23) 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: 15667a67-8130-479f-4e08-08db4c05c031 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZuLT0rkvn0wfJ7HkdahXR8eDl0zmFGByqOS/NrtC+uQDulHj3+Cm2wXSmVf7qWp0qffcnhnwU2uloW77p59IFJ/XRO0Yeq6+UOA0I0iI8vvg015XWGttWwXPXYvaV/WEipAMrBl2B1zmEw/QYb/+GsyjRyphDdJ1qElIuY8VEOWfWij33kDSwK5m/6jcZZstP4BSxCoBScfl1lNO9YAWsXpd/eB1xEoICWMtDU1bieTzSwqZxz2EGAbGl58oxF4h8mqEbWJrJsS/fQg9Iy4/VvPNjI7SZDp7hshp/H3ykEtPFWbeTorORPlFeBnHi+BSGc02sNS9OIdfLisKTE0tuW1032FaWJYF+wRI8+hQCuA81HKUbH8ZlvX1B1cgVfVOSdsoATfo1ubUT31VcBeDC3UtdX8KFDz8qAg2HygUgoIU7yrZMF655N0lBMy8oEXA5Ht+HxiMZEKxnAtHrJDrNHJy5BQqN+EQKnpqfHdGAnfnRP1Af3SMytd4vcdlFe9eQEbJoybl3n5KstQcqr4wCVQhVxXe9FYNAd1MBJhD/aLruJg/WwZtNmHjyAMJarT8bxJ3016+5Gcr67tW3sjmzrS7qR02zcKz9ZyMuWAhyKo= 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: hYAjRDI5PHPWHCY2VuwVIov6CshdLEKxFlw3RmwGHIs3VY7lsaLJmMr/PsQtROuJbF+HKsacCNlqN8hTlb+1A1VxBeN3lHaEj8hEAyecAVSJcfbhiRIka6Y3oFWqBND1ALx4hPX3fu2UaAe2JBV82UqgOSxFkoMe7ZtqEWcnqps0DwsuQuxbec8lPwRiKeziuZ+PY0scGMeEcYy4VKE33ywUCp1pHFIXjxA5mTweJzb/AI025A/WNW2x5Z6KZkmwMW+wRBeWMewUen++Kl+yjV5pDegMgPZyBC55Cop/BlHZzzAavkUr7EGciNRi4t141T+eeRXZzOpfxHOmLDBM/RXAUQjjRDeL4PTdnp3sYSU0EbUfLtKD6n2d4KnZH2eqIXGUv4KFnJwvjR63KvZYNdVEYGKSAlVwwsNwT/QHxjJAmQSmUoSIGNZKQpNUSxq2+MWC2tnQPTGolovUINo7sS9MGcqnlJj0khrI12uzNQdj4DIZMHloFwkZcwrJroC6B7AJK2u2Kw2Y0GGAAxJ+HdY6U979v/kwFMYMHcDhabROCsU/brmFaU00Fvp8jfmKZY8adCrv+DgQ5MG1B8SmsAdTuu2dvryYjgB4cRqVKwmyxSiae4kDD4n9wdAP5gFQrJX+juUNlN4AnlWK3EH/ctcFgxD4kihyKKdNuag90UUg7xT3/ozZCmvN+W1Hh2ys/erB4SJsS9XM8yCcpKdFGXh+ICLXQNK9uumKFMIT+ybGQHDp+qkhLssUAqjbQl3nSfbza7CSAo6ZS2Ngmy5LusdW3GjR1I4AQoGd4W5Z3c1Cq6KmR+QAiIgNTi2Lb7pT/96+byIe/NEMnBW/DyozJ3cG2wKRrkzeI5D9qxJqq+E+oNZTw2Z2OI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8bPjsTdYgFTfANYtvyCV1H5Ad15SFs8JSOPWQg/j3w6u6rY1HkLqwSYag0FL2rbqDsJEob6IXXyCDsA+ZtieCzW8hR0i8kjlXsFMMJWTD02rXoW0mjamrMcmqg2pnUpwcesOFboyJRMjIWLAGGdTt+UJKnr6ZIyJiw0YfZQpEHhPoY/o7C4yhF8pYL0FxDhrYxW2efiwahiJyTwmrDdVnwQht0coQgBc1uAnBGId1mRFjHsdDles9G6IHlSWx0Eadj3MzKmD22eo+ZApAxM/lyVuw2j1DYEnzpOR670fBPAb8AKkPdCjHAtP2eztDNMmfm0XjDhjGTKchATb7MjABS6gSE+r1ZXTUu5uJMuklJKNBMOzqxaAiTNLCbzz3EIwK8EuelEYgiSDz/Bkp6LM/1uW0Ka4H4BD8+QPdk6mYBZSe+E1bzBvs9g4KFaIyQXobRB9GO0NYQBi1DJN6d9UURpNm41tSQ49RGkdVQXQS3bQvNRvX87MiefbBtehBQi0BNGmTcfVqfJnl4RizVMvCBwL6m2OUEiKNUGCyaY1fh7lLCrJ8s2xiUHvLZqN/qQhTS0J+nRyVMxXoSf80Mqcmd3zBAoSCcYGydiCX88Tw39Dtsq69CKY/RmRUwsmcx8omrZVFWdhnaJbNMXFU0VMKIzTVRe4/hqYNiPc43PjL3S6RhsU0e6KTpOZoE6jJPDsy5eCP9V9+wo98ZeOGfRxRVYnPYPTkn2Kv/e0uGunq6gFpEX3XFIKx3EHLppNK3YZ0ITqvBTIblGOWzMUNYpnBsJcDf82Y+fwZgU+4YwpHMbDy4pJwvbivGrgNXW4rGPSB3hcqUnvwX0L7W15Vuxgqq3gCeJ X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15667a67-8130-479f-4e08-08db4c05c031 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:38.7540 (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: rW7S/kWOds7RDf5vTdI0u4NPgYcBWBUVxfL7U/zqwEoRaVpcFMR2gY8l1krijeFgnOFrBJWSpY4lUT7bz2BygA== 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 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-GUID: XOl-RfO40zUrnz7DfqKJ48yfTMzWQoJq X-Proofpoint-ORIG-GUID: XOl-RfO40zUrnz7DfqKJ48yfTMzWQoJq Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add bio.atomic_write_unit, which is the min size which we can split a bio. Any bio needs to be split in a multiple of this size and also aligned to this size. In __bio_iov_iter_get_pages(), use atomic_write_unit to trim a bio to be a multiple of atomic_write_unit. In bio_split_rw(), we need to consider splitting as follows: - For a regular split which does not cross an atomic write boundary, same as in __bio_iov_iter_get_pages(), trim to be a multiple of atomic_write_unit - We also need to check for when a bio straddles an atomic write boundary. In this case, split to be start/end-aligned with the boundary. We need to ignore lim->max_sectors since to may be less than bio->write_atomic_unit, which we cannot tolerate. Signed-off-by: John Garry --- block/bio.c | 7 +++- block/blk-merge.c | 84 ++++++++++++++++++++++++++++++++++----- include/linux/blk_types.h | 2 + 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/block/bio.c b/block/bio.c index fd11614bba4d..fc2f29e1c14c 100644 --- a/block/bio.c +++ b/block/bio.c @@ -247,6 +247,7 @@ void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table, unsigned short max_vecs, blk_opf_t opf) { bio->bi_next = NULL; + bio->atomic_write_unit = 0; bio->bi_bdev = bdev; bio->bi_opf = opf; bio->bi_flags = 0; @@ -815,6 +816,7 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp) bio->bi_ioprio = bio_src->bi_ioprio; bio->bi_iter = bio_src->bi_iter; + bio->atomic_write_unit = bio_src->atomic_write_unit; if (bio->bi_bdev) { if (bio->bi_bdev == bio_src->bi_bdev && bio_flagged(bio_src, BIO_REMAPPED)) @@ -1273,7 +1275,10 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) nr_pages = DIV_ROUND_UP(offset + size, PAGE_SIZE); - trim = size & (bdev_logical_block_size(bio->bi_bdev) - 1); + if (bio->atomic_write_unit) + trim = size & (bio->atomic_write_unit - 1); + else + trim = size & (bdev_logical_block_size(bio->bi_bdev) - 1); iov_iter_revert(iter, trim); size -= trim; diff --git a/block/blk-merge.c b/block/blk-merge.c index 6460abdb2426..95ab6b644955 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -171,7 +171,17 @@ static inline unsigned get_max_io_size(struct bio *bio, { unsigned pbs = lim->physical_block_size >> SECTOR_SHIFT; unsigned lbs = lim->logical_block_size >> SECTOR_SHIFT; - unsigned max_sectors = lim->max_sectors, start, end; + unsigned max_sectors, start, end; + + /* + * We ignore lim->max_sectors for atomic writes simply because + * it may less than bio->write_atomic_unit, which we cannot + * tolerate. + */ + if (bio->bi_opf & REQ_ATOMIC) + max_sectors = lim->atomic_write_max_bytes >> SECTOR_SHIFT; + else + max_sectors = lim->max_sectors; if (lim->chunk_sectors) { max_sectors = min(max_sectors, @@ -256,6 +266,22 @@ static bool bvec_split_segs(const struct queue_limits *lim, return len > 0 || bv->bv_len > max_len; } +static bool bio_straddles_boundary(struct bio *bio, unsigned int bytes, + unsigned int boundary) +{ + loff_t start = bio->bi_iter.bi_sector << SECTOR_SHIFT; + loff_t end = start + bytes; + loff_t start_mod = start % boundary; + loff_t end_mod = end % boundary; + + if (end - start > boundary) + return true; + if ((start_mod > end_mod) && (start_mod && end_mod)) + return true; + + return false; +} + /** * bio_split_rw - split a bio in two bios * @bio: [in] bio to be split @@ -276,10 +302,15 @@ static bool bvec_split_segs(const struct queue_limits *lim, * responsible for ensuring that @bs is only destroyed after processing of the * split bio has finished. */ + + struct bio *bio_split_rw(struct bio *bio, const struct queue_limits *lim, unsigned *segs, struct bio_set *bs, unsigned max_bytes) { + unsigned int atomic_write_boundary = lim->atomic_write_boundary; + bool atomic_write = bio->bi_opf & REQ_ATOMIC; struct bio_vec bv, bvprv, *bvprvp = NULL; + bool straddles_boundary = false; struct bvec_iter iter; unsigned nsegs = 0, bytes = 0; @@ -291,14 +322,31 @@ struct bio *bio_split_rw(struct bio *bio, const struct queue_limits *lim, if (bvprvp && bvec_gap_to_prev(lim, bvprvp, bv.bv_offset)) goto split; + if (atomic_write && atomic_write_boundary) { + straddles_boundary = bio_straddles_boundary(bio, + bytes + bv.bv_len, atomic_write_boundary); + } if (nsegs < lim->max_segments && bytes + bv.bv_len <= max_bytes && - bv.bv_offset + bv.bv_len <= PAGE_SIZE) { + bv.bv_offset + bv.bv_len <= PAGE_SIZE && + !straddles_boundary) { nsegs++; bytes += bv.bv_len; } else { - if (bvec_split_segs(lim, &bv, &nsegs, &bytes, - lim->max_segments, max_bytes)) + bool split_the_segs = + bvec_split_segs(lim, &bv, &nsegs, &bytes, + lim->max_segments, max_bytes); + + /* + * We may not actually straddle the boundary as we may + * have added less bytes than anticipated + */ + if (straddles_boundary) { + straddles_boundary = bio_straddles_boundary(bio, + bytes, atomic_write_boundary); + } + + if (split_the_segs || straddles_boundary) goto split; } @@ -321,12 +369,25 @@ struct bio *bio_split_rw(struct bio *bio, const struct queue_limits *lim, *segs = nsegs; - /* - * Individual bvecs might not be logical block aligned. Round down the - * split size so that each bio is properly block size aligned, even if - * we do not use the full hardware limits. - */ - bytes = ALIGN_DOWN(bytes, lim->logical_block_size); + if (straddles_boundary) { + loff_t new_end = (bio->bi_iter.bi_sector << SECTOR_SHIFT) + bytes; + unsigned int trim = new_end & (atomic_write_boundary - 1); + bytes -= trim; + new_end = (bio->bi_iter.bi_sector << SECTOR_SHIFT) + bytes; + BUG_ON(new_end % atomic_write_boundary); + } else if (bio->atomic_write_unit) { + unsigned int atomic_write_unit = bio->atomic_write_unit; + unsigned int trim = bytes % atomic_write_unit; + + bytes -= trim; + } else { + /* + * Individual bvecs might not be logical block aligned. Round down the + * split size so that each bio is properly block size aligned, even if + * we do not use the full hardware limits. + */ + bytes = ALIGN_DOWN(bytes, lim->logical_block_size); + } /* * Bio splitting may cause subtle trouble such as hang when doing sync @@ -355,7 +416,8 @@ struct bio *__bio_split_to_limits(struct bio *bio, const struct queue_limits *lim, unsigned int *nr_segs) { - struct bio_set *bs = &bio->bi_bdev->bd_disk->bio_split; + struct block_device *bi_bdev = bio->bi_bdev; + struct bio_set *bs = &bi_bdev->bd_disk->bio_split; struct bio *split; switch (bio_op(bio)) { diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 347b52e00322..daa44eac9f14 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -303,6 +303,8 @@ struct bio { struct bio_set *bi_pool; + unsigned int atomic_write_unit; + /* * We can inline a number of vecs at the end of the bio, to avoid * double allocations for a small number of bio_vecs. This member From patchwork Wed May 3 18:38:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230540 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 A9ED9C7EE26 for ; Wed, 3 May 2023 20:03:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229825AbjECUDy (ORCPT ); Wed, 3 May 2023 16:03:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229573AbjECUDw (ORCPT ); Wed, 3 May 2023 16:03:52 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CDF18A5F; Wed, 3 May 2023 13:03:43 -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 343HowO3000746; Wed, 3 May 2023 18:39:43 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=Uqi31ACeum0CeAaKd9sxHafDpmMy1GFIOFs8LzI2cOs=; b=mDA2U0pMxz3Z1pE84jLtGiOFOEfs1zcDjyMBve7uzUXkiWhdGCPtPo4vu81cETkQdwBD vv5vJmzW3A9aiTglpGKzQ4SYRLFhPF3/vPgMd/dYbjd9Ytz3XxmD3LEu9FkVcef4zckj wHyHug3yUg9LNv2yGUYzQcJumHw9yd29+uEFqxm5Q9naTGasg+YKbsvkHh5HAAojYquj A4hinEx/GIUCk7US02VpMjf5W99Tv61wUNlWfvpB7u+usI2g6YIYBn10kvgV/WNKwbHb cjcgnPRgtC0e56zoV0P8s3cVdwYWlsoUltZKPpfzcDxCua/ZabCoz05A8onC00qFM2FB TA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8usv0184-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:43 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343HEbSH027489; Wed, 3 May 2023 18:39:42 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8spdsj4e-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Apjeap5SoiJfBN52A4vNa/9Urj2wuUsv4tS7JgACa+8ifPFL3S2yWJWRYDs7hVfIHRvf3Mh/Frnpoj+JIiJ+7Xo6xIv3iOH7s//V1mqFGZPxmIajqofCCGIbMHzFb425SG6gz/ffH3edFdvIDF/6tbyFVgs/qjBBSYWWXs5aAu7hwxyhLxcwHdo6O6/cx7SbgDb3h5eKdTh9gUUwwS9Kq/rH7ucGYjyagCduX2FA72nA6GkxwT3Q2XqJaHrWOSAbKhFkIxlLbjAe4dK5QCrSqqikiLLBB7utAssIwskZJNqW0pL8/khpwddwjIDH3/moZ/lUyTDPK6ztQ//z20NFDg== 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=Uqi31ACeum0CeAaKd9sxHafDpmMy1GFIOFs8LzI2cOs=; b=YEd2lfz0y0ai8Wn5533ZIDJlDuEq0YTjwiJtgTnS7UMHv1U/u33FchSpgja76OeKEg7/y5tp+mK4M1s8v5s4DtJtHHuLE25Uo1APp0vGv7a3aFZIc0ammM9clMtCjUQmRULYL3VMpJr91XpHTDaGzZxKbSw/ReMp1Auule4zn2WktgZyX9ktvcVRU6YHqOWX3ptLlkL2HZydSBMPvlnKuN4QTkBUOUMhEyr2l/8w8EAn2V76DL5fCIczbkc3fAXD10DnpAX/LpGLKEBEJ5CY9FOivjiaAfWfQyavaiJaRL3bJMPeF9TdCILgvDLKS54543RHa4Z0Juz2B6H+ccmI5Q== 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=Uqi31ACeum0CeAaKd9sxHafDpmMy1GFIOFs8LzI2cOs=; b=Jag26nUKIufb3b9m7ArTC+tRTycfwT4VXXkl3WmPrYvL1n0uJz4A/gFStAYs9XQaB5VD7HMF/Ngfn7QmSG1y/XYJeMPdUBMpiQpMRySLQqsD8cdOoa3Ut8dTKllkLxC9z/07eclX20YLXYP9BhTBCMd+V9yewTFoOKFWZNE3Xhg= 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:39 +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:39 +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 09/16] block: Add blk_validate_atomic_write_op() Date: Wed, 3 May 2023 18:38:14 +0000 Message-Id: <20230503183821.1473305-10-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: DS7PR03CA0067.namprd03.prod.outlook.com (2603:10b6:5:3bb::12) 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: 66df7b92-5960-48ff-8ec4-08db4c05c0da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: G0y/8JUiSCgu9U0d3TqAfEStIiz+yD2iOBZyHhGU7iinxrL2uQkRKCWgOcPYI1p7ymPyOGWNTOrtR6w9tX74VlLsjFbXxPS5WFaUrq8SwEhR77HVHcVEFVilica+TQ0hkY6Trf1Kqol8aLg27AI7HM6PA5kCFA7cfFP7XJSlwyy2v4rdBMgKudwZxZ1jAXkl4w6oamfld4nPPYq52yF5Q7SDFkLLsH45KukxIk89LW0dVr8bYeNbJvdAbC0DdDOenWLRRg051aOah6s/7jIICKwxV8jrDF1TRGlmnHJX+c7UyzbWIpyC/wbkleWN/sckzFKQne4gKuy6TKtQFpEFT/LpgQJtgcNap+dFsHP4zfCxzBYPGR5o8qnYR0/zSfMfNe2sORVnVoQ0U/m65WmE4DgE9+S/71+g4juwbpiRnf67TYbYkiEUv75VAqLi9IKbaSOMYBGM4jvAT99KtjOFE9nXlKptlzDGTPOb3mnZ3b9enfVYCm/iEMNpceHfozDog2kE61L6p934vne/yKU8Zx5sfguwtJcfzbVSwPoxQgssmjJ80FAUA5YoyZvjPHj2cqzaokcFpcWUbfUeD4lIfUBKV9/BSl/AhXDqm15lF/8= 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: nqOzxhnvpCvBNV9cv7nnWcuS8LrFXvbOm5bgFMA53/PLyAxPC92NhaP9QoV+xycOAhnuU1s7hqdGqwd8ZMzgqQHJsLi7SuXXcNqgaiYOgvtC7R73aE/FcF9EtHP1gDjgt0WAf7o1Z5HxfuBRkrrDEIlYPAY6VMaTkuImUDXbclvcOidrQKmGwvX+Kki9O7wPP1v5S4gteIpyQH7YG6INsyp1hHk7SG/ARaOuWmvacLgXECfDkyW9mqdbXx6RMt3ydPG30yUOBTpy6uXfcFYv+r7YIhScAirvaBPPHCQ5kkq8lVCPAnWrBNFeP3ZeS00ucXc1weuZ4bM/AVdbQMECx8EEwUzCexhHex49cyLF0EcL24SSRB6bChwE8EBiZ+z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D85wTmfSiiLsFepoBSRvyXwtqDrPjuOuaF87kr1qErAHYP4iSey4ike/1Z2zNQrn93gF7CkhwkklDEBxLenjJIeFcEESihZ/+Mw6HmGDqVGNlFXkRhg/qnLKLG8fD98hcdGmURNk3D X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Kohvrn3oGkxox/AhRwZ8zA4N5Q98SPOf6nwMKSz95BXTMOnjragZLV/w03bZypv1QuhGUnVZWXpwDaVc6UztPfq8LloXBpKMmmTQvaqrID1XheY6Cq/AAYX6jHJHueuPEUF5K0pPeBg7nIfEp6Defy0fiGZKJKaKwEgvwNVOC9nPmCze7nEkw+2glZqqeV11YC1rdUpECjNhM+C1mkO3to6NX3A9v2kM/pbCo/1BrEUhePDqLJaJWogGFPlbMmwVirDUw9QEajs68p0XbYuRlkBvFP5GzvCzLIWHtCicIpgWXSNqxyTz7iusNKgIm9w37hk93fyKroEghaQPdVfdzht7avtgp5S8JPzN4Ee6u7++2CaTrfn9NNRRAa1XQyF6124KteHKGQEOOGPk1sNsfMgCX4mb69jL9OEBrK8ozowFGgmdgZ7u/kvJWMWSItdgU8ShO6cjN0BBemWe973KbDOMLw1Rtssbhn3cElXbSpmWB45pF6QDmG5mgI/di08I+inlLz/FBjMfbe+gmLLKdIHu9pDIbeOtRSj/npxXOtRIhmfdK302RCKlFcBi55qUN3ofI/+ALfBZA3Dr+2oAQeYi9nf33oWM0U0iqBAUmWc5qAxbDyb1K8d7CYwWXqZOpXVI87Ak/oN2lbtq74ngIdqDwwP4BB905+gXLispUlckOJC0WaUrYxqhKQPxyRgLgWFBPiuOKUk1m2C/Ijbos2H1oMgTAxd4y3NHDUWUQcleWlIB6UIdcIhx1OtS8qqrAqKeGpmWMPX43W3YGfRgT9Q5JeppjlQsoQl/9j9eG7lEuwOaOUOYjutAxsh+Y/HUz5X2XcqBcjiZu8q0/ofQJToc+oHNIQWtdvN0fJf6mXWJ1SGvFYEZPlfQ4IQITFxy2icyxW7SqiDqVTI1Hen+XifE9an0fXmrti/IzqCdZvT2CM3QCN+0yobcFfPoKxaXsdgu4Ogi3PWH1MwOkaom6HPjDcDsiym5b1wRz976fpEsn/dI0+A9uw37Aq85UJs/cQ1lBKT2PpeM8KOdzzAKsyEjx0Vj7FLIvU0t38uQ4tZcTSiIA/yDA2tgOwmD4no2vZDpm9ngVohnMoiphSwPl66t6MKJ2FqqY0L1OfWiBxpZY5aCRmyEzWzsVspSY3Rs X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 66df7b92-5960-48ff-8ec4-08db4c05c0da 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:39.8177 (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: vpmqYbHy8//MJlKdiuEubg+PPIjk0bLp9y6MOCmbJhLccNq2k4qSkHkwirpRHcjlmLR8qlQEENzk3feQc3AGjQ== 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 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-ORIG-GUID: vIfSSdPp-NrN1NAR2gTgwLEFpUhWkGP3 X-Proofpoint-GUID: vIfSSdPp-NrN1NAR2gTgwLEFpUhWkGP3 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Validate that an atomic write bio size satisfies atomic_write_unit_min and atomic_write_unit and that the sector satisfies atomic_write_unit. Also set REQ_NOMERGE - we do not support it yet. Signed-off-by: John Garry --- block/blk-core.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index 42926e6cb83c..91abf8cc2b62 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -591,6 +591,27 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q, return BLK_STS_OK; } +static blk_status_t blk_validate_atomic_write_op(struct request_queue *q, + struct bio *bio) +{ + struct queue_limits *limits = &q->limits; + + if (bio->bi_iter.bi_size % bio->atomic_write_unit) + return BLK_STS_IOERR; + + if ((bio->bi_iter.bi_size >> SECTOR_SHIFT) % + limits->atomic_write_unit_min) + return BLK_STS_IOERR; + + if (bio->bi_iter.bi_sector % limits->atomic_write_unit_min) + return BLK_STS_IOERR; + + /* No support to merge yet, so disable */ + bio->bi_opf |= REQ_NOMERGE; + + return BLK_STS_OK; +} + static void __submit_bio(struct bio *bio) { struct gendisk *disk = bio->bi_bdev->bd_disk; @@ -770,6 +791,13 @@ void submit_bio_noacct(struct bio *bio) bio_clear_polled(bio); switch (bio_op(bio)) { + case REQ_OP_WRITE: + if (bio->bi_opf & REQ_ATOMIC) { + status = blk_validate_atomic_write_op(q, bio); + if (status != BLK_STS_OK) + goto end_io; + } + break; case REQ_OP_DISCARD: if (!bdev_max_discard_sectors(bdev)) goto not_supported; From patchwork Wed May 3 18:38:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230539 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 1588EC77B75 for ; Wed, 3 May 2023 20:03:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229514AbjECUDj (ORCPT ); Wed, 3 May 2023 16:03:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjECUDi (ORCPT ); Wed, 3 May 2023 16:03:38 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A4777DBD; Wed, 3 May 2023 13:03:36 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HoZaE024249; Wed, 3 May 2023 18:39:48 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=6mPv6eOU8ryp+NvgTR5LIqhwUlXegmHvF4DUl/Hq4K4=; b=GjxhuqNP2CZniIyG9pYMxiFCsnnkWTSXcKNS4ZRrQtxQP5Wz15rJP8DeMaj5DOuAg3br ncVE/16E2Tlx70ToWPbvVf602+il4qNp+QoYFYysib8ZwYKMf8KFCdNAfVfcB6o1Ff74 3KGA4XD4ivWwDuZ2lWTEde+JabjIMIMthhFFJf2fYz19qOTe1skDGuQKirs6s04stD25 8dmM75lQXRdtOi6DYBm6odypz60EuOfrHLySneRMQfi9XMWbJ1019ZAS9nxMCJPZlclz PngMgkyyuXJMM/b4lnllcGlYeaGQL0GKV8D56DPT/t0/A9EXwNwRYkG8jdTExevwmixA 8A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8su1r3n2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:48 +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 343HABrT020757; Wed, 3 May 2023 18:39:47 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2176.outbound.protection.outlook.com [104.47.59.176]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp7g9ua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KWb+yCtC5ZDbfV1WM9wT0EhTXQpzTmiZmJFPUiYwaWL8++4S5PEenmgUNhFwhnmWU52qYdtcvEZs0SEd/r/vhf7pwD3686l2aHezaLENGk8DnEvHH1I2S2ig4LQT5+NnaNqGdmZSiqOwwKZMGZVJttKps9QxojWsOHYFGdNxxCjx+zLGNWgDOmkvIRQDkyAST7qVt0767QfLjkkofd/rIng4tytIQBcf9Juz0kXVwC/v6qJTLZAbY+/6Cov22E/h0uEeJD4tNSFrX+1MoTcT+1yY2ghW763hs8pYRb2M46d2UcQVJLt9qAMbQVI9FO+P+H8XdQxgdiaLQpT9/Tlazw== 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=6mPv6eOU8ryp+NvgTR5LIqhwUlXegmHvF4DUl/Hq4K4=; b=PkMGWmRQs/2RxTmB+y/b+RUMa3ZuzDhBdRBMWUkfN2gF9r3KQGKRdNR/fH1osvLAFYcrSAxJfyjssUbMBG96WS9HJhv2XQCJyOKDn6jLmyIbCFyMkRjitg1wOtxMk6upYtatX0292ys/Rhe7Q6n4erQtfsuJXILBYWGTXQVIYCYkdNA5P/q6w8Uadw+u5Tsx6eccJBhNgkxbxYdvO4hwKplhnb+IdpHZsDJJPe1ymTyH7uAt6kqjBEhf/uKie3dXkKy66gddAlGgQQ5ec49Ez+SVXcxOmj2R8DSUKhqHC/WxLemAmYVCz9yytBrdGGA03dVeR2OLSUnJ91s2b/j47A== 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=6mPv6eOU8ryp+NvgTR5LIqhwUlXegmHvF4DUl/Hq4K4=; b=GxumOssUq7/HDIt4W4xDG9K9nzTdR7EX3OTCHtjfOxG2tGTaS1Cb7kmkpYHtUvZA4yewJbvJ4Pst1k4lHFq7LE519m2t23du/JDQoT1Gi7MxAKko4Ix+Jauh3TLT9M7T5cpJFaZd8P5bUk32h/0hVoVwlfYN8dshPOhQS+nf//I= 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:45 +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:44 +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 10/16] block: Add fops atomic write support Date: Wed, 3 May 2023 18:38:15 +0000 Message-Id: <20230503183821.1473305-11-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: AM0PR10CA0005.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:17c::15) 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: 1ef1e3c7-8663-4807-d0d6-08db4c05c3cb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IQXioYQkvS2bketECbnPbfm74H/oQKPZSTPz/mrCkvzOsHwjT9jId5rXwb6Ll04mg42J9My3kZutOB80DsRSSlMtIZjp4pttdBfjIlSCriwtpwJxgWYBasOUccur/815ScAiR8y/D1vrfRh65ACaiY/6ksLUNt1Nyi2Xcs4k4zjITf567kzqmyBvuJm7Ra+W+vmPITAe04f9jkXYi/lUrAvnWO3SNDBYt7+Zd2OzYVJea5hxORXvy9qSutCfTFADt/dv2jwI1S5MOhBcFpiaX/YR1FayYKmtMidfdtfAt3N9B0TVSgvsCqZ2hyF0PN6dXZthKoluifLasPkb7dH2lBvr8IjnFVsJlX503Sj70pd2MPxen7JyE6S0fEXEEwTeuyGHvMcCXncDlQcd4Ac2rwrJmtF5Yc7yGKDq998928OV0ZM30ZRRoA8d9T3RU8DWe/9dcfE3oL5U0/H8ryeL+Nbqx9mrcEwMRmy9dE9/PVHJojTVsX2VPHqUAGJHqzMazN/2oRzOAurwMnX6TR6iMaoY67QpUIPezs87EFDcVMOCNMQve35FD0nzXDKRmtbiwWc9vHajAfEJNslZBwT4GmJnIkC9/VmIvrVlayXPd0Q= 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: hUV1jHIo2jy0PL2FnjiNjv6SiOv1u9DdChFIpKtkESt1iwZ0lJDPY4AVPNaif0UiwG4gfFsGupAVhsb+lo4AD6+Npr46xIiLwmQvLdH7coHERbCJkAD9Ab89N2L9VLjrhNhGAYqtHu72Mg1LPrPWnPfh+h+DQdzC5XoJE50KxzQfNVoKFmltDqiH8bsSb1dhDTeFRFk9bMxS0jRD7JQKAe7oi/6/vVrs4t9xwSLoaQ86qQVoQy2EUJOHApXa1Tpquyyp0/sNQl0Od0FgjZjHjChUO9MDGdqdD+IPo03xI5TxtzNVKl4snuvcGt4ZyS2WUFGobW0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62pP8K+mFmzbXrsLc/bzXYQ0ofnwVgVv98GHGNj96OoWe0CAKLj/kXucSSm88I8qckSamOW72iA9MI2XYk5Pa1ZSmJHkWlo/A/LzV+UglvVmPptqIfrEzGfI7UPaZxXdDDR/dGrJqkRkUwTx2AlTVQB0DetM1o6FIlNxkKmwuGp1YFD5X46cTzWK X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: cl8QuDRI0am97//c1FncTYNQud3uWsKZIj3NIKsOOB5yD6/pTW+s7wmzULtU6zM9ernRTFClj0+P4vnbfGOcypVNhDNqXJ2X7tm/FHWBUi3Fpevsg5+NaJsJPEzaimX36LbwEIjmtKcfFbYFDdQ/IcjOQ9lmyhRT47DEj8et9wHdtDKxvrtjhRPgJHvcXpeaiIVmpEAXs2iRO3sYAqIJqgE7ub9MIf74n+nUspzPA0xVr3bKvxK3KEohelPleuefihUGFuRk4otp14nVKQJdrSf2QfD3WezDoxMOUBsdvtNMKXmMMFB8+XzDqt1vqIAYhgJYsDgqR1syojk+E1HH0S/ip4N5oYQtKubTJytPd3hv3zG+5VBvgI8HFqHR0sUy2HGyjsLryE3jEBc+VxNBAWeej+TFqXz/s/MIuvTMGI+o7SLD1YYf3MyPNdGCvospLOf/8hQn1Gkn3kxOdsxzvir1OEUm3X0n06PZp/ssXMTVbVWg+Okkc4B+x5QEDx2gxp/sFAbyP6E6R2E7usRosd86tFhyJDD7jF6GhPij+IC0YC29AJ/88Qkgh9AyCTIszBmxAujTG36EnxdIWkmymyrh0nXbUDfWzuIESUU/l0/wPPQXmcXJkZHODgS3GR9vsJJpJzEslckxWMiWa6ukGajZTrhurZCGUZm0JbwZ/IX4yhDckQapdrskTRt61BxXekX3kx1smEbTpHa/Uy2nNebTP287GVpq9BJGkqnFhf1b0N22oD34JvHjGxF9FTmXv3O3P7YevwuniXq2y2/UCjHKH0lV11nNRUwOvuE2CvER2jhdWpDS6NB3FsZoqRfTd94nqFcogXLPwtZLX0GHJM3RVXUj877WrMFLCDahccOM8MP7p6QJV5v8WF0ZbmyY5ka+kHljrTSmR6yC4TLGngv5OvM82OMV3YdHvhmVlq5VDTLQbj1rBQhV0DdQd6vnUP4m+rH6u+llo+LHukS5cu121TEqWHyyf/uEASahdFcNGjavNDfjakVNdQCCBQz3Q1EqWaNhCzEz5XnKPP0H1/qqRSlYXGJAqhowm++poICXt1mzVHHBFN/3pdS3j4Qpg9x3Ue3VrlUYqIdpVUYzK0w9Mpl5qd16NB0dyJq5CZUgR1ybncRHhlHY3swKpqvx X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ef1e3c7-8663-4807-d0d6-08db4c05c3cb 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:44.8722 (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: jHUTRoNIHfVZrU8zx+D6DQyhrxBg8x5CoXdQJQ4V7+rWYz8oijEd8qxKxL03/AF6fbo/zxtCIxuqBus6GtQAxw== 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-GUID: p-bjNdDG3RxZgFULqNXCe-D9R7uDw_y5 X-Proofpoint-ORIG-GUID: p-bjNdDG3RxZgFULqNXCe-D9R7uDw_y5 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add support to set bio->atomic_write_unit Signed-off-by: John Garry --- block/fops.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/block/fops.c b/block/fops.c index d2e6be4e3d1c..9a2c595cd93d 100644 --- a/block/fops.c +++ b/block/fops.c @@ -43,8 +43,17 @@ static blk_opf_t dio_bio_write_op(struct kiocb *iocb) } static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos, - struct iov_iter *iter) + struct iov_iter *iter, bool atomic_write) { + if (atomic_write) { + unsigned int atomic_write_unit_min = + queue_atomic_write_unit_min(bdev_get_queue(bdev)); + if (pos % atomic_write_unit_min) + return false; + if (iov_iter_count(iter) % atomic_write_unit_min) + return false; + } + return pos & (bdev_logical_block_size(bdev) - 1) || !bdev_iter_is_aligned(bdev, iter); } @@ -56,12 +65,21 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, { struct block_device *bdev = iocb->ki_filp->private_data; struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS], *vecs; + bool is_read = iov_iter_rw(iter) == READ; + bool atomic_write = (iocb->ki_flags & IOCB_ATOMIC) && !is_read; + unsigned int max_align_bytes = 0; loff_t pos = iocb->ki_pos; bool should_dirty = false; struct bio bio; ssize_t ret; - if (blkdev_dio_unaligned(bdev, pos, iter)) + /* iov_iter_count() return value will change later, so calculate now */ + if (atomic_write) { + max_align_bytes = bdev_find_max_atomic_write_alignment(bdev, + iocb->ki_pos, iov_iter_count(iter)); + } + + if (blkdev_dio_unaligned(bdev, pos, iter, atomic_write)) return -EINVAL; if (nr_pages <= DIO_INLINE_BIO_VECS) @@ -73,7 +91,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, return -ENOMEM; } - if (iov_iter_rw(iter) == READ) { + if (is_read) { bio_init(&bio, bdev, vecs, nr_pages, REQ_OP_READ); if (user_backed_iter(iter)) should_dirty = true; @@ -82,6 +100,10 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, } bio.bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio.bi_ioprio = iocb->ki_ioprio; + if (atomic_write) { + bio.bi_opf |= REQ_ATOMIC; + bio.atomic_write_unit = max_align_bytes; + } ret = bio_iov_iter_get_pages(&bio, iter); if (unlikely(ret)) @@ -175,11 +197,19 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, struct blkdev_dio *dio; struct bio *bio; bool is_read = (iov_iter_rw(iter) == READ), is_sync; + bool atomic_write = (iocb->ki_flags & IOCB_ATOMIC) && !is_read; blk_opf_t opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb); + unsigned int max_align_bytes = 0; loff_t pos = iocb->ki_pos; int ret = 0; - if (blkdev_dio_unaligned(bdev, pos, iter)) + /* iov_iter_count() return value will change later, so calculate now */ + if (atomic_write) { + max_align_bytes = bdev_find_max_atomic_write_alignment(bdev, + iocb->ki_pos, iov_iter_count(iter)); + } + + if (blkdev_dio_unaligned(bdev, pos, iter, atomic_write)) return -EINVAL; if (iocb->ki_flags & IOCB_ALLOC_CACHE) @@ -214,6 +244,8 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, bio->bi_private = dio; bio->bi_end_io = blkdev_bio_end_io; bio->bi_ioprio = iocb->ki_ioprio; + if (atomic_write) + bio->atomic_write_unit = max_align_bytes; ret = bio_iov_iter_get_pages(bio, iter); if (unlikely(ret)) { @@ -244,8 +276,11 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, if (dio->flags & DIO_SHOULD_DIRTY) bio_set_pages_dirty(bio); } else { + if (atomic_write) + bio->bi_opf |= REQ_ATOMIC; task_io_account_write(bio->bi_iter.bi_size); } + dio->size += bio->bi_iter.bi_size; pos += bio->bi_iter.bi_size; @@ -313,14 +348,21 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, struct block_device *bdev = iocb->ki_filp->private_data; bool is_read = iov_iter_rw(iter) == READ; blk_opf_t opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb); + bool atomic_write = (iocb->ki_flags & IOCB_ATOMIC) && !is_read; + unsigned int max_align_bytes = 0; struct blkdev_dio *dio; struct bio *bio; loff_t pos = iocb->ki_pos; int ret = 0; - if (blkdev_dio_unaligned(bdev, pos, iter)) + if (blkdev_dio_unaligned(bdev, pos, iter, atomic_write)) return -EINVAL; + if (atomic_write) { + max_align_bytes = bdev_find_max_atomic_write_alignment(bdev, + iocb->ki_pos, iov_iter_count(iter)); + } + if (iocb->ki_flags & IOCB_ALLOC_CACHE) opf |= REQ_ALLOC_CACHE; bio = bio_alloc_bioset(bdev, nr_pages, opf, GFP_KERNEL, @@ -331,6 +373,8 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, bio->bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio->bi_end_io = blkdev_bio_end_io_async; bio->bi_ioprio = iocb->ki_ioprio; + if (atomic_write) + bio->atomic_write_unit = max_align_bytes; if (iov_iter_is_bvec(iter)) { /* @@ -355,6 +399,8 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, bio_set_pages_dirty(bio); } } else { + if (atomic_write) + bio->bi_opf |= REQ_ATOMIC; task_io_account_write(bio->bi_iter.bi_size); } From patchwork Wed May 3 18:38:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230464 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 C64E4C7EE29 for ; Wed, 3 May 2023 18:40:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229947AbjECSkn (ORCPT ); Wed, 3 May 2023 14:40:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbjECSk2 (ORCPT ); Wed, 3 May 2023 14:40:28 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0850C72A5; Wed, 3 May 2023 11:40:13 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HooCI017481; Wed, 3 May 2023 18:39:53 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=lvqx8GUfu4cSwEIYiUW6w2zBGGM0MZkm6cA9ZdS9qqE=; b=TEiRPVkE4l/q6studKoxHheT/timOUUagFAPXeaNzH0ISv95JhlVb5lTF/nrQhOnwkeQ WX6nJZQjZhFkinsnRu+FXXIif6JaTQdwstvrqiQ9D18us807ueT0rfpvvH1HuUYYOWFP VaJc9TxJPNI3Bk4JQxHQ9DlcABONUQtVrMx6Oe1HFH815HKbePn5SpG98oR5F0NWVeoZ ZMHNfdShUg+1wJM9jGVMkwACWNKxjdRj8h5v3b+ZFSuZR5XW20eA5hdStVlEFkjsztP7 Vn3b7eiIAUHfpsKMcfs7TRApx5PSFqqkWk1khC55Twebv46ZV4QN4cKD2CdB/dwWtPQV ag== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8u4aqygn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:53 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343H3gfp010067; Wed, 3 May 2023 18:39:52 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp805p9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N1i5uqp58yWLmTE8L1Ui2Eloy6hhQ/smBUIdWB6Cm6gPbvOxbOOCwEqs+PI/U5R+yldrjBuhjfWdr+d4g4gwo+x9yawnzfniZcKEZtLjn5vfg8n3iGsYbu7NWP3G2gsfpuHm7A7hLHdmvoVQQBSDPUzovbpOVwgk8QFWVxjg43eMj9yEPqgV4vql6hc1x6tVV4+04AV/fWVDP5DHpgLYhfKzv4yXrGavnF9UHks6nhFutjetnR/3BWMLiZ8rvPYh/Ee04qTNq1F8J1ddXdb462OGGIdvikK18V6AGyxMT9uyYQPaN4L5As8CE4pNi6aZABL0QeHbtO3gud32BBCBAQ== 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=lvqx8GUfu4cSwEIYiUW6w2zBGGM0MZkm6cA9ZdS9qqE=; b=gplbmRlUOcQtsJdU0l2NKkKWKWs69dcxWBB/VopL5OsXVnbrey86lJDU5dFY+6GnU+g+uvhux2HrLtYg239j7X3iiklJ7GmLYL/ykJrG2zaI9x0bnKQ4ZeyOQjLMmv9fW4xlipyzYY0iqgiNwqwRY7F9YIfGwlvG6HhSadbCR+eYjO+o4OIErLcqPAbHgcGgiQg3z1yuLcnsbcFdZticneno+C3NYTL/qY9aCI5U+Njh5VJldosz/a69wdpBchqz07dkarhwII5foIJlHjugJNrI7n0syDrV2AZSRaMu44J1fZvXtDwDWQ0xWT5RRfBqDv7Dvq9ICYXL0vwQ/t83Yw== 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=lvqx8GUfu4cSwEIYiUW6w2zBGGM0MZkm6cA9ZdS9qqE=; b=Ax4gGPsthr5syLZPDQohteRXIkobI94mhlim+FbzwN8d17Ekk1PGiR6m+e2IG0xq1OZ9j4qmZ+Jw81TgTv5PfRFk7VadIwSe4yYkMyqkMzhixP0VBYNuIIaEv4rWp5vZzmyoFnq76LgfIbx+i+zdlTNQtKKHcL0Q9jdN/JWdfNY= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB5677.namprd10.prod.outlook.com (2603:10b6:303:18b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 18:39:50 +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:50 +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 11/16] fs: iomap: Atomic write support Date: Wed, 3 May 2023 18:38:16 +0000 Message-Id: <20230503183821.1473305-12-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: AM0PR04CA0013.eurprd04.prod.outlook.com (2603:10a6:208:122::26) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB5677:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d74b584-661f-4046-d34e-08db4c05c6ff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vVUfWohHGOhBwq/Cc9WZtHvMtqQR8PmS3BPKGggrhNuIiQKxYIVAueULLqI/QZvZTIL2t0omFYAWXvCP/M8tjv0wUC7Ieuf3J3b+GFq+/DJGPCcIjsNFuq9Yw9Js9iYPLgSX02Ipr7gx6c1rvzNur642JD1pD1Qv/Zr4AHlA8UgcjunEHmWk0wc++l2hPJQ6EYfe46of/60u+DP4Gem8VgXdgIoehQjUlPR+gW6DnKal2pVGI/7deuepGvi7iVybc0XAXioeLY1a47g5wEskSNnL2ck1kR6dCeu7FwQjwCSWYv9qRSr0kdAS9W3B6THHxgFejCFrjFq9I2Bz4ppJEbo5DB/gGmeje5inxj/HATXisYfqiVGNQXQ+NpFv2WTmQrqnvmLrTB9vmkDr6olNdspHNDMjS3sRrHYPI6Kf7zSf/njQqnb/qTPC4n4AkIAmJNcUYRbVLrI5YCMGATbMAsqD9+C4GJJy0vIDdmidnOcAbX66sLrq1TEoEjgT8YlRM5gCc2dFc7Zlox45YHYBJrfAWv4YGNywy8zFkuw2IqPFdf5G7AizCEuRG4u1Zl6fjRrUK5SHYYwBMB1K8hM/oNY2HMa51CrccqohiKY4RDc= 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)(376002)(366004)(396003)(39860400002)(136003)(451199021)(2616005)(6506007)(1076003)(107886003)(6512007)(26005)(41300700001)(38100700002)(6666004)(83380400001)(186003)(6486002)(478600001)(66556008)(921005)(4326008)(316002)(66476007)(5660300002)(66946007)(2906002)(7416002)(8676002)(36756003)(86362001)(103116003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gaGPNPmBDoYN5/X48GUnB86NI2crtTSw7+pf2cm8P+bra3+pZBDFGeQDXuuyw7OxugOKD8l2zU77HFhmbXkabBzahuzwIL119f3ARbHp35nHcP1wleEMZtU9uLFWOKxV9T4Q85E7f3kimcn8WZwpO4SFSil1n6YJNxwNMCIunXQoSPXSLwdjrp29ky4tJwovQ7gQLLDN11IwNOR+6zaOgqHmfYUaylNCgnd8FZZUuDUgNFYTbY3ipGabjAR5/7gECJ5sEM4K2ot3wGsodZhUkR3ci5Yw4ufPwwGCvs2RyJtU6G/raZYoRrW8UJLZca3UNYp8fRwbqWW+BzKQy1pGKzF0OF0QXQuSZHMGhc/7X7CGvK1rp2kmtpC+a8byZMdXBOkpjHEXT3Av25CPzjhRuHoS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qVUGyPYKSGJGh5NCsnWFs28J7XDSXN/kEjcchON5ABUOk+ypXwX9H+ZYbZfHMuWA1LoUgRbNNvsvgJ4PZi5C6xk5zo81ZUoJAfIuuSsEdje/sTtueLLHbrzqTNece1nCPVrMCbhxdf4oX0s+VZUi0yd4sbaKioWJ1pFiceUWwoppzbKmFyuDteACJXzGBRIWvZW2T9P35LD4kWAtjhCbLehrai4lQLv4xT7nqu6p/tp+jK3xaB0PcSDKXLW2bFVTF4Ae X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d74b584-661f-4046-d34e-08db4c05c6ff 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:50.2452 (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: 0qMKPZ4jI0QWpQ35W5ip5hGmB7ND0/KA2g5S9UciZSr+yBvhOQIRRFeba6fOKGPuzZQGVfNY7JyaniW1Ubi9wQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB5677 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 adultscore=0 phishscore=0 spamscore=0 mlxlogscore=971 bulkscore=0 suspectscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-GUID: wcMl6Sz-pT9PVe-ByDhJaESc_Gyt4HsL X-Proofpoint-ORIG-GUID: wcMl6Sz-pT9PVe-ByDhJaESc_Gyt4HsL Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add support to create bio's whose bi_sector and bi_size are aligned to and multiple of atomic_write_unit, respectively. When we call iomap_dio_bio_iter() -> bio_iov_iter_get_pages() -> __bio_iov_iter_get_pages(), we trim the bio to a multiple of atomic_write_unit. As such, we expect the iomi start and length to have same size and alignment requirements per iomap_dio_bio_iter() call. In iomap_dio_bio_iter(), ensure that for a non-dsync iocb that the mapping is not dirty nor unmapped. Signed-off-by: John Garry --- fs/iomap/direct-io.c | 72 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index f771001574d0..37c3c926dfd8 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -36,6 +36,8 @@ struct iomap_dio { size_t done_before; bool wait_for_completion; + unsigned int atomic_write_unit; + union { /* used during submission and for synchronous completion: */ struct { @@ -229,9 +231,21 @@ static inline blk_opf_t iomap_dio_bio_opflags(struct iomap_dio *dio, return opflags; } + +/* + * Note: For atomic writes, each bio which we create when we iter should have + * bi_sector aligned to atomic_write_unit and also its bi_size should be + * a multiple of atomic_write_unit. + * The call to bio_iov_iter_get_pages() -> __bio_iov_iter_get_pages() + * should trim the length to a multiple of atomic_write_unit for us. + * This allows us to split each bio later in the block layer to fit + * request_queue limit. + */ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, struct iomap_dio *dio) { + bool atomic_write = (dio->iocb->ki_flags & IOCB_ATOMIC) && + (dio->flags & IOMAP_DIO_WRITE); const struct iomap *iomap = &iter->iomap; struct inode *inode = iter->inode; unsigned int fs_block_size = i_blocksize(inode), pad; @@ -249,6 +263,14 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, !bdev_iter_is_aligned(iomap->bdev, dio->submit.iter)) return -EINVAL; + + if (atomic_write && !iocb_is_dsync(dio->iocb)) { + if (iomap->flags & IOMAP_F_DIRTY) + return -EIO; + if (iomap->type != IOMAP_MAPPED) + return -EIO; + } + if (iomap->type == IOMAP_UNWRITTEN) { dio->flags |= IOMAP_DIO_UNWRITTEN; need_zeroout = true; @@ -318,6 +340,10 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, GFP_KERNEL); bio->bi_iter.bi_sector = iomap_sector(iomap, pos); bio->bi_ioprio = dio->iocb->ki_ioprio; + if (atomic_write) { + bio->bi_opf |= REQ_ATOMIC; + bio->atomic_write_unit = dio->atomic_write_unit; + } bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; @@ -492,6 +518,8 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, is_sync_kiocb(iocb) || (dio_flags & IOMAP_DIO_FORCE_WAIT); struct blk_plug plug; struct iomap_dio *dio; + bool is_read = iov_iter_rw(iter) == READ; + bool atomic_write = (iocb->ki_flags & IOCB_ATOMIC) && !is_read; if (!iomi.len) return NULL; @@ -500,6 +528,20 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, if (!dio) return ERR_PTR(-ENOMEM); + if (atomic_write) { + /* + * Note: This lookup is not proper for a multi-device scenario, + * however for current iomap users, the bdev per iter + * will be fixed, so "works" for now. + */ + struct super_block *i_sb = inode->i_sb; + struct block_device *bdev = i_sb->s_bdev; + + dio->atomic_write_unit = + bdev_find_max_atomic_write_alignment(bdev, + iomi.pos, iomi.len); + } + dio->iocb = iocb; atomic_set(&dio->ref, 1); dio->size = 0; @@ -513,7 +555,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->submit.waiter = current; dio->submit.poll_bio = NULL; - if (iov_iter_rw(iter) == READ) { + if (is_read) { if (iomi.pos >= dio->i_size) goto out_free_dio; @@ -567,7 +609,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, if (ret) goto out_free_dio; - if (iov_iter_rw(iter) == WRITE) { + if (!is_read) { /* * Try to invalidate cache pages for the range we are writing. * If this invalidation fails, let the caller fall back to @@ -592,6 +634,32 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, blk_start_plug(&plug); while ((ret = iomap_iter(&iomi, ops)) > 0) { + if (atomic_write) { + const struct iomap *_iomap = &iomi.iomap; + loff_t iomi_length = iomap_length(&iomi); + + /* + * Ensure length and start address is a multiple of + * atomic_write_unit - this is critical. If the length + * is not a multiple of atomic_write_unit, then we + * cannot create a set of bio's in iomap_dio_bio_iter() + * who are each a length which is a multiple of + * atomic_write_unit. + * + * Note: It may be more appropiate to have this check + * in iomap_dio_bio_iter() + */ + if ((iomap_sector(_iomap, iomi.pos) << SECTOR_SHIFT) % + dio->atomic_write_unit) { + ret = -EIO; + break; + } + + if (iomi_length % dio->atomic_write_unit) { + ret = -EIO; + break; + } + } iomi.processed = iomap_dio_iter(&iomi, dio); /* From patchwork Wed May 3 18:38:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230465 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 ADC9FC7EE21 for ; Wed, 3 May 2023 18:42:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230158AbjECSmb (ORCPT ); Wed, 3 May 2023 14:42:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbjECSki (ORCPT ); Wed, 3 May 2023 14:40:38 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A284E6E8F; Wed, 3 May 2023 11:40:29 -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 343Howes000742; Wed, 3 May 2023 18:40:01 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=+Cp1sxUB/MNfv+6Q3qg8WcBvazGRnue6fiNhdmifPJE=; b=cJGMlmHHa8IQXCP0o7UbYmVdhnIOUXeaocLowqo7qSOgvPfij4uJavoNGbObPNil4JJG 68Zu1rxDaBOUFzVoySqFd4YAGSweNMiU8MiYV5Lw1ufvch5JbL72jI5TiY3yC11N0hNr XQHymNdb/mwEa7pSJ4EsEmiw9CVKmsqw0KA/1/Gu0989nEg8cmJoHGXuZxejRkboU1W3 2Skj5KhFsjR3HznhIiUyiDRDbCeAcDJ+zQGapjWyJcQtJ51C6BOKR+e9PSNFT0vXgGpL tltFbxBDufTG88+Ruzi510u0KGqYmSmnpddqAndM/0Zt26CYi01y6nUVpdM4TqUVmzGc TQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8usv0196-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:40:00 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343H6LBT026767; Wed, 3 May 2023 18:39:59 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2103.outbound.protection.outlook.com [104.47.55.103]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8spdsctk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:39:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aoKPuytrqutrt2yYIQzxP6x7U9PPO2TbzJlmNR+99iyoyG7f7Ni9Of+/xVsmoYW56hn1rsKF85UrGVQL8hEXHQC/am6mRAyquuZOeDHK0v4QnUivirQo0YXyi0g9yLRdVb0GsbfTdPUZ1U7K3a6neUYtRHZgmu/4axw2JU3RpLnSXiqAgDZYGqpHIV50CbKpPbi6AI+VFCnvjCuIFysg81gAbHTLQ6kKfmlZlmzL062pZiZSzTamJkNmHhx/TIZl5vb5XfCfKSZUjxKhLqNecrbJ1bCDmhrxT9Cx9mQ482UMLXGi34+BgOGkk7T4hAEnSfTTx38BcWQtLeBefuuSpw== 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=+Cp1sxUB/MNfv+6Q3qg8WcBvazGRnue6fiNhdmifPJE=; b=mJXDVrEy4z2Ww11WD7K0tnCBOgMaU+hx/EYd4fdhW21809un8XifX5oD6IRyJPJwEwmBJC5xru9oLZ6+oAJazK9dQG46+++3+qOB+cluWfmW7n1BthMXz1tvCeTr9NvSNKkP8bWDqaxztVekFiycXrG9fVOjMFEsisUVa2pbB3tHb2uMsvYX7NEfMIB7Q9v5Y1B/QdQ2CuuOHPlRA4lPDY14V3WobotoTFKWRZFw5BXVKVGRT/qn8mX4f0/s3FuuITSANQg1qosiEuyP9iqJVKrlOGEKrj2p0P3bLzSBQuelV1Lr6z1kzirWgNgSg//1TRA8AWKv8F72gYrNmChUvw== 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=+Cp1sxUB/MNfv+6Q3qg8WcBvazGRnue6fiNhdmifPJE=; b=jTGcPZ0JKV9OIwFYm9YI2+P+0ajQM6nb6YdhfEyo/9zQeuy2YO1OKSHxeEWHGMLJx07ed/KF4eoX3AvmHqDyge5Jyk2qkkRJxRqG1pcKtyUs5yjcj7I2m84hTDF0z9nb4R9w9av2kqYgLdi0hYtsgdj4k7HEiMkNl+aeoQm0cUc= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB5677.namprd10.prod.outlook.com (2603:10b6:303:18b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 18:39:56 +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:56 +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, Allison Henderson , Catherine Hoang , John Garry Subject: [PATCH RFC 12/16] xfs: Add support for fallocate2 Date: Wed, 3 May 2023 18:38:17 +0000 Message-Id: <20230503183821.1473305-13-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: AM3PR07CA0093.eurprd07.prod.outlook.com (2603:10a6:207:6::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_|MW4PR10MB5677:EE_ X-MS-Office365-Filtering-Correlation-Id: aac9dec3-7b02-4b0e-2068-08db4c05ca61 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Poi53n1FcNLAMu8IjGr21vvw7k3fd4ecunOdubcYANt2tJpJav0ks17z8/UfBF5+052+ELHO8N5vzCBGMJX7DVlySy0yFsjsuSoQv2SbKYm0j2Nd9XpJWoVBXSmiRpvHE1uu8Ys9m4Oik22DGalqn81mZFfku0BYHvHkM1/Qn/lD1is0tjNANLBIXp2zBLQ4/QYoutV03q2quhQAM3X6CdIwNbsmehiNq2T9ASQ21vVyycITlulMTFSaZKYuLqWi65V0PW+6BuhRvYB+o4I/JbF7WPksSiszJlSVXietTpBi00vdhsRpuf8FkhMJJBNf7BqYzzdUvgQhaXuSbfgkV18f1Gf2rd4egRhETivynYtQDbaoa56wwH6euBSIAkzLlqqIqQhc3+HwIOXvZxae2tcHqw3I48uMRLmErYZBsEwHOv9hYg+GBKc/0P2wPCkyrL3InLZJwY7dfl5ILv0dSNrTqgKWBGMN8LEauoWaGnARCH4buelLh8ykJPpIPJAwWuRnVfmhxS4cQN4db967ANda6KZrn07pGRmhRvmrS/qp4UQH6TbwiRYvgX4xkUvshc6mqd2XWw5VvIWiMifNhURrtsHSp5FG1BeZkR6rtVo= 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)(376002)(366004)(396003)(39860400002)(136003)(451199021)(2616005)(6506007)(1076003)(107886003)(6512007)(26005)(41300700001)(38100700002)(6666004)(83380400001)(186003)(6486002)(478600001)(54906003)(66556008)(921005)(4326008)(316002)(66476007)(5660300002)(66946007)(2906002)(7416002)(8676002)(36756003)(86362001)(30864003)(103116003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1cETvpVwgqdsrTiaV6DuNT5rHM0NTmOxFCk0Zmj3zbw6bdOaKJw0mlvixqs1beObC2zl2WfvM4kDpGWr0Juhm9ClXEqWttim1/hLl/iLp2NTXJArQqBMP3n4RMr7PY6UAgxmK2eiM/uNjpPvl9jAXYoL75EakJjWv0xOBu4Kt0Tcc34/E6GH4qBYYnHktV3ZtlHv0feS22MCGDpKGUA7dCq+rxQCngL6gy4tXK6WwlxkMy/HgKlSTtwXjydzr1BrpBQPaPZH1o6bVfwijHsTAbtY78mS+tCyjxBd0Rfm0Lfce59LsO+p2Ot7ND06STSzWPVhxpr+vI+3bA/MaLNOqVmiRkp+OLTrp4xAOmIAP5kEEWMY8kpoFNk6Pf7tnQu2XYtLQaPKdsmz4gO5TpZwxadIAmFGYwfX6ftBI9RgK71vIOCqV8viIjeSjgwu2RlOWhqNnKQNPfvi5Fkpm3GvqgDTO3wpy19JcmV/7KFDfbU9kHN+uQTv0EAFzqwR6Pmf5KqyQEbwAD8BiNGCm0UDF/1zbQBTmDhbPZZLWDtVVZTbYWZ217S3BCB3d1DjXGPwfMrVzvDiMFkGR1ofCXahouyIusDgaweJD5gmjQ9sG2TbnQAzfP6zof6LGsSOd2wkSpmu/tm0UoXaC02UUkTSg1tGRhaQk9m6HYQLRDuD/5AQ1Zxlw1qzrYZljQx8NXqIX0hkgAiw6iHQX+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08db4c05ca61 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:55.9669 (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: uN7oGBbexHaDcuEmR5F60qEDuSsdOodfr/9ezHQU8YvZBJg9ibqGRnujOLivUUZJ/4LBRZ1x/yJWzLcsZNPz2w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB5677 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 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-ORIG-GUID: z5mx54VPjaI4ngAjkrmQ0DUg8PlijNWe X-Proofpoint-GUID: z5mx54VPjaI4ngAjkrmQ0DUg8PlijNWe Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Allison Henderson Add support for fallocate2 ioctl, which is xfs' own version of fallocate. Struct xfs_fallocate2 is passed in the ioctl, and xfs_fallocate2.alignment allows the user to specify required extent alignment. This is key for atomic write support, as we expect extents to be aligned on atomic_write_unit_max boundaries. The alignment flag is not sticky, so further extent mutation will not obey this original alignment request. In addition, extent lengths should always be a multiple of atomic_write_unit_max, which they are not yet. So this really just works for scenarios when we were lucky enough to get a single extent. The following is sample usage and c code: mkfs.xfs -f /dev/sda mount /dev/sda mnt xfs_fallocate2 mnt/test_file1.img 0 20971520 262144 filefrag -v mnt/test_file1.img xfs_fallocate2.c struct xfs_fallocate2 { int64_t offset; /* bytes */ int64_t length; /* bytes */ uint64_t flags; uint32_t alignment; /* bytes */ uint32_t padding[9]; }; int main(int argc, char **argv) { char *file; int fd, ret; struct xfs_fallocate2 fa = {}; if (argc != 5) { printf("expected 5 arguments\n"); exit(0); } argv++; file = *argv; argv++; fa.offset = atoi(*argv); argv++; fa.length = atoi(*argv); argv++; fa.alignment = atoi(*argv); argv++; if (fa.alignment) fa.flags = XFS_FALLOC2_ALIGNED; fd = open(file, O_RDWR | O_CREAT, 0600); if (fd < 0) exit(0); ret = ioctl(fd, XFS_IOC_FALLOCATE2, &fa); close(fd); return ret; } Signed-off-by: Allison Henderson Signed-off-by: Catherine Hoang Signed-off-by: John Garry --- fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_attr_remote.c | 2 +- fs/xfs/libxfs/xfs_bmap.c | 9 ++- fs/xfs/libxfs/xfs_bmap.h | 4 +- fs/xfs/libxfs/xfs_da_btree.c | 4 +- fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/xfs_bmap_util.c | 7 ++- fs/xfs/xfs_bmap_util.h | 2 +- fs/xfs/xfs_dquot.c | 2 +- fs/xfs/xfs_file.c | 19 +++++-- fs/xfs/xfs_fs_staging.c | 99 +++++++++++++++++++++++++++++++++ fs/xfs/xfs_fs_staging.h | 21 +++++++ fs/xfs/xfs_ioctl.c | 4 ++ fs/xfs/xfs_iomap.c | 4 +- fs/xfs/xfs_reflink.c | 4 +- fs/xfs/xfs_rtalloc.c | 2 +- fs/xfs/xfs_symlink.c | 2 +- security/security.c | 1 + 18 files changed, 168 insertions(+), 20 deletions(-) create mode 100644 fs/xfs/xfs_fs_staging.c create mode 100644 fs/xfs/xfs_fs_staging.h diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile index 92d88dc3c9f7..9b413544d358 100644 --- a/fs/xfs/Makefile +++ b/fs/xfs/Makefile @@ -93,6 +93,7 @@ xfs-y += xfs_aops.o \ xfs_sysfs.o \ xfs_trans.o \ xfs_xattr.o \ + xfs_fs_staging.o \ kmem.o # low-level transaction/log code diff --git a/fs/xfs/libxfs/xfs_attr_remote.c b/fs/xfs/libxfs/xfs_attr_remote.c index d440393b40eb..c5f190fef1b5 100644 --- a/fs/xfs/libxfs/xfs_attr_remote.c +++ b/fs/xfs/libxfs/xfs_attr_remote.c @@ -615,7 +615,7 @@ xfs_attr_rmtval_set_blk( error = xfs_bmapi_write(args->trans, dp, (xfs_fileoff_t)attr->xattri_lblkno, attr->xattri_blkcnt, XFS_BMAPI_ATTRFORK, args->total, - map, &nmap); + map, &nmap, 0); if (error) return error; diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 34de6e6898c4..52a6e2b61228 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3275,7 +3275,9 @@ xfs_bmap_compute_alignments( struct xfs_alloc_arg *args) { struct xfs_mount *mp = args->mp; - xfs_extlen_t align = 0; /* minimum allocation alignment */ + + /* minimum allocation alignment */ + xfs_extlen_t align = args->alignment; int stripe_align = 0; /* stripe alignment for allocation is determined by mount parameters */ @@ -3652,6 +3654,7 @@ xfs_bmap_btalloc( .datatype = ap->datatype, .alignment = 1, .minalignslop = 0, + .alignment = ap->align, }; xfs_fileoff_t orig_offset; xfs_extlen_t orig_length; @@ -4279,12 +4282,14 @@ xfs_bmapi_write( uint32_t flags, /* XFS_BMAPI_... */ xfs_extlen_t total, /* total blocks needed */ struct xfs_bmbt_irec *mval, /* output: map values */ - int *nmap) /* i/o: mval size/count */ + int *nmap, + xfs_extlen_t align) /* i/o: mval size/count */ { struct xfs_bmalloca bma = { .tp = tp, .ip = ip, .total = total, + .align = align, }; struct xfs_mount *mp = ip->i_mount; int whichfork = xfs_bmapi_whichfork(flags); diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h index dd08361ca5a6..0573dfc5fa6b 100644 --- a/fs/xfs/libxfs/xfs_bmap.h +++ b/fs/xfs/libxfs/xfs_bmap.h @@ -26,6 +26,7 @@ struct xfs_bmalloca { xfs_fileoff_t offset; /* offset in file filling in */ xfs_extlen_t length; /* i/o length asked/allocated */ xfs_fsblock_t blkno; /* starting block of new extent */ + xfs_extlen_t align; struct xfs_btree_cur *cur; /* btree cursor */ struct xfs_iext_cursor icur; /* incore extent cursor */ @@ -189,7 +190,8 @@ int xfs_bmapi_read(struct xfs_inode *ip, xfs_fileoff_t bno, int *nmap, uint32_t flags); int xfs_bmapi_write(struct xfs_trans *tp, struct xfs_inode *ip, xfs_fileoff_t bno, xfs_filblks_t len, uint32_t flags, - xfs_extlen_t total, struct xfs_bmbt_irec *mval, int *nmap); + xfs_extlen_t total, struct xfs_bmbt_irec *mval, int *nmap, + xfs_extlen_t align); int __xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip, xfs_fileoff_t bno, xfs_filblks_t *rlen, uint32_t flags, xfs_extnum_t nexts); diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c index e576560b46e9..e6581254092f 100644 --- a/fs/xfs/libxfs/xfs_da_btree.c +++ b/fs/xfs/libxfs/xfs_da_btree.c @@ -2174,7 +2174,7 @@ xfs_da_grow_inode_int( nmap = 1; error = xfs_bmapi_write(tp, dp, *bno, count, xfs_bmapi_aflag(w)|XFS_BMAPI_METADATA|XFS_BMAPI_CONTIG, - args->total, &map, &nmap); + args->total, &map, &nmap, 0); if (error) return error; @@ -2196,7 +2196,7 @@ xfs_da_grow_inode_int( nmap = min(XFS_BMAP_MAX_NMAP, c); error = xfs_bmapi_write(tp, dp, b, c, xfs_bmapi_aflag(w)|XFS_BMAPI_METADATA, - args->total, &mapp[mapi], &nmap); + args->total, &mapp[mapi], &nmap, 0); if (error) goto out_free_map; if (nmap < 1) diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index 1cfd5bc6520a..829316ca01ea 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -831,6 +831,7 @@ struct xfs_scrub_metadata { #define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom) #define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req) #define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) +#define XFS_IOC_FALLOCATE2 _IOR ('X', 129, struct xfs_fallocate2) /* XFS_IOC_GETFSUUID ---------- deprecated 140 */ diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index a09dd2606479..a0c55af6f051 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -776,10 +776,12 @@ int xfs_alloc_file_space( struct xfs_inode *ip, xfs_off_t offset, - xfs_off_t len) + xfs_off_t len, + xfs_off_t align) { xfs_mount_t *mp = ip->i_mount; xfs_off_t count; + xfs_filblks_t align_fsb; xfs_filblks_t allocated_fsb; xfs_filblks_t allocatesize_fsb; xfs_extlen_t extsz, temp; @@ -811,6 +813,7 @@ xfs_alloc_file_space( nimaps = 1; startoffset_fsb = XFS_B_TO_FSBT(mp, offset); endoffset_fsb = XFS_B_TO_FSB(mp, offset + count); + align_fsb = XFS_B_TO_FSB(mp, align); allocatesize_fsb = endoffset_fsb - startoffset_fsb; /* @@ -872,7 +875,7 @@ xfs_alloc_file_space( error = xfs_bmapi_write(tp, ip, startoffset_fsb, allocatesize_fsb, XFS_BMAPI_PREALLOC, 0, imapp, - &nimaps); + &nimaps, align_fsb); if (error) goto error; diff --git a/fs/xfs/xfs_bmap_util.h b/fs/xfs/xfs_bmap_util.h index 6888078f5c31..476f610ad617 100644 --- a/fs/xfs/xfs_bmap_util.h +++ b/fs/xfs/xfs_bmap_util.h @@ -54,7 +54,7 @@ int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip, /* preallocation and hole punch interface */ int xfs_alloc_file_space(struct xfs_inode *ip, xfs_off_t offset, - xfs_off_t len); + xfs_off_t len, xfs_off_t align); int xfs_free_file_space(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t len); int xfs_collapse_file_space(struct xfs_inode *, xfs_off_t offset, diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c index 8fb90da89787..475e1a56d1b0 100644 --- a/fs/xfs/xfs_dquot.c +++ b/fs/xfs/xfs_dquot.c @@ -328,7 +328,7 @@ xfs_dquot_disk_alloc( /* Create the block mapping. */ error = xfs_bmapi_write(tp, quotip, dqp->q_fileoffset, XFS_DQUOT_CLUSTER_SIZE_FSB, XFS_BMAPI_METADATA, 0, &map, - &nmaps); + &nmaps, 0); if (error) goto err_cancel; diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 705250f9f90a..9b1db42a8d33 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -883,12 +883,13 @@ static inline bool xfs_file_sync_writes(struct file *filp) FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | \ FALLOC_FL_INSERT_RANGE | FALLOC_FL_UNSHARE_RANGE) -STATIC long -xfs_file_fallocate( +long +_xfs_file_fallocate( struct file *file, int mode, loff_t offset, - loff_t len) + loff_t len, + loff_t alignment) { struct inode *inode = file_inode(file); struct xfs_inode *ip = XFS_I(inode); @@ -1035,7 +1036,7 @@ xfs_file_fallocate( } if (!xfs_is_always_cow_inode(ip)) { - error = xfs_alloc_file_space(ip, offset, len); + error = xfs_alloc_file_space(ip, offset, len, alignment); if (error) goto out_unlock; } @@ -1073,6 +1074,16 @@ xfs_file_fallocate( return error; } +STATIC long +xfs_file_fallocate( + struct file *file, + int mode, + loff_t offset, + loff_t len) +{ + return _xfs_file_fallocate(file, mode, offset, len, 0); +} + STATIC int xfs_file_fadvise( struct file *file, diff --git a/fs/xfs/xfs_fs_staging.c b/fs/xfs/xfs_fs_staging.c new file mode 100644 index 000000000000..1d635c0a9f49 --- /dev/null +++ b/fs/xfs/xfs_fs_staging.c @@ -0,0 +1,99 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2023 Oracle. All Rights Reserved. + */ + +#include "xfs.h" +#include "xfs_fs_staging.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_trans_resv.h" +#include "xfs_mount.h" +#include "xfs_inode.h" + +#include "linux/security.h" +#include "linux/fsnotify.h" + +extern long _xfs_file_fallocate( + struct file *file, + int mode, + loff_t offset, + loff_t len, + loff_t alignment); + +int xfs_fallocate2( struct file *filp, + void __user *arg) +{ + struct inode *inode = file_inode(filp); + //struct xfs_inode *ip = XFS_I(inode); + struct xfs_fallocate2 fallocate2; + int ret; + + if (copy_from_user(&fallocate2, arg, sizeof(fallocate2))) + return -EFAULT; + + if (fallocate2.flags & XFS_FALLOC2_ALIGNED) { + if (!fallocate2.alignment || !is_power_of_2(fallocate2.alignment)) + return -EINVAL; + + if (fallocate2.offset % fallocate2.alignment) + return -EINVAL; + + if (fallocate2.length % fallocate2.alignment) + return -EINVAL; + } else if (fallocate2.alignment) { + return -EINVAL; + } + + /* These are all just copied from vfs_fallocate() */ + if (fallocate2.offset < 0 || fallocate2.length <= 0) + return -EINVAL; + + if (!(filp->f_mode & FMODE_WRITE)) + return -EBADF; + + if (IS_IMMUTABLE(inode)) + return -EPERM; + + /* + * We cannot allow any fallocate operation on an active swapfile + */ + if (IS_SWAPFILE(inode)) + return -ETXTBSY; + + /* + * Revalidate the write permissions, in case security policy has + * changed since the files were opened. + */ + ret = security_file_permission(filp, MAY_WRITE); + if (ret) + return ret; + + if (S_ISFIFO(inode->i_mode)) + return -ESPIPE; + + if (S_ISDIR(inode->i_mode)) + return -EISDIR; + + if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode)) + return -ENODEV; + + /* Check for wrap through zero too */ + if (((fallocate2.offset + fallocate2.length) > inode->i_sb->s_maxbytes) || + ((fallocate2.offset + fallocate2.length) < 0)) + return -EFBIG; + + if (!filp->f_op->fallocate) + return -EOPNOTSUPP; + + file_start_write(filp); + ret = _xfs_file_fallocate(filp, 0, fallocate2.offset, fallocate2.length, fallocate2.alignment); + + if (ret == 0) + fsnotify_modify(filp); + + file_end_write(filp); + + return ret; +} diff --git a/fs/xfs/xfs_fs_staging.h b/fs/xfs/xfs_fs_staging.h new file mode 100644 index 000000000000..a82e61063dba --- /dev/null +++ b/fs/xfs/xfs_fs_staging.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2023 Oracle. All Rights Reserved. + */ +#ifndef __XFS_FS_STAGING_H__ +#define __XFS_FS_STAGING_H__ + +struct xfs_fallocate2 { + s64 offset; /* bytes */ + s64 length; /* bytes */ + u64 flags; + u32 alignment; /* bytes */ + u32 padding[8]; +}; + +#define XFS_FALLOC2_ALIGNED (1U << 0) + +int xfs_fallocate2( struct file *filp, + void __user *arg); + +#endif /* __XFS_FS_STAGING_H__ */ diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 55bb01173cde..6e60fce44068 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -4,6 +4,7 @@ * All Rights Reserved. */ #include "xfs.h" +#include "xfs_fs_staging.h" #include "xfs_fs.h" #include "xfs_shared.h" #include "xfs_format.h" @@ -2149,6 +2150,9 @@ xfs_file_ioctl( return error; } + case XFS_IOC_FALLOCATE2: + return xfs_fallocate2(filp, arg); + default: return -ENOTTY; } diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 285885c308bd..a4389a0c4bf2 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -306,7 +306,7 @@ xfs_iomap_write_direct( */ nimaps = 1; error = xfs_bmapi_write(tp, ip, offset_fsb, count_fsb, bmapi_flags, 0, - imap, &nimaps); + imap, &nimaps, 0); if (error) goto out_trans_cancel; @@ -614,7 +614,7 @@ xfs_iomap_write_unwritten( nimaps = 1; error = xfs_bmapi_write(tp, ip, offset_fsb, count_fsb, XFS_BMAPI_CONVERT, resblks, &imap, - &nimaps); + &nimaps, 0); if (error) goto error_on_bmapi_transaction; diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index f5dc46ce9803..a2e5ba6cf7f3 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -420,7 +420,7 @@ xfs_reflink_fill_cow_hole( nimaps = 1; error = xfs_bmapi_write(tp, ip, imap->br_startoff, imap->br_blockcount, XFS_BMAPI_COWFORK | XFS_BMAPI_PREALLOC, 0, cmap, - &nimaps); + &nimaps, 0); if (error) goto out_trans_cancel; @@ -490,7 +490,7 @@ xfs_reflink_fill_delalloc( error = xfs_bmapi_write(tp, ip, cmap->br_startoff, cmap->br_blockcount, XFS_BMAPI_COWFORK | XFS_BMAPI_PREALLOC, 0, - cmap, &nimaps); + cmap, &nimaps, 0); if (error) goto out_trans_cancel; diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 16534e9873f6..a57a8a4d8294 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -817,7 +817,7 @@ xfs_growfs_rt_alloc( */ nmap = 1; error = xfs_bmapi_write(tp, ip, oblocks, nblocks - oblocks, - XFS_BMAPI_METADATA, 0, &map, &nmap); + XFS_BMAPI_METADATA, 0, &map, &nmap, 0); if (!error && nmap < 1) error = -ENOSPC; if (error) diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 85e433df6a3f..2a4524bf34a5 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -269,7 +269,7 @@ xfs_symlink( nmaps = XFS_SYMLINK_MAPS; error = xfs_bmapi_write(tp, ip, first_fsb, fs_blocks, - XFS_BMAPI_METADATA, resblks, mval, &nmaps); + XFS_BMAPI_METADATA, resblks, mval, &nmaps, 0); if (error) goto out_trans_cancel; diff --git a/security/security.c b/security/security.c index cf6cc576736f..d53b1b6c2d59 100644 --- a/security/security.c +++ b/security/security.c @@ -1593,6 +1593,7 @@ int security_file_permission(struct file *file, int mask) return fsnotify_perm(file, mask); } +EXPORT_SYMBOL(security_file_permission); int security_file_alloc(struct file *file) { From patchwork Wed May 3 18:38:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230538 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 75C66C7EE21 for ; Wed, 3 May 2023 20:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229544AbjECUA1 (ORCPT ); Wed, 3 May 2023 16:00:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjECUAZ (ORCPT ); Wed, 3 May 2023 16:00:25 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54E6A118; Wed, 3 May 2023 13:00:24 -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 343HowO6000746; Wed, 3 May 2023 18:40:04 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=fllPnR11Wwo3F2gEcgHtSOoIXsNuGphAfCgAa9ulrQg=; b=mF8Wae5GCSyCOST7xX7pFlFYZNBPOS/r+eCOmsxIZsOmw0SRAXpugk3PB9fo/LYILPaC ZHfqEg8qZ5j/uszYC0bvdc9gBis7lbP3ZnnKKVgqeZvq3BbWnR4/Gv++UNpbvDR59JdG KKAShyKdS3wV1VmozpnXmqyI9ItPM62UOSEblDuXM/aH29NOf9/Gqs70AoDUjjbUPtPg 02i0brNj8CfYXOkfdH1FutCvGvy39hmtAsySLEKydUc4NsE7E0oOKmTApZwGT2omwr+I jap2GbcM9d0PLsF34rD7MZ1hH1IylXuFw3+JTMEhuKvsyyClC399+Scsr4nr7laHagQv TA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8usv019c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:40:04 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343HRjXe009885; Wed, 3 May 2023 18:40:03 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2103.outbound.protection.outlook.com [104.47.55.103]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp805tt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:40:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GaBjACQwXu02oBKZQmnQn2a/5LrFWScrn2GXc3SyfA7yiqWFazbf+wK85C7cgTXlY3Jjm02z3mSFzzIkgHbpZw6vWT+9WKZaPO7xNAXqnu48AFU9UGYvC22HJTcDZLo5nlp0kZw2qjDqu0FgffykwlWY2W7rjqu5dh+pBrnQQa1Czsu6m1TEtvKUP9JyC3QcXeP5X8eWEyLH40P832kJrf7IzYlq1ZEwXS/pQ+5ggvI5u+j13hBrZzqIUw5Xs9EGX8/tr0nBHJuvCXDS+DmiNai4J6J04L+QbLmHP9M0RsplSjcYmmEuZ12mtHufRj6P74TmWE5hLyC9PizJl3kqGQ== 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=fllPnR11Wwo3F2gEcgHtSOoIXsNuGphAfCgAa9ulrQg=; b=XnxoDg2Y5Bw6jkh9FmxbWjwJ6fm0bZ+sRW0xm5QqHsCvng7yRYr6AnvA9VNGB7l11Vvzxud9uCAFFNrXx5/uWOPe3/f/KMfqNzLSulOfawVcnZpsI2AQgpSA0QHK41G6LxSGqX9t1MJz6xlSVx1YSZmuCXtC4rn9ZeZY/Mj313E7rgAfK+giscvU4FyNwqfsCAUcP++m2yIvB2+NEp5C0bLDNHEqJaJ5KKEAjS6oUHrMK3fBq9UnstqWNXkHMZp7NhcREnKpJpWwNVqF2XrXfHQ5eeo6dJmaiw1C/+vZjruPb8pJXl2s0XqdmamdRzLSuY3FiTNkChDF6SyTN1unjw== 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=fllPnR11Wwo3F2gEcgHtSOoIXsNuGphAfCgAa9ulrQg=; b=xX1nhE3k8rCDhVn2sxZMWXYnso8N58nIM4SHIwvGILn3l4f1fo8TWGUBZcHucuvJpi4feodDsgs/OYg/3W6zIHFT7MQg17TxhqxxPS2j5Vawzreu76oJPh08WCAl3CSYj2xJok2XDzGaIaJjbrtJ2AbHZSi5PFebhBfTkmTP8Ps= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB5677.namprd10.prod.outlook.com (2603:10b6:303:18b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 18:40:01 +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:40:01 +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 13/16] scsi: sd: Support reading atomic properties from block limits VPD Date: Wed, 3 May 2023 18:38:18 +0000 Message-Id: <20230503183821.1473305-14-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: AS4P250CA0026.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:5e3::14) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB5677:EE_ X-MS-Office365-Filtering-Correlation-Id: cb2e7ff2-6ef9-4e48-87e5-08db4c05cd78 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e+w9BCO+v83Ywq2zuhgkxYSeMG6D2w6ylHm6h82M9CyGUi/uJJWiM+kVzdAzoazJMWV3aFZvsEKcOF2rhFfZUpUuroMzs+5JqbKF8MkyVNgZMU06xJxYVBsmdpSpEqzB84Vln/zwbbVm3l4kCaga4h5ZEDZui1tQcNilExd4uSBpuAz+9a5HeJZ73QCltY7N97I9FfLY5Z/uGetqz3rFqHuoEo+pCz2JZZUreMgHSV7Q5FACkRx2BeC0a19JkQncjTgsaeMgWQTG67r2+w0zVWHAMuGhArK3owqs7ZTpX13xlQ0o/jlxZeK3cSQ3VBrgHHCYMNXcVZPp+T1BpPTMWA3TYQWrkTmVH/rbwqLH2z00mrGpTeLbm4rZQLC2nDI/YyAf1QDMxMCvpYZqqB/eEvkkG1Jh8at2CCIiZTXXL+3LoiqXhN0BQa+uFaodjtY2NkKucd0Oqoa3z16isbcxNfL7eUjyjd6uFOLrU6msB+dWeKQr3m34aZsjs2PFNQ3HxGn3OEdPGUDFwAdOXnGch4cWgmxBXlKDqM6nt8wZYG9maaRosmLblOUVoBUn340q28Hwm/fmRasN1SAc7H39wAZhEIpyYm69OoGoAqj6T3c= 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)(376002)(366004)(396003)(39860400002)(136003)(451199021)(2616005)(6506007)(1076003)(107886003)(6512007)(26005)(41300700001)(38100700002)(6666004)(83380400001)(186003)(6486002)(478600001)(66556008)(921005)(4326008)(316002)(66476007)(5660300002)(66946007)(2906002)(7416002)(8676002)(36756003)(86362001)(103116003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /JCbfNTZB4CxvdHf8xgPTPIvXsWzu9o7CK7FDdH74pDfxXFKnWeChKaVVkTFttq5mpa8EttNGiMpx5+PgtBeYUoPFxr+6LjYBZB1BRw2S0BpaBdmHoFXbuOxbbSsddgYvtUkbjV5nmdG0RWWlwk6NE112ehMInE8X+Fr8MNvIRvLYtCsdLaWm3qqbnwvH152sZwa2nfbB8lpva6XM/x+Vhcp88psRioILyKlVHcNlPCrpERetIEXqxoH4gYbEcDZ3BBHm5TMpRHH4DB4CNcWJDdqivdckysSeauXdgep8CeCc9YSe+vhWHUJh4oouL7NVEnkq3eOhV8Y9FP0mbXMDAIis/ndBiaiMsjxGDoxp0LratbIEfd6N/a3RHiLR6nUvFAO2H7H9F2Msj5WVuR1ULd9EgSgZ2elXeHVu0fdsqswdyxXA4RwWSp40q6b+c7Fwsgc6WJuSnz4xhUgp9FYJ5NqFk1rfX1WwWHDT2mKLD43N++2B+QjyS5+YGoGND6Js1Ny5tzIpXK8F/AMEFaez++N+JdhT+4VhCs3JxYUF98ktwF9/8XoB4xoslLbQq+pNQtj35c5cN52AzsG7xpO+M6ANUthuTEtuyUNLXd0AAWm4TL5UNMcuLdmobWwzKqfL+0HLlN2JgelwRbkVh2215RZn8V2LQLSkZGGpP+QVEJTHRW+qh69oxKNY4Tc/1/vG70zLWdAOhQHPM0PadfKAUTyn0eEsloT/0W8ITlrf8bTEpPQ9ZNGYDr/wAzshZTVbtHQxQqnSQICZdWY0VDKfCqiKh/1tN2nFb5+F4GLF6mIyeN4pIto5ktmBikWgyz8AEtrIFIIZ09++Jdl2rRyDR8EmoCW41wCXptoMBqLDr9udAj3YGaiiP+ruHnP5+5BFGWDCpPyfYhqpwkt33R7/c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uU3o+jbw08P83/HMyBbBGY0Y2KLYDz7gC7kYOLmHJ5jKW7aaLUQfX2V7yzOuiCWC/81tLezL3+gDi0lxcJlMvHXl91HVwaJ4MUTebMSf7y3Q4x9eW25k5bjy0u8z4plJ42DRV77/tdLaQkbRVxprnEgRrvIpK6Qcc4+9ITqbIvzmd2ndPzi6AVnFR+70e4O4FpsyUDRB7gehQkvdqYaUvfd4PQkubds+4sVRAHsPsYY0G+wBXkhd+RjNfRV/oRdaxRkkAK67SIe7TT6TSwRoaGffJoP7TJqhCcfvQAGvM2Jt/9+sDaFoVr7vxqcj5S/Cw8KZJrT34tT6JAo1VMWKrqstigLS+XUzTis0GquZ4VHiLdWLP3WUvsFWBfRIlTLcffueKT859GA8tFMZtZfs8oL8pEDU6h/hwNmUrrPa9Q6pMrUkHw9zbP2sVx5jyvIvEo5QhAUd1hHAr3dN0SwqTLYgEIaFdlIziC199gJY0vQdlyVKnwcLC88C9r0RN4ZYRjCF/NTOtQEfzqJTag4ABrvrLH+qy1EoMI7uxj2A92wB8IV3U1WoYNWJTgnl+bkxzRq9k6W+DWkeWq3L8ZVdArr+Y5kJ2U9hBd2n1/tObrA9fvlPa60iskyLrVdv6vUfhIerRwubbYhGQFSL995TAOyFaorBUS4DJ7TW19f4n0Q7WsGx+jJyraUBtyzYeTi5lUYeSUtYY8dbOPE3FYTe0nkEKgO2F8e2jGDGdVkHHv1B/4HOHBN2gxpt2M+7TGAj0ISDaN4EabDGCY9UafRWDZJG8rkx3HzzId+4A2r/ZWmhNBYR+Xej3WqHf2xsQS8Yu5W X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: cb2e7ff2-6ef9-4e48-87e5-08db4c05cd78 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:40:01.1135 (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: cxZkoz+RL9CWELov2nC8CuEQutICvGNu4iKClT4ys0K5YSozem+TnTAytkvgYCE/3i6AHpPwyE84C0d4xvODjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB5677 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 adultscore=0 phishscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-ORIG-GUID: IJFcth3jTV0HVgtkO27drV0DEN3ks5Mr X-Proofpoint-GUID: IJFcth3jTV0HVgtkO27drV0DEN3ks5Mr Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Also update block layer request queue sysfs properties. See sbc4r22 section 6.6.4 - Block limits VPD page. Signed-off-by: John Garry --- drivers/scsi/sd.c | 34 +++++++++++++++++++++++++++++++++- drivers/scsi/sd.h | 7 +++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 4bb87043e6db..8db8b9389227 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -876,6 +876,30 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) return scsi_alloc_sgtables(cmd); } +static void sd_config_atomic(struct scsi_disk *sdkp) +{ + unsigned int logical_block_size = sdkp->device->sector_size; + struct request_queue *q = sdkp->disk->queue; + + if (sdkp->max_atomic) { + unsigned int physical_block_size_sectors = + sdkp->physical_block_size / sdkp->device->sector_size; + unsigned int max_atomic = max_t(unsigned int, + rounddown_pow_of_two(sdkp->max_atomic), + rounddown_pow_of_two(sdkp->max_atomic_with_boundary)); + unsigned int unit_max = min_t(unsigned int, max_atomic, + rounddown_pow_of_two(sdkp->max_atomic_boundary)); + unsigned int unit_min = sdkp->atomic_granularity ? + rounddown_pow_of_two(sdkp->atomic_granularity) : + physical_block_size_sectors; + + blk_queue_atomic_write_max_bytes(q, max_atomic * logical_block_size); + blk_queue_atomic_write_unit_min(q, unit_min); + blk_queue_atomic_write_unit_max(q, unit_max); + blk_queue_atomic_write_boundary(q, 0); + } +} + static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, bool unmap) { @@ -2922,7 +2946,7 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) sdkp->max_ws_blocks = (u32)get_unaligned_be64(&vpd->data[36]); if (!sdkp->lbpme) - goto out; + goto read_atomics; lba_count = get_unaligned_be32(&vpd->data[20]); desc_count = get_unaligned_be32(&vpd->data[24]); @@ -2953,6 +2977,14 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) else sd_config_discard(sdkp, SD_LBP_DISABLE); } +read_atomics: + sdkp->max_atomic = get_unaligned_be32(&vpd->data[44]); + sdkp->atomic_alignment = get_unaligned_be32(&vpd->data[48]); + sdkp->atomic_granularity = get_unaligned_be32(&vpd->data[52]); + sdkp->max_atomic_with_boundary = get_unaligned_be32(&vpd->data[56]); + sdkp->max_atomic_boundary = get_unaligned_be32(&vpd->data[60]); + + sd_config_atomic(sdkp); } out: diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 5eea762f84d1..bca05fbd74df 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -121,6 +121,13 @@ struct scsi_disk { u32 max_unmap_blocks; u32 unmap_granularity; u32 unmap_alignment; + + u32 max_atomic; + u32 atomic_alignment; + u32 atomic_granularity; + u32 max_atomic_with_boundary; + u32 max_atomic_boundary; + u32 index; unsigned int physical_block_size; unsigned int max_medium_access_timeouts; From patchwork Wed May 3 18:38:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230466 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 6CFAEC7EE2C for ; Wed, 3 May 2023 18:42:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230212AbjECSmd (ORCPT ); Wed, 3 May 2023 14:42:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229837AbjECSk7 (ORCPT ); Wed, 3 May 2023 14:40:59 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7544E72B2; Wed, 3 May 2023 11:40:31 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343Hom1v017459; Wed, 3 May 2023 18:40:11 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=jPwsteNaU9GXozxZhUVMYdJt2KKbOl367bZW1+vO2Xg=; b=cz8Djm9X06UtiD/QuBAP4bnFGT721QOdWTrNtnjlmo+OCNijO/mI80FHb14oMIdLmuew k7jvjErIOwFwyQja35GAKK37vnpWC2YhzNFR0JCI21rEdTgDq6dti+PIGYHVUgU1NDpJ BVZu2dYbO3pxkkCKLca2jva/xXqjB1vEDy4lF2OIzjG5la/TDFfFBOeXgHMXW/owj4sc QQPrSs3N8+cEnEPz1NXzFIOhtNFwDklw9vJMLsmLHfebRXm0/P/34Pje8Xzeg6wFG8z4 lP6G206JYKc/vfla0C44sQtJpqDIFfDSgQUPN+ohxQdWjSr91Tpw6KFZvbhiKK5aQXdl 9g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8u4aqyht-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:40:10 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343HcHP8040441; Wed, 3 May 2023 18:40:09 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2106.outbound.protection.outlook.com [104.47.55.106]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp7h049-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:40:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CTdiv+MIiLP2K/+FPQdnDe5uSJGEFFDcNWX3e0s/WzPmAnzw84fLhBfviGduglZic+GFisNe9UvXLCpfOVN6gyjaBBBibXtBj8kRISgGlqmWB169Ejqv1ehDHvcI2U7k+0nSIGqG5YTq3kMU9yopR6Lo5+GG0YQ1QEThEjYXgzItU71W9aNwkUiYOOX+nmL8Wcj6C/9alF4e3glyF6fz6IF7ot7FgjKpWkg36GM3wCJ2Uit1tufjmQJfK8gBCVUxJoYto7KOtBVuB0jHT7wewLSAaH9pA2bHlT3T+Z+GLcXjV3eH64QC+4rr30u5zuI2nAbkARSHoYJf+NxpTTBQhA== 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=jPwsteNaU9GXozxZhUVMYdJt2KKbOl367bZW1+vO2Xg=; b=a8NUEq5iFRO3BWcNYIK2AHDyHR8JF067QFaZaYzkY+Kdw08dByDJwE4kAD98jmyGd8PHyVFcGPmP2m7fMJeQT3byNvWuKqF5R1OwHfol+cytzAuGJnbXNS3bPdJfRa+Lx7WMzqHIwOc1vti0R7uV2WY371Jlx7C3Yeke1lK1dg8BE6Vnm6ML6GqGMz9Zn2P17fgKXKpTze3r9F4s7fE8YFzfxZqpawundGKXqgx1MzYVtUP/0vh3K3SPg1yoJpVXzEf9rCpcW9I9V76WQah3wo/rCCu+n5BoV2xkjR05QLeG0A4SRcUAIVvEEZkEXi6qNgNzLLdxLRtHztOEpqkGxA== 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=jPwsteNaU9GXozxZhUVMYdJt2KKbOl367bZW1+vO2Xg=; b=WtxG0H8lGxLUhM1E4xiZ0C7VrPxCvGcfTz0gxq4kAZSrigC937Jnw5yHjz/vVzM8N8LRauqvIMbtHurznkJhfDxfe9Ea941wopTE2AALtgQUdSxhUBmSXhAXLsp7lgmDtt6rR+RP+mONIzcBi4TQOFPZxqL00UuW7nLja3zEsQU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB5677.namprd10.prod.outlook.com (2603:10b6:303:18b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 18:40:06 +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:40:06 +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 14/16] scsi: sd: Add WRITE_ATOMIC_16 support Date: Wed, 3 May 2023 18:38:19 +0000 Message-Id: <20230503183821.1473305-15-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: AS4PR10CA0007.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5dc::9) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB5677:EE_ X-MS-Office365-Filtering-Correlation-Id: 2b6c74a6-d66c-4534-dc95-08db4c05d09b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: manxg4H21PiRaxmTg3Bk+7o+JIkRs04kYjyjjRmzVsSEamYzj+lmb+zUZm1r2EtCEs1c1hWtw4DWXS11bHvJHEeIQp5RK781GeM7IldTOkX3YnDYC4sySCE7OxYk+6+oaqeQQJFQ6Htzge8iuWVtmYJjNaMv8kZ6KlFvFg5Syg/FfbJb3okj9HOXr8Pj4wM4SlMoeDj0T4fR1nZ3vTZi1znLnTwbIk2luqShVizfHT46v2uj9Mro/5RIdhf9p8hyqt29HsJph3bymoKkqJOwlJWTI2k/anfbWnVTZ0yd/gQwZhuyNHn7x0IMyEBxk7V3pOQ88TSvtWCUtdhQBNKzhqv9EQFRpsD7zjXErPUUxdieP6yrhm4AA362MY9cZ0zaYL3hcQqdg9DWyETQw5Q/9w3KIlAKwGRY0SNOwXY1clHipWwvdCUCC4w+wKa0aeZN1wlTRqJR62Bc8b2nTP5TOcNUm7+0u5aBSr2wSpyOxrRCYUEjZEznYFcJPPS2zuQiTMJTAvgjG3SFaNTRT/PcdpCZIZeEGONQawQif7eBKwT/kO1AIzIsQ3QicJJGEKR4FmAsQcp1VqIRiHO4WbusPUlruvIdMonns7tZYSNsOFA= 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)(376002)(366004)(396003)(39860400002)(136003)(451199021)(2616005)(6506007)(1076003)(107886003)(6512007)(26005)(41300700001)(38100700002)(6666004)(83380400001)(186003)(6486002)(478600001)(66556008)(921005)(4326008)(316002)(66476007)(5660300002)(66946007)(2906002)(7416002)(8676002)(36756003)(86362001)(103116003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LxcKICn6wo+lczty+JzhJuhB1pzpYZNfE79g2CWwMceOl26+/+I0ygldN36kZ33ZrP3rNeQZzhJLiWBYfuWGbWXEP1l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FXpBTQHyUcA++0Joc9KGcQ47M/0yxQZ60qletoXR36J8sPBd7mVolNW2eJHenKa/Ik3xEzD0Vo4zjufwjsP0OLsGjPkJSxKNcxje8P8aGiEB3h5N9ZcXGOOLiiOLlAyZArfKq3r7BiM6+OUpPXwrSm7vQQjVjkjFgWVcd5id9tkFCT8DOgZfyo+Vd9GADmrfxQyFFaJJcaF9grNm03iAWfd/hiUVCmxIau+5oBfPVV3NqLngSdeiVu+kH8tFKXZWEF9ifaIgcxahxC6BFZtOPRbISRuaHEHDSBWzrfVOQqy55HpqU8tS8Pa+wqvX6yLXyuRZ/iQELGs+VzT7NctjRd88p4MyO7xwNN0Vbuw+HR3P7bj0fGFjM0XK4FonjLNvShvMNxhDSlXU68RL0absH82Xv8HzOlmIkbsUJVYO8kl7DdJRFUNECurcFkbsLEhcMxnBkvWwivx63YPIFu7N7KGMilG0ce41EKqnTc7NZUW0E7VnlfNEApQIIcbPNqu9Rpd5OVEfFSCGjgV3iVaJt6Eu2+m++nbU7yPQUGWnwx4CL6BMjivo+5 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b6c74a6-d66c-4534-dc95-08db4c05d09b 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:40:06.3720 (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: u7LvM0jteJnAS83+9uUPLy9ZnfXZnufl7mFISziIIvS19zJEA74/iphE7qoH+r++54731i6preZeCDuFhU20gg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB5677 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 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-GUID: vFfc-7-Yi9Gba-xt9EoKxX_QQfYJ0gXQ X-Proofpoint-ORIG-GUID: vFfc-7-Yi9Gba-xt9EoKxX_QQfYJ0gXQ Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add function sd_setup_atomic_cmnd() to setup an WRITE_ATOMIC_16 CDB for when REQ_ATOMIC flag is set for the request. Also add trace info. Signed-off-by: John Garry --- drivers/scsi/scsi_trace.c | 22 ++++++++++++++++++++++ drivers/scsi/sd.c | 20 ++++++++++++++++++++ include/scsi/scsi_proto.h | 1 + 3 files changed, 43 insertions(+) diff --git a/drivers/scsi/scsi_trace.c b/drivers/scsi/scsi_trace.c index 41a950075913..3e47c4472a80 100644 --- a/drivers/scsi/scsi_trace.c +++ b/drivers/scsi/scsi_trace.c @@ -325,6 +325,26 @@ scsi_trace_zbc_out(struct trace_seq *p, unsigned char *cdb, int len) return ret; } +static const char * +scsi_trace_atomic_write16_out(struct trace_seq *p, unsigned char *cdb, int len) +{ + const char *ret = trace_seq_buffer_ptr(p); + unsigned int boundary_size; + unsigned int nr_blocks; + sector_t lba; + + lba = get_unaligned_be64(&cdb[2]); + boundary_size = get_unaligned_be16(&cdb[10]); + nr_blocks = get_unaligned_be16(&cdb[12]); + + trace_seq_printf(p, "lba=%llu txlen=%u boundary_size=%u", + lba, nr_blocks, boundary_size); + + trace_seq_putc(p, 0); + + return ret; +} + static const char * scsi_trace_varlen(struct trace_seq *p, unsigned char *cdb, int len) { @@ -385,6 +405,8 @@ scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len) return scsi_trace_zbc_in(p, cdb, len); case ZBC_OUT: return scsi_trace_zbc_out(p, cdb, len); + case WRITE_ATOMIC_16: + return scsi_trace_atomic_write16_out(p, cdb, len); default: return scsi_trace_misc(p, cdb, len); } diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 8db8b9389227..e69473fa2dd7 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1139,6 +1139,23 @@ static blk_status_t sd_setup_rw6_cmnd(struct scsi_cmnd *cmd, bool write, return BLK_STS_OK; } +static blk_status_t sd_setup_atomic_cmnd(struct scsi_cmnd *cmd, + sector_t lba, unsigned int nr_blocks, + unsigned char flags) +{ + cmd->cmd_len = 16; + cmd->cmnd[0] = WRITE_ATOMIC_16; + cmd->cmnd[1] = flags; + put_unaligned_be64(lba, &cmd->cmnd[2]); + cmd->cmnd[10] = 0; + cmd->cmnd[11] = 0; + put_unaligned_be16(nr_blocks, &cmd->cmnd[12]); + cmd->cmnd[14] = 0; + cmd->cmnd[15] = 0; + + return BLK_STS_OK; +} + static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) { struct request *rq = scsi_cmd_to_rq(cmd); @@ -1149,6 +1166,7 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) unsigned int nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); unsigned int mask = logical_to_sectors(sdp, 1) - 1; bool write = rq_data_dir(rq) == WRITE; + bool atomic_write = !!(rq->cmd_flags & REQ_ATOMIC) && write; unsigned char protect, fua; blk_status_t ret; unsigned int dif; @@ -1208,6 +1226,8 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) { ret = sd_setup_rw32_cmnd(cmd, write, lba, nr_blocks, protect | fua); + } else if (atomic_write) { + ret = sd_setup_atomic_cmnd(cmd, lba, nr_blocks, protect | fua); } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { ret = sd_setup_rw16_cmnd(cmd, write, lba, nr_blocks, protect | fua); diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index fbe5bdfe4d6e..c449be9cba60 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -119,6 +119,7 @@ #define WRITE_SAME_16 0x93 #define ZBC_OUT 0x94 #define ZBC_IN 0x95 +#define WRITE_ATOMIC_16 0x9c #define SERVICE_ACTION_BIDIRECTIONAL 0x9d #define SERVICE_ACTION_IN_16 0x9e #define SERVICE_ACTION_OUT_16 0x9f From patchwork Wed May 3 18:38:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230552 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 D3677C7EE21 for ; Wed, 3 May 2023 20:14:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230073AbjECUOF (ORCPT ); Wed, 3 May 2023 16:14:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229946AbjECUOD (ORCPT ); Wed, 3 May 2023 16:14:03 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE579868F; Wed, 3 May 2023 13:13:30 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HoZBw024257; Wed, 3 May 2023 18:40:17 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=OcyJ+a6tyPNcEvP+YkBvZeGoC+dB+2mNvr7EYk6ZqjE=; b=TtbE/ZhmEe5xe7QF+dT/hsc72oQxm9FmVwOR2+Rbm/J1xC4OodVzrxveUovf4D/j7px0 EzBn0uI7FnlUjU3X41gllfV1/7zUpfOfZwkkDmXKgvnXDIxPiM58y66SiZMPOeSS8iRb ss5WGCsX3JkZ4A5AKkx1atU4hsSuKFHPrfXJ+4PRewx+9/yWpHJlqfbdYeTSkpoVijdY ZZnnTY5vc5NjyIN3+zWT2fC5zrDKGMCw98SDnzXZaJk6glIEBEPSqnXdxLXfeyPwhxjA 2HoPa1xnAwH2feMe9PEDOz2X2R0RzwMBtOtMsAErXwjbNmRlumartNtzyF75ugLeheho TA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8su1r3pj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:40:16 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343HKboL027453; Wed, 3 May 2023 18:40:15 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8spdsjpy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:40:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HzjJtIxBVoEa8kflOW6D5iGkKmK9m8rbZpmJ4Fsf2u+ogmd0GiC5PrwgNIb/nzImYs3nK8cNaEPbkeHXQXyDdflL+wJkDpWgl2MxYh1MZxqlDSTnpVz1jGgt9AlWvzjTvsnSIsPi4NZxCqYeE3QgpZkiiN9Idrzx8bFDHvXYRQ6NvAo4Oi12AKe2YdUUcSLz+e6gVXu8t8jvugtm1Cki7KCSQN3qwlCBFy73rzKk+8VcYyDNqlnmXSLaulMslrOW3OMpB5FCMZ9JDvnN9q1pyHwewpy8wnBRVzjJnCGh9YoYtdM4XLYXa9yHLkDbFiozJy2fL9Nc3ZVF3KvbH7wTKw== 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=OcyJ+a6tyPNcEvP+YkBvZeGoC+dB+2mNvr7EYk6ZqjE=; b=fZHoOfFh/BQ20VlxUlEE7FzRD6W90mQtoEjFgD3n9eFzFS8JItodQeQOYH/12SduNa19mifvmpYB+yedCcQfrPiFEsLaTvpFZ/5p+5Vvr13xlWCdZFkMD2VbO3KIQEeN+vu5Al+685cA/0n7q5Ni6Xlk/ET1s7HDPNfzqN8YXlWT6NqmWzPehlCnuy/wLhvSGBmK0wBe3OUsoGWNWI2Sf0LDgcxTlqDoNYjQDvwZxJJGOTcQccYnnh2V2y3NUiVzsZ3iuQiQpqibkGmfOJP5O0nLzc1w23nSl4SgzZuj1FWidCcY43+4ZCmgFtIwtMqjVL4i8KofbrIqpS5llHOdww== 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=OcyJ+a6tyPNcEvP+YkBvZeGoC+dB+2mNvr7EYk6ZqjE=; b=CBCgLq2NT5CXefEzGwLqv6vW7Zg4lZZwwVLzC0CcXBrw/u/YrgGF3x48UQHCb+U2UYCwfNgSFoDcQPUBpycBk2qeIvtDOKbhK4tc0jI5TcHoJ21yGbKiAIuOHj3dpLXRUFSNGC677QJt4Bt3bW0xcgbTsF/m9ZMmI47Fo6sJR8c= 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:40:11 +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:40:11 +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 15/16] scsi: scsi_debug: Atomic write support Date: Wed, 3 May 2023 18:38:20 +0000 Message-Id: <20230503183821.1473305-16-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: AM0PR05CA0085.eurprd05.prod.outlook.com (2603:10a6:208:136::25) 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: a165a73d-6232-4b38-06c5-08db4c05d3b8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dX5HYHPmDVGNOZ5TKxlobl5vDDyyU4rjozTneLCjvMUdGrYA0S0eLwlxmuJa9ZkoKtLdHXT0U0V8WPrf8P/XKhhmJ0hFVX6z6ynBB7iQUSNwLnLtXxVvVzRN1p1ANvBQHuWCIWLQrLkpE6fVP8Y4W0Ofxs7eOn5ptw27zkkArS2bMvbtmMQH9kU3ND62L16ARdIORMXwVCJNLxfRjRw22Mnu0UhXxYc2GclVKXPfxD0PnJHMYe+u1hz4fyvO8sfuJXd5N9ROxqlDWuovTWmllxNmhoPTviLxqahVRx9nkI8XtaDAQBs9/zYJYNoKfrA0YwUXgDZKdBaZV2730TlIEORsgLX2PrjnGwi6ficSHq2vsfGCBNmIBnCToWm+rbEK3X5RV3PeWuDa+0c5wnck0WpG0BTnH9fOR5Qmw07NVWyuycV5q+OpwUU6Zt9HnWfIqC2bH1RTC8SoBdzsDB94F7hrMebIe5BpQmi1o+dhqJNAOT1UFNY+mzR40dvrYlZlrXkV/5RLI8oLIWRmzLbpB4y0ov0yqiiCCQsd3pulMj9A26wp24kBnO/f0R7xmn5DWxOtO6Hv+VCSOQ4dgdbH0N82nE6QALZpZy0w3mj0qp/YM5OfDzDXvpjci+xs0TKj 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)(30864003)(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)(357404004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4iKGupQ8HmBm5Q2KhKon8uko9qEwDV1/DWQWhsWqoWFwfgpBHUbNgHU8gJ7tgE6pu6FXuY7hRpDfl7p9n26OjU6h/XQ9zJf+cFBsh+lJuPVlm8enijQHabsTypt4LzWo5Z+YfD78d5cgwg22FpLs33PHfLNmvqBfJQIaX5zNZIPkR3Zo7yoG+bpNSXnoZwtsQAiTW91SQjFFZzHCgwlV+FSRuvLfKjCn/2HaHl1JGN03/myOb7Hbl4wEk9thboG4Yqm7SlloFAjL5Ccv+EizsAJBrYN3vZnua0JhYfCeJ3tv43wCq4VYCuAEsVRGmlU5IHa8KvLpJkCUDPj6X+0lWwUST37kbaGiGZi049Q9syTeEoFkvuOs5lz8N39212yAVcyyTdQI/5B1grrv/76ZcynCQKKj+sLnDTpZNTgQ16G/83J7YyKNcDYvagg27GFOQ7YvYi2sdJTe/WYGTERM/qnGp3UkhL99Yq1eazA05Dc7ELiI38GuTwqIVAYWelrl5J9VcuFRg22t1NW+bT17IR9Eqp8HJ4HH1s1yQxQzKJSIWWwMgn/ss1Wlh5rBrCGnsh0ieavz9l494+KPpGYDjUQMcBEFfrNE0JC52Efzb6BGY2jPPGkgn316tfMKZO/8kSdUNbAcQ8TqpGlVvYDsGiMEYZFqa4OY0ZYZLCT62a1POK0AN4YC+RJmp0kiknlvpANCiqbvAy/DUYEJB7141FxerG2rJqmps40ibS7jOH92x3i5xbg2B2hA+MLIADSIjzPfZ0tJv/ess+RwvGdSjan8f3qqUF9LW5mh3UR7w34JhiXmgF5puwdC/1YyRH6RCAJWsKaRFwS6FdM0G47v0VQ8L+rhmFJTaT9QfsppFXO0MXwLUR23UjHw6wSO57IudUMJedz9uCzVQDt9c/mBP352J+jLQQlSh+GdTZWyr1AMSzSOCehPkkiMGz/A+iNh1dKYTAxGMAy/b9B10N+62Y0wFNYf3ntbsqjOGfAxt39S8szPtMRd8M7r/PlkpigmJKF8SkkKWXF/0RACfkZvg2/df7FV/oWOkIzZHAot4yOhyKrmrbU5aqQ/KM4vykhaelaUQauPH7zEP68ZE+/k6s742bnUeRLTSHP7npFdLoF3806mAOqMjl9TIKCwDTAc+Ale2dUwFjPjL5PUOUJFYBaB/oma2ChwIk4el+MpENMG+oqecfUMZv4Uc4KM4FAdDBLaNNnBCwVsbqqG54C9Li+GvUKRRjjtsRzV5jbWZTLS0japCcAFIvzPu+UIiwjBPIaMZxnsg579EuioyIv3o+eDcCHhEuJh67fpWjlRj7ClRRtBbOj3CdfsxMbgVtZge+9N0rwHTcTKe5OnZ0j6XbKDElneGNhe/AbO5jhBiMbqfBdnw0kyEB5lBcrUKeho7LfyR5lzWQjf21/r+H41P8Zjs0VEh374rBTraF8ek13Mpj2o9268CPPaNAhtZ51RmpAbKOERGBodsVKBwYHPHQfjyBwrMqTxYQCEQWDGYnsCow1AOcACKhCKKn4E0S0nO/CmESpSpIfutus6UlPYXekmr8bOthFeuaNj0ScV25atqyldcjAmEpPyD1YpxpGIX86uR/Mz/a0xIghVaRlyyw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 67xAg3i2vAXiWG5yD2BQzXyw/RyTo5E2psNMvgoARj6JHkGaNDt83H84rbQ381ytITpt20e5Q3h7IeSHVid7D6s+eLwAGoemNry7LXzHxHTh1L5FTrCIHgK1flzhfOPDPfJh5MpiNnZDdlx3R0ibDuuNWfnDjcfuxnxi7vW1tGoaGQsMOWUzJ71R5/ElzO3e0ptadzTVqPcyRe6oOEb6IGaCPvigdTho0SJOPcScODwEhB3Tl6YM47OQUt8McDiSrsaUvnxJpJ9a7C1QJf+nN24KInG6CviLLVKreyj2+9SGX4HcC4AB+liC1OI91NRa4EzGHMGiSdFVNYeQyu1QHLejy2SHG/HM5oXUB54erABCGw/TClAsxTVbohFhxCLz67avfSBwL6KFVNWQCLzFcWe3qUpo8eDXByF9woq9cTnO7ENUcFMc+za2rr7aGm6k7NSIfXKZ8M1n3HBjR66NjP+iPs1bfi3JdVBxT35Nmsf25eIRp5mT+ej68fptXp5XJomZoIGWyfkTC89luW95BMkexBFpcCL526gbagJi/zV/Oy7ole9Ce6yt/5A3tFTyJ/WIsuYWRw38nWpjfUwn5/prbM5lXRjogulCkJ58T1QtIJ1vDzdKEPGWOYN08fmj8QFBLnODcdXJBVduPAG0mCx+ltEpYchg4RBzcKYMI8FwhXHBgEL3irUK9+cy8llRTK7F7vz7gwrYUZZNsUwxkohUjOq6v638wVVVEQnyu5BsnHX+3udpGTwJRhCYrAoI0BgMol9fjhtz0nLFZlE0HB/cHwBFOEBjranKDcMOq/vpGByiwBYsxIWTbmUUZtZTdlKvuGKh7kwkJqxj/o9FVPBozrpJdKpqPnKoAFyfaW9bD+J/R0f0qfy1AEwD8Z1MvVJ+8FKsE8kPZ4p5j6QYECASrR+EmTInOenY4uLuZhQKsBoSUjK6CWMJlgprlpLmiTgJIIWF+IohT+1f8YJYn1H003lf2a/e2SG8Odx6+svxmrlZ2t3/5W+iQsN9DIi63wdAASryZ/hE/YAnZ0N8t3U6cyxpUgOi4+kmiCSgW8L7KJrBz//K3h1yNy1Wx+/h5Q47h3blR+aRQ4b0qPS+tl7K3LkpX/DysBUxcOIvvOH2ovoKUE2DmUSfwW3y51RS X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a165a73d-6232-4b38-06c5-08db4c05d3b8 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:40:11.6478 (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: QwP3Iue5NV6cEBZgrAm+crqspD8+jX3aotqZwqIgoIi99Mqjyxiaw+L725pGg30/3lteqfdvJxqsB3QFBaICig== 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 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-GUID: lTpLyZ2WGXYzdCtCoHqsde8L1IXPLP00 X-Proofpoint-ORIG-GUID: lTpLyZ2WGXYzdCtCoHqsde8L1IXPLP00 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add initial support for atomic writes. As is standard method, feed device properties via modules param, those being: - atomic_max_size_blks - atomic_alignment_blks - atomic_granularity_blks - atomic_max_size_with_boundary_blks - atomic_max_boundary_blks These just match sbc4r22 section 6.6.4 - Block limits VPD page. We just support ATOMIC_WRITE_16. The major change in the driver is how we lock the device for RW accesses. Currently the driver uses a per-device lock for accessing device metadata and "media" data (calls to do_device_access()) atomically for the duration of the whole read/write command. This should not suit verifying atomic writes. Reason being that currently all reads/writes are atomic, so using atomic writes does not prove anything. Change device access model to basis that regular writes only atomic on a per-sector basis, while reads and atomic writes are fully atomic. As mentioned, since accessing metadata and device media is atomic, continue to have regular writes involving metadata - like discard or PI - as atomic. We can improve this later. Currently we only support model where overlapping going reads or writes wait for current access to complete before commencing an atomic write. This is described in 4.29.3.2 section of the SBC. However, we simplify, things and wait for all accesses to complete (when issuing an atomic write). Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 593 +++++++++++++++++++++++++++++--------- 1 file changed, 460 insertions(+), 133 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 776371080762..0555aee30ea1 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -66,6 +66,8 @@ static const char *sdebug_version_date = "20210520"; /* Additional Sense Code (ASC) */ #define NO_ADDITIONAL_SENSE 0x0 +#define OVERLAP_ATOMIC_COMMAND_ASC 0x0 +#define OVERLAP_ATOMIC_COMMAND_ASCQ 0x23 #define LOGICAL_UNIT_NOT_READY 0x4 #define LOGICAL_UNIT_COMMUNICATION_FAILURE 0x8 #define UNRECOVERED_READ_ERR 0x11 @@ -100,6 +102,7 @@ static const char *sdebug_version_date = "20210520"; #define READ_BOUNDARY_ASCQ 0x7 #define ATTEMPT_ACCESS_GAP 0x9 #define INSUFF_ZONE_ASCQ 0xe +/* see drivers/scsi/sense_codes.h */ /* Additional Sense Code Qualifier (ASCQ) */ #define ACK_NAK_TO 0x3 @@ -149,6 +152,12 @@ static const char *sdebug_version_date = "20210520"; #define DEF_VIRTUAL_GB 0 #define DEF_VPD_USE_HOSTNO 1 #define DEF_WRITESAME_LENGTH 0xFFFF +#define DEF_ATOMIC_WRITE 1 +#define DEF_ATOMIC_MAX_LENGTH 8192 +#define DEF_ATOMIC_ALIGNMENT 2 +#define DEF_ATOMIC_GRANULARITY 2 +#define DEF_ATOMIC_BOUNDARY_MAX_LENGTH (DEF_ATOMIC_MAX_LENGTH) +#define DEF_ATOMIC_MAX_BOUNDARY 128 #define DEF_STRICT 0 #define DEF_STATISTICS false #define DEF_SUBMIT_QUEUES 1 @@ -318,7 +327,9 @@ struct sdebug_host_info { /* There is an xarray of pointers to this struct's objects, one per host */ struct sdeb_store_info { - rwlock_t macc_lck; /* for atomic media access on this store */ + rwlock_t macc_data_lck; /* for media data access on this store */ + rwlock_t macc_meta_lck; /* for atomic media meta access on this store */ + rwlock_t macc_sector_lck; /* per-sector media data access on this store */ u8 *storep; /* user data storage (ram) */ struct t10_pi_tuple *dif_storep; /* protection info */ void *map_storep; /* provisioning map */ @@ -345,12 +356,20 @@ struct sdebug_defer { enum sdeb_defer_type defer_t; }; +struct sdebug_device_access_info { + bool atomic_write; + u64 lba; + u32 num; + struct scsi_cmnd *self; +}; + struct sdebug_queued_cmd { /* corresponding bit set in in_use_bm[] in owning struct sdebug_queue * instance indicates this slot is in use. */ struct sdebug_defer *sd_dp; struct scsi_cmnd *a_cmnd; + struct sdebug_device_access_info *i; }; struct sdebug_queue { @@ -413,7 +432,8 @@ enum sdeb_opcode_index { SDEB_I_PRE_FETCH = 29, /* 10, 16 */ SDEB_I_ZONE_OUT = 30, /* 0x94+SA; includes no data xfer */ SDEB_I_ZONE_IN = 31, /* 0x95+SA; all have data-in */ - SDEB_I_LAST_ELEM_P1 = 32, /* keep this last (previous + 1) */ + SDEB_I_ATOMIC_WRITE_16 = 32, /* keep this last (previous + 1) */ + SDEB_I_LAST_ELEM_P1 = 33, /* keep this last (previous + 1) */ }; @@ -447,7 +467,8 @@ static const unsigned char opcode_ind_arr[256] = { 0, 0, 0, SDEB_I_VERIFY, SDEB_I_PRE_FETCH, SDEB_I_SYNC_CACHE, 0, SDEB_I_WRITE_SAME, SDEB_I_ZONE_OUT, SDEB_I_ZONE_IN, 0, 0, - 0, 0, 0, 0, 0, 0, SDEB_I_SERV_ACT_IN_16, SDEB_I_SERV_ACT_OUT_16, + 0, 0, 0, 0, + SDEB_I_ATOMIC_WRITE_16, 0, SDEB_I_SERV_ACT_IN_16, SDEB_I_SERV_ACT_OUT_16, /* 0xa0; 0xa0->0xbf: 12 byte cdbs */ SDEB_I_REPORT_LUNS, SDEB_I_ATA_PT, 0, SDEB_I_MAINT_IN, SDEB_I_MAINT_OUT, 0, 0, 0, @@ -495,6 +516,7 @@ static int resp_write_buffer(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_sync_cache(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_pre_fetch(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_report_zones(struct scsi_cmnd *, struct sdebug_dev_info *); +static int resp_atomic_write(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_open_zone(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_close_zone(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_finish_zone(struct scsi_cmnd *, struct sdebug_dev_info *); @@ -731,6 +753,11 @@ static const struct opcode_info_t opcode_info_arr[SDEB_I_LAST_ELEM_P1 + 1] = { resp_report_zones, zone_in_iarr, /* ZONE_IN(16), REPORT ZONES) */ {16, 0x0 /* SA */, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xc7} }, +/* 31 */ + {0, 0x0, 0x0, F_D_OUT | FF_MEDIA_IO, + resp_atomic_write, NULL, /* ATOMIC WRITE 16 */ + {16, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} }, /* sentinel */ {0xff, 0, 0, 0, NULL, NULL, /* terminating element */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, @@ -779,6 +806,12 @@ static unsigned int sdebug_unmap_granularity = DEF_UNMAP_GRANULARITY; static unsigned int sdebug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS; static unsigned int sdebug_unmap_max_desc = DEF_UNMAP_MAX_DESC; static unsigned int sdebug_write_same_length = DEF_WRITESAME_LENGTH; +static unsigned int sdebug_atomic_write = DEF_ATOMIC_WRITE; +static unsigned int sdebug_atomic_max_size_blks = DEF_ATOMIC_MAX_LENGTH; +static unsigned int sdebug_atomic_alignment_blks = DEF_ATOMIC_ALIGNMENT; +static unsigned int sdebug_atomic_granularity_blks = DEF_ATOMIC_GRANULARITY; +static unsigned int sdebug_atomic_max_size_with_boundary_blks = DEF_ATOMIC_BOUNDARY_MAX_LENGTH; +static unsigned int sdebug_atomic_max_boundary_blks = DEF_ATOMIC_MAX_BOUNDARY; static int sdebug_uuid_ctl = DEF_UUID_CTL; static bool sdebug_random = DEF_RANDOM; static bool sdebug_per_host_store = DEF_PER_HOST_STORE; @@ -880,6 +913,11 @@ static inline bool scsi_debug_lbp(void) (sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10); } +static inline bool scsi_debug_atomic_write(void) +{ + return 0 == sdebug_fake_rw && sdebug_atomic_write; +} + static void *lba2fake_store(struct sdeb_store_info *sip, unsigned long long lba) { @@ -1510,6 +1548,14 @@ static int inquiry_vpd_b0(unsigned char *arr) /* Maximum WRITE SAME Length */ put_unaligned_be64(sdebug_write_same_length, &arr[32]); + if (sdebug_atomic_write) { + put_unaligned_be32(sdebug_atomic_max_size_blks, &arr[40]); + put_unaligned_be32(sdebug_atomic_alignment_blks, &arr[44]); + put_unaligned_be32(sdebug_atomic_granularity_blks, &arr[48]); + put_unaligned_be32(sdebug_atomic_max_size_with_boundary_blks, &arr[52]); + put_unaligned_be32(sdebug_atomic_max_boundary_blks, &arr[56]); + } + return 0x3c; /* Mandatory page length for Logical Block Provisioning */ } @@ -3011,15 +3057,242 @@ static inline struct sdeb_store_info *devip2sip(struct sdebug_dev_info *devip, return xa_load(per_store_ap, devip->sdbg_host->si_idx); } + +static inline void +sdeb_read_lock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __acquire(lock); + else + read_lock(lock); +} + +static inline void +sdeb_read_unlock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __release(lock); + else + read_unlock(lock); +} + +static inline void +sdeb_write_lock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __acquire(lock); + else + write_lock(lock); +} + +static inline void +sdeb_write_unlock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __release(lock); + else + write_unlock(lock); +} + +static inline void +sdeb_data_read_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_lock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_read_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_unlock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_write_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_lock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_write_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_unlock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_sector_read_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_lock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_read_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_unlock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_write_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_lock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_write_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_unlock(&sip->macc_sector_lck); +} + +/* +Atomic locking: +We simplify the atomic model to allow only 1x atomic +write and many non-atomic reads or writes for all +LBAs. + +A RW lock has a similar bahaviour: +Only 1x writer and many readers. + +So use a RW lock for per-device read and write locking: +An atomic access grabs the lock as a writer and +non-atomic grabs the lock as a reader. +*/ + +static inline void +sdeb_data_lock(struct sdeb_store_info *sip, bool atomic_write) +{ + if (atomic_write) + sdeb_data_write_lock(sip); + else + sdeb_data_read_lock(sip); +} + +static inline void +sdeb_data_unlock(struct sdeb_store_info *sip, bool atomic_write) +{ + if (atomic_write) + sdeb_data_write_unlock(sip); + else + sdeb_data_read_unlock(sip); +} + +/* Allow many reads but only 1x write per sector */ +static inline void +sdeb_data_sector_lock(struct sdeb_store_info *sip, bool do_write) +{ + if (do_write) + sdeb_data_sector_write_lock(sip); + else + sdeb_data_sector_read_lock(sip); +} + +static inline void +sdeb_data_sector_unlock(struct sdeb_store_info *sip, bool do_write) +{ + if (do_write) + sdeb_data_sector_write_unlock(sip); + else + sdeb_data_sector_read_unlock(sip); +} + +static inline void +sdeb_meta_read_lock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __acquire(&sip->macc_meta_lck); + else + __acquire(&sdeb_fake_rw_lck); + } else { + if (sip) + read_lock(&sip->macc_meta_lck); + else + read_lock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_read_unlock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __release(&sip->macc_meta_lck); + else + __release(&sdeb_fake_rw_lck); + } else { + if (sip) + read_unlock(&sip->macc_meta_lck); + else + read_unlock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_write_lock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __acquire(&sip->macc_meta_lck); + else + __acquire(&sdeb_fake_rw_lck); + } else { + if (sip) + write_lock(&sip->macc_meta_lck); + else + write_lock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_write_unlock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __release(&sip->macc_meta_lck); + else + __release(&sdeb_fake_rw_lck); + } else { + if (sip) + write_unlock(&sip->macc_meta_lck); + else + write_unlock(&sdeb_fake_rw_lck); + } +} + +static struct sdebug_queue *get_queue(struct scsi_cmnd *cmnd); + /* Returns number of bytes copied or -1 if error. */ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, - u32 sg_skip, u64 lba, u32 num, bool do_write) + u32 sg_skip, u64 lba, u32 num, bool do_write, + bool atomic_write) { int ret; - u64 block, rest = 0; + u64 block; enum dma_data_direction dir; struct scsi_data_buffer *sdb = &scp->sdb; u8 *fsp; + int i; + + /* + * Even though reads are inherently atomic (in this driver), we expect + * the atomic flag only for writes. + */ + if (!do_write && atomic_write) + return -1; if (do_write) { dir = DMA_TO_DEVICE; @@ -3035,21 +3308,26 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, fsp = sip->storep; block = do_div(lba, sdebug_store_sectors); - if (block + num > sdebug_store_sectors) - rest = block + num - sdebug_store_sectors; - ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, + /* Only allow 1x atomic write or multiple non-atomic writes at any given time */ + sdeb_data_lock(sip, atomic_write); + for (i = 0; i < num; i++) { + /* We shouldn't need to lock for atomic writes, but do it anyway */ + sdeb_data_sector_lock(sip, do_write); + ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, fsp + (block * sdebug_sector_size), - (num - rest) * sdebug_sector_size, sg_skip, do_write); - if (ret != (num - rest) * sdebug_sector_size) - return ret; - - if (rest) { - ret += sg_copy_buffer(sdb->table.sgl, sdb->table.nents, - fsp, rest * sdebug_sector_size, - sg_skip + ((num - rest) * sdebug_sector_size), - do_write); + sdebug_sector_size, sg_skip, do_write); + sdeb_data_sector_unlock(sip, do_write); + if (ret != sdebug_sector_size) { + ret += (i * sdebug_sector_size); + break; + } + sg_skip += sdebug_sector_size; + if (++block >= sdebug_store_sectors) + block = 0; } + ret = num * sdebug_sector_size; + sdeb_data_unlock(sip, atomic_write); return ret; } @@ -3225,70 +3503,6 @@ static int prot_verify_read(struct scsi_cmnd *scp, sector_t start_sec, return ret; } -static inline void -sdeb_read_lock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __acquire(&sip->macc_lck); - else - __acquire(&sdeb_fake_rw_lck); - } else { - if (sip) - read_lock(&sip->macc_lck); - else - read_lock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_read_unlock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __release(&sip->macc_lck); - else - __release(&sdeb_fake_rw_lck); - } else { - if (sip) - read_unlock(&sip->macc_lck); - else - read_unlock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_write_lock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __acquire(&sip->macc_lck); - else - __acquire(&sdeb_fake_rw_lck); - } else { - if (sip) - write_lock(&sip->macc_lck); - else - write_lock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_write_unlock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __release(&sip->macc_lck); - else - __release(&sdeb_fake_rw_lck); - } else { - if (sip) - write_unlock(&sip->macc_lck); - else - write_unlock(&sdeb_fake_rw_lck); - } -} - static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) { bool check_prot; @@ -3298,6 +3512,7 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) u64 lba; struct sdeb_store_info *sip = devip2sip(devip, true); u8 *cmd = scp->cmnd; + bool meta_data_locked = false; switch (cmd[0]) { case READ_16: @@ -3356,6 +3571,10 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) atomic_set(&sdeb_inject_pending, 0); } + /* + * When checking device access params, for reads we only check data + * versus what is set at init time, so no need to lock. + */ ret = check_device_access_params(scp, lba, num, false); if (ret) return ret; @@ -3375,29 +3594,33 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } - sdeb_read_lock(sip); + if (sdebug_dev_is_zoned(devip) || + (sdebug_dix && scsi_prot_sg_count(scp))) { + sdeb_meta_read_lock(sip); + meta_data_locked = true; + } /* DIX + T10 DIF */ if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) { switch (prot_verify_read(scp, lba, num, ei_lba)) { case 1: /* Guard tag error */ if (cmd[1] >> 5 != 3) { /* RDPROTECT != 3 */ - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1); return check_condition_result; } else if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1); return illegal_condition_result; } break; case 3: /* Reference tag error */ if (cmd[1] >> 5 != 3) { /* RDPROTECT != 3 */ - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3); return check_condition_result; } else if (scp->prot_flags & SCSI_PROT_REF_CHECK) { - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3); return illegal_condition_result; } @@ -3405,8 +3628,9 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } } - ret = do_device_access(sip, scp, 0, lba, num, false); - sdeb_read_unlock(sip); + ret = do_device_access(sip, scp, 0, lba, num, false, false); + if (meta_data_locked) + sdeb_meta_read_unlock(sip); if (unlikely(ret == -1)) return DID_ERROR << 16; @@ -3595,6 +3819,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) u64 lba; struct sdeb_store_info *sip = devip2sip(devip, true); u8 *cmd = scp->cmnd; + bool meta_data_locked = false; switch (cmd[0]) { case WRITE_16: @@ -3648,10 +3873,17 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) "to DIF device\n"); } - sdeb_write_lock(sip); + if (sdebug_dev_is_zoned(devip) || + (sdebug_dix && scsi_prot_sg_count(scp)) || + scsi_debug_lbp()) { + sdeb_meta_write_lock(sip); + meta_data_locked = true; + } + ret = check_device_access_params(scp, lba, num, true); if (ret) { - sdeb_write_unlock(sip); + if (meta_data_locked) + sdeb_meta_write_unlock(sip); return ret; } @@ -3660,22 +3892,22 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) switch (prot_verify_write(scp, lba, num, ei_lba)) { case 1: /* Guard tag error */ if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1); return illegal_condition_result; } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1); return check_condition_result; } break; case 3: /* Reference tag error */ if (scp->prot_flags & SCSI_PROT_REF_CHECK) { - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3); return illegal_condition_result; } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3); return check_condition_result; } @@ -3683,13 +3915,16 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } } - ret = do_device_access(sip, scp, 0, lba, num, true); + ret = do_device_access(sip, scp, 0, lba, num, true, false); if (unlikely(scsi_debug_lbp())) map_region(sip, lba, num); + /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); - sdeb_write_unlock(sip); + if (meta_data_locked) + sdeb_meta_write_unlock(sip); + if (unlikely(-1 == ret)) return DID_ERROR << 16; else if (unlikely(sdebug_verbose && @@ -3796,7 +4031,8 @@ static int resp_write_scat(struct scsi_cmnd *scp, goto err_out; } - sdeb_write_lock(sip); + /* Just keep it simple and always lock for now */ + sdeb_meta_write_lock(sip); sg_off = lbdof_blen; /* Spec says Buffer xfer Length field in number of LBs in dout */ cum_lb = 0; @@ -3839,7 +4075,11 @@ static int resp_write_scat(struct scsi_cmnd *scp, } } - ret = do_device_access(sip, scp, sg_off, lba, num, true); + /* + * Write ranges atomically to keep as close to pre-atomic + * writes behaviour as possible. + */ + ret = do_device_access(sip, scp, sg_off, lba, num, true, true); /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); @@ -3878,7 +4118,7 @@ static int resp_write_scat(struct scsi_cmnd *scp, } ret = 0; err_out_unlock: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); err_out: kfree(lrdp); return ret; @@ -3897,14 +4137,16 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, scp->device->hostdata, true); u8 *fs1p; u8 *fsp; + bool meta_data_locked = false; - sdeb_write_lock(sip); + if (sdebug_dev_is_zoned(devip) || scsi_debug_lbp()) { + sdeb_meta_write_lock(sip); + meta_data_locked = true; + } ret = check_device_access_params(scp, lba, num, true); - if (ret) { - sdeb_write_unlock(sip); - return ret; - } + if (ret) + goto out; if (unmap && scsi_debug_lbp()) { unmap_region(sip, lba, num); @@ -3915,6 +4157,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, /* if ndob then zero 1 logical block, else fetch 1 logical block */ fsp = sip->storep; fs1p = fsp + (block * lb_size); + sdeb_data_write_lock(sip); if (ndob) { memset(fs1p, 0, lb_size); ret = 0; @@ -3922,8 +4165,8 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, ret = fetch_to_dev_buffer(scp, fs1p, lb_size); if (-1 == ret) { - sdeb_write_unlock(sip); - return DID_ERROR << 16; + ret = DID_ERROR << 16; + goto out; } else if (sdebug_verbose && !ndob && (ret < lb_size)) sdev_printk(KERN_INFO, scp->device, "%s: %s: lb size=%u, IO sent=%d bytes\n", @@ -3940,10 +4183,12 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); + sdeb_data_write_unlock(sip); + ret = 0; out: - sdeb_write_unlock(sip); - - return 0; + if (meta_data_locked) + sdeb_meta_write_unlock(sip); + return ret; } static int resp_write_same_10(struct scsi_cmnd *scp, @@ -4086,25 +4331,30 @@ static int resp_comp_write(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); - ret = do_dout_fetch(scp, dnum, arr); if (ret == -1) { retval = DID_ERROR << 16; - goto cleanup; + goto cleanup_free; } else if (sdebug_verbose && (ret < (dnum * lb_size))) sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb " "indicated=%u, IO sent=%d bytes\n", my_name, dnum * lb_size, ret); + + sdeb_data_write_lock(sip); + sdeb_meta_write_lock(sip); if (!comp_write_worker(sip, lba, num, arr, false)) { mk_sense_buffer(scp, MISCOMPARE, MISCOMPARE_VERIFY_ASC, 0); retval = check_condition_result; - goto cleanup; + goto cleanup_unlock; } + + /* Cover sip->map_storep (which map_region()) sets with data lock */ if (scsi_debug_lbp()) map_region(sip, lba, num); -cleanup: - sdeb_write_unlock(sip); +cleanup_unlock: + sdeb_meta_write_unlock(sip); + sdeb_data_write_unlock(sip); +cleanup_free: kfree(arr); return retval; } @@ -4148,7 +4398,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) desc = (void *)&buf[8]; - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); for (i = 0 ; i < descriptors ; i++) { unsigned long long lba = get_unaligned_be64(&desc[i].lba); @@ -4164,7 +4414,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ret = 0; out: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); kfree(buf); return ret; @@ -4277,12 +4527,13 @@ static int resp_pre_fetch(struct scsi_cmnd *scp, rest = block + nblks - sdebug_store_sectors; /* Try to bring the PRE-FETCH range into CPU's cache */ - sdeb_read_lock(sip); + sdeb_data_read_lock(sip); prefetch_range(fsp + (sdebug_sector_size * block), (nblks - rest) * sdebug_sector_size); if (rest) prefetch_range(fsp, rest * sdebug_sector_size); - sdeb_read_unlock(sip); + + sdeb_data_read_unlock(sip); fini: if (cmd[1] & 0x2) res = SDEG_RES_IMMED_MASK; @@ -4441,7 +4692,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } /* Not changing store, so only need read access */ - sdeb_read_lock(sip); + sdeb_data_read_lock(sip); ret = do_dout_fetch(scp, a_num, arr); if (ret == -1) { @@ -4463,7 +4714,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) goto cleanup; } cleanup: - sdeb_read_unlock(sip); + sdeb_data_read_unlock(sip); kfree(arr); return ret; } @@ -4509,7 +4760,7 @@ static int resp_report_zones(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_read_lock(sip); + sdeb_meta_read_lock(sip); desc = arr + 64; for (lba = zs_lba; lba < sdebug_capacity; @@ -4607,11 +4858,68 @@ static int resp_report_zones(struct scsi_cmnd *scp, ret = fill_from_dev_buffer(scp, arr, min_t(u32, alloc_len, rep_len)); fini: - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); kfree(arr); return ret; } +static int resp_atomic_write(struct scsi_cmnd *scp, + struct sdebug_dev_info *devip) +{ + struct sdeb_store_info *sip; + u8 *cmd = scp->cmnd; + u16 boundary, len; + u64 lba; + int ret; + + if (!scsi_debug_atomic_write()) { + mk_sense_invalid_opcode(scp); + return check_condition_result; + } + + sip = devip2sip(devip, true); + + lba = get_unaligned_be64(cmd + 2); + boundary = get_unaligned_be16(cmd + 10); + len = get_unaligned_be16(cmd + 12); + + if (sdebug_atomic_alignment_blks && lba % sdebug_atomic_alignment_blks) { + /* Does not meet alignment requirement */ + mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); + return check_condition_result; + } + + if (sdebug_atomic_granularity_blks && len % sdebug_atomic_granularity_blks) { + /* Does not meet alignment requirement */ + mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); + return check_condition_result; + } + + if (boundary > 0) { + if (boundary > sdebug_atomic_max_boundary_blks) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + + if (len > sdebug_atomic_max_size_with_boundary_blks) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + } else { + if (len > sdebug_atomic_max_size_blks) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + } + + ret = do_device_access(sip, scp, 0, lba, len, true, true); + if (unlikely(ret == -1)) + return DID_ERROR << 16; + if (unlikely(ret != len * sdebug_sector_size)) + return DID_ERROR << 16; + return 0; +} + /* Logic transplanted from tcmu-runner, file_zbc.c */ static void zbc_open_all(struct sdebug_dev_info *devip) { @@ -4638,8 +4946,7 @@ static int resp_open_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) mk_sense_invalid_opcode(scp); return check_condition_result; } - - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { /* Check if all closed zones can be open */ @@ -4688,7 +4995,7 @@ static int resp_open_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) zbc_open_zone(devip, zsp, true); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -4715,7 +5022,7 @@ static int resp_close_zone(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_close_all(devip); @@ -4744,7 +5051,7 @@ static int resp_close_zone(struct scsi_cmnd *scp, zbc_close_zone(devip, zsp); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -4787,7 +5094,7 @@ static int resp_finish_zone(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_finish_all(devip); @@ -4816,7 +5123,7 @@ static int resp_finish_zone(struct scsi_cmnd *scp, zbc_finish_zone(devip, zsp, true); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -4867,7 +5174,7 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_rwp_all(devip); @@ -4895,7 +5202,7 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) zbc_rwp_zone(devip, zsp); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -4962,6 +5269,8 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) retiring = 1; sqcp->a_cmnd = NULL; + scp->host_scribble = NULL; + sqcp->i = NULL; if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { spin_unlock_irqrestore(&sqp->qc_lock, iflags); pr_err("Unexpected completion\n"); @@ -5717,6 +6026,7 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, if (kt <= d) { /* elapsed duration >= kt */ spin_lock_irqsave(&sqp->qc_lock, iflags); sqcp->a_cmnd = NULL; + cmnd->host_scribble = NULL; atomic_dec(&devip->num_in_q); clear_bit(k, sqp->in_use_bm); spin_unlock_irqrestore(&sqp->qc_lock, iflags); @@ -5837,6 +6147,7 @@ module_param_named(lbprz, sdebug_lbprz, int, S_IRUGO); module_param_named(lbpu, sdebug_lbpu, int, S_IRUGO); module_param_named(lbpws, sdebug_lbpws, int, S_IRUGO); module_param_named(lbpws10, sdebug_lbpws10, int, S_IRUGO); +module_param_named(atomic_write, sdebug_atomic_write, int, S_IRUGO); module_param_named(lowest_aligned, sdebug_lowest_aligned, int, S_IRUGO); module_param_named(lun_format, sdebug_lun_am_i, int, S_IRUGO | S_IWUSR); module_param_named(max_luns, sdebug_max_luns, int, S_IRUGO | S_IWUSR); @@ -5871,6 +6182,11 @@ module_param_named(unmap_alignment, sdebug_unmap_alignment, int, S_IRUGO); module_param_named(unmap_granularity, sdebug_unmap_granularity, int, S_IRUGO); module_param_named(unmap_max_blocks, sdebug_unmap_max_blocks, int, S_IRUGO); module_param_named(unmap_max_desc, sdebug_unmap_max_desc, int, S_IRUGO); +module_param_named(atomic_max_size_blks, sdebug_unmap_alignment, int, S_IRUGO); +module_param_named(atomic_alignment_blks, sdebug_atomic_alignment_blks, int, S_IRUGO); +module_param_named(atomic_granularity_blks, sdebug_atomic_granularity_blks, int, S_IRUGO); +module_param_named(atomic_max_size_with_boundary_blks, sdebug_atomic_max_size_with_boundary_blks, int, S_IRUGO); +module_param_named(atomic_max_boundary_blks, sdebug_atomic_max_boundary_blks, int, S_IRUGO); module_param_named(uuid_ctl, sdebug_uuid_ctl, int, S_IRUGO); module_param_named(virtual_gb, sdebug_virtual_gb, int, S_IRUGO | S_IWUSR); module_param_named(vpd_use_hostno, sdebug_vpd_use_hostno, int, @@ -5913,6 +6229,7 @@ MODULE_PARM_DESC(lbprz, MODULE_PARM_DESC(lbpu, "enable LBP, support UNMAP command (def=0)"); MODULE_PARM_DESC(lbpws, "enable LBP, support WRITE SAME(16) with UNMAP bit (def=0)"); MODULE_PARM_DESC(lbpws10, "enable LBP, support WRITE SAME(10) with UNMAP bit (def=0)"); +MODULE_PARM_DESC(atomic_write, "enable ATOMIC WRITE support, support WRITE ATOMIC(16) (def=1)"); MODULE_PARM_DESC(lowest_aligned, "lowest aligned lba (def=0)"); MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method"); MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)"); @@ -5944,6 +6261,11 @@ MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)" MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=1)"); MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0xffffffff)"); MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=256)"); +MODULE_PARM_DESC(atomic_max_size_blks, "max # of blocks can be atomically written in one cmd (def=0xff)"); +MODULE_PARM_DESC(atomic_alignment_blks, "minimum alignment of atomic write in blocks (def=2)"); +MODULE_PARM_DESC(atomic_granularity_blks, "minimum granularity of atomic write in blocks (def=2)"); +MODULE_PARM_DESC(atomic_max_size_with_boundary_blks, "max # of blocks can be atomically written in one cmd with boundary set (def=0xff)"); +MODULE_PARM_DESC(atomic_boundary_blks, "max # boundaries per atomic write (def=0)"); MODULE_PARM_DESC(uuid_ctl, "1->use uuid for lu name, 0->don't, 2->all use same (def=0)"); MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)"); @@ -7079,6 +7401,7 @@ static int __init scsi_debug_init(void) goto free_q_arr; } } + xa_init_flags(per_store_ap, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ); if (want_store) { idx = sdebug_add_store(); @@ -7279,7 +7602,9 @@ static int sdebug_add_store(void) map_region(sip, 0, 2); } - rwlock_init(&sip->macc_lck); + rwlock_init(&sip->macc_data_lck); + rwlock_init(&sip->macc_meta_lck); + rwlock_init(&sip->macc_sector_lck); return (int)n_idx; err: sdebug_erase_store((int)n_idx, sip); @@ -7573,6 +7898,8 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) retiring = true; sqcp->a_cmnd = NULL; + sqcp->i = NULL; + scp->host_scribble = NULL; if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { pr_err("Unexpected completion sqp %p queue_num=%d qc_idx=%u from %s\n", sqp, queue_num, qc_idx, __func__); From patchwork Wed May 3 18:38:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13230467 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 E364EC77B7F for ; Wed, 3 May 2023 18:43:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230117AbjECSnU (ORCPT ); Wed, 3 May 2023 14:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230177AbjECSmb (ORCPT ); Wed, 3 May 2023 14:42:31 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFFFE7DB6; Wed, 3 May 2023 11:40:42 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HpRov003935; Wed, 3 May 2023 18:40:16 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=7d+s/0M45qtUO3zYE7BS+D09AQElSGIfbhoIoUYOSpA=; b=i+fnpszbJ9CSlVzJ3kgr7FKCwWHAilr03+8Ct4f9MBDCGuvpnCJGgrKVmk7Rhg56M2B6 KzuQDf/UAi8zd6tR6+0w6Bf7G8mR3Mb3RLGppQhwPiE4bTq5LII6qG8lRaRQT4RPIvR2 p7vRz3A36xGe6p7Tjeu75kGQkrd+OyeWFEv+WdpGRwRCiXFmmWwrMiEC5YTdd1oqkvAe +EbeybNkP2eBzhWAJ1cWtdJmiuvj1QCnuB/gcSREqKwpTWWof/t+EF71jcREASx8RePL OF4sBST+4tzCF1DhJdzROBZY269ZAW0FkFP1AcYVAHysTpkerKqf6TDIjPMcpU9WXfcv iw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8u9d07pd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:40:16 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343HKboM027453; Wed, 3 May 2023 18:40:15 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8spdsjpy-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 18:40:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OUFHlp2ZltwMglcdTDfK8ZSHh/toFB6hMn9/w1rTl3kqOR9pbPIlBNF8M1BzWgs9nQFnA2fBIgBGO2fh04VAP5rcqQLKVMHMh4KvwxiI4RWiqoTRAjdlXQcADWdsngct3x7rOvTj1yw1pYQV9QSJyH9JP82nye5nLCUbi4Wlo81NiJ3aU5bcIS0C0RWxAnDhLLuQGhI2sH7GbFZx9FrYsuaOVUmiCDILPhImzvRHYgZ5mybNR9+x18/oAnjChiBvqAqFHmsEQ1Y8yD3jtSI4QFPumcFSnLm0bWykSXK3HPyD+Rexqkn8MIECNJTbSVemQyAQ1vriUFmh/pzbUaLgnw== 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=7d+s/0M45qtUO3zYE7BS+D09AQElSGIfbhoIoUYOSpA=; b=eskqH3JaXFQlRwJH7lpzIhBmsVeQSgjuoFDo0bB4b5tmP6t4UsXyhRFgaxwzEKIrJFmHSn/PZVyEfXKMZBsEZHFlou89zTfs4wGPzilKz0ublTHIfl0Rw5C3Y1v19Xz5yBhiR+JqSKsbzgf2Qhd0C8VhKwbFZj+eDzZqQ33XIed/9HKM88NBJdPPcGD/1WEamla4xrtomZUn+JP9yXZVVtZVJeiRbQSwpvIKof9axou0/DOsz7qTSpWmi/ST2XnHo/4VKu7nDHMm/oo0YHLrvHflUNPtBYj2iSKWfcumNW9S6DVIjHz4+oQSmJMUlwE4Svd+zhsh73AicxO8uj+ToQ== 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=7d+s/0M45qtUO3zYE7BS+D09AQElSGIfbhoIoUYOSpA=; b=DFlcEn/oKAZIztivd2ZwT0wwKO84gYn1g1a9P0sgovaF8MjdiYn5PRmslHZck1en8GP/xJgmtydLVsNdih6odw5fJLpiXwq0fqc8wKjKpZVAKARgJ7vQmAli4mfcPShGJt+drA8mVg9FmTVXwKfBP3kKvarJE77lvaPPe/TlT5k= 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:40:13 +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:40:13 +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, Alan Adamson , John Garry Subject: [PATCH RFC 16/16] nvme: Support atomic writes Date: Wed, 3 May 2023 18:38:21 +0000 Message-Id: <20230503183821.1473305-17-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: SA1P222CA0190.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c4::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: 71087c64-35e8-4373-d526-08db4c05d4f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5jNUHJ3Z4b7xdJ/QTh53jrdGGqCvwNeFZxks8J+rn0y7mDGjIgNUhSuw8hDkPebdkyPgmYXhjez7rGnVC25ulFFzp8GyMJZPVMVia2moU6vaPWPbUUM/NADNAIzYIrR/r34hF1Za1j+QaMyafWjKLrRBeB786dhotlw9jfYzRFPGOnTS4RMgnDWbq7fO0lrkIFyDJ2LJedYftbSHcgBUuRkqXiW7EpCk/2vcU2zuhNcjX30MwVAddCq3ja+2qd/fo9qdVHPAv3foM/xUoKCbOMtk9lQZkmhWxjqoiCcBqLk973mTajRpd6FT1w/u0uM4szAZrhac69eaSmxcpJliGPVR6nRCNQIEjveNYik7y4jzopWEl4OinocgAKbYeF8r5WXWY4etAuOkVj5os3HrCfvtX3OMeB8Ah+XwpOpT3Id50eCXFaq6yQl1it9yKePXGNxSR43jK1fwty7z8PKKl764qvuYxr6CVvkD3Mz91zLoI/3XhA0je+ZAMn/tNAOzDTyHRzgxDsPMbW9whibt50rYtRUT3Vm6AbivEVseuGV1uuO5LHp60UQ2is+eoB10dPpoHIKwuyP7VNnKnQUQdiskaVUl5Eq6eb0ihk3CSn4= 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)(54906003)(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: ZXe+uQFa6Qkoq5Ku++78nnO4sBQtUCZvBThnhDTdyedttQgBtL4f/qwnzjhXNWWQSJrY2lSqvA+mRpF4DtPWTfzlaiYXL7ggn17TOHH2XCPub8cbWj8LGxgSu4Av44dsGB/iPLhT343BEGNYepIDJ/UMS4WXl9nWIxhabHvZCNnPrjj4RNQF03YGwqaghX8ZlUfubDURH5z53ESwn5zL0bHNxX1C77yNw2HoE7K5W+1wncxNoku61BK4A80+9g1ecedGMNX3IHj76fD3G855ouFODG3395ZolzZbSRPREMwQn8vDc2hVKN8sgo2ZTBJ8e9Wey8kZsZqDaMibUW0Bt6+IDnCmZcJSP2lpeF6H8kvMzC9845dbPsCRJIB45NeguMo2HJ3eXlj98sIo9mLvpWFoxkHdqHlf90N+OV62x77PaQRo12AJEPLFG9vJs+XrbA/WQ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y2UVVIpqNioY7WlKx0m10jkxIAC5jqsZipzzUkyE4oNnO93k3uJIzMmBJyxFhgrwzd0FCMQRXJHJa38BiZUm7REPfeZratcDYVpxjyAxh0t5zGb9oBiorSluVyvobCeeJXy0EvjL5WXszrIimlSgalDnryvvag10bKV79fn24MtiR4Xmh7cOaQGbLZmY+pRS2aNT0KzQHWU7lVvi4otodRrbixgFE2mv6Y/wJReW90OQ+z7ah/L1h9VUHnWLTGAyf X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71087c64-35e8-4373-d526-08db4c05d4f9 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:40:13.6603 (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: 7/Ptbx0+9iNRhWjbGo89NWiDxm2pbPaTcZCOsNJg0+xxSaYMbGF0QUCaNom46x5zPQ6UuqVpbBi7E5AIRjn4lA== 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 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030160 X-Proofpoint-GUID: zQ5jglPpdDNq2kpiiIF0x9YXSnyOTnt_ X-Proofpoint-ORIG-GUID: zQ5jglPpdDNq2kpiiIF0x9YXSnyOTnt_ Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Alan Adamson Support reading atomic write registers to fill in request_queue properties. Use following method to calculate limits: atomic_write_max_bytes = flp2(NAWUPF ?: AWUPF) atomic_write_unit_min = logical_block_size atomic_write_unit_max = flp2(NAWUPF ?: AWUPF) atomic_write_boundary = NABSPF Signed-off-by: Alan Adamson Signed-off-by: John Garry --- drivers/nvme/host/core.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index d6a9bac91a4c..289561915ad3 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1879,6 +1879,39 @@ static void nvme_update_disk_info(struct gendisk *disk, blk_queue_io_min(disk->queue, phys_bs); blk_queue_io_opt(disk->queue, io_opt); + atomic_bs = rounddown_pow_of_two(atomic_bs); + if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf) { + if (id->nabo) { + dev_err(ns->ctrl->device, "Support atomic NABO=%x\n", + id->nabo); + } else { + u32 boundary = 0; + + if (le16_to_cpu(id->nabspf)) + boundary = (le16_to_cpu(id->nabspf) + 1) * bs; + + if (!(boundary & (boundary - 1))) { + blk_queue_atomic_write_max_bytes(disk->queue, + atomic_bs); + blk_queue_atomic_write_unit_min(disk->queue, 1); + blk_queue_atomic_write_unit_max(disk->queue, + atomic_bs / bs); + blk_queue_atomic_write_boundary(disk->queue, + boundary); + } else { + dev_err(ns->ctrl->device, "Unsupported atomic boundary=0x%x\n", + boundary); + } + } + } else if (ns->ctrl->subsys->awupf) { + blk_queue_atomic_write_max_bytes(disk->queue, + atomic_bs); + blk_queue_atomic_write_unit_min(disk->queue, 1); + blk_queue_atomic_write_unit_max(disk->queue, + atomic_bs / bs); + blk_queue_atomic_write_boundary(disk->queue, 0); + } + /* * Register a metadata profile for PI, or the plain non-integrity NVMe * metadata masquerading as Type 0 if supported, otherwise reject block