From patchwork Tue Dec 12 11:08:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488986 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="iWt+rbOB"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="ZEBKg62r" Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 983F51BD1; Tue, 12 Dec 2023 03:10:17 -0800 (PST) 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 3BC7hhli004079; Tue, 12 Dec 2023 11:09:18 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-11-20; bh=/t0zPXXcRWFzWm94HZuIP3m7HVI3K70dH5CmAqqifJg=; b=iWt+rbOB7ercdVygWsmI4hqx2M4RGI5h4btVw8zMRvWvdo9nDjPdMBGd/H2eYOLOGcEQ IcbxLrL+10IZzxww+9i+tvJGPBwIkywb2CO6Eo3c2a00eVHYXsLQ3gqFYDxy6e6z+bXg 1bn2JD43RLmHRmIbgTtXmMBkvXmnXzaidpem9gPUanEBwGrFJuYh4IAY8hcx5q5jm8z0 a04RGJhEP7uzv4dsn9Tph1EqWsOB6A6shOcHuK0O28psCDObqD9k3UGHd+W090lFD9BZ lidUbashNn7j6lKdWpD8YBuj2eyYsPv3XmKutsdow09/KlWNMjQ2WowTh5apQnSzKQF7 Yw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uvfuu5bhg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:18 +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 3BCAxAsu003210; Tue, 12 Dec 2023 11:09:17 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6e16k-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FuB2eLGm4pDBtviyY0cmvrZb89DFKY8hv3ztWmhFl0yeDJoveoPmgl0Kt3n+/JWyohtHw3OGtRhoADoNJGFpDYaSJXplb29vxBGks++maKAw7EZ39GDqjyVy19H7p+czJ2reQHPU64NHUKWNdSe8RTQqOQJIh8kdwM83I+xGiQBLkACAHSuRn2RFZVMhfqyZ5NV7nS1WBr0zmdbKEhTjyaSqP1qyNisIKIZ2L75nNdQLiLcml16WXh9TyyHanRkw4psAizWjZBdNlDq54oeSLIO7N6Bl49yMJRyQ7FOfs/Y1ULFEDO0rHOmgfM1+9vI5q30TRwne8KIcFOqqliSAPQ== 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=/t0zPXXcRWFzWm94HZuIP3m7HVI3K70dH5CmAqqifJg=; b=KFiiCELSYOb6wM2ZTrH5FxiSQiQItYhYMnww8yZ7jKYwO8CVM3b5OGvVubD74EGGPXbY9adNmvd5VI/uOATZ3Uz+wBj5YQxHj62bFliLsgtlhTZMARbUSrTRssQ2YxdMYnZnWUknTF8aZxMq/DBIK6tnQeABho4oU7Y7zWcE0pJH0M4qIQGvSjGDJsqKAeNLGg2eJ3QsTlnIPnux+iHi357K03R9mHRnJBbbPiQAT3/Ou9sl4X0dQWr9PzSWk4qX8BIflMCjD5raHrXJeaBn7TZDyFAVf9zWhy2lBNGhs2aE3zKoOHajGFtlBoKEr/D/5KrsWW2GmofpEpns14WGdQ== 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=/t0zPXXcRWFzWm94HZuIP3m7HVI3K70dH5CmAqqifJg=; b=ZEBKg62reYevxTCzO1djRdfDTt1Aeq5wBVdZlNuT278008Nvko5g7lCvujMHWedNICCmjYHUpT3FGF6eCi3Cy05NVHby9pB7k2PXjnIxHmaMoVlSV/PCvi0KMrnUVV0VS1OMkgLNaU+hACGdmNPoCSKVvbEWKWjVQ8oaTWXasrA= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:15 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:15 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, Himanshu Madhani , John Garry Subject: [PATCH v2 01/16] block: Add atomic write operations to request_queue limits Date: Tue, 12 Dec 2023 11:08:29 +0000 Message-Id: <20231212110844.19698-2-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR17CA0031.namprd17.prod.outlook.com (2603:10b6:208:15e::44) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 28c6f2f5-15e8-4e1f-f6d3-08dbfb02c738 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ALdBC/EvuVYkOrTCyO/ohDIPyxDnhpPSiQq7eUQj5XJlFfhuktRaucw80P54EHeHMfEgV7pwnZzSGTHB0AvduJcokeDnj+knW43OXMhrvZ92WX8/u2mfjJi8zv81Hywek0Z7A/LTJcJRCAAIJJkE/Et1EJ5NeD/On8XJroTQ1cInyQ8XAq7jhgmm5RuPYQrCqfwplAo5Me9QIcysyHowIDuuvEPEvrRNOzjk1AgkNR5lebrgYVVplBWHuiaB0oaNp4B+nlot2RTWq/jKLTDFD64q8geJbxDfV4MybCiQ2uOT2MwrGCFHQI0zUNS1NO+gbwr3PVaiB4S4X4DXfTeSg3k7YrAZw0HKXZKB7hMHKe9wJdvzXh/QctxeKzAVkJyzLc0n6n7Q+3dJtDjdiVADazTTdUE+srx7JLhPTJ4Nm/YxgDVlpm+0Hv90obZjXnnSfIDBJlh3RNL4XkvkoRolwhkoLE9LU0JTlCchFVptsFeSJ9iciEGrdXSecE/5OCLDUARIANlAcSPqi0+AUemxokkX7EIERpJK9GwlN56NeCzHQnwD7bPl08jdlmQf818jAqjJV2YIugdbGw4IYx781MVpaMEk8mls3YGKLO39pqs= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(54906003)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EhDOrR8F0wnQqw+6Pt25Z5HPpnDjKny5enPwfiaKynUYa452xmXupCf3Tp4k8+6NKPPXKKZvVKv7u6ApkQo17wT3IR4yCRObp6Ki8o4nzigt698Bbz0Df5OGdgLE4nlSlpHTZk+FoeE+jyojKnTMxOXK+fBgfn6FTgz/8LFieQLrjs2MphsyzKYsAue+wlcE+QayYW/nNNIchT/R+xtBxEvSBit0fBXJ3Z4EEXPGS/O7IoK3/5go7+1X1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pMF2ZhFHaRkmQ8/Ku2Mom5NbxJRKU7s8ZbEXM8Zn6yrELHO+yOwrd5Sqdx8lDN4q/suKF/Yxad4B9qrHoQ8NKm7gqF3uOle3zt8ErxiVpfM8uIkxHNCyboFnPgK2hzSCM3rr2PMp9U/zqea03on4GCC1sHrx6xA3h7asIIrhfofiiOkm5DCYXvI48NgItLUnwGBkPLmTpX5bLjFJoJwAFsP03Oo9FYOBz9ws70rROCMdE7TSeJ1RuLX7Gf9DXFBXI5jepdIskj7dXPPG6kO/6j7/WxKA786n7MCmv39TN3C4/Cg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 0qoJPYQ7j+3WzEJ9IXykfVoq0l8unu6lYvLBwikSwTmVDCZNZ8x/nqqE3gIeV75mgIO0UaQXySWL/3tlN4SL7rILlRH9smxNTcQDbcT0qQOJcBQqapS+BR7nav/II3aehOGzPoEh8jq2VfQGifn90GfBybzkmUKRcWArfrtitBqtgwpcfmVRpuxGlcPo+4DanWNP4BXZxR5mgB+2ibsFcLG/Wvrb9v67fWylGKo/ctEkxOGAn/HkkNxDwExmcTfWiP4ufpRIjugjNJbvhXXqforez5mJ4L9xYVVA75cNtstOwBnDff+hw3HOBrZJvzZWKUi///LoD0T/7cfA3+EzvwO79Xn7FJhOo8lUwC+aUZz+rBLl/PH29rEPIiI2JiQZsPmpu/5tdwBHeMbHuS2RZhZx5Av0VImOaG66KmtamN23c2NXdCaHIzIsgcq7IF1Nk8MkptSBWFvV8e2EilY7A+8Cgxukx8LBVLOXoI2PscSILR5h1QFGkugzrCRScpr1GfSB0XmMuMpCSc0FCI4o0h1sF7uS5ZtyAqV/TF1ux0P8s7wfoLS5IL3LCvNcNLEY0d8MdhbN9b8HSEYrf6bcRzHQ/E1u6qN0JOwT7yrXvCY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28c6f2f5-15e8-4e1f-f6d3-08dbfb02c738 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:15.5085 (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: BtBrAxx19HWgQ25pPxl1bmmPccxJusrZYFN/zEG3xBkT6LSJnTLNq4GaGsSrWT0HivVB1vHVytwmTd0ooZ9ImA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-GUID: 68ZRdlAkdztc9O9E1I81pKTctJdFAUUi X-Proofpoint-ORIG-GUID: 68ZRdlAkdztc9O9E1I81pKTctJdFAUUi From: Himanshu Madhani Add the following limits: - atomic_write_boundary_bytes - atomic_write_max_bytes - atomic_write_unit_max_bytes - atomic_write_unit_min_bytes All atomic writes limits are initialised to 0 to indicate no atomic write support. Stacked devices are just not supported either for now. Signed-off-by: Himanshu Madhani #jpg: Heavy rewrite Signed-off-by: John Garry --- Documentation/ABI/stable/sysfs-block | 47 ++++++++++++++++++++++ block/blk-settings.c | 60 ++++++++++++++++++++++++++++ block/blk-sysfs.c | 33 +++++++++++++++ include/linux/blkdev.h | 37 +++++++++++++++++ 4 files changed, 177 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index 1fe9a553c37b..ba81a081522f 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -21,6 +21,53 @@ 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. This parameter is relevant + for merging of writes, where a merged atomic write + operation must not exceed this number of bytes. + The atomic_write_max_bytes may exceed the value in + atomic_write_unit_max_bytes if atomic_write_max_bytes + is not a power-of-two or atomic_write_unit_max_bytes is + limited by some queue limits, such as max_segments. + + +What: /sys/block//atomic_write_unit_min_bytes +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_bytes +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_bytes +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 0046b447268f..d151be394c98 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -59,6 +59,10 @@ 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_sectors = 0; + lim->atomic_write_unit_max_sectors = 0; + lim->atomic_write_max_sectors = 0; + lim->atomic_write_boundary_sectors = 0; } /** @@ -183,6 +187,62 @@ 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 bytes) +{ + q->limits.atomic_write_max_sectors = bytes >> SECTOR_SHIFT; +} +EXPORT_SYMBOL(blk_queue_atomic_write_max_bytes); + +/** + * blk_queue_atomic_write_boundary_bytes - Device's logical block address space + * which an atomic write should not cross. + * @q: the request queue for the device + * @bytes: must be a power-of-two. + */ +void blk_queue_atomic_write_boundary_bytes(struct request_queue *q, + unsigned int bytes) +{ + q->limits.atomic_write_boundary_sectors = bytes >> SECTOR_SHIFT; +} +EXPORT_SYMBOL(blk_queue_atomic_write_boundary_bytes); + +/** + * blk_queue_atomic_write_unit_min_sectors - 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_sectors(struct request_queue *q, + unsigned int sectors) +{ + struct queue_limits *limits = &q->limits; + + limits->atomic_write_unit_min_sectors = sectors; +} +EXPORT_SYMBOL(blk_queue_atomic_write_unit_min_sectors); + +/* + * blk_queue_atomic_write_unit_max_sectors - largest 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_max_sectors(struct request_queue *q, + unsigned int sectors) +{ + struct queue_limits *limits = &q->limits; + + limits->atomic_write_unit_max_sectors = sectors; +} +EXPORT_SYMBOL(blk_queue_atomic_write_unit_max_sectors); + /** * 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 0b2d04766324..4ebf148cf356 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -118,6 +118,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(queue_atomic_write_max_bytes(q), page); +} + +static ssize_t queue_atomic_write_boundary_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_boundary_bytes(q), 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_bytes(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_bytes(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); @@ -507,6 +531,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_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_unit_max, "atomic_write_unit_max_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_unit_min, "atomic_write_unit_min_bytes"); + 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"); @@ -634,6 +663,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 51fa7ffdee83..ab53163dd187 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -309,6 +309,11 @@ struct queue_limits { unsigned int discard_alignment; unsigned int zone_write_granularity; + unsigned int atomic_write_boundary_sectors; + unsigned int atomic_write_max_sectors; + unsigned int atomic_write_unit_min_sectors; + unsigned int atomic_write_unit_max_sectors; + unsigned short max_segments; unsigned short max_integrity_segments; unsigned short max_discard_segments; @@ -908,6 +913,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); +void blk_queue_atomic_write_max_bytes(struct request_queue *q, + unsigned int bytes); +void blk_queue_atomic_write_unit_max_sectors(struct request_queue *q, + unsigned int sectors); +void blk_queue_atomic_write_unit_min_sectors(struct request_queue *q, + unsigned int sectors); +void blk_queue_atomic_write_boundary_bytes(struct request_queue *q, + unsigned int bytes); 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); @@ -1312,6 +1325,30 @@ 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_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_unit_max_sectors << SECTOR_SHIFT; +} + +static inline unsigned int +queue_atomic_write_unit_min_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_unit_min_sectors << SECTOR_SHIFT; +} + +static inline unsigned int +queue_atomic_write_boundary_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_boundary_sectors << SECTOR_SHIFT; +} + +static inline unsigned int +queue_atomic_write_max_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_max_sectors << SECTOR_SHIFT; +} + static inline unsigned int bdev_dma_alignment(struct block_device *bdev) { return queue_dma_alignment(bdev_get_queue(bdev)); From patchwork Tue Dec 12 11:08:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488976 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="CFopWKc5"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="MiYwWPre" Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2B05DC; Tue, 12 Dec 2023 03:09:45 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BC7hpf8021911; Tue, 12 Dec 2023 11:09:19 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-11-20; bh=colzMufsJuw5xL9Z5Ds70rQsQNUsLTo5u2eT2eZG94Y=; b=CFopWKc5NOLLbXC1sxdN2+EtlP9msUFns1JpQRmxKenqjstyw5o6d4/zgCmLed+/DzeP LbnCzRndHbh0vMV0VezHAKqcRUKqqM3/+SPPvuh74z5CEN/NlDGN3UgyFGamreC5RQtW yV7NPwIKgHqVzQtk3mcj3nreGBCuVuc4NF3SoxJscYq/RRTD4p87NCxDEAu4yclU4TCU YZZ0jQS9rRcOaGWw+bj2ciYDHU91B9OPB5AmVQstWvVwgBWz6mu2RYQT4nr5PPgnTxry L2LvCUa2NW4Mp6gU9VSqkI0vrfY5yyZmegMA+lBTxBGq4vCp/FVnXnumwDYY8r5vbnf8 eQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uwgn3kn9v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:19 +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 3BCAxAsv003210; Tue, 12 Dec 2023 11:09:18 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6e16k-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EaSsQWq58fc3Capx39YJu1psXAA23JMPDyzOZUzzXGAMejQX4pMuG0Dh5Oh+/oNbAjt3lyobyDGqJ4zO6xI16mfbFrjlq9l5QvU59e/2ibb8kb071lsF5BeozYPeOAQ6nfma9m9purCe3EE6guvSU1d2YbGz2MX64+dMFqN0yoz5lT2Q+w1C1cB8zhR/jQqolNIXTf0jIuigsS3Pnak4W3P5bv+KPb+Se/brFvgiV8xj3OfcyNa5ahoq5bvQkbtxwwk/LUNvsPCBlvmvyzE3cjjAhHn5lNS9r+BA+TQz2VodqjU8hsv9YYxytkKFeQ4ZRgnzB4RO+BXQ1dBMhHRqxA== 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=colzMufsJuw5xL9Z5Ds70rQsQNUsLTo5u2eT2eZG94Y=; b=iXSPs3asMa0ALgpklXMEtrkMMlaA91XM2ypVkoWlYlKfbEVDIcv1+dWsw4mG1D4qx32ObT18uGrRuozuEk7J3WudZs3+GNccLVgWyqVs0kwfOix56zVB2jFOC5boZek/ctmdZk2LJ8krsf4yAnxDtN5yib0FVZ/NdwttVD9WobaQV/Bjb5MX8ihCH6dsTr0HGXqJL1jyULGONnj0LAtpgAh+xpH/UTN5uRSnA1f1Ntwk2/XRzC2tZDwDmtlWDzz6g759ba29K2LDa6d72ZGVVbRg4rZ1d71v2mo8vryGLyaNWvMY8eWAcM0dn+1z1ygWrw7EGy+Ua/vuro6tXjPD2g== 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=colzMufsJuw5xL9Z5Ds70rQsQNUsLTo5u2eT2eZG94Y=; b=MiYwWPreYfhbO5LRiUVW3XvDb6iCLLuiGACflCsL2ulfzrnYTF2H5cTxjQvUIKftYkZg0P5VpQSAYeSLnodV9TLcOtcu+YViNFAkCM/jOmv+81kHfj8cjGNSdx4oGcUYznY5dsk0LItJivY1YTj8YsQk3PAh6CiWswvWUcIWJ24= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:16 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:16 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v2 02/16] block: Limit atomic writes according to bio and queue limits Date: Tue, 12 Dec 2023 11:08:30 +0000 Message-Id: <20231212110844.19698-3-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0255.namprd13.prod.outlook.com (2603:10b6:208:2ba::20) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: b8ba3071-7499-4102-8fdf-08dbfb02c7f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VA3DmgVxI6WGT2956/2NVa//a6Xof1nJ4thgcfHfqWHuBYugdqrPOPeFD/V3T+BZ/UNsVjeicpXALH4grXzqgNLFPSv5v1n3914+PwmAaFN7Al7F/WGgLX9c0HhqMKPyyj54AcGtzhL+/Blkiwa5naEZGNQjv8bs96F+b0/6joa4EoVuF1uGgPE2dsU6MJbcYhyVWVY0afXCnFvMHp/+33yj+P81Qp/NKJun80/WmzKCXuj2E+3uhJqyhS2aHsDcssZ3XQApbX9Mc1DA6bHLuMRoKcZlI/34yEeFj8LTKs5HVH74dIswhnkvETlTFOdZfGSGnbYj36cObjNpwthLbcwVRvqCjzb0Ecyh/yIZebvFQxb5IQV1750rCNybt2M2OAuWKkacW8grr18oeSx5ftesWVg+4h446zQsQHNl/kiWidpe+gR4NVOJXfCNBetql7KVoQ/2/cyHjokMLLgKnL7Idkq9X6DWpI/jmySXrdMcsRF09pXKx4A2I5sbzd/hPaB9tALFkxuRV0weFacZA3jd1P2oWlo+drdGWXLmy6P3EOwRtjYP7YnOcsLHiHdveZ+SmE7aOykQrsK5Hau+sxk+k3PrjNEofdfpbfJ3f1w= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: clDQ3XYr3tP41S3KEVaIGDnJVozb34F+Qrwq63CkwsRL0cBhsckPN6MHdVMsCxNj88jH2SNGx5iFJRtRKtWFu+59PbwtoW3nKQ6ESRSckmjqYAyWaD30c1y2DnHLWEIw1qTj0QW85R0fJ42F+ZbstUl15lumHW4nV0oDuoQJ/DmNF5MIA0xgxlGbHhqIwpIYdedS5PSRcubE0VrL0boVypnsuHn0UCpwmUOu0Lmk5ou42FzJKu5QNbqh0a/qtDz2puSyHWMlAoU116GELh+W9GKQzD/lT4cIBi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Vki8pCCxX7QkHySs0GAUDOvj5L0+LD4vIGPs4vQga9RvBv4X1x4lrJv39GOBM1KuBnYstf7Z0XV1C69vvgfEpeJHeA0U+nKCPrADjC6/DORvg3qBn9+QuRHnkNih4qaN+amOY84HgWHehi2ct9a/QOqO+bJ/N7vNcEneZAo8na+b+n4uFHzOlyU1nUQN+6oxjC+kzFN/i5YBN3OcvHSB7QT0ZTmPB4k1I6e0Cn8wWQBLt5WOGGkzQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: tVdRUUYctiCmZBDmO3tWUNS0Nl1sStrNAjxTeMtDiZc9Co5egbIRRFZrDKrdjksa/HGBgJUPafJ6e6TIW6FwBXD9vhmhg9+Nlj8yif/VEncPrBEcrHRXMdGPfL3dEoc6pTvVlSQmg5DHlotniUkOwWlvdN4Cnse00SBbpyNZYZ1n8F+wKyk6GrtSs5X3TJFzQIhOSUime8FG2Wq1JBBBBA0U1UIqPifJ47S6ybGzwCh+FeUPI5S0Z6Qkr1X4A/EigdZLKWXF8/zYoN4I5qx1zaVUfuLuqQGFU56e9qLh/3TihKGCzQLK90/LTRERnhBGMCZRMlP4IQX0y3tJpY/FG4jH/sxVW81eryHx2OrQrkim3gyYIB4PSdCDOFeTIl/XDKPtQP4XmlVn/AEFuZtC47P+6f4TX/QE9SuKlQbDyLzmjMkuUM8szhesSnIebWwiY+APocNT07jq93tjJD7ZuDqsQjOS+HqcusLsdJzh3Agm/3n1afwd8zrtUZU5UQwmL4JAzFza0Rvb15X02E3npUFr8sLsFbduDmCs6UBQ1xoaqaMBvEqg0s3wH67aCsUoX19mZX/NWF5QUK55I+9wmmvuLr6pADULpWXPmbaYHXY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8ba3071-7499-4102-8fdf-08dbfb02c7f0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:16.6922 (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: 9j/zpVBTxma448A9oMFeeFtvF8HH22MshB7JXohBydR8l2FHoIBAB955phxe3PuYAw0083n2cA1geQctxyB0GA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-ORIG-GUID: wzi5k8_Qxv2KsbVo_jiven9vdYVAETww X-Proofpoint-GUID: wzi5k8_Qxv2KsbVo_jiven9vdYVAETww 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. A bio may contain min(BIO_MAX_VECS, limits->max_segments) vectors on the relevant submission paths for atomic writes and each vector contains at least a PAGE_SIZE of data, apart from the first vector. Signed-off-by: John Garry --- block/blk-settings.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index d151be394c98..dd699580fccd 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -213,6 +213,26 @@ void blk_queue_atomic_write_boundary_bytes(struct request_queue *q, } EXPORT_SYMBOL(blk_queue_atomic_write_boundary_bytes); + +/* + * Returns max guaranteed sectors which we can fit in a bio. For convenience of + * users, rounddown_pow_of_two() the return value. + * + * We always assume that we can fit in at least PAGE_SIZE in a segment. + */ +static unsigned int blk_queue_max_guaranteed_bio_sectors( + struct queue_limits *limits) +{ + unsigned int max_segments = min_t(unsigned int, BIO_MAX_VECS, + limits->max_segments); + + if (max_segments < 2) + return 0; + + /* subtract 2 to assume PAGE-misaligned IOV start address */ + return rounddown_pow_of_two((max_segments - 1) * PAGE_SECTORS); +} + /** * blk_queue_atomic_write_unit_min_sectors - smallest unit that can be written * atomically to the device. @@ -223,8 +243,10 @@ void blk_queue_atomic_write_unit_min_sectors(struct request_queue *q, unsigned int sectors) { struct queue_limits *limits = &q->limits; + unsigned int guaranteed_sectors = + blk_queue_max_guaranteed_bio_sectors(limits); - limits->atomic_write_unit_min_sectors = sectors; + limits->atomic_write_unit_min_sectors = min(guaranteed_sectors, sectors); } EXPORT_SYMBOL(blk_queue_atomic_write_unit_min_sectors); @@ -238,8 +260,10 @@ void blk_queue_atomic_write_unit_max_sectors(struct request_queue *q, unsigned int sectors) { struct queue_limits *limits = &q->limits; + unsigned int guaranteed_sectors = + blk_queue_max_guaranteed_bio_sectors(limits); - limits->atomic_write_unit_max_sectors = sectors; + limits->atomic_write_unit_max_sectors = min(guaranteed_sectors, sectors); } EXPORT_SYMBOL(blk_queue_atomic_write_unit_max_sectors); From patchwork Tue Dec 12 11:08:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488980 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="bSFKxIx/"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="sfFEiGD0" Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2811EA0; Tue, 12 Dec 2023 03:09:49 -0800 (PST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BC7i9iV008700; Tue, 12 Dec 2023 11:09:21 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-11-20; bh=ywF7mrnAuyKRPnMwwtKddSv+HQAGzlcpV+6vWz6T6Xc=; b=bSFKxIx/FCAf2VgJokIvElPXEIeK12Cw/SshzKGb8U/4EOgja+mw7a/kNMsALWIULijq WMTccPsdRepWaFM8brlEfe5zyZVR3ozVsOIQNmiNp9QiHesWyhm4yjYNwsNWY4gg9Qhi X24FS+OzYisxS1CGW4tJodadTlJCqYtN5/L0WV406DplwQvXcmj0h62vh7vEMs+PMlca pM2wEBieVrOYrgEqC55dInRJ1M6pQH5oNVuz3NIC9x0IPyyqoceFB3+defulCpNtm9s8 fdqxeOpImsJmMhDADKKzKfNfR3mbvixRUW6FfteDvXKBdKHzLFIftdT6Gx8iEgXqcI/M tw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uvf5c5bkc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:21 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3BCAwIaq018681; Tue, 12 Dec 2023 11:09:20 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6d55k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lIMY9gWlE1rItzhV6SeEC2HMAY9m9KkKGyGE5rmJsH6dVIHIWnsb0NTyeU1G2XhG0JxxsJkbjLLD0kWVG0ve2qGdIXQ4CTEqDWU7mXFKD9wYG6ZUfIfzOZGX2e1jFm5NCxQ5Pst4NjnIESH0XG0MJjWpXCbVT3j6FsV+/xLtuXpjMv2LA7WhKylMG1mfotzhahbEdn/PtPlErH7MvgxuLo/w8NT7HB/woNwtxBr5ZLAwnQkgiEKlyKdqtsl4jPWyAnboqq4QSwUEpf82mFaBtrM+XZQ78Uay21u3gZcb7Qb6mZ6dCBtrSrSPfgYQxQ/WqQwrnOocDrjFCnTCV3STBg== 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=ywF7mrnAuyKRPnMwwtKddSv+HQAGzlcpV+6vWz6T6Xc=; b=aovruYB9E15QYWFfamL/HS2hx/QW41OrQRk8Q87dqmB5dzJSg9frUbL6UycOLxTz9PtvIVQYQ+ONNJfUFSQX4/jLY55ZGFBuGX+kiGs2fepRWD/z3kywu1ZICsxH2bbHa9S1Z7fdr9mCts0wL3aFmmVBpMWa2XARAS/j+QvBVBD8Aj4I9RcFlJoAXJXOdfvzaE4m4qP5m/4Hrxwsog603mhy0kkk1RC9WmqiKrADCExOgipGpZ8Z2ceBfPuvUZYa2CtKV4NoIR0BwMEfzqYADWoz1oGjrpJBLxxHzfxmbq/4+qkcAy1a0FEM0YowPK04MwQENPZAtsY9/nXrhXiCHw== 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=ywF7mrnAuyKRPnMwwtKddSv+HQAGzlcpV+6vWz6T6Xc=; b=sfFEiGD0905Qvqz+gfZUi4HtxDBAIaqAA+Qret6S7boHLO+1vClbMWnvdJEwGJvfpPuRjs53Wcd+bypQcxoLHGt0fcQoAgZ7yMZbLPU4/sNVeA9h03w+e7s4Knrz6dm+1yZXgDAvIF2inTShZBPXuz8Zaa3YBRNrcNsrpfA8PIA= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:17 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:17 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, Prasad Singamsetty , John Garry Subject: [PATCH v2 03/16] fs/bdev: Add atomic write support info to statx Date: Tue, 12 Dec 2023 11:08:31 +0000 Message-Id: <20231212110844.19698-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1P221CA0020.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::7) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f01874c-80bf-4c8d-8fd9-08dbfb02c88b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 90NJowif3oo3W/0g79+Iiw8ekzNF53dm1h/6Xw5FQu01Wf9HogVRKtPppWzBUPhUhvfDu+lH6ndppIi/XhuJMNY3MgeGy8/di6cZfF3kIhHDmFiCw4PGx16LwQBLMRLtdEeEDGvmdAEt2ZJam9hdDC/0zjSOGPYEGqLBZSyeWc/gpUVN1szoF9fe6MPreKHistHhwxWk2UIVgEiHCrD/M64NW/ijeUfJkudOtqI2vfilhFV7X6i8HGvL0R9zZZTqIdg+3VVlOUl99QxDEKoJJL4iQx23bwOpN5h0jq/T/JB9gSxuTQodGyiYLxR9zcUkkwEnZi7ikaqne3ka1kjWPqBL6cGDusvX6KYG18HF74SObAkYdQZ/hmPEvdmYufZMnLuvjJFXCEa41+b2QG4OLlC9r/t8zE4I24FeMIxkoETmOrDuyd5r7RDcLfatZD0uFRn3mT+OlNfeeBq+jsIhrmx4cT9St5hnIJq2AQElT1GwJYe/zCnfQLhQH4le3LpqprcfD9X5Q1/zIZHjDsFUe4J+ATSPSVgviO7Ymf032S/+yzHGhc6ocBqFkiZXM3Cxs+29ih13zbLNd0Vf5g4EdrErS6z/D9cWXWXmyxS/lKw= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(54906003)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lebSU4I2Pj9Lsl5P7clfiqPQ8jMqNLB+EP31nzrCWFEkc/3qIlJ2U4F2uc4dyJVdo6QyYG7g62ErmA6SU8cLhXV2PhucB/e3Hpk7DBxKZsuCwBGG5eEW/oX0RW14PXNGG6MEVl2hICfWYLLONCH2Nfpi1J5OEoTawy8OfKuh4Xt7/d7P8L2yYPp62s3y5gVOKelTst/RIb2mQIn6xR3spAe5jd0CCiPvYxfOrXePuNiPe5oijQiZFRWcEWo3sPu/WGHlXYidbaQreJF+xhDS4qpB13Wz42jVPXylLPLoEKyBX5HuBxPtHjbgtcXEhtOsav3iXvc7NtGrX9TyZJRvhnQCtAsboMFY5CAuttPeXZBB+gg68roz3GzxxZa3lTFidzkJmg5C91uP+m2VkLjVbBRwgLIa14JVUItVRLVwLcUEU4XG7RUOT8e9wYe2wt16NEM6uzkA9IYjIWcOKPYrAZEb0Q74TrWNPboPQPHpOorxMJggw+pWHS0fXdS+Pe0ARBLtiaMVN8nPBdcxcwf8OukgySL7tiIidW6pcrPez6patMMUohHBpLCpiCk43bmbPN1OMjqRD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Exchange-AntiSpam-ExternalHop-MessageData-0: z2+eAYzSeq10mErczKYNwXZGTH9YBRjhpv/LMAyjAuSkpKkVPXngtVhMaP+rTNQXKTP2Ttk7SN6xZOWpldQVW2qmTzkjnMnFbpgM4FnVZ/fLnuV2TID3Xbyw6k1lgW9XMpxawJiLzi9GWynoWm4xa/M8Y7f2iZiQuMVYW83WStNNNH0IlpwXeUEI9vrWPvnhFUu+JXkWlOp4+/X/XlsrwXBKLHl2CP2VimTk5ic/pXPDVm8V1mF21BAomRwJXTD6QPXSdCi4KvVqf8FVG+Kfz7XGfM/IWWsouI65LV39nuPMOLgMQLj+V8xO8cFeTtwrzov29uv/lI1Hn75GjTKDpgkQZ4sa16Kb8y7apoa8JRAUNsgfbenxXjmDzf8ktbFdFrvYh8LMrcjX4P1FgEdwZvLXWYY3Isbonffmn9LEe/Myr7U2JugGKhoIx46SgYaE0+o4s21iaKeUhyrjG/mmtS1rFXYiV+Fa8ORxQ/0WcFEuw0BvTztSfI7XVbfK2HIT+St4sNmY8+cuGfMuVcpvoo2KmLdRN4GNH00xmW8rPD6H5Wi6eN7hWimxNBRbQZpXFjNuGoy9VzcU0MfDB1WKlzSLMjXkz36NyM8YsekTJ+Y= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f01874c-80bf-4c8d-8fd9-08dbfb02c88b X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:17.7129 (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: 9QsViAfy4THZpCHHX+HbN2uEqPVMvIdIFvBAgadMe3qAy4q+smTZ7J5BpDeDnMnlj5paw9Zn0YNtjoPcmP2vkg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 spamscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-ORIG-GUID: 043myKRgbO9iU9jJvO4bbnqMxK6b5qa4 X-Proofpoint-GUID: 043myKRgbO9iU9jJvO4bbnqMxK6b5qa4 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 | 31 ++++++++++++++++++--------- fs/stat.c | 44 ++++++++++++++++++++++++++++++++------- include/linux/blkdev.h | 4 ++-- include/linux/fs.h | 3 +++ include/linux/stat.h | 2 ++ include/uapi/linux/stat.h | 7 ++++++- 6 files changed, 71 insertions(+), 20 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 750aec178b6a..1b514df48dac 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1081,24 +1081,35 @@ void sync_bdevs(bool wait) iput(old_inode); } +#define BDEV_STATX_SUPPORTED_MSK (STATX_DIOALIGN | STATX_WRITE_ATOMIC) + /* - * Handle STATX_DIOALIGN for block devices. - * - * Note that the inode passed to this is the inode of a block device node file, - * not the block device's internal inode. Therefore it is *not* valid to use - * I_BDEV() here; the block device has to be looked up by i_rdev instead. + * Handle STATX_{DIOALIGN, WRITE_ATOMIC} for block devices. */ -void bdev_statx_dioalign(struct inode *inode, struct kstat *stat) +void bdev_statx(struct dentry *dentry, struct kstat *stat, u32 request_mask) { struct block_device *bdev; - bdev = blkdev_get_no_open(inode->i_rdev); + if (!(request_mask & BDEV_STATX_SUPPORTED_MSK)) + return; + + bdev = blkdev_get_no_open(d_backing_inode(dentry)->i_rdev); if (!bdev) return; - stat->dio_mem_align = bdev_dma_alignment(bdev) + 1; - stat->dio_offset_align = bdev_logical_block_size(bdev); - stat->result_mask |= STATX_DIOALIGN; + if (request_mask & STATX_DIOALIGN) { + stat->dio_mem_align = bdev_dma_alignment(bdev) + 1; + stat->dio_offset_align = bdev_logical_block_size(bdev); + stat->result_mask |= STATX_DIOALIGN; + } + + if (request_mask & STATX_WRITE_ATOMIC) { + struct request_queue *bd_queue = bdev->bd_queue; + + generic_fill_statx_atomic_writes(stat, + queue_atomic_write_unit_min_bytes(bd_queue), + queue_atomic_write_unit_max_bytes(bd_queue)); + } blkdev_put_no_open(bdev); } diff --git a/fs/stat.c b/fs/stat.c index f721d26ec3f7..ad8f9235f1c9 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -89,6 +89,35 @@ void generic_fill_statx_attr(struct inode *inode, struct kstat *stat) } EXPORT_SYMBOL(generic_fill_statx_attr); +/** + * generic_fill_statx_atomic_writes - Fill in the atomic writes statx attributes + * @stat: Where to fill in the attribute flags + * @unit_min: Minimum supported atomic write length + * @unit_max: Maximum supported atomic write length + * + * Fill in the STATX{_ATTR}_WRITE_ATOMIC flags in the kstat structure from + * atomic write unit_min and unit_max values. + */ +void generic_fill_statx_atomic_writes(struct kstat *stat, + unsigned int unit_min, + unsigned int unit_max) +{ + /* Confirm that the request type is known */ + stat->result_mask |= STATX_WRITE_ATOMIC; + + /* Confirm that the file attribute type is known */ + stat->attributes_mask |= STATX_ATTR_WRITE_ATOMIC; + + if (unit_min) { + stat->atomic_write_unit_min = unit_min; + stat->atomic_write_unit_max = unit_max; + + /* Confirm atomic writes are actually supported */ + stat->attributes |= STATX_ATTR_WRITE_ATOMIC; + } +} +EXPORT_SYMBOL(generic_fill_statx_atomic_writes); + /** * vfs_getattr_nosec - getattr without security checks * @path: file to get attributes from @@ -254,13 +283,12 @@ static int vfs_statx(int dfd, struct filename *filename, int flags, stat->attributes |= STATX_ATTR_MOUNT_ROOT; stat->attributes_mask |= STATX_ATTR_MOUNT_ROOT; - /* Handle STATX_DIOALIGN for block devices. */ - if (request_mask & STATX_DIOALIGN) { - struct inode *inode = d_backing_inode(path.dentry); - - if (S_ISBLK(inode->i_mode)) - bdev_statx_dioalign(inode, stat); - } + /* If this is a block device inode, override the filesystem + * attributes with the block device specific parameters + * that need to be obtained from the bdev backing inode + */ + if (S_ISBLK(d_backing_inode(path.dentry)->i_mode)) + bdev_statx(path.dentry, stat, request_mask); path_put(&path); if (retry_estale(error, lookup_flags)) { @@ -653,6 +681,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 ab53163dd187..ab7289995615 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1548,7 +1548,7 @@ int sync_blockdev(struct block_device *bdev); 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(struct dentry *dentry, struct kstat *stat, u32 request_mask); void printk_all_partitions(void); int __init early_lookup_bdev(const char *pathname, dev_t *dev); #else @@ -1566,7 +1566,7 @@ static inline int sync_blockdev_nowait(struct block_device *bdev) static inline void sync_bdevs(bool wait) { } -static inline void bdev_statx_dioalign(struct inode *inode, struct kstat *stat) +static inline void bdev_statx(struct dentry *dentry, struct kstat *stat, u32 request_mask) { } static inline void printk_all_partitions(void) diff --git a/include/linux/fs.h b/include/linux/fs.h index 98b7a7a8c42e..70329c81be31 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3084,6 +3084,9 @@ extern const struct inode_operations page_symlink_inode_operations; extern void kfree_link(void *); void generic_fillattr(struct mnt_idmap *, u32, struct inode *, struct kstat *); void generic_fill_statx_attr(struct inode *inode, struct kstat *stat); +void generic_fill_statx_atomic_writes(struct kstat *stat, + unsigned int unit_min, + unsigned int unit_max); extern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int); extern int vfs_getattr(const struct path *, struct kstat *, u32, unsigned int); void __inode_add_bytes(struct inode *inode, loff_t bytes); diff --git a/include/linux/stat.h b/include/linux/stat.h index 52150570d37a..ba690ff89efd 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_min; + u32 atomic_write_unit_max; }; /* 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..64dfc1baa640 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_min; + __u32 stx_atomic_write_unit_max; + /* 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 Tue Dec 12 11:08:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488977 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="dsiBiY09"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="SAPQKOIK" Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C31DEA; Tue, 12 Dec 2023 03:09:46 -0800 (PST) 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 3BC7hiwQ004107; Tue, 12 Dec 2023 11:09:22 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-11-20; bh=QsIaQSQ10+kf+HtOvgYV+0Vtu3ksOr0hxsYP642ebaY=; b=dsiBiY09VRGUGy8/LFrYQPw9RE+5PiHSyZohCRf8AAbW5XIjBY8s2rlzMb4vCrOvTBdM dUBqrjVUTJRVKqcyNuoZVig+F8bKDxKemk+qY0TIcps4TLxpdAZVHqIRyBFBDt1FWaKw qElCghpSQXrNxjU6+rdPYP/JtOqoKT4DQXgp8sx0540R1oOygm7MJqKeMYykQCl4Il9F IrTkrwiheD+QzK9XZ2bKJK+o6ze64g6uFjIWv33YTbwJL1V7b8gqHG265QwD/2rvSPoj ZNnFhcexejB++VdzGsuqupCiSYQJhoLr24l1AqR+vxZPn8x3JykDkWcflf4kMtws+fnB NQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uvfuu5bhp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:22 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3BCAwIar018681; Tue, 12 Dec 2023 11:09:21 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6d55k-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=biyuqB1znf+YA6Ww/DGAdkKCZFsG1OaNNEOgVixJ83sl1SgXiAOjoxJvWBT398yIGRXT8KGClSQcY35GYEvUMxcrtw5eu+Dh8KDX/uE+fWkQNZalxPdlYHv1gZJBEd8B87riCrW8azyz6Le44ScJqG6Gb1vmGkuhxApxZ3+TQPcVuWh9uP9JZj/59kDwbTsmsskDAjEk+O/bOll1HKuEhtsJcT7hWYrCPbXo0Yl0TAj3qn7zVdfxcJHh1P8dVIm0VEoXfJodAdzcTxNTYuQSpvwtriW0iRaknkhr7nzlj2WzLd+6ubnSzPlZpdxNO7C4DO4qq3iu8vKA4AmMi4tcDg== 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=QsIaQSQ10+kf+HtOvgYV+0Vtu3ksOr0hxsYP642ebaY=; b=cHyaNwiPwXZB6vUbR/nW8Avx8eB6JAj8+I7FMvPjUE7qgvjfRcd+04ebEQvIlh3Z0biTt8E56Inctvupd8fZ46IIR8nEWgfdNzWB69FtcKhazQCyex8d3KRn9fX7CDxMGbzvXmwyQ1SOAJEJV489LlhVJHs4huqB6u/to1Vdpz46cWlAuS1La8/LY+m5OlZwbdzUeKljbzR7B5xMc91nuK29QJJihRj0i/SZYVXhlVnM5b8hSlZ4Jv4WbNcxBHo5MN1+dBgjjpqZgUn47WHpzmvEuLtddXXfpMyWbzm1jxf29mw6T9zWRwSxrptsJbEMv1D5rkWvOku1e/Xh38bQcw== 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=QsIaQSQ10+kf+HtOvgYV+0Vtu3ksOr0hxsYP642ebaY=; b=SAPQKOIK1Y6hKBQS42EHXriOLgFQvxk5xBX68JwJBUUqsLrHugGNJUGM6T2yEDQvE2Uebu4kjb848iUKNuwWeVPwKmpz45rsDPhGas+2s4xM564+diz9G1XF6Ozrzs+m5/rVdsu+rprdC/6CkLoXloJ3dR9JlQIkVBH1FzWEcgc= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:18 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:18 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v2 04/16] fs: Increase fmode_t size Date: Tue, 12 Dec 2023 11:08:32 +0000 Message-Id: <20231212110844.19698-5-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR19CA0052.namprd19.prod.outlook.com (2603:10b6:208:19b::29) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 7657232f-660f-43bf-c272-08dbfb02c921 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JyygQuPpki0xctdwshaMOhPKHQeQLex/5qSEFjoOlhzDg7cmAvOEf9mPz2vyRe2S6+AWrEaLTODxI+S5wAvhgql78DqCWevFcEnWlZaPTsLSS3WBxGsZxPsHbc1zJeR9WA1dhYO7HuMBv1h9oNzbfDzez9hspsUItKotRZZI7RWR2zmLQfIZe1c1sVXK2lHbiIKByQfOjqdwyY9OPceFRj0wgZON52hfYo9G+kOC9YdNHPk5U1jnxt4oBkvIHs1gsgTS9Ak5mkmdKfPDmlblAXHslCW94s5BRKY4fTw9a35m+LG7pTBoowV8kK4QfHiMG/5zmdULXJc/bNI/jQIeiSOJdml2go5RhbZnOcHTkGxpEsWXFA4hSQb1jJabdobIdigNGJ0z+6melj4lhZLG7l5YzsdhCP5XGud6G6rUV5zSFgiV4IiGAp+Jyq/rd5KYKCabYZ6eCSu2BUIF9gn5oXXWgoIeUQwcTtsfF6W4F97SCi9Zf6y0jO0fAibe8JPl3Z6MBAG8ONdxY1qtSjDb/Q+2Xj558yb+KYxpLfdJ+ATK4qjnfcy0Ed/WLnfB3vsh+jF1WeZE+iJ5RnvBv+55EjFOEgMt/CjRNxhYAe9SU1U= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(66946007)(103116003)(86362001)(36756003)(921008)(66899024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jTTzRuh1XIYH1V3leFJ9NYWzecnd4f3h9cyW9rpoUUeWQpw6rVNr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JF3AS+vYINDtK1wEIuzGzRkHYooRbS83kzau1Hii64HLW/aNU+kCPCcukF4tqs42onW20sC3497BxzIEl5rJ1XqPO+qq0xGUhV2viM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7657232f-660f-43bf-c272-08dbfb02c921 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:18.7061 (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: rAU4+dEiOkNZK7qbq9sKhn1PxHPYL9sXqmBIgDpx/t6+GQb40yf+8Qr/NzCzIgpxOAU0vi6ZhQVU5Rb/DtyUXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 spamscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-GUID: P28bIBxBDMzJ2l0uxtjFOenkqUGGZokq X-Proofpoint-ORIG-GUID: P28bIBxBDMzJ2l0uxtjFOenkqUGGZokq Currently all bits are being used in fmode_t. To allow for further expansion, increase from unsigned int to unsigned long. Since the dma-buf driver prints the file->f_mode member, change the print as necessary to deal with the larger size. Signed-off-by: John Garry --- drivers/dma-buf/dma-buf.c | 2 +- include/linux/types.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 21916bba77d5..a5227ae3d637 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1628,7 +1628,7 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) spin_lock(&buf_obj->name_lock); - seq_printf(s, "%08zu\t%08x\t%08x\t%08ld\t%s\t%08lu\t%s\n", + seq_printf(s, "%08zu\t%08x\t%08lx\t%08ld\t%s\t%08lu\t%s\n", buf_obj->size, buf_obj->file->f_flags, buf_obj->file->f_mode, file_count(buf_obj->file), diff --git a/include/linux/types.h b/include/linux/types.h index 253168bb3fe1..49c754fde1d6 100644 --- a/include/linux/types.h +++ b/include/linux/types.h @@ -153,7 +153,7 @@ typedef u32 dma_addr_t; typedef unsigned int __bitwise gfp_t; typedef unsigned int __bitwise slab_flags_t; -typedef unsigned int __bitwise fmode_t; +typedef unsigned long __bitwise fmode_t; #ifdef CONFIG_PHYS_ADDR_T_64BIT typedef u64 phys_addr_t; From patchwork Tue Dec 12 11:08:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488979 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="CTxUYleb"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="UACCB3dz" Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFE1AB7; Tue, 12 Dec 2023 03:09:47 -0800 (PST) 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 3BC7i0Ym019194; Tue, 12 Dec 2023 11:09:23 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-11-20; bh=G9uPYGSR98Rb88RfONFKc4B5xQ0ce0WEpJWuGlPoTCU=; b=CTxUYlebMRRKF2HWSBlcFw5uaP99tSppZfS4tuOz/XiSRyjfeMEzD/b6VbJIAGg7KKZ3 Ik4rGSOaEcNAq1ASM6qZb/gvCKwBxN70XM9VcvhbCMMBmH4Y8WHKoqhKtRX7qpH2orZ8 Wt32QAHaMxq5KwxzbptPYXH5SYZJ6gaAR3kxn5nJQ7p9V0Vs2l8R2Dy14qiErL1KIJoa VnVNXYm9yRmRujesHSES2g+JY1jJfoxsVutEfGGG8WUgV5XZBuIDxgtoHB4X1SnoWAn2 cHO68vFDDHgKoXppMmGAs5w6B+cHu1GkwBeBwdvdoyopxI+tZHBZQebBLovtmOXA69VY Sw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uveu258rw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:22 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3BCAwIas018681; Tue, 12 Dec 2023 11:09:22 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6d55k-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N6dfzwvgTQAZpkQXZpWJGrvvSKjTnYHTqW3PSo22r6rrOhNY1eFZiCOUwxAAqchL/LPV6H2uBE4S6jeLOkbA1MCPwE8mKPc/MHlfcQ281+K7NJnO9KVANlzUQ9efeRoN1NHPpBxRoiZDY+McU+9+NmhsA6XrodqzDo0FDyx8EdpqiPj5hpja1owOkMwwonwH02/Qbd7gtQ6VnRFZuNQWMb4MBSlKFba7w7dgSHZCKd2rd0dMrxN2pbaXMCKLXQFQwWPogKhLtfFEJ5VLzYGAryuIa5H7qGegCYS3UtpdC/AQwLoCfRV8SS1bNGYYEUtqmVZRooebH7uNf291rGH5Nw== 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=G9uPYGSR98Rb88RfONFKc4B5xQ0ce0WEpJWuGlPoTCU=; b=LQCWI95oIStMdKp2VKqEETYGTRwhG/VokQ0kYr69qjLgqmkrgn4XU598+5K4G15QB53PDCAs7pmNLWp1dXDph31ZtmLEQ0qN5NM76c/MJSP8GPdgXZsIPxpI4JR7sDjqc6qFRNXbV7R8uJvwMj6QSb/Qsqxdj2B6iGltdrTtaF4rpP35ltnG3YY5nvYIGIkROCfoa8++LvUA3eLCwtHTUNNpju/IjxJKFjTkc3Yn2qHj2AgGAJ4L2h/ppg6V2f9fQICSo8dlLuFsn4iUneJISGlQUh5/3ob+gS2PeeGWr86r5opBH+TiPaBs8sgj+7AVPMeTVzgcNJYpYrfyJpvqVg== 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=G9uPYGSR98Rb88RfONFKc4B5xQ0ce0WEpJWuGlPoTCU=; b=UACCB3dz624SdpZQDrgf5J97z1Y8cPsA7xJr7JiENB3Xlg/9NenMCfYbEuCOExOEQdTyT7jbV+ESQwnPT6wriVsOV7MNYmL0nlOL0JZt+dWr3MS5+Z7rUFP8eyhnMwspPBgfknqXPQEf09hhKjSD3eiL57yXtrgS/xQjSu/yAg0= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:19 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:19 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, Prasad Singamsetty , John Garry Subject: [PATCH v2 05/16] fs: Add RWF_ATOMIC and IOCB_ATOMIC flags for atomic write support Date: Tue, 12 Dec 2023 11:08:33 +0000 Message-Id: <20231212110844.19698-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0365.namprd13.prod.outlook.com (2603:10b6:208:2c0::10) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 551c8a71-72ba-4e49-ac47-08dbfb02c9c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Fl4oPW/09BJjkptrAGvunxT/uPA7RIHpOkBhDDsSjO1B/bRaFloUqY8kk6BkQv6TjnS8qJjhRZdFwxDjIfMjd0FUrk84wgjfpCgmt5e6OGpSL4oYJzlyJlURZNvkQkQkcel/69ccNBQvz2uUB1vdCtJltGX//5JicwUjC3SE1B8ZHz/eo7d8VDtP4PST06arwmZTKbMZX/n75wVCegDJ1vnwz9q7CWP8bLBXL489voJ/WmO5r2CqXzBHRkZ7nqPDRzf5p+tGBpG0lUjU71gvbcDICQc7Cl+CF/80BQzV8sYf6OTrR1jGjUf5AxYImHRv0tp2aSwNgIvCHH/WdIG4Ekb65uhZUtNFlOg4chi21pbofrUmG9dNAEdkM0nAvHO4Hc4SEyrabxzUCzzuCYSqaKxmBvdV2auNXy9jMki1Ao687m6RrKapMoVJnnAm9Cs2ZZjUoFYkgVnLkBNPRciNhul/G1HEDJXcl5Z/kmKSsnsB179JuCZzMYfSp3nkH+PeJCu/8+Ho4/IrG3m9ZEzwK5ALUeCi5KgEUMMGchkc067gWcrf0/Zx1ejaxAj0tpkeDQZNOj+WVGlYONJrbTBNizvPv+BGBKXPk+a2Dv86igs= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(54906003)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wHl69egH9xBqAN9hIGoaQZiG9wgkLRPFnHBN0Kfoi96tEvTWQxcXLpGDWxIU89uxlkoK4xz/g1DVlj3ZLtZWAxqJlXp67+dl4iNvv6l5KfFHR3w3LJQpGJooeHcJkDKnjMxeqJ3/gsxDUJS39m+9VGYH3wJPO4WFKoQwaisoU1h5Up0oMG/E8VAsfiliwllZzFtnohgY6fy4VP8pEIcuy84Ic/4oZTW+a5cskruTxZLE8up1cmWXgGt3CvAoB6qCXyJwDmO6ajpd5Y10cyxIAT9TaSn+8uJyXcXkJ999alKNFIn2GxM/CPqDgVNyEPfjOxHX/ZJoI8AboH+FKEpO3vA8LS5rM37gpA1SRZkzHstD1npWppKP4bvynSZN9GkMVYxG/YTLhcU2hbtWdV/mLda0EWlu3gupnSQcDoDfMPkKY5DKM6xqL+QLxPTThbQ6JfeKSA+WrHShJfV0PUj+t1zRwTby8AJFq+QCKNeOdYeN0Od/9vPjWCvbppmam0/MZriX0ADq73PIXL5nO+sz9Hnc4mogRUyi3Q5C/byOkG8j4Fp/1kjJvqi9j34QexQLIkMzkom85UbX3sbrWKhDI9bSPQiWlpl/FWJKROSCrROxJbt6MzRnTOLJt1kIiCDYkZ4rbra+04pYj6YtIJRcnWH+GX5wnLuZOzVIAPVUpytzNAyIqSGNS0pY1oDu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oFiDtOlLSytE6lg2Cp9mpE2QduzOpAIYpUYrJYOvhWlIheEbc63pf37CFy9MRjUCKgY6f/B3ZliGSLx6s0nBZMkt+6lX6NrZh9xQh4FhcO3aKyEkXeT1fx1GK9MLPHw06+2hqBL8ggDX4lyX1ZwNpoCCeKXsbts9TLRm5C6BHIAoBRzNr8WfM11oOzVkgTMFnFN7oFm6qaXKIzAzS9P98eM0bfjtL4RD8KmT9jRPGMt8hTaPs84cnCUV8HWtiYquHfxLKjncvnJo6L1tIuPHJHQgoXl0TnlyfRcCt86tOujQTCcOZJBlYeHjN/kPjX4qw2AO4Icr55jJQEPBmXF+d0YlL+gQRmHB0d+pstzQ01zApomUhGdxvRz7dprXN4GLVa26dvh9Fmrx1mfg3zLxFlPopx9OmM7T5zSUO9nJUITMX2pT76UVwlLHS0cJeFcjZSUbqIKDtbNz1JN557JGKlwrN+sMO1ULuQaMRVkxoXR8mpn8pInFmNFAaI6R6q1DaL5hG0jz9ERGzrepkBftSEXHY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 551c8a71-72ba-4e49-ac47-08dbfb02c9c8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:19.8312 (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: 29Lc2AFRS23sOfpHEB9W9E3mDcSqPMa03AJq3hpQ3jwIhdKwU2GwBLkoS+p78eAP7B6aDY2XsgqHchUzLD7pMQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 spamscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-ORIG-GUID: _hof55kIx_G12pWsjH5qXTiXeXjdeOe- X-Proofpoint-GUID: _hof55kIx_G12pWsjH5qXTiXeXjdeOe- From: Prasad Singamsetty Userspace may add flag RWF_ATOMIC to pwritev2() to indicate that the write is to be issued with torn write prevention, according to special alignment and length rules. Torn write prevention means that for a power or any other HW failure, all or none of the data will be committed to storage, but never a mix of old and new. 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 the total length of a write is a power-of-2 in size and also sized between atomic_write_unit_min and atomic_write_unit_max, inclusive. Applications must ensure that the write is at a naturally-aligned offset in the file wrt the total write length. Add file mode flag FMODE_CAN_ATOMIC_WRITE, so files which do not have the flag set will have RWF_ATOMIC rejected and not just ignored. Signed-off-by: Prasad Singamsetty Signed-off-by: John Garry --- include/linux/fs.h | 8 ++++++++ include/uapi/linux/fs.h | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 70329c81be31..d725c194243c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -185,6 +185,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, /* File supports async nowait buffered writes */ #define FMODE_BUF_WASYNC ((__force fmode_t)0x80000000) +/* File supports atomic writes */ +#define FMODE_CAN_ATOMIC_WRITE ((__force fmode_t)0x100000000) + /* * Attribute flags. These should be or-ed together to figure out what * has been changed! @@ -328,6 +331,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) @@ -3265,6 +3269,10 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags) return -EOPNOTSUPP; kiocb_flags |= IOCB_NOIO; } + if (flags & RWF_ATOMIC) { + if (!(ki->ki_filp->f_mode & FMODE_CAN_ATOMIC_WRITE)) + return -EOPNOTSUPP; + } kiocb_flags |= (__force int) (flags & RWF_SUPPORTED); if (flags & RWF_SYNC) kiocb_flags |= IOCB_DSYNC; diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index da43810b7485..1a5c68d31ef5 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -301,9 +301,12 @@ 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) /* Pagemap ioctl */ #define PAGEMAP_SCAN _IOWR('f', 16, struct pm_scan_arg) From patchwork Tue Dec 12 11:08:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488975 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ieqL4Dz7"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="CYkeF4jt" Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B26E3D5; Tue, 12 Dec 2023 03:09:45 -0800 (PST) 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 3BC7hlpb028870; Tue, 12 Dec 2023 11:09:24 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-11-20; bh=LBFgxpedTkFbvvKS24Y29UjrBHCkfr4l9A2KfGnrW84=; b=ieqL4Dz75lRft8mwNoeRckfT/yJwuZeA8GRkoROPjS5MKJvQrLAr47hn6pZHAyITakJq hK4Ju5YKVgF6FJ78pD5nyPAMUmq0YqpullAgzbKhF4i3Z5N1Jca+GBCQJJ9CENebKuxQ dcOVY+fwo27XwhBvfA+sDV+9/TrM+y/k1J3Q3xD2oeDMiC3T8s4nSFEs/PNrjdmUZ9Gv nsxiDtYRiwvWD3sCjCMSATEVFgRzfyoKYs15qw+YWc0MiCAlcKA+rTCMASHk8mOiFbzF dsagv0vzYA08/o0m0D3X5B9bAInNNRc5BLnK6M9l9JjR+1qL/KxgvAP4+goVaMxarHKW XQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uvg9d5da0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:23 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3BCAwIat018681; Tue, 12 Dec 2023 11:09:22 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6d55k-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XuywUQWAW+X38ipm5PFvWFWHuo8y8u4BNFy2imCIV3YYhGRxDQy+sC9bNJEawNeIheKlzlk++kNmQjaIIiPtaVo8k9G0Tj5qYwuqmGresO+gTvlK7vmL2QWY83+3jvr6vmkazvuZ6JR0xOOtiTwfULmpBr3/H+Hm4hDC49diskIYgOVolB3Pdsl1CGd+4u7glRC2HWWrMM+SLwKUmoMCn6cbfDX7hlgGIGAsPQocyMCcPGzD9wO9spkzqMy4fFbUO+3zKNHiWnIEob6n5ixHeIY1miRPDydB2hNaVgRo9GlXDAKKtg8D4ST8TgYnYret+b8QZpoWWSqDLDjFW5J6gA== 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=LBFgxpedTkFbvvKS24Y29UjrBHCkfr4l9A2KfGnrW84=; b=bgmio9zQsjIX9kff4LuWMjjeAuA/k39Zh6hE0IGCYQAcrth0NUxyBFfkO0W8d/i2AL/9Z7pFFYdz8S6tljxFYRb9mUraxi+B/KbxMCYvzAlwzK3Loqp3OwYIX/1MeRLncposyXJNr7q/ZwSWsiIpXDHQjVuLYEdXdB2L0D5FYxd7eMXZ4SX3CK/Fanb7ELhis1Qsa+8jUatF9pW/gZd7JSdYiU4/Qj/4P+tnJtZkjjwn8Wg/1t4ypYWIw/sLfIjiuXfFmONDJtZxNgaX2kuSMTr2u4Xz3F+b+XdolBqO9BKijM3GB/ShxBIOGTzH6ZCThx+oq1OATc4so4ergZD63w== 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=LBFgxpedTkFbvvKS24Y29UjrBHCkfr4l9A2KfGnrW84=; b=CYkeF4jt0uFjJIjelC6xLsayayYtE26vo4BK3SejT7qyLTDk3eZgqU7+LXwri9TLaRtghh1ffuEYbdLJr+D1W+iRaw6LtjV994FAmUXbOFl177EEkLg0YjhcGWfTzylEVluiX1eFyHY/tt+MkKfAL7s+UXp+N4+MgAqr9cw0vE8= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:21 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:21 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, Himanshu Madhani , John Garry Subject: [PATCH v2 06/16] block: Add REQ_ATOMIC flag Date: Tue, 12 Dec 2023 11:08:34 +0000 Message-Id: <20231212110844.19698-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1P221CA0012.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::6) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: e8ca59c9-692a-43a7-07e9-08dbfb02ca85 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Z4vkeyTsDlQltXbnGb6taKf0zU5Y3kZL6iIY03n/cHksF+nEWAbEiosQjmoxAnPWY/jtx3RLv1csPhqo6VpcX5jGukoeHL1uwL3N0r0ET6G9lCxQni1JsBh+BN0eusX1nPI1UQ9qPfCgxCE1/LxPpQBth8x3nmq2XDvH34ldME8YjYiOpOQlTbvtSq0R/a4rJfITS4TgL30ltxgHnwWlIKWZvP/jPwTlMGfQcSFPT/ZGAykfgpspJUJWrZCU000aZHFjRGKS+qmL1Sj4EVEanLACTYtiit5dni4lUDjhOGP7SkYP4y0K05fiVQ3QG/0b8MOcWjtKXFiQbpcB1U3p5BOPfB7TEqODnW6VszK47UTYF05tBi3vMRRtaAHJ5tFW/L72HsbSpKaFVeo96lq+3dPxhndrOG7C23R3Hx0u4V18BNjJKVp4Wn2Mz+z3qzfUwQ9x8lvC95VXxwE3gSx37Xuiuf4lR14PUZlfC9EjvuVlEGYshg5keRH6qTFLyGpnEsJBsTjQj6yQsS0KC5yjm9M5e+RnGwMrF3JmZ/IbDwyGkbHAHkTIKE+WrlgCX6fpyPU+OIjuUb8pVD7NxD91E6KCvlKTud12t+ZYKg/+Ipw= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(54906003)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SWWWMk7n9ER1BmlbhkJR6ytjnKS8v41rFXIt+ydln3vZ4PpNhVzVPDd1ia52rP/e/ve0Cmyp/SN8inYhYMxI/4cXWApgGK8pnj9lBSmaUNrSJ2atki7V9aotpgO3l1+eBLcoTfZEV2mS4kRipnsHK87ddZWyMMpbrOF0uRpndYY6m736RjhPtugCgs/egXe4M78fFWTuac33UFH2wNZI2QeiCfno9DatZS8XvWOo6JifIM1rVWRXosMWxfjY0CfQjX+zYk46DDeMos8hvGG6H3vdhrfnMo1UEKR0TbzQigFkvYdGFbldnPnBUZWtqAurCCLBHi+jCc0QS6wlKWlIP605BiM8NTYg/C95+iBpXVRiQhD4MdSI/RtxrNPcVJoFzfydHx/AhPE9ToqAgXKV0zbZStJWuhTD2pkssOCaWhRIlD9Gcv2/LDZmG3URc+EUx6e23Do0cyYqcbdCYsx8pIN32avbDPS3183Hqk8HbJ2OALUOFrSUoB0VIbIL5DBtYmL8VXfgwZnnqmdYaLxBDHj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yoRsOV1lSL2321T1nUg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: sYM4ujFuTmFxveIPxMf0LQv4s1tTof8GzX1QS8ZJIsevLsAs88QRky/htMSbk3cj3RNlLqux1Q1bbQgLSdronktbm3QqkSijg1Zyis8X50HkMGiRBZyINGxv9Dg8WAXero0plt/c6JHa+NjRaBizMaxQy9Lg2dctijideBWv+uxBg4owpYF0J66WmWLaYXjkaZk4h2v80DQuyztcz9TV1K1+Pr2duhjP3ia/Q90Ev0ln7DokAbj6LCy/TRlYiojFkSmc2NWihFKytL9LfFcVDFmZcXV68Zqz7RZ9RHCb79WG7e8qzuiUK0uBWsFTDRarI5dnIzivvco5sKS8U7QbllMESpzDtNlfMN3ncrr6zLJIEKrSMq6BO1kW2Dw9BH6NXV/yd7NVH4F6tzVrjBA7FMPHsIv2idrOozfLWFGc049EAba9h31n7L/qsMbnAJxKiPqohWJYurRa06RaPVMvirYzEyfAeNYuNTzG+6FXAEKb67L0RlwUFj+iuEJxRZ29n+OB0SAU0JEqpzpqJJ4QxRig6inhqnpek0pltk8xl0yO53c2KGtAioqPDHjRuwamOpbcLUmUusnNV92KPvtLa4GMjPxup4nT00a4QM3ahBU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8ca59c9-692a-43a7-07e9-08dbfb02ca85 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:21.0717 (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: SaR8tGhr6q63KjVB1MK9ZswcBJ0PBhVX88wBfspAdSqKNIL48n2ewjspKw5qosj3YLMFM1HD6v6BIhzLAvBN6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 spamscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-GUID: e5568fBUaDPnyYcjuBc9Gen1LfvJi0Qs X-Proofpoint-ORIG-GUID: e5568fBUaDPnyYcjuBc9Gen1LfvJi0Qs 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. 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 b29ebd53417d..b10d4db753b9 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -424,6 +424,7 @@ enum req_flag_bits { __REQ_DRV, /* for driver use */ __REQ_FS_PRIVATE, /* for file system (submitter) use */ + __REQ_ATOMIC, /* for atomic write operations */ /* * Command specific flags, keep last: */ @@ -450,6 +451,7 @@ enum req_flag_bits { #define REQ_RAHEAD (__force blk_opf_t)(1ULL << __REQ_RAHEAD) #define REQ_BACKGROUND (__force blk_opf_t)(1ULL << __REQ_BACKGROUND) #define REQ_NOWAIT (__force blk_opf_t)(1ULL << __REQ_NOWAIT) +#define REQ_ATOMIC (__force blk_opf_t)(1ULL << __REQ_ATOMIC) #define REQ_POLLED (__force blk_opf_t)(1ULL << __REQ_POLLED) #define REQ_ALLOC_CACHE (__force blk_opf_t)(1ULL << __REQ_ALLOC_CACHE) #define REQ_SWAP (__force blk_opf_t)(1ULL << __REQ_SWAP) From patchwork Tue Dec 12 11:08:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488974 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ZfOplo8f"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="f2RkOJHK" Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCD16AC; Tue, 12 Dec 2023 03:09:47 -0800 (PST) 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 3BC7hlTg020135; Tue, 12 Dec 2023 11:09:26 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-11-20; bh=CMOjv+9CapWMIYf4DkV6dy+PvvxCg+E533Zxy8r0pXI=; b=ZfOplo8fhrqlLbzE0Pd7gvuCdhwxlES6e7UEEeBbEIOI0fh2YzSu6tz8NmtSuG1svKwu XqqM2O8KwC7/auun9i8yLEh+lMGjiQBfKqqgVxL6OzkHzcBqM9eve4yGIbfPc67nQOLe evIp0c60vJSpct6asdx2y3QJ2AcuFrfpxsYPPwWDLTVLeldefrzRiBkciH/ZYXJA2BdK GBAyKsQltQRI8fOp6ubGbx6PDZZmE0FgnC9L/mID4ugrHwedCbQcowy56MhwoYUQQsCJ Reeype2UzzMOwuZ5aHCOxeO5ZbJM+O6rfC2PozCeMLIahHfuAvIw1b5/F/KNr6CXh/da TA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uwfrrkrbj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:25 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3BCAZCin018664; Tue, 12 Dec 2023 11:09:24 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6d56w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wu6418NMDFTor1JRGc4nJk5Y3bmGvvyVdkqS/BRcZSFPsa/MYI4r+3wguaCQboub31FTBX8r6vqOGgI4qT+aMnE8ugxo+QbCClMpBJqNDG55uj7nGLAKL10tb+0ybbd9bPYgH6PPT2gL8XiAum+gbwMwWyBP5m0k+1MB2Hs9SWOPieLhtHswStsUYHW0Jbxt6cITAac/Jkm23kIhkJpvygZ1Q4ELD0Mi+4FJpGzjB4zzz2uAXN9k/9FRZioOfzk9xY8W+zknchqnfyf6NkSmZOpQ/14JyJZh8TSeK1JJRJZLWhrLy/OKqTvI6HAonkRyN8BHsw/1rLam08PB93FqXA== 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=CMOjv+9CapWMIYf4DkV6dy+PvvxCg+E533Zxy8r0pXI=; b=M9yXch3sreLXo8ZBUK9Buw0zKVdKYFjonEgRE+GaJPLyoCbDb6egWOUj/IAuV89A/dNw0kxSLsMzN1W8Fr8jDjrrDG2MfCJnwCrzjceEmQPIQKOVLQcCR2CMxEHjezYMtQdyOEFSNmm/9J7WzCUBR+ebEe3Xcc59mwudWADsdFSMcpmKmlfiVYqTe3w+DoilHwsB7t1umtsg4MXRv2J9+pqfZ4R6FTq52pkqfmupYwohOXyRWG9moEds7eJQaiCaFD0C8JEliT5nhgsCDuOHGAhZf0UO5gYr9orutb14vg6ERUR/3t3HtwmPfk8ElkFsw6zNW155/lVIODv1A2gypQ== 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=CMOjv+9CapWMIYf4DkV6dy+PvvxCg+E533Zxy8r0pXI=; b=f2RkOJHKYQRetKNlcuw8VTqx5WS4r0k4SDgEsi/UQ6gcOg0PQKQxChOOMnUTLC7ytoj0HaWRWWKej17m7nQF/Y3TmP1g8lLGBuuKICbzDevLNZrRiItlDSZKGnDgXPGP8+zc/C+dpiSCgVj0EWIcG9KrByBJI8JUwAofnr+KeEY= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:22 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:22 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v2 07/16] block: Pass blk_queue_get_max_sectors() a request pointer Date: Tue, 12 Dec 2023 11:08:35 +0000 Message-Id: <20231212110844.19698-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR19CA0042.namprd19.prod.outlook.com (2603:10b6:208:19b::19) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 59d83292-1dd0-44ae-16f8-08dbfb02cb33 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZNefzU2AJY3RuDVqpqMzjsWrmY4J6Tm87zLe5+CYwV9RSmGlagLqo3C3NysSN/KlFZrDVU53U3tkbZ/0CZP4ABpFLo5Pg5ebCTiXZqHlJ4GCLEXyuqEhnbpXOej1yPrk3H1vZItpLnkTApR/38gRdDHjmsF6VdQLwjqQuEupLI97L/Vb/pTof22yB2/KoAwJJT3F3nBIkrO0wVJ7cuWs3xSbdyahsMuEIHi49vrEq2CvoT01Y/q4HMjsOsEBkyg0BX/8Q50LsdGhEW6yvFTeLQM7eu06oJfc3p9U0wz9j7RozUPg3Bgbh5nfUZuRyPVkzD3OQGcE4rj3p45KoXIPBe/hAMNt5cOyaXlzNDZIJf6NfYwoJ5sGa3BrH4BjQSkeaki90OKmakn+KEybyrkRlf4tVOTfX3/ozGhZW+QLlsNbP100feMskxHP96bleqVzh7UdW1adrwerPHUpDVEZ6xHKl8bJvPmWn/ZpN8D/6mP4EVdBn47A2d9km/FKcSOBGnzCuyJjMHng46lfr/TDTBzcE635BSkZD6APBIrripGNOFtaFrRwF9/2ElEidrezrA7HHpSJb8MFzSwwi6Of/k5h27FdL5gjIv9Q+cPta+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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nb8hoA9A2sa/7C9hSNcEFA1psO3c8xI+B3eLBaWz54cFouccrpWJcmfWZcMMoSzt1bXd2D9IR6eBEq2GP0K/t4m68fCPNn+9w9nAEctqyIZXI34Rel56KfkawptawovBhLHmZkTBCeIChUv9ZR9k1JWNyAMo8TIHJF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EgmJrg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59d83292-1dd0-44ae-16f8-08dbfb02cb33 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:22.1695 (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: YgNin03wPXdi70znfEvP4WabT9OHkNVymA47UHypEuVYMpbIYSoYg8dhE3MgEW+s77sAGwZJYjnjJORveDo6Wg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 spamscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-GUID: x8Mur7bWVVwKpUcZaR43C_HYMjYqNr83 X-Proofpoint-ORIG-GUID: x8Mur7bWVVwKpUcZaR43C_HYMjYqNr83 Currently blk_queue_get_max_sectors() is passed a enum req_op, which does not work for atomic writes. This is because an atomic write has a different max sectors values to a regular write, and we need the rq->cmd_flags to know that we have an atomic write, so pass the request pointer, which has all information available. Also use rq->cmd_flags instead of rq->bio->bi_opf when possible. Signed-off-by: John Garry --- block/blk-merge.c | 3 ++- block/blk-mq.c | 2 +- block/blk.h | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 65e75efa9bd3..0ccc251e22ff 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -596,7 +596,8 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq, if (blk_rq_is_passthrough(rq)) return q->limits.max_hw_sectors; - max_sectors = blk_queue_get_max_sectors(q, req_op(rq)); + max_sectors = blk_queue_get_max_sectors(rq); + if (!q->limits.chunk_sectors || req_op(rq) == REQ_OP_DISCARD || req_op(rq) == REQ_OP_SECURE_ERASE) diff --git a/block/blk-mq.c b/block/blk-mq.c index ac18f802c027..58bacf9029b3 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3027,7 +3027,7 @@ void blk_mq_submit_bio(struct bio *bio) blk_status_t blk_insert_cloned_request(struct request *rq) { struct request_queue *q = rq->q; - unsigned int max_sectors = blk_queue_get_max_sectors(q, req_op(rq)); + unsigned int max_sectors = blk_queue_get_max_sectors(rq); unsigned int max_segments = blk_rq_get_max_segments(rq); blk_status_t ret; diff --git a/block/blk.h b/block/blk.h index 08a358bc0919..94e330e9c853 100644 --- a/block/blk.h +++ b/block/blk.h @@ -166,9 +166,11 @@ static inline unsigned int blk_rq_get_max_segments(struct request *rq) return queue_max_segments(rq->q); } -static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, - enum req_op op) +static inline unsigned int blk_queue_get_max_sectors(struct request *rq) { + struct request_queue *q = rq->q; + enum req_op op = req_op(rq); + if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) return min(q->limits.max_discard_sectors, UINT_MAX >> SECTOR_SHIFT); From patchwork Tue Dec 12 11:08:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488973 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="fPPsBLGc"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="k2Iv44bK" Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0B18D2; Tue, 12 Dec 2023 03:09:45 -0800 (PST) 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 3BC7iR7s032011; Tue, 12 Dec 2023 11:09:27 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-11-20; bh=qY7i1VBZZQ745lF7eevxcnu0k4K8YrzyHITvDtXhqno=; b=fPPsBLGcpTmHZ4j5Rois1QfjzcGIZB8AB6WjMphU9Y4RBGiRYtWCL4Qn4f/kEPskmgsb arpRNB6UA57NEhASWuL9JqelTEqI458a1nopTJiULaKb2ALHW6xNUV71x7sDmoZ0D8oJ 5CCaaaJ7ICtOqJEWcAvCq+eiQowVeiYVSlhAHi1jAWM041tU66XdqBB7cI04eLuXlH1a BRTheyxcW4oxe6oTBPNaeAI132DyxSDD5D2RThPs/LqA1ISq8lskHofmZFebRz6+4goR G2xbSUB0oIevAk0CfDX+ILWE1EkgOu0EFogPKZyxUpDEJILeIpGhupdQZ6JWMmfSx9w+ 2Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uvgsudb6s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:27 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3BCAZCip018664; Tue, 12 Dec 2023 11:09:25 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6d56w-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c9yLR70AiOEb6Z2gazA5hiT3+jSPwwBZWvEbR+y6rvhuNfACVVf5v3861AvaDkbUWRB2k0w45FL543UhpEhUtcN9Lji8nzow4hzgNcVn4OdrhzE+iKTUVk1ZIAfy9a+uMG0vfUU5NGNDcWSU4LDU46zYqt7YeDuE/0Y11mLyaRMQksL0F9isAmHmLy7egXVJ2kwxlmo4oLQ52ddrR8IxkoD+ZAW8b2kC9kSWzmYkELJlPkjBz5o6WfA3d2kqp4A+8CZjjM45V9n+PA+/bssfn6kvhQKx184X4D/E/ONr4rl+pPllbc+g6+0/sUkdneDaStbmJUcFzisxtmyxXYJc6g== 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=qY7i1VBZZQ745lF7eevxcnu0k4K8YrzyHITvDtXhqno=; b=dhgpLrRUL9VeXjjRwMdkjwAD7kUrTeU/91XkDMnB7Ix/5p9/FfmPL8wXgQML7SVg1Vt2ZI2NPvLnfg8sHzFoM06KZwZzO0vDk2R80AswdvlqFk3rMeLRhjbQdT0mwg0LjZcauwhhdjRvBDD6BSoI8TD+aBZwwHF1KQsPdlkNnYgJIO1XEumZYw8kPcG29eGLk2XIHwsM9U5ovKUl9cS2ztT3fOd0At+hqm5qAS1CPibXrzIQuChJypPvo6yWnbAQqzdU156ER4U7IUCxWOkWUMG/e0gZnDNn/PaSuDTI17Vxc2YGnpkcWp+3o7Dorhg2mbuMKpmeXxkd/6QfH3JS7g== 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=qY7i1VBZZQ745lF7eevxcnu0k4K8YrzyHITvDtXhqno=; b=k2Iv44bKSitELVRHERlS9+xiRsZoPnnQ94QMpbl+Ld45pStki/jgALR6pbPiZ3abgq7ImydU64b1ieApKns+xm/WqLcRGKyyRiV39NaHCzhw2N8GmEJ4Uk7GHSimY4Vml3BP0TCMDxoiCCmvlcorSjZJF4y1nlH61eTq1BaimTs= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:23 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:23 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v2 08/16] block: Limit atomic write IO size according to atomic_write_max_sectors Date: Tue, 12 Dec 2023 11:08:36 +0000 Message-Id: <20231212110844.19698-9-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1P221CA0025.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::13) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 26154140-fdba-4c59-ffaf-08dbfb02cbba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YO/La7JnbCidotp++p7LU4HgqjzcHmKvIQgJQPfe59okxUDfv6YrSPvJ3+1OwBMRQzHAjGWWlyuql4+ToI+/M6hlxuaz9fUrHuLjofwQgvEokkOR4GBd8WwDQxwBvk0BWPHdq6BHWIu2gbBoPAUtljhSHQjuD2ZFo4cggTlKBBCbgjZ0/fzXHrexkPSHi3Z0Vf0hOPYtkkY1qyvvNrtVxSjUwBN49QbPUFiG6M0YihAvvsGRGuRuhAl8xRo9vB/I8B9Y/QHVJ5IrdZb5v09SyMCNUvPN/Hk+BFr772U9BDj3WeeUSW5IoyfqcMT1rSFGTcs95kkmXOKEbADPqNRzud9tSLNye8UpF+/Lgg+32TL0R2F2nj6yfSFZnC7fga1nvJiIHIU7COWAZRGHu0W2QGO1DDJfTLNLn3NBCLoYk17RHYldoBlqHEKaTcsicAS+q/X7F5twLx2MXhpTtggud6iMhiyiosxFz96JHTUUvVAcLz7ZKoXF+K1maOiraS1jFFQ9lK+85sw7I+d5GtbWRIJ73WMfNf2BdLtUwWUJY9MO2HEjf1FjUOFYPNoXhawtTlWUcfJqYNMovLAK+Sumk7hiADE+cSsKwhf8VMo/ieo= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yriAlTzKIhvpIpvhXRpAjibY4JEWLafWdgwPIOeWdFLlToLkU0oZEU7uCDfptsGap3veO9jqrGkiXXb4WUJIR95ITok/BL0x+FFXimC7aqu1RO6K0W2F+qY0DH5TT/of4roCA1RlxmSEctrrs+mAQzop9b2ICd33zGuw/sZBXp6buBtVY8zfZm/1nhWEN60+AtHrx2WdyhcnaKqzII30WpirXMPA7k/VF9lMypVVQDXa9iqGGvClFBeSa9vonnz8motQs2CU0tleR3lQDr5jLuLJWJvwazGVOvGoORnDWnifP5g6n29UjBtm/OBuQQqgTTwiYNtABxgpap9puw9zGB+ZwCu2Zhd+siWezdxu5flf/ye73CU7a9tEnBse1joDNjrJI9Un1YRoTsKUFMmRfCv/EKPezY9BUSFFREPKlHEknHfWPvmDqR0JMZXui48q0UnJ5cRKRYZw8rzueUJRiQxCEU6Cuvd9Z/48q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8mwiGIyIdvIIBp8rLqE7WCRxHYCh4rlwjiYgUzH23p8CVwMuQr1CHRg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: hy+olQ4Tl11IDDFcJL9tEq/feqNnY9XUZYZsrBi+rOI4KtohhF9J3UY/+DRO90+myI/UOBbuAzMyRe472Iw+CXXvi4TNwo3WfPPlQKyDXkjt/Z+hfTLEnszcEY7WJatktP4e0r8cjKYr/hKB+Bm/nxl8NBzWdfLVf8SrL8XY5925sXdJxW2CM1CnLX9iIfPFFnjvwfBJpTwWH5ffaEXL4Ek7gACnKZEz0nr+jlxITdXaXTtSbtwVp3UwdeYA4y6bL47t6hjlC1TircKn3IYVmECmjS8I2hCK2/XP4znKwqrswEY204qrLAIFTEG2YQcBygogiR8Xr9h/qNvDf2ixszoyxb4lhSR7ArsEFiDWBoddneAYxoImm86wGKVIEQZwZwD3UvBXhiPfE7FSqbmSfhKYHir8DzlAT4DqY1/+1TWmDJLe28fT5g2HpveTC13D0KIsshYS3KO2K12w6ASN654amqApDoBzYbmqFCQ7qJKjXXshgMzAlnAi0LEbYiflNXKiyhsXTL14cUmxnCUEqW1CiPNmrQhTG0u1yD4MJDbv0WKqGxjJ1ALvWPVjMbY2yVtzPv/CyutlEut309IRGJULRq/0D6M6pkOYijaC294= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26154140-fdba-4c59-ffaf-08dbfb02cbba X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:23.1379 (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: 4nAmF2uFgQfpDTGe5a+16RpgkhwH/1OnENoKaR08f3D6p1I5EaHH8cUnf/N3pYDSSw4OH8nh35F6MGTgHVcKWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 spamscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-ORIG-GUID: 2rWle9ijbzIjJK9b_s1tCZYGHsrN96ap X-Proofpoint-GUID: 2rWle9ijbzIjJK9b_s1tCZYGHsrN96ap Currently an IO size is limited to the request_queue limits max_sectors. Limit the size for an atomic write to queue limit atomic_write_max_sectors value. Signed-off-by: John Garry --- block/blk-merge.c | 12 +++++++++++- block/blk.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 0ccc251e22ff..8d4de9253fe9 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_sectors; + else + max_sectors = lim->max_sectors; if (lim->chunk_sectors) { max_sectors = min(max_sectors, diff --git a/block/blk.h b/block/blk.h index 94e330e9c853..6f6cd5b1830a 100644 --- a/block/blk.h +++ b/block/blk.h @@ -178,6 +178,9 @@ static inline unsigned int blk_queue_get_max_sectors(struct request *rq) if (unlikely(op == REQ_OP_WRITE_ZEROES)) return q->limits.max_write_zeroes_sectors; + if (rq->cmd_flags & REQ_ATOMIC) + return q->limits.atomic_write_max_sectors; + return q->limits.max_sectors; } From patchwork Tue Dec 12 11:08:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488981 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="LJ6uHUik"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="pyH1PPxV" Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A0BBD5; Tue, 12 Dec 2023 03:09:52 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BC7hogf021829; Tue, 12 Dec 2023 11:09:29 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-11-20; bh=QcY9RC3avw9MZfKu9dEVIMCBEpzsZPmmKQ9DTJpxijE=; b=LJ6uHUikqTXbPTwwh/2ovIBVg3HUZGRiY6Qyk+fBcLt10gOELVYnV6Kyn00ss7VPP2GC nlU6kJwM9kPlMgmDtJUn1V0WlKM7Ka/q/ht45SCl7kw0+zpknz78ahUDhYLzDddTs5Nw qBvAgMFGd2tSxDCLpBeyBc6aSTfT/yfvujieLVlJmnn6t6Z7EDQedD9J+ulv8VwE0pal hx7jZh7fssPEUuEvtHeusGYHs3INa7RhFXTv3QuwVl58Tgj4dz6mszm3gEBHv14JGOQK k5xwu0on2sySlTLmvR19e97RE59td5B7Kf6dFjF12g7DXh530L/um2uGFCC3fiy7qqrR hQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uwgn3kna1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:29 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3BCAZCiq018664; Tue, 12 Dec 2023 11:09:26 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6d56w-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d1pyMqDL65J8SY9lXuq4aqDD1WPyu6YGPCybq2cmnmKniN3DeLsfE6runWVsHFK6FWOM8LYHEevusK4byz6LC2Zxs/q23EPyugExYg36awNFGlxXhAAF90OlWOBzU7ju585W1ws6qg6T1MVMqEvBHh0TB+0JrSVuJJJlxq/utiBP53QNMEemFENEVjMNZ2zZzw/Od2VC83tV5Ix2xGPY9qED2Q6f8+u3WIpBY4vPEXQFM0gcUcA8nMBVsK3l45+YQwSTu5Mpm9kwI7rbV/Z91l8udzIANo9cX6uW/FvC9yS0uDdrs1BlTmh+MbjrjNqyihy2/sCPZZNglFjjd6Jq+w== 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=QcY9RC3avw9MZfKu9dEVIMCBEpzsZPmmKQ9DTJpxijE=; b=LyyvWAbm66nYSigl/fiUiosiY2iN7T7q+L6gB4M7mnyy9WZptUWgpe6Bx3ndP/8jbakM9Okhlu1fVgb1Osj3dGb1qIbRSbQGNE35OfrY6xpdE0mz+MY2btB+2R7Foxin4vCI3Ul4MZLW+KcnHR2SnHVjfD5GeW+zTsaRjpuWV05UKG0BFdUyjavi1mUldfNDtj6yd1HscxXmb9YrhWzCB0fRB5QYC4GR2FJz9buvmjskci0CCfvdYtiwuPVw04asGrDeFcpg6IusdewoEtq8W2/xtruzHwqTSVzzIXp5p3IVJZDDExBnKPelVxRq3Wymc2t3tvJKikzxk0ED68Hnjw== 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=QcY9RC3avw9MZfKu9dEVIMCBEpzsZPmmKQ9DTJpxijE=; b=pyH1PPxVFtdOMMCBuIBzsJj1RNFIF3xVAQq6n8LI9U8LGXUZL8+HznNOPpyKweSyv5mpCfaRT0PFeW02qxrlIR1SKSkcQocqwiUijOwoi3MZxGQRem3cGbR4aQ9sJIoP9sINRchO9Xt7OnN1QRgvvqig2lZbQ4vDeW9fNLpqgSU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:24 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:24 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v2 09/16] block: Error an attempt to split an atomic write bio Date: Tue, 12 Dec 2023 11:08:37 +0000 Message-Id: <20231212110844.19698-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1P221CA0021.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::17) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 809b23a5-acf0-4b67-5e01-08dbfb02cc58 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ElZv+vnwItvXhM9NQ3AWMNkEFei2AyEvkJQNJE8PHdMVq2YwDJVatBqziV9KYpk0n4x+T7F/7yu4FLuCtLVTjCv1Deh9BLHbk5k2KNvrQygf983rScqqlnEX0cPPk0/MKV0xjGqMADD7DAmQSNGOeaLDcFOKsrgCSilRkVrWM1ZttmRI2hTDQk772iCIWmBDH1G9S+mSR0WB0BPTpY5x6QDPg72HXddkB0NNgkckSSm/qgzlBPQlCR37c6GIS7f6Hxe4iJu/sRTGgWx7Q++7MatTm8s2ZJqk/WD21fxn14sS4M8BhdAVBWqYg5vPDCS22Wav6cPv9jG5scOPH6hhWr9hPM/aMUWvJ6of4u5ubB8Ye5WcUGFuSaP+vg5qec9GrMZ8hM1Fijpf78DLLuIVo7nLgjQfqmoCMEvntWQWqwNsw+9IS2Q0Ow1lPHWybccH5ulwbQO/BrVH8hrY39xGapqnAZpAgV6YsoSaDXsa9tduwPcvAq7MCaOFi/ukFtlkMvZ7rWDXadTgzFnKe2OMGiBa6mH0cPxVQ1GU3xfvEP/MYMh9JdtMtX2Kvreem9U2yFbKP8q44Ae2dBGdsYB8BQ8Hx7fhnqZWnTtNJGZ1HRs= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(4744005)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5jWhRlyWq4JkCLK9oEjRLMCTuZBvw/fU3kytPjc+3noKN0mHT31jYSTbp48ezmj6DyCumKl4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mUdtZdgW+vJUy2VKNi6PI/izLz1zwtftyUeIUW+enn+8dpBttIVawlyT1mAykgre0DxpHbCLGUEde60Lj4gzEgHf2v5n9mVI13Ko2LxYvYUtUeMNURgypWvutcaZOXwf5ZEyeheG56YpR59smJslDnVOAPKQurCpg/1ZwKV9envUtLiKURiQMNko0JNa9CzI1WFOM5PmzDfh+XY5F1J6Q7Vknygrr51iFkaObNZx04AdyI/h4HLuIvkOn3F6LEkZfkHBajQUq9iXWU7vRLBHMCufhc0tJfMDl00Fxdi9xCGwnBg/BpQm3CdttVZZqJ1Yl5hML6Etj+JeDb/AA18Oe6i2xcKUA72W1X/vN8EHLe+LAICT0ItjDiFSc2KnWYmxsVB9VK4vhLxfjk6xh08IhP+QFrUdUh1EEeuJBSu9WVdgQhzH+eAJ+Gif140fNT5tgdqSxFdVJ+GDz/5yOBIDsI+aaGQFw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: nOT/esikKOMFcIHsVs+2/809kSYnH4clK3ho60jO58iDWJeFArQNWSYcqPA13/nCNUV9MBCSzdFo0TMLNfjvmMNpJfs+6+2FLUaMMSccG4Z7C6WBwPMo0tTvr17aU3aVN9Yas9nsBBsYIpyoEQRX5XXa1ElcpWRFgkUzTcor3PGfiiIu3vVB864ywirhYisSwkIfsw/MC61YW/VFMihtrXqMOtlo9vemiFjLDzYyDxfbIR3oMDwMmk+0VEPG1m0Orqi47r5l4RLQwa8VHTODnsWyURbKM9HcrdH1AFFoU61u+VFBZlBlmOIcYAAsdqb3F5qTLVYL5NAPkRlE6/51TZ50mo8ueMILJ2S4RdxDjCFUWsM3lEmCDNYYoT02BSW5mG2251AUDLey35A5D8ieFQElQbxiA5C2yKeXEhaBDe2xyxe7OAdgA07VafHzdffV8dK/i0LO6dnwOmqpcZp7H/SXTiJKQOVRpIECqeMdVQkG5FyV8Pljv7IIQCM1DUtwtYdX7B014/r9J8PnWbr24BzLRAKrRiOkI9abNH9BiZB2VKlvHdqTCv6nTYtOfxP2IV/8OVVNU3esProWbXWTtfqUH7dZ3HOJi63U4yMMeBw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 809b23a5-acf0-4b67-5e01-08dbfb02cc58 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:24.1206 (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: PQakJvdJMvasrKfyyp1dAimmYggIpla4ZFwaSUejn7CvCnU4dvGea6LiMilpWtlPp4tqOpF6GPYNjD2NR/6UzA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 spamscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-ORIG-GUID: DMgOnbWTaz44WN15Adm_VKhvivd5NfaK X-Proofpoint-GUID: DMgOnbWTaz44WN15Adm_VKhvivd5NfaK As the name suggests, we should not be splitting these. Signed-off-by: John Garry --- block/blk-merge.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/blk-merge.c b/block/blk-merge.c index 8d4de9253fe9..bc21f8ff4842 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -319,6 +319,11 @@ struct bio *bio_split_rw(struct bio *bio, const struct queue_limits *lim, *segs = nsegs; return NULL; split: + if (bio->bi_opf & REQ_ATOMIC) { + bio->bi_status = BLK_STS_IOERR; + bio_endio(bio); + return ERR_PTR(-EIO); + } /* * We can't sanely support splitting for a REQ_NOWAIT bio. End it * with EAGAIN if splitting is required and return an error pointer. From patchwork Tue Dec 12 11:08:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488982 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="OMF1rGOQ"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="mm9RVQ72" Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CC8EAC; Tue, 12 Dec 2023 03:09:51 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BC7hrR7021975; Tue, 12 Dec 2023 11:09:29 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-11-20; bh=BIEby+qrRH9/KKKqVmi3p/Hpl0mSIdRTMzAbdzkwOrI=; b=OMF1rGOQnU1A96miiYSfgColIveyoyiKjQYNaYUG/ruARZAB+ho/ROa7lmg5hLznAzEo 8sc7/ec9dXD9RwAomfEsSjA6LtrBtSjoywslGBiDQB6Lsy1J8etJUbcECn6g5A8fTuKX KFZfPpgXwS6sCbf6xE/eF3NwVRYHjTKFDN18P0m7ZBnaqsoNUH1/aV3+fcGI2hyF4kql 4G3tTVTwPqfekZ+mA3HEmXyJiB51Ab7mcQo5aCmjcsb1fqfBEdqsHiJQHJc/b8i/uDh6 KEBX3Hk3DinRJ7RVL4yRigdrO42FaiSZsl7a7QWZzbgKSJZf7abLbQSNrHTPISIf+cJ1 Rw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uwgn3kna4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:29 +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 3BCB6w8a009916; Tue, 12 Dec 2023 11:09:28 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6dfg9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tbsmi6jWEiQKJTFsbQ5RhsOSHcoMfgavd+7f+bzeuju5ny+102+lJNf/0bOTNiTBG6IqAnnZwaPIls8DZOPzdtk6F3p0/8/Zlz6ZqsGauznUtDl3eA/iAjN+7Sgb+GS1nPr4k7CPhguc9+bEJP1VTEm7Q94kIU3fGOQDO/5wZwSjM0wg/OhkAZfS0e95kCP+hJKgVRVfv2xldL8D2k1p9uJPdSiOaVimDgZ9gVscvK+qG+yel2Gevxw6Z9o9IfqJE+R1mUn3yEag83knFzgSiShFKs0njJWWdKFbf9H08YZm/cQegNE8fvre0CK78uK+Zx43Ky5q5jJjHhsfuOd1yQ== 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=BIEby+qrRH9/KKKqVmi3p/Hpl0mSIdRTMzAbdzkwOrI=; b=m554JK1lE0IgGvk44bN/SVHLf1MgNw7nZlMVjW0jYC+gM1+nAvKP5taxM6wYp36zqUX83c+xqz6T9m3g2bJlYix7SrMmtSrbK6CH1AvvDWICpPkg9lBWDq19A1fPxLauNrMRLnIZO0X3+Ntv054h334bpQZ/AP9wyrclFd0d8fMwvk1rqX5ciRec0TlUKOnbpx9qGkRyVKuYYlKcVhdOXm7YSho4cnsr3xW1P7YHaOMPkTFZO0q1+g9T36GVs4u6YlgQYkSP4hSbrmlzneviyjSJbf/Vdd50lL8ldUnGiXPeEZSu04wTy2hyijGQdT+ivhPxdYyrGVFIxIK6eYwAEw== 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=BIEby+qrRH9/KKKqVmi3p/Hpl0mSIdRTMzAbdzkwOrI=; b=mm9RVQ72nXgLXatZFDGnd6C6F6KeJGT8GgP1t1AhdoKyrPks6wq9FIwcMfMFvziZzwTjhwR6JQ0W8Dth+YxSYtO0TvV6s8MqITTWw/ficdTJnQySsRruDdnkfGhRQoJO6yAIYnAqWYlZ/S0D0r2lvJ7xw3xq92aGfingnBExxu8= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:26 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:26 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v2 10/16] block: Add checks to merging of atomic writes Date: Tue, 12 Dec 2023 11:08:38 +0000 Message-Id: <20231212110844.19698-11-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BY5PR04CA0015.namprd04.prod.outlook.com (2603:10b6:a03:1d0::25) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 4ae97a58-1355-4e84-ba83-08dbfb02cd90 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Az3dRb/5XxdyoGAx7CMZMQOViobc9AmcAk1ZkNLlgUXlHIJeK7BqBlXyo70RRsTlIMzk/vEuFSoI1zjS6+Dsu/sZf8cZIInqbXosM/YHJghHlUV6UU4Dbx/EtTgLdcdPfAPmTQZs3eWbzKGbwDVOdxr0xv9w9ES4fPBuVEw4+IIVfQj2+qnwOpGmx8C3qhgLEq7CrJ4h5D/f31K4U3g4pSyk6Z8Hf6KQKDpbc5R118VUN4/iYlcxxUP9lAzSGOXo6HWL5G6YfMEcO7yysikfVLMbimcSgEHQ/X+o9KaQ0W9WUSwz6mec8waEScBk4FMc1tnVah8BPXLM2BYKIor55eo9EzcPYGy8pe2Hkq7lWMrwP0lUk1Q3bP/t4yYLcXAVw+eK9B23iFGpZslRNoPmx/zfBIJVoniYfOhKTcZ5j1d3f2k/oGooOUz6Ov6tKaUmREqPNbzlT3nzWLu1Lic5gO83N7QDZIhsbIjFo3HsfR63Fm7A4FAibT60bk7BlpjL7iISjh46F/GfnXtMfK1p0ZlBePnTfxT8/S0Pw6KzyOEbk1KIe4aWQgVhWSKLzNFf9VOsWlTDdXtH0nJQWdW5t5ndU7DPdJix4IGDgoc1RGA= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UTI/9KdLqabV5P42TuU6CeTp0FxRgkZm/a5HvQyW6n4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vG1cDVVOPyVs7/JwkWeVzp0A9qEd8V3K0i5KKbmU6cs97KFawARWs+qF9nCb+fhWWUJ0hqtEXuU5+2chdTE3A0yGpxLNiRfQ5/7tRiDaA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ae97a58-1355-4e84-ba83-08dbfb02cd90 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:26.1746 (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: V+NeYy0iI1u2doxcR7SnDS87RnlTSV5J7+5tf+sT6FhGWaSTHCaoOr/bdYv2hmJ/5CIhtl84dVqoV+oEwmUtiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-ORIG-GUID: Je6yWMQ4gDSeKJd3lb6811HVLh3-YyCB X-Proofpoint-GUID: Je6yWMQ4gDSeKJd3lb6811HVLh3-YyCB For atomic writes we allow merging, but we must adhere to some additional rules: - Only allow merging of atomic writes with other atomic writes - Ensure that the merged IO would not cross an atomic write boundary, if any We already ensure that we don't exceed the atomic writes size limit in get_max_io_size(). Signed-off-by: John Garry --- block/blk-merge.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/block/blk-merge.c b/block/blk-merge.c index bc21f8ff4842..05eb227a5644 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -18,6 +18,42 @@ #include "blk-rq-qos.h" #include "blk-throttle.h" +static bool blk_rq_straddles_atomic_write_boundary(struct request *rq, + unsigned int front, + unsigned int back) +{ + unsigned int boundary = queue_atomic_write_boundary_bytes(rq->q); + unsigned int mask, imask; + loff_t start, end; + + if (!boundary) + return false; + + start = rq->__sector << SECTOR_SHIFT; + end = start + rq->__data_len; + + start -= front; + end += back; + + /* We're longer than the boundary, so must be crossing it */ + if (end - start > boundary) + return true; + + mask = boundary - 1; + + /* start/end are boundary-aligned, so cannot be crossing */ + if (!(start & mask) || !(end & mask)) + return false; + + imask = ~mask; + + /* Top bits are different, so crossed a boundary */ + if ((start & imask) != (end & imask)) + return true; + + return false; +} + static inline void bio_get_first_bvec(struct bio *bio, struct bio_vec *bv) { *bv = mp_bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); @@ -664,6 +700,13 @@ int ll_back_merge_fn(struct request *req, struct bio *bio, unsigned int nr_segs) return 0; } + if (req->cmd_flags & REQ_ATOMIC) { + if (blk_rq_straddles_atomic_write_boundary(req, + 0, bio->bi_iter.bi_size)) { + return 0; + } + } + return ll_new_hw_segment(req, bio, nr_segs); } @@ -683,6 +726,13 @@ static int ll_front_merge_fn(struct request *req, struct bio *bio, return 0; } + if (req->cmd_flags & REQ_ATOMIC) { + if (blk_rq_straddles_atomic_write_boundary(req, + bio->bi_iter.bi_size, 0)) { + return 0; + } + } + return ll_new_hw_segment(req, bio, nr_segs); } @@ -719,6 +769,13 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req, blk_rq_get_max_sectors(req, blk_rq_pos(req))) return 0; + if (req->cmd_flags & REQ_ATOMIC) { + if (blk_rq_straddles_atomic_write_boundary(req, + 0, blk_rq_bytes(next))) { + return 0; + } + } + total_phys_segments = req->nr_phys_segments + next->nr_phys_segments; if (total_phys_segments > blk_rq_get_max_segments(req)) return 0; @@ -814,6 +871,18 @@ static enum elv_merge blk_try_req_merge(struct request *req, return ELEVATOR_NO_MERGE; } +static bool blk_atomic_write_mergeable_rq_bio(struct request *rq, + struct bio *bio) +{ + return (rq->cmd_flags & REQ_ATOMIC) == (bio->bi_opf & REQ_ATOMIC); +} + +static bool blk_atomic_write_mergeable_rqs(struct request *rq, + struct request *next) +{ + return (rq->cmd_flags & REQ_ATOMIC) == (next->cmd_flags & REQ_ATOMIC); +} + /* * For non-mq, this has to be called with the request spinlock acquired. * For mq with scheduling, the appropriate queue wide lock should be held. @@ -833,6 +902,9 @@ static struct request *attempt_merge(struct request_queue *q, if (req->ioprio != next->ioprio) return NULL; + if (!blk_atomic_write_mergeable_rqs(req, next)) + return NULL; + /* * If we are allowed to merge, then append bio list * from next to rq and release next. merge_requests_fn @@ -960,6 +1032,9 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) if (rq->ioprio != bio_prio(bio)) return false; + if (blk_atomic_write_mergeable_rq_bio(rq, bio) == false) + return false; + return true; } From patchwork Tue Dec 12 11:08:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488987 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="FSe5TA3N"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="jpxFIn96" Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E78A2D43; Tue, 12 Dec 2023 03:12:10 -0800 (PST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BC7i7xM008317; Tue, 12 Dec 2023 11:09: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-11-20; bh=918OzZyIf2lHbcyEav2kilhstKVFTBfs6SW4lfJSiq4=; b=FSe5TA3Nmi6IKX002RUmFPnt+O36RusDH0q2iMh5pN94Ln3obF8SIhz3gEkcDE/OmSE/ 4BxGmp5Lk6C1UwUDT1FcmOk4o9QROgCRq15Cz/2z2nTjA31UlImNdikZveSRLtAE3PRB K0g0NJbcRhlsYbP5yeWrcBLf5Nunr2vZCHEMeNnwVP89xW3wFZzBJ+KQ70o/nzGO5fUk GWESXwkzEVhcRqRizMJT6nlFluPjQeKNFqHZmAXcTCAXKNIsCRanOPWm7JsGiJK4Gyh4 vdMluk+FYoUTIvLyhsf67OHmZDherXgyLByTiqjK8Pju/FMXcfJoUxNDjO2UHvUj9AkD WA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uvf5c5bkr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:31 +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 3BCAwAk8008220; Tue, 12 Dec 2023 11:09:31 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6cwks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gpwW2ySTSfKTnbKP/B7yBj942dKx9hQjAx7grQR5QrUCE7XlVpO9VRTg6XaELXO/zpFgk/PZIgIywtWxuAEAYCtVM2PxNWCZ8dpS1BI9gwzBL3QcdgwaY1JknnSGLGG+zazeQjCAdi+6Ulg/AFnZDEBTd1yNKZYyJGNFcYFJLu6Bo4+q+oNXlLi+YkIRmKeIGlXj9KSLGeEmT2kS82kVOnIuijrUfPHJ36ClBFnQIisinqq+5JtzfhbFOJPOBO9tWKdtq+g7GDHWd/2BP29J+TFdtLFWDtASPSG1JsMxWj1FSaBwsi4p48MFxwqKlQ9mCP+BrT8zY8vga3IQQTC5Bg== 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=918OzZyIf2lHbcyEav2kilhstKVFTBfs6SW4lfJSiq4=; b=LO4JhgCT4RiuksPb+5EzwFJYfNAY96Nc4cnZs+4xGpzm4vBNN267lIfdWhK/YGM1iz0aqEQZRg4pjq9SUEK119tn5PMkNEOEl/J+cQbiOPHjVs2K1ARmy/+3TOrIxkWlWUbkaafBOE20eA9dEXn9klmVEatTba8+QjVyv7/2T89YfCrGcWM1bWpvH5VkEU+lS2W/dmcHgTP3zWQyOGAS71wHDxAxT/dmSDwykI0YIGhQQ05xdNbTX2gJr2ZDnbqV6xGXghHvmUVCBi2U8hJPThC9/G+BbfzCms8USQGEHz5lrPHGjaTXw2iaTAXmh9ds/rZgSepi2xiZAfdWolI4Pw== 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=918OzZyIf2lHbcyEav2kilhstKVFTBfs6SW4lfJSiq4=; b=jpxFIn96YvV4ANKFOpxbuIfOfFEx+83IZ4I/IALG05c4ZaVeDyyeEf+lLC6HFx/g732U7JNp+DF4SI/0PhExcy+IncFWVNEZ8Ac1RFB8GbnT0ZaQmpHWd495s/5fnAGHxFgfIJXf0UTd33qkEIOJXoiviLEUcW9dpXRd2tf9mSQ= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:28 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:28 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v2 11/16] block: Add fops atomic write support Date: Tue, 12 Dec 2023 11:08:39 +0000 Message-Id: <20231212110844.19698-12-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BY5PR04CA0022.namprd04.prod.outlook.com (2603:10b6:a03:1d0::32) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: efa23dcb-72cc-41ed-87f7-08dbfb02cede X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QXWURaFRHntAPTBV2PF1+hkirL4hM5N7lUH3K8uQjcQpFPUY10HgVNTeWK+glL6qKrS5tJMTU0XyyCT9bbkpBMq8h+wGdAJpILkms9IEOxhZHJ63xWN81zwNObzvu3lcoxuaKwamYWiXLThmKTVjL66OL/eDPCvfnaXtbJTXVe9OPw7nOdREwmt6FjaT0AAAQzL1UqQnzMEoL8SXalV5bTmYx6Ty+lbBYeBOrayAZQqtSH/FUIo8OrIxwX8ensf25EcXkS6d7hkvE8+okbehJzdHAIaSERQGO+RICwu6P9crzvXa3jT2Jw/M6npBfaCFATNNbdp57xq+RDCiZb0r+tQ6ZgCxlAeQoyyvDXQIAmVYWdtC7sVntUvlpQt8rqv8QiEI/ZCA1BMcX4MaQdcOphkbY2sv2DBGaLbqIn7DzQLgmOo0x4EgEdRP9djjKMe63PEFIEf7Vw/A90IYjEH2gyEhbCjFinwYE5M3yekZGoVnO9wnV4CEhTZpB2+dxqEmvIBiGtl0oaO8YvbMxSNYiupsc+Knp2yQ1C/Yl9TIBVJLTQBR3/1Eg+9nBZs9b5QYyXixBSnY1Q9jUbSBaNXy9Qth4M46bJkTZT0jxYAl2Oc= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nocAZu8PuRVhC8JIMO/WR8shiu3zjDMaZpXqHS9Rhe3y1Ivg+IyQouRs/sKgDAiDRFKwuw+Sf2Xwx7aNg8kIqxpk/AOfYdkLFDdiaipDsrt67HSBnS1V4fh6fyu+C14G3ehYWy6IJALr/iYr4ROpQ/K2igdM1dUpS4+EqE6oNrKpEnfjGYRn+2XjPS56Xjr8aluwilEw6wRH0sVMZiufsqw6R6xTQ+nRy924d4cEk6JTiL/m8KVsJyPVZo/YWKDCxzppsG+LEceUH5VYnrO6TnPtARwMBfPv0hhPpQFtmv1MT5FQKwqg2T2oPJU77fy7Q7tWbTk1nQYLdWUYzkcaleFm3m7ilVOK3FRcyPJ7FYRSWCUJ0ryNUh9kYAEH2Sx5piiiNehPcUNgk3ZIXdZ14qECLO3+bz4yyhgW0UnyeaOGAEG38Mhft+y8zkedJxIiiBrs9MA+QYqLHaP9fy1rvd5/OVPTXtgpN2jLKl0/+7z2Pd1YMvQxYrG2XU3Rqr/xAiA1ZrykcbAz7z2k4SFaEXe2NXAJ3V9W80lXRW9BWvSHDdHPzeTQ2bxOvq7rszABi3nhwdiKQ//u8J86ZP0Fh85jpj/Zs0ww4CU+UX9M3C7BODLbUibdBdNQZAcfgsoUX75aFuX9W2CG/0pJnsFRmzSb47yeL94LdIj7cx925og6UT5H74y6hMzI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nPwdayoH27GTAiIUDAd+PD9bWhmF+Y4BDoX8ZXRYCEXjCVVSTrSTRbsRY9klsCuUONDJU5P24MH2AaaN9yHApEiwrYiZBm8BEaO5ZKHcIKP73eObKS5ct4L1X9nDUdisBX+MqiXQLyewRLQrfiBgQsda0/VqfXAZthuyG//zwjHLrmIpEcD9tG4zz4lbZsVjS52tviDgoDqyu8Mj4TJYQNBvQLoBG6FXQMDgkwiLbK9H+ki5g0ztnA46UnnI7kBKh+3hsSyuw4ukr9IOpVE537dM1KLI/J7SqHbkRdPk/65n/X6Sy3XjhorbaMZwiKt2inxX81fHiXXVIt9AqWOrf9gst/uhcve0MiWeHR3El71fEP8acTesxFvkx6dm7YhxTSfqLLjKzWvDDwpKBIzCMnUnzq5185SDHcNCEceBtILheYEC1oioauzBOg2BF5M8LvNA3TURJBLwhL+cyWNETUIQal6RhLrwzWLJwieMTBa0xfVWLiqlQGxcUrxHFT8Wxg0tawHsWYrKaCGZ/CEyvZSiE7KZTZ6H5J48KdXyeY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: efa23dcb-72cc-41ed-87f7-08dbfb02cede X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:28.3907 (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: RENRQV1NfBtHclKPyjucw9jaDVHAk4AMS5wWl8s//g/7cJPQdoHhiluVd8O2zfAT9yQ3aouiHX7h+FOV1Qgftg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-ORIG-GUID: D_VDOgAfLjlKB2oZyoQIbz2wV8LnhhOn X-Proofpoint-GUID: D_VDOgAfLjlKB2oZyoQIbz2wV8LnhhOn Add support for atomic writes, as follows: - Ensure that the IO follows all the atomic writes rules, like must be naturally aligned - Set REQ_ATOMIC Signed-off-by: John Garry --- block/fops.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/block/fops.c b/block/fops.c index 0abaac705daf..ba6a2c5a74b1 100644 --- a/block/fops.c +++ b/block/fops.c @@ -41,6 +41,24 @@ static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos, !bdev_iter_is_aligned(bdev, iter); } +static bool blkdev_atomic_write_valid(struct block_device *bdev, loff_t pos, + struct iov_iter *iter) +{ + struct request_queue *q = bdev_get_queue(bdev); + unsigned int min_bytes = queue_atomic_write_unit_min_bytes(q); + unsigned int max_bytes = queue_atomic_write_unit_max_bytes(q); + + if (iov_iter_count(iter) & (min_bytes - 1)) + return false; + if (!is_power_of_2(iov_iter_count(iter))) + return false; + if (pos & (iov_iter_count(iter) - 1)) + return false; + if (iov_iter_count(iter) > max_bytes) + return false; + return true; +} + #define DIO_INLINE_BIO_VECS 4 static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, @@ -48,6 +66,8 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, { struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); 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; loff_t pos = iocb->ki_pos; bool should_dirty = false; struct bio bio; @@ -56,6 +76,9 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, if (blkdev_dio_unaligned(bdev, pos, iter)) return -EINVAL; + if (atomic_write && !blkdev_atomic_write_valid(bdev, pos, iter)) + return -EINVAL; + if (nr_pages <= DIO_INLINE_BIO_VECS) vecs = inline_vecs; else { @@ -65,7 +88,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; @@ -74,6 +97,8 @@ 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; ret = bio_iov_iter_get_pages(&bio, iter); if (unlikely(ret)) @@ -167,10 +192,14 @@ 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); loff_t pos = iocb->ki_pos; int ret = 0; + if (atomic_write) + return -EINVAL; + if (blkdev_dio_unaligned(bdev, pos, iter)) return -EINVAL; @@ -305,6 +334,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); 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; struct blkdev_dio *dio; struct bio *bio; loff_t pos = iocb->ki_pos; @@ -313,6 +343,9 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, if (blkdev_dio_unaligned(bdev, pos, iter)) return -EINVAL; + if (atomic_write && !blkdev_atomic_write_valid(bdev, pos, iter)) + return -EINVAL; + if (iocb->ki_flags & IOCB_ALLOC_CACHE) opf |= REQ_ALLOC_CACHE; bio = bio_alloc_bioset(bdev, nr_pages, opf, GFP_KERNEL, @@ -347,6 +380,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); } @@ -605,6 +640,9 @@ static int blkdev_open(struct inode *inode, struct file *filp) if (bdev_nowait(handle->bdev)) filp->f_mode |= FMODE_NOWAIT; + if (queue_atomic_write_unit_min_bytes(bdev_get_queue(handle->bdev))) + filp->f_mode |= FMODE_CAN_ATOMIC_WRITE; + filp->f_mapping = handle->bdev->bd_inode->i_mapping; filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping); filp->private_data = handle; From patchwork Tue Dec 12 11:08:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488988 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="f4bx7mSs"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="hYI5+Vnd" Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46895D5B; Tue, 12 Dec 2023 03:12:11 -0800 (PST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BC7iRbN008820; Tue, 12 Dec 2023 11:09: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-11-20; bh=LOfd5S9ReCEogL9goxCB0fbMXjqtgR8FVaHhYpnjI0Q=; b=f4bx7mSsaO+tT4goJUc4tW+Y5K0cEzFYxQrLmf0BN8+SoRI+6699TDm4jlqEPRkdU3Do oqodlPxE7nbqAvyOMk0XVSga4ESXQX5j1WnRzK0HEzrDsdrNY5jXd1Ua22BIkMRmbG+y 6YsMXzoCoOChMcY2UZ/wdBDmwut0Prc1H+urRKaYJ5AG+mGO10q+G8VlTOXbrweKOHTp WEBBLOLJVQAGpU7HCXfHdIPamJ2Tk7n7C/jdcjDMFv2uEN/nw26ooiixi5wniYLekHOT l5d3+JzdV3159druDVCwRF1c3cRwjFasKb7M9Di2+R7hTuGkDgnKf9Rk9IwSlcL2M5eb xw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uvf5c5bks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:34 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3BCAIQ8v018689; Tue, 12 Dec 2023 11:09:33 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6d59h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bCiT+FCknxF71c/Im8if4Lws4vUwQJC6lUq1uMYyY7S40eN5JxcvD+qu85jFiqmIk9mZQBDzRbwXh49JgcBZy0IFMGHba3apXXkDc5VONaYhrNEfRgBqaK1SYyIOzC6wV+GjEJCDB/MSrxK8biAoI0fGuo+8JHIs827DGR361/cret7jqCBp1R7k6ALKs9IOhH23sLAvFzadARP99MjAF0mdl59JxztfxkUqTrlZv518qVv5gkCj3XfPzkhqvyO9hEuxt4PhH0Krh4nj/BGFvmGCakvR8dO7YncpdPzQguBM8ioFAnMggX+N3/roegATl89f1xbtu4hvi1sY86/ASA== 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=LOfd5S9ReCEogL9goxCB0fbMXjqtgR8FVaHhYpnjI0Q=; b=HF+x1mvWDYX4vbylZJDUaCB9Hm9I6Xm9NAuzlIi0nWPYzPTuoMMphsw6YcHiM9V9CZxJhI/vV7ouX98CB9sDtJdefz/GSUz6W7icQQQ6kQksJE/qXnPokd7lF3OMmsjeHLDLuKR3YIIceOsbgZ5D2loPh+MzkoRy9ibDRNcFLbWcYELMCIuA9uI26PcuM4j/cC/tfcUOA4rGp+BLGhP2uLSghSMgyqub4hJH5lJTeCP7BExDhv5Mm+ILs+kZLW1coGTZDmc8IC3Ubht96Wgz0FKbYzF8Hc6juO0yIVAulU9u4++hveXFJXcgozJ/5FrgkZEHw5Ig+AHjEUXs4UPQTA== 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=LOfd5S9ReCEogL9goxCB0fbMXjqtgR8FVaHhYpnjI0Q=; b=hYI5+VndNmP86ecJDhQM9mto5uKxelpu8NzOhhiwP3IZLcea13NvP1NokHtEo7PAMsA9wOAPVpd5d0HRrEuU8/ru+TG5ZAvAwzz6sPmLQNGcMOrmUhHzJnjgmErmb5OFNvUIEG9zREnSlH06lzxGkhCHfHGDf4EzHROtfz+1yoY= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:30 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:30 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v2 12/16] scsi: sd: Support reading atomic write properties from block limits VPD Date: Tue, 12 Dec 2023 11:08:40 +0000 Message-Id: <20231212110844.19698-13-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BY5PR17CA0020.namprd17.prod.outlook.com (2603:10b6:a03:1b8::33) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 896c5ce4-2ade-4370-07c6-08dbfb02d05c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KVv130Ve3gwxstWtKTmGhd0jfCFzqag9Dmx26jTYBS+qHMCipJ4kh7Y0ooYfvxLg8pnzBgYXAwl+txKgwPBHbye3UC/SbHtAThCvBR7bS1gdgUptPWnc69PitlhcfCqKloCOHfPAw5UJYxTt94pVAHYpelzKizhu6YLdVGSzrlTG/7RMKHm5Gb0fSvZROoh05GhKWdnBnKWo+NobEc0DYLGgtR0Z2JVIIGuWCjrM8ZdYhRq1W2HNFOn5nJcGVvEC4+nGnGHgFi8SEEY4HDl1M94ZUAMSYnjbJKEN06aIvpm4l6XnkySybs5wAnrMTKIcT4oEShJ/pNaLM/M3Dm4Qc7jQwh2MtEW2bPO93S2V0ngYQH8K89Ft3bh+YRCmhQKW4LGc6oniqvDeK0s2iRSgwIZA857/BfseytzVkzfq4uhBcyt5pfwa9wK4rcsvS8Wrtj10LX3V/C/t0UUwhW8wMDY7lOoTo+e7LMw1X4yjsTwZA8/GOlXUdfwjcwmh1kd+tx+ad0VmHVD/7ytZpiqzJkESrIq9mv2d4yB82f+Posd6jDGCQPGxuABgnEGenuUOMK5xOXv7OIkW4S6v9mGoEmaQAbBm6ahYXBvTWnvzZXg= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MHllQb3NMD5tB+pyvQeE9kP+wIMLt9LpoZzbGA7BEY1Ab5XTN1l7JZ1f4NwqfzgAarMUwuTMDOoNRNr+sRViB+d6P4hy20tFHCm+7DBP0d7zIlQQfBFRgNGZiaJSfeAYhqNPEQE4GHdNwNyIZyjqKe+TKhLMqroNJj/C4LB3dgjo7sKMvKzLi5io8m5ZWL+oEvn+ZAJ73RWQHPuHIExqBsBXlPC8/zEyV3aCAWWdMDrcjk57lutdjhroph9X454xu9AduPj5sWibcyMlautxRrfGY2sMkNByZMsXylxxi5tLMZs4nrMmD8ks06sCakMhpeqVzhGOdwaVO6YGAidGFrYedeKsXQydTYlkkrRSnCB11kmXDCStO5AehhOZZKId50BmxvQtTP88SmBlIM57V/iKBPJf7vvTHpw6JPy8fx7taucpY/q2gm+I1sPJG5P6OLg2tANQZwgnunt2SyzjJBxri4geiwdl6AyeSwFEdBr4W51RpeKFpi4xO6BZ/qYtV250FFk90+a39ALCJ7m91K38NEYPzyStkciCXgosl3EqjPe0NsKaGQV9W/TJCoy3S6zRfZnGr2Z6aCFnwwMD68EHSU8Lb8mtsPT5aVZmyofxGZP0YQArfqAqvYkGJ15yhuLIu4IPm3oJuC5WrkUGCbDx7wYq/yWzOYH6DXES8ErzKFlI/TwsOHb/bCl/2/U7mPBdKqmSKmATiBTvKJONezWthvRP1bskd5ombiP9qS4Ea7VIv8Gfgk6fmzW0rGr52f9S+f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P9TMT23JlsYn/Tl1ggBoh05WnQ/lLOjY+apeJQoFaMALiZryNTEjKCinZ1BJKKs9cjLKjXXdf8bcPUNCypMIIxkAaKXfJyhSLQU/H3yAmJS8738H2wbvqBqCa8A1MDgxQ9Abw3OV+mXT7xI5P/Dh06CoHGue5qQ3T1cNI8JCi7jQouUCsgtpfWRFjyZ3J4+FEAeEJwCYjJDZSuggzRt2c5Oj/Ht5bNNYReki18Ggq3g/bfGsS/MCRtdDe1XeBanHeM0mtiMQbgVcCBl062PRz7R1d22rGiqjfpp6evwrB/GVQXZ8cx/emNYBI6wmfujU/vDt8Jl2lzRNqhQKEAVZO+Qdsn9GrlrJTLM3XOkmyr+CQ+Nw0NGSIDMJlvu/eX0o+ce2JaqFbYiQBayHCtNVnMXuBuC8xFgOT5w+cVmbm9WXgGnUqXpukr7L/MQw/mVZ1zehFooM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 896c5ce4-2ade-4370-07c6-08dbfb02d05c X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:30.8498 (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: RLTEaG1EjqJzFcSOpZvqpW0A2/YvBNUGb61B7JYYtSWCCAHqVhM8hg7p+aEZFSnwtcWZ0yq0NnmEBaGFvUCAQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 spamscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-ORIG-GUID: TFyAdV_s6EB-i5GP0BZjTJUJfCGOr5Pu X-Proofpoint-GUID: TFyAdV_s6EB-i5GP0BZjTJUJfCGOr5Pu 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 | 69 ++++++++++++++++++++++++++++++++++++++++++++++- drivers/scsi/sd.h | 8 ++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 542a4bbb21bc..fa857a08341f 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -916,6 +916,65 @@ 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, + physical_block_size_sectors, max_atomic, unit_min, unit_max; + struct request_queue *q = sdkp->disk->queue; + + if ((!sdkp->max_atomic && !sdkp->max_atomic_with_boundary) || + sdkp->protection_type == T10_PI_TYPE2_PROTECTION) + return; + + physical_block_size_sectors = sdkp->physical_block_size / + sdkp->device->sector_size; + + unit_min = rounddown_pow_of_two(sdkp->atomic_granularity ? + sdkp->atomic_granularity : + physical_block_size_sectors); + + /* + * Only use atomic boundary when we have the odd scenario of + * sdkp->max_atomic == 0, which the spec does permit. + */ + if (sdkp->max_atomic) { + max_atomic = sdkp->max_atomic; + unit_max = rounddown_pow_of_two(sdkp->max_atomic); + sdkp->use_atomic_write_boundary = 0; + } else { + max_atomic = sdkp->max_atomic_with_boundary; + unit_max = rounddown_pow_of_two(sdkp->max_atomic_boundary); + sdkp->use_atomic_write_boundary = 1; + } + + /* + * Ensure compliance with granularity and alignment. For now, keep it + * simple and just don't support atomic writes for values mismatched + * with max_{boundary}atomic, physical block size, and + * atomic_granularity itself. + * + * We're really being distrustful by checking unit_max also... + */ + if (sdkp->atomic_granularity > 1) { + if (unit_min > 1 && unit_min % sdkp->atomic_granularity) + return; + if (unit_max > 1 && unit_max % sdkp->atomic_granularity) + return; + } + + if (sdkp->atomic_alignment > 1) { + if (unit_min > 1 && unit_min % sdkp->atomic_alignment) + return; + if (unit_max > 1 && unit_max % sdkp->atomic_alignment) + return; + } + + blk_queue_atomic_write_max_bytes(q, max_atomic * logical_block_size); + blk_queue_atomic_write_unit_min_sectors(q, unit_min); + blk_queue_atomic_write_unit_max_sectors(q, unit_max); + blk_queue_atomic_write_boundary_bytes(q, 0); +} + static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, bool unmap) { @@ -3071,7 +3130,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]); @@ -3102,6 +3161,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 409dda5350d1..990188a56b51 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; @@ -151,6 +158,7 @@ struct scsi_disk { unsigned urswrz : 1; unsigned security : 1; unsigned ignore_medium_access_errors : 1; + unsigned use_atomic_write_boundary : 1; }; #define to_scsi_disk(obj) container_of(obj, struct scsi_disk, disk_dev) From patchwork Tue Dec 12 11:08:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488989 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="NNvtiNlc"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="B619psh8" Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A81BD5D; Tue, 12 Dec 2023 03:12:11 -0800 (PST) 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 3BC7iCtk020707; Tue, 12 Dec 2023 11:09:36 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-11-20; bh=e2MtufRTXXYathMPqWsaL2vZTc0diGY0QRspYAKXl5c=; b=NNvtiNlcD47Ow0Iu1m8BYzpUPQOKqThzNAk05WMzFMySWQJ1aTGb77JlAPn3yo+dE7mO wv49LafWo0Jw14/oqfSrBAcCA4skRghNA2D9/YP3tGwiw6m4WLThOxOP9B1X7+Kv7MdC eFu+aR0AmoI2mmfW/oLG/f+9ucoRCieFzV8X6VavgIxgWENy1O2JKO1Mtw8C8cpcKv3l yDr+GKf1diz/xVxnO/vHinf1a+diaWsQWmT9iyXZl5wN6/CCt48vtdmOpTsQlO1AX56K L4CbdoiLK1Qn053A4pu2DFnYWfmJu1Ojc3rIx0Xo09jtBvQPkogvtgF94UAevCePYvbV +w== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ux5df21hh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:36 +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 3BCAq2C2010022; Tue, 12 Dec 2023 11:09:34 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6dfje-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tt5m7xd3GxY+jzQVZqD3PzSBzcS5aSr+sF+PMv7UN8NRSfhKP4qA7z7hvG2WXF2tkY+QpU9L+NB9toryiIOwkAifVVDiVc/epGNHWj3Oc9zdwHLb8q8roGxGB1XSS+fSWCQOf782Dt6I3nWZa7EclcKEG5QumsHIv18AlP9a6YVJwefMcne/AHOAINGstz2UBccJuVN527I1HOOIJLCi+m3l1NlJUp8t4YPPLdA/U+Ml3HadTsjddD0kIAsBA1OOZQ1ZBEmY9SYqbBVpqbTq643m3zNJGn8ldArtOHwnU9k8pVK7YWGw5ujtECtmfxtUgfsQ5dySytRayl15yax2qA== 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=e2MtufRTXXYathMPqWsaL2vZTc0diGY0QRspYAKXl5c=; b=PDi7v6+Uc2fTuuIV/reFWGZoN12iQu7fkhT7W62ajCcYJhxFiVoEERRNVDngZKIMS2m7OI7RwZTZNScTQFOd2sXyNu8zU/iDChHJpB/33KSDqsx2PHiiRdPn9rFshW4daXqjbwlHUq4JFdDKiB0ILRdcZTF7kITwHRfQgZ618FMgyWz/aeeczfz1Y4JB+tXtNzT6Kb//pIYx3YsIp0bpFEIwGkIPwvWjIr2XsXueYgcGicv7EbWIRJQYW5zIE9j8eAO7r8LVW0CZlzBH6yhHblOmSndWyRl2pz4hi9JmoCPbsqWv1+B+owimuqGhv9ylRvzW1lOEMGWIuz1H8k3yJQ== 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=e2MtufRTXXYathMPqWsaL2vZTc0diGY0QRspYAKXl5c=; b=B619psh8vmP1pig5dGyl29J8S0KB+oIM5F7/a50lqlQhVpUmddOAOZAVJDWHIikpvM/F8tczBrjj9Py5rpeFLf51bc/TE7LMBC4RuPmawvHUzT4LwC5GPDGIqkxREgsH6eiGSv10oMXBrWOlckZmAun/kReZ+gt8/VFdAPHbRVU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:32 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:32 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v2 13/16] scsi: sd: Add WRITE_ATOMIC_16 support Date: Tue, 12 Dec 2023 11:08:41 +0000 Message-Id: <20231212110844.19698-14-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BYAPR06CA0053.namprd06.prod.outlook.com (2603:10b6:a03:14b::30) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e3ddb56-2cae-4e30-ec59-08dbfb02d17e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tkBoYTyHVmVZIQtbv7Zqap7qWEt+j2Ga8K6NLqSiMAOSXB1JRLBIpH6tsNgnT8WpyHGO7SCFUR5FEc/bCIcJfGs8nHBtfYLEVSX9Yrm3iaH2V7Bxui0sjwAHOH8K7nnKaP4PUgHMVXa+jvhymPJ73FAi/i3THPaOJJonrC937VWqZYuNkh1190I5w4bqbU21r/xQQQOzjsYMCnegvAJ9rqWIOZHcb2Y9tmJ1FY8QZTAR382mZEV58j1e6s7+ryQZRZXYZ4DMGpwihVKJHGvJTm4fdhkREgTPvZDRo77lZ1a01cXoreWZQ4wL5jeDlYCJUvIyCH8Ljo2/W/p9coysFz8/ezr2u+SGvGvxSkJIkNN8LbXqtweWI7jOSp/n0DFoW44rs3UMFh7Ipz4y0s9aADDsPxO3hBaPD0MCocHrLN9VVyKJBMR2q+9pxS7TRBqqKdJrYS4l60XVF2ClF42DerIIC3B6g+qU8aNOksKszJVSqEA+h4m70RED1cufpI/KaSFQIpFyMKmHb4F4TsoGQf55LstV4QgHb8gNJuRqNbUSpBWxDtonwHulf2N3MZjRc2F45RHBabbufsWM4GQNZfBWfeyiWGtDQKkf9/w3aUI= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VqzI9dqGNjcQuenugiv2ll+op2gS+gU+e07dtvBqvYeZg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6K3Mi8IxFX/RCwhsM6CV43ggDU1vnpoplYdswIm4oLt4LqI943/+kSvYSuTGEzEkTBSKD7NGnqomdb6NCeLlFuaHtDeoTUzXMu55e0LSCrThSceFQ5LlZ8Ml4P5IlycopdV0jRtXF9AaK/2y78KSmDYhvYdYALlwkb0Ubrvd6zftX5y+49JpYCZ4a0aqKkPFg8Y8NZjG0J/dJapRVallfLbvCU6NcyMvjdza08bRxpxS3TIb0MADSmDq9zkj8hmw/gRzloPu2t0/pDgW+ghS4IV0c8vNpnmrWrXEbsVQGPkGhx7vEJHRZvfwiZpFK7/hmyi+6518oiOGsmRbn4TfNvlpXGl13JvYSCjG5CEPJHHOmwr7hXGhqi4ViF/ptcceZViehUuR+pQ1YRR1BIIOY0bCNaswltZd/VdGmvYbPkNzXJf0UloVL526zhdeWJigaPt0f9Q+11q1JEDyLfQXe/FAXnzfY1d15Cc/G4NRejzQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: CDu5j9vu47gDDfjnW6/fgUcq9qxco5CjO1NNtUB4C2VkCjrv15GFI39wx0/NtZwE9laQtmspyUkW910jhcFwQa8kmJYY9a+81otdzwv12Gm9XLd0ZYu3SHmFJmPtR87BiYERBNPU0wqCWbEaNTN0Aruqft1uz7j1zn75UQ+wfhLYNZeuMoD3Srwkw2LpQbBbDJD3rMCM/avNbtE8w7GfxWrk8Uf3jQgYvQcm5DnmVoP896wkyTxW/6pg2kDGNKivk605BhD/Uz7mXoaar4kPr7MjVbopCYUwr/61gdazusnxrMuWUisnKtAJJylOtuxQ5I6v7QbHjWCXRIU8LnWYo6npUC6AHdV7fPv7nRQ6J2dJlJichegB1sb+rZeGwDhMs5euDx3sEKuK50EFhs/3haO7T6FtyobveDCcmdtmNwn2wgAzWlGU/qTkx1XBaakxDLrX23FBPHK0hNcfk8t+RE+wSSUMBMUX53+Nz8yneOQ8fs0nWZG1TOfTnVl+MRupqTtT349FqI02bWGLu1L5So6E9/tl7MGEuSWo0LIoE2T7Hg47yalKKIlZF5T1a3yDRKLdKQL8jRCBTbxJ7ufxopttKdTFEt3VhnD+nTX/kBo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e3ddb56-2cae-4e30-ec59-08dbfb02d17e X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:32.7653 (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: EGzIHM0PWHbaArDkCyZxoUQ4U5eAFAepYe42Z6vLFyDWT554RKcdcsWC4aaF7MvsK797vFsybgfXMYiwswIkcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-GUID: c4Pv2dGC33CHDAUH2eyQv6pkhjEXNLM5 X-Proofpoint-ORIG-GUID: c4Pv2dGC33CHDAUH2eyQv6pkhjEXNLM5 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 | 24 ++++++++++++++++++++++++ include/scsi/scsi_proto.h | 1 + include/trace/events/scsi.h | 1 + 4 files changed, 48 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 fa857a08341f..10942e322253 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1240,6 +1240,26 @@ static int sd_cdl_dld(struct scsi_disk *sdkp, struct scsi_cmnd *scmd) return (hint - IOPRIO_HINT_DEV_DURATION_LIMIT_1) + 1; } +static blk_status_t sd_setup_atomic_cmnd(struct scsi_cmnd *cmd, + sector_t lba, unsigned int nr_blocks, + bool boundary, unsigned char flags) +{ + cmd->cmd_len = 16; + cmd->cmnd[0] = WRITE_ATOMIC_16; + cmd->cmnd[1] = flags; + put_unaligned_be64(lba, &cmd->cmnd[2]); + put_unaligned_be16(nr_blocks, &cmd->cmnd[12]); + if (boundary) + put_unaligned_be16(nr_blocks, &cmd->cmnd[10]); + else + put_unaligned_be16(0, &cmd->cmnd[10]); + 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); @@ -1311,6 +1331,10 @@ 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, dld); + } else if (rq->cmd_flags & REQ_ATOMIC && write) { + ret = sd_setup_atomic_cmnd(cmd, lba, nr_blocks, + sdkp->use_atomic_write_boundary, + protect | fua); } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { ret = sd_setup_rw16_cmnd(cmd, write, lba, nr_blocks, protect | fua, dld); diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index 07d65c1f59db..833de67305b5 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 diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h index 8e2d9b1b0e77..05f1945ed204 100644 --- a/include/trace/events/scsi.h +++ b/include/trace/events/scsi.h @@ -102,6 +102,7 @@ scsi_opcode_name(WRITE_32), \ scsi_opcode_name(WRITE_SAME_32), \ scsi_opcode_name(ATA_16), \ + scsi_opcode_name(WRITE_ATOMIC_16), \ scsi_opcode_name(ATA_12)) #define scsi_hostbyte_name(result) { result, #result } From patchwork Tue Dec 12 11:08:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488985 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="gL96HSs5"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="oG2Srx3g" Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 080EF1BC3; Tue, 12 Dec 2023 03:10:16 -0800 (PST) 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 3BC7hlIl028850; Tue, 12 Dec 2023 11:09:50 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-11-20; bh=wP0nm9QqN/P7E2NLBY5g0WTClOu/jw3Wp3yzSs/pv9A=; b=gL96HSs5fzQIyHsRczyekGH3SNcBDT35VFvqt4K+mdI/c1F+5ZwkGUiHGQ4HoyAtVYHg j7yACDSIJmoCYafAtokylEO2HCxihNG2k+dVzwza8bk/docG3udJDnexVbNU5XsRFq1Y PAvwMlS78nHWP+27P3KqlCgZ8HVJMIcJNERw17esmRJt07QbPw3PtTG41l44Hop929V6 C+aaizQI9Mnys771WfTUSMnFV8iw+EZhX6be+nPG1GwsZbaGt36yfMuVAsno4jiRluZw MJ74HMjlY+aINKdvINiAi4375CoJ44AFsoJ9OZvcrtZWjLNKnKdKRFbDT49TJSZR5k8F Mg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uvg9d5dam-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:49 +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 3BCAwj7H008234; Tue, 12 Dec 2023 11:09:48 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6cwvf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BDcediAaV3wU+IZQ1rno/qX2DxIWY+ncJuuFuLL4jeUS5cWizJgbATFd8FCm9L00I80W7L/HFL0IPhgi3VBucSn4crcfUhAaw/jrOdTthvlB0d8vzJfwV9JDTVxzMMeh5SMli1v/OrcYxqYVo85Ig7XBT+zZydroQQ7Q2DAjD2YNT4HX5coe145q2PshIkgqj38NuzPrG1meW2linnVgSHkioIC2+OhfopIxLj/ZlFSd6zZ6WT9orexSel916sPjNNF1AUQjzYnXj1GleC4c95G65UuGeRauW2y3nhKglYZOKjoHviDu9bfl9cqL1XqNMrk3pvXqNkBJiNkeHJHMjQ== 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=wP0nm9QqN/P7E2NLBY5g0WTClOu/jw3Wp3yzSs/pv9A=; b=ORL3/g6O5UNSiD1aixoOplYx3kgHOXjzY+Wp9D2ls0S4iAPWMfdQaCPi7XlFP0wCam5Mya9+b+MRR3HYSVfSIJVla4XnbJ1TezKRwRd1jqeYyhU/sDeoRWqZBXuWOU/ggLesrjWwNA6ihDLSVmTuL9B/B0/mCNfr4tZST+tF3Z3v0mStVZOKKilQz6XyVNrLGWukmLd9PvN3ZeGKS22zVbATyI843ZH9HlUTbDkJx159Ywa4gwuayb/uQV7/11grjklr0NGqs6Zyo8hiEjcUKovQbQqkidf5YINjvfR387EEXekCMtnAdMW8IPc7vHfg/of2KyXZe1C6Ufimx6Hiug== 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=wP0nm9QqN/P7E2NLBY5g0WTClOu/jw3Wp3yzSs/pv9A=; b=oG2Srx3gERuJkxseuwf7UmnODNEJ6d8y2oxhtJZGSBIzBR7c/gIFNcTxFnHRpd6XFajET2Qx0nBeVDt1iUk0NLS2z2PMbjBgOvyoZjryeIT+W964tU50euN2hH39f1OJfHQTI2eFA7KamNu3DgRPDSFC66OvbLKz2oNO/FLdlcc= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:45 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:44 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v2 14/16] scsi: scsi_debug: Atomic write support Date: Tue, 12 Dec 2023 11:08:42 +0000 Message-Id: <20231212110844.19698-15-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BYAPR06CA0047.namprd06.prod.outlook.com (2603:10b6:a03:14b::24) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 6daf1feb-b626-42bd-80e4-08dbfb02d8a8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KmdXMaQ/bfuxGdlhV4hEQaJOMegc6UGoR4phKKF3y9bL8O/hCi3CaRV21BP+JG2F48jERbQvMy/OFa8MAHZO1QHDZHclXu5JM+IDWEMmFg6lCnaCDJP4IuYXy1FB41+f/ydKTqTedrUrog60iCkiuhtuVPPn1C1478BeJnysIyGJtHrK29DGyU5ZnkQFunT5iw3QP3mMGwNy9tLupsmRjP60XJ/uMoJWbxdrbpUYbbfzBbmTlCO4YutR24c6yaqhaACSZukIwGyMXbKLGrsKS3+utJrhSVXuqG2xpwQ+kIci0s4dt9z9eVCQRvFpVfU73wTY6VSVMPHl0JzGYcJDtLOygfL4wKihmd9hZdDUqP+32SPBBDWpXgrsMhMSxIKALj60SUC5vFYVL1AsWhSL2zm3f0cQMQAWtb5d5XwlCPS9ovZvucdwHiiQ5Gm3dizltRAzte50haa2s84Glj31FTOT4ApHgwfzXa+GHrs54GAT4RghxH1MI/J1wg4NjO8BMFMH1UT5Y0LcF3zqVCe+XHYc1Xee9B3kPhrNS/bovJiS3rJB920zTInmBnYQHxkE6X2+LC+tHtJEM10SXGIyaoTvW1f8jlPgjcjwVdFwjB4fkFcvJJR3cI/7fyjGP1Sy 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(30864003)(38100700002)(316002)(66476007)(66556008)(66946007)(103116003)(86362001)(36756003)(921008)(357404004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HCjMOSN1uo0Ye0ECTZLFlZWGrLojRX1ba5o/j5qOgqQBnUX4XUaZ1BNJaFpoGIQYHat7AXtZi5QkcX6GbVyWJENKsH/OXSIt2Qh+dZg0GwHlp2uCU4gU6n7k0qVGL82XPgVUbkAJSbnV+BbwPLscYY1zKmNvkZj5LI8sVczmm6tq+Smr/6rQMqv1OH8gNksAAi6iyc/Uc9QISrkE2R4rCmIBYGX9KcrA7v0AZFuGDVQPj3/tkzbepQkb7JQTurW1q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0nMdbdjLw7zYadD9UzLIJY9FDD1Zzlz66atMUookmgHgDDX7SOx84TW6MrFqfR2JpHWqEDKyFrbCVuTk/odMWh++bUPxs4SkKdJyM2JCYbIr8jhxU9MkHrY9WSyy07yDwZ9ZzkomcaRHJYfCMNnfq/l+4boqNy2tJCA0Dpip308XFnFhT+2VNyGR/wPP9eHiMY9B9OY4A3aP2FIals8DINUQrQWn5+rLHXAwPbU1zEqLk+lR0siydObOW30xZ+BX9eibswfgZ0kex0n9Bm6wfISsVknNm/GQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: AtqcS6iGj8hwbAchFje7ddl8MLUP5+EpY8ChmxTca2XnS3pQhD0lq+wzgG9BBsQTFsK51FhksNy1E7/khAxoBcwI1HbY3JGTZ8gVwePR0xlFMdCHK8pSaw+rXrEiFgV7NTaUNxpR317E1I6IjsQxKKnIH9NfChU/chX2lQBzvw9d7aNkrdNdxbZdu5fkFpoSPZgd3UeVWh81TD9o3fcVa2MPYiPfrAyyu0/z6pb5YLyAAtfW1xtsDNUrcn07Hu0Oj66Vj23B5Ct+p5kEq62EUJJEwnbo4K+20UxxwkHH2bzD33Bp28cXwFv6HqUjEde3x+k64j5x7gsodX5qR+XL7z1HH8TULKkk8zOChbEx2SvjL8W1DGVgrkvSUYKRJ37GzbLm0LX4Zr/qlGZ5vD6tFW+/7XVaezE4YZBVZ8mGtxKOo9v2urReuqkRRCUuoEIHWxpFyQSLAugGJG6/XbtqxcV5yNy7gbnc6/VI6UK5FPOET/DAFbI9I1unF9XgH5M1L3kO9UTVARUhUKQhuFPdVRxCX2NAsXDnE5reT8tttXGgBy3mkrI/Xs9LrmzkRQ3Ye+tvDL7/lcHcSmF6RySoOO6ND6EkGfJXL32yWjGVP9U= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6daf1feb-b626-42bd-80e4-08dbfb02d8a8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:44.9318 (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: jPLkJdHbZ0ahuOM8ChC6MWtrQajtwHY+yA+WwK9pOkJD/ihZ3Sft0uiz+NjuWw6LNvemCW/koWL17ATUzaNBaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-GUID: VYMDyUoFLMNJDtW26lBF7yuv6zMB4ui8 X-Proofpoint-ORIG-GUID: VYMDyUoFLMNJDtW26lBF7yuv6zMB4ui8 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 | 590 +++++++++++++++++++++++++++++--------- 1 file changed, 457 insertions(+), 133 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 512fae20c56c..645571b0fd2c 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -68,6 +68,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 @@ -102,6 +104,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 @@ -151,6 +154,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_WR 0 +#define DEF_ATOMIC_WR_MAX_LENGTH 8192 +#define DEF_ATOMIC_WR_ALIGN 2 +#define DEF_ATOMIC_WR_GRAN 2 +#define DEF_ATOMIC_WR_MAX_LENGTH_BNDRY (DEF_ATOMIC_WR_MAX_LENGTH) +#define DEF_ATOMIC_WR_MAX_BNDRY 128 #define DEF_STRICT 0 #define DEF_STATISTICS false #define DEF_SUBMIT_QUEUES 1 @@ -373,7 +382,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 */ @@ -397,12 +408,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 *scmd; + struct sdebug_device_access_info *i; }; struct sdebug_scsi_cmd { @@ -462,7 +481,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, + SDEB_I_LAST_ELEM_P1 = 33, /* keep this last (previous + 1) */ }; @@ -496,7 +516,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, @@ -544,6 +565,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 *); @@ -782,6 +804,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} }, @@ -829,6 +856,13 @@ 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_wr = DEF_ATOMIC_WR; +static unsigned int sdebug_atomic_wr_max_length = DEF_ATOMIC_WR_MAX_LENGTH; +static unsigned int sdebug_atomic_wr_align = DEF_ATOMIC_WR_ALIGN; +static unsigned int sdebug_atomic_wr_gran = DEF_ATOMIC_WR_GRAN; +static unsigned int sdebug_atomic_wr_max_length_bndry = + DEF_ATOMIC_WR_MAX_LENGTH_BNDRY; +static unsigned int sdebug_atomic_wr_max_bndry = DEF_ATOMIC_WR_MAX_BNDRY; static int sdebug_uuid_ctl = DEF_UUID_CTL; static bool sdebug_random = DEF_RANDOM; static bool sdebug_per_host_store = DEF_PER_HOST_STORE; @@ -1177,6 +1211,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_wr; +} + static void *lba2fake_store(struct sdeb_store_info *sip, unsigned long long lba) { @@ -1804,6 +1843,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_wr) { + put_unaligned_be32(sdebug_atomic_wr_max_length, &arr[40]); + put_unaligned_be32(sdebug_atomic_wr_align, &arr[44]); + put_unaligned_be32(sdebug_atomic_wr_gran, &arr[48]); + put_unaligned_be32(sdebug_atomic_wr_max_length_bndry, &arr[52]); + put_unaligned_be32(sdebug_atomic_wr_max_bndry, &arr[56]); + } + return 0x3c; /* Mandatory page length for Logical Block Provisioning */ } @@ -3305,15 +3352,240 @@ 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); + } +} + /* 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; @@ -3329,21 +3601,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; } @@ -3519,70 +3796,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; @@ -3592,6 +3805,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: @@ -3650,6 +3864,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; @@ -3669,29 +3887,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; } @@ -3699,8 +3921,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; @@ -3889,6 +4112,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: @@ -3942,10 +4166,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; } @@ -3954,22 +4185,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; } @@ -3977,13 +4208,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 && @@ -4090,7 +4324,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; @@ -4133,7 +4368,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); @@ -4172,7 +4411,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; @@ -4191,14 +4430,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); @@ -4209,6 +4450,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; @@ -4216,8 +4458,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", @@ -4234,10 +4476,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, @@ -4380,25 +4624,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; } @@ -4442,7 +4691,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); @@ -4458,7 +4707,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; @@ -4571,12 +4820,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; @@ -4735,7 +4985,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) { @@ -4757,7 +5007,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; } @@ -4803,7 +5053,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; @@ -4901,11 +5151,70 @@ 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, lba_tmp; + 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); + + lba_tmp = lba; + if (sdebug_atomic_wr_align && + do_div(lba_tmp, sdebug_atomic_wr_align)) { + /* Does not meet alignment requirement */ + mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); + return check_condition_result; + } + + if (sdebug_atomic_wr_gran && len % sdebug_atomic_wr_gran) { + /* 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_wr_max_bndry) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + + if (len > sdebug_atomic_wr_max_length_bndry) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + } else { + if (len > sdebug_atomic_wr_max_length) { + 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) { @@ -4932,8 +5241,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 */ @@ -4982,7 +5290,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; } @@ -5009,7 +5317,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); @@ -5038,7 +5346,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; } @@ -5081,7 +5389,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); @@ -5110,7 +5418,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; } @@ -5161,7 +5469,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); @@ -5189,7 +5497,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; } @@ -5216,6 +5524,7 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) if (!scp) { pr_err("scmd=NULL\n"); goto out; + } sdsc = scsi_cmd_priv(scp); @@ -6153,6 +6462,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_wr, sdebug_atomic_wr, 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); @@ -6187,6 +6497,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_wr_max_length, sdebug_atomic_wr_max_length, int, S_IRUGO); +module_param_named(atomic_wr_align, sdebug_atomic_wr_align, int, S_IRUGO); +module_param_named(atomic_wr_gran, sdebug_atomic_wr_gran, int, S_IRUGO); +module_param_named(atomic_wr_max_length_bndry, sdebug_atomic_wr_max_length_bndry, int, S_IRUGO); +module_param_named(atomic_wr_max_bndry, sdebug_atomic_wr_max_bndry, 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, @@ -6230,6 +6545,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)"); @@ -6261,6 +6577,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_wr_max_length, "max # of blocks can be atomically written in one cmd (def=8192)"); +MODULE_PARM_DESC(atomic_wr_align, "minimum alignment of atomic write in blocks (def=2)"); +MODULE_PARM_DESC(atomic_wr_gran, "minimum granularity of atomic write in blocks (def=2)"); +MODULE_PARM_DESC(atomic_wr_max_length_bndry, "max # of blocks can be atomically written in one cmd with boundary set (def=8192)"); +MODULE_PARM_DESC(atomic_wr_max_bndry, "max # boundaries per atomic write (def=128)"); 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)"); @@ -7407,6 +7728,7 @@ static int __init scsi_debug_init(void) return -EINVAL; } } + xa_init_flags(per_store_ap, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ); if (want_store) { idx = sdebug_add_store(); @@ -7614,7 +7936,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); From patchwork Tue Dec 12 11:08:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488983 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="oINOyPuU"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="ARlhJx+S" Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A06EB10C1; Tue, 12 Dec 2023 03:10:08 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BC7hpfB021911; Tue, 12 Dec 2023 11:09:50 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-11-20; bh=AI7wWNeH9LWA0Y0nIu01iwJ5SXOwYnCuLWBO5mP506U=; b=oINOyPuUOLmi7LYwFIHsZiFyeDiNaZXs7Ln4cb6ZMIPZjt8oVRAoGvZ3JUaqaPo5dn/r +FHMUxu1HF/M/dXF4jLBLFOTXv4aQJJQV6Ea1YnvNHKdbzENYnHlZHt2yOzWk4cnSayV rkIeWINhBPGwNoOsMNkGx4GuUvR1uI07Ix3X+fCQj+gTUlMCbJxD8H/cL45euacHOAP+ d300vdvoVe7aUNbxqQvooiK5F0dRDEaxShwZj9x8arg+xo+EEd11XbMkHAaPqG7fkID6 UygwzSJo3gvMiLhQL2rUGabvFi9VGwPPJzR6rCJhZYIkHubIgCE6V9amHjxDdBBZwBQG 3A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uwgn3knah-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:50 +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 3BCAwj7I008234; Tue, 12 Dec 2023 11:09:49 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6cwvf-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mWh+CchaiMDwtS+BQMtAdWtTs2ePs537BAzX0aQ7VuYoI4lA+X5QC58jeEbwqxznD99ctY3eTCVijMD1l6DL/XjmEhy+CE+6lrI7lhneDNSSTQ65Z6FsYzh3lwcDeYjFiKk1eEP45ZORsPyr1ZhFZZjrjwX1CSn9d3S/nK8xIsh+DzBse99joMAvM05/8Mn0ZODvXAJxe7o3hF6h6jozGZ9RGlELEa6Ye/4atOb4JLzIjtA4tuxOtdML+AqMqVettOlf1seqUdaMY9wSyrG+dtUaKa58prh45/5s9r9z/trNk+EjBIaA9jgGtJHR7fPMDxAyfKIi2jnVlk/xJBWLgQ== 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=AI7wWNeH9LWA0Y0nIu01iwJ5SXOwYnCuLWBO5mP506U=; b=Df7tPCt6m3gn3al3p0M5iWpxZf3JdM0/KmHSu8YvidlwTRShOt4GLDZVwr3TulBUFWY5I74KoGe5vTHauzWC/bz9CDzRW2Op7KXM64aNXb/hq0ygVyh9+Sm9bzUVhuKuYP27G/ZTKkBv+3AaKz3F3URq2GGvTgHaYVuBbZdCrx5QbWmOKthfvIY+x8MhuxyCu5B6aDGn9fb9OuPkD7RVy4vfwvn2Ase5sKkSTiKTQR4F+PcIgzLRKqc7hrjx3lzI2brivj/ikjzoGTtDWWwUzaL7vKxoLmPiS5cyp9UhtB3w6G7pDyquYsXjaNpFSPTv4LYDUV8a8r5gl/LfdGF/oA== 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=AI7wWNeH9LWA0Y0nIu01iwJ5SXOwYnCuLWBO5mP506U=; b=ARlhJx+S7NV1MABU1IOqqmcfAYfSrBGVu4wX+SHko3tmub0Z6j5ShCx/Td/ThqckhHBCq82pfxHJSdwgl1ZMN1dEXjYpIBJ+QKpSirDJem+fMJlmqqjWNzbrrYPvkHIt34buh1yCqf3N2fjGcEvWhGQ4ilhBGxzGKO6WT91duwk= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:46 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:46 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, Alan Adamson , John Garry Subject: [PATCH v2 15/16] nvme: Support atomic writes Date: Tue, 12 Dec 2023 11:08:43 +0000 Message-Id: <20231212110844.19698-16-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0263.namprd13.prod.outlook.com (2603:10b6:208:2ba::28) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 2cd8afd4-9a3c-4251-451a-08dbfb02d967 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e7nR1ybpOKPgqMigIdNNaVuObIrIz6bzuGeLV6MrdoLQa3+yP8mgn/EpnsFqEFcUoVx3Mf83cUxEgdLUdIHejIrA56rYrHioJGOD0e45H33YE7qze/8bcFD0tu69fipeW4hUEVZIsTL2mNlBc395Fks8JBPatznesMuZHi+LlW+9v6dtvZKrN6InfNH4PDfm1w7yQ0dMsWByFd40F4nrnQphOv9+1wYginNOJTd7kLG8HzEQ8gy7cIS9PbotF3tvSEfEDZVX3YYqrDScePXTJ/GQX4dZ/oHwwaJlYMpKxyD77RZ1MR8RpOByH3IAv4NwMDKXMyZvVRcUjWeQjP0aQDfCYVFmVLbm2K66YJylWyzjscfcSLH4XYMv8zN/gKiTwgpVPcZ6QFXjoAFnBufq48T9pRhEnGoJhR1n+gbfqWwcGh+0ghNpKRPMNdl3TMK7SsGelxf42iR7igcRjPHW4/09d8M367qCv+DKOcmYyGws0YP1NB7OXDsIcvuXTxHNScUu3FpX3jYQ/7Rq7UhGBIdVHENyslPie759HMbtNPMxY6KrypQbGHCXkqsO/61PRvxjyplK08GDkZfvRM85PRAAFU4KiVthilmFuuz46JI= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(54906003)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v8Qu7NSlN7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qQAqzvYP8NoZxuv7uwdYmX8QM+j84MDl/MxiYXqwBOwSVtwvTNKL5K1ToK/agGbAVhzEqfCvWReF15ew1vgemfLrWFDFAqu2FUJA9NgYWwip2vRdUH3vrK0g6QMUywDqYO/rKedmzfq43vNj0/xu0AWhjSJylHE6ADnY8a1D6zPy2vSeyA7047fE/duMeDJr0qIDoacAKWemerenXgRRyWB0aSV/b0lqUiBFCn0Vy4RAIhdCLcGV9ifvQ+mKR/PPpNPt2hwJ6tc63uwuaavOjT9za3Etb8Lnwks+Nq5CJcdAH4/rEOPsW1UI908kJBWK64HALCxPRODgrnAoywRdCHuCUn6LBtxgxEqOdOudaRZdeMKsTDs13eic0qp1eejPtZcL7ctDX5iMVhxGnDnU6MZpqaX/1yRIEqi9ZvXfhsNft1SQdpB15A40OB1dF9YDx2WyoQXMKLMcuRy1MUyH9LPlr8hjSNMplYCKsVFnqKvj9daN1MM/F6FpDe2zfOHYKCOav5RD0lO8YEpovtFgPwEKLJial9qA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: muhR3dUeTk5Xo8KpIL/LVcPkwCbvC80n9Qp/s3N9UK4ubeuHGiMtgERWnPMWlpuJMrg3Tr0+bu1ofYGiefqKDsh9Q6xEq3o4dA4k6A4LNd6WTIFU7EqgpLR6z9DMHyQZvUnAclckh8cUTPRe59enExbOFlNPi5b21pErPfSNQbqaE6kK5Qc8S7cQX37WSu0rZPy+nze4WAtwFQSgVqH/aq6FprvdSD3bpUf+vAf+meLDh/apQqtThorjm9pT5hY2epXv4AATlgwe+afRaN+m+eiKb6GgeFVL6uFtsUuDK4uMBiF/saFM2Ww+fl47irFsGNV3yOnzD4ssUNXcVstrjDno5eSPuKmONUonvSP0c9zwQjcMMH0NAZKv6GpLojSgsfwV+mnSbBlIUdGFDnaNyL3+6IDzrUsM9MvFpagfb3YGkMNGyF7InlDlF9soFKcIcbTrBzZ7wEVF55k+eKaBzKCZn6BO/fsrmXgbCnyypg+OPMFu7K9c8Te+m2etpoufunl7PlkYsqP066U0607F2Oc9b4Oz4iMe8aea/nHpSCfZ5hWfJjO2T7J3rDhvjxx7mDouoghVWASIVw8+qtvZhqhKKuMnm3VKUMBgS7Mcvyg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2cd8afd4-9a3c-4251-451a-08dbfb02d967 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:46.0487 (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: Mc+/w9XzbyXAcFHwg6sxiYfXgZ0Seeok5SqDcU6w1A76UoqkStMgYdEdXloBzPqLrDJ4wrZHnhwQ98+6g4NoBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-ORIG-GUID: cupF7vrX7tqhuHEXQ3tNHBFh3q3pcOlV X-Proofpoint-GUID: cupF7vrX7tqhuHEXQ3tNHBFh3q3pcOlV 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 #jpg: some rewrite Signed-off-by: John Garry --- drivers/nvme/host/core.c | 85 ++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 21 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 8ebdfd623e0f..fd4f09f9dbe8 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1894,12 +1894,68 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl, blk_queue_write_cache(q, vwc, vwc); } +static void nvme_update_atomic_write_disk_info(struct gendisk *disk, + struct nvme_ns *ns, struct nvme_id_ns *id, u32 bs, u32 phys_bs) +{ + unsigned int max_bytes = 0, unit_min = 0, unit_max = 0, boundary = 0; + u32 atomic_bs = bs; + + if (id->nabo == 0) { + unsigned int ns_boundary; + + /* + * Bit 1 indicates whether NAWUPF is defined for this namespace + * and whether it should be used instead of AWUPF. If NAWUPF == + * 0 then AWUPF must be used instead. + */ + if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf) + atomic_bs = (1 + le16_to_cpu(id->nawupf)) * bs; + else + atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs; + + if (le16_to_cpu(id->nabspf)) + ns_boundary = (le16_to_cpu(id->nabspf) + 1) * bs; + else + ns_boundary = 0; + + /* + * The boundary size just needs to be a multiple + * of unit_max (and not necessarily a power-of-2), so + * this could be relaxed in the block layer in future. + */ + if (!ns_boundary || is_power_of_2(ns_boundary)) { + max_bytes = atomic_bs; + unit_min = bs >> SECTOR_SHIFT; + unit_max = rounddown_pow_of_two(atomic_bs) >> SECTOR_SHIFT; + boundary = ns_boundary; + } else { + dev_notice(ns->ctrl->device, "Unsupported atomic write boundary (%d bytes)\n", + ns_boundary); + } + } else { + dev_info(ns->ctrl->device, "Atomic writes not supported for NABO set (%d blocks)\n", + id->nabo); + } + + blk_queue_atomic_write_max_bytes(disk->queue, atomic_bs); + blk_queue_atomic_write_unit_min_sectors(disk->queue, bs >> SECTOR_SHIFT); + blk_queue_atomic_write_unit_max_sectors(disk->queue, + rounddown_pow_of_two(atomic_bs) >> SECTOR_SHIFT); + blk_queue_atomic_write_boundary_bytes(disk->queue, boundary); + + /* + * Linux filesystems assume writing a single physical block is + * an atomic operation. Hence limit the physical block size to the + * value of the Atomic Write Unit Power Fail parameter. + */ + blk_queue_physical_block_size(disk->queue, min(phys_bs, atomic_bs)); +} + static void nvme_update_disk_info(struct gendisk *disk, struct nvme_ns *ns, struct nvme_id_ns *id) { sector_t capacity = nvme_lba_to_sect(ns, le64_to_cpu(id->nsze)); - u32 bs = 1U << ns->lba_shift; - u32 atomic_bs, phys_bs, io_opt = 0; + u32 bs, phys_bs, io_opt = 0; /* * The block layer can't support LBA sizes larger than the page size @@ -1909,37 +1965,24 @@ static void nvme_update_disk_info(struct gendisk *disk, if (ns->lba_shift > PAGE_SHIFT || ns->lba_shift < SECTOR_SHIFT) { capacity = 0; bs = (1 << 9); + } else { + bs = 1U << ns->lba_shift; } blk_integrity_unregister(disk); - atomic_bs = phys_bs = bs; - if (id->nabo == 0) { - /* - * Bit 1 indicates whether NAWUPF is defined for this namespace - * and whether it should be used instead of AWUPF. If NAWUPF == - * 0 then AWUPF must be used instead. - */ - if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf) - atomic_bs = (1 + le16_to_cpu(id->nawupf)) * bs; - else - atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs; - } - if (id->nsfeat & NVME_NS_FEAT_IO_OPT) { /* NPWG = Namespace Preferred Write Granularity */ phys_bs = bs * (1 + le16_to_cpu(id->npwg)); /* NOWS = Namespace Optimal Write Size */ io_opt = bs * (1 + le16_to_cpu(id->nows)); + } else { + phys_bs = bs; } + nvme_update_atomic_write_disk_info(disk, ns, id, bs, phys_bs); + blk_queue_logical_block_size(disk->queue, bs); - /* - * Linux filesystems assume writing a single physical block is - * an atomic operation. Hence limit the physical block size to the - * value of the Atomic Write Unit Power Fail parameter. - */ - blk_queue_physical_block_size(disk->queue, min(phys_bs, atomic_bs)); blk_queue_io_min(disk->queue, phys_bs); blk_queue_io_opt(disk->queue, io_opt); From patchwork Tue Dec 12 11:08:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13488984 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="l0+HftME"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="jszRWtSA" Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 651AC198C; Tue, 12 Dec 2023 03:10:12 -0800 (PST) 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 3BC7hhll004079; Tue, 12 Dec 2023 11:09:51 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-11-20; bh=OAVy/9R0/bbRD70fkTvpQqSioGRhdig6Z34ouGNPKM0=; b=l0+HftMEWO+ZPaKnUsQ24HF8jz3yvRbkQQSk3lJXWDlIs6cU8QU1G1p0ww8VFGIJgSaM 9CJggRSsYiwWM499DS9OKvKbkU9fdX1RdeABrvIPNVbhX9jx5UnbmOWbbcRyNUae+R8+ x5Zmw3lBkjmyK3MvLIsER5ZFiL1PyURNcO6tYEDfXZ7MP3oc+gxP4R6M3rPNG0rHSuid CVO8Pq6LaIX3KPCCmtho/OmtAjnklTntpzvEUfWf/kBxDltxr/WhL9VsG0yAEyn0Ku9F eKA22EwJgg4iUfaU1FaVQAcw34Yl3FaNWQmk3yHUYa7m5SQr8dqskx0st9S4LLMHn2Oh bQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uvfuu5bjb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:51 +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 3BCAwj7J008234; Tue, 12 Dec 2023 11:09:50 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvep6cwvf-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Dec 2023 11:09:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IlFAxsUvCiMo7ejoblEMn6wjUYRfBpZm6a7ljZWIlUvUJ9VhV8X1bmn21RGuYJF8QT+/2r9qP0rViMKeAVguCmeZLHvFoDTNJ+kqc6zqMAmQ9DR8xbaLfo2eBw3EwVgIwcuEqoBh/jib3tFc4tlIiivl2x7nnT6gC3QUio+Zs9MZ0HvEsgizOo1PimfliK29VULt6Wk/xgIORog/iayQzsV6RXEarSkOhx+KgXjxkXIcFy5VBLc2/ATeBHogadRRtH1X4LM9yFFAK71Ls+1nDnaJAogmoK2B/vbzIGYdyygh8hb6xwmb27RgC43poG9b1Q3KTPxrPOmFGABlXvcnyA== 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=OAVy/9R0/bbRD70fkTvpQqSioGRhdig6Z34ouGNPKM0=; b=gCR9ofKvMjmYTA7CePEjQ3SojpdnnNRI5rnDqJOZoedsknhzAn1wmcMc9PD4dEuqMaB9WTnzbXctMnvZY8Iv8kBBnqe6ikJYyaAm11YFuKpswqNa/sUNc+fiyJ3qeVP3MwdPqdM+EWR+QJ62DgPbkgyy2bYehNy6/hB/g7HVXnoGpwvY1tNwkQ0nyYNCnpyweXXWE0Jsp4dQTnoW49R4UfjoTVJYEon9+q6LD06EAr8o/Xhnk10yOaf3+8RtRCTNhBZTs6gteIVH33QFHZdp8+MTPzBRSYuvixwFj9syvooJLxlF/BhVzxiEhmR65HUNqkzFLZ2ayVGq90FMnBBsog== 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=OAVy/9R0/bbRD70fkTvpQqSioGRhdig6Z34ouGNPKM0=; b=jszRWtSA2CHsxcAaHX4uKepgpjyOMkblwlwbKL6ZcrCbVfFEAM8o5GliIY+SgtMOdVBj+c+9aDK7M0IJNET+LVj1MIr3awNh/BfZ3cFG6hlMA0FgKSTfj9cIchbE5qF5NWpbBfYX30c+ZByHNVZBTOZKgXJxDiBKv3PcQB3E5VE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA1PR10MB6663.namprd10.prod.outlook.com (2603:10b6:806:2ba::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26; Tue, 12 Dec 2023 11:09:47 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::102a:f31:30c6:3187%4]) with mapi id 15.20.7068.033; Tue, 12 Dec 2023 11:09:47 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, jaswin@linux.ibm.com, bvanassche@acm.org, Alan Adamson , John Garry Subject: [PATCH v2 16/16] nvme: Ensure atomic writes will be executed atomically Date: Tue, 12 Dec 2023 11:08:44 +0000 Message-Id: <20231212110844.19698-17-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231212110844.19698-1-john.g.garry@oracle.com> References: <20231212110844.19698-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0241.namprd13.prod.outlook.com (2603:10b6:208:2ba::6) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SA1PR10MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 74db341f-d7ec-476b-b5ad-08dbfb02d9f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sjb0YosYf88Xey4WL0pMTkcjvbGuDxICSmHxJAbKuSgKBdAraHIkP2iXL4sSrak0F/LDphoe8wqboMhnD978m18lec2iirQQF7QbmEAf8FWo/+BYJygdjTApvuoVOmuC//NZZlOrVi46YEpKZqrK9Cca/VVvnrY8p3cmiqlJ3duOTKbSWHdDANuP1E2A20TA0AfF0Dg/Xr3mtEKV6+G6QZPv0EDnIVMMSsTJhyaGds+9e6B36w5ZaXak5Q1n2rkuOa9cZYpLBwwxDgtfka3g7msjTN04w858jbNEp8PxKhCmVhIhcceeg5REMywxCsuSW5beGBOm64OOqlYtwYTtIJRM0HmhESHZiU6Y5ttSAxI/E3SgUH/2IL++BU+YiOJ/Qza862augLl3S4RKgvRtFwtP3+zDnklPw8XHAuWAUK/a1oVI24d3+3TRABTL2N3M5/5g3y+1gWt/TuceQL/iodn5RO2dGMGtIpFrVmNjN6d1DJ90d/2shZ8TtiDD3Ox3EgTw8Wsz79PPszSAUf/q5MUSt3vrOG85ES9cPgGpf+whYXWKA7a31OJDooRYTJDk2uqBy3ufOHCK41mdZI4rJFCuq+AYuNjQcVaSugBefI8= 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:(13230031)(396003)(346002)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(26005)(83380400001)(6506007)(6512007)(2616005)(107886003)(1076003)(478600001)(5660300002)(4326008)(8936002)(8676002)(41300700001)(7416002)(2906002)(6486002)(6666004)(38100700002)(316002)(66476007)(66556008)(54906003)(66946007)(103116003)(86362001)(36756003)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DwQqT4bWfRNkCG1qsWiNFQ9jFajVPPxrEgQSOKuTEMNQ9rJQtRzgByiSWgYJwhVl4/1Up+RnICuXGH/gPrf6PCmTOhmmsr11RzZFzBfvR0BbNNdGk/9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0AIo3vkGw/DxPiWnmumQ1MOvr4UbdZMDplw0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74db341f-d7ec-476b-b5ad-08dbfb02d9f8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 11:09:46.9945 (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: iebAWjyjEq2gAM1FaJs8cSFDdVi0C9FRgXTZ36ZBXwTefzpzUsu2TKddqptmpEvYtOMHFJm8rvVQCHiS+taKZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6663 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-12_04,2023-12-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312120089 X-Proofpoint-GUID: DKW9AuX8fVUZuUVTnOkx6uiXE9aF-f7a X-Proofpoint-ORIG-GUID: DKW9AuX8fVUZuUVTnOkx6uiXE9aF-f7a From: Alan Adamson There is no dedicated NVMe atomic write command (which may error for a command which exceeds the controller atomic write limits). As an insurance policy against the block layer sending requests which cannot be executed atomically, add a check in the queue path. Signed-off-by: Alan Adamson Signed-off-by: John Garry --- drivers/nvme/host/core.c | 23 +++++++++++++++++++++++ drivers/nvme/host/nvme.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index fd4f09f9dbe8..6b89ee7e9921 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -905,6 +905,26 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, if (req->cmd_flags & REQ_RAHEAD) dsmgmt |= NVME_RW_DSM_FREQ_PREFETCH; + /* + * Ensure that nothing has been sent which cannot be executed + * atomically. + */ + if (req->cmd_flags & REQ_ATOMIC) { + if (blk_rq_bytes(req) > ns->atomic_max) + return BLK_STS_IOERR; + + if (ns->atomic_boundary) { + u32 boundary = ns->atomic_boundary >> ns->lba_shift; + u32 imask = ~(boundary - 1); + u32 lba = nvme_sect_to_lba(ns, blk_rq_pos(req)); + u32 end = lba + (blk_rq_bytes(req) >> ns->lba_shift) + - 1; + + if ((lba & imask) != (end & imask)) + return BLK_STS_IOERR; + } + } + cmnd->rw.opcode = op; cmnd->rw.flags = 0; cmnd->rw.nsid = cpu_to_le32(ns->head->ns_id); @@ -1937,6 +1957,9 @@ static void nvme_update_atomic_write_disk_info(struct gendisk *disk, id->nabo); } + ns->atomic_max = atomic_bs; + ns->atomic_boundary = boundary; + blk_queue_atomic_write_max_bytes(disk->queue, atomic_bs); blk_queue_atomic_write_unit_min_sectors(disk->queue, bs >> SECTOR_SHIFT); blk_queue_atomic_write_unit_max_sectors(disk->queue, diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index e7411dac00f7..5a3d76bc816f 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -520,6 +520,8 @@ struct nvme_ns { struct nvme_fault_inject fault_inject; + u32 atomic_max; + u32 atomic_boundary; }; /* NVMe ns supports metadata actions by the controller (generate/strip) */