From patchwork Wed Dec 7 20:30:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13067584 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 ACC1AC4708D for ; Wed, 7 Dec 2022 20:30:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEF248E0005; Wed, 7 Dec 2022 15:30:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C9FCB8E000A; Wed, 7 Dec 2022 15:30:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7C488E0005; Wed, 7 Dec 2022 15:30:53 -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 6DD238E000A for ; Wed, 7 Dec 2022 15:30:53 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 408B4A0EC8 for ; Wed, 7 Dec 2022 20:30:53 +0000 (UTC) X-FDA: 80216653986.13.F86E907 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id CA7C680016 for ; Wed, 7 Dec 2022 20:30:52 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="GS+AOg/+"; spf=pass (imf30.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=1670445052; a=rsa-sha256; cv=none; b=GXrbi9F1g/f+VvGCrL0VNEcYCxaHGPcIVyBLk1KOHb2+HuatOflVuhRAjcKXR8XUFfv0uf /rKjNlaFGiSDsd8d65CSTK9ieD9QizfAYkizsEiKhoGW/C9LVtvymysOQkB5AquMT9vNnp Yt/v+8mK9ZTOlioHVEzwsJw0FGBQkE4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="GS+AOg/+"; spf=pass (imf30.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=1670445052; 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=PxW1+7FnblUXilUivNjEMBQoO6EpHq3+X52yjUcQpsM=; b=imNmEFvRyAG9u+MovO8j7Bg48LIWLwGjaX30fG+sRGWGmKqEtCkbDP08Yd2pL6tJiOTwjD PECexcsdm0mP2DvqsiqCfUNcJphsrAAVioutAnbJn4wl16AUd75C1AePcB9VbUBCuHErGZ lXcFBJdSI5qd4Mo8+z9vw6dewIF7AAk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670445052; 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=PxW1+7FnblUXilUivNjEMBQoO6EpHq3+X52yjUcQpsM=; b=GS+AOg/+Xwe6W7r8CL5nK3G0RitZE/m6YPWFAZo9hwlJ5xbjbdm0jeRiW5YX3sxWwhVhy+ Z2ckqlG7Z+GexpDB39hIi25pfssGTBVA8dLVygbEX5u3roVyPOsuLEdngY6N/i49l/gzNk 2i6E6J5IMXUsGNUWBqBfzkv9N4DVyH0= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-411-bz1CFdliNE2Vqf20W98KFw-1; Wed, 07 Dec 2022 15:30:48 -0500 X-MC-Unique: bz1CFdliNE2Vqf20W98KFw-1 Received: by mail-qt1-f200.google.com with SMTP id s14-20020a05622a1a8e00b00397eacd9c1aso40513200qtc.21 for ; Wed, 07 Dec 2022 12:30:48 -0800 (PST) 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=PxW1+7FnblUXilUivNjEMBQoO6EpHq3+X52yjUcQpsM=; b=E/bu3qtS2YN4/4iE/LKFuqnOsW/xOjNuOqB5YHnrycFRjW/JNKoJ6nzYUZRs7cVWJR GCEjx6MNGPMPCfrlPl3R6Nt7UU3gQKD9n0s5fNmeBqJMh68W+tEozYUfwIzibmMtwLKb tpfANSKGj08/4ifes1JLMqpl4jTMnTmWcRNbY2B41nktqoYOHzefmzCVLush+U8TCnvv TxZr/8KdBfARHF4BEl1Hbif9CnQFa7gFACBj5wkATAkAzvcBSB8PA4lU+O6UrguPmrRv LM3QPdm5dgWuBaTz2FMcqkgMuKKOtQ/St77E0BWQOd/vhs7UXDJBNlWMATTo3HD/fG/i Yc0Q== X-Gm-Message-State: ANoB5pkJi7p4rveDOfiDyZEEYGQYCuP8xAzETIWL/BGzdVwqBUznUpP8 qrBlufjN+IBPx5/nmcdgks/ELNpOu8m6LoWGtu18ZNXOG+0f/JFsT8cETQXUKf6bvv4SIwJ5e2W o/LS4MhmIWiiYaQkZscuJtiYCbSD1TZOoPFdrLJU7onafTWGH+5NgVJc2d6UF X-Received: by 2002:a05:622a:1b1c:b0:3a6:a205:741f with SMTP id bb28-20020a05622a1b1c00b003a6a205741fmr1433049qtb.32.1670445047827; Wed, 07 Dec 2022 12:30:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf4LgYx0Tk+k6P2vLtvZSUdKvr8Brzp1Zc7q0zTbDSasDnwn5BMIAU2eNX9tOidMqIznOg+0Lg== X-Received: by 2002:a05:622a:1b1c:b0:3a6:a205:741f with SMTP id bb28-20020a05622a1b1c00b003a6a205741fmr1433023qtb.32.1670445047366; Wed, 07 Dec 2022 12:30:47 -0800 (PST) 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 dc53-20020a05620a523500b006fefa5f7fcesm855594qkb.10.2022.12.07.12.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 12:30:47 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muchun Song , John Hubbard , Andrea Arcangeli , James Houghton , Jann Horn , Rik van Riel , Miaohe Lin , Andrew Morton , Mike Kravetz , peterx@redhat.com, David Hildenbrand , Nadav Amit Subject: [PATCH v2 06/10] mm/hugetlb: Make hugetlb_follow_page_mask() safe to pmd unshare Date: Wed, 7 Dec 2022 15:30:30 -0500 Message-Id: <20221207203034.650899-7-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221207203034.650899-1-peterx@redhat.com> References: <20221207203034.650899-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain X-Spamd-Result: default: False [4.30 / 9.00]; BAYES_HAM(-4.80)[97.25%]; SORBS_IRL_BL(3.00)[209.85.160.200:received]; R_MISSING_CHARSET(2.50)[]; SUSPICIOUS_RECIPS(1.50)[]; SUBJECT_HAS_UNDERSCORES(1.00)[]; MID_CONTAINS_FROM(1.00)[]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[14]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_ALLOW(0.00)[redhat.com:s=mimecast20190719]; MIME_TRACE(0.00)[0:+]; TAGGED_RCPT(0.00)[]; DMARC_POLICY_ALLOW(0.00)[redhat.com,none]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; DKIM_TRACE(0.00)[redhat.com:+]; R_SPF_ALLOW(0.00)[+ip4:170.10.129.0/24]; RCVD_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: CA7C680016 X-Stat-Signature: i5h164pcbgjiissqqgedunawzog3towr X-HE-Tag: 1670445052-520402 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: Since hugetlb_follow_page_mask() walks the pgtable, it needs the vma lock to make sure the pgtable page will not be freed concurrently. Acked-by: David Hildenbrand Reviewed-by: Mike Kravetz Signed-off-by: Peter Xu Reviewed-by: John Hubbard --- mm/hugetlb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 49f73677a418..3fbbd599d015 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6226,9 +6226,10 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, if (WARN_ON_ONCE(flags & FOLL_PIN)) return NULL; + hugetlb_vma_lock_read(vma); pte = huge_pte_offset(mm, haddr, huge_page_size(h)); if (!pte) - return NULL; + goto out_unlock; ptl = huge_pte_lock(h, mm, pte); entry = huge_ptep_get(pte); @@ -6251,6 +6252,8 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, } out: spin_unlock(ptl); +out_unlock: + hugetlb_vma_unlock_read(vma); return page; }