From patchwork Wed Jan 31 20:52:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13539945 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D14B538DDB for ; Wed, 31 Jan 2024 20:53:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734388; cv=none; b=M4WjDEpQDdVdd3MfN2br8+/hWpa1Zh3BLJanytwbu2JHt3uSd76VE4qh8HumTubSsnNzC0n9ddmob7NAsuXs+vMCCCRXMNztKBuqptNOEJRE52EZgPEuuBk6M618wiFzg8R3kh3NXqKCZKuW4D7XOavhc+Y/xZh0PpSzBha2jWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734388; c=relaxed/simple; bh=S/P24wcTvrFOg4SsS4CeD+d5rBmERutoXicKIgS4CC4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O7jXPigZTQRaGwXvLLzsLvXViePfcK8eD5JotWQ9Wdozc704xPjvpEvNA7u25HwuRWSn0K7gbYp3k09G0HSV+QXXQ5zd6MwY0gmU5syehM+hCwQz+QDxpwQFrvy/JRFa9Owj1ZlaYWuBcNtWfmwKgIrISujeyYcMwqb8F7QKShs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5d81b08d6f2so241377a12.0 for ; Wed, 31 Jan 2024 12:53:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706734386; x=1707339186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4NnkzmgwtRA87qL5gc3Zv1AqjSPa8netVCv6+D4Bmn0=; b=jtaUOjcrC8W9aHzsCLR/XYPBjB3ygmm9ibH2mz+o5b/1QDyz6o+ZEwj/IgyDHwr9HY L6TFNX4Nnzw53Bqza+gy0ivf++V8fZYY52+svD4SRz090cXTvncWcqGKkzAP1ec6l+LB Vw/TIuSFqtHusMEUrJfWN+reV4NXZ//TZbV18QCXndI6LJBnwsLqitoDC78whImahcEf xChIzMq3baqgTPykLaynP+6HvYuTDMxSAyBNrHg4KBJLh3hljFNfzJ87m0VEuPNH0AXI XNgQE/9oCFyS40f8re3f7hp3bwb6DHT8VDfyag+TWxhPpCcJvyzQ1dBRoXPUzV6qSRnO eMUQ== X-Gm-Message-State: AOJu0YzWYbeOwrnmkKHphQVMMvYY6MrflbLdKCDMh61WL1uwtzPTaS2G ZxQr0PNAq4Xr0RQ6pI2gxwUbdMcwDjpjgQI7iVGGUA+qgfcYVsv9 X-Google-Smtp-Source: AGHT+IE+UJJ0kLBHoXRlZXYYLitM5b9XaYCGpNRygRHhTLYzYjTQ+7VsN4XoL49bSlEV820gENvliA== X-Received: by 2002:a05:6a20:8b15:b0:19c:5037:9d8c with SMTP id l21-20020a056a208b1500b0019c50379d8cmr172728pzh.14.1706734385929; Wed, 31 Jan 2024 12:53:05 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:1d95:ca94:1cbe:1409]) by smtp.gmail.com with ESMTPSA id g3-20020a17090ace8300b00295fb7e7b87sm855977pju.27.2024.01.31.12.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 12:53:05 -0800 (PST) From: Bart Van Assche To: Christian Brauner , Alexander Viro Cc: linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig , "Martin K . Petersen" , Bart Van Assche , Kanchan Joshi , Jeff Layton , Chuck Lever , Stephen Rothwell Subject: [PATCH 1/6] fs: Fix rw_hint validation Date: Wed, 31 Jan 2024 12:52:32 -0800 Message-ID: <20240131205237.3540210-2-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240131205237.3540210-1-bvanassche@acm.org> References: <20240131205237.3540210-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reject values that are valid rw_hints after truncation but not before truncation by passing an untruncated value to rw_hint_valid(). Reviewed-by: Christoph Hellwig Reviewed-by: Kanchan Joshi Cc: Jeff Layton Cc: Chuck Lever Cc: Jens Axboe Cc: Stephen Rothwell Fixes: 5657cb0797c4 ("fs/fcntl: use copy_to/from_user() for u64 types") Signed-off-by: Bart Van Assche --- fs/fcntl.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fs/fcntl.c b/fs/fcntl.c index c80a6acad742..3ff707bf2743 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -268,7 +268,7 @@ static int f_getowner_uids(struct file *filp, unsigned long arg) } #endif -static bool rw_hint_valid(enum rw_hint hint) +static bool rw_hint_valid(u64 hint) { switch (hint) { case RWH_WRITE_LIFE_NOT_SET: @@ -288,19 +288,17 @@ static long fcntl_rw_hint(struct file *file, unsigned int cmd, { struct inode *inode = file_inode(file); u64 __user *argp = (u64 __user *)arg; - enum rw_hint hint; - u64 h; + u64 hint; switch (cmd) { case F_GET_RW_HINT: - h = inode->i_write_hint; - if (copy_to_user(argp, &h, sizeof(*argp))) + hint = inode->i_write_hint; + if (copy_to_user(argp, &hint, sizeof(*argp))) return -EFAULT; return 0; case F_SET_RW_HINT: - if (copy_from_user(&h, argp, sizeof(h))) + if (copy_from_user(&hint, argp, sizeof(hint))) return -EFAULT; - hint = (enum rw_hint) h; if (!rw_hint_valid(hint)) return -EINVAL; From patchwork Wed Jan 31 20:52:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13539946 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78B6531A61 for ; Wed, 31 Jan 2024 20:53:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734389; cv=none; b=lXqvYLfnDE3ZLheiM/qmxpVWOEorGkO0ulVNlxN4rQB3Dy1Nz/HlYwz1RHAlwv6BBrauLpzaR2yPWo5GgHAYETtiNlN58rQN2DvRFLBAehT3eQiavScbJ1DIxiWWeEI1+FVzt2ByE+yjYsh05jYZZX6DAJjNZ5kRJPq4y2GeP3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734389; c=relaxed/simple; bh=PeigcjR0fJHqnWYzUNDhF0SumumPwInd9lmx/bLcwVY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d8WOktnvQt0kFfofQejlUkjFmQDxzKVBU6NLMNRkwagfFRl5X8GyH4j7JQouQyv64/tu1wveWQbeU/eTjRdQPyH0chWMCc3AJ2wsJ6VD2WoOQXSiRtk5uWZUo1vS5XdK3a/DRU2wCIkrTO+beE5mTgcAlTIfN9jbafQb1YC0nKs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5c66b093b86so1127469a12.0 for ; Wed, 31 Jan 2024 12:53:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706734388; x=1707339188; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jkb7BdFD0GARRMQmHbkGbl9/+4lufBLaMcZRoVBPKBQ=; b=CKSfIooTbLCfMaJ4UZ68msNTDZ0BSaKNRblBCl0xlHZIPqzhtZWAn6D18Fz4MYQA2E YH6IU8xsmgv1A48VG2euFPLEQXUppsaSMukozJPF4m1y4DRP7GTz/QBt78KULQaODhNp /VYeRb/hCpFQQeNx5vJ40DQ+UiGGv3GzOUWZXiRMHlLRtYre6b4QkQ9wcAAufOaQd6w0 nfMShWGcVFMEuig5hVzZ7mXERFkr9SOonj1zdkA5nCKjDIsCQUl8HrvHW6m8Wd+DijEB Sih7mMeqlFnnq5aN1RUDUCBsx9nxr/9ILdfhxGTMNMOo3TE43UQ7CfoG/kUuzEETCpQZ 888w== X-Gm-Message-State: AOJu0YzIMY2Db+MSq6/nCOUdjjZyxJ647+ksPiy7IhBY1AVmq8YGjBu7 CiN1BC0VLR2UhrEJjxUQuOFPZKS9akzFuVoWtlxY4+ML/1vyhjQX6/+a12hF X-Google-Smtp-Source: AGHT+IEvycIMxFLgh2e0qulchHE4MjIi5PO0cDi8Mc+9BawiFu34LyfBkXPu69gthpcOgksw+YQegQ== X-Received: by 2002:a17:90a:c208:b0:296:67b:1894 with SMTP id e8-20020a17090ac20800b00296067b1894mr791729pjt.0.1706734387653; Wed, 31 Jan 2024 12:53:07 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:1d95:ca94:1cbe:1409]) by smtp.gmail.com with ESMTPSA id g3-20020a17090ace8300b00295fb7e7b87sm855977pju.27.2024.01.31.12.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 12:53:06 -0800 (PST) From: Bart Van Assche To: Christian Brauner , Alexander Viro Cc: linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig , "Martin K . Petersen" , Bart Van Assche , Johannes Thumshirn Subject: [PATCH 2/6] fs: Verify write lifetime constants at compile time Date: Wed, 31 Jan 2024 12:52:33 -0800 Message-ID: <20240131205237.3540210-3-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240131205237.3540210-1-bvanassche@acm.org> References: <20240131205237.3540210-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The code in fs/fcntl.c converts RWH_* constants to and from WRITE_LIFE_* constants using casts. Verify at compile time that these casts will yield the intended effect. Reviewed-by: Christoph Hellwig Suggested-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Signed-off-by: Bart Van Assche --- fs/fcntl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/fcntl.c b/fs/fcntl.c index 3ff707bf2743..f3bc4662455f 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -270,6 +270,13 @@ static int f_getowner_uids(struct file *filp, unsigned long arg) static bool rw_hint_valid(u64 hint) { + BUILD_BUG_ON(WRITE_LIFE_NOT_SET != RWH_WRITE_LIFE_NOT_SET); + BUILD_BUG_ON(WRITE_LIFE_NONE != RWH_WRITE_LIFE_NONE); + BUILD_BUG_ON(WRITE_LIFE_SHORT != RWH_WRITE_LIFE_SHORT); + BUILD_BUG_ON(WRITE_LIFE_MEDIUM != RWH_WRITE_LIFE_MEDIUM); + BUILD_BUG_ON(WRITE_LIFE_LONG != RWH_WRITE_LIFE_LONG); + BUILD_BUG_ON(WRITE_LIFE_EXTREME != RWH_WRITE_LIFE_EXTREME); + switch (hint) { case RWH_WRITE_LIFE_NOT_SET: case RWH_WRITE_LIFE_NONE: From patchwork Wed Jan 31 20:52:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13539947 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA73238DDB for ; Wed, 31 Jan 2024 20:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734391; cv=none; b=tEGOOxSqnW5MOAxGbvY9ynBLCdYwcqe6H7jTRFf4Y+J7s+NCNGJmnxw3tGe0NoNi0QXNp3JWGNjZdV1NZZgXNpJcMIAmbkCBVpCaXBdvKBs7oYXD9mMASunGXx8Zhftb44SIidLUefees2w3v2qmyaHFUnibA1/sV4vJuQINglo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734391; c=relaxed/simple; bh=cy2v+uThw8Y/HPBCNLskDXnVfR9wp+PMesjqdm7xfMg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kGu64zqQpj//Oao8yMiVyMiXblHgeNiq5Qb0vAPjPr3W25ZBGqL2GMqSgzPF53fvWyBBohpaI9paXEXZIdKK9rMHSjolchcLQMYdhYwsFVW4EacH/Cs5m8pL/4WsUhgltGQ5y/VDBLpXDo2FYfpnWZXLBtXU0ur1RDv7w0o9n4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2906bcae4feso111394a91.3 for ; Wed, 31 Jan 2024 12:53:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706734389; x=1707339189; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H+Bs4pKxgGTdzOZDEst+uV1iftPjS+z9tfcTtKkkLTw=; b=pVUKG9DKJ9MuDEZ4jEYKBq+IeLy6Yuqu+rO1sVLq1QglikWnfwDkPtRxtksFRBrwOn PtzI2lB2KwocYssD7P4jxf1M+kxcEQadSH3zLp40F6hM5tMA7kvnTd/WWSSHmdNu8rYo KueToFrk05f1MUWVmJASHw9IxLZv6SiZmcbc1G1QHBYrmhzwPfLBw9leOE7jyawOZemn HstXtVdj4fWriqleX7Q0rhMq5owxXqyycSaox1AskEYrtjyl0bPI/W2E7+xICMt+DCpf Awj//8+51WiycT6QMX9+4O4ev8L5wWO4pK5ZowR0yGv2veddZFllV0a54s/dLazrfxjV l6nw== X-Gm-Message-State: AOJu0YwV8pSvvtFKN05HweNdTulmudaeCVe94Qe22PhWqrsgpRpbRDBA 0LXaYkfCclYOBJ3lQiEsAdIXf5Gb595cssIfxejzNyC+2lYyPGzjP3nl9Xb/ X-Google-Smtp-Source: AGHT+IGvz4l8RQ/ic/j4ydN9LbepFI88Xy7ZivcBOPEGak97rysriBxp07XHremho1ALJ55p20p2zw== X-Received: by 2002:a17:90b:364a:b0:295:c64c:fe53 with SMTP id nh10-20020a17090b364a00b00295c64cfe53mr2841696pjb.16.1706734388926; Wed, 31 Jan 2024 12:53:08 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:1d95:ca94:1cbe:1409]) by smtp.gmail.com with ESMTPSA id g3-20020a17090ace8300b00295fb7e7b87sm855977pju.27.2024.01.31.12.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 12:53:08 -0800 (PST) From: Bart Van Assche To: Christian Brauner , Alexander Viro Cc: linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig , "Martin K . Petersen" , Bart Van Assche , Kanchan Joshi , Jeff Layton , Chuck Lever , Stephen Rothwell Subject: [PATCH 3/6] fs: Split fcntl_rw_hint() Date: Wed, 31 Jan 2024 12:52:34 -0800 Message-ID: <20240131205237.3540210-4-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240131205237.3540210-1-bvanassche@acm.org> References: <20240131205237.3540210-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Split fcntl_rw_hint() such that there is one helper function per fcntl. No functionality is changed by this patch. Reviewed-by: Christoph Hellwig Suggested-by: Christoph Hellwig Reviewed-by: Kanchan Joshi Cc: Jeff Layton Cc: Chuck Lever Cc: Jens Axboe Cc: Stephen Rothwell Signed-off-by: Bart Van Assche --- fs/fcntl.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/fs/fcntl.c b/fs/fcntl.c index f3bc4662455f..5fa2d95114bf 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -290,32 +290,35 @@ static bool rw_hint_valid(u64 hint) } } -static long fcntl_rw_hint(struct file *file, unsigned int cmd, - unsigned long arg) +static long fcntl_get_rw_hint(struct file *file, unsigned int cmd, + unsigned long arg) { struct inode *inode = file_inode(file); u64 __user *argp = (u64 __user *)arg; - u64 hint; + u64 hint = inode->i_write_hint; - switch (cmd) { - case F_GET_RW_HINT: - hint = inode->i_write_hint; - if (copy_to_user(argp, &hint, sizeof(*argp))) - return -EFAULT; - return 0; - case F_SET_RW_HINT: - if (copy_from_user(&hint, argp, sizeof(hint))) - return -EFAULT; - if (!rw_hint_valid(hint)) - return -EINVAL; + if (copy_to_user(argp, &hint, sizeof(*argp))) + return -EFAULT; + return 0; +} - inode_lock(inode); - inode->i_write_hint = hint; - inode_unlock(inode); - return 0; - default: +static long fcntl_set_rw_hint(struct file *file, unsigned int cmd, + unsigned long arg) +{ + struct inode *inode = file_inode(file); + u64 __user *argp = (u64 __user *)arg; + u64 hint; + + if (copy_from_user(&hint, argp, sizeof(hint))) + return -EFAULT; + if (!rw_hint_valid(hint)) return -EINVAL; - } + + inode_lock(inode); + inode->i_write_hint = hint; + inode_unlock(inode); + + return 0; } static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, @@ -421,8 +424,10 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, err = memfd_fcntl(filp, cmd, argi); break; case F_GET_RW_HINT: + err = fcntl_get_rw_hint(filp, cmd, arg); + break; case F_SET_RW_HINT: - err = fcntl_rw_hint(filp, cmd, arg); + err = fcntl_set_rw_hint(filp, cmd, arg); break; default: break; From patchwork Wed Jan 31 20:52:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13539948 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82D8938FBC for ; Wed, 31 Jan 2024 20:53:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734393; cv=none; b=B4nlBSkl/ifTFtReBPOZ0EHy50BShwiMm5RZwju/EMoeW2QcqD6eGpH1uEAbs/nHYya6pn+/raYGK5szS9546lHo+pM3bw5PsxOmwtqY7/E+uZpC/wxNqyJ8cXCbvTSkK2dVvvPX4v+4YNvqA8W6anlzLZlozIf9nD4eFOgjJF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734393; c=relaxed/simple; bh=vPA84qeWmp0cURAGPENkY/uMQdtl/36qkCAmo3eJr48=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eGGCXPykm8EGP8fJmsQcsgpCvTsX/YMfx9wX3uraEIRVBqnzrQU8vq9rLNqnOwkZEfUE5m94S9LFf/H+aNG6TdQ9uEa6RlkX4Icku8KQXl21xrbWIO+GJYlcG5l7z4xNP+oa/JFu0ScTjuo5FEpD2gUI0vKn377/dBVvJGAq1LA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3bd72353d9fso168836b6e.3 for ; Wed, 31 Jan 2024 12:53:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706734390; x=1707339190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MO1tFiQajMsYAq4KiTOhGu2FSOc6j8yOraYVWH9sMws=; b=uCCx6CN0Mb09lT5aPlvDnRvrb+onrOGDkGH0+aCy6ymD6g748VpuqtDkE8iJCLqiZJ FK4MvkRuVYqBiZSbA2TElou8j2RvBm47yVyHc6YTp9TnTCc1ixrs/FJ8ynFvQBFbEe4q tQG+7bfKVxDfBXklGH4cx1AruTixrEkx05CmZYKjy1rT0Amujy1PM+OAMnGYyb+K6rrB UVsIguPQAIakjQU4Jhycpc05BBxTCGBtxmRzZWm7Na2fbDzxO1H5DB9T2we3jwMyNIN0 ltLxMW/xatMS972rD63g2JhmpQ9zMGvO5uhIxKtwenniC0GmLILcff0SP4bKKo1Eazo5 03cA== X-Gm-Message-State: AOJu0YymVcXu2WdYR2SanJbUWNIpRWBqhuIOYw21dvY9m1jf8DuMIRbo 0CTmdZ6QRz6DIQYQi4i4p84y1mBIRxhuO7H212Tf40N4g6YFoIdB X-Google-Smtp-Source: AGHT+IEbdvgI/zqfU0PZUlq8QPFqsu7eZX+yJCAxgMhfEMuBrf2JBINCHGoRqH51pP0jeZfmAlAJCQ== X-Received: by 2002:a05:6358:7f0a:b0:175:67e3:f9be with SMTP id p10-20020a0563587f0a00b0017567e3f9bemr1880461rwn.31.1706734390351; Wed, 31 Jan 2024 12:53:10 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:1d95:ca94:1cbe:1409]) by smtp.gmail.com with ESMTPSA id g3-20020a17090ace8300b00295fb7e7b87sm855977pju.27.2024.01.31.12.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 12:53:09 -0800 (PST) From: Bart Van Assche To: Christian Brauner , Alexander Viro Cc: linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig , "Martin K . Petersen" , Bart Van Assche , Chao Yu , Jan Kara Subject: [PATCH 4/6] fs: Move enum rw_hint into a new header file Date: Wed, 31 Jan 2024 12:52:35 -0800 Message-ID: <20240131205237.3540210-5-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240131205237.3540210-1-bvanassche@acm.org> References: <20240131205237.3540210-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move enum rw_hint into a new header file to prepare for using this data type in the block layer. Add the attribute __packed to reduce the space occupied by instances of this data type from four bytes to one byte. Change the data type of i_write_hint from u8 into enum rw_hint. Reviewed-by: Christoph Hellwig Acked-by: Chao Yu # for the F2FS part Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Christoph Hellwig Signed-off-by: Bart Van Assche --- fs/f2fs/f2fs.h | 1 + fs/fcntl.c | 1 + fs/inode.c | 1 + include/linux/fs.h | 16 ++-------------- include/linux/rw_hint.h | 24 ++++++++++++++++++++++++ 5 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 include/linux/rw_hint.h diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index dda0aed95464..4a4e60cdac4e 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include diff --git a/fs/fcntl.c b/fs/fcntl.c index 5fa2d95114bf..fc73c5fae43c 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include diff --git a/fs/inode.c b/fs/inode.c index 6d0d54230363..585d79d40158 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "internal.h" diff --git a/include/linux/fs.h b/include/linux/fs.h index ebce4763b4bb..f3ba0895bcd7 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -309,19 +310,6 @@ struct address_space; struct writeback_control; struct readahead_control; -/* - * Write life time hint values. - * Stored in struct inode as u8. - */ -enum rw_hint { - WRITE_LIFE_NOT_SET = 0, - WRITE_LIFE_NONE = RWH_WRITE_LIFE_NONE, - WRITE_LIFE_SHORT = RWH_WRITE_LIFE_SHORT, - WRITE_LIFE_MEDIUM = RWH_WRITE_LIFE_MEDIUM, - WRITE_LIFE_LONG = RWH_WRITE_LIFE_LONG, - WRITE_LIFE_EXTREME = RWH_WRITE_LIFE_EXTREME, -}; - /* Match RWF_* bits to IOCB bits */ #define IOCB_HIPRI (__force int) RWF_HIPRI #define IOCB_DSYNC (__force int) RWF_DSYNC @@ -677,7 +665,7 @@ struct inode { spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ unsigned short i_bytes; u8 i_blkbits; - u8 i_write_hint; + enum rw_hint i_write_hint; blkcnt_t i_blocks; #ifdef __NEED_I_SIZE_ORDERED diff --git a/include/linux/rw_hint.h b/include/linux/rw_hint.h new file mode 100644 index 000000000000..309ca72f2dfb --- /dev/null +++ b/include/linux/rw_hint.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_RW_HINT_H +#define _LINUX_RW_HINT_H + +#include +#include +#include + +/* Block storage write lifetime hint values. */ +enum rw_hint { + WRITE_LIFE_NOT_SET = RWH_WRITE_LIFE_NOT_SET, + WRITE_LIFE_NONE = RWH_WRITE_LIFE_NONE, + WRITE_LIFE_SHORT = RWH_WRITE_LIFE_SHORT, + WRITE_LIFE_MEDIUM = RWH_WRITE_LIFE_MEDIUM, + WRITE_LIFE_LONG = RWH_WRITE_LIFE_LONG, + WRITE_LIFE_EXTREME = RWH_WRITE_LIFE_EXTREME, +} __packed; + +/* Sparse ignores __packed annotations on enums, hence the #ifndef below. */ +#ifndef __CHECKER__ +static_assert(sizeof(enum rw_hint) == 1); +#endif + +#endif /* _LINUX_RW_HINT_H */ From patchwork Wed Jan 31 20:52:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13539949 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58A8638DDB for ; Wed, 31 Jan 2024 20:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734393; cv=none; b=OzFzxpxousJNMnO53p9QtCN7HbQVjXThPUCe297kVi9ESJGuF5/NR1MXZbAvrTAe5RaiMx/m5f3e+wypU2NEcOi9kSwXId/0vNt+H5giSpAQooE2rXzYxs9ELxVrveuutvaykg4Jvb0VfCLBCmzN6K5R4rOnPa9NXcXjX9Xwobk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734393; c=relaxed/simple; bh=a9xeRjxhwBRpDypO6xyQ/fsqW9JHBu84hagwRacOxZs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pHJBlVwT1m2jR0YzG5jugGxjGLQ/sxx7skpSre8/YCX/j+Pz5gU5RYXnAabUQEBS/QAUuxL0BHX+hRargzPRiFrDIaIxLagdrLKcOCAitfT1OcdXCQL51KtmvqkkQ6XjSd2CEfPm9noTMuG/0efXHnQDZ7AUgDyG+BCG/cA2YUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-5ca29c131ebso219247a12.0 for ; Wed, 31 Jan 2024 12:53:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706734392; x=1707339192; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vRbR4tcw6ZmMdKHBUsp7le5LvEzpVmQE81VD12TX0W4=; b=PRW5S//r8m+xFKT0LNs/MySEyOOj1poNdpzqkQQofhpQyQ/dvnooKs2O9DrlkVG9GJ R2mZ7lbMS7otsSVgfPtzQgPSyCaGRKWTAAMxZhKSnBgj8E5eOWw+9OZvztcNNu3Smk4X QvIS2KECu8PZMDAQiCkauU6X1miE41xW+L71AJ1t9ghkTYCdf7AIAwjGVjltTDsxiiVh lZuBLt2Y69hUbpY3iqpnyni2O9PuBke6NqJAl8E09Liw8QtBKgMNRoq3tlS/hfHvp017 +qVqCL+IsmbuN1/gylLVLxT5PhSWLZT9dHEfAFySKwkkKPB2GHHIjH4cn0e4Ov2kHeml 9iCw== X-Gm-Message-State: AOJu0Yyxj0oqhX/sHjJz5J7ebt8GVM1mDEdVz2cr5ej8eTIZ373NF368 z5wk07Kyzl7URbJTuLWMe74d6xrGuRFpDVyp6bV/IHe0WF2zRGKm X-Google-Smtp-Source: AGHT+IF5oFO5T4nJrK6PKziqvstfvoiCOlBsZDG1xx8iaqtYVG5qJ4LyL8So94WAi2GIDJZIvTmQCA== X-Received: by 2002:a17:90a:b385:b0:295:ec45:9cd8 with SMTP id e5-20020a17090ab38500b00295ec459cd8mr2422981pjr.13.1706734391508; Wed, 31 Jan 2024 12:53:11 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:1d95:ca94:1cbe:1409]) by smtp.gmail.com with ESMTPSA id g3-20020a17090ace8300b00295fb7e7b87sm855977pju.27.2024.01.31.12.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 12:53:11 -0800 (PST) From: Bart Van Assche To: Christian Brauner , Alexander Viro Cc: linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig , "Martin K . Petersen" , Bart Van Assche , Kanchan Joshi , Jeff Layton , Chuck Lever Subject: [PATCH 5/6] fs: Propagate write hints to the struct block_device inode Date: Wed, 31 Jan 2024 12:52:36 -0800 Message-ID: <20240131205237.3540210-6-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240131205237.3540210-1-bvanassche@acm.org> References: <20240131205237.3540210-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Write hints applied with F_SET_RW_HINT on a block device affect the block device inode only. Propagate these hints to the inode associated with struct block_device because that is the inode used when writing back dirty pages. Reviewed-by: Kanchan Joshi Cc: Alexander Viro Cc: Christian Brauner Cc: Jens Axboe Cc: Christoph Hellwig Cc: Jeff Layton Cc: Chuck Lever Signed-off-by: Bart Van Assche --- fs/fcntl.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/fcntl.c b/fs/fcntl.c index fc73c5fae43c..cfb52c3a4577 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -319,6 +319,17 @@ static long fcntl_set_rw_hint(struct file *file, unsigned int cmd, inode->i_write_hint = hint; inode_unlock(inode); + /* + * file->f_mapping->host may differ from inode. As an example, + * blkdev_open() modifies file->f_mapping. + */ + if (file->f_mapping->host != inode) { + inode = file->f_mapping->host; + inode_lock(inode); + inode->i_write_hint = hint; + inode_unlock(inode); + } + return 0; } From patchwork Wed Jan 31 20:52:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13539950 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B032B38FBC for ; Wed, 31 Jan 2024 20:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734395; cv=none; b=A/JlkDZt+thK37rimkO/36XSGNIvm5Lw4uR90QvP3nIhwg8Mf9Pbf3oneBRII0ecifQrHbYwrL9qyVfZU8AXcrKe5pdrqiKvWfApWIGJ7i0q9H5ziQkOhDsT4SMXlH49zErTgWo/ZA9uPWoIeC9r6L5XioPTPYkcT9aKhO9jc+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706734395; c=relaxed/simple; bh=a+okDlWx9/qPLdBcy7htYvkIivsaWX4NYZq96zRjvIw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YDKKw4Ymhrl4soNz9CST7c3h2inYCeTUr5Vf0Qa1jcqg8CRepC7wr3FuBXHwR6I/pZN5wJ1Jzfv4RcxKHu0ywF4hlz/NuZPAOHceYh9bySBWYfLc/ALBh0EtjzQ4kG0S8ySIG4yw7iwYxWc5b0Qbce13EGx8M/o+fipDQuAAP4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-295f95ac74aso118776a91.1 for ; Wed, 31 Jan 2024 12:53:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706734393; x=1707339193; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZQtRy8aH4+NZcdv1DbXtSr6CX/Icu9Trjb7pmXD4VBs=; b=rci9jp/YTqYPtrB8gCr0j6umeUMvQ3S4mGhdgzeqTxkUxf6EGXXwmxE9xmQPel/16e kctwg1yHDWQkuRLBxJ008b7fiJKsJd7jxzpdB1ry6xSBE/8np8o2SYlyOuzvMAK7/tLo /Rnyo8Ivhpt6Abk5BithfWrU9Q/3zbWfJQ2DBzplO8G+YHnLbzWkWqWHmmDa0FOLBc7k fDfDMCo9kPXa9HHZ3J2aqRqXKjoCTg/ziRbP2Ner49k6qxXwPRpHfn1/IL4vCVDMFqyK 6EW/Rhbt5oSEGcu3crnW84qiAna8/1JKU1BDu/IEicb3NW6dreEYLaWSxa8Bs546zG9C dM2g== X-Gm-Message-State: AOJu0YyeRjYIgj0KYdttQiSYwy5X+UMqv/AbjePbffPiqeVA/tJi9XR1 GH02ihja4GfdoUzZjxp+ff7RBvvNVexs9Xen6d+YnwcVVtdn1hr7 X-Google-Smtp-Source: AGHT+IFRBdJ3Qo7SWYftLxaNase8/u8qHhrlRksrACE/t4Kaedxp1+yLQaTYcLVKecLVDmKFlPoGug== X-Received: by 2002:a17:90a:ce97:b0:295:aa97:d6ad with SMTP id g23-20020a17090ace9700b00295aa97d6admr2828956pju.39.1706734392847; Wed, 31 Jan 2024 12:53:12 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:1d95:ca94:1cbe:1409]) by smtp.gmail.com with ESMTPSA id g3-20020a17090ace8300b00295fb7e7b87sm855977pju.27.2024.01.31.12.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 12:53:12 -0800 (PST) From: Bart Van Assche To: Christian Brauner , Alexander Viro Cc: linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig , "Martin K . Petersen" , Bart Van Assche , Kanchan Joshi Subject: [PATCH 6/6] block, fs: Restore the per-bio/request data lifetime fields Date: Wed, 31 Jan 2024 12:52:37 -0800 Message-ID: <20240131205237.3540210-7-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240131205237.3540210-1-bvanassche@acm.org> References: <20240131205237.3540210-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Restore support for passing data lifetime information from filesystems to block drivers. This patch reverts commit b179c98f7697 ("block: Remove request.write_hint") and commit c75e707fe1aa ("block: remove the per-bio/request write hint"). This patch does not modify the size of struct bio because the new bi_write_hint member fills a hole in struct bio. pahole reports the following for struct bio on an x86_64 system with this patch applied: /* size: 112, cachelines: 2, members: 20 */ /* sum members: 110, holes: 1, sum holes: 2 */ /* last cacheline: 48 bytes */ Reviewed-by: Kanchan Joshi Cc: Jens Axboe Cc: Christoph Hellwig Signed-off-by: Bart Van Assche --- block/bio.c | 2 ++ block/blk-crypto-fallback.c | 1 + block/blk-merge.c | 8 ++++++++ block/blk-mq.c | 2 ++ block/bounce.c | 1 + block/fops.c | 3 +++ fs/buffer.c | 12 ++++++++---- fs/direct-io.c | 2 ++ fs/iomap/buffered-io.c | 2 ++ fs/iomap/direct-io.c | 1 + fs/mpage.c | 1 + include/linux/blk-mq.h | 2 ++ include/linux/blk_types.h | 2 ++ 13 files changed, 35 insertions(+), 4 deletions(-) diff --git a/block/bio.c b/block/bio.c index b9642a41f286..c9223e9d31da 100644 --- a/block/bio.c +++ b/block/bio.c @@ -251,6 +251,7 @@ void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table, bio->bi_opf = opf; bio->bi_flags = 0; bio->bi_ioprio = 0; + bio->bi_write_hint = 0; bio->bi_status = 0; bio->bi_iter.bi_sector = 0; bio->bi_iter.bi_size = 0; @@ -813,6 +814,7 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp) { bio_set_flag(bio, BIO_CLONED); bio->bi_ioprio = bio_src->bi_ioprio; + bio->bi_write_hint = bio_src->bi_write_hint; bio->bi_iter = bio_src->bi_iter; if (bio->bi_bdev) { diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c index e6468eab2681..b1e7415f8439 100644 --- a/block/blk-crypto-fallback.c +++ b/block/blk-crypto-fallback.c @@ -172,6 +172,7 @@ static struct bio *blk_crypto_fallback_clone_bio(struct bio *bio_src) if (bio_flagged(bio_src, BIO_REMAPPED)) bio_set_flag(bio, BIO_REMAPPED); bio->bi_ioprio = bio_src->bi_ioprio; + bio->bi_write_hint = bio_src->bi_write_hint; bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; diff --git a/block/blk-merge.c b/block/blk-merge.c index 2d470cf2173e..2a06fd33039d 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -810,6 +810,10 @@ static struct request *attempt_merge(struct request_queue *q, if (rq_data_dir(req) != rq_data_dir(next)) return NULL; + /* Don't merge requests with different write hints. */ + if (req->write_hint != next->write_hint) + return NULL; + if (req->ioprio != next->ioprio) return NULL; @@ -937,6 +941,10 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) if (!bio_crypt_rq_ctx_compatible(rq, bio)) return false; + /* Don't merge requests with different write hints. */ + if (rq->write_hint != bio->bi_write_hint) + return false; + if (rq->ioprio != bio_prio(bio)) return false; diff --git a/block/blk-mq.c b/block/blk-mq.c index aa87fcfda1ec..34ceb15d2ea4 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2585,6 +2585,7 @@ static void blk_mq_bio_to_request(struct request *rq, struct bio *bio, rq->cmd_flags |= REQ_FAILFAST_MASK; rq->__sector = bio->bi_iter.bi_sector; + rq->write_hint = bio->bi_write_hint; blk_rq_bio_prep(rq, bio, nr_segs); /* This can't fail, since GFP_NOIO includes __GFP_DIRECT_RECLAIM. */ @@ -3185,6 +3186,7 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src, } rq->nr_phys_segments = rq_src->nr_phys_segments; rq->ioprio = rq_src->ioprio; + rq->write_hint = rq_src->write_hint; if (rq->bio && blk_crypto_rq_bio_prep(rq, rq->bio, gfp_mask) < 0) goto free_and_out; diff --git a/block/bounce.c b/block/bounce.c index 7cfcb242f9a1..d6a5219f29dd 100644 --- a/block/bounce.c +++ b/block/bounce.c @@ -169,6 +169,7 @@ static struct bio *bounce_clone_bio(struct bio *bio_src) if (bio_flagged(bio_src, BIO_REMAPPED)) bio_set_flag(bio, BIO_REMAPPED); bio->bi_ioprio = bio_src->bi_ioprio; + bio->bi_write_hint = bio_src->bi_write_hint; bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; diff --git a/block/fops.c b/block/fops.c index 0cf8cf72cdfa..ab0e37d1dc48 100644 --- a/block/fops.c +++ b/block/fops.c @@ -73,6 +73,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, bio_init(&bio, bdev, vecs, nr_pages, dio_bio_write_op(iocb)); } bio.bi_iter.bi_sector = pos >> SECTOR_SHIFT; + bio.bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint; bio.bi_ioprio = iocb->ki_ioprio; ret = bio_iov_iter_get_pages(&bio, iter); @@ -203,6 +204,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, for (;;) { bio->bi_iter.bi_sector = pos >> SECTOR_SHIFT; + bio->bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint; bio->bi_private = dio; bio->bi_end_io = blkdev_bio_end_io; bio->bi_ioprio = iocb->ki_ioprio; @@ -321,6 +323,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, dio->flags = 0; dio->iocb = iocb; bio->bi_iter.bi_sector = pos >> SECTOR_SHIFT; + bio->bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint; bio->bi_end_io = blkdev_bio_end_io_async; bio->bi_ioprio = iocb->ki_ioprio; diff --git a/fs/buffer.c b/fs/buffer.c index b55dea034a5d..d6b64124977a 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -55,7 +55,7 @@ static int fsync_buffers_list(spinlock_t *lock, struct list_head *list); static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh, - struct writeback_control *wbc); + enum rw_hint hint, struct writeback_control *wbc); #define BH_ENTRY(list) list_entry((list), struct buffer_head, b_assoc_buffers) @@ -1889,7 +1889,8 @@ int __block_write_full_folio(struct inode *inode, struct folio *folio, do { struct buffer_head *next = bh->b_this_page; if (buffer_async_write(bh)) { - submit_bh_wbc(REQ_OP_WRITE | write_flags, bh, wbc); + submit_bh_wbc(REQ_OP_WRITE | write_flags, bh, + inode->i_write_hint, wbc); nr_underway++; } bh = next; @@ -1944,7 +1945,8 @@ int __block_write_full_folio(struct inode *inode, struct folio *folio, struct buffer_head *next = bh->b_this_page; if (buffer_async_write(bh)) { clear_buffer_dirty(bh); - submit_bh_wbc(REQ_OP_WRITE | write_flags, bh, wbc); + submit_bh_wbc(REQ_OP_WRITE | write_flags, bh, + inode->i_write_hint, wbc); nr_underway++; } bh = next; @@ -2756,6 +2758,7 @@ static void end_bio_bh_io_sync(struct bio *bio) } static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh, + enum rw_hint write_hint, struct writeback_control *wbc) { const enum req_op op = opf & REQ_OP_MASK; @@ -2783,6 +2786,7 @@ static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh, fscrypt_set_bio_crypt_ctx_bh(bio, bh, GFP_NOIO); bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9); + bio->bi_write_hint = write_hint; __bio_add_page(bio, bh->b_page, bh->b_size, bh_offset(bh)); @@ -2802,7 +2806,7 @@ static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh, void submit_bh(blk_opf_t opf, struct buffer_head *bh) { - submit_bh_wbc(opf, bh, NULL); + submit_bh_wbc(opf, bh, WRITE_LIFE_NOT_SET, NULL); } EXPORT_SYMBOL(submit_bh); diff --git a/fs/direct-io.c b/fs/direct-io.c index 60456263a338..62c97ff9e852 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -410,6 +410,8 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, bio->bi_end_io = dio_bio_end_io; if (dio->is_pinned) bio_set_flag(bio, BIO_PAGE_PINNED); + bio->bi_write_hint = file_inode(dio->iocb->ki_filp)->i_write_hint; + sdio->bio = bio; sdio->logical_offset_in_bio = sdio->cur_page_fs_offset; } diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 093c4515b22a..c961511bece1 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1667,6 +1667,7 @@ iomap_alloc_ioend(struct inode *inode, struct iomap_writepage_ctx *wpc, REQ_OP_WRITE | wbc_to_write_flags(wbc), GFP_NOFS, &iomap_ioend_bioset); bio->bi_iter.bi_sector = sector; + bio->bi_write_hint = inode->i_write_hint; wbc_init_bio(wbc, bio); ioend = container_of(bio, struct iomap_ioend, io_inline_bio); @@ -1697,6 +1698,7 @@ iomap_chain_bio(struct bio *prev) new = bio_alloc(prev->bi_bdev, BIO_MAX_VECS, prev->bi_opf, GFP_NOFS); bio_clone_blkg_association(new, prev); new->bi_iter.bi_sector = bio_end_sector(prev); + new->bi_write_hint = prev->bi_write_hint; bio_chain(prev, new); bio_get(prev); /* for iomap_finish_ioend */ diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index bcd3f8cf5ea4..f3b43d223a46 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -380,6 +380,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits, GFP_KERNEL); bio->bi_iter.bi_sector = iomap_sector(iomap, pos); + bio->bi_write_hint = inode->i_write_hint; bio->bi_ioprio = dio->iocb->ki_ioprio; bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; diff --git a/fs/mpage.c b/fs/mpage.c index 738882e0766d..fa8b99a199fa 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -605,6 +605,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, GFP_NOFS); bio->bi_iter.bi_sector = first_block << (blkbits - 9); wbc_init_bio(wbc, bio); + bio->bi_write_hint = inode->i_write_hint; } /* diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 7a8150a5f051..492b0128b5d9 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -8,6 +8,7 @@ #include #include #include +#include struct blk_mq_tags; struct blk_flush_queue; @@ -135,6 +136,7 @@ struct request { struct blk_crypto_keyslot *crypt_keyslot; #endif + enum rw_hint write_hint; unsigned short ioprio; enum mq_rq_state state; diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index f288c94374b3..12d87cef2c03 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -10,6 +10,7 @@ #include #include #include +#include struct bio_set; struct bio; @@ -269,6 +270,7 @@ struct bio { */ unsigned short bi_flags; /* BIO_* below */ unsigned short bi_ioprio; + enum rw_hint bi_write_hint; blk_status_t bi_status; atomic_t __bi_remaining;