Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17753581rwd; Tue, 27 Jun 2023 07:12:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ZlBOEqqFEiY9PpDVXfKuP6LgtwvaMDujyMfKyRA5FKQa2lqQApzrEOqidgC+3AnVCqf+4 X-Received: by 2002:a17:906:dac4:b0:974:5399:c21 with SMTP id xi4-20020a170906dac400b0097453990c21mr25885170ejb.24.1687875151351; Tue, 27 Jun 2023 07:12:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687875151; cv=none; d=google.com; s=arc-20160816; b=DB+XWqdtmacnZfaEagzGIDFsl3gyrtecJfKHSwfllnnWik+bNTmWxgen5AwaCfJqQJ QDpH4GpvYkcMSI/cSqzGcagmosBs35KghzoNQfOZ+fbs/Iafl6sKcxg89vL/cYVO7rkl ygaZMzRyPAPKes4xibwOexFTiNIHKAGBQMjaSmSknBVOFHuQYyLA1tVH227bHTv0ZSAA Gh2cl/pIYh2xWu7/XJu9Xiy3aJuzd0pY/ntKhTKs7ydNUzWIOG4LepyJQYXUTRSHpo/a PP/9FKx2SyXVwBx5Jw0iTpaM///hRkYrF1XuQxHRKWoI/F/Vj5/XBbBSF8Yo6t5hPGlW XqJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=yC0qdsVlzqom1maXrFmWbBV9EFBNb4pDFIg7xKX9iVU=; fh=kYyaoPOjyUFJUGUCZIN+Z1dAYTFebns376BE/yG4jKY=; b=ftfvCgwfWDJeATwPJ49sZ2Yt9qdvmk5tZjaRZcUBogq2qQWB+MAXQMUQA7NmAg+Rqg GwbIfrFNJju4gRledoCHbt1ZgC0+O50c5X3l2nwAtpnyTsS/eJrd9PyGhJTg3M4E4TMq +fRcUDdlrF7zwKwDm2/2KVbYgd/LFAtk+8nWfmJOMrApjZhznj3x/HQC8kJiyrn05D0c rrf1ga3a3jrAUcXIIdi4we0HQhA7QtteOAgA4hl/eEvhol4uyH9xeMhCbBBUPQ7mot4S ojhK58L4Pcg9/XPYVWpM5IEeaVrRQzz7L3gNx7xwnYLH0TrScHIzUCii5jFc1kMpnzdQ yvWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NMXss8hE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pk11-20020a170906d7ab00b0099014bccfc9si2885024ejb.142.2023.06.27.07.12.04; Tue, 27 Jun 2023 07:12:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NMXss8hE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231133AbjF0NvY (ORCPT + 99 others); Tue, 27 Jun 2023 09:51:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbjF0NvX (ORCPT ); Tue, 27 Jun 2023 09:51:23 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B80322115; Tue, 27 Jun 2023 06:51:22 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-262c42d3fafso2269152a91.0; Tue, 27 Jun 2023 06:51:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687873882; x=1690465882; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=yC0qdsVlzqom1maXrFmWbBV9EFBNb4pDFIg7xKX9iVU=; b=NMXss8hEntoOBfcERaamzECMxwW0IQb8YoySdVTtM3Z4qg/iIwH1bK9KxtaWCdWWHr 005b9wSIiaFMqYzGpbcLUAD0hEmEx+6jtCXxln7D73zyY4T950uoPgaAiAlgc9JGXAm6 1qQdu8nYFEzfrS+tPixR1P9/TvSXezbbynBRAOWVVrQLA0i6t2+/GSPCysTKX67xNdRO o3Qs6TiLAY6wIHAhyK4a7tRAMWfq5pOIR66AK3bg+w251KftsmmQlwOlJPy3Zl8lhUR/ Ha8E6gKj+qcHG306E6yHhwyvMakN76BQg9F/WLDFWjcRHBmiTmxItqtE7TiCo6W0s5Sq oTSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687873882; x=1690465882; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yC0qdsVlzqom1maXrFmWbBV9EFBNb4pDFIg7xKX9iVU=; b=MT2fhiqRMKu6lWKoPMpws1gIq1MqlElOV4XdNc8+KB8eO7SrT0cmccEuCjeE8sR0YC tpxzmpcaZAudFLtAWPAZE1Qwjf2HCkD2Io/SEPGkVDBD8t2BmMKXxsKAXrm2cog9Eb+r t8VVRxfjJxF9HIjt7VlVwmCjlkKLv629F6o5Ii31foznws//+99Ocj+7H9VCgZ01jUZ7 EzKFBm4vYX6du/Tdj5QM/zF5eUcjSRrw4+OYuho6N/sLmAzuyKb+ywUfrUhSvfdkzdJC plBtAC4ZbyyrFDPG+EDFGj+P+D1xUcVL3Di1SSxFf3A1AqCm9/4c1k22XeDb+IEF43Nx sidw== X-Gm-Message-State: AC+VfDwdQdaiGydVNmCWSUNk1Q/8CxsKr5FDHzBaWA8ya0T5Kshgiq1p 78E3AlAln97ktaMJnY8MtN8= X-Received: by 2002:a17:90b:390a:b0:262:f550:6413 with SMTP id ob10-20020a17090b390a00b00262f5506413mr7683107pjb.6.1687873881919; Tue, 27 Jun 2023 06:51:21 -0700 (PDT) Received: from sumitra.com ([59.95.154.112]) by smtp.gmail.com with ESMTPSA id m7-20020a17090a414700b00262d368b220sm5553968pjg.40.2023.06.27.06.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 06:51:21 -0700 (PDT) Date: Tue, 27 Jun 2023 06:51:15 -0700 From: Sumitra Sharma To: Hans de Goede , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , Fabio , Deepak R Varma , Sumitra Sharma Subject: [PATCH] fs/vboxsf: Replace kmap() with kmap_local_{page, folio}() Message-ID: <20230627135115.GA452832@sumitra.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kmap() has been deprecated in favor of the kmap_local_page() due to high cost, restricted mapping space, the overhead of a global lock for synchronization, and making the process sleep in the absence of free slots. kmap_local_{page, folio}() is faster than kmap() and offers thread-local and CPU-local mappings, can take pagefaults in a local kmap region and preserves preemption by saving the mappings of outgoing tasks and restoring those of the incoming one during a context switch. The difference between kmap_local_page() and kmap_local_folio() consist only in the first taking a pointer to a page and the second taking two arguments, a pointer to a folio and the byte offset within the folio which identifies the page. The mappings are kept thread local in the functions 'vboxsf_read_folio', 'vboxsf_writepage', 'vboxsf_write_end' in file.c Suggested-by: Ira Weiny Signed-off-by: Sumitra Sharma --- fs/vboxsf/file.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/vboxsf/file.c b/fs/vboxsf/file.c index 572aa1c43b37..5190619bc3c5 100644 --- a/fs/vboxsf/file.c +++ b/fs/vboxsf/file.c @@ -234,7 +234,7 @@ static int vboxsf_read_folio(struct file *file, struct folio *folio) u8 *buf; int err; - buf = kmap(page); + buf = kmap_local_folio(folio, off); err = vboxsf_read(sf_handle->root, sf_handle->handle, off, &nread, buf); if (err == 0) { @@ -245,7 +245,7 @@ static int vboxsf_read_folio(struct file *file, struct folio *folio) SetPageError(page); } - kunmap(page); + kunmap_local(buf); unlock_page(page); return err; } @@ -286,10 +286,10 @@ static int vboxsf_writepage(struct page *page, struct writeback_control *wbc) if (!sf_handle) return -EBADF; - buf = kmap(page); + buf = kmap_local_page(page); err = vboxsf_write(sf_handle->root, sf_handle->handle, off, &nwrite, buf); - kunmap(page); + kunmap_local(buf); kref_put(&sf_handle->refcount, vboxsf_handle_release); @@ -320,10 +320,10 @@ static int vboxsf_write_end(struct file *file, struct address_space *mapping, if (!PageUptodate(page) && copied < len) zero_user(page, from + copied, len - copied); - buf = kmap(page); + buf = kmap_local_page(page); err = vboxsf_write(sf_handle->root, sf_handle->handle, pos, &nwritten, buf + from); - kunmap(page); + kunmap_local(buf); if (err) { nwritten = 0; -- 2.25.1