Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1924326lqb; Mon, 27 May 2024 01:54:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUPdpgYQETLclwEc3bMdnxCLuL3JOE1rEXTg1fBDviYo39FkIJk2vILk1dX18WH+IYpDvBoverQ3ImjYQhy6+2MqW/3XOs95M+Av5xZeg== X-Google-Smtp-Source: AGHT+IEtFLmrO0WijYIgnl7M/T1zLhIBoOfbtUZtvq/tXNyUVzNMuHktRq2giam6v7lzWZuf06xz X-Received: by 2002:a05:6a21:2791:b0:1ad:ab1:9a03 with SMTP id adf61e73a8af0-1b212d2bc37mr7601182637.25.1716800047725; Mon, 27 May 2024 01:54:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716800047; cv=pass; d=google.com; s=arc-20160816; b=AJ0R9WIYkx/HHaJmuS2su43WPNBc4pCSQFOIze1WwvlGAwINkzRzv7UXKv5IBD6qsl HWm/njg7YuEHuUbyJQ7++h28UMgHu81aQhtdpIAww8g+lX7KpCpzJgv6hXGnX4X2GxcM aMt0wMvx62OQqZbVXscale2ClzIbKpHqX9+8gSz2OFVnlSUccSss2dFmBa2FEeTZGPqM ekilkqRoz6R7VsGWBJJN4G2veL+K6EZqn/8xmaU4Uez3ci1clnLWr+SIg6RHEauJ/u0c TbRK0OGirXQGbircZSx4+KELvVzvYuy5A+3RkGE/04rKwZtj8xPYf4EpYqy8xkG4Ru2k JIdA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=rVC/dDk5c+fIGn0MOwcknof/hJlc/Q9eHr02ULk1Nx8=; fh=eBRd6jknnto4l+sMOQcuBhkOd7NKV38dIsIYl9k4H38=; b=VdF792UBhet6ewu4ystJrRHs615lBWCTmfjmJwHm3fwDUxbchJo0a4vHbtKYzdjDF1 kj1Bvk70BysO8e4Ea1bYTS5VDvS9d/poMRAF0HOk87ykF+RChFRA4X+uMuiMP+agCH8a Fd5NMRGRimJm3M4ad3QyvAma/tYasnbeUbbW6aFyzbDQRPXqpwDuXAhYY+Z3PblwUJNY lyQZWQvToe48ZhGG2ViFiollC6vOdYzFAYOGqaT3h8lesVKqUPTWct18h9/AgHmKjGcT DmLgmFH0m5V9zhLlxFXeYmJwLLTU0Nskr7Z2bfO7xdYIR6GqWIz7ljkOcSTnhMkCdtid eBXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=mW+A8a81; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=AovZ2QB2; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=mW+A8a81; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-190268-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190268-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2bdda14da18si7872744a91.154.2024.05.27.01.54.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 01:54:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190268-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=mW+A8a81; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=AovZ2QB2; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=mW+A8a81; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-190268-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190268-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 030EA280F06 for ; Mon, 27 May 2024 08:54:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BCC586A33A; Mon, 27 May 2024 08:54:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="mW+A8a81"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="AovZ2QB2"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="mW+A8a81"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="AovZ2QB2" 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 3301028684 for ; Mon, 27 May 2024 08:54:00 +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=1716800041; cv=none; b=eTguDRi38SD017I6jybTxg/gUl4zGTFmVykHAPS3dV8pN7Z99fuZLSbcxeIpHr8CPdyi/EWSChW6BVCX/IZ/AcTs/DwpfhVcFB0V4czCcaUDpVWGgOe+zZuzLCoGEz/zUC7cFQdpiMVodjgb4PTT/2XdoTtl9ktcJbsMb+0m1NY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716800041; c=relaxed/simple; bh=/PCwCOQJpwGYnX/sOpLT7J90NpmZjtGgeaPN06REkN4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=h3GYabu0oZ9qfjHL3k0THo6fO6Wbdra/yDUyls8cnDSuNBs/H0GaDKMJEPwd39wWH6/OtGkXDbUljVeyjjwSmktnTC0FO7uBI465rQPCpmz9wcxxcc9EvpWzl71hHoSxtc064jf+zQdlQTvP53GaG0fnyi58AGLDQkuDFaEHMfA= 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=mW+A8a81; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=AovZ2QB2; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=mW+A8a81; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=AovZ2QB2; 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 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 459BB21D66; Mon, 27 May 2024 08:53:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716800037; 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=rVC/dDk5c+fIGn0MOwcknof/hJlc/Q9eHr02ULk1Nx8=; b=mW+A8a81nA/4/BMW6BWQa/mUk3SVkQXftMlE+3NsmhGRELQznuJOH7vKTSedt+Ct0GinS2 7ih0mgJotbupc43DGY7vPEychw6+XfNL1A5RQB/DTziSjp9qibMX6vhmbXKTmfPTx4UJRR CBilRCx95VMDGZfcWO1gtEtw+Z5dxFs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716800037; 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=rVC/dDk5c+fIGn0MOwcknof/hJlc/Q9eHr02ULk1Nx8=; b=AovZ2QB2O2C4eZQV4G7q3edNeGnxBtm5G0BycbrLiAfdBqMgtBaIdPLKnI7qxbK6fRxhW/ GNr/X3cQD8n5kcAQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716800037; 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=rVC/dDk5c+fIGn0MOwcknof/hJlc/Q9eHr02ULk1Nx8=; b=mW+A8a81nA/4/BMW6BWQa/mUk3SVkQXftMlE+3NsmhGRELQznuJOH7vKTSedt+Ct0GinS2 7ih0mgJotbupc43DGY7vPEychw6+XfNL1A5RQB/DTziSjp9qibMX6vhmbXKTmfPTx4UJRR CBilRCx95VMDGZfcWO1gtEtw+Z5dxFs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716800037; 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=rVC/dDk5c+fIGn0MOwcknof/hJlc/Q9eHr02ULk1Nx8=; b=AovZ2QB2O2C4eZQV4G7q3edNeGnxBtm5G0BycbrLiAfdBqMgtBaIdPLKnI7qxbK6fRxhW/ GNr/X3cQD8n5kcAQ== 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 E861813A6B; Mon, 27 May 2024 08:53:56 +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 A/MfNiRKVGZaWAAAD6G6ig (envelope-from ); Mon, 27 May 2024 08:53:56 +0000 Date: Mon, 27 May 2024 10:53:55 +0200 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , Vishal Moola Subject: Re: [PATCH] mm/hugetlb: Move vmf_anon_prepare upfront in hugetlb_wp Message-ID: References: <20240521073446.23185-1-osalvador@suse.de> 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: <20240521073446.23185-1-osalvador@suse.de> X-Spam-Flag: NO X-Spam-Score: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; MISSING_XM_UA(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,linux.dev,gmail.com]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_FIVE(0.00)[5] On Tue, May 21, 2024 at 09:34:46AM +0200, Oscar Salvador wrote: > I did not hit this bug, I just spotted this because I was looking at hugetlb_wp > for some other reason. And I did not want to get creative to see if I could > trigger this so I could get a backtrace. > My assumption is that we could trigger this if 1) this was a shared mapping, > so no anon_vma and 2) we call in GUP code with FOLL_WRITE, which would cause > the FLAG_UNSHARE to be passed, so we will end up in hugetlb_wp(). So I checked this again and I have to confess I am bit confused. hugetlb_wp() can be called from either hugetlb_fault() or hugetlb_no_page(). hugetlb_fault()->hugetlb_wp() upon FAULT_FLAG_{WRITE,UNSHARE} hugetlb_no_page->hugetlb_wp()-> upon FAULT_FLAG_WRITE && !VM_SHARED hugetlb_no_page()->vmf_anon_prepare() upon !VM_SHARED, which means that VM_SHARED mappings do not have vma->anon_vma, while others do. hugetlb_wp() will call set_huge_ptep_writable() right away and return if it sees that the mapping is shared. So the only other we have to end up in hugetlb_wp() is via FAULT_FLAG_UNSHARE. For that to happen gup_must_unshare() must return true, which means the following assumptions must hold. - For Anonymous pages: 1) !PageAnonExclusive - For Filebacked pages: 2) We do not have a vma 3) It is a COW mapping 1) If gup_must_unshare() returns true for Anonymous pages because the page is not exclusive and must be unshared, hugetlb_wp() will already see the vma->anon_prepare being initialized because of the previous hugetlb_no_page()->vmf_anon_prepare. 2) I do not quite understand this case. 3) !VMSHARED mappings already had its anon_vma initialized in hugetlb_no_page()->vmf_anon_prepare. Probably I am missing some bits here, but I cannot see how we would even need vmf_anon_prepare() in hugetlb_wp() in the first place. -- Oscar Salvador SUSE Labs