From patchwork Tue Oct 4 00:37:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12997901 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 E4BDEC433F5 for ; Tue, 4 Oct 2022 00:37:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 242536B0073; Mon, 3 Oct 2022 20:37:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EEE06B0074; Mon, 3 Oct 2022 20:37:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0940A6B0075; Mon, 3 Oct 2022 20:37:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id ED28D6B0073 for ; Mon, 3 Oct 2022 20:37:12 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C4C1DA0500 for ; Tue, 4 Oct 2022 00:37:12 +0000 (UTC) X-FDA: 79981402704.19.50F06CF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 72C58180018 for ; Tue, 4 Oct 2022 00:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664843831; 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=x4xYjXYzlE422UA6NYhxH1mMMh8xu1ZsHfGS6BWev5s=; b=B+wk3O6HNItR/O+4GHzbhwHZV3U5YrGJtkTUzcThGODBdfCePalOQEUr3zByXIvjbmsPXI gzADlGbYBGRPQpNSvfuEzxBd1guZagpJJ5ho2dFinM4Mk/XxCwG10FptfwxYRFKzxyu/ZR ZAGZT0FuNORarDifMCoosSTSOcZsBEw= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-653-ThTcsKajMcCIHgG7AqD6qQ-1; Mon, 03 Oct 2022 20:37:11 -0400 X-MC-Unique: ThTcsKajMcCIHgG7AqD6qQ-1 Received: by mail-qv1-f72.google.com with SMTP id i1-20020a056214020100b004afa3dbf35dso8025019qvt.14 for ; Mon, 03 Oct 2022 17:37:11 -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; bh=x4xYjXYzlE422UA6NYhxH1mMMh8xu1ZsHfGS6BWev5s=; b=dZ6/7gKHtDLlwkEySRz92Kr64b+RC9C1YuRVTF1hAgDzkHpPRDrjaEnoSga6aUsTqr 5sMvHiXCBwwFhkrIpeY+r7SkvLL8Lrp0o7Ce5pi61Y/14/zNYuzHdMj6uu6tU5lvfRBN CHfaYfMrXiJL1SxksBuSAHyW3gSMJUbzAwCJHgwBufWmscui6PoNKzG7t4FezwKKoOaA cPmFluBu+Htd6KQTvkAYBdeTUqSbE1+fZHcQR3C3ShZiMloWuEPAlfgxhWxLAAdBj9wJ IkQI/CR2Dlq8OgwHLAX0qNEBLKeJ5m9Fa/B2niNiuCLhrsO19/69L70V85NN4IV+xJQi 9/eA== X-Gm-Message-State: ACrzQf1xQitp5ec8nDhiX81ePEcInI/UWtT2ZgiShT1pHaMMYaT+27AM dBmQz9+z0y8zVnYMI+Aiy7zxy5SgNBN9FZ9cyaHFMazYSsAOIr1RwxwqeXIb94MBj6QoADPClI8 zgv6+fWkRNz8= X-Received: by 2002:a05:620a:d94:b0:6bc:5a8c:3168 with SMTP id q20-20020a05620a0d9400b006bc5a8c3168mr15260767qkl.56.1664843830681; Mon, 03 Oct 2022 17:37:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5mTbnDGFwa4OqFZLWTwpewQHP9t+R+EHTP9kL897GWBWxesSU9GeVQIGXXHofPQ4um9Sh1gw== X-Received: by 2002:a05:620a:d94:b0:6bc:5a8c:3168 with SMTP id q20-20020a05620a0d9400b006bc5a8c3168mr15260759qkl.56.1664843830507; Mon, 03 Oct 2022 17:37:10 -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 u30-20020a37ab1e000000b006bb9125363fsm12228104qke.121.2022.10.03.17.37.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 17:37:10 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: peterx@redhat.com, Andrew Morton , David Hildenbrand , Nadav Amit , Mike Kravetz , Andrea Arcangeli , Axel Rasmussen , Mike Rapoport Subject: [PATCH v2 2/3] mm/hugetlb: Use hugetlb_pte_stable in migration race check Date: Mon, 3 Oct 2022 20:37:04 -0400 Message-Id: <20221004003705.497782-3-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221004003705.497782-1-peterx@redhat.com> References: <20221004003705.497782-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664843832; 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=x4xYjXYzlE422UA6NYhxH1mMMh8xu1ZsHfGS6BWev5s=; b=uJ67EPclaX5v9QmOKvKV/dhhkStBgJpDYsILQZz8U3oRy2WpKmaeuj/o8owkB33lllmts8 Ph62pzT8KHO90sRzqaVLEvPi8cDRzF3Ps8CS3pNeRl/ilZaMV4UIbzW1HBGUEcrDuj+KDF 9od0SSlW7wjR4LFTO4f6kaXZjywAAO4= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B+wk3O6H; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664843832; a=rsa-sha256; cv=none; b=DAuCagI778ZQ1LGycLZcuD7sUD+Rhg665iEEAa48d+WGr+UjT7LZGwTS9nT0S005e4EbdS r/wz11o4PpM1soK4/2AQ5e79gDwA4N/pV32951cygVu7zZgrQuX1HuUECz99IDxIxDFVOp PmlNaPFArgizSFB7lcUhmTSqN5HlOA0= X-Rspam-User: X-Stat-Signature: 4yidui8ru41ghatazi6p53u86okd8sdd X-Rspamd-Queue-Id: 72C58180018 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B+wk3O6H; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam01 X-HE-Tag: 1664843832-644380 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: After hugetlb_pte_stable() introduced, we can also rewrite the migration race condition against page allocation to use the new helper too. Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand --- mm/hugetlb.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index fa3fcdb0c4b8..e762c5369a6f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5620,11 +5620,10 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, * here. Before returning error, get ptl and make * sure there really is no pte entry. */ - ptl = huge_pte_lock(h, mm, ptep); - ret = 0; - if (huge_pte_none(huge_ptep_get(ptep))) + if (hugetlb_pte_stable(h, mm, ptep, old_pte)) ret = vmf_error(PTR_ERR(page)); - spin_unlock(ptl); + else + ret = 0; goto out; } clear_huge_page(page, address, pages_per_huge_page(h));