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 X-Spam-Level: X-Spam-Status: No, score=-7.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AAB1C2B9F4 for ; Thu, 17 Jun 2021 11:41:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E39B613D5 for ; Thu, 17 Jun 2021 11:41:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231276AbhFQLnn (ORCPT ); Thu, 17 Jun 2021 07:43:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52518 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231610AbhFQLnl (ORCPT ); Thu, 17 Jun 2021 07:43:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623930093; h=from:from: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; bh=VmCLvCRTlrH58yubKa8HF1xENLoVvDewdsvG/LgtDCE=; b=QKhcyJg4xZ3IsAapRO/6xV2CClxElDsDKwmJWrlpRagChY+8UZiEHBoeqjBjkmjoBiGkF4 D4e+HOcR+8Go+hGauXG1O5UDHwyyW2t3YPakgVk8C7nk5rCfffIcEZcK0mjCZaBsjLJIz/ C4UVs/eXJuP7LXVQKVQ6jinbWTN7A7I= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-337-UhfAOk4LNG--l8TUdSmIBw-1; Thu, 17 Jun 2021 07:41:32 -0400 X-MC-Unique: UhfAOk4LNG--l8TUdSmIBw-1 Received: by mail-lj1-f197.google.com with SMTP id o15-20020a2e9b4f0000b029015ae56d3aa0so2668705ljj.0 for ; Thu, 17 Jun 2021 04:41:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=VmCLvCRTlrH58yubKa8HF1xENLoVvDewdsvG/LgtDCE=; b=foXr6CimQdheECGz5mEjZ4um000C/XmzCZfdab7XSHR/64srz27diDsIxpqaD8ei6U eLC6jGIhWNDB1hsvVe+BtPgdPzhWAZG0ft3pYq/oWuQTXAn5nxinteVRPiKbzEkWfRde +i9AONoAvQNb3bjyA5P/D9MYQClEGbjlD2H09i9gfvzU7cLVtQVSbPJnVSyBrkIgY51k SExtMK0ttK3YGgaNq7RSSn/vaXGo/leu2d673FBwfyH4uPuO8yBNFSk8HChArddqBIbZ tjKdEbl7OlsBRM+y2/DRSqnyu5ujMJzch3dDT0Vsf4yyB/bdBk1PezXuuUXJD+tsamwG g38g== X-Gm-Message-State: AOAM533eO6WeVhf9lfxyFQpLgKCe26NHiStTuxvpioDBe5ztgGi7bSnC 6tDDaRDIYwCGi7NCk7IB6deKfLwOYiP3rFf6vHKD6t1Wid3ao2hJnPUhf3Ypk5igW3hAXElJAww RpAjGsNBcLC4n X-Received: by 2002:a17:906:b317:: with SMTP id n23mr4753232ejz.324.1623929020526; Thu, 17 Jun 2021 04:23:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhbQ8ssqFmZsWb8sMpnt1Xu4dlg8VyEm5RPjNu6NQPEN0NLgvmdDkk7J48/7gKKGpvO8cI2w== X-Received: by 2002:a17:906:b317:: with SMTP id n23mr4753201ejz.324.1623929020383; Thu, 17 Jun 2021 04:23:40 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id by23sm3167995ejc.85.2021.06.17.04.23.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Jun 2021 04:23:39 -0700 (PDT) Subject: Re: [PATCH v10 2/5] KVM: stats: Add fd-based API to read binary stats data To: Greg KH , Jing Zhang Cc: KVM , KVMARM , LinuxMIPS , KVMPPC , LinuxS390 , Linuxkselftest , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Will Deacon , Huacai Chen , Aleksandar Markovic , Thomas Bogendoerfer , Paul Mackerras , Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Peter Shier , Oliver Upton , David Rientjes , Emanuele Giuseppe Esposito , David Matlack , Ricardo Koller , Krish Sadhukhan , Fuad Tabba References: <20210617044146.2667540-1-jingzhangos@google.com> <20210617044146.2667540-3-jingzhangos@google.com> From: Paolo Bonzini Message-ID: Date: Thu, 17 Jun 2021 13:23:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 17/06/21 09:03, Greg KH wrote: >> 3. Fd-based solution provides the possibility that a telemetry can >> read KVM stats in a less privileged situation. > "possiblity"? Does this work or not? Have you tested it? > I think this is essentially s/that/for/. But more precisely: 3. Compared for example to a ioctl, a separate file descriptor makes it possible for an external program to read statistics, while maintaining privilege separation between VMM and telemetry code. >> >> + snprintf(&kvm_vm_stats_header.id[0], sizeof(kvm_vm_stats_header.id), >> + "kvm-%d", task_pid_nr(current)); > > Why do you write to this static variable for EVERY read? Shouldn't you > just do it once at open? How can it change? > > Wait, it's a single shared variable, what happens when multiple tasks > open this thing and read from it? You race between writing to this > variable here and then: > >> + return kvm_stats_read(&kvm_vm_stats_header, &kvm_vm_stats_desc[0], >> + &kvm->stat, sizeof(kvm->stat), user_buffer, size, offset); > > Accessing it here. > > So how is this really working? It's not - Jing, kvm_vm_stats_header is small enough that you can store a copy in struct kvm. Paolo