From patchwork Mon Nov 21 06:48:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huacai Chen X-Patchwork-Id: 23545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1423389wrr; Sun, 20 Nov 2022 22:56:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf6t8mlNg70R7yBE5YmNnvwWE5RZDiQrZgzjGXvW4CX0Xdqu/bDxpNACAB4VLZUEIUcjK3I8 X-Received: by 2002:a63:712:0:b0:438:e0dc:9c53 with SMTP id 18-20020a630712000000b00438e0dc9c53mr16519907pgh.322.1669013787802; Sun, 20 Nov 2022 22:56:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669013787; cv=none; d=google.com; s=arc-20160816; b=h52iY4J4AEoGrGuvrkwI6/lCyA67jqwpEdSZgkYZLBs1YuosLjm7l16f1yarQXdsvL AvvHArlQcQETEk6lRxKGxJTM0HXCzcKsqj9Pqg22ovx3An7QQMe3pHsnBBxBgvWRhIKf C9oee1DIN79J9NeOcyQiCk9qkeEHR3a6ZAiYdy/5nt2gp3/S3n9nnrnttoc0FQO3VCfr +/iwpoi74wIcTtHq/LKvC+Adaf0x8nTX76QLsjclyYff+ar7Ghv5+XKjlmEAxxwTK926 uxHkQ9dy+ZRgCbGWiX45JbRXs5Pe3IYNQx3JS/BgPLWMZzVbpFRxldLyrLvhF0IQXWok eYJg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l3-20020a170902f68300b00186c37272a6si12352309plg.178.2022.11.20.22.55.53; Sun, 20 Nov 2022 22:56:27 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750087801581069325?= X-GMAIL-MSGID: =?utf-8?q?1750087801581069325?= 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 Reviewed-by: Guo Ren --- 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; }