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 1634EC61DA4 for ; Thu, 23 Feb 2023 19:25:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A20656B0073; Thu, 23 Feb 2023 14:25:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D07B6B0074; Thu, 23 Feb 2023 14:25:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8709D6B0075; Thu, 23 Feb 2023 14:25:54 -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 743FB6B0073 for ; Thu, 23 Feb 2023 14:25:54 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 44DC6C01A3 for ; Thu, 23 Feb 2023 19:25:54 +0000 (UTC) X-FDA: 80499536628.09.2D2C479 Received: from mail-vs1-f48.google.com (mail-vs1-f48.google.com [209.85.217.48]) by imf30.hostedemail.com (Postfix) with ESMTP id 7B0A68000D for ; Thu, 23 Feb 2023 19:25:52 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=EdY0Zf42; spf=pass (imf30.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.48 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677180352; a=rsa-sha256; cv=none; b=7u4o0sdNX+YJC2QxQTveKRPqjtHzEHCgRJAeDi+FkqwMq9t9DJxZlsV5I2+SL+kN1Q2E9u lvIv4hK5VNp58iTiASxCYuX0y7uYWY6pJh8XqVnc7JG7//IbhcaEl+yoZJL0ESVzUiOZ4o wNZiSCbyXFcTTJeaH2DIvzos++Zmq/A= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=EdY0Zf42; spf=pass (imf30.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.48 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677180352; 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=RaN2m3eSdvQkZvFXVE5UwMtaHXh9kInOcPsQSxfuApo=; b=Nhr1aDS8mRHjCXkxrllRJ8Ids60UqjbGQwhx9vd86PEmWpVzbLmgaKqy86dB7w7c9Lq4f1 jh9JwU1o7JRtdI1u7o+ShaXjgj2t9oGV4BrvCwepdnkBcnJSBnFWycy671S7bPHY2elrJa 8dRsYXT2CseZkfX6hTWo7NlA4iLK5II= Received: by mail-vs1-f48.google.com with SMTP id o6so17608756vsq.10 for ; Thu, 23 Feb 2023 11:25:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RaN2m3eSdvQkZvFXVE5UwMtaHXh9kInOcPsQSxfuApo=; b=EdY0Zf42ZDRE5qttzyl6jWrHpR09fR1WYt885kd5Np43hjOjFvTgv/qafLuP2e/iYn Q5NiW0sXJQ99vo9CaNQ0NgLbSkRRmaO8aMUbNLNlhu2ZbabhX9zEOX5k/kc2LuYCJFtr qQnSvXzZNvaThZ8gqnSKqcakXE3Dm5AGNefE0M3sBomy7U9GtpPIIzmUgxTF3/IyYYmw 3J4ppBng3VEdZz4yGITOqYKi96kzh8seeVMxnEEhXUZrW50AtA5j0DmRye+ILDXMuKh9 5yZ+74iJ6VpGIZ9GKicdgFx5BWvLcdUTerJkJh4BQ8UOfIm5uv4FE50NVc66HSEwySfk y1sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RaN2m3eSdvQkZvFXVE5UwMtaHXh9kInOcPsQSxfuApo=; b=ZMw4oJ3idnol7LlHW7pf3t6mw7/ZGk3DTcTLxR2SiQz2J7UtSr+6ha0WewFiwTMgEf g5POz1nrQQGieq9w1C+WUPPhbXRe0wYDxo+bpzcNDPigXh9+9D0f+rQMhIXQj1QUQNi6 rYqPpBLKu+dJEuUOGS+bArqJL67UP99d1HY+z5tES35TqUGr+YhPMSAZx/VaYhRBc4UJ iNLsWDB6h06eZ8ufQH44MO8U7bW6juPwlAQJyk+WOIX80045eooIM6h8USQ1DqbgUE6Z tBRxtnCyGbdsrkDvfITqRDYk/4Xlu3fivu/H2SWAFGKqhEOXxe6q0p7oz4+CyvjpNNlB pJ9A== X-Gm-Message-State: AO0yUKXuMi7RHZBCwqX07a/bpQLlT4O5xiUED5SCljxq5n8FvsVxlM5M 8A4UGs93MBrPS7uDR04vIbn5gFrujb2N6JvuuK/iiw== X-Google-Smtp-Source: AK7set+MwFQXgKVqTLbdOfE3WTC6SqYAp6Rxgj82MRbQDTDH/3m6ISbS4ACZu2dBD1p1qYLzl2lVlP0QCPWzHhdfVlA= X-Received: by 2002:a05:6102:5d9:b0:415:74b4:6067 with SMTP id v25-20020a05610205d900b0041574b46067mr633121vsf.6.1677180351265; Thu, 23 Feb 2023 11:25:51 -0800 (PST) MIME-Version: 1.0 References: <20230217041230.2417228-1-yuzhao@google.com> <20230217041230.2417228-3-yuzhao@google.com> In-Reply-To: From: Yu Zhao Date: Thu, 23 Feb 2023 12:25:12 -0700 Message-ID: Subject: Re: [PATCH mm-unstable v1 2/5] kvm/x86: add kvm_arch_test_clear_young() To: Sean Christopherson 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-Queue-Id: 7B0A68000D X-Rspamd-Server: rspam01 X-Stat-Signature: p1w6gbmr59nce6xzkn8shpwjf3g4dte3 X-HE-Tag: 1677180352-702694 X-HE-Meta: U2FsdGVkX186XN7CbZYisOhy11Vdl6ezu87kvnAVOpjPNKQ8a4Di17ctxAvp/54oVbxiwCqLR5gKmeTWvBm7XlKyiVuSAHxUI6X86cYXrwT/aGRVNMcVySgowcdjafBDtjM6jrafJN6FFVbgA9woptavvC/bF3IEBYPG0nb6PL/szn9Ome48+anRN+f6PJD6EHpZsUoyhtFdwm7DJ42iNlFD8vmLCMjXXfcnf6qvLBJMoq/7QWUv8Yldh0pRuj/Hvngo5VcS8FMGCws4ZlGxXN+zMQUDr9TKNXch03F3cv/4dAk95zqj9Paw8UM7sybA8AyFckFARfjMzdeyRx3CYxKxd8YzXO71V0N5Eq2Mn8Z0TMeAa9vtv7HxIQ3pYBry5Kjol3qCqFFA/w5Rfpfgo72EyT4ImHlQjIWO2lik18s6sNYkLNP+iHLaOCCcZYv5ks05ppPufIMYhUo2mEdXuo3OLSpex/TuzbvEa3B3hIrZ6om8Ip4xObFH06kFbMCqzMNmsFhB0NkFIs6hyPIJnVl/JzhpBe9DWIWFiBfG8VUrHapjeDtWEtDJlIXy7uBaGPNBgKWeq3EQm27JRPMSL/Bi5NuU39wVz/Ba89hOGFVJVck4x5yx/RiKD51oTdz78gHuHlxWohnG+vroSlZEkm5sJyuwY8uZrN2Xp0/aaFYWtJcdEGRjeara1PAv0RhmRMK+PXhaUiFvfH/4HkRDTE0gTSVHMpMYgb/wh9z54otqrF8XYJaUt0Kvrzhntzd5W5lUYbSBVb3ZvWBQe+FQ8QgNNJXFIaGxiD/tQpMNXjUue1BFekiGh65YrgJQeOiGw59yelQa3mAOZWEqaNz2HWYG6r1ArXwdk6ScYGp/HkPFds+d56b2v8HLuIgi2+cKaqTHU/r8QueS+2adeE+nZYQb8UL7qP9IZLolnMkxMgqhFcJCjlfmfquswt8e27E3aZUbVWtYq9g0kIZOcNo iWJTzsPn csHG/VGJnjkus1yLHMrcEJTOX35sM+mjewpPgYoyXb55P7B4YBFetbIdtu/XCvrjxyvMOs8RJ+eK8RQTgN0Z26mD4PPFpc33QBX0ewA99N1CgRcUoR+nraGqI9ifMsj6E8XI/wFbtGV34XygeB7l4zkNMjdgJ9DV2WWOKQXa46OacLvPG50o+grkg8QOZtoAWnuTcOs5EGLm13/McpDjmOB6ELgWrGmts1nvu2lbcg85nnPQ1nMNj0hBd6DpjHoPNpnwnxfj+S00uUm3v4vjRWy+HxJza+jniQAmfG/gQXn8cvv8bleKs3tFAarDhzf1JRpNWHOwKSR3Vjhgprnw2sifzkuoCD7hcrk5zPxW0vij+DjUPzkIeACEhW5zpTCJCKMt0KrcDPCD5j0Dt1AfB2UfIl1AFiCfeG5wQ2YVQ7mFwNujfsrcx2aZxuQ== 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 at 12:21=E2=80=AFPM Sean Christopherson wrote: > > 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= cause any > > > > > > > > practical damage but is technically wrong because, for exam= ple, it can > > > > > > > > end up clearing the A-bit in a non-leaf PMD. (cmpxchg will = just fail > > > > > > > > in this case, obviously.) > > > > > > > > > > > > > > Eh, not really. By that argument, clearing an A-bit in a hug= e PTE is also technically > > > > > > > wrong because the target gfn may or may not have been accesse= d. > > > > > > > > > > > > Sorry, I don't understand. You mean clear_bit() on a huge PTE i= s > > > > > > technically wrong? Yes, that's what I mean. (cmpxchg() on a hug= e 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 specif= ic: > > > > > > 1. Clearing the A-bit in a non-leaf entry is technically wrong = because > > > > > > 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 n= o problem. > > > > > > 4. cmpxchg() can avoid 2). > > > > > > > > > > > > Does this make sense? > > > > > > > > > > I understand what you're saying, but clearing an A-bit on a non-l= eaf PMD that > > > > > _just_ got converted from a leaf PMD is "wrong" if and only if th= e intented > > > > > behavior is nonsensical. > > > > > > > > Sorry, let me rephrase: > > > > 1. Clearing the A-bit in a non-leaf entry is technically wrong beca= use > > > > 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-l= eaf > > > > entries. > > > > > > Heh, by that definition, anything and everything is "technically wron= g". > > > > I really don't see how what I said, in our context, > > > > "Clearing the A-bit in a non-leaf entry is technically wrong because > > we didn't make sure there is the A-bit there" > > > > can infer > > > > "anything and everything is "technically wrong"." > > > > And how what I said can be an analogy to > > > > "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." > > > > 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= / > > > > Let's just agree to disagree. > > No, because I don't want anyone to leave with the impression that relying= on the > Accessed bit to uniformly exist (or not) at all levels in the TDP MMU is = somehow > technically wrong. The link you posted is about running as a Xen guest, = and is > in arch-agnostic code. That is wildly different than what we are talking= about > here, where the targets are strictly limited to x86-64 TDP, and the exist= ence of > the Accessed bit is architecturally defined. Yes, I see now. Sorry to say this, but this is all I needed to hear: "the existence of the Accessed bit is architecturally defined". (I didn't know and see this is what you meant.) > In this code, there are exactly two flavors of paging that can be in use,= and > using clear_bit() to clear shadow_accessed_mask is safe for both, full st= op.