From patchwork Sun Oct 27 22:23:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13852746 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB107D1358B for ; Sun, 27 Oct 2024 22:23:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46ABD6B0089; Sun, 27 Oct 2024 18:23:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 419ED6B008A; Sun, 27 Oct 2024 18:23:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E27B6B008C; Sun, 27 Oct 2024 18:23:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0C3EF6B0089 for ; Sun, 27 Oct 2024 18:23:42 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 64CB9140B81 for ; Sun, 27 Oct 2024 22:23:18 +0000 (UTC) X-FDA: 82720810032.28.B3F4AB5 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by imf18.hostedemail.com (Postfix) with ESMTP id 209C01C0012 for ; Sun, 27 Oct 2024 22:23:29 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=LQSdVM0j; spf=pass (imf18.hostedemail.com: domain of hughd@google.com designates 209.85.210.42 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730067741; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=+XkdkUsBCpwU48QmXXg+E+cbuL3jYIMICiO/oJZ7j9Y=; b=A9NuCyVOWeg3edK5IyIrnrjkOXYBTXdoGPzJsFMt9+2bC38UGU3JbYGObmUbcKnUr5BUpm BbdkZmKnN3IOKYbMo+UP2fc4I3Si98R6qrqbAlLa+n3U4KsOrp4JDn1kVreoBhFmHirPTg 7fmkqoH1xY7i7HnaHGqs53KwA8hfpFw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=LQSdVM0j; spf=pass (imf18.hostedemail.com: domain of hughd@google.com designates 209.85.210.42 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730067741; a=rsa-sha256; cv=none; b=n65Wx1sJuXYPM4EOM/7wHkpDKwWM/5v/xkeVdwCFmNUhkiJfhHHwuK1X2623wHwy35V9aT VotG3R/+Qre0dYxeLYlWC6g984t1jmEePdWSFgo5zggEeBbt3w137qrMlQG7WeBXsLLTWx hQZOutmK0Vkbir0vfXMP3PVCuAXCkK8= Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-718119fc061so1953586a34.2 for ; Sun, 27 Oct 2024 15:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730067819; x=1730672619; darn=kvack.org; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=+XkdkUsBCpwU48QmXXg+E+cbuL3jYIMICiO/oJZ7j9Y=; b=LQSdVM0j57hwuuoOmjm/bNoLgx73p5GFquogFuQ6tW7KHgKjq8XMTIl0Lk+Xl8taMJ IwCTtUh0RDqK6wqOM54/qoupgM4qcW1cHOvW3hGSos8sdtu8XW1RV8EGFZfqP8BkMqQA 66rSoMX6jW93ydPugpmyYF8mFOnMJdQOZxLcxEbXaIwo55mrwOECJoWBzDmUIDpWULEt oqG/Y6Z/BMFJesSJb+WHNQ0ppnJpBHJyTwij36V0pFW2zMVBXECGCwa6GhTLq3x8C9Cp 5ZFLVxzBR4B160RNtmmHrsbue7NpOASlVkAegTlFTe+0ZU1vOwOqwd1W5IXvacvO53bx lmww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730067819; x=1730672619; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=+XkdkUsBCpwU48QmXXg+E+cbuL3jYIMICiO/oJZ7j9Y=; b=B/ZcTKrftH6ZoXCXKUL8hklIo6J73a3e+pxu/nsXe++o69f4O+WaAnsnaCWP4b0tkm HbM1BHKh/I9bjT4sTdc0nQmVo+uwXWHSr2YJTQia2nST2arEgqS24o9M25YkjNsehbhF RylvlkPIM+NgfBdL72jkpFaj6hVqUZReKoZKybm1EDeGElpMu1TlwOAdJyxqe85lT642 sHSydtDF2MzY7MEM6jl24ddjStRrPJrRenJE1Tl97s9Xjs6slDd6o/4lB/cvGsq4zoEa kgjG5LhX9DgGm1c+UxqhEwmrmYFp846ZbaF4qao+CBegeHjwipPHtJEXy9epUpwVOtC1 DzzA== X-Forwarded-Encrypted: i=1; AJvYcCVT2SVXRx9aLFIUxzMgZA27t0XcR4iuZmhBK2zj+NNjXgUVOZrLeW0rvUPb3qEC7XCcRHDgDJgseA==@kvack.org X-Gm-Message-State: AOJu0Yw3JTPm8ytg0ncBmrSqwUhnZeRZo6f7qEXUcjFLB21ykHrEj2YG /NKmTOlsBv8rAGB39benqrmUwzVc2AyIKY0E1TBfjgTdjwdT/uxlDV1dGM5tcg== X-Google-Smtp-Source: AGHT+IHWRKvprk92gXrSyzyMGO8sYq9D2+dQAwzgUyL9Up++6xFGJPIJrFUiroBsPDyQ5b0RA039+w== X-Received: by 2002:a05:6830:440f:b0:718:118d:2bf6 with SMTP id 46e09a7af769-718683256d2mr5142266a34.23.1730067818830; Sun, 27 Oct 2024 15:23:38 -0700 (PDT) Received: from darker.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec186fd35bsm1389857eaf.30.2024.10.27.15.23.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2024 15:23:37 -0700 (PDT) Date: Sun, 27 Oct 2024 15:23:23 -0700 (PDT) From: Hugh Dickins To: Alexander Viro cc: Andrew Morton , Christian Brauner , Matthew Wilcox , Christoph Hellwig , Kent Overstreet , "Darrick J. Wong" , Thomas Gleixner , Peter Zijlstra , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] iov_iter: fix copy_page_from_iter_atomic() if KMAP_LOCAL_FORCE_MAP Message-ID: MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 209C01C0012 X-Stat-Signature: 334zspipiczwp9dz7paqhph1piny6cyb X-HE-Tag: 1730067809-851530 X-HE-Meta: U2FsdGVkX18zb7aUN5xAU1Wh2Cxfw4/O5KVopfJ3qc2P+7hKq+NqZ35AM4+c4LgPRbn2BCWZQb3BlSUyrjar97tTNvqJUmOoSgyGhproPB2wRxXxXnebZod+tBCnSodQdHJ9t9qqNzNVn1q/RQgBPYARy0zwkXk70iQ3PeGeHqfKm/KYhwjU57txng0jug7BVTrW3lg2LbszWiryd7LcmAabPZLck0fmqBGBlL+lin4Q7gTKggSFv6QsT8cpFmTUqzjmLU5M8XuLUDreUuQ2Dkzy5EhNNoV8ISvdxWE9Z0kW7O6nCpMhru7HR3j7AyxCvyqNqBFLpVTG9ek0hK61Wx/xC8HAhoa3LYO2GG5tJUXzd9cZzF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, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: generic/077 on x86_32 CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP=y with highmem, on huge=always tmpfs, issues a warning and then hangs (interruptibly): WARNING: CPU: 5 PID: 3517 at mm/highmem.c:622 kunmap_local_indexed+0x62/0xc9 CPU: 5 UID: 0 PID: 3517 Comm: cp Not tainted 6.12.0-rc4 #2 ... copy_page_from_iter_atomic+0xa6/0x5ec generic_perform_write+0xf6/0x1b4 shmem_file_write_iter+0x54/0x67 Fix copy_page_from_iter_atomic() by limiting it in that case (include/linux/skbuff.h skb_frag_must_loop() does similar). But going forward, perhaps CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP is too surprising, has outlived its usefulness, and should just be removed? Fixes: 908a1ad89466 ("iov_iter: Handle compound highmem pages in copy_page_from_iter_atomic()") Signed-off-by: Hugh Dickins Cc: stable@vger.kernel.org Reviewed-by: Christoph Hellwig --- lib/iov_iter.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 1abb32c0da50..94051b83fdd8 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -461,6 +461,8 @@ size_t copy_page_from_iter_atomic(struct page *page, size_t offset, size_t bytes, struct iov_iter *i) { size_t n, copied = 0; + bool uses_kmap = IS_ENABLED(CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP) || + PageHighMem(page); if (!page_copy_sane(page, offset, bytes)) return 0; @@ -471,7 +473,7 @@ size_t copy_page_from_iter_atomic(struct page *page, size_t offset, char *p; n = bytes - copied; - if (PageHighMem(page)) { + if (uses_kmap) { page += offset / PAGE_SIZE; offset %= PAGE_SIZE; n = min_t(size_t, n, PAGE_SIZE - offset); @@ -482,7 +484,7 @@ size_t copy_page_from_iter_atomic(struct page *page, size_t offset, kunmap_atomic(p); copied += n; offset += n; - } while (PageHighMem(page) && copied != bytes && n > 0); + } while (uses_kmap && copied != bytes && n > 0); return copied; }