From patchwork Wed Aug 23 05:14:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13361615 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 1C50DEE49AF for ; Wed, 23 Aug 2023 05:14:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3A1B280041; Wed, 23 Aug 2023 01:14:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C289280040; Wed, 23 Aug 2023 01:14:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 862CC280041; Wed, 23 Aug 2023 01:14:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 73838280040 for ; Wed, 23 Aug 2023 01:14:58 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 37A60120459 for ; Wed, 23 Aug 2023 05:14:58 +0000 (UTC) X-FDA: 81154205076.02.8206F39 Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) by imf24.hostedemail.com (Postfix) with ESMTP id 7AC37180012 for ; Wed, 23 Aug 2023 05:14:56 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=CbKL3WxN; spf=pass (imf24.hostedemail.com: domain of hughd@google.com designates 209.85.219.176 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=1692767696; 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=3CTb60vp1T1lh9oDcHmIIF0P5J2klG07sdTavTJbf0c=; b=F9ah3BxiCtNwq97wtDcoLk0BAbfQzkBRFVLQyiYw4aiPcPU+pMVIWIi/xNoiFvXFxglW5X eHUrqU2/n4Nk0oCELUfgyy0RI50p1lqBccsDMa25CgFZjbiZRRmkozeDCIMXOCZ4ZHU38v Rryqr/v1eAHZOEm2/+1moXPNI+xdS3Q= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=CbKL3WxN; spf=pass (imf24.hostedemail.com: domain of hughd@google.com designates 209.85.219.176 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=1692767696; a=rsa-sha256; cv=none; b=Eg/1qOVxzv8Rn/QYk56F83HhSGTSIX2D7tW9NLIfa+XtaEsKr2B8XtiCTYgfwWoAGRtTfE sbUb20rjw8F6F+fogowkC7GgRs0K2IPxNeHfuvQfWlLAgGZqZTgxDDFbjmGvS4kRRF8DlR dvCgGu7i6L4t72ZFetgiV13by9ov2JA= Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-d73c595b558so5170819276.2 for ; Tue, 22 Aug 2023 22:14:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692767695; x=1693372495; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=3CTb60vp1T1lh9oDcHmIIF0P5J2klG07sdTavTJbf0c=; b=CbKL3WxN7ItM+ZH0lQ582XMB0fXou8ULzlR4X7ZUliorGB6Xqq7ZJi1h01bCjXo0Pg zjCc8KRb48umQJo/XMu4G0J06YdTbBWZjQ09P/zqq6IHuJKD31E80SIqeqsTXuCFmNbi 759eGDKtHio0TZ8Py4QcNwsx3uTLSWuShB/AQVwkEiVyI13BSFeBbEi2NmKRJCd0cCRY JhvlPzoI2afkJVdRrB9PH6P61QC8j8gENmSshZU6OiwYg9MWVuegwWW8+jZig/vLwNPU /RNifRtf36bq/mK85mqs5EL3UbqL8s7prMCQx00kOgnx1KIL3e5cNdD3VtfCJkxFiAgs KOoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767695; x=1693372495; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3CTb60vp1T1lh9oDcHmIIF0P5J2klG07sdTavTJbf0c=; b=P1DU1PyaPH0ZjHrlmYC2D79F8qANhGeB0VK49RPrU1cIhESzBfeXajD2/ugfP1p/Zm MVkldeTj8V79YAgqHvshDf+jVnnDob4AZowjx7XnhQH3DdtNZ6pJe2076w/gBtBp0pgj wWvxLTCfRKdAfVzslLgKyw0C2krnoNQSeevxqb6ZwYWexbT/KR+XzGmyLW8bk1XxZvmt hevNmRUZ1K0/ELK2/IOktu74I5191DuDQxwfykaQGyHQPtiFeGYlWM8rHHy9hqYpdQOu 2BSi9zbM6mBl5Wa8W43muXnHoPL9PW8YbxC4lHCENYDvyGFOmfXxuoJH6IvH1ucdug8M KZ4A== X-Gm-Message-State: AOJu0Yy169BmW0o0pL/p/6mxpezZiosQoM2R/E6fu/xJPnfIaIGOhFrt jFG/EgLh3Xhfb1Nt4oEqdnrm7Kj9pRhZUhAbRiuGVg== X-Google-Smtp-Source: AGHT+IEVo6Uw6EP+G7LmxwNxYXkC8mncBJRfLAroWqt/vqp4we0nE9bT4rSu1myGU2RDZUJD898l6w== X-Received: by 2002:a0d:cc4f:0:b0:589:9717:22c7 with SMTP id o76-20020a0dcc4f000000b00589971722c7mr12539538ywd.22.1692767695505; Tue, 22 Aug 2023 22:14:55 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id j80-20020a819253000000b005845e6f9b50sm3182329ywg.113.2023.08.22.22.14.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:14:55 -0700 (PDT) Date: Tue, 22 Aug 2023 22:14:47 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Edward Liaw , Peter Xu , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH mm-hotfixes-unstable] shmem: fix smaps BUG sleeping while atomic Message-ID: <6fe3b3ec-abdf-332f-5c23-6a3b3a3b11a9@google.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7AC37180012 X-Rspam-User: X-Stat-Signature: km1zpdc9synmrz16ofgtudhixentm1n6 X-Rspamd-Server: rspam01 X-HE-Tag: 1692767696-80906 X-HE-Meta: U2FsdGVkX186Ptp6qTMz1InA2bEXR9A0sPLuNV9o8K/Ig5QYOeUritV1lYJAGObOAyt+9fG2O3yCoglW+Lj4OTi/GmI3gKPvAE6lL90KsYfMPYBC8+AjlTRkuIF1cFP+56zsvbWdUWCjVrb+7LzeMtbQBa7fki9IQ72AHODxOrjvdF8KpNlDSsXZHiVjfJU1VRGEQxaMR2zR5vgh8XP0D/MAnmDFTSBlNv869haSAzXHGmsMICJP+vrEcZ4WYr1US1P8LBl/sVSIZGQiaPJBN8rYVKMJdVs4ToTh8zDz00QJ64SMJr4BGEh86r5cmw3E7R7PMnxQDbp+o+XOddmeprV9cXvXbpXihFgIpNJHKPbQZst8AqIzFKTKovgZVxsDYnfwt04n3CaXQ7xPYCQq9b0IhbBybib87pgLaOiF5+Ef9zZ4qo4AgQu+VM2nlUZvVqGvpV5IzM03xprgqO+9zkeEA/xRzc4iE0C3W9OaGIj9W75njeFwmcH2jU7ligTgc4hgbsYnzDS1TAz9OvYJQri7ZnRZOQXpX83QnvTf6I/w2FJStlS599NM5gShwfj+QXrYWNj4XV93OjIdTwJjAkhMcOMUHqs15scatujJfjVZvKtVmc+X2ao/DAyAuQLf0wpkhdQALQgBiVtPM56gzFv/UcC2jnrCcn2XOBGEeQh82dluWrQN/SRiWpWnReXDREwsRgOG4yoGIIV/RN2vqmweFaQpjJlIlD6GVsGo5daVDW3IgqwtouR5tvODLvUgOT6eUvfH3tu7GPl9w/4UUVSqDVyIiYQXNMXnEc18LEpQeJJ79T3HfuDrhweWf+72ej9ZurKSYNa2lp1+v3YPOPn9AuTctcmy/IMC86udvjnygqIaHp3TH/r7nuGupYz7JkA60AFkl/kQRnFQ4m3b8w6JDsbw4LlD0RtT6L8uh7wqaweZ2KVC4U2VR/68YZubxjMfuRI+IDYSx18F/DD gUYDX0Lh sC4Ha4cmgdv1yTcKp9+m4VGWukrKmvi1cQrGz6DhdJiySb91pc0m2j7BQSCsCQXeRb8uh78HjrYe37pHPiP0kcmG9Hu1HFWAkGWEoCJbX60pwmxRiQ45e075GqJRK1dlhmPN7BuK7pfvk8ZBAqbcSKfdKwAq9f7a1i38uxSveJqUW2FX2y0m2UeS0mKp3mLOyVytW4I+M+sqoeIj8iALml0jk4mK5auG9xSJNXjKBfSptqa8h1h1orKtPtq0IP56YWBKLckSCNj+FbyBuQSWu93+iTGxFI2PelpPvJtJidkaVfdYNwOSiYCB2gIjvaxq0mNAP9yLl64Qc7gi06I0oci7wyT1P02418uIM3IG+iXFEzj03krGRjOh+t8M3dAvovwYyEDTZb5SKs/yGGr9x3oKJukehg9UFof6GT/4yOTN9DBhO8XSIPuVlRw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: smaps_pte_hole_lookup() is calling shmem_partial_swap_usage() with page table lock held: but shmem_partial_swap_usage() does cond_resched_rcu() if need_resched(): "BUG: sleeping function called from invalid context". Since shmem_partial_swap_usage() is designed to count across a range, but smaps_pte_hole_lookup() only calls it for a single page slot, just break out of the loop on the last or only page, before checking need_resched(). Fixes: 230100321518 ("mm/smaps: simplify shmem handling of pte holes") Signed-off-by: Hugh Dickins Cc: stable@vger.kernel.org # 5.16+ Acked-by: Peter Xu --- mm/shmem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 7a0c1e19d9f8..c512a5e82f8d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -806,14 +806,16 @@ unsigned long shmem_partial_swap_usage(struct address_space *mapping, XA_STATE(xas, &mapping->i_pages, start); struct page *page; unsigned long swapped = 0; + unsigned long max = end - 1; rcu_read_lock(); - xas_for_each(&xas, page, end - 1) { + xas_for_each(&xas, page, max) { if (xas_retry(&xas, page)) continue; if (xa_is_value(page)) swapped++; - + if (xas.xa_index == max) + break; if (need_resched()) { xas_pause(&xas); cond_resched_rcu();