Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1462178lqt; Wed, 20 Mar 2024 05:03:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWNq73u8wH9gB0agnwDp4QKA/aKIY/jnJnN41yH5Um6Xtvn8eZRYjPzPW+wVXOPA8L4Dk0Pc+HkYF0LLh3lND1mmAsTJeI/SHPS6mN6sw== X-Google-Smtp-Source: AGHT+IEvhzvM9LS1RvzdMaFQBaOcZGxoVfMDQB2/0XmS8iXrN2/+WIs2BhMes70rrC2PKbF5kd6Q X-Received: by 2002:ac2:4db7:0:b0:513:cc4f:52b8 with SMTP id h23-20020ac24db7000000b00513cc4f52b8mr13941017lfe.12.1710936204264; Wed, 20 Mar 2024 05:03:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710936204; cv=pass; d=google.com; s=arc-20160816; b=W8N5pKNcIa4FIXFniS14MUT21PDx6Zf13rf9e/j0qvKwVXObGYPWJTOBwjKusO3ctN csdrIkadou5L/wmMQr+CNJ0ovEAUHVOQgtAtlVZrWimc+tTlLRLt6ovBbmD6DQm+szOB 5vVJoOOlDloe1UX0t19d5DDLoybt78D9/RwYHIiyZJDkgRlIKRinvMfvEXk0Ajd5nLFK EJnzw+6nQmCPlgYdpCEPxdl9AzLhxUT69zxjYxA7g+uoM2juT/qe97YglbGVIiwYZFav zT1PS8NEAcicwMQ2WQa78NkMBZ3PsQ8/e/TXdVMyJa63ROSefO3OxpLLO7losBakE0KA jfbw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=Rjyl0RsxCiR3BnHPMVorROqGtL6yCk3lVv5lYb3r+gY=; fh=qLToLdMHqpM7Ma6tALpvdBNgwpQh9ljKkiVaP6mzF/U=; b=071z8v+mqFM5fG4DKGT6SPTfk3Me1n1Eucjlr35+GrdXS1LaofLmDkT2ylHmsIT557 rr1kMSv5bI1mNddEuZv3GIVNeWEbRiYmPg4iBJwURV7SQEuibmbE9XuAtZ9IT150zaVG lZ/o4pmz01mt4rINJslSojcvQBy8BddicgVVPjX2kVM8+YgN3ofFAKiW+TXgdOwCIgo1 qu7gmSUqzDBWG5MdXflMd/QrYAkOtjWuD+S5ck6B38HN2QDOJ+E3NQz9lvFORyina8Fy Y9yxW3i88ZNnfqCeJE01bCX03LJ7Hek4PbM6D02rBGllMXi46rSAo0Lfl/OtmXeSRbZm 9o2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ie4uKGyi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-108890-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108890-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id fe11-20020a056402390b00b00568b0dfec82si5239537edb.578.2024.03.20.05.03.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 05:03:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108890-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ie4uKGyi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-108890-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108890-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id ED4341F24508 for ; Wed, 20 Mar 2024 12:03:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 533713F9F8; Wed, 20 Mar 2024 12:03:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ie4uKGyi" Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 022DC3EA9C for ; Wed, 20 Mar 2024 12:03:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710936196; cv=none; b=U5AoFtWC61n0FTfNdbxCTjolEijbOnuKmHE8qLplk4O0/T9m6CNx0sM8yzvUki9CldNzuC5n7DXJqMFD846P4Y4JSybHLUikpRuem9IkYyebz3ppJGkz85ReFqsVtaztHBasnIlhloOkevsliYu7VbI4DIyHfpTqx5C3CHUTJxU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710936196; c=relaxed/simple; bh=Ph5Y3t4V9Ilh9TejaQuF5yjKbwO0v7oIAU5fLicb7V0=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=I+JUvKg6MZAFDYI2Vh6PGWl6IU2/GQLcndf/W5V6odXdH/WYtNFwcaCtH/vD4/bPKovSuF/07kFP54KfpeDoKl3Hjy2hII6c20mOTpJASS98IbKYgjtRG2C5JHidSiEFCcDrvLwqJeLryCQRSm92VC9n3fLtFQxJVwkON2GF978= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ie4uKGyi; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6e8f765146fso252638b3a.0 for ; Wed, 20 Mar 2024 05:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710936194; x=1711540994; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Rjyl0RsxCiR3BnHPMVorROqGtL6yCk3lVv5lYb3r+gY=; b=Ie4uKGyi7wJumF8OLxNBnjeKAMpE+V7WrMSEL9aHOLWvMHMbaGMURXsA/97UNMqG0W v91/OHZnpaoztL/Ml2H+gT2gI7n+AHqM4l0aV0rN8WTIuUWDOwxGzQLp6SXWb9zjUI+C zmYSm+VH5ZIn2/UpgtRo4ooz+6dDVX9ce4yOzcCEcSXBkdmoqu4sqEnErQizRO/+PsNl RBAQqxQ0tpT2AeVY4IDoYy/QPCHLgSvupaRHbbDvF3ed4qyrYYYVH6n3sgo9Q1m4WfUM ot+GoX3CtazhZk3HERJmZiV6eY+Bsqd8C/YAPcEowZDhf+O2Lq7nT2RQVT2IV5a/5twU dACA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710936194; x=1711540994; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Rjyl0RsxCiR3BnHPMVorROqGtL6yCk3lVv5lYb3r+gY=; b=sITTpi/Di0myuXRt6GNjfsPV4VU1ySrVriNpWxdZD/KmZcD4U6wCeR/t6JOzImNPzt LQbkR+Bm/WwRC8/x0FVUgwDlHHOuoI8eW5fdmKaM3MF/es1sGPM/QdO/6qxGWVrTunmA rGYq8DB1i7rJJENpfGWe0uO1s0Z/a5vUjgNngg3HKhkDHMdYXifCKvsRgWWXsSZQXRYR iFO6oSrzYr9wop45ceJDtsWMOI+uQXgLfAUAdCOUoTEmPMxX9OdNgKwzv2EPcoRSuY+v JQYOlo3WOLrskwEYcDDtEs3Vz3xayWBa/yWtREfY+dcNEkJcupKsPuM/KDw1VNHOTNEo tI8Q== X-Forwarded-Encrypted: i=1; AJvYcCXdCPJgObqdukFdNCaERWZBhMu0ShTfs8rlkcbm/uR5i/LzA61BHGRTbDCVCgFiBHbZPpQtBVMGRW5PgLLdH+rgXyNI5MnEHMuqqi5r X-Gm-Message-State: AOJu0YzwXAcK+GftdVDs+FlABxHOaw3Jy6Tplqi1t3gcSN/onpIH33u/ /JdjYwS4U/Blb5tOh73+QoNBtgjOKG1/iq3qxvAkeO6YmLHK40az X-Received: by 2002:a05:6a00:2284:b0:6e7:821b:e972 with SMTP id f4-20020a056a00228400b006e7821be972mr1811564pfe.29.1710936194212; Wed, 20 Mar 2024 05:03:14 -0700 (PDT) Received: from [192.168.255.10] ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id h25-20020a62b419000000b006e739e09504sm3925090pfn.137.2024.03.20.05.03.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Mar 2024 05:03:13 -0700 (PDT) Message-ID: Date: Wed, 20 Mar 2024 20:03:10 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 01/12] mm/ksm: catch tail page abnormal in page_stable_node Content-Language: en-US To: David Hildenbrand , alexs@kernel.org, kasong@tencent.com, Andrew Morton , "open list:MEMORY MANAGEMENT" , open list References: <20240318121443.3991104-1-alexs@kernel.org> <7a0d7d0e-d241-4942-b6c1-e60d597b3dd6@redhat.com> <54a8ec22-ce00-425c-bb58-54cf8606a362@gmail.com> <280409c6-3479-4c6b-a94e-1d90994917cd@redhat.com> From: Alex Shi In-Reply-To: <280409c6-3479-4c6b-a94e-1d90994917cd@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 3/20/24 5:29 PM, David Hildenbrand wrote: > On 20.03.24 10:05, Alex Shi wrote: >> >> >> On 3/18/24 8:25 PM, David Hildenbrand wrote: >>> On 18.03.24 13:14, alexs@kernel.org wrote: >>>> From: Alex Shi >>>> >>>> commit 19138349ed59 ("mm/migrate: Add folio_migrate_flags()") change the >>>> meaning of func page_stable_node() to check the compound head for tail >>>> 'page' instead of tail page self. >>>> But seems both semantics are same at results, the func always return NULL >>>>    for tail page. So adding a bug monitor here in case of abnormal. >>>> >>>> Signed-off-by: Alex Shi >>>> Cc: Izik Eidus >>>> Cc: Matthew Wilcox >>>> Cc: Andrea Arcangeli >>>> Cc: Hugh Dickins >>>> Cc: Chris Wright >>>> To: linux-kernel@vger.kernel.org >>>> To: linux-mm@kvack.org >>>> To: Andrew Morton >>>> --- >>>>    mm/ksm.c | 7 ++++++- >>>>    1 file changed, 6 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/mm/ksm.c b/mm/ksm.c >>>> index 8c001819cf10..3ff469961927 100644 >>>> --- a/mm/ksm.c >>>> +++ b/mm/ksm.c >>>> @@ -1091,7 +1091,12 @@ static inline struct ksm_stable_node *folio_stable_node(struct folio *folio) >>>>      static inline struct ksm_stable_node *page_stable_node(struct page *page) >>>>    { >>>> -    return folio_stable_node(page_folio(page)); >>>> +    struct ksm_stable_node *node; >>>> + >>>> +    node = folio_stable_node(page_folio(page)); >>>> +    VM_BUG_ON_PAGE(PageTail(page) && node, page); >>> >>> I don't really understand why we would want this. >>> >>> Only KSM folios can have a node in the stable tree. KSM folios cannot be large folios. At that is precisely what folio_stable_node() checks. >>> >>> If we'd have a large folio identify as a KSM folio we'd be in much bigger trouble. >>> >>> >>> Besides, I'm sure you read "22) Do not crash the kernel" in Documentation/process/coding-style.rst >>> >> >> Hi David, >> >> Thanks for comments! >> Forgive my stupidity, I understand KSM stable tree has no compound pages, but when searching a tail page in ksm_do_scan(), why we couldn't be in a race, that another VM doing THP collapse on the same contents pages, while the 3rd vm is doing hugepage spliting? > > We always call cmp_and_merge_page() while holding a reference on the page. > > There, we call page_stable_node() directly and via stable_tree_search()->page_stable_node() on that page. > > When stable_tree_search() returns a kpage, we also hold a reference to that kpage. So calling page_stable_node() on the kpage behaves the same. > > As we are holding page references, pages cannot be split/merged and we should not see any races in page_stable_node(). > > Am I missing something? > > Note that your change would also not help here: if it would be racy, you'd also not reliably catch any tail pages. > > But it should not be racy unless I am missing something. > Hi David, Thanks for the info, I see. BTW, I should cc you for my KSM folio patchset review: https://lore.kernel.org/linux-mm/20240320074049.4130552-2-alexs@kernel.org/ Best regards! Alex