From patchwork Sun Oct 30 21:30:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13025222 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 5F4B6ECAAA1 for ; Sun, 30 Oct 2022 21:30:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFF8C8E0002; Sun, 30 Oct 2022 17:30:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E88EA6B0074; Sun, 30 Oct 2022 17:30:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D04F28E0002; Sun, 30 Oct 2022 17:30:48 -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 C29AC6B0071 for ; Sun, 30 Oct 2022 17:30:48 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9BA5F1C6209 for ; Sun, 30 Oct 2022 21:30:48 +0000 (UTC) X-FDA: 80078910576.05.7413DEA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 53E2620007 for ; Sun, 30 Oct 2022 21:30:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667165447; 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: in-reply-to:in-reply-to:references:references; bh=18dXjMMHISRNlhGaFpCwLJgIneJr5paDcQBCMHn2vKI=; b=RPpNh4jEPEssaaPDA/aG59xRNzUMZNX1O+j+TdjkMqX5KZZp+pj+q25cxjNwdoQImZdZuU bl1R+dDKOrCpGLa/t3MfG5JJQkpqrwg4e+2TueDjQkyh7KGjCKJPyC87FgpN/uFz3p/GCr EmGqRHq3u0zyjL8oT4wcopwXxfHkMTw= 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_128_GCM_SHA256) id us-mta-317-cJOCLHf2NguLvZs9qc03Ww-1; Sun, 30 Oct 2022 17:30:46 -0400 X-MC-Unique: cJOCLHf2NguLvZs9qc03Ww-1 Received: by mail-qk1-f198.google.com with SMTP id az31-20020a05620a171f00b006fa2cc1b0bfso892759qkb.23 for ; Sun, 30 Oct 2022 14:30:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=18dXjMMHISRNlhGaFpCwLJgIneJr5paDcQBCMHn2vKI=; b=fc7O42iieTUnbo6clBtVNcuREBHxE6MeHDwd7N8od60tO7uVKf/rodef+5qx7l27Bq brX62lroSWd1OK37drLV8K+CqFntTLS7NwpWcVMZUDnW1ifghcEM6bmiJJAIhwUE5jie I904VeVygUx5dP4/JJxhbAKrIHiyV/jY48xkoNY4DXCBaNqt7gja+35IyYjrE3bl0RxR EZkkic0a7IbZWmsIOXqICA4xvAtVE7Q32uHhnC8U6RlnCuoW7Q4ztj4abcQ6ABdGZU4g 18lST7RddhLHaP4JXsaVSv/vnOU15PeqDKSElVeejZNCVOv3hLV4oSGTordcVI086BsO gRqw== X-Gm-Message-State: ACrzQf07YWNyVrNpENJCk+pBdu+2kh1PoFe5Ld7IJlxvKQeRgSxC8/vk XoW2ADUQ20FgM/FX0ABBarXp7bgedWyWofY3iCI6uns3bRMZu/9YUmvT1CVWCsZvLQJs+lpJkeQ IbPyjGP7Hngc6t0cFKC1p+Y1kgpWQw6EtsbmG4h8dwNMI1EP8vKGD52YPUJHg X-Received: by 2002:a05:6214:262f:b0:4b6:89bc:3ba4 with SMTP id gv15-20020a056214262f00b004b689bc3ba4mr8361043qvb.44.1667165445985; Sun, 30 Oct 2022 14:30:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4WHS7WPiG6eK0xCLe5+DVpxce9WhNLEtvaEGwRBNhlLTs5Fva2fkLlQL6Z/FlVCcCkdSkbsQ== X-Received: by 2002:a05:6214:262f:b0:4b6:89bc:3ba4 with SMTP id gv15-20020a056214262f00b004b689bc3ba4mr8361010qvb.44.1667165445716; Sun, 30 Oct 2022 14:30:45 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id i3-20020a05620a248300b006ee9d734479sm3533891qkn.33.2022.10.30.14.30.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 14:30:45 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: James Houghton , Mike Kravetz , David Hildenbrand , Andrea Arcangeli , Rik van Riel , peterx@redhat.com, Andrew Morton , Muchun Song , Miaohe Lin , Nadav Amit Subject: [PATCH RFC 09/10] mm/hugetlb: Make hugetlb_fault() RCU-safe Date: Sun, 30 Oct 2022 17:30:43 -0400 Message-Id: <20221030213043.335669-1-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221030212929.335473-1-peterx@redhat.com> References: <20221030212929.335473-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RPpNh4jE; spf=pass (imf13.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=1667165448; a=rsa-sha256; cv=none; b=w2VvEGxQsABDueGZKUxznUV6cz2PVNzdPax/gfZa4Hrrn6fImT68X3899HfUhluzoXF9zO caiRYTWYEo99GPsAVBVMdNsdC1HWZTlUpM+C67IsYegaqIs/VQ4FRe9NCMmldLCtKAkOPL 455dM0wF+VQVaFbEHn/loSh6eKnMW58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667165448; 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:in-reply-to:references:references:dkim-signature; bh=18dXjMMHISRNlhGaFpCwLJgIneJr5paDcQBCMHn2vKI=; b=lqtIM1S758vQrPvB6/JnzaKJOFGtsHUI8+41wMAYMZNDL8zQ3FMxs2Q8escpQ8ISQRJ0/P L4R9vYVyCy83k93qpo7BJOq/iXyNz9HzxTk6AWgvD5804e2rHUtay4XewjRF4hiZz4iB0A v1CIcyxgYpScact3WtYisv+YWPenzeM= X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RPpNh4jE; spf=pass (imf13.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 X-Rspamd-Server: rspam07 X-Stat-Signature: 4gdrq1dwypwuubaphixy97qhmbiipwrq X-Rspamd-Queue-Id: 53E2620007 X-HE-Tag: 1667165448-649438 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: RCU makes sure the pte_t* won't go away from under us. Please refer to the comment above huge_pte_offset() for more information. Signed-off-by: Peter Xu --- mm/hugetlb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5dc87e4e6780..6d336d286394 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5822,6 +5822,8 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, int need_wait_lock = 0; unsigned long haddr = address & huge_page_mask(h); + /* For huge_pte_offset() */ + rcu_read_lock(); ptep = huge_pte_offset(mm, haddr, huge_page_size(h)); if (ptep) { /* @@ -5830,13 +5832,15 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, * not actually modifying content here. */ entry = huge_ptep_get(ptep); + rcu_read_unlock(); if (unlikely(is_hugetlb_entry_migration(entry))) { migration_entry_wait_huge(vma, ptep); return 0; } else if (unlikely(is_hugetlb_entry_hwpoisoned(entry))) return VM_FAULT_HWPOISON_LARGE | VM_FAULT_SET_HINDEX(hstate_index(h)); - } + } else + rcu_read_unlock(); /* * Serialize hugepage allocation and instantiation, so that we don't