From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11E9C154C05 for ; Thu, 9 Jan 2025 02:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736390472; cv=none; b=OADTWJkQI64Wl4h+KKZ5F2hcwNSqWi5vRAQcb4L7xUaA6SefWw24WFR5Cq5d9Jho2GKgSsvywFJN2IFPQUBqY/nABO+SoIC9ISIS6uRY10+LB4zV8131bztm5nhG4uMgfC9oK484r20ANb/sSFv6jpx3dCgN4+CUSj19s41j/kg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736390472; c=relaxed/simple; bh=5Z00di/YHk03x71nRTYN63Qszagb3+/dvDD4xgeRJFw=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=tt8LAGse5Q0lmpzD8gRb6JNp/6HSRPMqe10hGGuTyEDT+DVSCOCiTeUjtYLBRxyxmB7oqFjr69vCIJfEHiMKdmRpYKnqoDh4fqEWvFjPExr5nj34D3UCJ9SaQ6YSnxgDflEcxaq34Lbkj34BLXXfPixV+pr1BGofGZaIKbA8ps0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ljCttWWw; arc=none smtp.client-ip=95.215.58.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ljCttWWw" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1736390466; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IlED6M0hl6FWbiy+Jum74yPg5nWZUNQfGEB25PnRo/U=; b=ljCttWWwqBY4ZUWbEeatUmg92tHJr4W6WPAPphxVZQK6L6Eq30fvihjuTXYaju1gW2JW3j JHchoeqHIDxTwez/Dmeo2WoIcJZptoYQNA+PrRB8xziw2USSaT/Y+IRFg7GRcrKLZamSVc pRJowArkSEKAP2sn5L84/5s9V79m0Yo= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.200.121\)) Subject: Re: [PATCH mm-unstable v2] mm/hugetlb_vmemmap: fix memory loads ordering X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20250108074822.722696-1-yuzhao@google.com> Date: Thu, 9 Jan 2025 10:40:26 +0800 Cc: Andrew Morton , David Hildenbrand , Mateusz Guzik , "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Will Deacon Content-Transfer-Encoding: quoted-printable Message-Id: <4D77AD25-6DC2-406D-9D54-9032F38260B4@linux.dev> References: <20250108074822.722696-1-yuzhao@google.com> To: Yu Zhao X-Migadu-Flow: FLOW_OUT > On Jan 8, 2025, at 15:48, Yu Zhao wrote: >=20 > Using x86_64 as an example, for a 32KB struct page[] area describing a > 2MB hugeTLB, HVO reduces the area to 4KB by the following steps: > 1. Split the (r/w vmemmap) PMD mapping the area into 512 (r/w) PTEs; > 2. For the 8 PTEs mapping the area, remap PTE 1-7 to the page mapped > by PTE 0, and at the same time change the permission from r/w to > r/o; > 3. Free the pages PTE 1-7 used to map, hence the reduction from 32KB > to 4KB. >=20 > However, the following race can happen due to improperly memory loads > ordering: > CPU 1 (HVO) CPU 2 (speculative PFN walker) >=20 > page_ref_freeze() > synchronize_rcu() > rcu_read_lock() > page_is_fake_head() is false > vmemmap_remap_pte() > XXX: struct page[] becomes r/o >=20 > page_ref_unfreeze() > page_ref_count() is not zero >=20 > atomic_add_unless(&page->_refcount) > XXX: try to modify r/o struct page[] >=20 > Specifically, page_is_fake_head() must be ordered after > page_ref_count() on CPU 2 so that it can only return true for this > case, to avoid the later attempt to modify r/o struct page[]. >=20 > This patch adds the missing memory barrier and makes the tests on > page_is_fake_head() and page_ref_count() done in the proper order. >=20 > Fixes: bd225530a4c7 ("mm/hugetlb_vmemmap: fix race with speculative = PFN walkers") > Reported-by: Will Deacon > Closes: = https://lore.kernel.org/20241128142028.GA3506@willie-the-truck/ > Signed-off-by: Yu Zhao Reviewed-by: Muchun Song Thanks.