From patchwork Sat Dec 31 07:57:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 13085975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1305EC4332F for ; Sat, 31 Dec 2022 07:57:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230138AbiLaH51 (ORCPT ); Sat, 31 Dec 2022 02:57:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229546AbiLaH50 (ORCPT ); Sat, 31 Dec 2022 02:57:26 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6020CD9D; Fri, 30 Dec 2022 23:57:25 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id fm16-20020a05600c0c1000b003d96fb976efso14843220wmb.3; Fri, 30 Dec 2022 23:57:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t4IpF0CMnhbBf7H7iLN0nfh/18GS/Ps3ATwtaps4Vp8=; b=AOl7o3fmt3GWKSukWb8eLrplMvNc8lqZmXLnm8MPUxTsxPucV3/hhW063eGVE1JXg/ tFrop3VJAz0M3OYKgqncR0UuoMlCV/SJ7vy/NHDNuQsFkfuzyMsecph3+tzNMNPeQ+Uk bjpujoOPzTGGa3PaaODY9yWrdaUw/p1tluWLd4suv34ZqrEEDf+o2AAJ94McrOoA9SGN tIifYv3uoqRq4Mw8c4+MxJkSX8CrwMAdZJ3ssvjo/5K9lieSW8cbD2WgLUUPm5yYSYq3 S4ysG2PlRxt9fT73c5m2Dt8fFKzJEB0IkVzJvMw7UcCkmF8lEOKlgifqe2f3Dc0OZWav SI4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=t4IpF0CMnhbBf7H7iLN0nfh/18GS/Ps3ATwtaps4Vp8=; b=DLhlfuP4hcpsxauMgEwphMkYRL7ax9AeGBviKFWfUNnX2UqKHW7oF9QoYs7FdrS1PV WxkFilmACUcuV+NV7c5nnNs2iVCDVhwZlhYJvLN8JhtyAdW2kJleaeNrMtTE2QsVROwv cII6YBa4JXOAOLwrig/a+hGwOH56HIZTqyARnAMgPrM4UMS6thQzL4FGZxzKM4iu40gF 9x2SZVe8fPPQe8DE86U7UiBXdAZHsN7mk7TzBB34bPOZk1itArmANP8bYGaM4Gtz1Zok G7mmkZMps/EjjlOBjukBMtZ1tuTy1vXuGdECxacAT9e1dtoBjbtxOWYArZrpn4akbThH 8ufQ== X-Gm-Message-State: AFqh2ko8YtVZ99p26ZRXxf+2G4BLlVuGm9PfIxmsEB9VcMBYei9nsxyz 2QrjS/raTsBxKF+/CjKpouencRbMzBc= X-Google-Smtp-Source: AMrXdXtLKJOTY3ROoXoRtERdQqXUEdnIAQMc3WUqq79mAgfZYayLl+tF5dfMyDFfgYNb6jVM1jEfwg== X-Received: by 2002:a05:600c:a13:b0:3d0:2485:c046 with SMTP id z19-20020a05600c0a1300b003d02485c046mr24077127wmp.27.1672473443870; Fri, 30 Dec 2022 23:57:23 -0800 (PST) Received: from localhost.localdomain (host-79-56-217-20.retail.telecomitalia.it. [79.56.217.20]) by smtp.gmail.com with ESMTPSA id l42-20020a05600c1d2a00b003d23928b654sm39389232wms.11.2022.12.30.23.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Dec 2022 23:57:23 -0800 (PST) From: "Fabio M. De Francesco" To: Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "Fabio M. De Francesco" , Ira Weiny , Al Viro Subject: [PATCH 1/4] fs/sysv: Use the offset_in_page() helper Date: Sat, 31 Dec 2022 08:57:14 +0100 Message-Id: <20221231075717.10258-2-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221231075717.10258-1-fmdefrancesco@gmail.com> References: <20221231075717.10258-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the offset_in_page() helper because it is more suitable than doing explicit subtractions between pointers to directory entries and kernel virtual addresses of mapped pages. Cc: Ira Weiny Suggested-by: Al Viro Signed-off-by: Fabio M. De Francesco --- fs/sysv/dir.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index 88e38cd8f5c9..685379bc9d64 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c @@ -206,8 +206,7 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode) return -EINVAL; got_it: - pos = page_offset(page) + - (char*)de - (char*)page_address(page); + pos = page_offset(page) + offset_in_page(de); lock_page(page); err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE); if (err) @@ -230,8 +229,7 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode) int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page) { struct inode *inode = page->mapping->host; - char *kaddr = (char*)page_address(page); - loff_t pos = page_offset(page) + (char *)de - kaddr; + loff_t pos = page_offset(page) + offset_in_page(de); int err; lock_page(page); @@ -328,8 +326,7 @@ void sysv_set_link(struct sysv_dir_entry *de, struct page *page, struct inode *inode) { struct inode *dir = page->mapping->host; - loff_t pos = page_offset(page) + - (char *)de-(char*)page_address(page); + loff_t pos = page_offset(page) + offset_in_page(de); int err; lock_page(page); From patchwork Sat Dec 31 07:57:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 13085978 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1357EC5479D for ; Sat, 31 Dec 2022 07:57:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231664AbiLaH5e (ORCPT ); Sat, 31 Dec 2022 02:57:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231561AbiLaH53 (ORCPT ); Sat, 31 Dec 2022 02:57:29 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F024933F; Fri, 30 Dec 2022 23:57:26 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id k26-20020a05600c1c9a00b003d972646a7dso13832357wms.5; Fri, 30 Dec 2022 23:57:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2WGDj24HpD7Fo6/hb6lWcextCLZNM+3WgApo42pp5bs=; b=PLbdELi1nRGwMCglDcSwc1BWlakcf17hJxcXqkHIeaL1xfgDECfdFpOFMLNuZsuRRR AtE97k3gY3oflnsRlxm8empC08LnfGuSSvv07iLbZ3DxV/5mNE+hATn4rUmjcNwOi43V BG7yIvoA3l/m4aGM0fd0hSTeGv/Ig1EmsNfkq4F/WxFOLueggX9dDtZxm1zkA0yBegi6 DXthstEJ9YOAt0vgtPK47xQwyUAvi2c8LZqu6oopzlmbXzD0yZHUWD/QUqP0EFAexTW0 +rrQxEExL8nb7xCtuA+KZ9m+2Jo/Fd5DAI4fNuxTJxWKgZiAy8qaZX7tJHks6t2Ype2f XpKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=2WGDj24HpD7Fo6/hb6lWcextCLZNM+3WgApo42pp5bs=; b=ndEXL3aCXhczamIjg0ahWFYtrgehiFErlcNaiQg8QnOSNCYkEGWEiwo7FVzeV64FXP TNwEaUFFYUX69aKmP5SD+sM9WmC5Y2rP9PjgxMTvAHxYYUuYGDK/G266KxddOXLFNJTg eN2dZq3eoxgzgN3WMBGcGOG44PDQMM+Z547s70vwhbgvwJz085dXYbCeSTgk8VDUyJO5 lYRdLAle6Gd+NyUhHk6JTn4mczJXyABFaYAVQOk48HQkE1Nvoau8tOS9DYtdxdoW3xzc aB8JT+VqNTVOP2PaB4MgqU+dQ8rCu69pSImqrzYRvboxPU6c/mD6pMUxlzNsap1KtqIc zo1w== X-Gm-Message-State: AFqh2kqku6olZQVZK1qTJygC0/13uS+v4JPDbarZTzOPdmv4oj88IhAQ 6HdzLlnmQX/PdgOPG9JKdHRHCvSoTXw= X-Google-Smtp-Source: AMrXdXs4Kavj3cJknZ10v1GrO1/fa7oLrOIX049dDFrrZETbqVZvPi8vNuEUER8+Ie6WoQULyGyosQ== X-Received: by 2002:a05:600c:3b22:b0:3c6:e63e:814b with SMTP id m34-20020a05600c3b2200b003c6e63e814bmr24007443wms.2.1672473445417; Fri, 30 Dec 2022 23:57:25 -0800 (PST) Received: from localhost.localdomain (host-79-56-217-20.retail.telecomitalia.it. [79.56.217.20]) by smtp.gmail.com with ESMTPSA id l42-20020a05600c1d2a00b003d23928b654sm39389232wms.11.2022.12.30.23.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Dec 2022 23:57:24 -0800 (PST) From: "Fabio M. De Francesco" To: Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "Fabio M. De Francesco" , Ira Weiny , Al Viro Subject: [PATCH 2/4] fs/sysv: Change the signature of dir_get_page() Date: Sat, 31 Dec 2022 08:57:15 +0100 Message-Id: <20221231075717.10258-3-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221231075717.10258-1-fmdefrancesco@gmail.com> References: <20221231075717.10258-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Change the signature of dir_get_page() in order to prepare this function to the conversion to the use of kmap_local_page(). Change also those call sites which are required to conform to the new signature. Cc: Ira Weiny Suggested-by: Al Viro Signed-off-by: Fabio M. De Francesco --- fs/sysv/dir.c | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index 685379bc9d64..0a8b5828c390 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c @@ -52,13 +52,15 @@ static int dir_commit_chunk(struct page *page, loff_t pos, unsigned len) return err; } -static struct page * dir_get_page(struct inode *dir, unsigned long n) +static void *dir_get_page(struct inode *dir, unsigned long n, struct page **p) { struct address_space *mapping = dir->i_mapping; struct page *page = read_mapping_page(mapping, n, NULL); - if (!IS_ERR(page)) - kmap(page); - return page; + if (IS_ERR(page)) + return ERR_CAST(page); + kmap(page); + *p = page; + return page_address(page); } static int sysv_readdir(struct file *file, struct dir_context *ctx) @@ -80,11 +82,11 @@ static int sysv_readdir(struct file *file, struct dir_context *ctx) for ( ; n < npages; n++, offset = 0) { char *kaddr, *limit; struct sysv_dir_entry *de; - struct page *page = dir_get_page(inode, n); + struct page *page; - if (IS_ERR(page)) + kaddr = dir_get_page(inode, n, &page); + if (IS_ERR(kaddr)) continue; - kaddr = (char *)page_address(page); de = (struct sysv_dir_entry *)(kaddr+offset); limit = kaddr + PAGE_SIZE - SYSV_DIRSIZE; for ( ;(char*)de <= limit; de++, ctx->pos += sizeof(*de)) { @@ -142,11 +144,10 @@ struct sysv_dir_entry *sysv_find_entry(struct dentry *dentry, struct page **res_ n = start; do { - char *kaddr; - page = dir_get_page(dir, n); - if (!IS_ERR(page)) { - kaddr = (char*)page_address(page); - de = (struct sysv_dir_entry *) kaddr; + char *kaddr = dir_get_page(dir, n, &page); + + if (!IS_ERR(kaddr)) { + de = (struct sysv_dir_entry *)kaddr; kaddr += PAGE_SIZE - SYSV_DIRSIZE; for ( ; (char *) de <= kaddr ; de++) { if (!de->inode) @@ -185,11 +186,10 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode) /* We take care of directory expansion in the same loop */ for (n = 0; n <= npages; n++) { - page = dir_get_page(dir, n); + kaddr = dir_get_page(dir, n, &page); err = PTR_ERR(page); - if (IS_ERR(page)) - goto out; - kaddr = (char*)page_address(page); + if (IS_ERR(kaddr)) + return PTR_ERR(kaddr); de = (struct sysv_dir_entry *)kaddr; kaddr += PAGE_SIZE - SYSV_DIRSIZE; while ((char *)de <= kaddr) { @@ -219,7 +219,6 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode) mark_inode_dirty(dir); out_page: dir_put_page(page); -out: return err; out_unlock: unlock_page(page); @@ -288,12 +287,11 @@ int sysv_empty_dir(struct inode * inode) for (i = 0; i < npages; i++) { char *kaddr; struct sysv_dir_entry * de; - page = dir_get_page(inode, i); - if (IS_ERR(page)) + kaddr = dir_get_page(inode, i, &page); + if (IS_ERR(kaddr)) continue; - kaddr = (char *)page_address(page); de = (struct sysv_dir_entry *)kaddr; kaddr += PAGE_SIZE-SYSV_DIRSIZE; @@ -339,16 +337,16 @@ void sysv_set_link(struct sysv_dir_entry *de, struct page *page, mark_inode_dirty(dir); } -struct sysv_dir_entry * sysv_dotdot (struct inode *dir, struct page **p) +struct sysv_dir_entry *sysv_dotdot(struct inode *dir, struct page **p) { - struct page *page = dir_get_page(dir, 0); - struct sysv_dir_entry *de = NULL; + struct page *page = NULL; + struct sysv_dir_entry *de = dir_get_page(dir, 0, &page); - if (!IS_ERR(page)) { - de = (struct sysv_dir_entry*) page_address(page) + 1; + if (!IS_ERR(de)) { *p = page; + return (struct sysv_dir_entry *)page_address(page) + 1; } - return de; + return NULL; } ino_t sysv_inode_by_name(struct dentry *dentry) From patchwork Sat Dec 31 07:57:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 13085977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02A41C53210 for ; Sat, 31 Dec 2022 07:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231644AbiLaH5c (ORCPT ); Sat, 31 Dec 2022 02:57:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231602AbiLaH5a (ORCPT ); Sat, 31 Dec 2022 02:57:30 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FAAED9D; Fri, 30 Dec 2022 23:57:28 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id m8-20020a05600c3b0800b003d96f801c48so14682549wms.0; Fri, 30 Dec 2022 23:57:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R3DzRI51PYBUXFaa7iBRSWpK+zXF1njrTHM9hKQ8ASA=; b=TWi2DOINUP9biKc29xu8+VPFZChm3y+eYFuYj2cz3sp6slza4h2+ljvtEd6hBKK8R1 D09H9UubeyVSG/vgLwFehi+d0nfWBITHromhUKcsIA1elW/SbZ94DuBoyjbBB7+Em4Op o6D4+sXDq7OtoHClC4nyOPYlF2ExJDOaUgbcMrplVb4xT3T1ihjT/zDwhZW/4J4m/hb5 bJkQwv10S+07WacGgDxLhD523W6SUpTsBGv5AZ+IcZZa/qjVIuzMAENYOzRrSSiES0Cw sW7cugericU8oZMktIM3WPEV/oV2QDRtzGVFjPfn1E+6cdjMfc7bYMcCVQhbhjRFfdjA h9FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=R3DzRI51PYBUXFaa7iBRSWpK+zXF1njrTHM9hKQ8ASA=; b=DLdgmu9iUxaW7v5Ph5Dklz/b0AHRJfWQLP4NZYL/v2ynYMF6Al/Pxb/kqP2U0c6eG9 h596FY7Ojk7+ySGPV36Z7066LY3XPCk6K6QH027MgeknBm821gCU8m3bKixS8lNcFzuw vQYa6bPXzng+0uoYSp8ZoGmYduTe9qRTCZa1u2tepyjZ/wIHRbLu7ZBzNeJUGeazY6hU i/JTF8GMAFasTZWnbHQTK3sJpaJsJytuOxy2kIwR9Sqql06cfuKX6XFQ3avk7IRrbmkw +NCs1hFkMUqRiV/iNHb5a8cCVi2u56VhcYkHfEyIwB7hd0Q27c5K93QoW+wrL2NYI/Oi 3cIA== X-Gm-Message-State: AFqh2kq7Tu4BVqYwHG+fr51ZiiF+fVMrEqH1VpOy/Vq1qNjhjNGJwS7i LQ12pv3maNEu6QpkWFlE312thEKBOvU= X-Google-Smtp-Source: AMrXdXsDJKyyNtMIrc6A9JejwwuK62KOBjlQJaNVSMsRpfEvhuodXc2sTdc0APG2Gdb4lgNjCXYRvA== X-Received: by 2002:a05:600c:3d05:b0:3d3:5c21:dd94 with SMTP id bh5-20020a05600c3d0500b003d35c21dd94mr25123341wmb.9.1672473447131; Fri, 30 Dec 2022 23:57:27 -0800 (PST) Received: from localhost.localdomain (host-79-56-217-20.retail.telecomitalia.it. [79.56.217.20]) by smtp.gmail.com with ESMTPSA id l42-20020a05600c1d2a00b003d23928b654sm39389232wms.11.2022.12.30.23.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Dec 2022 23:57:26 -0800 (PST) From: "Fabio M. De Francesco" To: Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "Fabio M. De Francesco" , Al Viro , Ira Weiny Subject: [PATCH 3/4] fs/sysv: Use dir_put_page() in sysv_rename() Date: Sat, 31 Dec 2022 08:57:16 +0100 Message-Id: <20221231075717.10258-4-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221231075717.10258-1-fmdefrancesco@gmail.com> References: <20221231075717.10258-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the dir_put_page() helper in sysv_rename() instead of open-coding two kunmap() + put_page(). Cc: Al Viro Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- fs/sysv/dir.c | 2 +- fs/sysv/namei.c | 9 +++------ fs/sysv/sysv.h | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index 0a8b5828c390..a37747e9e9a3 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c @@ -28,7 +28,7 @@ const struct file_operations sysv_dir_operations = { .fsync = generic_file_fsync, }; -static inline void dir_put_page(struct page *page) +inline void dir_put_page(struct page *page) { kunmap(page); put_page(page); diff --git a/fs/sysv/namei.c b/fs/sysv/namei.c index b2e6abc06a2d..981c1d76f342 100644 --- a/fs/sysv/namei.c +++ b/fs/sysv/namei.c @@ -250,13 +250,10 @@ static int sysv_rename(struct user_namespace *mnt_userns, struct inode *old_dir, return 0; out_dir: - if (dir_de) { - kunmap(dir_page); - put_page(dir_page); - } + if (dir_de) + dir_put_page(dir_page); out_old: - kunmap(old_page); - put_page(old_page); + dir_put_page(old_page); out: return err; } diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h index 99ddf033da4f..b250ac1dd348 100644 --- a/fs/sysv/sysv.h +++ b/fs/sysv/sysv.h @@ -148,6 +148,7 @@ extern void sysv_destroy_icache(void); /* dir.c */ +extern void dir_put_page(struct page *page); extern struct sysv_dir_entry *sysv_find_entry(struct dentry *, struct page **); extern int sysv_add_link(struct dentry *, struct inode *); extern int sysv_delete_entry(struct sysv_dir_entry *, struct page *); From patchwork Sat Dec 31 07:57:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 13085976 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3725C4332F for ; Sat, 31 Dec 2022 07:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231704AbiLaH5g (ORCPT ); Sat, 31 Dec 2022 02:57:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231642AbiLaH5c (ORCPT ); Sat, 31 Dec 2022 02:57:32 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3861EE0C; Fri, 30 Dec 2022 23:57:30 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id m8-20020a05600c3b0800b003d96f801c48so14682569wms.0; Fri, 30 Dec 2022 23:57:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DcSze+U7PfTyjTQa3rm6f69rHENmMnX7aW5kNhZMEAo=; b=a/l98VSRyAGoTPGUzjPt62kx2BRR55noi+PjympWB+j+H5ge7OhmeGWPw5Vv35ipam vP04+gNteF4gLtYq5gsI8Vm2sMxi+Z3SS+kW0MCTF9Gj9fK/CHSgmjuZYdfjlNrwSPmq DAJy8+Dkxy895Ecwlsl2QikEUch0s/+9LAh+vP43qFYLAqNBNgEtWAjNkrruRJmKcu8Y X4WRBAc1VuGzrVTrepvBdgN0hyosuE1sSNWVd2ZhPhJAjMvQYmEQWE63EnF73gqRrG3E rSPAV7hf6OdCQgHOxOTEYE9gcq0RCcWwtPWIbpga7fZyA4NjuGLD7oxhpxqkO4u1k6FZ puWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=DcSze+U7PfTyjTQa3rm6f69rHENmMnX7aW5kNhZMEAo=; b=LnDWIkZE5fKprARpnEHSCq+J9FQH4QJcJ9rYz05AQWD+nxuQxN/sDhTZUupCyPbfgn cR6hIW0brcavxJ6aPJ0YHXGfS4x1EVQqx1Oqe4Ar/krBuGVWufLWD/S4tn8bTD0QfGjC 6YVFfXaR+j9N6112OO+kG2goi9kz9Wype32baxzlqQzXwG0FB/FQq1koTZ+koHkAE7FR VPvQzIJE967e+YMnlVQprfTeSLV90z2npMmX5sgL4wY5SKKD6lDZ3Xf2MYT55CXO7W1s l6WnRqmIRdm82iWCjMEu860YG+3a2NTeKd/0rKdNb/TddoeFry1PfZHFFVfEOPvLddMj S3/g== X-Gm-Message-State: AFqh2koYJ7ugSxeqNd6P4tRfpCjk2K2Zq/mYQFdlnBy8Hnj4wuKkYrtU Vb8jHRd61S7F4KUImmNGyB8= X-Google-Smtp-Source: AMrXdXuHwn9zIhuW1y8j/MLIO5XBTVYw+EQXmN9nfTxbIKv1MGiFoCJeevaIp1pWo26vRw0iVpbnqQ== X-Received: by 2002:a05:600c:13ca:b0:3d3:4427:dfbf with SMTP id e10-20020a05600c13ca00b003d34427dfbfmr23804176wmg.5.1672473448748; Fri, 30 Dec 2022 23:57:28 -0800 (PST) Received: from localhost.localdomain (host-79-56-217-20.retail.telecomitalia.it. [79.56.217.20]) by smtp.gmail.com with ESMTPSA id l42-20020a05600c1d2a00b003d23928b654sm39389232wms.11.2022.12.30.23.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Dec 2022 23:57:27 -0800 (PST) From: "Fabio M. De Francesco" To: Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "Fabio M. De Francesco" , Al Viro , Ira Weiny Subject: [PATCH 4/4] fs/sysv: Replace kmap() with kmap_local_page() Date: Sat, 31 Dec 2022 08:57:17 +0100 Message-Id: <20221231075717.10258-5-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221231075717.10258-1-fmdefrancesco@gmail.com> References: <20221231075717.10258-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org kmap() is being deprecated in favor of kmap_local_page(). There are two main problems with kmap(): (1) It comes with an overhead as the mapping space is restricted and protected by a global lock for synchronization and (2) it also requires global TLB invalidation when the kmap’s pool wraps and it might block when the mapping space is fully utilized until a slot becomes available. With kmap_local_page() the mappings are per thread, CPU local, can take page faults, and can be called from any context (including interrupts). It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, the tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and still valid. Since kmap_local_page() would not break the strict rules of local mappings (i.e., the thread locality and the stack based nesting), this function can be easily and safely replace the deprecated API. Therefore, replace kmap() with kmap_local_page() in fs/sysv. kunmap_local() requires the mapping address, so return that address from dir_get_page() to be used in dir_put_page(). Suggested-by: Al Viro Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- fs/sysv/dir.c | 64 +++++++++++++++++++++++++++++++++---------------- fs/sysv/namei.c | 4 ++-- fs/sysv/sysv.h | 2 +- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index a37747e9e9a3..ab409aa24757 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c @@ -28,9 +28,9 @@ const struct file_operations sysv_dir_operations = { .fsync = generic_file_fsync, }; -inline void dir_put_page(struct page *page) +inline void dir_put_page(struct page *page, void *page_addr) { - kunmap(page); + kunmap_local(page_addr); put_page(page); } @@ -52,15 +52,21 @@ static int dir_commit_chunk(struct page *page, loff_t pos, unsigned len) return err; } +/* + * Calls to dir_get_page()/dir_put_page() must be nested according to the + * rules documented in mm/highmem.rst. + * + * NOTE: sysv_find_entry() and sysv_dotdot() act as calls to dir_get_page() + * and must be treated accordingly for nesting purposes. + */ static void *dir_get_page(struct inode *dir, unsigned long n, struct page **p) { struct address_space *mapping = dir->i_mapping; struct page *page = read_mapping_page(mapping, n, NULL); if (IS_ERR(page)) return ERR_CAST(page); - kmap(page); *p = page; - return page_address(page); + return kmap_local_page(page); } static int sysv_readdir(struct file *file, struct dir_context *ctx) @@ -98,11 +104,11 @@ static int sysv_readdir(struct file *file, struct dir_context *ctx) if (!dir_emit(ctx, name, strnlen(name,SYSV_NAMELEN), fs16_to_cpu(SYSV_SB(sb), de->inode), DT_UNKNOWN)) { - dir_put_page(page); + dir_put_page(page, kaddr); return 0; } } - dir_put_page(page); + dir_put_page(page, kaddr); } return 0; } @@ -125,6 +131,11 @@ static inline int namecompare(int len, int maxlen, * returns the cache buffer in which the entry was found, and the entry * itself (as a parameter - res_dir). It does NOT read the inode of the * entry - you'll have to do that yourself if you want to. + * + * On Success dir_put_page() should be called on *res_page. + * + * sysv_find_entry() acts as a call to dir_get_page() and must be treated + * accordingly for nesting purposes. */ struct sysv_dir_entry *sysv_find_entry(struct dentry *dentry, struct page **res_page) { @@ -156,7 +167,7 @@ struct sysv_dir_entry *sysv_find_entry(struct dentry *dentry, struct page **res_ name, de->name)) goto found; } - dir_put_page(page); + dir_put_page(page, kaddr); } if (++n >= npages) @@ -200,7 +211,7 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode) goto out_page; de++; } - dir_put_page(page); + dir_put_page(page, kaddr); } BUG(); return -EINVAL; @@ -218,7 +229,7 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode) dir->i_mtime = dir->i_ctime = current_time(dir); mark_inode_dirty(dir); out_page: - dir_put_page(page); + dir_put_page(page, kaddr); return err; out_unlock: unlock_page(page); @@ -229,6 +240,12 @@ int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page) { struct inode *inode = page->mapping->host; loff_t pos = page_offset(page) + offset_in_page(de); + /* + * The "de" dentry points somewhere in the same page whose we need the + * address of; therefore, we can simply get the base address "kaddr" by + * masking the previous with PAGE_MASK. + */ + char *kaddr = (char *)((unsigned long)de & PAGE_MASK); int err; lock_page(page); @@ -236,7 +253,7 @@ int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page) BUG_ON(err); de->inode = 0; err = dir_commit_chunk(page, pos, SYSV_DIRSIZE); - dir_put_page(page); + dir_put_page(page, kaddr); inode->i_ctime = inode->i_mtime = current_time(inode); mark_inode_dirty(inode); return err; @@ -256,9 +273,7 @@ int sysv_make_empty(struct inode *inode, struct inode *dir) unlock_page(page); goto fail; } - kmap(page); - - base = (char*)page_address(page); + base = kmap_local_page(page); memset(base, 0, PAGE_SIZE); de = (struct sysv_dir_entry *) base; @@ -268,7 +283,7 @@ int sysv_make_empty(struct inode *inode, struct inode *dir) de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), dir->i_ino); strcpy(de->name,".."); - kunmap(page); + kunmap_local(base); err = dir_commit_chunk(page, 0, 2 * SYSV_DIRSIZE); fail: put_page(page); @@ -283,10 +298,10 @@ int sysv_empty_dir(struct inode * inode) struct super_block *sb = inode->i_sb; struct page *page = NULL; unsigned long i, npages = dir_pages(inode); + char *kaddr; for (i = 0; i < npages; i++) { - char *kaddr; - struct sysv_dir_entry * de; + struct sysv_dir_entry *de; kaddr = dir_get_page(inode, i, &page); if (IS_ERR(kaddr)) @@ -310,12 +325,12 @@ int sysv_empty_dir(struct inode * inode) if (de->name[1] != '.' || de->name[2]) goto not_empty; } - dir_put_page(page); + dir_put_page(page, kaddr); } return 1; not_empty: - dir_put_page(page); + dir_put_page(page, kaddr); return 0; } @@ -332,11 +347,18 @@ void sysv_set_link(struct sysv_dir_entry *de, struct page *page, BUG_ON(err); de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), inode->i_ino); err = dir_commit_chunk(page, pos, SYSV_DIRSIZE); - dir_put_page(page); + dir_put_page(page, de); dir->i_mtime = dir->i_ctime = current_time(dir); mark_inode_dirty(dir); } +/* + * Calls to dir_get_page()/dir_put_page() must be nested according to the + * rules documented in mm/highmem.rst. + * + * sysv_dotdot() acts as a call to dir_get_page() and must be treated + * accordingly for nesting purposes. + */ struct sysv_dir_entry *sysv_dotdot(struct inode *dir, struct page **p) { struct page *page = NULL; @@ -344,7 +366,7 @@ struct sysv_dir_entry *sysv_dotdot(struct inode *dir, struct page **p) if (!IS_ERR(de)) { *p = page; - return (struct sysv_dir_entry *)page_address(page) + 1; + return (struct sysv_dir_entry *)de + 1; } return NULL; } @@ -357,7 +379,7 @@ ino_t sysv_inode_by_name(struct dentry *dentry) if (de) { res = fs16_to_cpu(SYSV_SB(dentry->d_sb), de->inode); - dir_put_page(page); + dir_put_page(page, de); } return res; } diff --git a/fs/sysv/namei.c b/fs/sysv/namei.c index 981c1d76f342..371cf9012052 100644 --- a/fs/sysv/namei.c +++ b/fs/sysv/namei.c @@ -251,9 +251,9 @@ static int sysv_rename(struct user_namespace *mnt_userns, struct inode *old_dir, out_dir: if (dir_de) - dir_put_page(dir_page); + dir_put_page(dir_page, dir_de); out_old: - dir_put_page(old_page); + dir_put_page(old_page, old_de); out: return err; } diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h index b250ac1dd348..50f19bfd8d10 100644 --- a/fs/sysv/sysv.h +++ b/fs/sysv/sysv.h @@ -148,7 +148,7 @@ extern void sysv_destroy_icache(void); /* dir.c */ -extern void dir_put_page(struct page *page); +extern void dir_put_page(struct page *page, void *vaddr); extern struct sysv_dir_entry *sysv_find_entry(struct dentry *, struct page **); extern int sysv_add_link(struct dentry *, struct inode *); extern int sysv_delete_entry(struct sysv_dir_entry *, struct page *);