Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5389176rwi; Mon, 17 Oct 2022 20:58:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4+JFUGUQDKdcnw6wRToNf2qwxRAyrN8I11+CjTjsCyGiMNlvyvivhWca7n/xF4IKzKYi0L X-Received: by 2002:a05:6a00:124a:b0:563:55ba:a6f8 with SMTP id u10-20020a056a00124a00b0056355baa6f8mr1188714pfi.2.1666065489896; Mon, 17 Oct 2022 20:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666065489; cv=none; d=google.com; s=arc-20160816; b=tSSsr4adiz4hOxMtJ9fBiwnEqn4kPY5Cfo/OsLJ7HTFzFW5iIldGa9sBDXo2rjyizd MsatOl2F7Y3mgjZDnZBJSNzLi8wJk92vhbtDK6LmpHCWyfAE++v6fiRX+8XD+omxgncR uzIpfmGJ1nQTiGYKaP3SkARPPP5HAOF9rDlMxIJ3bcxsx4xsFsLULQ4ufvCMmt1gKvLG Okm2+bjbVCkl9JjRiPqmVeBiHAH6zylLnA7RDwCLXaOGWI7qhWMrKQmVvVc48Ezh4gHI kPczDUHhVb/UypCErz8OFs9lm8kpz3fFVEFqjr5gKMeI8j2sBvHBh38tDgtLcxX9LQNk /Wpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=g3vYctWMe2Khoxx+tqp1Z68DkYIq+ZmCbB/96U7bDx8=; b=vcFsALNGruvPMG346qHFZCUM+WttoAEo1thK0otO8e4HIjJBsWvn/Cdjolaeao6qm9 T4D93e6znK9h1QFqjGW6N+H6T1YczpDIrLOqLmwkcjF6aFq/fAX9MBt19dIE0A1ktFxn LT5l6RRbB9gRokOIbXG9eCu2UVsU8/O3y4bXraujuARwf5DpTmuGaz5E23s3o4mIVWa2 SFFOqK5rULTLBOoLOJGT0FeJPwi5WqSlw+5jIN+2hScuYSnSzZER+vrHdlNWdm+P0VrS X1p6leMalMG64u8iB6BvLl+jzIHcOAQlIaACTfVwNZq44+Y1dwSxainRFDLb0QCZ33bs dy5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XTq4VNAt; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u3-20020a17090341c300b001822121c45fsi15812534ple.338.2022.10.17.20.57.57; Mon, 17 Oct 2022 20:58:09 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XTq4VNAt; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbiJRD0K (ORCPT + 99 others); Mon, 17 Oct 2022 23:26:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbiJRDZT (ORCPT ); Mon, 17 Oct 2022 23:25:19 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D2C921E29; Mon, 17 Oct 2022 20:19:41 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id t10-20020a17090a4e4a00b0020af4bcae10so12753159pjl.3; Mon, 17 Oct 2022 20:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=g3vYctWMe2Khoxx+tqp1Z68DkYIq+ZmCbB/96U7bDx8=; b=XTq4VNAtxYa02TWlV9dzQRCrMsA1pXBUDdALUmwbLyor47kqIOIvXiT1Es6nd+08Om d5TbTRNVqGCC+lf3/9G3U3DRaxKRfz65Ax6JHGlg7Xg1ezeN/0nHLlo9mFcx56xJm8YW uZv0LnVfCGOUb0MTvfHWSbX+r/HDGcrIUoSeGUm4xWlJKfhoIrGO96HLglhUK/bQjUYR ajdZZpJQYjyL+/ktKdbd8hTrWbmignyR6I5gU3YFdMOpo9PQEsjB3J8OPP6hYMFELbNK zJCiYpLIb6+Psj0eTricgfSSFSLBI6LUzoia+mB+N9gMaZ6gyEsJ7jhh+PuxdhM3kanU 0SaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=g3vYctWMe2Khoxx+tqp1Z68DkYIq+ZmCbB/96U7bDx8=; b=c1Jg1Kja7R/t/YtRnbUagswZPhVnjhp2tOGdD3PWIuG/OT3o9RNo/G6t/4S7HHmEDP Zt5pfzj1RJGgx1tRE6ruRrXN3Rq1yELfndgr+ucuD9cUZw7z2kE86XncYHRv2eacgRbZ oSl/C3NmxlyighYSeraElI9gQ2WXQ8EH/9k9Mc87dgXO/NyShJr0dzeIqMdw/n+nJwZs ZZgh1Asx4Le23J2g1oHg4nvThWFm/jiKVfJ5lsJIJ0XcIkaprURMPP0EZm5lBBfhVZ7a 9KvJnTyf8wJ3Jd6VPhxB7GWGnK6kGZf7UvEgbv09KfBJQJbKV4IX/Q8NVO/eab+zbS3E Om4A== X-Gm-Message-State: ACrzQf0JnQZ7TsQ2J2ZIfnM//W2lLjljTfwwQeQBqtLq37nRoYc+1nLM mQgvY1kBn7U244Uu4rcqUeO2Eg1UDV1CpA== X-Received: by 2002:a17:902:e804:b0:185:5276:7063 with SMTP id u4-20020a170902e80400b0018552767063mr863672plg.171.1666063181339; Mon, 17 Oct 2022 20:19:41 -0700 (PDT) Received: from [127.0.0.1] (n058152077178.netvigator.com. [58.152.77.178]) by smtp.gmail.com with ESMTPSA id t10-20020a1709027fca00b00178aaf6247bsm7356211plb.21.2022.10.17.20.19.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Oct 2022 20:19:40 -0700 (PDT) Message-ID: <50faa0c3-6996-c1b2-572a-96b296f4268b@gmail.com> Date: Tue, 18 Oct 2022 11:19:32 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH 0/3] kvm support for ksm Content-Language: en-US To: Izik Eidus Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, avi@redhat.com, aarcange@redhat.com, chrisw@redhat.com, riel@redhat.com, jeremy@goop.org, mtosatti@redhat.com, hugh@veritas.com, corbet@lwn.net, yaniv@redhat.com, dmonakhov@openvz.org References: <1238457604-7637-1-git-send-email-ieidus@redhat.com> From: ewandevelop In-Reply-To: <1238457604-7637-1-git-send-email-ieidus@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,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 Hi, I'm learning kvm-mmu codes, when I was reading codes from this patch, I can't understand why we need to do special process for "writable pte". > +static int kvm_set_pte_rmapp(struct kvm *kvm, unsigned long *rmapp, > +                 unsigned long data) > +{ > +    int need_flush = 0; > +    u64 *spte, new_spte; > +    pte_t *ptep = (pte_t *)data; > +    pfn_t new_pfn; > + > +    new_pfn = pte_pfn(ptep_val(ptep)); > +    spte = rmap_next(kvm, rmapp, NULL); > +    while (spte) { > +        BUG_ON(!is_shadow_present_pte(*spte)); > +        rmap_printk("kvm_set_pte_rmapp: spte %p %llx\n", spte, *spte); > +        need_flush = 1; > +        if (pte_write(ptep_val(ptep))) { > +            rmap_remove(kvm, spte); > +            set_shadow_pte(spte, shadow_trap_nonpresent_pte); > +            spte = rmap_next(kvm, rmapp, NULL); > +        } else { > +            new_spte = *spte &~ (PT64_BASE_ADDR_MASK); > +            new_spte |= new_pfn << PAGE_SHIFT; > + > +            if (!pte_write(ptep_val(ptep))) { > +                new_spte &= ~PT_WRITABLE_MASK; > +                new_spte &= ~SPTE_HOST_WRITEABLE; > +                if (is_writeble_pte(*spte)) > +                    kvm_set_pfn_dirty(spte_to_pfn(*spte)); > +            } > +            set_shadow_pte(spte, new_spte); > +            spte = rmap_next(kvm, rmapp, spte); > +        } > +    } > +    if (need_flush) > +        kvm_flush_remote_tlbs(kvm); > + > +    return 0; > +} > + In my opinion, we can just regard writable pte same as readable/executable, all the corresponding sptes will be set as write-protect, and when guest access them, an EPT-violation occurs and we do this #PF in kvm. Shall anyone has some hint ? On 2009/3/31 08:00, Izik Eidus wrote: > apply it against Avi git tree. > > Izik Eidus (3): > kvm: dont hold pagecount reference for mapped sptes pages. > kvm: add SPTE_HOST_WRITEABLE flag to the shadow ptes. > kvm: add support for change_pte mmu notifiers > > arch/x86/include/asm/kvm_host.h | 1 + > arch/x86/kvm/mmu.c | 89 ++++++++++++++++++++++++++++++++------- > arch/x86/kvm/paging_tmpl.h | 16 ++++++- > virt/kvm/kvm_main.c | 14 ++++++ > 4 files changed, 101 insertions(+), 19 deletions(-) > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > >