From patchwork Thu May 18 11:07:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 95788 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp408404vqo; Thu, 18 May 2023 04:13:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ67hWrmJTLZ7LzkiEauiGi7IVwkeX33RmKGG+JkPTtameYMm8mVSbhH3Rb+lAwcBYXgZ3V+ X-Received: by 2002:a17:902:e842:b0:1ac:63ac:109d with SMTP id t2-20020a170902e84200b001ac63ac109dmr2815217plg.15.1684408380309; Thu, 18 May 2023 04:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684408380; cv=none; d=google.com; s=arc-20160816; b=DG2ghcI8rAPNQF5ivif4G4K1LQh9RsDepPfVNx2Z1csnHiMFO48M2QN5drF8cG6Boa qFXBH486MVsTHixREBTCPq+9hpQNsDxrHeq260qtw59nef1DJmwWIwyTTm0PfpHoSjA7 8Hy3idZIHkUV5XjdRDvteeGOfrBrDYfZpi2M9P2xHdcfLLp4HgIAJRxrN4QzGHCWjHnF NPEfAHMEkHLrWdXI/yCb3PV+qfjSWyLve790pyh5EooIx2BTTyxrUeT/3r2DcxTi/oie DhLg5Dh/BAeRAiy4wLNgKttK9sI0dIkjOiSHFRVUUbdZu20SB/TX/lAvG13Brh/O2iQ0 FvLQ== 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=NEW0x3p/iFg/JUm9c2rErOqCzOzNE0TGsXEgs7dca+s=; b=dpFZc762koIpTp585zjonWxGVGdbsvRv8vMS3xULih91YID2AJEAIqkdL6VbwmSbwL v96UkvIqaW/EchrxO0HrW9WpKCWkuXXlushz+VbbeXM9xuL+QTg53N2uxcHfazX4rtLU p5FbCAWbtkMsz8H1l4Ng+BTbAefqhyC8lPF3LnWUejsKs/LI9PUss0UBaE9lcCOStD/F cxP0BK1EJKAfShv3f5ImtXhAEptoIsT7eF59WZIXbV3WYTw106V2bk/AHQGwGCLiTYeu BIm/m13ECjOWcU0Dhv8LTrR5vSC/izVR+OfmfhzMuh9XAEmCg31krSOZU7VkB5DyAXsN uzNw== 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 b6-20020a1709027e0600b001aae905065csi1018779plm.284.2023.05.18.04.12.44; Thu, 18 May 2023 04:13:00 -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 S230395AbjERLHn (ORCPT + 99 others); Thu, 18 May 2023 07:07:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbjERLHl (ORCPT ); Thu, 18 May 2023 07:07:41 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 446D8B8 for ; Thu, 18 May 2023 04:07:40 -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 D08C52F4; Thu, 18 May 2023 04:08:24 -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 5D0033F793; Thu, 18 May 2023 04:07:38 -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 , linux-kernel@vger.kernel.org, linux-mm@kvack.org, damon@lists.linux.dev, Christoph Hellwig Subject: [PATCH v2 1/5] mm: vmalloc must set pte via arch code Date: Thu, 18 May 2023 12:07:23 +0100 Message-Id: <20230518110727.2106156-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518110727.2106156-1-ryan.roberts@arm.com> References: <20230518110727.2106156-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?1766230201429484858?= X-GMAIL-MSGID: =?utf-8?q?1766230201429484858?= 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; }