Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3813041rwb; Sun, 20 Nov 2022 22:58:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf56N5UHHETbWWQjhva/+i5Untac2liLuE0o0JnFxMeHsfVQg/I8KDXwblkDGEK0dWujtoPD X-Received: by 2002:a05:6402:f:b0:468:56c3:7c8 with SMTP id d15-20020a056402000f00b0046856c307c8mr15190587edu.109.1669013929852; Sun, 20 Nov 2022 22:58:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669013929; cv=none; d=google.com; s=arc-20160816; b=zT1eERaOAWzAhSyMupdcOCOEomYqkE/GswcsB9MZjhqGoYWHH9qmg6JwO59S7PyRwQ FVrjLpUu5vVo1SWWcKlDI9Bo3f2OIGLF8hUfkCoViuIi0Masj/jLu4mBFDYNlzJRhddQ NOkGTykrOWHnrWcQKZuUeNYDke0J8SMVhEXs2neP2w+fu7HaIK5HhpZVpTzIufR/7jPU hE2FW3QhGWrgSnwUqmP4eeWx8bmbkRmhT2t5T819+rPrElyzH8ehbQgHMTrO5YE+zokS bQS1fBFH06pSsmdvARX3ee9raMfHh+njCHNSZ5zPOOikHWDWmGc7Y9yHAGch+JbfQJ5V Dhxg== 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 :message-id:date:subject:cc:to:from; bh=Zud0gBOIRdlyz/kwzy2xGxsy/MI/gKOZhlJKXrVQP8I=; b=YnYJZgyb/QiU3pQDBbr5myRsL3ETbaum7rOuTeJ6U7rZLca3yCcnRKZ43tgjyJ6HdT ZATru2pWZAI79FXtcGnj8NSJbvKcwuAKYzaprhy0w15CZMeKja67bpjOqboxk/3juhDD neVcZB+I4IQIuH3YB5dXP0oBcXLUkqwUCBW6irGobKbzN1NyyfRlZAWHV3DccudFF9K1 BM0OxOkMMhJn7X9fseZN0yFKc1moJRmHex3IQwPxO5uHCKPNz6lRbgD5IdjO3xU86X5o fOaLj4yUCKjvxcPand9vdpLUCVgDqETkmdlXBv/InsO6F7l+/qaOoU6sgKZ5ETrF+Vya 7jhQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc30-20020a1709071c1e00b0077f3a9c58e2si8865750ejc.6.2022.11.20.22.58.26; Sun, 20 Nov 2022 22:58:49 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229612AbiKUGvP (ORCPT + 93 others); Mon, 21 Nov 2022 01:51:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbiKUGvM (ORCPT ); Mon, 21 Nov 2022 01:51:12 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38644186D0 for ; Sun, 20 Nov 2022 22:51:11 -0800 (PST) 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 D119560ED2 for ; Mon, 21 Nov 2022 06:51:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AC29C433D6; Mon, 21 Nov 2022 06:51:07 +0000 (UTC) From: Huacai Chen To: Huacai Chen Cc: loongarch@lists.linux.dev, Xuefeng Li , Guo Ren , Xuerui Wang , Jiaxun Yang , linux-kernel@vger.kernel.org, Huacai Chen Subject: [PATCH] LoongArch: Set _PAGE_DIRTY only if _PAGE_MODIFIED is set in {pmd,pte}_mkwrite() Date: Mon, 21 Nov 2022 14:48:26 +0800 Message-Id: <20221121064826.2115193-1-chenhuacai@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 Set _PAGE_DIRTY only if _PAGE_MODIFIED is set in {pmd,pte}_mkwrite(). Otherwise, _PAGE_DIRTY silences the TLB modify exception and make us have no chance to mark a pmd/pte dirty (_PAGE_MODIFIED) for software. Signed-off-by: Huacai Chen --- arch/loongarch/include/asm/pgtable.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h index debbe116f105..aa0e0e0d4ee5 100644 --- a/arch/loongarch/include/asm/pgtable.h +++ b/arch/loongarch/include/asm/pgtable.h @@ -357,7 +357,9 @@ static inline pte_t pte_mkdirty(pte_t pte) static inline pte_t pte_mkwrite(pte_t pte) { - pte_val(pte) |= (_PAGE_WRITE | _PAGE_DIRTY); + pte_val(pte) |= _PAGE_WRITE; + if (pte_val(pte) & _PAGE_MODIFIED) + pte_val(pte) |= _PAGE_DIRTY; return pte; } @@ -457,7 +459,9 @@ static inline int pmd_write(pmd_t pmd) static inline pmd_t pmd_mkwrite(pmd_t pmd) { - pmd_val(pmd) |= (_PAGE_WRITE | _PAGE_DIRTY); + pmd_val(pmd) |= _PAGE_WRITE; + if (pmd_val(pmd) & _PAGE_MODIFIED) + pmd_val(pmd) |= _PAGE_DIRTY; return pmd; } -- 2.31.1