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 B0241C61DA4 for ; Thu, 23 Feb 2023 19:21:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25B056B0073; Thu, 23 Feb 2023 14:21:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 20B626B0074; Thu, 23 Feb 2023 14:21:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D37D6B0075; Thu, 23 Feb 2023 14:21:43 -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 F1CE16B0073 for ; Thu, 23 Feb 2023 14:21:42 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BF6221C6615 for ; Thu, 23 Feb 2023 19:21:42 +0000 (UTC) X-FDA: 80499526044.04.9B4FF3C Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf05.hostedemail.com (Postfix) with ESMTP id 06C24100012 for ; Thu, 23 Feb 2023 19:21:40 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=H4d0auWy; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 3xLz3YwYKCEMxjfsohlttlqj.htrqnsz2-rrp0fhp.twl@flex--seanjc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3xLz3YwYKCEMxjfsohlttlqj.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=1677180101; 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=ZopDWrZnbH+TBZHwFmu9lqsS8DLdv4K+JgWTWbyi1iU=; b=zw0VOWl9vnH8mRad4JUz45IuMkXr0w/2suTPiP2OBxE8culgWOSU2ekKNqkowLd0AZWoy4 A758r/ui1W4RXU26OO7i6WPHOzfbPMb9u/fyh+WZBHk8vSzh4dP4pOU69bWjZNYRAxVfJ7 YEbqgPPQIkl944/R3zSBYJcb9BZ6ueY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=H4d0auWy; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 3xLz3YwYKCEMxjfsohlttlqj.htrqnsz2-rrp0fhp.twl@flex--seanjc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3xLz3YwYKCEMxjfsohlttlqj.htrqnsz2-rrp0fhp.twl@flex--seanjc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677180101; a=rsa-sha256; cv=none; b=zxN37ZjLq39k4EQ/XBiCGB7r30PRxNeti1c2MapkwMB56fBLga4L7zQZo41NIQBOYiOzkG LSXwncUNvmmNlC/fHuXSHvqiGni//TDmcMepNggv8SXte0uYd8H7vEWzSD/4KxbhIl/Z19 Xrz/uTaOhIcZ2/js7iFDFKjoj7ySWoI= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-536a545bfbaso162000137b3.20 for ; Thu, 23 Feb 2023 11:21:40 -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=ZopDWrZnbH+TBZHwFmu9lqsS8DLdv4K+JgWTWbyi1iU=; b=H4d0auWygP+hmWPqWDO3qHOcWpnYjVNf506Kv9RG0yijBoQVPVDvpSxMBTdo4uUJGO MLoFt/yVDt/rfg/KEjjWlgTsmtn2v/BJ7mcJ0tNJd/5B2yEYthUWMcP49jnHZIFS2xWD PYy85xVSu7OInOx0VfGConFKXB/8dzggfBGddjwi36FY4Kr5lsfQrJsHMyzxbXSZ6ul6 eCrHhGBT4UNlyZ86MP+6pfLoRnP4BLJ+Xa6gqTf/lpjJRMImNB9r2JninNlL079C7W8J WgAk4CnNyPXAa81eo8Y6q3j7OEpZehi0vMcVGDQwUdb/BDgWqwnBxKdZk8Lqvnm0cjJZ PEtA== 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=ZopDWrZnbH+TBZHwFmu9lqsS8DLdv4K+JgWTWbyi1iU=; b=jRcybkbqrduR+8L2vk8iUkymVOPp0MISRt7d2rMPZJG9RPfrGhh8p17wwZJbXm4sJR 0oDCCUe+1nGjhNOmtEl9sAAHchmWlQkjCGBRC1WJoFwByWIVH2sX633DUpa28w90QPje W1PMudAybAWkfWjkz3644lmEEBOfeE335lCifxOUf3KKSNbfylNC+P2DQj0gRHxnEPXK i9Y+8CJG4KinDPCgdLPOkTEx7op7ZKaV9YQL/aOif/FjVnlBNPS4puP0Y9nYKB5mQ7dW Hx7FfJEqaMuCitqx7OicZjynKSOvH1KZ4QbVX2GXOhRyGe9JQ5TWdCdye5drPlzrsBD1 /XaQ== X-Gm-Message-State: AO0yUKUrU//zlyoQyIfbyxmKZga2YY6L3ACgmijWiKdJ1vhCNd7hGZTZ RcDptMKPmpIJq3pgfL0mj5atFIUP9/w= X-Google-Smtp-Source: AK7set8Y6PDK0RpzEk696ekGVhLGOajZqUcJ01xvSF46QVcIbnp7Dq+AUoIZCvKnF1H54bpA/2pnHYcG804= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:11cd:b0:8a3:d147:280b with SMTP id n13-20020a05690211cd00b008a3d147280bmr4056323ybu.3.1677180100192; Thu, 23 Feb 2023 11:21:40 -0800 (PST) Date: Thu, 23 Feb 2023 11:21:38 -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-Rspamd-Queue-Id: 06C24100012 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: b4tzjjm3ww84j54ci64rskndhxdjduds X-HE-Tag: 1677180100-346805 X-HE-Meta: U2FsdGVkX19EiJBStjQazitjoPmfzbu+DbtkdBr8Y8LTMydD0xfaEMNMsS0IXYETLx2YT+cqCssuzb5KvHkDUwiH4NSMv4/nQN6qnp2NeDfr+SXO9Apoy/fzvwLibgyEbfpb2XvCq3vcUXFURx6m5fjTRqUCgbse7VOD/ltEd9DT/aTUWgRs8iSXv6Z6BJ9OCRVOVP2fj6ESIsmM1NxDUAaRbmLh36fNZe+lHIUnlaY3Yg2jBXjNI6KjLDz2duoWR0+ye3ZLxYk2L9QTq9nBij5AhgKb0EgAx9mr/4Pw8GAnUfpnvkDpRBYAa7iDSD8g/63Bxo2EsLaoM8NtJT/5b7AzrQXMAjf0Je4wP1gDO6xExbqApB8zsMvOet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XPQjNDmTVGZdfv1nijA/8VLNYbAc/BPpt+hOeQUje4u5X3C1I2e/3X5v4zZXsTeUiTofKdfbTVnv0gVmdTixOMX97+2DANQXOCDkJJcvyn5xxb5qLhLpxfgcH0iEIbJLJRS/s+IPOgcNnEXFgnLTetbx2qXp4vU6b/7Q9E/duH3AxqtcRxi1ttuiEq5+ebuhtkcdWxpGmWj3zrPHMZuN60ExzbjY0H2Cv6IgMdueIJHngwEEiAb/6gud/NJfkm2CCNAAZPgDYw23l/lxhua4HgvkB0MVjqA6W4stqI71tIohe2uE7GoTshZYJxBXgaiSSEpSueYgw/THHvkMfwM/XWcF3c= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000371, 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:47=E2=80=AFAM Sean Christopherson wrote: > > > > 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 c= ause any > > > > > > > practical damage but is technically wrong because, for exampl= e, it can > > > > > > > end up clearing the A-bit in a non-leaf PMD. (cmpxchg will ju= st fail > > > > > > > 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 huge 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 be= cause > > > > > that's not our intention. > > > > > 2. When we try to clear_bit() on a leaf PMD, it can at the same t= ime > > > > > 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 = problem. > > > > > 4. cmpxchg() can avoid 2). > > > > > > > > > > Does this make sense? > > > > > > > > I understand what you're saying, but clearing an A-bit on a non-lea= f PMD that > > > > _just_ got converted from a leaf PMD is "wrong" if and only if the = intented > > > > behavior is nonsensical. > > > > > > Sorry, let me rephrase: > > > 1. Clearing the A-bit in a non-leaf entry is technically wrong becaus= e > > > 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-lea= f > > > entries. > > > > Heh, by that definition, anything and everything is "technically wrong"= . >=20 > I really don't see how what I said, in our context, >=20 > "Clearing the A-bit in a non-leaf entry is technically wrong because > we didn't make sure there is the A-bit there" >=20 > can infer >=20 > "anything and everything is "technically wrong"." >=20 > And how what I said can be an analogy to >=20 > "An Intel CPU might support SVM, even though we know no such CPUs > exist, so requiring AMD or Hygon to enable SVM is technically wrong." >=20 > BTW, here is a bug caused by clearing the A-bit in non-leaf entries in > a different scenario: > https://lore.kernel.org/linux-mm/20221123064510.16225-1-jgross@suse.com/ >=20 > Let's just agree to disagree. No, because I don't want anyone to leave with the impression that relying o= n the Accessed bit to uniformly exist (or not) at all levels in the TDP MMU is so= mehow technically wrong. The link you posted is about running as a Xen guest, an= d is in arch-agnostic code. That is wildly different than what we are talking a= bout here, where the targets are strictly limited to x86-64 TDP, and the existen= ce of the Accessed bit is architecturally defined. In this code, there are exactly two flavors of paging that can be in use, a= nd using clear_bit() to clear shadow_accessed_mask is safe for both, full stop= .