From mboxrd@z Thu Jan 1 00:00:00 1970 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 0542FE7716C for ; Thu, 5 Dec 2024 15:23:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F0F76B0112; Thu, 5 Dec 2024 10:19:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 24B9B6B013B; Thu, 5 Dec 2024 10:19:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE9EC6B0107; Thu, 5 Dec 2024 10:19:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1A2936B00A8 for ; Wed, 30 Oct 2024 17:32:55 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C8A9DA109F for ; Wed, 30 Oct 2024 21:32:54 +0000 (UTC) X-FDA: 82731566904.17.A1C5BC3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 92F0340020 for ; Wed, 30 Oct 2024 21:32:40 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="E8W25/WK"; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730323892; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=T9oOkd/Ta3caPUrXJiMZwEtxAvdW01kxki+ZonDRvcU=; b=pXRdXBIkxOcwhFNi/FAuDy6jNAgmF5Fbj1cl8R3gFb2Ng6sD0A+r3caFExJFtuVqLSu+Ip iVHnm4vzM4+ekzdtpYIFT0eYLgs+/I75ga7ufgBlV+IINPEdiWGjLe5smp14HBnvzxxeEK hjvQUW/XGHju7496JTLDXrFKjk0oZEg= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="E8W25/WK"; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730323892; a=rsa-sha256; cv=none; b=NpaAGAhFyvl2kjXVE1bhTjzbKkd8i97PBPPQAg+r8Wa69wcPwgSfozxUCk8hJwo5KqKlQd AZOFiHMOfePx4tr29jTBkv8NdE1OyEwMBVi7YuLDxzJzGjWcqqFhiuc+9mRrwxPDTWX2RP q3/KiXbSiHGqianiLs+gzO1KyEM1s44= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730323971; 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: in-reply-to:in-reply-to:references:references; bh=T9oOkd/Ta3caPUrXJiMZwEtxAvdW01kxki+ZonDRvcU=; b=E8W25/WKdtfOC2bttswg4Yl0AY7f1ZGNhFR7Stdm24nKRs0wiUjdSc8nr8AlI0prOxi29m HCOYUl2Opw40SYevZvxGmVB0MPjN7q1+SW+23OEfMIUqQcDFJTNHtD3EWownPbJ+SSkt+g E3mi3jC6AE7hkXVO0m+4aA5FMvjkyFI= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-465-whsFXMZjN3OmchrObDHMdA-1; Wed, 30 Oct 2024 17:32:50 -0400 X-MC-Unique: whsFXMZjN3OmchrObDHMdA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7b15d3cd6dcso36631485a.0 for ; Wed, 30 Oct 2024 14:32:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730323970; x=1730928770; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=T9oOkd/Ta3caPUrXJiMZwEtxAvdW01kxki+ZonDRvcU=; b=mfREzfOivgErxhHF9Eq51IFrUneWjLXwIVdBetOTJdVsy/BxCDxBD6ri1/v0l4LycS 71hfTUV8iR/uKCr094m5SyVoKRG57Kx1jquRwECKjhOsgxr6zDQxBuWOejFcd4ypH71d BayLb5WJG5pk8e5Wl18dNj0qqFAy0BDVv0agvmvyBKD+uJ5RH2DyGy67umdEUI4+a+I2 ZFP6xuPHhxIEDnsTyvgBq5eiDKARwOxF9yglA5o9RsX8kC7W3K08Lm9m6Zd5Sa4/ikg1 49oP1TaWScoeVW6p7HAe+zgsraOJ0dziC5DTJ9/W3+XruRtyF6VDwD8mrqETXR+CU/GC ECuA== X-Forwarded-Encrypted: i=1; AJvYcCV5bHRPzUL5joMFaAnvE9cmQ54iKZX2n3SfOvxpRHWE88CgRdejxv2ZJpEAyyNqcx7geyYXES8u3g==@kvack.org X-Gm-Message-State: AOJu0YwmrNtTFb0ECO3HwGb8RBll7vXbjk+ISaWPSjpmt3wgM3Pd796D MaL7UxujNn1NtB7ucXnKgLBBGg+tW3eBeUae5YP0/hRUBOUsHsiWlUzSalPs4pC0JNDejGMa87J 259Gn0a5PftEoWgKfxWYR/lNM6y53ZCPGWUgwHPLCPh4fRnvC X-Received: by 2002:a05:620a:4504:b0:7b1:4caf:3750 with SMTP id af79cd13be357-7b193f5d97cmr2407764685a.53.1730323969942; Wed, 30 Oct 2024 14:32:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFD668Os7kBM4L/eQ5Q1w2L3HF//ExCrImc44DBAYo/TO9jIl7iyA11psw8cXIMCnhcXJm1Pw== X-Received: by 2002:a05:620a:4504:b0:7b1:4caf:3750 with SMTP id af79cd13be357-7b193f5d97cmr2407761885a.53.1730323969566; Wed, 30 Oct 2024 14:32:49 -0700 (PDT) Received: from x1n (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b2f3a82e77sm5599985a.105.2024.10.30.14.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 14:32:48 -0700 (PDT) Date: Wed, 30 Oct 2024 17:32:45 -0400 From: Peter Xu To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, xingwei lee , yuxin wang , Marius Fleischer , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Andrew Morton , Ma Wupeng Subject: Re: [PATCH v1] x86/mm/pat: fix VM_PAT handling when fork() fails in copy_page_range() Message-ID: References: <20241029210331.1339581-1-david@redhat.com> MIME-Version: 1.0 In-Reply-To: <20241029210331.1339581-1-david@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 92F0340020 X-Stat-Signature: 1hirewo9q4h3ggzpgkoawu6xon5og8e1 X-HE-Tag: 1730323960-222525 X-HE-Meta: U2FsdGVkX1+KTDPcMBJmbiUI+wAZ+xJ2JuHEZ/NKSThRsWxRZgwvA0xmeNYNeppfY7jnwj9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PM6BmB2pBi6FcNbmkPcKqJUbO0/MPC8L/33yf2scq8A0M8OCrKmvq613ZMPBmeXynm6fBsLUfNwJkQLB4LjM5t9DYEb92pLgISTX3I1OuQgliPny2fQ8eyqIG22M6v4k90crw7rinQ8WBYcVjxdoQDgXznBKUx2NoyKIb07o0HBgr/PiJr0zD84khK6cvRdyL+f1AkbT7dwkMInUEEMtA065IoRddK9bAc68GpZ6bXZ+Nx9018UQFvgu0K9a92bPn0m7BvYVjHBUePmzpupOvl3rAmiZBA9bKM64rUQUHDQ8GHeF9NCyNg+3YX8l8pU7x9W7C3ALh9SFyepXDBI/EtBmboBSnqtEpq+mL9uhS33hujkW6BFAn 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: On Tue, Oct 29, 2024 at 10:03:31PM +0100, David Hildenbrand wrote: > If track_pfn_copy() fails, we already added the dst VMA to the maple > tree. As fork() fails, we'll cleanup the maple tree, and stumble over > the dst VMA for which we neither performed any reservation nor copied > any page tables. > > Consequently untrack_pfn() will see VM_PAT and try obtaining the > PAT information from the page table -- which fails because the page > table was not copied. > > The easiest fix would be to simply clear the VM_PAT flag of the dst VMA > if track_pfn_copy() fails. However, the whole thing is about "simply" > clearing the VM_PAT flag is shaky as well: if we passed track_pfn_copy() > and performed a reservation, but copying the page tables fails, we'll > simply clear the VM_PAT flag, not properly undoing the reservation ... > which is also wrong. David, Sorry to not have chance yet reply to your other email.. The only concern I have with the current fix to fork() is.. we started to have device drivers providing fault() on PFNMAPs as vfio-pci does, then I think it means we could potentially start to hit the same issue even without fork(), but as long as the 1st pgtable entry of the PFNMAP range is not mapped when the process with VM_PAT vma exit()s, or munmap() the vma. So I do feel like at some point we still need to make get_pat_info() work without walking the pgtable, so as to fix all possible such issues. Thanks, -- Peter Xu