From patchwork Mon Feb 5 19:18:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13546070 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 A6023C48292 for ; Mon, 5 Feb 2024 19:19:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3BBDC6B0080; Mon, 5 Feb 2024 14:19:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 36B7C6B0081; Mon, 5 Feb 2024 14:19:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25A046B0082; Mon, 5 Feb 2024 14:19:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1740A6B0080 for ; Mon, 5 Feb 2024 14:19:00 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 903C5C021A for ; Mon, 5 Feb 2024 19:18:59 +0000 (UTC) X-FDA: 81758712798.14.A03081B Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf17.hostedemail.com (Postfix) with ESMTP id CF7C840007 for ; Mon, 5 Feb 2024 19:18:57 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=breno.debian@gmail.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707160737; 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:references; bh=dWo//23UNgHLh4YlpYiYx7hMvmjaebYbXFXXNlcC930=; b=LE+HcKXSWijYhtg/E0v2P3lO3d1twdLUPMo6uqtAE4RS+vKnQSRmqBXO8YbXIJwJ1XaED/ Wff87zIhcFpAvcHqrtomAbbIiCootnU75/JC7IK2bA/sJUDyhEUXyCHDK76L2Crr7xsIJG IPLOXr+TG8PGDYUVtgah3gDcFfrvOPo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707160737; a=rsa-sha256; cv=none; b=na3ZSuNwe+IxWlwLm2IchN3e2uvO/wEPgmhsxKy3PldN51gg2DKM6rjBcjJTqYwe8WnlKx +PEv7KoWbux7butE9fX2PCSoTk5dnh6rehCaLi5LKuQIIiZidp74DKMA2qFKz85DL6qQVd 7Fs09JfnRS8TGueTTx/Z9BYUbx7BqMU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=breno.debian@gmail.com; dmarc=none Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a26ed1e05c7so666813066b.2 for ; Mon, 05 Feb 2024 11:18:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707160736; x=1707765536; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dWo//23UNgHLh4YlpYiYx7hMvmjaebYbXFXXNlcC930=; b=AlEXwvPX0qD39R0SH9c9Sa1lU9kCt1QOwsNI6+xhwTEmKyoyhl+F4QNU9py8ugi1qw FDkmXg5zwUSUKvlL40em0zL5iD7KamNlTjj+sBH7diKM0G29MlI1YUalZJBxewNnnwpT FgARbkkICW1GamO8G/ftnVgdyi/Zuic+B0XDMj6YoOaMqZc1IDAPBbKgmluVpjknk2r5 x6ptvPvY2oYTMChW75m2G7zKRCkapeqJRfoMo2lSvupXDlPCGmxr5Pu5feZpJLTr9T4o PnWi/jMhkbO3XXPdNsh0JUZt1PB/yD0hp4g4OhVyvVJSMkRMkK3MBaO6SOZ+3eV4+Tqm 2uyw== X-Gm-Message-State: AOJu0YwwEDl9aeyTO8g3B7hx/B0fVS0KwLINoCTQxb57Tgpm/XiKzgW/ sV7EFFtf30BmMm3wx80qGnXH/oqDjmP17692koID6zQBZfKMYaZCLgj7icZLFns= X-Google-Smtp-Source: AGHT+IFJVJGFgzRP+JaCEmQBc6TWhCiJzh1skkZ70pPkTz2uMwB7wUZVtWtShQrHjEG7KDUUk9q3Dg== X-Received: by 2002:a17:907:2cd8:b0:a37:2c8f:f605 with SMTP id hg24-20020a1709072cd800b00a372c8ff605mr226983ejc.75.1707160736219; Mon, 05 Feb 2024 11:18:56 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVZvlIdAv+MhPs4qzcEzvnoVUzK7+u6M9FOC1fvWg/yZXEkctPC5uNwEIjIvbUvI/Hi7sDpAqGoU9cdH3EKVPoNRrSiqW5qINM/IFETVsbD+uEJRV7E59I45wG40opcJiWt1JtNkea+Hh5e/VjLrAGGQsyFDCttvU/Q60KcVmm/zdQgiZfH9EvXSOHTkq+0wgUI6dzJz+QkVn/EhHRJ+sWwmYBIRd3+mgyjWn7umFJ0C5MouDVD9eTfcWEKZEREaRaAR+NmCO47rcSy0/3xgr3JLEcs39ayGC/AKq1qzU/QzQo20IvtG5Ij Received: from localhost (fwdproxy-cln-119.fbsv.net. [2a03:2880:31ff:77::face:b00c]) by smtp.gmail.com with ESMTPSA id c1-20020a170906d18100b00a367cf97b40sm156860ejz.131.2024.02.05.11.18.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 11:18:55 -0800 (PST) From: Breno Leitao To: mike.kravetz@oracle.com, linux-mm@kvack.org, akpm@linux-foundation.org, muchun.song@linux.dev Cc: lstoakes@gmail.com, willy@infradead.org, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 0/2] mm/hugetlb: Restore the reservation Date: Mon, 5 Feb 2024 11:18:40 -0800 Message-Id: <20240205191843.4009640-1-leitao@debian.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Stat-Signature: zcbaazgm4f1g98upc69uq59ogshzj445 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: CF7C840007 X-Rspam-User: X-HE-Tag: 1707160737-851797 X-HE-Meta: U2FsdGVkX18V3zDtSFBOn1jLqG9K0gK/hs1viRGWI3k243scw64kD/acDw6lyB8ZvjgTleMrzxnr8X3/UGGRTdOywjVVlDcwV753mB1SB/gq2uLThMrxrehlh/UmP6Hpg3LTd4AZX+MHSBDbwBhht2c64eCZTTQp54RklDFj2NhRQJ4oYTVBCR9DfvoVpQyjn2l1l18MJwMV2Re7hzsn8J+y+UcEMemnw5QFNt7LyInpwtLeOofZ6ON308Hugc7lX1zP24t287BqvD6f4JWgUBCW9vkab3yny+sd1gZVN6oSBTGSkdqvOPEzqCT37ibxdKCgFhui39mGFrJxn9E5E0woy+l2u1g7tdg/WvZtQpI2rzEYxZGkcnhK1Und+qUQYlkjWP8FPdyJWNDDsTAUGM8Tw3y/0jlFSy10NTifJ8EuWyC7VCUJoJWdJbYnPC1pOdJEBgkOD9IExsEEUYLNtFpXuPNqRjqpvtTpfFRbNEonud62GF5Vp6pr1mY+cCnhO3KOdQnxHEejwhW8CcWGZ5NyXc93ryOK+m94eK7wu0wMoPrbC3pSVkPqIp43caXXlm5QCEciMyK1SXHJ4ECKRoRbJcCAQuK/gQr/A1zYSb72lfK0/5NZLYmT82Tg2/qauz2C1pvFeoz5D0+VMCSmWtxaf2IT/BhZxvYFfPolbtdTUbs9CmTMP2q5R+XRNITUSH5h2dkSwCOz3N0altLHDkAZrb6V1kPDplacdBl8CIiAFuJ4vujzslALhEHiVECk/x0cU5mE+LyKXadqARBu9+pWBhKgYhjmMwFifCaH3LxvQ1B7LseqVOHplqnkISRLfvHc7YAB1eKMMpTtpjZN2VmEytplx7DbriU2HaXbBjAoZxXRmpzsGBXBpoZdEqmVa1VKyR5ogkWUfI6xXkdZZ48RfRKamp137kq9oCMTsaiUEc54yKgJL4sHF+rYdsiaYayxv+fgasmtlmHW3T8 YU0c/diZ 01OzqKpzql7R1HPynrF+lmT9YRU241ZbhlcqgydFajasgC9ODaSZq/Q+ntyCCu8FN6Lnx5HLlgpke+tYgRRurSdgr5vsBVv1RVJZ9BjrGPmdAmL1jadklGxX5h6gxVcX2srY9hKPFZS1VmSnRoaYFDHZZH52N8jwDFA3tXxbbJioJSwGw82eX/G4AN1cs/D0/dh5oITRb0u5/Qz5YzU++1P7G0XTF7ZG1G3n7n2/2UNaofKbK9/5wk0e0qpADDz3jCVnksq7u9sGJp/Iapd8j09fxwccXJz5ia+2p6Q4gnNgMEc3cp8DHdIWvvOaMHgMWPkHkfdPL7JHr+QoHE/ce+/U37731VRAoFHYdvACwWCjcm1h1KZLDALD2Y4fOWeU1EY0rbf3pcSZ2l4XGyNOxV3Cg6EarZ5tR4P8f9tcNZtZejkUARtqg9Yp4vKTdqSZq6eEoHKhUmb1ycF/lyDzcy2PPwQlTYtaJKLS2IykYgV0BaBysNWKTV0sJW0SRshocgZfxFeFF7lbbpxQemMM3r/6DLw== 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: This is a fix for a case where a backing huge page could stolen after madvise(MADV_DONTNEED). A full reproducer is in selftest. See https://lore.kernel.org/all/20240105155419.1939484-1-leitao@debian.org/ v1: * https://lore.kernel.org/all/20240117171058.2192286-1-leitao@debian.org/ v2: * In version 1, there was a lockdep dependency detected by syzbot. * https://lore.kernel.org/all/00000000000050a2fb060fdc478c@google.com/ * The lockdep dependency was caused because `vma_add_reservation()` was called with the pte lock. This is fixed now by deferring the vma_add_reservation() to after the spinlock. * Version 2 fixes the problem above by setting the restore_reserve bit inside the ptl, but, calling vma_add_reservation() later, after the lock is released. * Reported by a test done by Ryan Roberts. In order to test this patch, I instrumented the kernel with LOCKDEP and KASAN, and run the following tests, without any regression: * The self test that reproduces the problem * All mm hugetlb selftests SUMMARY: PASS=9 SKIP=0 FAIL=0 * All libhugetlbfs tests PASS: 0 86 FAIL: 0 0 Breno Leitao (2): mm/hugetlb: Restore the reservation if needed selftests/mm: run_vmtests.sh: add hugetlb_madv_vs_map mm/hugetlb.c | 25 +++++++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 1 + 2 files changed, 26 insertions(+)