From patchwork Mon Mar 11 19:43:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13589298 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 0DD8CC5475B for ; Mon, 11 Mar 2024 19:43:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9411A8D0006; Mon, 11 Mar 2024 15:43:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CA8B8D0002; Mon, 11 Mar 2024 15:43:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76A538D0006; Mon, 11 Mar 2024 15:43:51 -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 6137C8D0002 for ; Mon, 11 Mar 2024 15:43:51 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EEF1240519 for ; Mon, 11 Mar 2024 19:43:50 +0000 (UTC) X-FDA: 81885783420.05.7321044 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf26.hostedemail.com (Postfix) with ESMTP id 6F1EB140004 for ; Mon, 11 Mar 2024 19:43:49 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Enwo3Ce5; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 39F7vZQoKCKUdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=39F7vZQoKCKUdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710186229; 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=o6UJtu1HH16m2XbkBIYqvJ1tQp9TP2uMiQKdHkNHJvQ=; b=rih+O3VUBL0nSwMTdM6nvcQ88hrmraxoZHeV5w8ksU/iY7IYvX9ygsEK9O70AnYErFEbuy B0Zh3NVJmaQ0I7JGUxEDFRaXoHeu+Vym7Jhmnm8WZWjGNT+d859dBcIMETr6bSikMQ4poF ZNTl/pRLIBBA76QmuE4UzHL9vvX5F2o= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Enwo3Ce5; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 39F7vZQoKCKUdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=39F7vZQoKCKUdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710186229; a=rsa-sha256; cv=none; b=iuH4nDNpM50idwPT76oLqhZyQFzQRqpwu/7yUPitjUIjxLZqiQxWZCtEu2z0emx+pHw8ME T3PGYFs2WfgMx4ckYRybVIb4ZBI4FP1cRmsMKizaTXqm9Feo5QNfQ2mps5jBi+f53GEdp4 Bi32zOEDlQjn7whh7uScAvBf0xawybo= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60a08eb0956so47452967b3.3 for ; Mon, 11 Mar 2024 12:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710186228; x=1710791028; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=o6UJtu1HH16m2XbkBIYqvJ1tQp9TP2uMiQKdHkNHJvQ=; b=Enwo3Ce5n0AAm77fllzodEsGth5fGEVu9WTASd7Bai0sK9QCciIOxlTgHYsNfx4QfH A/TXwNPfXOpa0EhsAf3gfT1S8SWJjN8XdzXR+H184OcxYIUinXZGS/PEvwnWwvTGUu4c mvCHXR2OCaJJec6aGPCdj/Qr9iHYlPxj9ZiIBdsS6n7Qm4RCUwUthHVcF4ZpjHv4R84n dSp/T9NJZMsbGbhx2dOKV9lI+XEXj7NDXPQT7HdFImMqA4mT7VF6ArcYOspez+B5qZPH 5imme6cQ3Uq3eScMpIOP6ph3nXbb6t9hM2BwvjQ+7hKCYbokmQlCwD62159yhMJhd/fU YH6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710186228; x=1710791028; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=o6UJtu1HH16m2XbkBIYqvJ1tQp9TP2uMiQKdHkNHJvQ=; b=wr58Gg5j18cGPpMmew+koottLNFD7jC234mtGuExx6+Y7SWML8th1oqygjl/gbAfM7 TS3wu3Bp07gYjkTMKriO0U0TS8fOnqWViX1f6vggmG4ogJ8LQ1Lk56lNCfxhGy9Gr4bw VdSCUAl7mKx2RF1KBtaFRT5eF5pXOE0VIdpqUO84XC7VMKDz+2M3Xb5eLyhqG9eV1uyY 2nlgQwxjB9KRbfX+dPrHf/9K4zc8b9d4TEB0Je5eio9krCV9tnAgKS3dkxGamzor7oOR d1XZNR7+VTFu8bXn0RRpKN6rm+dsEJqStcRDTli+ySAfzZbt2zLEQxecp9KpfN0CDxdz 9I/A== X-Gm-Message-State: AOJu0YyNt+yFzyji/lZzGJxV1mnfG9IDyJ41Sj/JkebSGC/tmncSZLvM DvBBP27mVjDa4VUpTxCr8QNfMoFkvTWE9iYPyl38Rm5aVHMQlfIKADEIq/syYDQQx4bXIcqghEI DWBc/I4xvwRORt2yRvg== X-Google-Smtp-Source: AGHT+IEjE4RPBh2h1ZjpLGnSOpuQW3myo032wQ/NGNsdybflZDgTA9lg25piUM2Q2N+xBQnJoHArMT+oFGdf8EMZ X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:f02:b0:dcd:2f2d:7a0f with SMTP id et2-20020a0569020f0200b00dcd2f2d7a0fmr387205ybb.9.1710186228508; Mon, 11 Mar 2024 12:43:48 -0700 (PDT) Date: Mon, 11 Mar 2024 19:43:46 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240311194346.2291333-1-yosryahmed@google.com> Subject: [PATCH] percpu: clean up all mappings when pcpu_map_pages() fails From: Yosry Ahmed To: Dennis Zhou , Tejun Heo , Christoph Lameter , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspam-User: X-Stat-Signature: pbpwbtyq8ko1bqz3krqzg1873irfntkq X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6F1EB140004 X-HE-Tag: 1710186229-508856 X-HE-Meta: U2FsdGVkX1+CyMPrfIZuPyfYlvENTKJyOrtIXaDe5Yvdai2xkdzxHVuPO3SpcwiWlIGjqJHkgOZW0Llx92x8ecoy99KRJa/sIqDB+UHCPoC+wxLjd26GrIsS0M4aFpfQmNKvjsU3oNifSqmj33X2ASOof4HCBFIDbNKYUn5gAWV9BWzq1S/uPfeoWO73VPaCZX02Ym6A217wZ258Oi5rXCEvLM/01RuMzH4SNLedNxseERpeNVh1mhaI/xXrWZ5rSl/oUBmOzKv22gv/azn9hY7/r5Pgq/4mmgDnuSbb7iNeBa152Smt/yiYslpvwjx5mV6J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ir15S6nxxmpSr9/SXpgMofOb+FHsPDhmJqA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.005164, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In pcpu_map_pages(), if __pcpu_map_pages() fails on a CPU, we call __pcpu_unmap_pages() to clean up mappings on all CPUs where mappings were created, but not on the CPU where __pcpu_map_pages() fails. __pcpu_map_pages() and __pcpu_unmap_pages() are wrappers around vmap_pages_range_noflush() and vunmap_range_noflush(). All other callers of vmap_pages_range_noflush() call vunmap_range_noflush() when mapping fails, except pcpu_map_pages(). The reason could be that partial mappings may be left behind from a failed mapping attempt. Call __pcpu_unmap_pages() for the failed CPU as well in pcpu_map_pages(). This was found by code inspection, no failures or bugs were observed. Signed-off-by: Yosry Ahmed Acked-by: Dennis Zhou --- Perhaps the reason __pcpu_unmap_pages() is not currently being called for the failed CPU is that the size and alignment requirements make sure we never leave any partial mappings behind? I have no idea. Nonetheless, I think we want this change as that could be fragile, and is inconsistent with other callers. --- mm/percpu-vm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c index 2054c9213c433..cd69caf6aa8d8 100644 --- a/mm/percpu-vm.c +++ b/mm/percpu-vm.c @@ -231,10 +231,10 @@ static int pcpu_map_pages(struct pcpu_chunk *chunk, return 0; err: for_each_possible_cpu(tcpu) { - if (tcpu == cpu) - break; __pcpu_unmap_pages(pcpu_chunk_addr(chunk, tcpu, page_start), page_end - page_start); + if (tcpu == cpu) + break; } pcpu_post_unmap_tlb_flush(chunk, page_start, page_end); return err;