From patchwork Fri Jun 2 09:29:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 102416 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp904662vqr; Fri, 2 Jun 2023 02:44:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5IyStkJu2CpcSo6tTdY8FHW0uFbpXV0b18rZyR/4hWojMPPMJsMZFEXedfDPZHorXOBW+Y X-Received: by 2002:a05:6a00:2496:b0:651:9ca6:de40 with SMTP id c22-20020a056a00249600b006519ca6de40mr4097552pfv.3.1685699052404; Fri, 02 Jun 2023 02:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685699052; cv=none; d=google.com; s=arc-20160816; b=J5RwqKfWVm/iWfdmPJ4KmbT4aIp7UPjFiVFnVStlHvapTaDViVgB6TyQ8uOK7aKtBs YoAkBycfoVBzGXL7s+eAKHRfCZOijXSn5RMfLAUeqKsqnj/+xYX0RGupuZ8e1d4MWgnq 6vF5yMBthmXaPjGhdjYhVP9Y7FMVECh2TiXg7YwZagGrzq64um/TkNqmcPYXaGFElqIj X36jwdC0WQhEzEVUyW3AOs97c56pMbYYZUQtBM/1wnX/2UENHPTCbXMmmLQewhXHnY4R oHQAr+5c32oJ8dDG1G/es9qsfo4CXXCwIRHdHa2LRrwJbPrGpURrVlUsFO5s51tGWvug SzKQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=fR4yNwzvaAJnisMVw8RkhRtyeaH2J5bwe2DxjFB1zZ8=; b=Hrt2Gz9dAA/+dlUCt3Y616DN//a4UP4UeVIwgdbruluAercTz2kwkTA3yr0wTn1zop Rzw3zS+jZYWDxJT9yQRqBj4Bi9UpAgUZK05yGdJQNk1+/Pt24f5rvDCUP193uYNn/xY/ q27XG4j8wSVk/SO9vKhGrej8gNZVOidYpQq1lmLuSck2Xw6BQUNp6TPD0u2yUgH+c7GG 7B1RMQwu4+cRkRTrhewib9C2HPAGreR+u0qJR5Ue3xkPyfSpCN2wHsSvVw9Y7TdysKFD pyY7ysGi5l6MUPSg7X9Kfy0osjQBDEQqhQfa/DAhUaRCVBlg3w03SULweZ2Uqm4QI3Pz mNrw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q13-20020aa7960d000000b0063d48d82e85si518606pfg.15.2023.06.02.02.44.00; Fri, 02 Jun 2023 02:44:12 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234244AbjFBJbN (ORCPT + 99 others); Fri, 2 Jun 2023 05:31:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234686AbjFBJah (ORCPT ); Fri, 2 Jun 2023 05:30:37 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E899BE5A for ; Fri, 2 Jun 2023 02:30:05 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 19B1E12FC; Fri, 2 Jun 2023 02:30:51 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C874E3F7BD; Fri, 2 Jun 2023 02:30:03 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , SeongJae Park , Christoph Hellwig Cc: Ryan Roberts , "Matthew Wilcox (Oracle)" , "Kirill A. Shutemov" , Lorenzo Stoakes , Uladzislau Rezki , Zi Yan , Yu Zhao , Mike Rapoport , linux-kernel@vger.kernel.org, linux-mm@kvack.org, damon@lists.linux.dev, Christoph Hellwig Subject: [PATCH v3 1/4] mm: vmalloc must set pte via arch code Date: Fri, 2 Jun 2023 10:29:46 +0100 Message-Id: <20230602092949.545577-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230602092949.545577-1-ryan.roberts@arm.com> References: <20230602092949.545577-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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?1767583569350961017?= X-GMAIL-MSGID: =?utf-8?q?1767583569350961017?= It is bad practice to directly set pte entries within a pte table. Instead all modifications must go through arch-provided helpers such as set_pte_at() to give the arch code visibility and allow it to check (and potentially modify) the operation. Fixes: 3e9a9e256b1e ("mm: add a vmap_pfn function") Signed-off-by: Ryan Roberts Reviewed-by: Zi Yan Acked-by: Lorenzo Stoakes Reviewed-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) Reviewed-by: Mike Rapoport (IBM) --- mm/vmalloc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 9683573f1225..48202ec5f79a 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2899,10 +2899,16 @@ struct vmap_pfn_data { static int vmap_pfn_apply(pte_t *pte, unsigned long addr, void *private) { struct vmap_pfn_data *data = private; + unsigned long pfn = data->pfns[data->idx]; + pte_t ptent; - if (WARN_ON_ONCE(pfn_valid(data->pfns[data->idx]))) + if (WARN_ON_ONCE(pfn_valid(pfn))) return -EINVAL; - *pte = pte_mkspecial(pfn_pte(data->pfns[data->idx++], data->prot)); + + ptent = pte_mkspecial(pfn_pte(pfn, data->prot)); + set_pte_at(&init_mm, addr, pte, ptent); + + data->idx++; return 0; }