From patchwork Sat May 6 14:05:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13233549 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 E6BDEC77B75 for ; Sat, 6 May 2023 14:05:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 089966B0072; Sat, 6 May 2023 10:05:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 038E66B0078; Sat, 6 May 2023 10:05:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E90856B007B; Sat, 6 May 2023 10:05:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by kanga.kvack.org (Postfix) with ESMTP id B29E16B0072 for ; Sat, 6 May 2023 10:05:47 -0400 (EDT) Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-30639daee76so1855551f8f.1 for ; Sat, 06 May 2023 07:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683381946; x=1685973946; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=CuEXCDxX9XAQkRyAGlh6/9QGDrlqvP94XzM0l6Y+8Jk=; b=gamggnXmqYSnjOTjLciqY80nYyWyus/obNDrZTtrdpVAr4Ko4M4yyA8Pg8TYO5oqEE 1Zy8pKw/H+Ik6hYLwjEv3B8Pl3Z0UibhAurfvl+tlttfxQULwjkWb/VUQMF66hPhKZhF kA55rAQgPoYKbGbMVAO0YdxvZ2UhXApZJXoQFj5kxnAgXwpdvSOgXYFTF9rvSR9btRvh pw5q9tWZKm8s03kjqjigd6x1jeFPto3W76pb7OLq038QfF2YzPxKuQN2LENzRqiSzl2I ZUL80xpmzGTAM0gnuDetBnZKtPT6fqke/+EQ2gLiHYEgS+FPrP8T9zgauu1wQW4xtSHW 58PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683381946; x=1685973946; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CuEXCDxX9XAQkRyAGlh6/9QGDrlqvP94XzM0l6Y+8Jk=; b=YxDXZqhAjrr/3vsAEc4A9v7uY4VQz2rE4bRVx6gsOp2SLETH/grnK+JQzRPqZdZPpQ QN3zOD9PCSjJLkVqcOS40cES/+vqnAtDdWZ35DNDa3qkL9+AjV6s8ZpeE8u/HWRLxaCt BpDYgrwUDxKNzQbOoYELo7OZdVXr3bMgE65lq6cSNt3IzeIsmtJb2Yb4f7MRytrgIMGJ QzrFxRkPdiF7+GOR5IGfA5WBD9xe9EzcAmByJX24uYJJnGJd0nQ9ZE9hNgvf+vudnD4u 9Dwh/02TcMyUu0IJHbRED6rfuP+0LOwjgio1Wf18ms07jaMSOdcegbhfKiCRirSfJJNQ 6YVw== X-Gm-Message-State: AC+VfDwhHN71Pz03mIXrieGyN4HoemwmyGiHGcLR9uRtfutL1+XnyzhU S4T6rEAeq06/Xb0Laer8OLPN+BxrHcwK1Q== X-Google-Smtp-Source: ACHHUZ4B81/e6wsHuW60PU0lrl/acdbNNOf+SI+D0uRKTPsa2HQTwwsVCLqvrubbgUZ8A2PvLUZDww== X-Received: by 2002:a05:6000:104b:b0:2e4:eebe:aee3 with SMTP id c11-20020a056000104b00b002e4eebeaee3mr3047635wrx.60.1683381946277; Sat, 06 May 2023 07:05:46 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id q3-20020a1cf303000000b003f3157988f8sm10993650wmq.26.2023.05.06.07.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 May 2023 07:05:45 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: David Hildenbrand , Lorenzo Stoakes Subject: [PATCH] mm/gup: add missing gup_must_unshare() check to gup_huge_pgd() Date: Sat, 6 May 2023 15:05:25 +0100 Message-Id: X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: All other instances of gup_huge_pXd() perform the unshare check, so update the PGD-specific function to do so as well. While checking pgd_write() might seem unusual, this function already performs such a check via pgd_access_permitted() so this is in line with the existing implementation. Suggested-by: David Hildenbrand Signed-off-by: Lorenzo Stoakes Acked-by: David Hildenbrand --- mm/gup.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index ef43ffb3d1fe..78a5198e3212 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2898,6 +2898,11 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr, return 0; } + if (!pgd_write(orig) && gup_must_unshare(NULL, flags, &folio->page)) { + gup_put_folio(folio, refs, flags); + return 0; + } + *nr += refs; folio_set_referenced(folio); return 1;