From patchwork Sat Sep 14 19:41:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13804546 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 DBECEC021AF for ; Sat, 14 Sep 2024 19:43:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0E7B6B007B; Sat, 14 Sep 2024 15:43:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9BE7F6B0082; Sat, 14 Sep 2024 15:43:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 885E86B0083; Sat, 14 Sep 2024 15:43:34 -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 6B7956B007B for ; Sat, 14 Sep 2024 15:43:34 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DBDD01A0A15 for ; Sat, 14 Sep 2024 19:43:33 +0000 (UTC) X-FDA: 82564368306.01.D8E8EF1 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf09.hostedemail.com (Postfix) with ESMTP id 17932140003 for ; Sat, 14 Sep 2024 19:43:31 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QgSzILIp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726342892; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lMqUitFjkcZcjYpS18hn6NOxdl1sw7VhZop5Rjz/ORE=; b=yHnQTjNu5otdcBqr2lcwYDl8e+ally5tHhBfYuDACTYmT9s/+Jbh/zrnADxEwW1Uqx7fYO i9+h5lUVrMNr5qQB4Srx76pg5XBfFJ4maBh6hcICfjoxjdOlxqn1ClNHBnaZKffcCiZybT TpSiqEAEXwRSaDZv0Dj7rSxvaf9c8xc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726342892; a=rsa-sha256; cv=none; b=NEI7aatSBPpsEjXlaA4ZK/fU0NKpwSoDuaRmaealDuzTQ3rrftwtHKVoszKWlWE6gqtuk6 oGR367o7SZ7VwUrfjIDCYoQ763ClOk1caf5bdz59HF3NfF482jbu8AQELv8BisD3byIngM puOuLhsjgkSCQ5hhvme0pnjmyCw5JWA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QgSzILIp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7191df6b5f5so2332437b3a.0 for ; Sat, 14 Sep 2024 12:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726343011; x=1726947811; darn=kvack.org; 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=lMqUitFjkcZcjYpS18hn6NOxdl1sw7VhZop5Rjz/ORE=; b=QgSzILIp846BDkF+LU58FCwS3l0bcaA9juUQ+8JTFWgZkzvO2rThXnS7Xcuba+JAZs axY7v5foeDkJqfV43g7FvylsRWgJ1iuT+n8oF8Dkcxhz1bwU0LUy0+4KJrBkGZ6yU/5W Odj1DlMQhqFknoYrocI6EvfZ2gKg/2Ry9dxW6NMM6oKnWlkS/TyE1e3jNnGHy2L0QbAe s/k/8S3NdqApWmB+afu5iMu3jxuE7WMEZM2mJe8kBRt4b7rpiJoFZDwqSyvEt73SbCBm HcLPj0gjf7YUYCaOSopqEZB2++n1TEsfJY3aBzKxPswN6oK73MTpyqapNNVGtdlAdmcH T7VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726343011; x=1726947811; 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=lMqUitFjkcZcjYpS18hn6NOxdl1sw7VhZop5Rjz/ORE=; b=nhOh9ou4wst0rAV3+7zSKFrzYuREAxgQWLvDEKyn1jB+o9u0dIOCfbZS0YNkh6T5dR rCw6Y9WkeaD5o3OoURvFh3ALm+esrKcNpIdCVcN0Bbv734VUs7JB1/kl4HDxIp17WKb3 fLdsAKeXknHW8kPpLyU2nSsIFo0j2l5yycNv9epZMIQMvbIiQCaWI95R1P4ZyJ5HNKzS JJQ00yB0ezl+wIm1n1sSRvAdapcPFa9ZtP3JKnVyBns3YABnqeV86CTRYSpl72IsUmKT T7cm22hpFYEL3vl462R9uSPQfGBoUiCgTynSG0OlTlpAXTbdGagnH+QrX3xq8f02VSWS VoHg== X-Forwarded-Encrypted: i=1; AJvYcCWiq0TpvTT6gcBlwVcsGF/ZMwSCfu/N0/wCNsmPaAsouxAl0J0wi0o8eZ4C3IGlZplz+tOirF1bOA==@kvack.org X-Gm-Message-State: AOJu0YwLJpUq84KDEPFInupv/Tcs17k6J3B9h0/PM5w0RM7j/vqsAcBq vWbDQ6QepSJX1QYIGn1PC95wTAqjRtpz5QOuxiFzezwk1SXd4JO9 X-Google-Smtp-Source: AGHT+IGbSz5ZrbkdFVY2/IUM0yAh9WDYo41O7oqGgog7gsBuZxxoqHgZ7U8FgzUcNxgXkrRlAxoFeQ== X-Received: by 2002:a05:6a21:4a41:b0:1cf:3b0b:d723 with SMTP id adf61e73a8af0-1cf75c7ed30mr14321637637.8.1726343010479; Sat, 14 Sep 2024 12:43:30 -0700 (PDT) Received: from localhost.localdomain (c-67-164-59-41.hsd1.ca.comcast.net. [67.164.59.41]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-71944a9cab5sm1294742b3a.5.2024.09.14.12.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Sep 2024 12:43:29 -0700 (PDT) From: "Vishal Moola (Oracle)" To: Muchun Song , syzbot , Andrew Morton , LKML , Linux Memory Management List , syzkaller-bugs@googlegroups.com Cc: "Vishal Moola (Oracle)" Subject: [PATCH 1/2] mm: Change vmf_anon_prepare() to __vmf_anon_prepare() Date: Sat, 14 Sep 2024 12:41:18 -0700 Message-ID: <20240914194243.245-1-vishal.moola@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <7B2E5B76-8FC6-49EA-B0B3-2452ED6ABC5D@linux.dev> References: <7B2E5B76-8FC6-49EA-B0B3-2452ED6ABC5D@linux.dev> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 17932140003 X-Stat-Signature: ayypsqdzoubfffqwempyf6zdtnuqnbxa X-Rspam-User: X-HE-Tag: 1726343011-752017 X-HE-Meta: U2FsdGVkX19cc4is8VU/qYfqsiw/jDuKTHolVyu3qRb3ZheSKYT610BuYEqVhUKaany5NydG/9HdnESwvdyCv0eygp1kk+N57zGSefRHr1oiCCHzm9WPh1j1wZ9rMnpuGlLGcLgbUoSNF9MsNpC3PHeOR4QR3d9C+cXmVAvuLSS41Ltmhmpvbwtr+zreJpHeSZzG+/IKkfb3ZIXjkfLimm27G9PF5eMl+AvXEPQhaKLZ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vUDUliGPEFO+oKX6JHpaoDeVhNGT9+U/+w0m5mLXFNZEdkBws7HXKmAISUVkLjdHgvKLkbaX9SxeZy4ceg6Di7k1VIEenJtUsK17JJ5EkD7XVHXKMH1MbsG3+3wZ73AJvxX7ZIvaVavHYNtJj5DdCx/4fdX+9LNtBzKR0n8xecNFeurEMciTZ3K2Pg52Rvo/Tn6QNfOjnMTh8xsDiGTfcou5GqJKQWpYuhmMLWgIgjwFuOes/h45+SGBkc/rzIyNc+cmk6SV4tV5d85c6N5HxbcAl 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: List-Subscribe: List-Unsubscribe: Some callers of vmf_anon_prepare() may not want us to release the per-VMA lock ourselves. Rename vmf_anon_prepare() to __vmf_anon_prepare() and let the callers drop the lock when desired. Also, make vmf_anon_prepare() a wrapper that releases the per-VMA lock itself for any callers that don't care. This is in preparation to fix this bug reported by syzbot: https://lore.kernel.org/linux-mm/00000000000067c20b06219fbc26@google.com/ Signed-off-by: Vishal Moola (Oracle) --- mm/internal.h | 11 ++++++++++- mm/memory.c | 8 +++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 44c8dec1f0d7..93083bbeeefa 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -320,7 +320,16 @@ static inline void wake_throttle_isolated(pg_data_t *pgdat) wake_up(wqh); } -vm_fault_t vmf_anon_prepare(struct vm_fault *vmf); +vm_fault_t __vmf_anon_prepare(struct vm_fault *vmf); +static inline vm_fault_t vmf_anon_prepare(struct vm_fault *vmf) +{ + vm_fault_t ret = __vmf_anon_prepare(vmf); + + if (unlikely(ret & VM_FAULT_RETRY)) + vma_end_read(vmf->vma); + return ret; +} + vm_fault_t do_swap_page(struct vm_fault *vmf); void folio_rotate_reclaimable(struct folio *folio); bool __folio_end_writeback(struct folio *folio); diff --git a/mm/memory.c b/mm/memory.c index 36f655eb66c4..d564737255f8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3262,7 +3262,7 @@ static inline vm_fault_t vmf_can_call_fault(const struct vm_fault *vmf) } /** - * vmf_anon_prepare - Prepare to handle an anonymous fault. + * __vmf_anon_prepare - Prepare to handle an anonymous fault. * @vmf: The vm_fault descriptor passed from the fault handler. * * When preparing to insert an anonymous page into a VMA from a @@ -3276,7 +3276,7 @@ static inline vm_fault_t vmf_can_call_fault(const struct vm_fault *vmf) * Return: 0 if fault handling can proceed. Any other value should be * returned to the caller. */ -vm_fault_t vmf_anon_prepare(struct vm_fault *vmf) +vm_fault_t __vmf_anon_prepare(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; vm_fault_t ret = 0; @@ -3284,10 +3284,8 @@ vm_fault_t vmf_anon_prepare(struct vm_fault *vmf) if (likely(vma->anon_vma)) return 0; if (vmf->flags & FAULT_FLAG_VMA_LOCK) { - if (!mmap_read_trylock(vma->vm_mm)) { - vma_end_read(vma); + if (!mmap_read_trylock(vma->vm_mm)) return VM_FAULT_RETRY; - } } if (__anon_vma_prepare(vma)) ret = VM_FAULT_OOM;