From patchwork Fri May 31 12:56:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13681656 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 E4A7DC25B75 for ; Fri, 31 May 2024 12:56:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C6E76B0099; Fri, 31 May 2024 08:56:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 676D66B009A; Fri, 31 May 2024 08:56:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 566246B009B; Fri, 31 May 2024 08:56:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3A7A56B0099 for ; Fri, 31 May 2024 08:56:29 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E0AC740991 for ; Fri, 31 May 2024 12:56:28 +0000 (UTC) X-FDA: 82178689656.17.E5858BD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 5AC0CC0009 for ; Fri, 31 May 2024 12:56:26 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OlFvV8X7; spf=pass (imf22.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@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=1717160186; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=5JmbUXvyxSjbvlIBB7oWRC92t6DkK3PEurnFcNBHVLA=; b=gh/3UIJgFf8sNHsxvBLq1RYQEu3AU3gmQOxnHd6M2Lwo6DTKJDLASW6e/gVCn3KuNSruHF txynGlA4y8nrTUkQj5TxWpWj0Ofn+ssyatEitTb3nrH31g8SnwIW50iBsKeqyMfWNrQEqy A9PUv8RM9sgLJFkeNFgScqHqHTKlOps= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OlFvV8X7; spf=pass (imf22.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717160186; a=rsa-sha256; cv=none; b=6gIb5XRe8Q4MTokbPOk6Jf3SkwcVwFIzc9SYjR0K9wm92uA1uJfwXcZwAo++FALl1dPDrX u8PiSw+I0SAyZO2kf3I1TFxQC89PU5y+ajDnh5jtIspZeBk+/hqvnhiqwstyfa93J0esod Z68hSDbdeSdFrkxuM7wM7MZRzY800/o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717160185; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=5JmbUXvyxSjbvlIBB7oWRC92t6DkK3PEurnFcNBHVLA=; b=OlFvV8X7AoZh3NLQxxQkC9RlKRX8dVDoJrR6FkOdNZHLMnfsuXk7KkEqfBd8bjc/dRqPOc j78R4D94zaXDhB0EHsJJ3SCKhDtHNEo1MDsddbDADMEqCfio8ZeCdMZzPIazx+nPe2pKnx b7tGrPXa0V51QAyW/zKBj5DSjwrIno8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-148-nFMmd0dgMgm67x1EOr1SQA-1; Fri, 31 May 2024 08:56:22 -0400 X-MC-Unique: nFMmd0dgMgm67x1EOr1SQA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9123F185A780; Fri, 31 May 2024 12:56:21 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.194.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B09C200A35C; Fri, 31 May 2024 12:56:17 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , kernel test robot , Oscar Salvador , Miaohe Lin , Matthew Wilcox Subject: [PATCH v1] mm: read page_type using READ_ONCE Date: Fri, 31 May 2024 14:56:16 +0200 Message-ID: <20240531125616.2850153-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Stat-Signature: fasuonzi5o6y5awr9ytdiptro11gjqdx X-Rspamd-Queue-Id: 5AC0CC0009 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1717160186-91504 X-HE-Meta: U2FsdGVkX1+2/wgARF/weCapgW3Fnjq7kx0/ytX6YWWesVfVyVIQOoOrbG3sAJ656IL4p1+Un81EkRSGyuCaygs1B2uq+1SEwUtucjl8U6O0pAQmti7ojOWUEebw3EZGd5/cXYV/AFZIIT7ZC6grgoilLCba1gRvenyTV9aAhBb99jkuGFcTAK0SAbCyId1oou41fOCuA8nRTxKZhD/Y1AUiSWciyJxABD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ohElQ41SLHSmQv75juqNpMxmZ4Uk0z49C18fJr9gJZRdgLnram7vEwK4cD 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: KCSAN complains about possible data races: while we check for a page_type -- for example for sanity checks -- we might concurrently modify the mapcount that overlays page_type. Let's use READ_ONCE to avoid load tearing (shouldn't make a difference) and to make KCSAN happy. Likely, we might also want to use WRITE_ONCE for the writer side of page_type, if KCSAN ever complains about that. But we'll not mess with that for now. Note: nothing should really be broken besides wrong KCSAN complaints. The sanity check that triggers this was added in commit 68f0320824fa ("mm/rmap: convert folio_add_file_rmap_range() into folio_add_file_rmap_[pte|ptes|pmd]()"). Even before that similar races likely where possible, ever since we added page_type in commit 6e292b9be7f4 ("mm: split page_type out from _mapcount"). Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202405281431.c46a3be9-lkp@intel.com Reviewed-by: Oscar Salvador Reviewed-by: Miaohe Lin Cc: Matthew Wilcox Signed-off-by: David Hildenbrand --- include/linux/page-flags.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index f04fea86324d9..03eebb1aadbb1 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -961,9 +961,9 @@ PAGEFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) #define PAGE_MAPCOUNT_RESERVE (~0x0000ffff) #define PageType(page, flag) \ - ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE) + ((READ_ONCE(page->page_type) & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE) #define folio_test_type(folio, flag) \ - ((folio->page.page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE) + ((READ_ONCE(folio->page.page_type) & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE) static inline int page_type_has_type(unsigned int page_type) { @@ -972,7 +972,7 @@ static inline int page_type_has_type(unsigned int page_type) static inline int page_has_type(const struct page *page) { - return page_type_has_type(page->page_type); + return page_type_has_type(READ_ONCE(page->page_type)); } #define FOLIO_TYPE_OPS(lname, fname) \