From patchwork Fri Apr 4 12:49:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 14038444 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 ACFC7C36010 for ; Fri, 4 Apr 2025 12:49:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D91A26B0022; Fri, 4 Apr 2025 08:49:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D18D06B0023; Fri, 4 Apr 2025 08:49:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B930D6B0024; Fri, 4 Apr 2025 08:49:40 -0400 (EDT) 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 969B36B0022 for ; Fri, 4 Apr 2025 08:49:40 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AC9C71428AD for ; Fri, 4 Apr 2025 12:49:40 +0000 (UTC) X-FDA: 83296342920.09.2A485B9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 1D8B540011 for ; Fri, 4 Apr 2025 12:49:36 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dZjlBY9Q; spf=pass (imf11.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743770977; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=ElXx7zpuGVuLExIEH/CSyLaDSb9egBTulKg0etuqtaU=; b=3uNHvp4yW1e/jAJf3DUFJ4Uso7bvivNsqpkQOUaPwR6iLMhl2GE30QIvAg1MoJ+CwoIb0p wDUjc4gDORM8lnmlR9GXoIPTWlBY8Hp8xM0aTm7Lcq00A9wOWsVAuSDd4WZhlpAbAdiQs5 ki1ttqD0ApLsuaQ4ejvrbS3c9uv8fAk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743770977; a=rsa-sha256; cv=none; b=oxe2W9hCpSzq4KQsNxIAQYv2vCWlilcnkDDO3l11+Y4Da8al3aLQOJlMuRKcQQVQbPgyq9 HZn9uvCv769bul5TgRdbO38NwTil5HSxUbnxxdRC1wS28+Ovh5SXg3SmaKIXFyw4EzPgCJ a2vY5bILt9XVVy9f/kwCZ9zSWh49rRQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dZjlBY9Q; spf=pass (imf11.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743770976; 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; bh=ElXx7zpuGVuLExIEH/CSyLaDSb9egBTulKg0etuqtaU=; b=dZjlBY9QCO98PX1KHpcMqyvJpXa2nxC3hLn1L3cN24USlcyqwMgsV0OJ9EYdl++ol2y4/B 7c/bJ3FZbGHJry/6HOwQe5zARND1Xtl9++dKgsW9seejwjdNtVle3ZLSBnmvbZiTiuU/Eg 7klLmnS9bCJCnEG8I27Q0PBqT9M1MKU= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-292-8zR4d9uXOcuAmuhdwPw0vA-1; Fri, 04 Apr 2025 08:49:35 -0400 X-MC-Unique: 8zR4d9uXOcuAmuhdwPw0vA-1 X-Mimecast-MFC-AGG-ID: 8zR4d9uXOcuAmuhdwPw0vA_1743770974 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3913f546dfdso1180564f8f.1 for ; Fri, 04 Apr 2025 05:49:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743770974; x=1744375774; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ElXx7zpuGVuLExIEH/CSyLaDSb9egBTulKg0etuqtaU=; b=vbg0BP2VmW0IJZACcbTKIL4G++PPyagxGFN0jmDHrbDFJW4NQJEwAWWGrS3JmCeRNh XM5sRoEt1nh9W4dmQpm40PvxWUc8+Lxv9R8kv/po2ZNjoexYjrg1Km/Ju4dXbapOSFL0 PFFMl/MZU7NqhZCI5g0Uw5PUJMVpr/c5Ph1FpZqtYy3vNtuZ7cN7Ec25OZ145t4yPtK6 w+c/E+1wKVE3ILwCEWhYYo8ncEK/bwcknF4EyrV85XpYQpmrBnjYhk469B9N4ii+LiZN +OQjutb7weCjrnw0Ngdqs/O+1mltIwSsH5y7Omw9u/h8opRV8xPIfpBjIS81XCjk7x+0 4Nlw== X-Gm-Message-State: AOJu0Yw3MXV4TcBGc9mKwN0LFHr/jZVQSJeZiF7iyeHPi4rE3lCdfpG+ /S+J3S0zuqzlm8GARxulJp/b2dCydP77/pL7eo19Pc4KO4hQ/k/7B4i6wfDUwu1/kfq25oxP4gh RmP7xrXSAu8VTmTB4NwHZMslQ2DfS+FbshLd6ErWZ77GhJAwI6h3hmRiihXg= X-Gm-Gg: ASbGnctGRrSpBQzBZXL8UblX0OmHRTOVWz2Ds6zfQaTSfyIR1MMa4XqclfOE5WtgnMJ nfFrPJHLUeDgw0BAWSX1VGy4w1RuINlsH2qdz9H8cmjw5tR+4MMZsoUxWLHrnn6DqoNQWxu0oq0 B89GzOlW4oBZHLe3yDKGmH+HMsIqqM2QXPVh5cJO/z78i2Xheh2K1GEtMmYzCT2cJ7TA5JyDeJF efLtei51C9QzqbCWGGj6aNxbPpR6WIYbUlHSYC5b2+bsA9tpLHdvWw9eR5/GVHDU/+sHA/sAMHV G2mQey8VsEDmJ0gI5G3zjL/TGTaAGjqdEAwLf5pspXunP2x0a6lbQzR0WmaZQcwIIZ/e4S8kIOw C X-Received: by 2002:a5d:64aa:0:b0:391:2e0f:efce with SMTP id ffacd0b85a97d-39cb357afdbmr2965607f8f.1.1743770973868; Fri, 04 Apr 2025 05:49:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxeNigkOC4vFDlRTg479b4ch7LTcpwjsYTaaPSI5BjxB79+5TOYvrjeCOmeWoLaXZpSaxwig== X-Received: by 2002:a5d:64aa:0:b0:391:2e0f:efce with SMTP id ffacd0b85a97d-39cb357afdbmr2965579f8f.1.1743770973517; Fri, 04 Apr 2025 05:49:33 -0700 (PDT) Received: from localhost (p200300cbc71b79008752fae3f9c9a07e.dip0.t-ipconnect.de. [2003:cb:c71b:7900:8752:fae3:f9c9:a07e]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-39c3020d62fsm4351146f8f.79.2025.04.04.05.49.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Apr 2025 05:49:32 -0700 (PDT) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, x86@kernel.org, David Hildenbrand , kernel test robot , Dan Carpenter , Andrew Morton , Lorenzo Stoakes , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Rik van Riel , "H. Peter Anvin" , Linus Torvalds Subject: [PATCH v1] x86/mm/pat: (un)track_pfn_copy() fix + improvements Date: Fri, 4 Apr 2025 14:49:31 +0200 Message-ID: <20250404124931.2255618-1-david@redhat.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: JL9LQG8bmAJmhSiViFkeK5ZeZzSPRd5B26Lax4Hi_yE_1743770974 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Stat-Signature: 3i4u7yqeakcksdp3iw5uoy867pahfanf X-Rspam-User: X-Rspamd-Queue-Id: 1D8B540011 X-Rspamd-Server: rspam08 X-HE-Tag: 1743770976-534424 X-HE-Meta: U2FsdGVkX19jXCokrNtTxIr0syMjAKbtbmPWbfMrNlnfTb39LOoPQd80aLQ+Cxu+kt8ITh4ZBwKwg/6tT4cz6Utmi/Z0GrimHVXRFc/aP7e6ZBCLhvDxknx1YxyA2d2/uSceqEDRiJDLgFyjeaSQjTQPyPhENAhQX3tzBGHrob2lNqlgdzZnCJQPcNtVQsVSzq/Qk7N4sFir5jvzoi8T8JjRiRxkHMit3eZQo8SLbDxRKvxVpSeL/v9NiuXM6FwGlNn0pjU8+CKwN8pyDpwaINniOyeZnSO8/y4cRK2tIV0w3d59NQRa/6GO57ZS85Ysj4Yaz961DSqv8RB722UgrXjk40+R50LD4AtaFziUlnEH+K8cxXk26bibBTKPk0u9R6Bv1lV1GAcUF9X6gKLuz+V4vqq1cJ9tp2BtFCeddV03VENDdVJTkmCYyNhZD+9qUm0bBkLc2zd6Pt/dDnGF31V13QtggBriNaJspIMOBJphD/GDTRC18pmrz8ZiQORAKCaSt1aHnj/R45IDxnU2vDS02b3zpeTFFq/Nsrbo+5WoEHy3VbRQxC3tLNpaFE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y/PteMRT3j4FGWBi81RjEGt3QGG5Q+ch2P6/jN5ivLmmw/IMM5xKXgYOLZ/RD7fXqHbn3PHq/ubyzZfUAAnuq2YQ6xfp9zV7gaXibK5D4SlYOD+AxQfb0wAj0eP4VK9xltDUOWV5C/bdNi1QfaOTTW5CCx0Mx5u9HAWIA704EWC2FYHjfndaxbiovPQgrCoBzXTJOJiTSUvkjjU= 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: We got a late smatch warning and some additional review feedback. smatch warnings: mm/memory.c:1428 copy_page_range() error: uninitialized symbol 'pfn'. We actually use the pfn only when it is properly initialized; however, we may pass an uninitialized value to a function -- although it will not use it that likely still is UB in C. Fix it by always initializing pfn when track_pfn_copy() returns 0 -- just as we document ("On success, stores the pfn to be passed to untrack_pfn_copy()"). In addition, to avoid further wrong smatch warnings, just initialize pfn = 0 in the caller as well. While at it, clarify the doc of untrack_pfn_copy(), that internal checks make sure if we actually have to untrack anything. Fixes: dc84bc2aba85 ("x86/mm/pat: Fix VM_PAT handling when fork() fails in copy_page_range()") Reported-by: kernel test robot Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202503270941.IFILyNCX-lkp@intel.com/ Cc: Andrew Morton Cc: Lorenzo Stoakes Cc: Dave Hansen Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Rik van Riel Cc: "H. Peter Anvin" Cc: Linus Torvalds Signed-off-by: David Hildenbrand Reviewed-by: Lorenzo Stoakes --- arch/x86/mm/pat/memtype.c | 4 +++- include/linux/pgtable.h | 5 ++++- mm/memory.c | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 72d8cbc611583..9ad3e5b055d8a 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -992,8 +992,10 @@ int track_pfn_copy(struct vm_area_struct *dst_vma, pgprot_t pgprot; int rc; - if (!(src_vma->vm_flags & VM_PAT)) + if (!(src_vma->vm_flags & VM_PAT)) { + *pfn = 0; return 0; + } /* * Duplicate the PAT information for the dst VMA based on the src diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index e2b705c149454..9457064292141 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1517,12 +1517,15 @@ static inline void track_pfn_insert(struct vm_area_struct *vma, pgprot_t *prot, static inline int track_pfn_copy(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, unsigned long *pfn) { + *pfn = 0; return 0; } /* * untrack_pfn_copy is called when a VM_PFNMAP VMA failed to copy during - * copy_page_range(), but after track_pfn_copy() was already called. + * copy_page_range(), but after track_pfn_copy() was already called. Can + * be called even if track_pfn_copy() did not actually track anything: + * handled internally. */ static inline void untrack_pfn_copy(struct vm_area_struct *dst_vma, unsigned long pfn) diff --git a/mm/memory.c b/mm/memory.c index 2d8c265fc7d60..1a35165622e1c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1361,7 +1361,7 @@ copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) struct mm_struct *dst_mm = dst_vma->vm_mm; struct mm_struct *src_mm = src_vma->vm_mm; struct mmu_notifier_range range; - unsigned long next, pfn; + unsigned long next, pfn = 0; bool is_cow; int ret;