From patchwork Mon Oct 24 11:28:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp418130wru; Mon, 24 Oct 2022 05:14:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Ag0va0H/OfV+hnn6ZE1h3/r7O1uueRRuS4sSutvpDRrW5+jq7qfyl9WRmNQs+ACgNZ1AE X-Received: by 2002:a17:907:1c9b:b0:78d:af10:1a80 with SMTP id nb27-20020a1709071c9b00b0078daf101a80mr27187747ejc.582.1666613649700; Mon, 24 Oct 2022 05:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666613649; cv=none; d=google.com; s=arc-20160816; b=n+M5J2K6dYWoGlGfnORjwxJKEQEkOfbzfLt0SIkebjcV5fMp2q4/SlBCE3Hz7t5YMj A3KRXjSw7k733UV4dtrgVmPPwG3pgSYD9QxHrgyDzQ+GaytMJaD9ae16TqUGaWzBBa8W NUVbIdMuPyGLnb3/PjNitjR4GpK/2GltliKf4cxCjVjpoCvjjC0pOXsuKttny5CWplMi 8MEfkWlakl56DeYAnJ4Sc//JSTvV5Mt+7kAzXhEAp1yeetGkchqZFKOWwoKYMJYc/K+k ldv/MZ+/uO2oLSmcQ+jlDNC/9P4mgm+On2IvPZVb1B19qvuV5XFiePaR53HWtU0LC4VA TG+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NquElzENuAN1w5XKH9Awsp20RFq3RlH9Nu6YqGR+CWg=; b=vNY4mXRSPLjAgc8z4XsQlHObL5toAyCDhR15dKKFM1zBLpi5a89mpB7szHx4/HqttP pqcxPsMAbruqbA0tAn29qJ+FOVleLbc+4zsIpjrU+JfQtj3TT8PflbCnl0ZqgGpzjDew s+GjYZxqTZVbVWaA1mOlPen9ulw77hR/p1KozU3SNcJuJXDt8czB5VcodwS3aKpwnZdo VkiPHLo47dx4pV7BCr7MHlS/uHu4Fuf9wnt3SkGHMMu3JcCGX6HI9BSutMFZyb3wgxTo 4WuOqe/8bZBDdUpjnWfqG9v/KN6Oj82IturoFrGqmwME6vPclKmARMelIlcee6PV5rPI ycLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wstHEply; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b8-20020a0564021f0800b00461b0566a29si3529649edb.137.2022.10.24.05.13.44; Mon, 24 Oct 2022 05:14:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wstHEply; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232545AbiJXMFf (ORCPT + 99 others); Mon, 24 Oct 2022 08:05:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232498AbiJXMDn (ORCPT ); Mon, 24 Oct 2022 08:03:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D95B82529A; Mon, 24 Oct 2022 04:49:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 160E661297; Mon, 24 Oct 2022 11:46:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC2F4C433C1; Mon, 24 Oct 2022 11:46:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612014; bh=jhLDQTT4TMT/PEN5WFUx8lDz+PpXY7GMiLZ2aEmsCXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wstHEplyTeePBHY9czhAmpdBhzlSqpqglyEk3AC068+HhOGl7CVt5ZfpXrwwFP1AV 2CGkSUrJBrT2R1sjGtJZt7m1Y7wOe0/vB2zSvgeAghGh47JbmToQg572FMWTQb9oYI 7PKuWKeeBLzd+It7hsYD+61Yf5ScLqOWoSDw/JWc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alistair Popple , Nadav Amit , "Huang, Ying" , David Hildenbrand , Peter Xu , Alex Sierra , Ben Skeggs , Felix Kuehling , huang ying , Jason Gunthorpe , John Hubbard , Karol Herbst , Logan Gunthorpe , Lyude Paul , Matthew Wilcox , Paul Mackerras , Ralph Campbell , Andrew Morton Subject: [PATCH 4.14 009/210] mm/migrate_device.c: flush TLB while holding PTL Date: Mon, 24 Oct 2022 13:28:46 +0200 Message-Id: <20221024112957.183720272@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747571074154197151?= X-GMAIL-MSGID: =?utf-8?q?1747571074154197151?= From: Alistair Popple commit 60bae73708963de4a17231077285bd9ff2f41c44 upstream. When clearing a PTE the TLB should be flushed whilst still holding the PTL to avoid a potential race with madvise/munmap/etc. For example consider the following sequence: CPU0 CPU1 ---- ---- migrate_vma_collect_pmd() pte_unmap_unlock() madvise(MADV_DONTNEED) -> zap_pte_range() pte_offset_map_lock() [ PTE not present, TLB not flushed ] pte_unmap_unlock() [ page is still accessible via stale TLB ] flush_tlb_range() In this case the page may still be accessed via the stale TLB entry after madvise returns. Fix this by flushing the TLB while holding the PTL. Fixes: 8c3328f1f36a ("mm/migrate: migrate_vma() unmap page from vma while collecting pages") Link: https://lkml.kernel.org/r/9f801e9d8d830408f2ca27821f606e09aa856899.1662078528.git-series.apopple@nvidia.com Signed-off-by: Alistair Popple Reported-by: Nadav Amit Reviewed-by: "Huang, Ying" Acked-by: David Hildenbrand Acked-by: Peter Xu Cc: Alex Sierra Cc: Ben Skeggs Cc: Felix Kuehling Cc: huang ying Cc: Jason Gunthorpe Cc: John Hubbard Cc: Karol Herbst Cc: Logan Gunthorpe Cc: Lyude Paul Cc: Matthew Wilcox Cc: Paul Mackerras Cc: Ralph Campbell Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/migrate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2349,13 +2349,14 @@ next: migrate->dst[migrate->npages] = 0; migrate->src[migrate->npages++] = mpfn; } - arch_leave_lazy_mmu_mode(); - pte_unmap_unlock(ptep - 1, ptl); /* Only flush the TLB if we actually modified any entries */ if (unmapped) flush_tlb_range(walk->vma, start, end); + arch_leave_lazy_mmu_mode(); + pte_unmap_unlock(ptep - 1, ptl); + return 0; }