From patchwork Mon Dec 4 17:26:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13478803 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 42B77C46CA0 for ; Mon, 4 Dec 2023 17:27:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3B6A6B02B6; Mon, 4 Dec 2023 12:27:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A9C5C6B02D1; Mon, 4 Dec 2023 12:27:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93EC16B02D8; Mon, 4 Dec 2023 12:27:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 814016B02B6 for ; Mon, 4 Dec 2023 12:27:14 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5B7911A02C0 for ; Mon, 4 Dec 2023 17:27:14 +0000 (UTC) X-FDA: 81529816788.27.AD9EBC7 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf24.hostedemail.com (Postfix) with ESMTP id A7430180014 for ; Mon, 4 Dec 2023 17:27:12 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=esCxaBMz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 37wtuZQoKCPAblZgmYZlgfYggYdW.Ugedafmp-eecnSUc.gjY@flex--jthoughton.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=37wtuZQoKCPAblZgmYZlgfYggYdW.Ugedafmp-eecnSUc.gjY@flex--jthoughton.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701710832; a=rsa-sha256; cv=none; b=DN3xBZkr3mSZUiVwawOslO6iSvV89dORUdIGIO651OGiOFS4gpWCUX2igekYLySN83bLsE SFiEcB7oqRd17Bcynfio1e19JT8gvrxxpeIwqZLuznArDsxpdlioPHB1y1I36Y+ox2K0Iy anDNmz8YJ1vt7BOo8OyJV1bvhArOakM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=esCxaBMz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 37wtuZQoKCPAblZgmYZlgfYggYdW.Ugedafmp-eecnSUc.gjY@flex--jthoughton.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=37wtuZQoKCPAblZgmYZlgfYggYdW.Ugedafmp-eecnSUc.gjY@flex--jthoughton.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701710832; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BIP1VBSrHfriGjh5Ogk9INZtbtmoj9c5sEQfKrkJBSE=; b=5tlD05Trc54ngxZ43k/C3NUmTerrXWf7pAvM/fcF9wh4J0T5UyiI8mNKRbdUNuGYb/lyze WmB5htQHM4Lwf8UdqoeZhjuiQ6LLBE+vIPxXQv219HqHlS1w8QNisRFigMxaNHU8/fJWtM MJ/xKrrAXbMSpA7e0VdReqfuyn2F9O0= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5ce16bc121aso78038607b3.1 for ; Mon, 04 Dec 2023 09:27:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701710832; x=1702315632; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BIP1VBSrHfriGjh5Ogk9INZtbtmoj9c5sEQfKrkJBSE=; b=esCxaBMzXfLERo32K4kWiVLAsdinaccwJXveL6mbn7p2/0/WOoUVjnnkh8u0i0MZme ZfWkHVXupYBI+97H3jaDYliB09uVM6RmBdZ3ahUOy8PpIhbD9RUw4Ue+8lW+y1gtvTs6 fT68Xxygeh7Gvj5BYT0KHC32L1Ij83qMLHoglMx7Hwguri4CaXBJGDHueqf1JXmnmuaO /S8/KyB01XdQuX6Ui7o3vOi668GZgQdzLglTSlrg5loY0Fr1P+tpgASunIuhLeXh0S4I nSGCHkYUMp0BpMW8FrBvROtyDyGxCIjREMOxKLRCbf/nFXeD3rwT0uyV7CU76lctlF1g gX9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701710832; x=1702315632; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BIP1VBSrHfriGjh5Ogk9INZtbtmoj9c5sEQfKrkJBSE=; b=UdV9X8GD8t3gOgi9tlozchHeUXoyGwyeMcU823UExwvlbIT49qBxwwtigKk7OYk8iO r0oVCrDMTfAgUzx+Y/5LWEsMlWsZT9A/bkwNnXWnrXe7xq8kUklhdKUTXZk+0aQXR3Ix MErzRoFnu8vchJTiylfHm6CxBzXkRKfSET3OI2ay2xbeSMzClfe2GBYPr4ep773RTzei jfs32PdFZxCIGCJ4TcHJFKn/NwgWXDMGKj4e4MdljFIvumpuwPkxvkd74+gTxSHfJvls vT0ZWxoLIYL+bUyvJ8VBInI1aaNcwy+ls7nmoeKTqgsTt0lgd0MEuPlh9IbrQA3f8zG1 t/EA== X-Gm-Message-State: AOJu0YywIHK8y/2UL79SnXIsgMBusOz306ictTYOSsmx1KAnLO1awR4l OKPwWh0/HeAX0G4jbMLps1wnggtNHTiSWMq0 X-Google-Smtp-Source: AGHT+IFq88uu4hPlgv5GbGd/ux88m4iUlZ64ATBmq3rePqIk98p8cvyl0w6nJZb3uZTHk5FQwmgEwV0mbM4oM1P0 X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:690c:2710:b0:5d5:5183:ebd7 with SMTP id dy16-20020a05690c271000b005d55183ebd7mr222984ywb.7.1701710831851; Mon, 04 Dec 2023 09:27:11 -0800 (PST) Date: Mon, 4 Dec 2023 17:26:46 +0000 In-Reply-To: <20231204172646.2541916-1-jthoughton@google.com> Mime-Version: 1.0 References: <20231204172646.2541916-1-jthoughton@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Message-ID: <20231204172646.2541916-3-jthoughton@google.com> Subject: [PATCH 2/2] arm64: mm: Always make sw-dirty PTEs hw-dirty in pte_modify From: James Houghton To: Steve Capper , Will Deacon , Andrew Morton Cc: Mike Kravetz , Muchun Song , Anshuman Khandual , Catalin Marinas , Ryan Roberts , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A7430180014 X-Stat-Signature: 88d7krioqxdmjnehnj9ycsraj6ru61if X-HE-Tag: 1701710832-763869 X-HE-Meta: U2FsdGVkX1888M9OmFBNv8tzdXeGRoqiTVfEmmURRMJmogTQdci/4EpH0ivgAoXeBGgZoHqbzbjmKTslX95EXFnuLQzmBE2s1fKWRDmeO+MPwC6WijatAlJwQmmPcTalzXlKh4+LfdcfeszjS7hGAUy5Wct+DzB03mRbtpXQmPiIhdyEFLvpdJ0FaSvuBgff+jo12ViqB6RC18vo6eatkwX5lN6YMMrO1LpwUn+B+0q0LTqY0lrvJAXQKlLYJAgDlggUKL0us3ylCKlDYm89AkYjJZsfmChz3wz3qRcXMNFpVevyiTkw9a1IvYoFsm2VZ+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y+GX487YllQA2Hk5XfSpRIc4tbmif3IWUMJ0CXqDTj7eZp+tjk1TH0UtndK8/Jn+2+kpc/ejO1N3MuiCmxskzyDPZV4TqgRWrcKXpcB7Zirzf0wBJvec/0lhWL0/F59mhwQUdNnwqpQ7qXrgFw2d6vJfH8YKZMxpXl6fC9hfQdsch6qNmjMtP8diDMq18SXR+eeMnoEVq/jcr5heR0BrFMEnZAb2zS/Wt4B1hlfkjSoZluJKo//c+vSQ9u97rn0Q30Vkt7BQmgDah6s7xp1zzCvS9U= X-Bogosity: Ham, tests=bogofilter, spamicity=0.015920, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Make it impossible to create a sw-dirty, hw-clean PTE with pte_modify. Such a PTE should be impossible to create, and there may be places that assume that pte_dirty() implies pte_hw_dirty(). Signed-off-by: James Houghton Reviewed-by: Ryan Roberts diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index b19a8aee684c..79ce70fbb751 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -834,6 +834,12 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) pte = set_pte_bit(pte, __pgprot(PTE_DIRTY)); pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask); + /* + * If we end up clearing hw dirtiness for a sw-dirty PTE, set hardware + * dirtiness again. + */ + if (pte_sw_dirty(pte)) + pte = pte_mkdirty(pte); return pte; }