From mboxrd@z Thu Jan 1 00:00:00 1970 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 F1E0AC636D7 for ; Thu, 23 Feb 2023 18:47:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EB706B0071; Thu, 23 Feb 2023 13:47:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29B336B0072; Thu, 23 Feb 2023 13:47:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1624E6B0073; Thu, 23 Feb 2023 13:47:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0535E6B0071 for ; Thu, 23 Feb 2023 13:47:52 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CAE4EA0B0D for ; Thu, 23 Feb 2023 18:47:51 +0000 (UTC) X-FDA: 80499440742.05.8112437 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf27.hostedemail.com (Postfix) with ESMTP id 00C4740017 for ; Thu, 23 Feb 2023 18:47:49 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="lNvI/2rg"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 31LT3YwYKCEMxjfsohlttlqj.htrqnsz2-rrp0fhp.twl@flex--seanjc.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=31LT3YwYKCEMxjfsohlttlqj.htrqnsz2-rrp0fhp.twl@flex--seanjc.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677178070; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9Ny3Ht+RWz/HwV/rhms1DlUfHO1U87sDcU+U5kFbTW4=; b=3rQjDuhHNAX+itLe09gXfq+9qNf1wknD55h985VW8C/I87FFORyiPFtqIxyac21mOgFUqJ PIKPCNnVpgLfsu5WfLuA6IIMK9bc+9FxLMEaVkoV1iydnvWkzgiv0d9+fNQiY47FN2OUG/ iCvDEL3fboN39ZsLRHszf4LrOeYGNr0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="lNvI/2rg"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 31LT3YwYKCEMxjfsohlttlqj.htrqnsz2-rrp0fhp.twl@flex--seanjc.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=31LT3YwYKCEMxjfsohlttlqj.htrqnsz2-rrp0fhp.twl@flex--seanjc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677178070; a=rsa-sha256; cv=none; b=pHjrWJ1uJn14kd2DOmSQVEqCNtfBSgIverqyT1C/TmQ8f40W6oVJEjI2kWOCIU7V1xH253 wnCP2feUU8p1OeObNj6Wf4H6tKiolX7p3pNly4Z40NZQaIe+7bzEwTBKqZ8osiDrzkqUoo Rq9RmsY3DA8+WglmPeFg30QT88IDYm4= Received: by mail-pf1-f202.google.com with SMTP id p5-20020a056a0026c500b005cbeecd5c0dso4867794pfw.3 for ; Thu, 23 Feb 2023 10:47:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=9Ny3Ht+RWz/HwV/rhms1DlUfHO1U87sDcU+U5kFbTW4=; b=lNvI/2rgj77Ic7ZvRg0lZ3CNmRucFlSj1+rQwgfvitkvy19Jw0pxzNMx6FDvqCPFgd fn7VvVppBKZsXPQhRzKJCkooJ1oyseISzoGS+zDrrC4kbkpz6pSAbvEq8JhS6plQEk9q GaU9E7UQAt/0o4s9nTWcnmlOZZQZR7Wez5KV2PxLO0WB0tDVrdFUyd+T6Hyj40TI2nEx H7df+dSoERd5mIARNVp4RJW9qzoqsk1dw8VWiF+VkWBRU5oX4U7Ze618a/cVc1xIOtFm XTxfpiw3IlfubSNl590W+AZZI8EVvNZsS+T/gWaccOVxmQJj2hJcgPaJQSqH67nvLspK 7zGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=9Ny3Ht+RWz/HwV/rhms1DlUfHO1U87sDcU+U5kFbTW4=; b=opdhQyzYkTOXSucUIB8ma8N8cppilMO1awc2u0oxlITmJTvCGx7YGN9sQ1Zt+USUrh 6BQC9w1cPP2SDxULfARkzkahVkCtVgRYU5uOTJOEiZzQG/zwc85DVsYM4kkskSiQ0ls5 CrK+S3rVNwKgn9d9/N7yjFcQe/bIVMzRdHJy7SWlrFqm3ecf8s4QGQ4d4/+4BUw8J5ao mmqklG8rLOxX7LxEn1a3gQ1i7TZUdmV+cS8gAwH/HH+mORCgPq6SLvtTbuglppumqknh kW/c93IRp5JBltFA5lpQfpCx4ZlSA9LZcVpcxh5tjBOeJ8N0A/H/nrtfbQ5plRzSqahC 5YBg== X-Gm-Message-State: AO0yUKXuc2Pne7iEx2fZ1BdD3kylPq3diw77PWqusj6jgEUlutSoitdy eSVL6TTNEK8tMCZsW8VsKiKPUc6HRcY= X-Google-Smtp-Source: AK7set8sDaiXwAv5raafMe6W95s8Ae365ZmaLbZB81kaT6psKhE8P1bs3HjFLIj62NtTvEiT8J5dndICUjg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:3282:b0:19a:7e00:da70 with SMTP id jh2-20020a170903328200b0019a7e00da70mr1903601plb.12.1677178068660; Thu, 23 Feb 2023 10:47:48 -0800 (PST) Date: Thu, 23 Feb 2023 10:47:47 -0800 In-Reply-To: Mime-Version: 1.0 References: <20230217041230.2417228-1-yuzhao@google.com> <20230217041230.2417228-3-yuzhao@google.com> Message-ID: Subject: Re: [PATCH mm-unstable v1 2/5] kvm/x86: add kvm_arch_test_clear_young() From: Sean Christopherson To: Yu Zhao Cc: Andrew Morton , Paolo Bonzini , Jonathan Corbet , Michael Larabel , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-mm@google.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 00C4740017 X-Stat-Signature: ir98gh4kwp9o4i7b93k8gijjfdfimx6o X-HE-Tag: 1677178069-199381 X-HE-Meta: U2FsdGVkX1/LFYetG62emlk8Qzc/8ehEVzHOpXwY8wu35d9lGuVB6nJeYQoqpWe2z8pwU0bEhw8xPwH9rJfZ8CiYDw8ZR4geTrbRyq/DR9RiBvRd/vgA6xjvRvPXDtLpHgUYma+ptLUsjNDQzYTLSa3tMv0XemrQ3qv2BYXZVQ5/q1HORqJAWAVmrCA2rUo8F0VzdexvjZ8iW/kQkGZnJin/42ws0wbVmpGfit8zR57MNravBBAdIkJrCiYkzZQpbKRjTHK0PIE0pFVmegBxEoyL9QtS+DvWDreUueotkn5aBBPzisZ8KbPc3BE6SPafwquOrSPewyoGm8tQao7N80cJi4kDnqOI57U3QhsyVFWyAn3RewGP+7ricf8XN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wqdIdoQx/we/F8aG8EBPhmhfTG3ohraOsmtqCkUhDl/YGdLNaZPqiJHCwmstJtQMTCDd0aPhwUbePmTf9dWkvXgOt5uKv4gWKZHGhFpGgmafYf6IQbFSsg7pXJJ9eKK5PIVg9S6uqb21zxd68CpjnSyMgdfiMK+2igQ9kYmbR2uXZioaKDJk+I/TDYHCsTml5htsnN9LyuSjfq59rFI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Feb 23, 2023, Yu Zhao wrote: > On Thu, Feb 23, 2023 at 11:24=E2=80=AFAM Sean Christopherson wrote: > > > > On Thu, Feb 23, 2023, Yu Zhao wrote: > > > On Thu, Feb 23, 2023 at 10:09=E2=80=AFAM Sean Christopherson wrote: > > > > > I'll take a look at that series. clear_bit() probably won't cause= any > > > > > practical damage but is technically wrong because, for example, i= t can > > > > > end up clearing the A-bit in a non-leaf PMD. (cmpxchg will just f= ail > > > > > in this case, obviously.) > > > > > > > > Eh, not really. By that argument, clearing an A-bit in a huge PTE = is also technically > > > > wrong because the target gfn may or may not have been accessed. > > > > > > Sorry, I don't understand. You mean clear_bit() on a huge PTE is > > > technically wrong? Yes, that's what I mean. (cmpxchg() on a huge PTE > > > is not.) > > > > > > > The only way for > > > > KVM to clear a A-bit in a non-leaf entry is if the entry _was_ a hu= ge PTE, but was > > > > replaced between the "is leaf" and the clear_bit(). > > > > > > I think there is a misunderstanding here. Let me be more specific: > > > 1. Clearing the A-bit in a non-leaf entry is technically wrong becaus= e > > > that's not our intention. > > > 2. When we try to clear_bit() on a leaf PMD, it can at the same time > > > become a non-leaf PMD, which causes 1) above, and therefore is > > > technically wrong. > > > 3. I don't think 2) could do any real harm, so no practically no prob= lem. > > > 4. cmpxchg() can avoid 2). > > > > > > Does this make sense? > > > > I understand what you're saying, but clearing an A-bit on a non-leaf PM= D that > > _just_ got converted from a leaf PMD is "wrong" if and only if the inte= nted > > behavior is nonsensical. >=20 > Sorry, let me rephrase: > 1. Clearing the A-bit in a non-leaf entry is technically wrong because > we didn't make sure there is the A-bit there -- the bit we are > clearing can be something else. (Yes, we know it's not, but we didn't > define this behavior, e.g., a macro to designate that bit for non-leaf > entries. Heh, by that definition, anything and everything is "technically wrong". A= n Intel CPU might support SVM, even though we know no such CPUs exist, so requiring= AMD or Hygon to enable SVM is technically wrong. > Also I didn't check the spec -- does EPT actually support the > A-bit in non-leaf entries? My guess is that NPT does.) If A/D bits are enabled, both EPT and 64-bit NPT support the Accessed bit a= t all levels irrespective of whether or not the entry maps a huge page. PAE NPT is a different story, but the TDP MMU is limited to 64-bit kernels,= i.e. requires 64-bit NPT.