From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 F3B0720DD45 for ; Thu, 23 Jan 2025 09:55:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737626137; cv=none; b=ifKQZQjXgvbxR/ERf+fJgl982vB20/t5TmHNGQ1EAoEN+5iD2XW+e+mcMpIqqkq+r2cgUgkUrxXZ0qQMO8GwgVxf94l/TQOeOM8W3qFvhUWAay3BpXf7+QjZTUr+wuFIkMhB2f4cG+UakSKmPPfF0Uo6KMbPDuwfPPfV8rfT5fY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737626137; c=relaxed/simple; bh=zch9owS6HwU2JCY7MOBPcza8waKd/g50kxNrt8z1QIU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Y6dZHl7S01hkKF1HwwYY9hzomDgJ1d20+qKSGuz5dlz6tQufrgabci63oB+Nk/kW9xqAtlzEZEYlb0iOXHpOoNsv7g94rwCSVYXkmtHmGxcSXoJUz9CAp6AEytQaSLYB66zr9hvg44SQ5Q2olHjJ+IcAsCK+omTzgHHe70UlLUg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=2MJbtIT9; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=682VtZVx; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=2MJbtIT9; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=682VtZVx; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="2MJbtIT9"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="682VtZVx"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="2MJbtIT9"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="682VtZVx" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1979521175; Thu, 23 Jan 2025 09:55:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1737626134; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=q+aYTZUf0dzsT1u/QgGTFJmJGAmzo6stlKHyaCuMmE4=; b=2MJbtIT9w3oyxUG3dtM1RCSDlA+k0yRnL79ESld2exG1Ve9xT7k/glPQo3JNnLwumv4TAR 4CYxQYdoGGfExY1XgnPZj2cpsjNWk8MKDxeqsIsvynDdJbB3oos+44Ai+uXLaZ4japefr7 QqiBE3I64rIZpX8AhZUWxt+VXB+GjLo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1737626134; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=q+aYTZUf0dzsT1u/QgGTFJmJGAmzo6stlKHyaCuMmE4=; b=682VtZVx3vy2gEfmybnBdwbZXWiLj80+hUUq+5tQ6MG774F5fKoe2/Z6tZD99v1ShvDmgY 1oPBQg5czwColBCw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1737626134; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=q+aYTZUf0dzsT1u/QgGTFJmJGAmzo6stlKHyaCuMmE4=; b=2MJbtIT9w3oyxUG3dtM1RCSDlA+k0yRnL79ESld2exG1Ve9xT7k/glPQo3JNnLwumv4TAR 4CYxQYdoGGfExY1XgnPZj2cpsjNWk8MKDxeqsIsvynDdJbB3oos+44Ai+uXLaZ4japefr7 QqiBE3I64rIZpX8AhZUWxt+VXB+GjLo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1737626134; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=q+aYTZUf0dzsT1u/QgGTFJmJGAmzo6stlKHyaCuMmE4=; b=682VtZVx3vy2gEfmybnBdwbZXWiLj80+hUUq+5tQ6MG774F5fKoe2/Z6tZD99v1ShvDmgY 1oPBQg5czwColBCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6E1DE1351A; Thu, 23 Jan 2025 09:55:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Dk60FxUSkme4YQAAD6G6ig (envelope-from ); Thu, 23 Jan 2025 09:55:33 +0000 Date: Thu, 23 Jan 2025 10:55:16 +0100 From: Oscar Salvador To: Liu Shixin Cc: Andrew Morton , Kefeng Wang , Muchun Song , David Hildenbrand , Zi Yan , Johannes Weiner , "Kirill A . Shutemov" , Nanyong Sun , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: page_isolation: avoid call folio_hstate() without hugetlb_lock Message-ID: References: <20250122061151.578768-1-liushixin2@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250122061151.578768-1-liushixin2@huawei.com> X-Spam-Score: -4.30 X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_SEVEN(0.00)[11]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[huawei.com:email,suse.de:email] X-Spam-Flag: NO X-Spam-Level: On Wed, Jan 22, 2025 at 02:11:51PM +0800, Liu Shixin wrote: > I found a NULL pointer dereference as followed: > > BUG: kernel NULL pointer dereference, address: 0000000000000028 > #PF: supervisor read access in kernel mode > #PF: error_code(0x0000) - not-present page > PGD 0 P4D 0 > Oops: Oops: 0000 [#1] SMP PTI > CPU: 5 UID: 0 PID: 5964 Comm: sh Kdump: loaded Not tainted 6.13.0-dirty #20 > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1. > RIP: 0010:has_unmovable_pages+0x184/0x360 > ... > Call Trace: > > set_migratetype_isolate+0xd1/0x180 > start_isolate_page_range+0xd2/0x170 > alloc_contig_range_noprof+0x101/0x660 > alloc_contig_pages_noprof+0x238/0x290 > alloc_gigantic_folio.isra.0+0xb6/0x1f0 > only_alloc_fresh_hugetlb_folio.isra.0+0xf/0x60 > alloc_pool_huge_folio+0x80/0xf0 > set_max_huge_pages+0x211/0x490 > __nr_hugepages_store_common+0x5f/0xe0 > nr_hugepages_store+0x77/0x80 > kernfs_fop_write_iter+0x118/0x200 > vfs_write+0x23c/0x3f0 > ksys_write+0x62/0xe0 > do_syscall_64+0x5b/0x170 > entry_SYSCALL_64_after_hwframe+0x76/0x7e > > As has_unmovable_pages() call folio_hstate() without hugetlb_lock, there > is a race to free the HugeTLB page between PageHuge() and folio_hstate(). > There is no need to add hugetlb_lock here as the HugeTLB page can be freed > in lot of places. So it's enough to unfold folio_hstate() and add a check > to avoid NULL pointer dereference for hugepage_migration_supported(). > > Fixes: 464c7ffbcb16 ("mm/hugetlb: filter out hugetlb pages if HUGEPAGE migration is not supported.") > Signed-off-by: Liu Shixin I wonder whether we should place a comment in hugepage_migration_supported stating that the hstate _must_ be valid, as we do not perform any sanity check further down the road. Reviewed-by: Oscar Salvador -- Oscar Salvador SUSE Labs